From: svenpanne@chromium.org Date: Thu, 23 Oct 2014 07:26:13 +0000 (+0000) Subject: Simplify TurboFan's c1visualizer file handling. X-Git-Tag: upstream/4.7.83~6174 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c5a8743a1bbc7dea32c415019f492f19ab7871e7;p=platform%2Fupstream%2Fv8.git Simplify TurboFan's c1visualizer file handling. Still having GetTurboCfgFileName in Isolate is ugly, but if we decide that we don't want to truncate the output file (which would be consistent with --trace-hydrogen), this could be moved to TurboCfgFile where it actually belongs. R=bmeurer@chromium.org Review URL: https://codereview.chromium.org/666223003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24819 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index 438f104..f050c9b 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -4,6 +4,7 @@ #include "src/compiler/pipeline.h" +#include // NOLINT(readability/streams) #include #include "src/base/platform/elapsed-timer.h" @@ -97,19 +98,10 @@ 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 filename(buffer, sizeof(buffer)); - isolate()->GetTurboCfgFileName(filename); - stream->open(filename.start(), std::fstream::out | std::fstream::app); -} +struct TurboCfgFile : public std::ofstream { + explicit TurboCfgFile(Isolate* isolate) + : std::ofstream(isolate->GetTurboCfgFileName(), std::ios_base::app) {} +}; void Pipeline::VerifyAndPrintGraph( @@ -158,24 +150,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 { public: explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, @@ -234,7 +208,7 @@ Handle Pipeline::GenerateCode() { << "Begin compiling method " << info()->function()->debug_name()->ToCString().get() << " using Turbofan" << std::endl; - PrintCompilationStart(); + TurboCfgFile(isolate()) << AsC1VCompilation(info()); } ZonePool zone_pool(isolate()); @@ -487,8 +461,8 @@ Handle Pipeline::GenerateCode(ZonePool* zone_pool, Linkage* linkage, OFStream os(stdout); os << "----- Instruction sequence before register allocation -----\n" << sequence; - PrintScheduleAndInstructions("CodeGen", schedule, source_positions, - &sequence); + TurboCfgFile(isolate()) + << AsC1V("CodeGen", schedule, source_positions, &sequence); } // Allocate registers. @@ -507,7 +481,7 @@ Handle Pipeline::GenerateCode(ZonePool* zone_pool, Linkage* linkage, return Handle::null(); } if (FLAG_trace_turbo) { - PrintAllocator("CodeGen", &allocator); + TurboCfgFile(isolate()) << AsC1VAllocator("CodeGen", &allocator); } } diff --git a/src/compiler/pipeline.h b/src/compiler/pipeline.h index 87c22a6..cf4fa5e 100644 --- a/src/compiler/pipeline.h +++ b/src/compiler/pipeline.h @@ -5,8 +5,6 @@ #ifndef V8_COMPILER_PIPELINE_H_ #define V8_COMPILER_PIPELINE_H_ -#include // NOLINT(readability/streams) - #include "src/v8.h" #include "src/compiler.h" @@ -53,12 +51,6 @@ class Pipeline { Zone* zone() { return info_->zone(); } 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, bool untyped = false); Handle GenerateCode(ZonePool* zone_pool, Linkage* linkage, Graph* graph, diff --git a/src/isolate.cc b/src/isolate.cc index 6caaf19..152c936 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -1951,12 +1951,8 @@ bool Isolate::Init(Deserializer* des) { if (!create_heap_objects) Assembler::QuietNaN(heap_.nan_value()); if (FLAG_trace_turbo) { - // Erase the file. - char buffer[512]; - Vector filename(buffer, sizeof(buffer)); - GetTurboCfgFileName(filename); - std::ofstream turbo_cfg_stream(filename.start(), - std::fstream::out | std::fstream::trunc); + // Create an empty file. + std::ofstream(GetTurboCfgFileName(), std::ios_base::trunc); } // If we are deserializing, log non-function code objects and compiled @@ -2372,13 +2368,11 @@ BasicBlockProfiler* Isolate::GetOrCreateBasicBlockProfiler() { } -void Isolate::GetTurboCfgFileName(Vector 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()); - } +std::string Isolate::GetTurboCfgFileName() { + return FLAG_trace_turbo_cfg_file == NULL + ? "turbo-" + std::to_string(base::OS::GetCurrentProcessId()) + + "-" + std::to_string(id()) + ".cfg" + : FLAG_trace_turbo_cfg_file; } diff --git a/src/isolate.h b/src/isolate.h index 55d139c..854bce4 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -1098,7 +1098,7 @@ class Isolate { static Isolate* NewForTesting() { return new Isolate(false); } - void GetTurboCfgFileName(Vector buffer); + std::string GetTurboCfgFileName(); private: explicit Isolate(bool enable_serializer);