| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/pipeline.h" | 5 #include "src/compiler/pipeline.h" |
| 6 | 6 |
| 7 #include <fstream> // NOLINT(readability/streams) | 7 #include <fstream> // NOLINT(readability/streams) |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "src/ostreams.h" | 47 #include "src/ostreams.h" |
| 48 #include "src/utils.h" | 48 #include "src/utils.h" |
| 49 | 49 |
| 50 namespace v8 { | 50 namespace v8 { |
| 51 namespace internal { | 51 namespace internal { |
| 52 namespace compiler { | 52 namespace compiler { |
| 53 | 53 |
| 54 class PipelineData { | 54 class PipelineData { |
| 55 public: | 55 public: |
| 56 explicit PipelineData(ZonePool* zone_pool, CompilationInfo* info) | 56 explicit PipelineData(ZonePool* zone_pool, CompilationInfo* info) |
| 57 : isolate_(info->zone()->isolate()), | 57 : isolate_(info->isolate()), |
| 58 info_(info), | 58 info_(info), |
| 59 outer_zone_(nullptr), | 59 outer_zone_(nullptr), |
| 60 zone_pool_(zone_pool), | 60 zone_pool_(zone_pool), |
| 61 pipeline_statistics_(nullptr), | 61 pipeline_statistics_(nullptr), |
| 62 compilation_failed_(false), | 62 compilation_failed_(false), |
| 63 code_(Handle<Code>::null()), | 63 code_(Handle<Code>::null()), |
| 64 graph_zone_scope_(zone_pool_), | 64 graph_zone_scope_(zone_pool_), |
| 65 graph_zone_(nullptr), | 65 graph_zone_(nullptr), |
| 66 graph_(nullptr), | 66 graph_(nullptr), |
| 67 loop_assignment_(nullptr), | 67 loop_assignment_(nullptr), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 89 outer_zone_ = info()->zone(); | 89 outer_zone_ = info()->zone(); |
| 90 pipeline_statistics_ = pipeline_statistics; | 90 pipeline_statistics_ = pipeline_statistics; |
| 91 graph_zone_ = graph_zone_scope_.zone(); | 91 graph_zone_ = graph_zone_scope_.zone(); |
| 92 graph_ = new (graph_zone()) Graph(graph_zone()); | 92 graph_ = new (graph_zone()) Graph(graph_zone()); |
| 93 source_positions_.Reset(new SourcePositionTable(graph())); | 93 source_positions_.Reset(new SourcePositionTable(graph())); |
| 94 machine_ = new (graph_zone()) MachineOperatorBuilder( | 94 machine_ = new (graph_zone()) MachineOperatorBuilder( |
| 95 graph_zone(), kMachPtr, | 95 graph_zone(), kMachPtr, |
| 96 InstructionSelector::SupportedMachineOperatorFlags()); | 96 InstructionSelector::SupportedMachineOperatorFlags()); |
| 97 common_ = new (graph_zone()) CommonOperatorBuilder(graph_zone()); | 97 common_ = new (graph_zone()) CommonOperatorBuilder(graph_zone()); |
| 98 javascript_ = new (graph_zone()) JSOperatorBuilder(graph_zone()); | 98 javascript_ = new (graph_zone()) JSOperatorBuilder(graph_zone()); |
| 99 jsgraph_ = | 99 jsgraph_ = new (graph_zone()) |
| 100 new (graph_zone()) JSGraph(graph(), common(), javascript(), machine()); | 100 JSGraph(info()->isolate(), graph(), common(), javascript(), machine()); |
| 101 typer_.Reset(new Typer(graph(), info()->context())); | 101 typer_.Reset(new Typer(info()->isolate(), graph(), info()->context())); |
| 102 instruction_zone_ = instruction_zone_scope_.zone(); | 102 instruction_zone_ = instruction_zone_scope_.zone(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // For machine graph testing entry point. | 105 // For machine graph testing entry point. |
| 106 void InitializeTorTesting(Graph* graph, Schedule* schedule) { | 106 void InitializeTorTesting(Graph* graph, Schedule* schedule) { |
| 107 graph_ = graph; | 107 graph_ = graph; |
| 108 source_positions_.Reset(new SourcePositionTable(graph)); | 108 source_positions_.Reset(new SourcePositionTable(graph)); |
| 109 schedule_ = schedule; | 109 schedule_ = schedule; |
| 110 instruction_zone_ = instruction_zone_scope_.zone(); | 110 instruction_zone_ = instruction_zone_scope_.zone(); |
| 111 } | 111 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 sequence_ = nullptr; | 190 sequence_ = nullptr; |
| 191 frame_ = nullptr; | 191 frame_ = nullptr; |
| 192 register_allocator_ = nullptr; | 192 register_allocator_ = nullptr; |
| 193 } | 193 } |
| 194 | 194 |
| 195 void InitializeInstructionSequence() { | 195 void InitializeInstructionSequence() { |
| 196 DCHECK_EQ(nullptr, sequence_); | 196 DCHECK_EQ(nullptr, sequence_); |
| 197 InstructionBlocks* instruction_blocks = | 197 InstructionBlocks* instruction_blocks = |
| 198 InstructionSequence::InstructionBlocksFor(instruction_zone(), | 198 InstructionSequence::InstructionBlocksFor(instruction_zone(), |
| 199 schedule()); | 199 schedule()); |
| 200 sequence_ = new (instruction_zone()) | 200 sequence_ = new (instruction_zone()) InstructionSequence( |
| 201 InstructionSequence(instruction_zone(), instruction_blocks); | 201 info()->isolate(), instruction_zone(), instruction_blocks); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void InitializeRegisterAllocator(Zone* local_zone, | 204 void InitializeRegisterAllocator(Zone* local_zone, |
| 205 const RegisterConfiguration* config, | 205 const RegisterConfiguration* config, |
| 206 const char* debug_name) { | 206 const char* debug_name) { |
| 207 DCHECK_EQ(nullptr, register_allocator_); | 207 DCHECK_EQ(nullptr, register_allocator_); |
| 208 DCHECK_EQ(nullptr, frame_); | 208 DCHECK_EQ(nullptr, frame_); |
| 209 frame_ = new (instruction_zone()) Frame(); | 209 frame_ = new (instruction_zone()) Frame(); |
| 210 register_allocator_ = new (instruction_zone()) | 210 register_allocator_ = new (instruction_zone()) |
| 211 RegisterAllocator(config, local_zone, frame(), sequence(), debug_name); | 211 RegisterAllocator(config, local_zone, frame(), sequence(), debug_name); |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 // the correct solution is to restore the context register after invoking | 778 // the correct solution is to restore the context register after invoking |
| 779 // builtins from full-codegen. | 779 // builtins from full-codegen. |
| 780 Handle<SharedFunctionInfo> shared = info()->shared_info(); | 780 Handle<SharedFunctionInfo> shared = info()->shared_info(); |
| 781 if (isolate()->bootstrapper()->IsActive() || | 781 if (isolate()->bootstrapper()->IsActive() || |
| 782 shared->disable_optimization_reason() == | 782 shared->disable_optimization_reason() == |
| 783 kBuiltinFunctionCannotBeOptimized) { | 783 kBuiltinFunctionCannotBeOptimized) { |
| 784 shared->DisableOptimization(kBuiltinFunctionCannotBeOptimized); | 784 shared->DisableOptimization(kBuiltinFunctionCannotBeOptimized); |
| 785 return Handle<Code>::null(); | 785 return Handle<Code>::null(); |
| 786 } | 786 } |
| 787 | 787 |
| 788 ZonePool zone_pool(isolate()); | 788 ZonePool zone_pool; |
| 789 SmartPointer<PipelineStatistics> pipeline_statistics; | 789 SmartPointer<PipelineStatistics> pipeline_statistics; |
| 790 | 790 |
| 791 if (FLAG_turbo_stats) { | 791 if (FLAG_turbo_stats) { |
| 792 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); | 792 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); |
| 793 pipeline_statistics->BeginPhaseKind("initializing"); | 793 pipeline_statistics->BeginPhaseKind("initializing"); |
| 794 } | 794 } |
| 795 | 795 |
| 796 PipelineData data(&zone_pool, info()); | 796 PipelineData data(&zone_pool, info()); |
| 797 this->data_ = &data; | 797 this->data_ = &data; |
| 798 data.Initialize(pipeline_statistics.get()); | 798 data.Initialize(pipeline_statistics.get()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 | 917 |
| 918 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, | 918 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
| 919 Graph* graph, | 919 Graph* graph, |
| 920 Schedule* schedule) { | 920 Schedule* schedule) { |
| 921 CallDescriptor* call_descriptor = | 921 CallDescriptor* call_descriptor = |
| 922 Linkage::ComputeIncoming(info->zone(), info); | 922 Linkage::ComputeIncoming(info->zone(), info); |
| 923 return GenerateCodeForTesting(info, call_descriptor, graph, schedule); | 923 return GenerateCodeForTesting(info, call_descriptor, graph, schedule); |
| 924 } | 924 } |
| 925 | 925 |
| 926 | 926 |
| 927 Handle<Code> Pipeline::GenerateCodeForTesting(CallDescriptor* call_descriptor, | 927 Handle<Code> Pipeline::GenerateCodeForTesting(Isolate* isolate, |
| 928 CallDescriptor* call_descriptor, |
| 928 Graph* graph, | 929 Graph* graph, |
| 929 Schedule* schedule) { | 930 Schedule* schedule) { |
| 930 CompilationInfo info(graph->zone()->isolate(), graph->zone()); | 931 CompilationInfo info(isolate, graph->zone()); |
| 931 return GenerateCodeForTesting(&info, call_descriptor, graph, schedule); | 932 return GenerateCodeForTesting(&info, call_descriptor, graph, schedule); |
| 932 } | 933 } |
| 933 | 934 |
| 934 | 935 |
| 935 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, | 936 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
| 936 CallDescriptor* call_descriptor, | 937 CallDescriptor* call_descriptor, |
| 937 Graph* graph, | 938 Graph* graph, |
| 938 Schedule* schedule) { | 939 Schedule* schedule) { |
| 939 CHECK(SupportedBackend()); | 940 CHECK(SupportedBackend()); |
| 940 ZonePool zone_pool(info->isolate()); | 941 ZonePool zone_pool; |
| 941 Pipeline pipeline(info); | 942 Pipeline pipeline(info); |
| 942 PipelineData data(&zone_pool, info); | 943 PipelineData data(&zone_pool, info); |
| 943 pipeline.data_ = &data; | 944 pipeline.data_ = &data; |
| 944 data.InitializeTorTesting(graph, schedule); | 945 data.InitializeTorTesting(graph, schedule); |
| 945 if (schedule == NULL) { | 946 if (schedule == NULL) { |
| 946 // TODO(rossberg): Should this really be untyped? | 947 // TODO(rossberg): Should this really be untyped? |
| 947 pipeline.RunPrintAndVerify("Machine", true); | 948 pipeline.RunPrintAndVerify("Machine", true); |
| 948 pipeline.Run<ComputeSchedulePhase>(); | 949 pipeline.Run<ComputeSchedulePhase>(); |
| 949 } else { | 950 } else { |
| 950 TraceSchedule(schedule); | 951 TraceSchedule(schedule); |
| 951 } | 952 } |
| 952 | 953 |
| 953 Linkage linkage(info->zone(), call_descriptor); | 954 Linkage linkage(info->isolate(), info->zone(), call_descriptor); |
| 954 pipeline.GenerateCode(&linkage); | 955 pipeline.GenerateCode(&linkage); |
| 955 Handle<Code> code = data.code(); | 956 Handle<Code> code = data.code(); |
| 956 | 957 |
| 957 #if ENABLE_DISASSEMBLER | 958 #if ENABLE_DISASSEMBLER |
| 958 if (!code.is_null() && FLAG_print_opt_code) { | 959 if (!code.is_null() && FLAG_print_opt_code) { |
| 959 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); | 960 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); |
| 960 OFStream os(tracing_scope.file()); | 961 OFStream os(tracing_scope.file()); |
| 961 code->Disassemble("test code", os); | 962 code->Disassemble("test code", os); |
| 962 } | 963 } |
| 963 #endif | 964 #endif |
| 964 return code; | 965 return code; |
| 965 } | 966 } |
| 966 | 967 |
| 967 | 968 |
| 968 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, | 969 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, |
| 969 InstructionSequence* sequence, | 970 InstructionSequence* sequence, |
| 970 bool run_verifier) { | 971 bool run_verifier) { |
| 971 CompilationInfo info(sequence->zone()->isolate(), sequence->zone()); | 972 CompilationInfo info(sequence->isolate(), sequence->zone()); |
| 972 ZonePool zone_pool(sequence->zone()->isolate()); | 973 ZonePool zone_pool; |
| 973 PipelineData data(&zone_pool, &info); | 974 PipelineData data(&zone_pool, &info); |
| 974 data.InitializeTorTesting(sequence); | 975 data.InitializeTorTesting(sequence); |
| 975 Pipeline pipeline(&info); | 976 Pipeline pipeline(&info); |
| 976 pipeline.data_ = &data; | 977 pipeline.data_ = &data; |
| 977 pipeline.AllocateRegisters(config, run_verifier); | 978 pipeline.AllocateRegisters(config, run_verifier); |
| 978 return !data.compilation_failed(); | 979 return !data.compilation_failed(); |
| 979 } | 980 } |
| 980 | 981 |
| 981 | 982 |
| 982 void Pipeline::GenerateCode(Linkage* linkage) { | 983 void Pipeline::GenerateCode(Linkage* linkage) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 | 1038 |
| 1038 | 1039 |
| 1039 void Pipeline::AllocateRegisters(const RegisterConfiguration* config, | 1040 void Pipeline::AllocateRegisters(const RegisterConfiguration* config, |
| 1040 bool run_verifier) { | 1041 bool run_verifier) { |
| 1041 PipelineData* data = this->data_; | 1042 PipelineData* data = this->data_; |
| 1042 | 1043 |
| 1043 // Don't track usage for this zone in compiler stats. | 1044 // Don't track usage for this zone in compiler stats. |
| 1044 SmartPointer<Zone> verifier_zone; | 1045 SmartPointer<Zone> verifier_zone; |
| 1045 RegisterAllocatorVerifier* verifier = nullptr; | 1046 RegisterAllocatorVerifier* verifier = nullptr; |
| 1046 if (run_verifier) { | 1047 if (run_verifier) { |
| 1047 verifier_zone.Reset(new Zone(info()->isolate())); | 1048 verifier_zone.Reset(new Zone()); |
| 1048 verifier = new (verifier_zone.get()) RegisterAllocatorVerifier( | 1049 verifier = new (verifier_zone.get()) RegisterAllocatorVerifier( |
| 1049 verifier_zone.get(), config, data->sequence()); | 1050 verifier_zone.get(), config, data->sequence()); |
| 1050 } | 1051 } |
| 1051 | 1052 |
| 1052 SmartArrayPointer<char> debug_name; | 1053 SmartArrayPointer<char> debug_name; |
| 1053 #ifdef DEBUG | 1054 #ifdef DEBUG |
| 1054 debug_name = GetDebugName(data->info()); | 1055 debug_name = GetDebugName(data->info()); |
| 1055 #endif | 1056 #endif |
| 1056 | 1057 |
| 1057 ZonePool::Scope zone_scope(data->zone_pool()); | 1058 ZonePool::Scope zone_scope(data->zone_pool()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 } | 1111 } |
| 1111 | 1112 |
| 1112 | 1113 |
| 1113 void Pipeline::TearDown() { | 1114 void Pipeline::TearDown() { |
| 1114 InstructionOperand::TearDownCaches(); | 1115 InstructionOperand::TearDownCaches(); |
| 1115 } | 1116 } |
| 1116 | 1117 |
| 1117 } // namespace compiler | 1118 } // namespace compiler |
| 1118 } // namespace internal | 1119 } // namespace internal |
| 1119 } // namespace v8 | 1120 } // namespace v8 |
| OLD | NEW |