Reland 'Simplify TurboFan's c1visualizer file handling.'

This is r24819 plus some tiny fixes to make the Mac toolchain happy.

TBR=bmeurer@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24840 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 707ed29a
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/compiler/pipeline.h"
#include <fstream> // NOLINT(readability/streams)
#include <sstream> #include <sstream>
#include "src/base/platform/elapsed-timer.h" #include "src/base/platform/elapsed-timer.h"
...@@ -20,7 +23,6 @@ ...@@ -20,7 +23,6 @@
#include "src/compiler/js-typed-lowering.h" #include "src/compiler/js-typed-lowering.h"
#include "src/compiler/machine-operator-reducer.h" #include "src/compiler/machine-operator-reducer.h"
#include "src/compiler/phi-reducer.h" #include "src/compiler/phi-reducer.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/pipeline-statistics.h" #include "src/compiler/pipeline-statistics.h"
#include "src/compiler/register-allocator.h" #include "src/compiler/register-allocator.h"
#include "src/compiler/schedule.h" #include "src/compiler/schedule.h"
...@@ -47,19 +49,11 @@ static inline bool VerifyGraphs() { ...@@ -47,19 +49,11 @@ static inline bool VerifyGraphs() {
} }
void Pipeline::PrintCompilationStart() { struct TurboCfgFile : public std::ofstream {
std::ofstream turbo_cfg_stream; explicit TurboCfgFile(Isolate* isolate)
OpenTurboCfgFile(&turbo_cfg_stream); : std::ofstream(isolate->GetTurboCfgFileName().c_str(),
turbo_cfg_stream << AsC1VCompilation(info()); std::ios_base::app) {}
} };
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( void Pipeline::VerifyAndPrintGraph(
...@@ -108,24 +102,6 @@ void Pipeline::VerifyAndPrintGraph( ...@@ -108,24 +102,6 @@ void Pipeline::VerifyAndPrintGraph(
} }
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 { class AstGraphBuilderWithPositions : public AstGraphBuilder {
public: public:
explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info,
...@@ -190,7 +166,8 @@ Handle<Code> Pipeline::GenerateCode() { ...@@ -190,7 +166,8 @@ Handle<Code> Pipeline::GenerateCode() {
<< "Begin compiling method " << "Begin compiling method "
<< info()->function()->debug_name()->ToCString().get() << info()->function()->debug_name()->ToCString().get()
<< " using Turbofan" << std::endl; << " using Turbofan" << std::endl;
PrintCompilationStart(); TurboCfgFile tcf(isolate());
tcf << AsC1VCompilation(info());
} }
// Build the graph. // Build the graph.
...@@ -448,8 +425,8 @@ Handle<Code> Pipeline::GenerateCode(PipelineStatistics* pipeline_statistics, ...@@ -448,8 +425,8 @@ Handle<Code> Pipeline::GenerateCode(PipelineStatistics* pipeline_statistics,
OFStream os(stdout); OFStream os(stdout);
os << "----- Instruction sequence before register allocation -----\n" os << "----- Instruction sequence before register allocation -----\n"
<< sequence; << sequence;
PrintScheduleAndInstructions("CodeGen", schedule, source_positions, TurboCfgFile tcf(isolate());
&sequence); tcf << AsC1V("CodeGen", schedule, source_positions, &sequence);
} }
// Allocate registers. // Allocate registers.
...@@ -468,7 +445,8 @@ Handle<Code> Pipeline::GenerateCode(PipelineStatistics* pipeline_statistics, ...@@ -468,7 +445,8 @@ Handle<Code> Pipeline::GenerateCode(PipelineStatistics* pipeline_statistics,
return Handle<Code>::null(); return Handle<Code>::null();
} }
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
PrintAllocator("CodeGen", &allocator); TurboCfgFile tcf(isolate());
tcf << AsC1VAllocator("CodeGen", &allocator);
} }
} }
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#ifndef V8_COMPILER_PIPELINE_H_ #ifndef V8_COMPILER_PIPELINE_H_
#define V8_COMPILER_PIPELINE_H_ #define V8_COMPILER_PIPELINE_H_
#include <fstream> // NOLINT(readability/streams)
#include "src/v8.h" #include "src/v8.h"
#include "src/compiler.h" #include "src/compiler.h"
...@@ -54,12 +52,6 @@ class Pipeline { ...@@ -54,12 +52,6 @@ class Pipeline {
Zone* zone() { return info_->zone(); } Zone* zone() { return info_->zone(); }
Schedule* ComputeSchedule(ZonePool* zone_pool, Graph* graph); Schedule* ComputeSchedule(ZonePool* zone_pool, 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, void VerifyAndPrintGraph(Graph* graph, const char* phase,
bool untyped = false); bool untyped = false);
Handle<Code> GenerateCode(PipelineStatistics* pipeline_statistics, Handle<Code> GenerateCode(PipelineStatistics* pipeline_statistics,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <fstream> // NOLINT(readability/streams) #include <fstream> // NOLINT(readability/streams)
#include <iostream> // NOLINT(readability/streams) #include <iostream> // NOLINT(readability/streams)
#include <sstream>
#include "src/v8.h" #include "src/v8.h"
...@@ -1955,12 +1956,8 @@ bool Isolate::Init(Deserializer* des) { ...@@ -1955,12 +1956,8 @@ bool Isolate::Init(Deserializer* des) {
if (!create_heap_objects) Assembler::QuietNaN(heap_.nan_value()); if (!create_heap_objects) Assembler::QuietNaN(heap_.nan_value());
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
// Erase the file. // Create an empty file.
char buffer[512]; std::ofstream(GetTurboCfgFileName().c_str(), std::ios_base::trunc);
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 // If we are deserializing, log non-function code objects and compiled
...@@ -2377,12 +2374,13 @@ BasicBlockProfiler* Isolate::GetOrCreateBasicBlockProfiler() { ...@@ -2377,12 +2374,13 @@ BasicBlockProfiler* Isolate::GetOrCreateBasicBlockProfiler() {
} }
void Isolate::GetTurboCfgFileName(Vector<char> filename) { std::string Isolate::GetTurboCfgFileName() {
if (FLAG_trace_turbo_cfg_file == NULL) { if (FLAG_trace_turbo_cfg_file == NULL) {
SNPrintF(filename, "turbo-%d-%d.cfg", base::OS::GetCurrentProcessId(), std::ostringstream os;
id()); os << "turbo-" << base::OS::GetCurrentProcessId() << "-" << id() << ".cfg";
return os.str();
} else { } else {
StrNCpy(filename, FLAG_trace_turbo_cfg_file, filename.length()); return FLAG_trace_turbo_cfg_file;
} }
} }
......
...@@ -1099,7 +1099,7 @@ class Isolate { ...@@ -1099,7 +1099,7 @@ class Isolate {
static Isolate* NewForTesting() { return new Isolate(false); } static Isolate* NewForTesting() { return new Isolate(false); }
void GetTurboCfgFileName(Vector<char> buffer); std::string GetTurboCfgFileName();
private: private:
explicit Isolate(bool enable_serializer); 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