Commit 173b07fa authored by jarin@chromium.org's avatar jarin@chromium.org

[turbofan] Output schedule, instructions and register allocator in C1...

[turbofan] Output schedule, instructions and register allocator in C1 visualizer format when --turbo-trace is specified.

BUG=
R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/637313002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24583 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d75f736c
This diff is collapsed.
......@@ -9,9 +9,17 @@
namespace v8 {
namespace internal {
class CompilationInfo;
namespace compiler {
class Graph;
class InstructionSequence;
class RegisterAllocator;
class Schedule;
class SourcePositionTable;
struct AsDOT {
explicit AsDOT(const Graph& g) : graph(g) {}
......@@ -28,6 +36,39 @@ struct AsJSON {
std::ostream& operator<<(std::ostream& os, const AsJSON& ad);
struct AsC1VCompilation {
explicit AsC1VCompilation(const CompilationInfo* info) : info_(info) {}
const CompilationInfo* info_;
};
struct AsC1V {
AsC1V(const char* phase, const Schedule* schedule,
const SourcePositionTable* positions = NULL,
const InstructionSequence* instructions = NULL)
: schedule_(schedule),
instructions_(instructions),
positions_(positions),
phase_(phase) {}
const Schedule* schedule_;
const InstructionSequence* instructions_;
const SourcePositionTable* positions_;
const char* phase_;
};
struct AsC1VAllocator {
explicit AsC1VAllocator(const char* phase,
const RegisterAllocator* allocator = NULL)
: phase_(phase), allocator_(allocator) {}
const char* phase_;
const RegisterAllocator* allocator_;
};
std::ostream& operator<<(std::ostream& os, const AsDOT& ad);
std::ostream& operator<<(std::ostream& os, const AsC1VCompilation& ac);
std::ostream& operator<<(std::ostream& os, const AsC1V& ac);
std::ostream& operator<<(std::ostream& os, const AsC1VAllocator& ac);
} // namespace compiler
} // namespace internal
} // namespace v8
......
......@@ -291,7 +291,7 @@ std::ostream& operator<<(std::ostream& os, const Instruction& instr) {
os << " " << *instr.InputAt(i);
}
}
return os << "\n";
return os;
}
......@@ -564,7 +564,7 @@ std::ostream& operator<<(std::ostream& os, const InstructionSequence& code) {
j <= block->last_instruction_index(); j++) {
// TODO(svenpanne) Add some basic formatting to our streams.
SNPrintF(buf, "%5d", j);
os << " " << buf.start() << ": " << *code.InstructionAt(j);
os << " " << buf.start() << ": " << *code.InstructionAt(j) << "\n";
}
os << " " << block->control();
......
......@@ -29,7 +29,7 @@ void NodeAuxData<T>::Set(Node* node, const T& data) {
template <class T>
T NodeAuxData<T>::Get(Node* node) {
T NodeAuxData<T>::Get(Node* node) const {
int id = node->id();
if (id >= static_cast<int>(aux_data_.size())) {
return T();
......
......@@ -21,7 +21,7 @@ class NodeAuxData {
inline explicit NodeAuxData(Zone* zone);
inline void Set(Node* node, const T& data);
inline T Get(Node* node);
inline T Get(Node* node) const;
private:
ZoneVector<T> aux_data_;
......
......@@ -90,13 +90,28 @@ static inline bool VerifyGraphs() {
}
void Pipeline::PrintCompilationStart() {
std::ofstream turbo_cfg_stream;
OpenTurboCfgFile(&turbo_cfg_stream);
turbo_cfg_stream << AsC1VCompilation(info());
}
void Pipeline::OpenTurboCfgFile(std::ofstream* stream) {
char buffer[512];
Vector<char> filename(buffer, sizeof(buffer));
isolate()->GetTurboCfgFileName(filename);
stream->open(filename.start(), std::fstream::out | std::fstream::app);
}
void Pipeline::VerifyAndPrintGraph(Graph* graph, const char* phase) {
if (FLAG_trace_turbo) {
char buffer[256];
Vector<char> filename(buffer, sizeof(buffer));
SmartArrayPointer<char> functionname;
if (!info_->shared_info().is_null()) {
SmartArrayPointer<char> functionname =
info_->shared_info()->DebugName()->ToCString();
functionname = info_->shared_info()->DebugName()->ToCString();
if (strlen(functionname.get()) > 0) {
SNPrintF(filename, "turbo-%s-%s", functionname.get(), phase);
} else {
......@@ -132,6 +147,24 @@ void Pipeline::VerifyAndPrintGraph(Graph* graph, const char* phase) {
}
void Pipeline::PrintScheduleAndInstructions(
const char* phase, const Schedule* schedule,
const SourcePositionTable* positions,
const InstructionSequence* instructions) {
std::ofstream turbo_cfg_stream;
OpenTurboCfgFile(&turbo_cfg_stream);
turbo_cfg_stream << AsC1V(phase, schedule, positions, instructions);
}
void Pipeline::PrintAllocator(const char* phase,
const RegisterAllocator* allocator) {
std::ofstream turbo_cfg_stream;
OpenTurboCfgFile(&turbo_cfg_stream);
turbo_cfg_stream << AsC1VAllocator(phase, allocator);
}
class AstGraphBuilderWithPositions : public AstGraphBuilder {
public:
explicit AstGraphBuilderWithPositions(CompilationInfo* info, JSGraph* jsgraph,
......@@ -188,6 +221,7 @@ Handle<Code> Pipeline::GenerateCode() {
<< "Begin compiling method "
<< info()->function()->debug_name()->ToCString().get()
<< " using Turbofan" << std::endl;
PrintCompilationStart();
}
// Build the graph.
......@@ -405,6 +439,8 @@ Handle<Code> Pipeline::GenerateCode(Linkage* linkage, Graph* graph,
OFStream os(stdout);
os << "----- Instruction sequence before register allocation -----\n"
<< sequence;
PrintScheduleAndInstructions("CodeGen", schedule, source_positions,
&sequence);
}
// Allocate registers.
......@@ -419,6 +455,9 @@ Handle<Code> Pipeline::GenerateCode(Linkage* linkage, Graph* graph,
linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc);
return Handle<Code>::null();
}
if (FLAG_trace_turbo) {
PrintAllocator("CodeGen", &allocator);
}
}
if (FLAG_trace_turbo) {
......
......@@ -5,6 +5,8 @@
#ifndef V8_COMPILER_PIPELINE_H_
#define V8_COMPILER_PIPELINE_H_
#include <fstream> // NOLINT(readability/streams)
#include "src/v8.h"
#include "src/compiler.h"
......@@ -18,9 +20,11 @@ namespace compiler {
// Clients of this interface shouldn't depend on lots of compiler internals.
class Graph;
class InstructionSequence;
class Linkage;
class RegisterAllocator;
class Schedule;
class SourcePositionTable;
class Linkage;
class Pipeline {
public:
......@@ -48,6 +52,12 @@ class Pipeline {
Zone* zone() { return info_->zone(); }
Schedule* ComputeSchedule(Graph* graph);
void OpenTurboCfgFile(std::ofstream* stream);
void PrintCompilationStart();
void PrintScheduleAndInstructions(const char* phase, const Schedule* schedule,
const SourcePositionTable* positions,
const InstructionSequence* instructions);
void PrintAllocator(const char* phase, const RegisterAllocator* allocator);
void VerifyAndPrintGraph(Graph* graph, const char* phase);
Handle<Code> GenerateCode(Linkage* linkage, Graph* graph, Schedule* schedule,
SourcePositionTable* source_positions);
......
......@@ -218,11 +218,12 @@ class Schedule FINAL : public ZoneObject {
void AddSuccessor(BasicBlock* block, BasicBlock* succ);
BasicBlockVector* rpo_order() { return &rpo_order_; }
const BasicBlockVector* rpo_order() const { return &rpo_order_; }
BasicBlock* start() { return start_; }
BasicBlock* end() { return end_; }
Zone* zone() { return zone_; }
Zone* zone() const { return zone_; }
private:
friend class Scheduler;
......
......@@ -46,7 +46,7 @@ void SourcePositionTable::RemoveDecorator() {
}
SourcePosition SourcePositionTable::GetSourcePosition(Node* node) {
SourcePosition SourcePositionTable::GetSourcePosition(Node* node) const {
return table_.Get(node);
}
......
......@@ -79,7 +79,7 @@ class SourcePositionTable FINAL {
void AddDecorator();
void RemoveDecorator();
SourcePosition GetSourcePosition(Node* node);
SourcePosition GetSourcePosition(Node* node) const;
private:
class Decorator;
......
......@@ -1625,6 +1625,7 @@ int Shell::Main(int argc, char* argv[]) {
StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob);
#endif
SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg");
SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg");
SetFlagsFromString("--redirect-code-traces-to=code.asm");
ShellArrayBufferAllocator array_buffer_allocator;
MockArrayBufferAllocator mock_arraybuffer_allocator;
......
......@@ -333,6 +333,8 @@ DEFINE_BOOL(omit_map_checks_for_leaf_maps, true,
// Flags for TurboFan.
DEFINE_STRING(turbo_filter, "~", "optimization filter for TurboFan compiler")
DEFINE_BOOL(trace_turbo, false, "trace generated TurboFan IR")
DEFINE_STRING(trace_turbo_cfg_file, NULL,
"trace turbo cfg graph (for C1 visualizer) to a given file name")
DEFINE_BOOL(trace_turbo_types, true, "trace generated TurboFan types")
DEFINE_BOOL(trace_turbo_scheduler, false, "trace generated TurboFan scheduler")
DEFINE_BOOL(turbo_asm, false, "enable TurboFan for asm.js code")
......
......@@ -4,6 +4,8 @@
#include <stdlib.h>
#include <fstream> // NOLINT(readability/streams)
#include "src/v8.h"
#include "src/ast.h"
......@@ -1951,6 +1953,16 @@ bool Isolate::Init(Deserializer* des) {
runtime_profiler_ = new RuntimeProfiler(this);
if (FLAG_trace_turbo) {
// Erase the file.
char buffer[512];
Vector<char> filename(buffer, sizeof(buffer));
GetTurboCfgFileName(filename);
std::ofstream turbo_cfg_stream(filename.start(),
std::fstream::out | std::fstream::trunc);
}
// If we are deserializing, log non-function code objects and compiled
// functions found in the snapshot.
if (!create_heap_objects &&
......@@ -2364,6 +2376,16 @@ BasicBlockProfiler* Isolate::GetOrCreateBasicBlockProfiler() {
}
void Isolate::GetTurboCfgFileName(Vector<char> filename) {
if (FLAG_trace_turbo_cfg_file == NULL) {
SNPrintF(filename, "turbo-%d-%d.cfg", base::OS::GetCurrentProcessId(),
id());
} else {
StrNCpy(filename, FLAG_trace_turbo_cfg_file, filename.length());
}
}
bool StackLimitCheck::JsHasOverflowed() const {
StackGuard* stack_guard = isolate_->stack_guard();
#ifdef USE_SIMULATOR
......
......@@ -1107,6 +1107,8 @@ class Isolate {
static Isolate* NewForTesting() { return new Isolate(false); }
void GetTurboCfgFileName(Vector<char> buffer);
private:
explicit Isolate(bool enable_serializer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment