Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/compiler/pipeline.h" |
| 6 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7 | #include <fstream> // NOLINT(readability/streams) |
| 8 | #include <sstream> |
| 9 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | #include "src/base/adapters.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/base/platform/elapsed-timer.h" |
| 12 | #include "src/compiler/ast-graph-builder.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 13 | #include "src/compiler/ast-loop-assignment-analyzer.h" |
| 14 | #include "src/compiler/basic-block-instrumentor.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 15 | #include "src/compiler/branch-elimination.h" |
| 16 | #include "src/compiler/bytecode-graph-builder.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 17 | #include "src/compiler/code-generator.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 18 | #include "src/compiler/common-operator-reducer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 19 | #include "src/compiler/control-flow-optimizer.h" |
| 20 | #include "src/compiler/dead-code-elimination.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 21 | #include "src/compiler/effect-control-linearizer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | #include "src/compiler/escape-analysis-reducer.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 23 | #include "src/compiler/escape-analysis.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | #include "src/compiler/frame-elider.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 25 | #include "src/compiler/graph-replay.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 26 | #include "src/compiler/graph-trimmer.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | #include "src/compiler/graph-visualizer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | #include "src/compiler/greedy-allocator.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 29 | #include "src/compiler/instruction-selector.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 30 | #include "src/compiler/instruction.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 31 | #include "src/compiler/js-builtin-reducer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 32 | #include "src/compiler/js-call-reducer.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 33 | #include "src/compiler/js-context-specialization.h" |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 34 | #include "src/compiler/js-create-lowering.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 35 | #include "src/compiler/js-frame-specialization.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 36 | #include "src/compiler/js-generic-lowering.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 37 | #include "src/compiler/js-global-object-specialization.h" |
| 38 | #include "src/compiler/js-inlining-heuristic.h" |
| 39 | #include "src/compiler/js-intrinsic-lowering.h" |
| 40 | #include "src/compiler/js-native-context-specialization.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 41 | #include "src/compiler/js-typed-lowering.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 42 | #include "src/compiler/jump-threading.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | #include "src/compiler/live-range-separator.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 44 | #include "src/compiler/load-elimination.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 45 | #include "src/compiler/loop-analysis.h" |
| 46 | #include "src/compiler/loop-peeling.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 47 | #include "src/compiler/machine-operator-reducer.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 48 | #include "src/compiler/memory-optimizer.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 49 | #include "src/compiler/move-optimizer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | #include "src/compiler/osr.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 51 | #include "src/compiler/pipeline-statistics.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 52 | #include "src/compiler/register-allocator-verifier.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 53 | #include "src/compiler/register-allocator.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 54 | #include "src/compiler/schedule.h" |
| 55 | #include "src/compiler/scheduler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 56 | #include "src/compiler/select-lowering.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | #include "src/compiler/simplified-lowering.h" |
| 58 | #include "src/compiler/simplified-operator-reducer.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 59 | #include "src/compiler/simplified-operator.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 60 | #include "src/compiler/tail-call-optimization.h" |
| 61 | #include "src/compiler/type-hint-analyzer.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 62 | #include "src/compiler/typer.h" |
| 63 | #include "src/compiler/value-numbering-reducer.h" |
| 64 | #include "src/compiler/verifier.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 65 | #include "src/compiler/zone-pool.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 66 | #include "src/isolate-inl.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | #include "src/ostreams.h" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 68 | #include "src/parsing/parser.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 69 | #include "src/register-configuration.h" |
| 70 | #include "src/type-info.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | #include "src/utils.h" |
| 72 | |
| 73 | namespace v8 { |
| 74 | namespace internal { |
| 75 | namespace compiler { |
| 76 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 77 | class PipelineData { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 78 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 79 | // For main entry point. |
| 80 | PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
| 81 | PipelineStatistics* pipeline_statistics) |
| 82 | : isolate_(info->isolate()), |
| 83 | info_(info), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 84 | debug_name_(info_->GetDebugName()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 85 | outer_zone_(info_->zone()), |
| 86 | zone_pool_(zone_pool), |
| 87 | pipeline_statistics_(pipeline_statistics), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 88 | graph_zone_scope_(zone_pool_), |
| 89 | graph_zone_(graph_zone_scope_.zone()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 90 | instruction_zone_scope_(zone_pool_), |
| 91 | instruction_zone_(instruction_zone_scope_.zone()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 92 | register_allocation_zone_scope_(zone_pool_), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 93 | register_allocation_zone_(register_allocation_zone_scope_.zone()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 94 | PhaseScope scope(pipeline_statistics, "init pipeline data"); |
| 95 | graph_ = new (graph_zone_) Graph(graph_zone_); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 96 | source_positions_ = new (graph_zone_) SourcePositionTable(graph_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 97 | simplified_ = new (graph_zone_) SimplifiedOperatorBuilder(graph_zone_); |
| 98 | machine_ = new (graph_zone_) MachineOperatorBuilder( |
| 99 | graph_zone_, MachineType::PointerRepresentation(), |
| 100 | InstructionSelector::SupportedMachineOperatorFlags()); |
| 101 | common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); |
| 102 | javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); |
| 103 | jsgraph_ = new (graph_zone_) |
| 104 | JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_); |
| 105 | } |
| 106 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 107 | // For WASM compile entry point. |
| 108 | PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, |
| 109 | SourcePositionTable* source_positions) |
| 110 | : isolate_(info->isolate()), |
| 111 | info_(info), |
| 112 | debug_name_(info_->GetDebugName()), |
| 113 | zone_pool_(zone_pool), |
| 114 | graph_zone_scope_(zone_pool_), |
| 115 | graph_(graph), |
| 116 | source_positions_(source_positions), |
| 117 | instruction_zone_scope_(zone_pool_), |
| 118 | instruction_zone_(instruction_zone_scope_.zone()), |
| 119 | register_allocation_zone_scope_(zone_pool_), |
| 120 | register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
| 121 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 122 | // For machine graph testing entry point. |
| 123 | PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, |
| 124 | Schedule* schedule) |
| 125 | : isolate_(info->isolate()), |
| 126 | info_(info), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 127 | debug_name_(info_->GetDebugName()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 128 | zone_pool_(zone_pool), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 129 | graph_zone_scope_(zone_pool_), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 130 | graph_(graph), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 131 | source_positions_(new (info->zone()) SourcePositionTable(graph_)), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 132 | schedule_(schedule), |
| 133 | instruction_zone_scope_(zone_pool_), |
| 134 | instruction_zone_(instruction_zone_scope_.zone()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 135 | register_allocation_zone_scope_(zone_pool_), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 136 | register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 137 | |
| 138 | // For register allocation testing entry point. |
| 139 | PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
| 140 | InstructionSequence* sequence) |
| 141 | : isolate_(info->isolate()), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 142 | info_(info), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 143 | debug_name_(info_->GetDebugName()), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 144 | zone_pool_(zone_pool), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 145 | graph_zone_scope_(zone_pool_), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 146 | instruction_zone_scope_(zone_pool_), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 147 | instruction_zone_(sequence->zone()), |
| 148 | sequence_(sequence), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 149 | register_allocation_zone_scope_(zone_pool_), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 150 | register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 151 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 152 | ~PipelineData() { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 153 | DeleteRegisterAllocationZone(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 154 | DeleteInstructionZone(); |
| 155 | DeleteGraphZone(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 158 | Isolate* isolate() const { return isolate_; } |
| 159 | CompilationInfo* info() const { return info_; } |
| 160 | ZonePool* zone_pool() const { return zone_pool_; } |
| 161 | PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } |
| 162 | bool compilation_failed() const { return compilation_failed_; } |
| 163 | void set_compilation_failed() { compilation_failed_ = true; } |
| 164 | Handle<Code> code() { return code_; } |
| 165 | void set_code(Handle<Code> code) { |
| 166 | DCHECK(code_.is_null()); |
| 167 | code_ = code; |
| 168 | } |
| 169 | |
| 170 | // RawMachineAssembler generally produces graphs which cannot be verified. |
| 171 | bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } |
| 172 | |
| 173 | Zone* graph_zone() const { return graph_zone_; } |
| 174 | Graph* graph() const { return graph_; } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 175 | SourcePositionTable* source_positions() const { return source_positions_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 176 | MachineOperatorBuilder* machine() const { return machine_; } |
| 177 | CommonOperatorBuilder* common() const { return common_; } |
| 178 | JSOperatorBuilder* javascript() const { return javascript_; } |
| 179 | JSGraph* jsgraph() const { return jsgraph_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 180 | MaybeHandle<Context> native_context() const { |
| 181 | if (info()->is_native_context_specializing()) { |
| 182 | return handle(info()->native_context(), isolate()); |
| 183 | } |
| 184 | return MaybeHandle<Context>(); |
| 185 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 186 | |
| 187 | LoopAssignmentAnalysis* loop_assignment() const { return loop_assignment_; } |
| 188 | void set_loop_assignment(LoopAssignmentAnalysis* loop_assignment) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 189 | DCHECK(!loop_assignment_); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 190 | loop_assignment_ = loop_assignment; |
| 191 | } |
| 192 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 193 | TypeHintAnalysis* type_hint_analysis() const { return type_hint_analysis_; } |
| 194 | void set_type_hint_analysis(TypeHintAnalysis* type_hint_analysis) { |
| 195 | DCHECK_NULL(type_hint_analysis_); |
| 196 | type_hint_analysis_ = type_hint_analysis; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | Schedule* schedule() const { return schedule_; } |
| 200 | void set_schedule(Schedule* schedule) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 201 | DCHECK(!schedule_); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 202 | schedule_ = schedule; |
| 203 | } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 204 | void reset_schedule() { schedule_ = nullptr; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 205 | |
| 206 | Zone* instruction_zone() const { return instruction_zone_; } |
| 207 | InstructionSequence* sequence() const { return sequence_; } |
| 208 | Frame* frame() const { return frame_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 209 | |
| 210 | Zone* register_allocation_zone() const { return register_allocation_zone_; } |
| 211 | RegisterAllocationData* register_allocation_data() const { |
| 212 | return register_allocation_data_; |
| 213 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 214 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 215 | BasicBlockProfiler::Data* profiler_data() const { return profiler_data_; } |
| 216 | void set_profiler_data(BasicBlockProfiler::Data* profiler_data) { |
| 217 | profiler_data_ = profiler_data; |
| 218 | } |
| 219 | |
| 220 | std::string const& source_position_output() const { |
| 221 | return source_position_output_; |
| 222 | } |
| 223 | void set_source_position_output(std::string const& source_position_output) { |
| 224 | source_position_output_ = source_position_output; |
| 225 | } |
| 226 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 227 | void DeleteGraphZone() { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 228 | if (graph_zone_ == nullptr) return; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 229 | graph_zone_scope_.Destroy(); |
| 230 | graph_zone_ = nullptr; |
| 231 | graph_ = nullptr; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 232 | source_positions_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 233 | loop_assignment_ = nullptr; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 234 | type_hint_analysis_ = nullptr; |
| 235 | simplified_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 236 | machine_ = nullptr; |
| 237 | common_ = nullptr; |
| 238 | javascript_ = nullptr; |
| 239 | jsgraph_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 240 | schedule_ = nullptr; |
| 241 | } |
| 242 | |
| 243 | void DeleteInstructionZone() { |
| 244 | if (instruction_zone_ == nullptr) return; |
| 245 | instruction_zone_scope_.Destroy(); |
| 246 | instruction_zone_ = nullptr; |
| 247 | sequence_ = nullptr; |
| 248 | frame_ = nullptr; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void DeleteRegisterAllocationZone() { |
| 252 | if (register_allocation_zone_ == nullptr) return; |
| 253 | register_allocation_zone_scope_.Destroy(); |
| 254 | register_allocation_zone_ = nullptr; |
| 255 | register_allocation_data_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 258 | void InitializeInstructionSequence(const CallDescriptor* descriptor) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 259 | DCHECK(sequence_ == nullptr); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 260 | InstructionBlocks* instruction_blocks = |
| 261 | InstructionSequence::InstructionBlocksFor(instruction_zone(), |
| 262 | schedule()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 263 | sequence_ = new (instruction_zone()) InstructionSequence( |
| 264 | info()->isolate(), instruction_zone(), instruction_blocks); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 265 | if (descriptor && descriptor->RequiresFrameAsIncoming()) { |
| 266 | sequence_->instruction_blocks()[0]->mark_needs_frame(); |
| 267 | } else { |
| 268 | DCHECK_EQ(0, descriptor->CalleeSavedFPRegisters()); |
| 269 | DCHECK_EQ(0, descriptor->CalleeSavedRegisters()); |
| 270 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 273 | void InitializeFrameData(CallDescriptor* descriptor) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 274 | DCHECK(frame_ == nullptr); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 275 | int fixed_frame_size = 0; |
| 276 | if (descriptor != nullptr) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 277 | fixed_frame_size = CalculateFixedFrameSize(descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 278 | } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 279 | frame_ = new (instruction_zone()) Frame(fixed_frame_size); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | void InitializeRegisterAllocationData(const RegisterConfiguration* config, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 283 | CallDescriptor* descriptor) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 284 | DCHECK(register_allocation_data_ == nullptr); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 285 | register_allocation_data_ = new (register_allocation_zone()) |
| 286 | RegisterAllocationData(config, register_allocation_zone(), frame(), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 287 | sequence(), debug_name_.get()); |
| 288 | } |
| 289 | |
| 290 | void BeginPhaseKind(const char* phase_kind_name) { |
| 291 | if (pipeline_statistics() != nullptr) { |
| 292 | pipeline_statistics()->BeginPhaseKind(phase_kind_name); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | void EndPhaseKind() { |
| 297 | if (pipeline_statistics() != nullptr) { |
| 298 | pipeline_statistics()->EndPhaseKind(); |
| 299 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | private: |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 303 | Isolate* const isolate_; |
| 304 | CompilationInfo* const info_; |
| 305 | base::SmartArrayPointer<char> debug_name_; |
| 306 | Zone* outer_zone_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 307 | ZonePool* const zone_pool_; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 308 | PipelineStatistics* pipeline_statistics_ = nullptr; |
| 309 | bool compilation_failed_ = false; |
| 310 | Handle<Code> code_ = Handle<Code>::null(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 311 | |
| 312 | // All objects in the following group of fields are allocated in graph_zone_. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 313 | // They are all set to nullptr when the graph_zone_ is destroyed. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 314 | ZonePool::Scope graph_zone_scope_; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 315 | Zone* graph_zone_ = nullptr; |
| 316 | Graph* graph_ = nullptr; |
| 317 | SourcePositionTable* source_positions_ = nullptr; |
| 318 | LoopAssignmentAnalysis* loop_assignment_ = nullptr; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 319 | TypeHintAnalysis* type_hint_analysis_ = nullptr; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 320 | SimplifiedOperatorBuilder* simplified_ = nullptr; |
| 321 | MachineOperatorBuilder* machine_ = nullptr; |
| 322 | CommonOperatorBuilder* common_ = nullptr; |
| 323 | JSOperatorBuilder* javascript_ = nullptr; |
| 324 | JSGraph* jsgraph_ = nullptr; |
| 325 | Schedule* schedule_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 326 | |
| 327 | // All objects in the following group of fields are allocated in |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 328 | // instruction_zone_. They are all set to nullptr when the instruction_zone_ |
| 329 | // is |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 330 | // destroyed. |
| 331 | ZonePool::Scope instruction_zone_scope_; |
| 332 | Zone* instruction_zone_; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 333 | InstructionSequence* sequence_ = nullptr; |
| 334 | Frame* frame_ = nullptr; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 335 | |
| 336 | // All objects in the following group of fields are allocated in |
| 337 | // register_allocation_zone_. They are all set to nullptr when the zone is |
| 338 | // destroyed. |
| 339 | ZonePool::Scope register_allocation_zone_scope_; |
| 340 | Zone* register_allocation_zone_; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 341 | RegisterAllocationData* register_allocation_data_ = nullptr; |
| 342 | |
| 343 | // Basic block profiling support. |
| 344 | BasicBlockProfiler::Data* profiler_data_ = nullptr; |
| 345 | |
| 346 | // Source position output for --trace-turbo. |
| 347 | std::string source_position_output_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 348 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 349 | int CalculateFixedFrameSize(CallDescriptor* descriptor) { |
| 350 | if (descriptor->IsJSFunctionCall()) { |
| 351 | return StandardFrameConstants::kFixedSlotCount; |
| 352 | } |
| 353 | return descriptor->IsCFunctionCall() |
| 354 | ? (CommonFrameConstants::kFixedSlotCountAboveFp + |
| 355 | CommonFrameConstants::kCPSlotCount) |
| 356 | : TypedFrameConstants::kFixedSlotCount; |
| 357 | } |
| 358 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 359 | DISALLOW_COPY_AND_ASSIGN(PipelineData); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 360 | }; |
| 361 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 362 | class PipelineImpl final { |
| 363 | public: |
| 364 | explicit PipelineImpl(PipelineData* data) : data_(data) {} |
| 365 | |
| 366 | // Helpers for executing pipeline phases. |
| 367 | template <typename Phase> |
| 368 | void Run(); |
| 369 | template <typename Phase, typename Arg0> |
| 370 | void Run(Arg0 arg_0); |
| 371 | template <typename Phase, typename Arg0, typename Arg1> |
| 372 | void Run(Arg0 arg_0, Arg1 arg_1); |
| 373 | |
| 374 | // Run the graph creation and initial optimization passes. |
| 375 | bool CreateGraph(); |
| 376 | |
| 377 | // Run the concurrent optimization passes. |
| 378 | bool OptimizeGraph(Linkage* linkage); |
| 379 | |
| 380 | // Perform the actual code generation and return handle to a code object. |
| 381 | Handle<Code> GenerateCode(Linkage* linkage); |
| 382 | |
| 383 | bool ScheduleAndSelectInstructions(Linkage* linkage); |
| 384 | void RunPrintAndVerify(const char* phase, bool untyped = false); |
| 385 | Handle<Code> ScheduleAndGenerateCode(CallDescriptor* call_descriptor); |
| 386 | void AllocateRegisters(const RegisterConfiguration* config, |
| 387 | CallDescriptor* descriptor, bool run_verifier); |
| 388 | |
| 389 | CompilationInfo* info() const; |
| 390 | Isolate* isolate() const; |
| 391 | |
| 392 | PipelineData* const data_; |
| 393 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 395 | namespace { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 396 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 397 | struct TurboCfgFile : public std::ofstream { |
| 398 | explicit TurboCfgFile(Isolate* isolate) |
| 399 | : std::ofstream(isolate->GetTurboCfgFileName().c_str(), |
| 400 | std::ios_base::app) {} |
| 401 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 402 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 403 | struct TurboJsonFile : public std::ofstream { |
| 404 | TurboJsonFile(CompilationInfo* info, std::ios_base::openmode mode) |
| 405 | : std::ofstream(GetVisualizerLogFileName(info, nullptr, "json").get(), |
| 406 | mode) {} |
| 407 | }; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 408 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 409 | void TraceSchedule(CompilationInfo* info, Schedule* schedule) { |
| 410 | if (FLAG_trace_turbo) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 411 | AllowHandleDereference allow_deref; |
| 412 | TurboJsonFile json_of(info, std::ios_base::app); |
| 413 | json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\""; |
| 414 | std::stringstream schedule_stream; |
| 415 | schedule_stream << *schedule; |
| 416 | std::string schedule_string(schedule_stream.str()); |
| 417 | for (const auto& c : schedule_string) { |
| 418 | json_of << AsEscapedUC16ForJSON(c); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 419 | } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 420 | json_of << "\"},\n"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 421 | } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 422 | if (FLAG_trace_turbo_graph || FLAG_trace_turbo_scheduler) { |
| 423 | AllowHandleDereference allow_deref; |
| 424 | OFStream os(stdout); |
| 425 | os << "-- Schedule --------------------------------------\n" << *schedule; |
| 426 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 430 | class AstGraphBuilderWithPositions final : public AstGraphBuilder { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 431 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 432 | AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, |
| 433 | JSGraph* jsgraph, |
| 434 | LoopAssignmentAnalysis* loop_assignment, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 435 | TypeHintAnalysis* type_hint_analysis, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 436 | SourcePositionTable* source_positions) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 437 | : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment, |
| 438 | type_hint_analysis), |
| 439 | source_positions_(source_positions), |
| 440 | start_position_(info->shared_info()->start_position()) {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 441 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 442 | bool CreateGraph(bool stack_check) { |
| 443 | SourcePositionTable::Scope pos_scope(source_positions_, start_position_); |
| 444 | return AstGraphBuilder::CreateGraph(stack_check); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | #define DEF_VISIT(type) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 448 | void Visit##type(type* node) override { \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 449 | SourcePositionTable::Scope pos(source_positions_, \ |
| 450 | SourcePosition(node->position())); \ |
| 451 | AstGraphBuilder::Visit##type(node); \ |
| 452 | } |
| 453 | AST_NODE_LIST(DEF_VISIT) |
| 454 | #undef DEF_VISIT |
| 455 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 456 | private: |
| 457 | SourcePositionTable* const source_positions_; |
| 458 | SourcePosition const start_position_; |
| 459 | }; |
| 460 | |
| 461 | |
| 462 | class SourcePositionWrapper final : public Reducer { |
| 463 | public: |
| 464 | SourcePositionWrapper(Reducer* reducer, SourcePositionTable* table) |
| 465 | : reducer_(reducer), table_(table) {} |
| 466 | ~SourcePositionWrapper() final {} |
| 467 | |
| 468 | Reduction Reduce(Node* node) final { |
| 469 | SourcePosition const pos = table_->GetSourcePosition(node); |
| 470 | SourcePositionTable::Scope position(table_, pos); |
| 471 | return reducer_->Reduce(node); |
| 472 | } |
| 473 | |
| 474 | void Finalize() final { reducer_->Finalize(); } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 475 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 476 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 477 | Reducer* const reducer_; |
| 478 | SourcePositionTable* const table_; |
| 479 | |
| 480 | DISALLOW_COPY_AND_ASSIGN(SourcePositionWrapper); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 481 | }; |
| 482 | |
| 483 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 484 | class JSGraphReducer final : public GraphReducer { |
| 485 | public: |
| 486 | JSGraphReducer(JSGraph* jsgraph, Zone* zone) |
| 487 | : GraphReducer(zone, jsgraph->graph(), jsgraph->Dead()) {} |
| 488 | ~JSGraphReducer() final {} |
| 489 | }; |
| 490 | |
| 491 | |
| 492 | void AddReducer(PipelineData* data, GraphReducer* graph_reducer, |
| 493 | Reducer* reducer) { |
| 494 | if (data->info()->is_source_positions_enabled()) { |
| 495 | void* const buffer = data->graph_zone()->New(sizeof(SourcePositionWrapper)); |
| 496 | SourcePositionWrapper* const wrapper = |
| 497 | new (buffer) SourcePositionWrapper(reducer, data->source_positions()); |
| 498 | graph_reducer->AddReducer(wrapper); |
| 499 | } else { |
| 500 | graph_reducer->AddReducer(reducer); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 505 | class PipelineRunScope { |
| 506 | public: |
| 507 | PipelineRunScope(PipelineData* data, const char* phase_name) |
| 508 | : phase_scope_( |
| 509 | phase_name == nullptr ? nullptr : data->pipeline_statistics(), |
| 510 | phase_name), |
| 511 | zone_scope_(data->zone_pool()) {} |
| 512 | |
| 513 | Zone* zone() { return zone_scope_.zone(); } |
| 514 | |
| 515 | private: |
| 516 | PhaseScope phase_scope_; |
| 517 | ZonePool::Scope zone_scope_; |
| 518 | }; |
| 519 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 520 | PipelineStatistics* CreatePipelineStatistics(CompilationInfo* info, |
| 521 | ZonePool* zone_pool) { |
| 522 | PipelineStatistics* pipeline_statistics = nullptr; |
| 523 | |
| 524 | if (FLAG_turbo_stats) { |
| 525 | pipeline_statistics = new PipelineStatistics(info, zone_pool); |
| 526 | pipeline_statistics->BeginPhaseKind("initializing"); |
| 527 | } |
| 528 | |
| 529 | if (FLAG_trace_turbo) { |
| 530 | TurboJsonFile json_of(info, std::ios_base::trunc); |
| 531 | Handle<Script> script = info->script(); |
| 532 | base::SmartArrayPointer<char> function_name = info->GetDebugName(); |
| 533 | int pos = info->shared_info()->start_position(); |
| 534 | json_of << "{\"function\":\"" << function_name.get() |
| 535 | << "\", \"sourcePosition\":" << pos << ", \"source\":\""; |
| 536 | if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
| 537 | DisallowHeapAllocation no_allocation; |
| 538 | int start = info->shared_info()->start_position(); |
| 539 | int len = info->shared_info()->end_position() - start; |
| 540 | String::SubStringRange source(String::cast(script->source()), start, len); |
| 541 | for (const auto& c : source) { |
| 542 | json_of << AsEscapedUC16ForJSON(c); |
| 543 | } |
| 544 | } |
| 545 | json_of << "\",\n\"phases\":["; |
| 546 | } |
| 547 | |
| 548 | return pipeline_statistics; |
| 549 | } |
| 550 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 551 | } // namespace |
| 552 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 553 | class PipelineCompilationJob final : public CompilationJob { |
| 554 | public: |
| 555 | PipelineCompilationJob(Isolate* isolate, Handle<JSFunction> function) |
| 556 | // Note that the CompilationInfo is not initialized at the time we pass it |
| 557 | // to the CompilationJob constructor, but it is not dereferenced there. |
| 558 | : CompilationJob(&info_, "TurboFan"), |
| 559 | zone_(isolate->allocator()), |
| 560 | zone_pool_(isolate->allocator()), |
| 561 | parse_info_(&zone_, function), |
| 562 | info_(&parse_info_, function), |
| 563 | pipeline_statistics_(CreatePipelineStatistics(info(), &zone_pool_)), |
| 564 | data_(&zone_pool_, info(), pipeline_statistics_.get()), |
| 565 | pipeline_(&data_), |
| 566 | linkage_(nullptr) {} |
| 567 | |
| 568 | protected: |
| 569 | Status CreateGraphImpl() final; |
| 570 | Status OptimizeGraphImpl() final; |
| 571 | Status GenerateCodeImpl() final; |
| 572 | |
| 573 | private: |
| 574 | Zone zone_; |
| 575 | ZonePool zone_pool_; |
| 576 | ParseInfo parse_info_; |
| 577 | CompilationInfo info_; |
| 578 | base::SmartPointer<PipelineStatistics> pipeline_statistics_; |
| 579 | PipelineData data_; |
| 580 | PipelineImpl pipeline_; |
| 581 | Linkage* linkage_; |
| 582 | }; |
| 583 | |
| 584 | PipelineCompilationJob::Status PipelineCompilationJob::CreateGraphImpl() { |
| 585 | if (info()->shared_info()->asm_function()) { |
| 586 | if (info()->osr_frame()) info()->MarkAsFrameSpecializing(); |
| 587 | info()->MarkAsFunctionContextSpecializing(); |
| 588 | } else { |
| 589 | if (!FLAG_always_opt) { |
| 590 | info()->MarkAsBailoutOnUninitialized(); |
| 591 | } |
| 592 | if (FLAG_native_context_specialization) { |
| 593 | info()->MarkAsNativeContextSpecializing(); |
| 594 | } |
| 595 | } |
| 596 | if (!info()->shared_info()->asm_function() || FLAG_turbo_asm_deoptimization) { |
| 597 | info()->MarkAsDeoptimizationEnabled(); |
| 598 | } |
| 599 | if (!info()->is_optimizing_from_bytecode()) { |
| 600 | if (!Compiler::EnsureDeoptimizationSupport(info())) return FAILED; |
| 601 | } |
| 602 | |
| 603 | linkage_ = new (&zone_) Linkage(Linkage::ComputeIncoming(&zone_, info())); |
| 604 | |
| 605 | if (!pipeline_.CreateGraph()) { |
| 606 | if (isolate()->has_pending_exception()) return FAILED; // Stack overflowed. |
| 607 | return AbortOptimization(kGraphBuildingFailed); |
| 608 | } |
| 609 | |
| 610 | return SUCCEEDED; |
| 611 | } |
| 612 | |
| 613 | PipelineCompilationJob::Status PipelineCompilationJob::OptimizeGraphImpl() { |
| 614 | if (!pipeline_.OptimizeGraph(linkage_)) return FAILED; |
| 615 | return SUCCEEDED; |
| 616 | } |
| 617 | |
| 618 | PipelineCompilationJob::Status PipelineCompilationJob::GenerateCodeImpl() { |
| 619 | Handle<Code> code = pipeline_.GenerateCode(linkage_); |
| 620 | if (code.is_null()) { |
| 621 | if (info()->bailout_reason() == kNoReason) { |
| 622 | return AbortOptimization(kCodeGenerationFailed); |
| 623 | } |
| 624 | return FAILED; |
| 625 | } |
| 626 | info()->dependencies()->Commit(code); |
| 627 | info()->SetCode(code); |
| 628 | if (info()->is_deoptimization_enabled()) { |
| 629 | info()->context()->native_context()->AddOptimizedCode(*code); |
| 630 | RegisterWeakObjectsInOptimizedCode(code); |
| 631 | } |
| 632 | return SUCCEEDED; |
| 633 | } |
| 634 | |
| 635 | class PipelineWasmCompilationJob final : public CompilationJob { |
| 636 | public: |
| 637 | explicit PipelineWasmCompilationJob(CompilationInfo* info, Graph* graph, |
| 638 | CallDescriptor* descriptor, |
| 639 | SourcePositionTable* source_positions) |
| 640 | : CompilationJob(info, "TurboFan"), |
| 641 | zone_pool_(info->isolate()->allocator()), |
| 642 | data_(&zone_pool_, info, graph, source_positions), |
| 643 | pipeline_(&data_), |
| 644 | linkage_(descriptor) {} |
| 645 | |
| 646 | protected: |
| 647 | Status CreateGraphImpl() final; |
| 648 | Status OptimizeGraphImpl() final; |
| 649 | Status GenerateCodeImpl() final; |
| 650 | |
| 651 | private: |
| 652 | ZonePool zone_pool_; |
| 653 | PipelineData data_; |
| 654 | PipelineImpl pipeline_; |
| 655 | Linkage linkage_; |
| 656 | }; |
| 657 | |
| 658 | PipelineWasmCompilationJob::Status |
| 659 | PipelineWasmCompilationJob::CreateGraphImpl() { |
| 660 | return SUCCEEDED; |
| 661 | } |
| 662 | |
| 663 | PipelineWasmCompilationJob::Status |
| 664 | PipelineWasmCompilationJob::OptimizeGraphImpl() { |
| 665 | if (FLAG_trace_turbo) { |
| 666 | TurboJsonFile json_of(info(), std::ios_base::trunc); |
| 667 | json_of << "{\"function\":\"" << info()->GetDebugName().get() |
| 668 | << "\", \"source\":\"\",\n\"phases\":["; |
| 669 | } |
| 670 | |
| 671 | pipeline_.RunPrintAndVerify("Machine", true); |
| 672 | |
| 673 | if (!pipeline_.ScheduleAndSelectInstructions(&linkage_)) return FAILED; |
| 674 | return SUCCEEDED; |
| 675 | } |
| 676 | |
| 677 | PipelineWasmCompilationJob::Status |
| 678 | PipelineWasmCompilationJob::GenerateCodeImpl() { |
| 679 | pipeline_.GenerateCode(&linkage_); |
| 680 | return SUCCEEDED; |
| 681 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 682 | |
| 683 | template <typename Phase> |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 684 | void PipelineImpl::Run() { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 685 | PipelineRunScope scope(this->data_, Phase::phase_name()); |
| 686 | Phase phase; |
| 687 | phase.Run(this->data_, scope.zone()); |
| 688 | } |
| 689 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 690 | template <typename Phase, typename Arg0> |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 691 | void PipelineImpl::Run(Arg0 arg_0) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 692 | PipelineRunScope scope(this->data_, Phase::phase_name()); |
| 693 | Phase phase; |
| 694 | phase.Run(this->data_, scope.zone(), arg_0); |
| 695 | } |
| 696 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 697 | template <typename Phase, typename Arg0, typename Arg1> |
| 698 | void PipelineImpl::Run(Arg0 arg_0, Arg1 arg_1) { |
| 699 | PipelineRunScope scope(this->data_, Phase::phase_name()); |
| 700 | Phase phase; |
| 701 | phase.Run(this->data_, scope.zone(), arg_0, arg_1); |
| 702 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 703 | |
| 704 | struct LoopAssignmentAnalysisPhase { |
| 705 | static const char* phase_name() { return "loop assignment analysis"; } |
| 706 | |
| 707 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 708 | if (!data->info()->is_optimizing_from_bytecode()) { |
| 709 | AstLoopAssignmentAnalyzer analyzer(data->graph_zone(), data->info()); |
| 710 | LoopAssignmentAnalysis* loop_assignment = analyzer.Analyze(); |
| 711 | data->set_loop_assignment(loop_assignment); |
| 712 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 713 | } |
| 714 | }; |
| 715 | |
| 716 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 717 | struct TypeHintAnalysisPhase { |
| 718 | static const char* phase_name() { return "type hint analysis"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 719 | |
| 720 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 721 | if (!data->info()->is_optimizing_from_bytecode()) { |
| 722 | TypeHintAnalyzer analyzer(data->graph_zone()); |
| 723 | Handle<Code> code(data->info()->shared_info()->code(), data->isolate()); |
| 724 | TypeHintAnalysis* type_hint_analysis = analyzer.Analyze(code); |
| 725 | data->set_type_hint_analysis(type_hint_analysis); |
| 726 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 727 | } |
| 728 | }; |
| 729 | |
| 730 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 731 | struct GraphBuilderPhase { |
| 732 | static const char* phase_name() { return "graph builder"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 733 | |
| 734 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 735 | bool stack_check = !data->info()->IsStub(); |
| 736 | bool succeeded = false; |
| 737 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 738 | if (data->info()->is_optimizing_from_bytecode()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 739 | BytecodeGraphBuilder graph_builder(temp_zone, data->info(), |
| 740 | data->jsgraph()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 741 | succeeded = graph_builder.CreateGraph(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 742 | } else { |
| 743 | AstGraphBuilderWithPositions graph_builder( |
| 744 | temp_zone, data->info(), data->jsgraph(), data->loop_assignment(), |
| 745 | data->type_hint_analysis(), data->source_positions()); |
| 746 | succeeded = graph_builder.CreateGraph(stack_check); |
| 747 | } |
| 748 | |
| 749 | if (!succeeded) { |
| 750 | data->set_compilation_failed(); |
| 751 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 752 | } |
| 753 | }; |
| 754 | |
| 755 | |
| 756 | struct InliningPhase { |
| 757 | static const char* phase_name() { return "inlining"; } |
| 758 | |
| 759 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 760 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 761 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 762 | data->common()); |
| 763 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 764 | data->common(), data->machine()); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 765 | JSCallReducer call_reducer(data->jsgraph(), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 766 | data->info()->is_deoptimization_enabled() |
| 767 | ? JSCallReducer::kDeoptimizationEnabled |
| 768 | : JSCallReducer::kNoFlags, |
| 769 | data->native_context()); |
| 770 | JSContextSpecialization context_specialization( |
| 771 | &graph_reducer, data->jsgraph(), |
| 772 | data->info()->is_function_context_specializing() |
| 773 | ? data->info()->context() |
| 774 | : MaybeHandle<Context>()); |
| 775 | JSFrameSpecialization frame_specialization(data->info()->osr_frame(), |
| 776 | data->jsgraph()); |
| 777 | JSGlobalObjectSpecialization global_object_specialization( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 778 | &graph_reducer, data->jsgraph(), data->native_context(), |
| 779 | data->info()->dependencies()); |
| 780 | JSNativeContextSpecialization::Flags flags = |
| 781 | JSNativeContextSpecialization::kNoFlags; |
| 782 | if (data->info()->is_bailout_on_uninitialized()) { |
| 783 | flags |= JSNativeContextSpecialization::kBailoutOnUninitialized; |
| 784 | } |
| 785 | if (data->info()->is_deoptimization_enabled()) { |
| 786 | flags |= JSNativeContextSpecialization::kDeoptimizationEnabled; |
| 787 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 788 | JSNativeContextSpecialization native_context_specialization( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 789 | &graph_reducer, data->jsgraph(), flags, data->native_context(), |
| 790 | data->info()->dependencies(), temp_zone); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 791 | JSInliningHeuristic inlining(&graph_reducer, |
| 792 | data->info()->is_inlining_enabled() |
| 793 | ? JSInliningHeuristic::kGeneralInlining |
| 794 | : JSInliningHeuristic::kRestrictedInlining, |
| 795 | temp_zone, data->info(), data->jsgraph()); |
| 796 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 797 | AddReducer(data, &graph_reducer, &common_reducer); |
| 798 | if (data->info()->is_frame_specializing()) { |
| 799 | AddReducer(data, &graph_reducer, &frame_specialization); |
| 800 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 801 | if (data->info()->is_deoptimization_enabled()) { |
| 802 | AddReducer(data, &graph_reducer, &global_object_specialization); |
| 803 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 804 | AddReducer(data, &graph_reducer, &native_context_specialization); |
| 805 | AddReducer(data, &graph_reducer, &context_specialization); |
| 806 | AddReducer(data, &graph_reducer, &call_reducer); |
| 807 | AddReducer(data, &graph_reducer, &inlining); |
| 808 | graph_reducer.ReduceGraph(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 809 | } |
| 810 | }; |
| 811 | |
| 812 | |
| 813 | struct TyperPhase { |
| 814 | static const char* phase_name() { return "typer"; } |
| 815 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 816 | void Run(PipelineData* data, Zone* temp_zone, Typer* typer) { |
| 817 | NodeVector roots(temp_zone); |
| 818 | data->jsgraph()->GetCachedNodes(&roots); |
| 819 | typer->Run(roots); |
| 820 | } |
| 821 | }; |
| 822 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 823 | #ifdef DEBUG |
| 824 | |
| 825 | struct UntyperPhase { |
| 826 | static const char* phase_name() { return "untyper"; } |
| 827 | |
| 828 | void Run(PipelineData* data, Zone* temp_zone) { |
| 829 | class RemoveTypeReducer final : public Reducer { |
| 830 | public: |
| 831 | Reduction Reduce(Node* node) final { |
| 832 | if (NodeProperties::IsTyped(node)) { |
| 833 | NodeProperties::RemoveType(node); |
| 834 | return Changed(node); |
| 835 | } |
| 836 | return NoChange(); |
| 837 | } |
| 838 | }; |
| 839 | |
| 840 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 841 | RemoveTypeReducer remove_type_reducer; |
| 842 | AddReducer(data, &graph_reducer, &remove_type_reducer); |
| 843 | graph_reducer.ReduceGraph(); |
| 844 | } |
| 845 | }; |
| 846 | |
| 847 | #endif // DEBUG |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 848 | |
| 849 | struct OsrDeconstructionPhase { |
| 850 | static const char* phase_name() { return "OSR deconstruction"; } |
| 851 | |
| 852 | void Run(PipelineData* data, Zone* temp_zone) { |
| 853 | OsrHelper osr_helper(data->info()); |
| 854 | osr_helper.Deconstruct(data->jsgraph(), data->common(), temp_zone); |
| 855 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 856 | }; |
| 857 | |
| 858 | |
| 859 | struct TypedLoweringPhase { |
| 860 | static const char* phase_name() { return "typed lowering"; } |
| 861 | |
| 862 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 863 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 864 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 865 | data->common()); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 866 | LoadElimination load_elimination(&graph_reducer, data->graph(), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 867 | data->jsgraph()->simplified()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 868 | JSBuiltinReducer builtin_reducer(&graph_reducer, data->jsgraph()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 869 | MaybeHandle<LiteralsArray> literals_array = |
| 870 | data->info()->is_native_context_specializing() |
| 871 | ? handle(data->info()->closure()->literals(), data->isolate()) |
| 872 | : MaybeHandle<LiteralsArray>(); |
| 873 | JSCreateLowering create_lowering( |
| 874 | &graph_reducer, data->info()->dependencies(), data->jsgraph(), |
| 875 | literals_array, temp_zone); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 876 | JSTypedLowering::Flags typed_lowering_flags = JSTypedLowering::kNoFlags; |
| 877 | if (data->info()->is_deoptimization_enabled()) { |
| 878 | typed_lowering_flags |= JSTypedLowering::kDeoptimizationEnabled; |
| 879 | } |
| 880 | if (data->info()->shared_info()->HasBytecodeArray()) { |
| 881 | typed_lowering_flags |= JSTypedLowering::kDisableBinaryOpReduction; |
| 882 | } |
| 883 | JSTypedLowering typed_lowering(&graph_reducer, data->info()->dependencies(), |
| 884 | typed_lowering_flags, data->jsgraph(), |
| 885 | temp_zone); |
| 886 | JSIntrinsicLowering intrinsic_lowering( |
| 887 | &graph_reducer, data->jsgraph(), |
| 888 | data->info()->is_deoptimization_enabled() |
| 889 | ? JSIntrinsicLowering::kDeoptimizationEnabled |
| 890 | : JSIntrinsicLowering::kDeoptimizationDisabled); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 891 | SimplifiedOperatorReducer simple_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 892 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 893 | data->common(), data->machine()); |
| 894 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 895 | AddReducer(data, &graph_reducer, &builtin_reducer); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 896 | if (data->info()->is_deoptimization_enabled()) { |
| 897 | AddReducer(data, &graph_reducer, &create_lowering); |
| 898 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 899 | AddReducer(data, &graph_reducer, &typed_lowering); |
| 900 | AddReducer(data, &graph_reducer, &intrinsic_lowering); |
| 901 | AddReducer(data, &graph_reducer, &load_elimination); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 902 | AddReducer(data, &graph_reducer, &simple_reducer); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 903 | AddReducer(data, &graph_reducer, &common_reducer); |
| 904 | graph_reducer.ReduceGraph(); |
| 905 | } |
| 906 | }; |
| 907 | |
| 908 | |
| 909 | struct BranchEliminationPhase { |
| 910 | static const char* phase_name() { return "branch condition elimination"; } |
| 911 | |
| 912 | void Run(PipelineData* data, Zone* temp_zone) { |
| 913 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 914 | BranchElimination branch_condition_elimination(&graph_reducer, |
| 915 | data->jsgraph(), temp_zone); |
| 916 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 917 | data->common()); |
| 918 | AddReducer(data, &graph_reducer, &branch_condition_elimination); |
| 919 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 920 | graph_reducer.ReduceGraph(); |
| 921 | } |
| 922 | }; |
| 923 | |
| 924 | |
| 925 | struct EscapeAnalysisPhase { |
| 926 | static const char* phase_name() { return "escape analysis"; } |
| 927 | |
| 928 | void Run(PipelineData* data, Zone* temp_zone) { |
| 929 | EscapeAnalysis escape_analysis(data->graph(), data->jsgraph()->common(), |
| 930 | temp_zone); |
| 931 | escape_analysis.Run(); |
| 932 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 933 | EscapeAnalysisReducer escape_reducer(&graph_reducer, data->jsgraph(), |
| 934 | &escape_analysis, temp_zone); |
| 935 | AddReducer(data, &graph_reducer, &escape_reducer); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 936 | graph_reducer.ReduceGraph(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 937 | escape_reducer.VerifyReplacement(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 938 | } |
| 939 | }; |
| 940 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 941 | struct RepresentationSelectionPhase { |
| 942 | static const char* phase_name() { return "representation selection"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 943 | |
| 944 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 945 | SimplifiedLowering lowering(data->jsgraph(), temp_zone, |
| 946 | data->source_positions()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 947 | lowering.LowerAllNodes(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 948 | } |
| 949 | }; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 950 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 951 | struct EarlyOptimizationPhase { |
| 952 | static const char* phase_name() { return "early optimization"; } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 953 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 954 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 955 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 956 | JSGenericLowering generic_lowering(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 957 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 958 | data->common()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 959 | SimplifiedOperatorReducer simple_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 960 | ValueNumberingReducer value_numbering(temp_zone); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 961 | MachineOperatorReducer machine_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 962 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 963 | data->common(), data->machine()); |
| 964 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 965 | AddReducer(data, &graph_reducer, &simple_reducer); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 966 | AddReducer(data, &graph_reducer, &generic_lowering); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 967 | AddReducer(data, &graph_reducer, &value_numbering); |
| 968 | AddReducer(data, &graph_reducer, &machine_reducer); |
| 969 | AddReducer(data, &graph_reducer, &common_reducer); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 970 | graph_reducer.ReduceGraph(); |
| 971 | } |
| 972 | }; |
| 973 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 974 | struct ControlFlowOptimizationPhase { |
| 975 | static const char* phase_name() { return "control flow optimization"; } |
| 976 | |
| 977 | void Run(PipelineData* data, Zone* temp_zone) { |
| 978 | ControlFlowOptimizer optimizer(data->graph(), data->common(), |
| 979 | data->machine(), temp_zone); |
| 980 | optimizer.Optimize(); |
| 981 | } |
| 982 | }; |
| 983 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 984 | struct EffectControlLinearizationPhase { |
| 985 | static const char* phase_name() { return "effect linearization"; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 986 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 987 | void Run(PipelineData* data, Zone* temp_zone) { |
| 988 | // The scheduler requires the graphs to be trimmed, so trim now. |
| 989 | // TODO(jarin) Remove the trimming once the scheduler can handle untrimmed |
| 990 | // graphs. |
| 991 | GraphTrimmer trimmer(temp_zone, data->graph()); |
| 992 | NodeVector roots(temp_zone); |
| 993 | data->jsgraph()->GetCachedNodes(&roots); |
| 994 | trimmer.TrimGraph(roots.begin(), roots.end()); |
| 995 | |
| 996 | // Schedule the graph without node splitting so that we can |
| 997 | // fix the effect and control flow for nodes with low-level side |
| 998 | // effects (such as changing representation to tagged or |
| 999 | // 'floating' allocation regions.) |
| 1000 | Schedule* schedule = Scheduler::ComputeSchedule(temp_zone, data->graph(), |
| 1001 | Scheduler::kNoFlags); |
| 1002 | if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); |
| 1003 | TraceSchedule(data->info(), schedule); |
| 1004 | |
| 1005 | // Post-pass for wiring the control/effects |
| 1006 | // - connect allocating representation changes into the control&effect |
| 1007 | // chains and lower them, |
| 1008 | // - get rid of the region markers, |
| 1009 | // - introduce effect phis and rewire effects to get SSA again. |
| 1010 | EffectControlLinearizer linearizer(data->jsgraph(), schedule, temp_zone); |
| 1011 | linearizer.Run(); |
| 1012 | } |
| 1013 | }; |
| 1014 | |
| 1015 | struct MemoryOptimizationPhase { |
| 1016 | static const char* phase_name() { return "memory optimization"; } |
| 1017 | |
| 1018 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1019 | MemoryOptimizer optimizer(data->jsgraph(), temp_zone); |
| 1020 | optimizer.Optimize(); |
| 1021 | } |
| 1022 | }; |
| 1023 | |
| 1024 | struct LateOptimizationPhase { |
| 1025 | static const char* phase_name() { return "late optimization"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1026 | |
| 1027 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1028 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 1029 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 1030 | data->common()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1031 | ValueNumberingReducer value_numbering(temp_zone); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1032 | MachineOperatorReducer machine_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1033 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 1034 | data->common(), data->machine()); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1035 | SelectLowering select_lowering(data->jsgraph()->graph(), |
| 1036 | data->jsgraph()->common()); |
| 1037 | TailCallOptimization tco(data->common(), data->graph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1038 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1039 | AddReducer(data, &graph_reducer, &value_numbering); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1040 | AddReducer(data, &graph_reducer, &machine_reducer); |
| 1041 | AddReducer(data, &graph_reducer, &common_reducer); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1042 | AddReducer(data, &graph_reducer, &select_lowering); |
| 1043 | AddReducer(data, &graph_reducer, &tco); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1044 | graph_reducer.ReduceGraph(); |
| 1045 | } |
| 1046 | }; |
| 1047 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1048 | struct EarlyGraphTrimmingPhase { |
| 1049 | static const char* phase_name() { return "early graph trimming"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1050 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1051 | GraphTrimmer trimmer(temp_zone, data->graph()); |
| 1052 | NodeVector roots(temp_zone); |
| 1053 | data->jsgraph()->GetCachedNodes(&roots); |
| 1054 | trimmer.TrimGraph(roots.begin(), roots.end()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1055 | } |
| 1056 | }; |
| 1057 | |
| 1058 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1059 | struct LateGraphTrimmingPhase { |
| 1060 | static const char* phase_name() { return "late graph trimming"; } |
| 1061 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1062 | GraphTrimmer trimmer(temp_zone, data->graph()); |
| 1063 | NodeVector roots(temp_zone); |
| 1064 | data->jsgraph()->GetCachedNodes(&roots); |
| 1065 | trimmer.TrimGraph(roots.begin(), roots.end()); |
| 1066 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1067 | }; |
| 1068 | |
| 1069 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1070 | struct StressLoopPeelingPhase { |
| 1071 | static const char* phase_name() { return "stress loop peeling"; } |
| 1072 | |
| 1073 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1074 | // Peel the first outer loop for testing. |
| 1075 | // TODO(titzer): peel all loops? the N'th loop? Innermost loops? |
| 1076 | LoopTree* loop_tree = LoopFinder::BuildLoopTree(data->graph(), temp_zone); |
| 1077 | if (loop_tree != nullptr && loop_tree->outer_loops().size() > 0) { |
| 1078 | LoopPeeler::Peel(data->graph(), data->common(), loop_tree, |
| 1079 | loop_tree->outer_loops()[0], temp_zone); |
| 1080 | } |
| 1081 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1082 | }; |
| 1083 | |
| 1084 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1085 | struct ComputeSchedulePhase { |
| 1086 | static const char* phase_name() { return "scheduling"; } |
| 1087 | |
| 1088 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1089 | Schedule* schedule = Scheduler::ComputeSchedule( |
| 1090 | temp_zone, data->graph(), data->info()->is_splitting_enabled() |
| 1091 | ? Scheduler::kSplitNodes |
| 1092 | : Scheduler::kNoFlags); |
| 1093 | if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1094 | data->set_schedule(schedule); |
| 1095 | } |
| 1096 | }; |
| 1097 | |
| 1098 | |
| 1099 | struct InstructionSelectionPhase { |
| 1100 | static const char* phase_name() { return "select instructions"; } |
| 1101 | |
| 1102 | void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1103 | InstructionSelector selector( |
| 1104 | temp_zone, data->graph()->NodeCount(), linkage, data->sequence(), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1105 | data->schedule(), data->source_positions(), data->frame(), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1106 | data->info()->is_source_positions_enabled() |
| 1107 | ? InstructionSelector::kAllSourcePositions |
| 1108 | : InstructionSelector::kCallSourcePositions); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1109 | selector.SelectInstructions(); |
| 1110 | } |
| 1111 | }; |
| 1112 | |
| 1113 | |
| 1114 | struct MeetRegisterConstraintsPhase { |
| 1115 | static const char* phase_name() { return "meet register constraints"; } |
| 1116 | |
| 1117 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1118 | ConstraintBuilder builder(data->register_allocation_data()); |
| 1119 | builder.MeetRegisterConstraints(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1120 | } |
| 1121 | }; |
| 1122 | |
| 1123 | |
| 1124 | struct ResolvePhisPhase { |
| 1125 | static const char* phase_name() { return "resolve phis"; } |
| 1126 | |
| 1127 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1128 | ConstraintBuilder builder(data->register_allocation_data()); |
| 1129 | builder.ResolvePhis(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1130 | } |
| 1131 | }; |
| 1132 | |
| 1133 | |
| 1134 | struct BuildLiveRangesPhase { |
| 1135 | static const char* phase_name() { return "build live ranges"; } |
| 1136 | |
| 1137 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1138 | LiveRangeBuilder builder(data->register_allocation_data(), temp_zone); |
| 1139 | builder.BuildLiveRanges(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1140 | } |
| 1141 | }; |
| 1142 | |
| 1143 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1144 | struct SplinterLiveRangesPhase { |
| 1145 | static const char* phase_name() { return "splinter live ranges"; } |
| 1146 | |
| 1147 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1148 | LiveRangeSeparator live_range_splinterer(data->register_allocation_data(), |
| 1149 | temp_zone); |
| 1150 | live_range_splinterer.Splinter(); |
| 1151 | } |
| 1152 | }; |
| 1153 | |
| 1154 | |
| 1155 | template <typename RegAllocator> |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1156 | struct AllocateGeneralRegistersPhase { |
| 1157 | static const char* phase_name() { return "allocate general registers"; } |
| 1158 | |
| 1159 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1160 | RegAllocator allocator(data->register_allocation_data(), GENERAL_REGISTERS, |
| 1161 | temp_zone); |
| 1162 | allocator.AllocateRegisters(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1163 | } |
| 1164 | }; |
| 1165 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1166 | template <typename RegAllocator> |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1167 | struct AllocateFPRegistersPhase { |
| 1168 | static const char* phase_name() { |
| 1169 | return "allocate floating point registers"; |
| 1170 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1171 | |
| 1172 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1173 | RegAllocator allocator(data->register_allocation_data(), FP_REGISTERS, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1174 | temp_zone); |
| 1175 | allocator.AllocateRegisters(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1176 | } |
| 1177 | }; |
| 1178 | |
| 1179 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1180 | struct MergeSplintersPhase { |
| 1181 | static const char* phase_name() { return "merge splintered ranges"; } |
| 1182 | void Run(PipelineData* pipeline_data, Zone* temp_zone) { |
| 1183 | RegisterAllocationData* data = pipeline_data->register_allocation_data(); |
| 1184 | LiveRangeMerger live_range_merger(data, temp_zone); |
| 1185 | live_range_merger.Merge(); |
| 1186 | } |
| 1187 | }; |
| 1188 | |
| 1189 | |
| 1190 | struct LocateSpillSlotsPhase { |
| 1191 | static const char* phase_name() { return "locate spill slots"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1192 | |
| 1193 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1194 | SpillSlotLocator locator(data->register_allocation_data()); |
| 1195 | locator.LocateSpillSlots(); |
| 1196 | } |
| 1197 | }; |
| 1198 | |
| 1199 | |
| 1200 | struct AssignSpillSlotsPhase { |
| 1201 | static const char* phase_name() { return "assign spill slots"; } |
| 1202 | |
| 1203 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1204 | OperandAssigner assigner(data->register_allocation_data()); |
| 1205 | assigner.AssignSpillSlots(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1206 | } |
| 1207 | }; |
| 1208 | |
| 1209 | |
| 1210 | struct CommitAssignmentPhase { |
| 1211 | static const char* phase_name() { return "commit assignment"; } |
| 1212 | |
| 1213 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1214 | OperandAssigner assigner(data->register_allocation_data()); |
| 1215 | assigner.CommitAssignment(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1216 | } |
| 1217 | }; |
| 1218 | |
| 1219 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1220 | struct PopulateReferenceMapsPhase { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1221 | static const char* phase_name() { return "populate pointer maps"; } |
| 1222 | |
| 1223 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1224 | ReferenceMapPopulator populator(data->register_allocation_data()); |
| 1225 | populator.PopulateReferenceMaps(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1226 | } |
| 1227 | }; |
| 1228 | |
| 1229 | |
| 1230 | struct ConnectRangesPhase { |
| 1231 | static const char* phase_name() { return "connect ranges"; } |
| 1232 | |
| 1233 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1234 | LiveRangeConnector connector(data->register_allocation_data()); |
| 1235 | connector.ConnectRanges(temp_zone); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1236 | } |
| 1237 | }; |
| 1238 | |
| 1239 | |
| 1240 | struct ResolveControlFlowPhase { |
| 1241 | static const char* phase_name() { return "resolve control flow"; } |
| 1242 | |
| 1243 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1244 | LiveRangeConnector connector(data->register_allocation_data()); |
| 1245 | connector.ResolveControlFlow(temp_zone); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1246 | } |
| 1247 | }; |
| 1248 | |
| 1249 | |
| 1250 | struct OptimizeMovesPhase { |
| 1251 | static const char* phase_name() { return "optimize moves"; } |
| 1252 | |
| 1253 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1254 | MoveOptimizer move_optimizer(temp_zone, data->sequence()); |
| 1255 | move_optimizer.Run(); |
| 1256 | } |
| 1257 | }; |
| 1258 | |
| 1259 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1260 | struct FrameElisionPhase { |
| 1261 | static const char* phase_name() { return "frame elision"; } |
| 1262 | |
| 1263 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1264 | FrameElider(data->sequence()).Run(); |
| 1265 | } |
| 1266 | }; |
| 1267 | |
| 1268 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1269 | struct JumpThreadingPhase { |
| 1270 | static const char* phase_name() { return "jump threading"; } |
| 1271 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1272 | void Run(PipelineData* data, Zone* temp_zone, bool frame_at_start) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1273 | ZoneVector<RpoNumber> result(temp_zone); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1274 | if (JumpThreading::ComputeForwarding(temp_zone, result, data->sequence(), |
| 1275 | frame_at_start)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1276 | JumpThreading::ApplyForwarding(result, data->sequence()); |
| 1277 | } |
| 1278 | } |
| 1279 | }; |
| 1280 | |
| 1281 | |
| 1282 | struct GenerateCodePhase { |
| 1283 | static const char* phase_name() { return "generate code"; } |
| 1284 | |
| 1285 | void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { |
| 1286 | CodeGenerator generator(data->frame(), linkage, data->sequence(), |
| 1287 | data->info()); |
| 1288 | data->set_code(generator.GenerateCode()); |
| 1289 | } |
| 1290 | }; |
| 1291 | |
| 1292 | |
| 1293 | struct PrintGraphPhase { |
| 1294 | static const char* phase_name() { return nullptr; } |
| 1295 | |
| 1296 | void Run(PipelineData* data, Zone* temp_zone, const char* phase) { |
| 1297 | CompilationInfo* info = data->info(); |
| 1298 | Graph* graph = data->graph(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1299 | |
| 1300 | { // Print JSON. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1301 | AllowHandleDereference allow_deref; |
| 1302 | TurboJsonFile json_of(info, std::ios_base::app); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1303 | json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" |
| 1304 | << AsJSON(*graph, data->source_positions()) << "},\n"; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1305 | } |
| 1306 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1307 | if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1308 | AllowHandleDereference allow_deref; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1309 | OFStream os(stdout); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1310 | os << "-- Graph after " << phase << " -- " << std::endl; |
| 1311 | os << AsRPO(*graph); |
| 1312 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1313 | } |
| 1314 | }; |
| 1315 | |
| 1316 | |
| 1317 | struct VerifyGraphPhase { |
| 1318 | static const char* phase_name() { return nullptr; } |
| 1319 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1320 | void Run(PipelineData* data, Zone* temp_zone, const bool untyped, |
| 1321 | bool values_only = false) { |
| 1322 | Verifier::Run(data->graph(), !untyped ? Verifier::TYPED : Verifier::UNTYPED, |
| 1323 | values_only ? Verifier::kValuesOnly : Verifier::kAll); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1324 | } |
| 1325 | }; |
| 1326 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1327 | void PipelineImpl::RunPrintAndVerify(const char* phase, bool untyped) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1328 | if (FLAG_trace_turbo) { |
| 1329 | Run<PrintGraphPhase>(phase); |
| 1330 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1331 | if (FLAG_turbo_verify) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1332 | Run<VerifyGraphPhase>(untyped); |
| 1333 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1336 | bool PipelineImpl::CreateGraph() { |
| 1337 | PipelineData* data = this->data_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1338 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1339 | data->BeginPhaseKind("graph creation"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1340 | |
| 1341 | if (FLAG_trace_turbo) { |
| 1342 | OFStream os(stdout); |
| 1343 | os << "---------------------------------------------------\n" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1344 | << "Begin compiling method " << info()->GetDebugName().get() |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1345 | << " using Turbofan" << std::endl; |
| 1346 | TurboCfgFile tcf(isolate()); |
| 1347 | tcf << AsC1VCompilation(info()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1350 | data->source_positions()->AddDecorator(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1351 | |
| 1352 | if (FLAG_loop_assignment_analysis) { |
| 1353 | Run<LoopAssignmentAnalysisPhase>(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1356 | Run<TypeHintAnalysisPhase>(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1357 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1358 | Run<GraphBuilderPhase>(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1359 | if (data->compilation_failed()) { |
| 1360 | data->EndPhaseKind(); |
| 1361 | return false; |
| 1362 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1363 | RunPrintAndVerify("Initial untyped", true); |
| 1364 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1365 | // Perform OSR deconstruction. |
| 1366 | if (info()->is_osr()) { |
| 1367 | Run<OsrDeconstructionPhase>(); |
| 1368 | RunPrintAndVerify("OSR deconstruction", true); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1371 | // Perform function context specialization and inlining (if enabled). |
| 1372 | Run<InliningPhase>(); |
| 1373 | RunPrintAndVerify("Inlined", true); |
| 1374 | |
| 1375 | // Remove dead->live edges from the graph. |
| 1376 | Run<EarlyGraphTrimmingPhase>(); |
| 1377 | RunPrintAndVerify("Early trimmed", true); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1378 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1379 | if (FLAG_print_turbo_replay) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1380 | // Print a replay of the initial graph. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1381 | GraphReplayPrinter::PrintReplay(data->graph()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1384 | // Run the type-sensitive lowerings and optimizations on the graph. |
| 1385 | { |
| 1386 | // Type the graph and keep the Typer running on newly created nodes within |
| 1387 | // this scope; the Typer is automatically unlinked from the Graph once we |
| 1388 | // leave this scope below. |
| 1389 | Typer typer(isolate(), data->graph(), info()->is_deoptimization_enabled() |
| 1390 | ? Typer::kDeoptimizationEnabled |
| 1391 | : Typer::kNoFlags, |
| 1392 | info()->dependencies()); |
| 1393 | Run<TyperPhase>(&typer); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1394 | RunPrintAndVerify("Typed"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1395 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1396 | data->BeginPhaseKind("lowering"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1397 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1398 | // Lower JSOperators where we can determine types. |
| 1399 | Run<TypedLoweringPhase>(); |
| 1400 | RunPrintAndVerify("Lowered typed"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1401 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1402 | if (FLAG_turbo_stress_loop_peeling) { |
| 1403 | Run<StressLoopPeelingPhase>(); |
| 1404 | RunPrintAndVerify("Loop peeled"); |
| 1405 | } |
| 1406 | |
| 1407 | if (FLAG_turbo_escape) { |
| 1408 | Run<EscapeAnalysisPhase>(); |
| 1409 | RunPrintAndVerify("Escape Analysed"); |
| 1410 | } |
| 1411 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1412 | // Select representations. |
| 1413 | Run<RepresentationSelectionPhase>(); |
| 1414 | RunPrintAndVerify("Representations selected"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1415 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1416 | // Run early optimization pass. |
| 1417 | Run<EarlyOptimizationPhase>(); |
| 1418 | RunPrintAndVerify("Early optimized"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1421 | #ifdef DEBUG |
| 1422 | // From now on it is invalid to look at types on the nodes, because: |
| 1423 | // |
| 1424 | // (a) The remaining passes (might) run concurrent to the main thread and |
| 1425 | // therefore must not access the Heap or the Isolate in an uncontrolled |
| 1426 | // way (as done by the type system), and |
| 1427 | // (b) the types on the nodes might not make sense after representation |
| 1428 | // selection due to the way we handle truncations; if we'd want to look |
| 1429 | // at types afterwards we'd essentially need to re-type (large portions |
| 1430 | // of) the graph. |
| 1431 | // |
| 1432 | // In order to catch bugs related to type access after this point we remove |
| 1433 | // the types from the nodes at this point (currently only in Debug builds). |
| 1434 | Run<UntyperPhase>(); |
| 1435 | RunPrintAndVerify("Untyped", true); |
| 1436 | #endif |
| 1437 | |
| 1438 | data->EndPhaseKind(); |
| 1439 | |
| 1440 | return true; |
| 1441 | } |
| 1442 | |
| 1443 | bool PipelineImpl::OptimizeGraph(Linkage* linkage) { |
| 1444 | PipelineData* data = this->data_; |
| 1445 | |
| 1446 | data->BeginPhaseKind("block building"); |
| 1447 | |
| 1448 | Run<EffectControlLinearizationPhase>(); |
| 1449 | RunPrintAndVerify("Effect and control linearized", true); |
| 1450 | |
| 1451 | Run<BranchEliminationPhase>(); |
| 1452 | RunPrintAndVerify("Branch conditions eliminated", true); |
| 1453 | |
| 1454 | // Optimize control flow. |
| 1455 | if (FLAG_turbo_cf_optimization) { |
| 1456 | Run<ControlFlowOptimizationPhase>(); |
| 1457 | RunPrintAndVerify("Control flow optimized", true); |
| 1458 | } |
| 1459 | |
| 1460 | // Optimize memory access and allocation operations. |
| 1461 | Run<MemoryOptimizationPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1462 | // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1463 | RunPrintAndVerify("Memory optimized", true); |
| 1464 | |
| 1465 | // Lower changes that have been inserted before. |
| 1466 | Run<LateOptimizationPhase>(); |
| 1467 | // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
| 1468 | RunPrintAndVerify("Late optimized", true); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1469 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1470 | Run<LateGraphTrimmingPhase>(); |
| 1471 | // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
| 1472 | RunPrintAndVerify("Late trimmed", true); |
| 1473 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1474 | data->source_positions()->RemoveDecorator(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1475 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1476 | return ScheduleAndSelectInstructions(linkage); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1479 | Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, |
| 1480 | CallDescriptor* call_descriptor, |
| 1481 | Graph* graph, Schedule* schedule, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1482 | Code::Flags flags, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1483 | const char* debug_name) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1484 | CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), flags); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1485 | |
| 1486 | // Construct a pipeline for scheduling and code generation. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1487 | ZonePool zone_pool(isolate->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1488 | PipelineData data(&zone_pool, &info, graph, schedule); |
| 1489 | base::SmartPointer<PipelineStatistics> pipeline_statistics; |
| 1490 | if (FLAG_turbo_stats) { |
| 1491 | pipeline_statistics.Reset(new PipelineStatistics(&info, &zone_pool)); |
| 1492 | pipeline_statistics->BeginPhaseKind("stub codegen"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1493 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1494 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1495 | PipelineImpl pipeline(&data); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1496 | DCHECK_NOT_NULL(data.schedule()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1497 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1498 | if (FLAG_trace_turbo) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1499 | TurboJsonFile json_of(&info, std::ios_base::trunc); |
| 1500 | json_of << "{\"function\":\"" << info.GetDebugName().get() |
| 1501 | << "\", \"source\":\"\",\n\"phases\":["; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1502 | pipeline.Run<PrintGraphPhase>("Machine"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1505 | pipeline.Run<VerifyGraphPhase>(false, true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1506 | return pipeline.ScheduleAndGenerateCode(call_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1509 | // static |
| 1510 | Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info) { |
| 1511 | ZonePool zone_pool(info->isolate()->allocator()); |
| 1512 | base::SmartPointer<PipelineStatistics> pipeline_statistics( |
| 1513 | CreatePipelineStatistics(info, &zone_pool)); |
| 1514 | PipelineData data(&zone_pool, info, pipeline_statistics.get()); |
| 1515 | PipelineImpl pipeline(&data); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1516 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1517 | Linkage linkage(Linkage::ComputeIncoming(data.instruction_zone(), info)); |
| 1518 | |
| 1519 | if (!pipeline.CreateGraph()) return Handle<Code>::null(); |
| 1520 | if (!pipeline.OptimizeGraph(&linkage)) return Handle<Code>::null(); |
| 1521 | return pipeline.GenerateCode(&linkage); |
| 1522 | } |
| 1523 | |
| 1524 | // static |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1525 | Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
| 1526 | Graph* graph, |
| 1527 | Schedule* schedule) { |
| 1528 | CallDescriptor* call_descriptor = |
| 1529 | Linkage::ComputeIncoming(info->zone(), info); |
| 1530 | return GenerateCodeForTesting(info, call_descriptor, graph, schedule); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1533 | // static |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1534 | Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
| 1535 | CallDescriptor* call_descriptor, |
| 1536 | Graph* graph, |
| 1537 | Schedule* schedule) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1538 | // Construct a pipeline for scheduling and code generation. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1539 | ZonePool zone_pool(info->isolate()->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1540 | PipelineData data(&zone_pool, info, graph, schedule); |
| 1541 | base::SmartPointer<PipelineStatistics> pipeline_statistics; |
| 1542 | if (FLAG_turbo_stats) { |
| 1543 | pipeline_statistics.Reset(new PipelineStatistics(info, &zone_pool)); |
| 1544 | pipeline_statistics->BeginPhaseKind("test codegen"); |
| 1545 | } |
| 1546 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1547 | PipelineImpl pipeline(&data); |
| 1548 | |
| 1549 | if (FLAG_trace_turbo) { |
| 1550 | TurboJsonFile json_of(info, std::ios_base::trunc); |
| 1551 | json_of << "{\"function\":\"" << info->GetDebugName().get() |
| 1552 | << "\", \"source\":\"\",\n\"phases\":["; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1553 | } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1554 | // TODO(rossberg): Should this really be untyped? |
| 1555 | pipeline.RunPrintAndVerify("Machine", true); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1556 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1557 | return pipeline.ScheduleAndGenerateCode(call_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1560 | // static |
| 1561 | CompilationJob* Pipeline::NewCompilationJob(Handle<JSFunction> function) { |
| 1562 | return new PipelineCompilationJob(function->GetIsolate(), function); |
| 1563 | } |
| 1564 | |
| 1565 | // static |
| 1566 | CompilationJob* Pipeline::NewWasmCompilationJob( |
| 1567 | CompilationInfo* info, Graph* graph, CallDescriptor* descriptor, |
| 1568 | SourcePositionTable* source_positions) { |
| 1569 | return new PipelineWasmCompilationJob(info, graph, descriptor, |
| 1570 | source_positions); |
| 1571 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1572 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1573 | bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, |
| 1574 | InstructionSequence* sequence, |
| 1575 | bool run_verifier) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1576 | CompilationInfo info(ArrayVector("testing"), sequence->isolate(), |
| 1577 | sequence->zone()); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1578 | ZonePool zone_pool(sequence->isolate()->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1579 | PipelineData data(&zone_pool, &info, sequence); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1580 | PipelineImpl pipeline(&data); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1581 | pipeline.data_->InitializeFrameData(nullptr); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1582 | pipeline.AllocateRegisters(config, nullptr, run_verifier); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1583 | return !data.compilation_failed(); |
| 1584 | } |
| 1585 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1586 | bool PipelineImpl::ScheduleAndSelectInstructions(Linkage* linkage) { |
| 1587 | CallDescriptor* call_descriptor = linkage->GetIncomingDescriptor(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1588 | PipelineData* data = this->data_; |
| 1589 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1590 | DCHECK_NOT_NULL(data->graph()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1591 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1592 | if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); |
| 1593 | TraceSchedule(data->info(), data->schedule()); |
| 1594 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1595 | if (FLAG_turbo_profiling) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1596 | data->set_profiler_data(BasicBlockInstrumentor::Instrument( |
| 1597 | info(), data->graph(), data->schedule())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1598 | } |
| 1599 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1600 | data->InitializeInstructionSequence(call_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1601 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1602 | data->InitializeFrameData(call_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1603 | // Select and schedule instructions covering the scheduled graph. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1604 | Run<InstructionSelectionPhase>(linkage); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1605 | |
| 1606 | if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1607 | AllowHandleDereference allow_deref; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1608 | TurboCfgFile tcf(isolate()); |
| 1609 | tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(), |
| 1610 | data->sequence()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1613 | if (FLAG_trace_turbo) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1614 | std::ostringstream source_position_output; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1615 | // Output source position information before the graph is deleted. |
| 1616 | data_->source_positions()->Print(source_position_output); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1617 | data_->set_source_position_output(source_position_output.str()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1620 | data->DeleteGraphZone(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1621 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1622 | data->BeginPhaseKind("register allocation"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1623 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1624 | bool run_verifier = FLAG_turbo_verify_allocation; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1625 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1626 | // Allocate registers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1627 | AllocateRegisters( |
| 1628 | RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN), |
| 1629 | call_descriptor, run_verifier); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1630 | Run<FrameElisionPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1631 | if (data->compilation_failed()) { |
| 1632 | info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1633 | data->EndPhaseKind(); |
| 1634 | return false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1637 | // TODO(mtrofin): move this off to the register allocator. |
| 1638 | bool generate_frame_at_start = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1639 | data_->sequence()->instruction_blocks().front()->must_construct_frame(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1640 | // Optimimize jumps. |
| 1641 | if (FLAG_turbo_jt) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1642 | Run<JumpThreadingPhase>(generate_frame_at_start); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1643 | } |
| 1644 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1645 | data->EndPhaseKind(); |
| 1646 | |
| 1647 | return true; |
| 1648 | } |
| 1649 | |
| 1650 | Handle<Code> PipelineImpl::GenerateCode(Linkage* linkage) { |
| 1651 | PipelineData* data = this->data_; |
| 1652 | |
| 1653 | data->BeginPhaseKind("code generation"); |
| 1654 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1655 | // Generate final machine code. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1656 | Run<GenerateCodePhase>(linkage); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1657 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1658 | Handle<Code> code = data->code(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1659 | if (data->profiler_data()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1660 | #if ENABLE_DISASSEMBLER |
| 1661 | std::ostringstream os; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1662 | code->Disassemble(nullptr, os); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1663 | data->profiler_data()->SetCode(&os); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1664 | #endif |
| 1665 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1666 | |
| 1667 | info()->SetCode(code); |
| 1668 | v8::internal::CodeGenerator::PrintCode(code, info()); |
| 1669 | |
| 1670 | if (FLAG_trace_turbo) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1671 | TurboJsonFile json_of(info(), std::ios_base::app); |
| 1672 | json_of << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\""; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1673 | #if ENABLE_DISASSEMBLER |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1674 | std::stringstream disassembly_stream; |
| 1675 | code->Disassemble(nullptr, disassembly_stream); |
| 1676 | std::string disassembly_string(disassembly_stream.str()); |
| 1677 | for (const auto& c : disassembly_string) { |
| 1678 | json_of << AsEscapedUC16ForJSON(c); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1679 | } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1680 | #endif // ENABLE_DISASSEMBLER |
| 1681 | json_of << "\"}\n],\n"; |
| 1682 | json_of << "\"nodePositions\":"; |
| 1683 | json_of << data->source_position_output(); |
| 1684 | json_of << "}"; |
| 1685 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1686 | OFStream os(stdout); |
| 1687 | os << "---------------------------------------------------\n" |
| 1688 | << "Finished compiling method " << info()->GetDebugName().get() |
| 1689 | << " using Turbofan" << std::endl; |
| 1690 | } |
| 1691 | |
| 1692 | return code; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1695 | Handle<Code> PipelineImpl::ScheduleAndGenerateCode( |
| 1696 | CallDescriptor* call_descriptor) { |
| 1697 | Linkage linkage(call_descriptor); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1698 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1699 | // Schedule the graph, perform instruction selection and register allocation. |
| 1700 | if (!ScheduleAndSelectInstructions(&linkage)) return Handle<Code>(); |
| 1701 | |
| 1702 | // Generate the final machine code. |
| 1703 | return GenerateCode(&linkage); |
| 1704 | } |
| 1705 | |
| 1706 | void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, |
| 1707 | CallDescriptor* descriptor, |
| 1708 | bool run_verifier) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1709 | PipelineData* data = this->data_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1710 | // Don't track usage for this zone in compiler stats. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1711 | base::SmartPointer<Zone> verifier_zone; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1712 | RegisterAllocatorVerifier* verifier = nullptr; |
| 1713 | if (run_verifier) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1714 | verifier_zone.Reset(new Zone(isolate()->allocator())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1715 | verifier = new (verifier_zone.get()) RegisterAllocatorVerifier( |
| 1716 | verifier_zone.get(), config, data->sequence()); |
| 1717 | } |
| 1718 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1719 | #ifdef DEBUG |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1720 | data_->sequence()->ValidateEdgeSplitForm(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1721 | data_->sequence()->ValidateDeferredBlockEntryPaths(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1722 | data_->sequence()->ValidateDeferredBlockExitPaths(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1723 | #endif |
| 1724 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1725 | data->InitializeRegisterAllocationData(config, descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1726 | if (info()->is_osr()) { |
| 1727 | OsrHelper osr_helper(info()); |
| 1728 | osr_helper.SetupFrame(data->frame()); |
| 1729 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1730 | |
| 1731 | Run<MeetRegisterConstraintsPhase>(); |
| 1732 | Run<ResolvePhisPhase>(); |
| 1733 | Run<BuildLiveRangesPhase>(); |
| 1734 | if (FLAG_trace_turbo_graph) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1735 | AllowHandleDereference allow_deref; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1736 | OFStream os(stdout); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1737 | os << "----- Instruction sequence before register allocation -----\n" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1738 | << PrintableInstructionSequence({config, data->sequence()}); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1739 | } |
| 1740 | if (verifier != nullptr) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1741 | CHECK(!data->register_allocation_data()->ExistsUseWithoutDefinition()); |
| 1742 | CHECK(data->register_allocation_data() |
| 1743 | ->RangesDefinedInDeferredStayInDeferred()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1744 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1745 | |
| 1746 | if (FLAG_turbo_preprocess_ranges) { |
| 1747 | Run<SplinterLiveRangesPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1748 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1749 | |
| 1750 | if (FLAG_turbo_greedy_regalloc) { |
| 1751 | Run<AllocateGeneralRegistersPhase<GreedyAllocator>>(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1752 | Run<AllocateFPRegistersPhase<GreedyAllocator>>(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1753 | } else { |
| 1754 | Run<AllocateGeneralRegistersPhase<LinearScanAllocator>>(); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1755 | Run<AllocateFPRegistersPhase<LinearScanAllocator>>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1756 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1757 | |
| 1758 | if (FLAG_turbo_preprocess_ranges) { |
| 1759 | Run<MergeSplintersPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1760 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1761 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1762 | Run<AssignSpillSlotsPhase>(); |
| 1763 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1764 | Run<CommitAssignmentPhase>(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1765 | Run<PopulateReferenceMapsPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1766 | Run<ConnectRangesPhase>(); |
| 1767 | Run<ResolveControlFlowPhase>(); |
| 1768 | if (FLAG_turbo_move_optimization) { |
| 1769 | Run<OptimizeMovesPhase>(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1772 | Run<LocateSpillSlotsPhase>(); |
| 1773 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1774 | if (FLAG_trace_turbo_graph) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1775 | AllowHandleDereference allow_deref; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1776 | OFStream os(stdout); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1777 | os << "----- Instruction sequence after register allocation -----\n" |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1778 | << PrintableInstructionSequence({config, data->sequence()}); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | if (verifier != nullptr) { |
| 1782 | verifier->VerifyAssignment(); |
| 1783 | verifier->VerifyGapMoves(); |
| 1784 | } |
| 1785 | |
| 1786 | if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { |
| 1787 | TurboCfgFile tcf(data->isolate()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1788 | tcf << AsC1VRegisterAllocationData("CodeGen", |
| 1789 | data->register_allocation_data()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1790 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1791 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1792 | data->DeleteRegisterAllocationZone(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1795 | CompilationInfo* PipelineImpl::info() const { return data_->info(); } |
| 1796 | |
| 1797 | Isolate* PipelineImpl::isolate() const { return info()->isolate(); } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1798 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1799 | } // namespace compiler |
| 1800 | } // namespace internal |
| 1801 | } // namespace v8 |