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/change-lowering.h" |
| 18 | #include "src/compiler/code-generator.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 19 | #include "src/compiler/common-operator-reducer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 20 | #include "src/compiler/control-flow-optimizer.h" |
| 21 | #include "src/compiler/dead-code-elimination.h" |
| 22 | #include "src/compiler/escape-analysis.h" |
| 23 | #include "src/compiler/escape-analysis-reducer.h" |
| 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.h" |
| 30 | #include "src/compiler/instruction-selector.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" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 48 | #include "src/compiler/move-optimizer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 49 | #include "src/compiler/osr.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 50 | #include "src/compiler/pipeline-statistics.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 51 | #include "src/compiler/register-allocator.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 52 | #include "src/compiler/register-allocator-verifier.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 53 | #include "src/compiler/schedule.h" |
| 54 | #include "src/compiler/scheduler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 55 | #include "src/compiler/select-lowering.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | #include "src/compiler/simplified-lowering.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 57 | #include "src/compiler/simplified-operator.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | #include "src/compiler/simplified-operator-reducer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 59 | #include "src/compiler/tail-call-optimization.h" |
| 60 | #include "src/compiler/type-hint-analyzer.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | #include "src/compiler/typer.h" |
| 62 | #include "src/compiler/value-numbering-reducer.h" |
| 63 | #include "src/compiler/verifier.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 64 | #include "src/compiler/zone-pool.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 65 | #include "src/ostreams.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 66 | #include "src/register-configuration.h" |
| 67 | #include "src/type-info.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | #include "src/utils.h" |
| 69 | |
| 70 | namespace v8 { |
| 71 | namespace internal { |
| 72 | namespace compiler { |
| 73 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 74 | class PipelineData { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 75 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 76 | // For main entry point. |
| 77 | PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
| 78 | PipelineStatistics* pipeline_statistics) |
| 79 | : isolate_(info->isolate()), |
| 80 | info_(info), |
| 81 | outer_zone_(info_->zone()), |
| 82 | zone_pool_(zone_pool), |
| 83 | pipeline_statistics_(pipeline_statistics), |
| 84 | compilation_failed_(false), |
| 85 | code_(Handle<Code>::null()), |
| 86 | graph_zone_scope_(zone_pool_), |
| 87 | graph_zone_(graph_zone_scope_.zone()), |
| 88 | graph_(nullptr), |
| 89 | loop_assignment_(nullptr), |
| 90 | simplified_(nullptr), |
| 91 | machine_(nullptr), |
| 92 | common_(nullptr), |
| 93 | javascript_(nullptr), |
| 94 | jsgraph_(nullptr), |
| 95 | schedule_(nullptr), |
| 96 | instruction_zone_scope_(zone_pool_), |
| 97 | instruction_zone_(instruction_zone_scope_.zone()), |
| 98 | sequence_(nullptr), |
| 99 | frame_(nullptr), |
| 100 | register_allocation_zone_scope_(zone_pool_), |
| 101 | register_allocation_zone_(register_allocation_zone_scope_.zone()), |
| 102 | register_allocation_data_(nullptr) { |
| 103 | PhaseScope scope(pipeline_statistics, "init pipeline data"); |
| 104 | graph_ = new (graph_zone_) Graph(graph_zone_); |
| 105 | source_positions_.Reset(new SourcePositionTable(graph_)); |
| 106 | simplified_ = new (graph_zone_) SimplifiedOperatorBuilder(graph_zone_); |
| 107 | machine_ = new (graph_zone_) MachineOperatorBuilder( |
| 108 | graph_zone_, MachineType::PointerRepresentation(), |
| 109 | InstructionSelector::SupportedMachineOperatorFlags()); |
| 110 | common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); |
| 111 | javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); |
| 112 | jsgraph_ = new (graph_zone_) |
| 113 | JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_); |
| 114 | } |
| 115 | |
| 116 | // For machine graph testing entry point. |
| 117 | PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, |
| 118 | Schedule* schedule) |
| 119 | : isolate_(info->isolate()), |
| 120 | info_(info), |
| 121 | outer_zone_(nullptr), |
| 122 | zone_pool_(zone_pool), |
| 123 | pipeline_statistics_(nullptr), |
| 124 | compilation_failed_(false), |
| 125 | code_(Handle<Code>::null()), |
| 126 | graph_zone_scope_(zone_pool_), |
| 127 | graph_zone_(nullptr), |
| 128 | graph_(graph), |
| 129 | source_positions_(new SourcePositionTable(graph_)), |
| 130 | loop_assignment_(nullptr), |
| 131 | simplified_(nullptr), |
| 132 | machine_(nullptr), |
| 133 | common_(nullptr), |
| 134 | javascript_(nullptr), |
| 135 | jsgraph_(nullptr), |
| 136 | schedule_(schedule), |
| 137 | instruction_zone_scope_(zone_pool_), |
| 138 | instruction_zone_(instruction_zone_scope_.zone()), |
| 139 | sequence_(nullptr), |
| 140 | frame_(nullptr), |
| 141 | register_allocation_zone_scope_(zone_pool_), |
| 142 | register_allocation_zone_(register_allocation_zone_scope_.zone()), |
| 143 | register_allocation_data_(nullptr) {} |
| 144 | |
| 145 | // For register allocation testing entry point. |
| 146 | PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
| 147 | InstructionSequence* sequence) |
| 148 | : isolate_(info->isolate()), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 149 | info_(info), |
| 150 | outer_zone_(nullptr), |
| 151 | zone_pool_(zone_pool), |
| 152 | pipeline_statistics_(nullptr), |
| 153 | compilation_failed_(false), |
| 154 | code_(Handle<Code>::null()), |
| 155 | graph_zone_scope_(zone_pool_), |
| 156 | graph_zone_(nullptr), |
| 157 | graph_(nullptr), |
| 158 | loop_assignment_(nullptr), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 159 | simplified_(nullptr), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 160 | machine_(nullptr), |
| 161 | common_(nullptr), |
| 162 | javascript_(nullptr), |
| 163 | jsgraph_(nullptr), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 164 | schedule_(nullptr), |
| 165 | instruction_zone_scope_(zone_pool_), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 166 | instruction_zone_(sequence->zone()), |
| 167 | sequence_(sequence), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 168 | frame_(nullptr), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 169 | register_allocation_zone_scope_(zone_pool_), |
| 170 | register_allocation_zone_(register_allocation_zone_scope_.zone()), |
| 171 | register_allocation_data_(nullptr) {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 172 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 173 | ~PipelineData() { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 174 | DeleteRegisterAllocationZone(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 175 | DeleteInstructionZone(); |
| 176 | DeleteGraphZone(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 179 | Isolate* isolate() const { return isolate_; } |
| 180 | CompilationInfo* info() const { return info_; } |
| 181 | ZonePool* zone_pool() const { return zone_pool_; } |
| 182 | PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } |
| 183 | bool compilation_failed() const { return compilation_failed_; } |
| 184 | void set_compilation_failed() { compilation_failed_ = true; } |
| 185 | Handle<Code> code() { return code_; } |
| 186 | void set_code(Handle<Code> code) { |
| 187 | DCHECK(code_.is_null()); |
| 188 | code_ = code; |
| 189 | } |
| 190 | |
| 191 | // RawMachineAssembler generally produces graphs which cannot be verified. |
| 192 | bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } |
| 193 | |
| 194 | Zone* graph_zone() const { return graph_zone_; } |
| 195 | Graph* graph() const { return graph_; } |
| 196 | SourcePositionTable* source_positions() const { |
| 197 | return source_positions_.get(); |
| 198 | } |
| 199 | MachineOperatorBuilder* machine() const { return machine_; } |
| 200 | CommonOperatorBuilder* common() const { return common_; } |
| 201 | JSOperatorBuilder* javascript() const { return javascript_; } |
| 202 | JSGraph* jsgraph() const { return jsgraph_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 203 | MaybeHandle<Context> native_context() const { |
| 204 | if (info()->is_native_context_specializing()) { |
| 205 | return handle(info()->native_context(), isolate()); |
| 206 | } |
| 207 | return MaybeHandle<Context>(); |
| 208 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 209 | |
| 210 | LoopAssignmentAnalysis* loop_assignment() const { return loop_assignment_; } |
| 211 | void set_loop_assignment(LoopAssignmentAnalysis* loop_assignment) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 212 | DCHECK(!loop_assignment_); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 213 | loop_assignment_ = loop_assignment; |
| 214 | } |
| 215 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 216 | TypeHintAnalysis* type_hint_analysis() const { return type_hint_analysis_; } |
| 217 | void set_type_hint_analysis(TypeHintAnalysis* type_hint_analysis) { |
| 218 | DCHECK_NULL(type_hint_analysis_); |
| 219 | type_hint_analysis_ = type_hint_analysis; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | Schedule* schedule() const { return schedule_; } |
| 223 | void set_schedule(Schedule* schedule) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 224 | DCHECK(!schedule_); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 225 | schedule_ = schedule; |
| 226 | } |
| 227 | |
| 228 | Zone* instruction_zone() const { return instruction_zone_; } |
| 229 | InstructionSequence* sequence() const { return sequence_; } |
| 230 | Frame* frame() const { return frame_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 231 | |
| 232 | Zone* register_allocation_zone() const { return register_allocation_zone_; } |
| 233 | RegisterAllocationData* register_allocation_data() const { |
| 234 | return register_allocation_data_; |
| 235 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 236 | |
| 237 | void DeleteGraphZone() { |
| 238 | // Destroy objects with destructors first. |
| 239 | source_positions_.Reset(nullptr); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 240 | if (graph_zone_ == nullptr) return; |
| 241 | // Destroy zone and clear pointers. |
| 242 | graph_zone_scope_.Destroy(); |
| 243 | graph_zone_ = nullptr; |
| 244 | graph_ = nullptr; |
| 245 | loop_assignment_ = nullptr; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 246 | type_hint_analysis_ = nullptr; |
| 247 | simplified_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 248 | machine_ = nullptr; |
| 249 | common_ = nullptr; |
| 250 | javascript_ = nullptr; |
| 251 | jsgraph_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 252 | schedule_ = nullptr; |
| 253 | } |
| 254 | |
| 255 | void DeleteInstructionZone() { |
| 256 | if (instruction_zone_ == nullptr) return; |
| 257 | instruction_zone_scope_.Destroy(); |
| 258 | instruction_zone_ = nullptr; |
| 259 | sequence_ = nullptr; |
| 260 | frame_ = nullptr; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void DeleteRegisterAllocationZone() { |
| 264 | if (register_allocation_zone_ == nullptr) return; |
| 265 | register_allocation_zone_scope_.Destroy(); |
| 266 | register_allocation_zone_ = nullptr; |
| 267 | register_allocation_data_ = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 268 | } |
| 269 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 270 | void InitializeInstructionSequence(const CallDescriptor* descriptor) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 271 | DCHECK(sequence_ == nullptr); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 272 | InstructionBlocks* instruction_blocks = |
| 273 | InstructionSequence::InstructionBlocksFor(instruction_zone(), |
| 274 | schedule()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 275 | sequence_ = new (instruction_zone()) InstructionSequence( |
| 276 | info()->isolate(), instruction_zone(), instruction_blocks); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 277 | if (descriptor && descriptor->RequiresFrameAsIncoming()) { |
| 278 | sequence_->instruction_blocks()[0]->mark_needs_frame(); |
| 279 | } else { |
| 280 | DCHECK_EQ(0, descriptor->CalleeSavedFPRegisters()); |
| 281 | DCHECK_EQ(0, descriptor->CalleeSavedRegisters()); |
| 282 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 285 | void InitializeFrameData(CallDescriptor* descriptor) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 286 | DCHECK(frame_ == nullptr); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 287 | int fixed_frame_size = 0; |
| 288 | if (descriptor != nullptr) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 289 | fixed_frame_size = CalculateFixedFrameSize(descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 290 | } |
| 291 | frame_ = new (instruction_zone()) Frame(fixed_frame_size, descriptor); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void InitializeRegisterAllocationData(const RegisterConfiguration* config, |
| 295 | CallDescriptor* descriptor, |
| 296 | const char* debug_name) { |
| 297 | DCHECK(register_allocation_data_ == nullptr); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 298 | register_allocation_data_ = new (register_allocation_zone()) |
| 299 | RegisterAllocationData(config, register_allocation_zone(), frame(), |
| 300 | sequence(), debug_name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | private: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 304 | Isolate* isolate_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 305 | CompilationInfo* info_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 306 | Zone* outer_zone_; |
| 307 | ZonePool* const zone_pool_; |
| 308 | PipelineStatistics* pipeline_statistics_; |
| 309 | bool compilation_failed_; |
| 310 | Handle<Code> code_; |
| 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_; |
| 315 | Zone* graph_zone_; |
| 316 | Graph* graph_; |
| 317 | // TODO(dcarney): make this into a ZoneObject. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 318 | base::SmartPointer<SourcePositionTable> source_positions_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 319 | LoopAssignmentAnalysis* loop_assignment_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 320 | TypeHintAnalysis* type_hint_analysis_ = nullptr; |
| 321 | SimplifiedOperatorBuilder* simplified_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 322 | MachineOperatorBuilder* machine_; |
| 323 | CommonOperatorBuilder* common_; |
| 324 | JSOperatorBuilder* javascript_; |
| 325 | JSGraph* jsgraph_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 326 | Schedule* schedule_; |
| 327 | |
| 328 | // All objects in the following group of fields are allocated in |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 329 | // instruction_zone_. They are all set to nullptr when the instruction_zone_ |
| 330 | // is |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 331 | // destroyed. |
| 332 | ZonePool::Scope instruction_zone_scope_; |
| 333 | Zone* instruction_zone_; |
| 334 | InstructionSequence* sequence_; |
| 335 | Frame* frame_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 336 | |
| 337 | // All objects in the following group of fields are allocated in |
| 338 | // register_allocation_zone_. They are all set to nullptr when the zone is |
| 339 | // destroyed. |
| 340 | ZonePool::Scope register_allocation_zone_scope_; |
| 341 | Zone* register_allocation_zone_; |
| 342 | RegisterAllocationData* register_allocation_data_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 343 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 344 | int CalculateFixedFrameSize(CallDescriptor* descriptor) { |
| 345 | if (descriptor->IsJSFunctionCall()) { |
| 346 | return StandardFrameConstants::kFixedSlotCount; |
| 347 | } |
| 348 | return descriptor->IsCFunctionCall() |
| 349 | ? (CommonFrameConstants::kFixedSlotCountAboveFp + |
| 350 | CommonFrameConstants::kCPSlotCount) |
| 351 | : TypedFrameConstants::kFixedSlotCount; |
| 352 | } |
| 353 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 354 | DISALLOW_COPY_AND_ASSIGN(PipelineData); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 358 | namespace { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 359 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 360 | struct TurboCfgFile : public std::ofstream { |
| 361 | explicit TurboCfgFile(Isolate* isolate) |
| 362 | : std::ofstream(isolate->GetTurboCfgFileName().c_str(), |
| 363 | std::ios_base::app) {} |
| 364 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 365 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 366 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 367 | void TraceSchedule(CompilationInfo* info, Schedule* schedule) { |
| 368 | if (FLAG_trace_turbo) { |
| 369 | FILE* json_file = OpenVisualizerLogFile(info, nullptr, "json", "a+"); |
| 370 | if (json_file != nullptr) { |
| 371 | OFStream json_of(json_file); |
| 372 | json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\""; |
| 373 | std::stringstream schedule_stream; |
| 374 | schedule_stream << *schedule; |
| 375 | std::string schedule_string(schedule_stream.str()); |
| 376 | for (const auto& c : schedule_string) { |
| 377 | json_of << AsEscapedUC16ForJSON(c); |
| 378 | } |
| 379 | json_of << "\"},\n"; |
| 380 | fclose(json_file); |
| 381 | } |
| 382 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 383 | if (!FLAG_trace_turbo_graph && !FLAG_trace_turbo_scheduler) return; |
| 384 | OFStream os(stdout); |
| 385 | os << "-- Schedule --------------------------------------\n" << *schedule; |
| 386 | } |
| 387 | |
| 388 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 389 | class AstGraphBuilderWithPositions final : public AstGraphBuilder { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 390 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 391 | AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, |
| 392 | JSGraph* jsgraph, |
| 393 | LoopAssignmentAnalysis* loop_assignment, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 394 | TypeHintAnalysis* type_hint_analysis, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 395 | SourcePositionTable* source_positions) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 396 | : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment, |
| 397 | type_hint_analysis), |
| 398 | source_positions_(source_positions), |
| 399 | start_position_(info->shared_info()->start_position()) {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 400 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 401 | bool CreateGraph(bool stack_check) { |
| 402 | SourcePositionTable::Scope pos_scope(source_positions_, start_position_); |
| 403 | return AstGraphBuilder::CreateGraph(stack_check); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | #define DEF_VISIT(type) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 407 | void Visit##type(type* node) override { \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 408 | SourcePositionTable::Scope pos(source_positions_, \ |
| 409 | SourcePosition(node->position())); \ |
| 410 | AstGraphBuilder::Visit##type(node); \ |
| 411 | } |
| 412 | AST_NODE_LIST(DEF_VISIT) |
| 413 | #undef DEF_VISIT |
| 414 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 415 | private: |
| 416 | SourcePositionTable* const source_positions_; |
| 417 | SourcePosition const start_position_; |
| 418 | }; |
| 419 | |
| 420 | |
| 421 | class SourcePositionWrapper final : public Reducer { |
| 422 | public: |
| 423 | SourcePositionWrapper(Reducer* reducer, SourcePositionTable* table) |
| 424 | : reducer_(reducer), table_(table) {} |
| 425 | ~SourcePositionWrapper() final {} |
| 426 | |
| 427 | Reduction Reduce(Node* node) final { |
| 428 | SourcePosition const pos = table_->GetSourcePosition(node); |
| 429 | SourcePositionTable::Scope position(table_, pos); |
| 430 | return reducer_->Reduce(node); |
| 431 | } |
| 432 | |
| 433 | void Finalize() final { reducer_->Finalize(); } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 434 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 435 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 436 | Reducer* const reducer_; |
| 437 | SourcePositionTable* const table_; |
| 438 | |
| 439 | DISALLOW_COPY_AND_ASSIGN(SourcePositionWrapper); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 443 | class JSGraphReducer final : public GraphReducer { |
| 444 | public: |
| 445 | JSGraphReducer(JSGraph* jsgraph, Zone* zone) |
| 446 | : GraphReducer(zone, jsgraph->graph(), jsgraph->Dead()) {} |
| 447 | ~JSGraphReducer() final {} |
| 448 | }; |
| 449 | |
| 450 | |
| 451 | void AddReducer(PipelineData* data, GraphReducer* graph_reducer, |
| 452 | Reducer* reducer) { |
| 453 | if (data->info()->is_source_positions_enabled()) { |
| 454 | void* const buffer = data->graph_zone()->New(sizeof(SourcePositionWrapper)); |
| 455 | SourcePositionWrapper* const wrapper = |
| 456 | new (buffer) SourcePositionWrapper(reducer, data->source_positions()); |
| 457 | graph_reducer->AddReducer(wrapper); |
| 458 | } else { |
| 459 | graph_reducer->AddReducer(reducer); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 464 | class PipelineRunScope { |
| 465 | public: |
| 466 | PipelineRunScope(PipelineData* data, const char* phase_name) |
| 467 | : phase_scope_( |
| 468 | phase_name == nullptr ? nullptr : data->pipeline_statistics(), |
| 469 | phase_name), |
| 470 | zone_scope_(data->zone_pool()) {} |
| 471 | |
| 472 | Zone* zone() { return zone_scope_.zone(); } |
| 473 | |
| 474 | private: |
| 475 | PhaseScope phase_scope_; |
| 476 | ZonePool::Scope zone_scope_; |
| 477 | }; |
| 478 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 479 | } // namespace |
| 480 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 481 | |
| 482 | template <typename Phase> |
| 483 | void Pipeline::Run() { |
| 484 | PipelineRunScope scope(this->data_, Phase::phase_name()); |
| 485 | Phase phase; |
| 486 | phase.Run(this->data_, scope.zone()); |
| 487 | } |
| 488 | |
| 489 | |
| 490 | template <typename Phase, typename Arg0> |
| 491 | void Pipeline::Run(Arg0 arg_0) { |
| 492 | PipelineRunScope scope(this->data_, Phase::phase_name()); |
| 493 | Phase phase; |
| 494 | phase.Run(this->data_, scope.zone(), arg_0); |
| 495 | } |
| 496 | |
| 497 | |
| 498 | struct LoopAssignmentAnalysisPhase { |
| 499 | static const char* phase_name() { return "loop assignment analysis"; } |
| 500 | |
| 501 | void Run(PipelineData* data, Zone* temp_zone) { |
| 502 | AstLoopAssignmentAnalyzer analyzer(data->graph_zone(), data->info()); |
| 503 | LoopAssignmentAnalysis* loop_assignment = analyzer.Analyze(); |
| 504 | data->set_loop_assignment(loop_assignment); |
| 505 | } |
| 506 | }; |
| 507 | |
| 508 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 509 | struct TypeHintAnalysisPhase { |
| 510 | static const char* phase_name() { return "type hint analysis"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 511 | |
| 512 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 513 | TypeHintAnalyzer analyzer(data->graph_zone()); |
| 514 | Handle<Code> code(data->info()->shared_info()->code(), data->isolate()); |
| 515 | TypeHintAnalysis* type_hint_analysis = analyzer.Analyze(code); |
| 516 | data->set_type_hint_analysis(type_hint_analysis); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 517 | } |
| 518 | }; |
| 519 | |
| 520 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 521 | struct GraphBuilderPhase { |
| 522 | static const char* phase_name() { return "graph builder"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 523 | |
| 524 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 525 | bool stack_check = !data->info()->IsStub(); |
| 526 | bool succeeded = false; |
| 527 | |
| 528 | if (data->info()->shared_info()->HasBytecodeArray()) { |
| 529 | BytecodeGraphBuilder graph_builder(temp_zone, data->info(), |
| 530 | data->jsgraph()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 531 | succeeded = graph_builder.CreateGraph(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 532 | } else { |
| 533 | AstGraphBuilderWithPositions graph_builder( |
| 534 | temp_zone, data->info(), data->jsgraph(), data->loop_assignment(), |
| 535 | data->type_hint_analysis(), data->source_positions()); |
| 536 | succeeded = graph_builder.CreateGraph(stack_check); |
| 537 | } |
| 538 | |
| 539 | if (!succeeded) { |
| 540 | data->set_compilation_failed(); |
| 541 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 542 | } |
| 543 | }; |
| 544 | |
| 545 | |
| 546 | struct InliningPhase { |
| 547 | static const char* phase_name() { return "inlining"; } |
| 548 | |
| 549 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 550 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 551 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 552 | data->common()); |
| 553 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 554 | data->common(), data->machine()); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 555 | JSCallReducer call_reducer(data->jsgraph(), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 556 | data->info()->is_deoptimization_enabled() |
| 557 | ? JSCallReducer::kDeoptimizationEnabled |
| 558 | : JSCallReducer::kNoFlags, |
| 559 | data->native_context()); |
| 560 | JSContextSpecialization context_specialization( |
| 561 | &graph_reducer, data->jsgraph(), |
| 562 | data->info()->is_function_context_specializing() |
| 563 | ? data->info()->context() |
| 564 | : MaybeHandle<Context>()); |
| 565 | JSFrameSpecialization frame_specialization(data->info()->osr_frame(), |
| 566 | data->jsgraph()); |
| 567 | JSGlobalObjectSpecialization global_object_specialization( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 568 | &graph_reducer, data->jsgraph(), data->native_context(), |
| 569 | data->info()->dependencies()); |
| 570 | JSNativeContextSpecialization::Flags flags = |
| 571 | JSNativeContextSpecialization::kNoFlags; |
| 572 | if (data->info()->is_bailout_on_uninitialized()) { |
| 573 | flags |= JSNativeContextSpecialization::kBailoutOnUninitialized; |
| 574 | } |
| 575 | if (data->info()->is_deoptimization_enabled()) { |
| 576 | flags |= JSNativeContextSpecialization::kDeoptimizationEnabled; |
| 577 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 578 | JSNativeContextSpecialization native_context_specialization( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 579 | &graph_reducer, data->jsgraph(), flags, data->native_context(), |
| 580 | data->info()->dependencies(), temp_zone); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 581 | JSInliningHeuristic inlining(&graph_reducer, |
| 582 | data->info()->is_inlining_enabled() |
| 583 | ? JSInliningHeuristic::kGeneralInlining |
| 584 | : JSInliningHeuristic::kRestrictedInlining, |
| 585 | temp_zone, data->info(), data->jsgraph()); |
| 586 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 587 | AddReducer(data, &graph_reducer, &common_reducer); |
| 588 | if (data->info()->is_frame_specializing()) { |
| 589 | AddReducer(data, &graph_reducer, &frame_specialization); |
| 590 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 591 | if (data->info()->is_deoptimization_enabled()) { |
| 592 | AddReducer(data, &graph_reducer, &global_object_specialization); |
| 593 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 594 | AddReducer(data, &graph_reducer, &native_context_specialization); |
| 595 | AddReducer(data, &graph_reducer, &context_specialization); |
| 596 | AddReducer(data, &graph_reducer, &call_reducer); |
| 597 | AddReducer(data, &graph_reducer, &inlining); |
| 598 | graph_reducer.ReduceGraph(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 599 | } |
| 600 | }; |
| 601 | |
| 602 | |
| 603 | struct TyperPhase { |
| 604 | static const char* phase_name() { return "typer"; } |
| 605 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 606 | void Run(PipelineData* data, Zone* temp_zone, Typer* typer) { |
| 607 | NodeVector roots(temp_zone); |
| 608 | data->jsgraph()->GetCachedNodes(&roots); |
| 609 | typer->Run(roots); |
| 610 | } |
| 611 | }; |
| 612 | |
| 613 | |
| 614 | struct OsrDeconstructionPhase { |
| 615 | static const char* phase_name() { return "OSR deconstruction"; } |
| 616 | |
| 617 | void Run(PipelineData* data, Zone* temp_zone) { |
| 618 | OsrHelper osr_helper(data->info()); |
| 619 | osr_helper.Deconstruct(data->jsgraph(), data->common(), temp_zone); |
| 620 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 621 | }; |
| 622 | |
| 623 | |
| 624 | struct TypedLoweringPhase { |
| 625 | static const char* phase_name() { return "typed lowering"; } |
| 626 | |
| 627 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 628 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 629 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 630 | data->common()); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 631 | LoadElimination load_elimination(&graph_reducer, data->graph(), |
| 632 | data->common()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 633 | JSBuiltinReducer builtin_reducer(&graph_reducer, data->jsgraph()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 634 | MaybeHandle<LiteralsArray> literals_array = |
| 635 | data->info()->is_native_context_specializing() |
| 636 | ? handle(data->info()->closure()->literals(), data->isolate()) |
| 637 | : MaybeHandle<LiteralsArray>(); |
| 638 | JSCreateLowering create_lowering( |
| 639 | &graph_reducer, data->info()->dependencies(), data->jsgraph(), |
| 640 | literals_array, temp_zone); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 641 | JSTypedLowering::Flags typed_lowering_flags = JSTypedLowering::kNoFlags; |
| 642 | if (data->info()->is_deoptimization_enabled()) { |
| 643 | typed_lowering_flags |= JSTypedLowering::kDeoptimizationEnabled; |
| 644 | } |
| 645 | if (data->info()->shared_info()->HasBytecodeArray()) { |
| 646 | typed_lowering_flags |= JSTypedLowering::kDisableBinaryOpReduction; |
| 647 | } |
| 648 | JSTypedLowering typed_lowering(&graph_reducer, data->info()->dependencies(), |
| 649 | typed_lowering_flags, data->jsgraph(), |
| 650 | temp_zone); |
| 651 | JSIntrinsicLowering intrinsic_lowering( |
| 652 | &graph_reducer, data->jsgraph(), |
| 653 | data->info()->is_deoptimization_enabled() |
| 654 | ? JSIntrinsicLowering::kDeoptimizationEnabled |
| 655 | : JSIntrinsicLowering::kDeoptimizationDisabled); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 656 | SimplifiedOperatorReducer simple_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 657 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 658 | data->common(), data->machine()); |
| 659 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 660 | AddReducer(data, &graph_reducer, &builtin_reducer); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 661 | if (data->info()->is_deoptimization_enabled()) { |
| 662 | AddReducer(data, &graph_reducer, &create_lowering); |
| 663 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 664 | AddReducer(data, &graph_reducer, &typed_lowering); |
| 665 | AddReducer(data, &graph_reducer, &intrinsic_lowering); |
| 666 | AddReducer(data, &graph_reducer, &load_elimination); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 667 | AddReducer(data, &graph_reducer, &simple_reducer); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 668 | AddReducer(data, &graph_reducer, &common_reducer); |
| 669 | graph_reducer.ReduceGraph(); |
| 670 | } |
| 671 | }; |
| 672 | |
| 673 | |
| 674 | struct BranchEliminationPhase { |
| 675 | static const char* phase_name() { return "branch condition elimination"; } |
| 676 | |
| 677 | void Run(PipelineData* data, Zone* temp_zone) { |
| 678 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 679 | BranchElimination branch_condition_elimination(&graph_reducer, |
| 680 | data->jsgraph(), temp_zone); |
| 681 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 682 | data->common()); |
| 683 | AddReducer(data, &graph_reducer, &branch_condition_elimination); |
| 684 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 685 | graph_reducer.ReduceGraph(); |
| 686 | } |
| 687 | }; |
| 688 | |
| 689 | |
| 690 | struct EscapeAnalysisPhase { |
| 691 | static const char* phase_name() { return "escape analysis"; } |
| 692 | |
| 693 | void Run(PipelineData* data, Zone* temp_zone) { |
| 694 | EscapeAnalysis escape_analysis(data->graph(), data->jsgraph()->common(), |
| 695 | temp_zone); |
| 696 | escape_analysis.Run(); |
| 697 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 698 | EscapeAnalysisReducer escape_reducer(&graph_reducer, data->jsgraph(), |
| 699 | &escape_analysis, temp_zone); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 700 | escape_reducer.SetExistsVirtualAllocate( |
| 701 | escape_analysis.ExistsVirtualAllocate()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 702 | AddReducer(data, &graph_reducer, &escape_reducer); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 703 | graph_reducer.ReduceGraph(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 704 | escape_reducer.VerifyReplacement(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 705 | } |
| 706 | }; |
| 707 | |
| 708 | |
| 709 | struct SimplifiedLoweringPhase { |
| 710 | static const char* phase_name() { return "simplified lowering"; } |
| 711 | |
| 712 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 713 | SimplifiedLowering lowering(data->jsgraph(), temp_zone, |
| 714 | data->source_positions()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 715 | lowering.LowerAllNodes(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 716 | |
| 717 | // TODO(bmeurer): See comment on SimplifiedLowering::abort_compilation_. |
| 718 | if (lowering.abort_compilation_) { |
| 719 | data->set_compilation_failed(); |
| 720 | return; |
| 721 | } |
| 722 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 723 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 724 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 725 | data->common()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 726 | SimplifiedOperatorReducer simple_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 727 | ValueNumberingReducer value_numbering(temp_zone); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 728 | MachineOperatorReducer machine_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 729 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 730 | data->common(), data->machine()); |
| 731 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 732 | AddReducer(data, &graph_reducer, &simple_reducer); |
| 733 | AddReducer(data, &graph_reducer, &value_numbering); |
| 734 | AddReducer(data, &graph_reducer, &machine_reducer); |
| 735 | AddReducer(data, &graph_reducer, &common_reducer); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 736 | graph_reducer.ReduceGraph(); |
| 737 | } |
| 738 | }; |
| 739 | |
| 740 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 741 | struct ControlFlowOptimizationPhase { |
| 742 | static const char* phase_name() { return "control flow optimization"; } |
| 743 | |
| 744 | void Run(PipelineData* data, Zone* temp_zone) { |
| 745 | ControlFlowOptimizer optimizer(data->graph(), data->common(), |
| 746 | data->machine(), temp_zone); |
| 747 | optimizer.Optimize(); |
| 748 | } |
| 749 | }; |
| 750 | |
| 751 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 752 | struct ChangeLoweringPhase { |
| 753 | static const char* phase_name() { return "change lowering"; } |
| 754 | |
| 755 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 756 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 757 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 758 | data->common()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 759 | SimplifiedOperatorReducer simple_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 760 | ValueNumberingReducer value_numbering(temp_zone); |
| 761 | ChangeLowering lowering(data->jsgraph()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 762 | MachineOperatorReducer machine_reducer(data->jsgraph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 763 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 764 | data->common(), data->machine()); |
| 765 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 766 | AddReducer(data, &graph_reducer, &simple_reducer); |
| 767 | AddReducer(data, &graph_reducer, &value_numbering); |
| 768 | AddReducer(data, &graph_reducer, &lowering); |
| 769 | AddReducer(data, &graph_reducer, &machine_reducer); |
| 770 | AddReducer(data, &graph_reducer, &common_reducer); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 771 | graph_reducer.ReduceGraph(); |
| 772 | } |
| 773 | }; |
| 774 | |
| 775 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 776 | struct EarlyGraphTrimmingPhase { |
| 777 | static const char* phase_name() { return "early graph trimming"; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 778 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 779 | GraphTrimmer trimmer(temp_zone, data->graph()); |
| 780 | NodeVector roots(temp_zone); |
| 781 | data->jsgraph()->GetCachedNodes(&roots); |
| 782 | trimmer.TrimGraph(roots.begin(), roots.end()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 783 | } |
| 784 | }; |
| 785 | |
| 786 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 787 | struct LateGraphTrimmingPhase { |
| 788 | static const char* phase_name() { return "late graph trimming"; } |
| 789 | void Run(PipelineData* data, Zone* temp_zone) { |
| 790 | GraphTrimmer trimmer(temp_zone, data->graph()); |
| 791 | NodeVector roots(temp_zone); |
| 792 | data->jsgraph()->GetCachedNodes(&roots); |
| 793 | trimmer.TrimGraph(roots.begin(), roots.end()); |
| 794 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 795 | }; |
| 796 | |
| 797 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 798 | struct StressLoopPeelingPhase { |
| 799 | static const char* phase_name() { return "stress loop peeling"; } |
| 800 | |
| 801 | void Run(PipelineData* data, Zone* temp_zone) { |
| 802 | // Peel the first outer loop for testing. |
| 803 | // TODO(titzer): peel all loops? the N'th loop? Innermost loops? |
| 804 | LoopTree* loop_tree = LoopFinder::BuildLoopTree(data->graph(), temp_zone); |
| 805 | if (loop_tree != nullptr && loop_tree->outer_loops().size() > 0) { |
| 806 | LoopPeeler::Peel(data->graph(), data->common(), loop_tree, |
| 807 | loop_tree->outer_loops()[0], temp_zone); |
| 808 | } |
| 809 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 810 | }; |
| 811 | |
| 812 | |
| 813 | struct GenericLoweringPhase { |
| 814 | static const char* phase_name() { return "generic lowering"; } |
| 815 | |
| 816 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 817 | JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 818 | DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
| 819 | data->common()); |
| 820 | CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
| 821 | data->common(), data->machine()); |
| 822 | JSGenericLowering generic_lowering(data->info()->is_typing_enabled(), |
| 823 | data->jsgraph()); |
| 824 | SelectLowering select_lowering(data->jsgraph()->graph(), |
| 825 | data->jsgraph()->common()); |
| 826 | TailCallOptimization tco(data->common(), data->graph()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 827 | AddReducer(data, &graph_reducer, &dead_code_elimination); |
| 828 | AddReducer(data, &graph_reducer, &common_reducer); |
| 829 | AddReducer(data, &graph_reducer, &generic_lowering); |
| 830 | AddReducer(data, &graph_reducer, &select_lowering); |
| 831 | AddReducer(data, &graph_reducer, &tco); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 832 | graph_reducer.ReduceGraph(); |
| 833 | } |
| 834 | }; |
| 835 | |
| 836 | |
| 837 | struct ComputeSchedulePhase { |
| 838 | static const char* phase_name() { return "scheduling"; } |
| 839 | |
| 840 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 841 | Schedule* schedule = Scheduler::ComputeSchedule( |
| 842 | temp_zone, data->graph(), data->info()->is_splitting_enabled() |
| 843 | ? Scheduler::kSplitNodes |
| 844 | : Scheduler::kNoFlags); |
| 845 | if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 846 | data->set_schedule(schedule); |
| 847 | } |
| 848 | }; |
| 849 | |
| 850 | |
| 851 | struct InstructionSelectionPhase { |
| 852 | static const char* phase_name() { return "select instructions"; } |
| 853 | |
| 854 | void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 855 | InstructionSelector selector( |
| 856 | temp_zone, data->graph()->NodeCount(), linkage, data->sequence(), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 857 | data->schedule(), data->source_positions(), data->frame(), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 858 | data->info()->is_source_positions_enabled() |
| 859 | ? InstructionSelector::kAllSourcePositions |
| 860 | : InstructionSelector::kCallSourcePositions); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 861 | selector.SelectInstructions(); |
| 862 | } |
| 863 | }; |
| 864 | |
| 865 | |
| 866 | struct MeetRegisterConstraintsPhase { |
| 867 | static const char* phase_name() { return "meet register constraints"; } |
| 868 | |
| 869 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 870 | ConstraintBuilder builder(data->register_allocation_data()); |
| 871 | builder.MeetRegisterConstraints(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 872 | } |
| 873 | }; |
| 874 | |
| 875 | |
| 876 | struct ResolvePhisPhase { |
| 877 | static const char* phase_name() { return "resolve phis"; } |
| 878 | |
| 879 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 880 | ConstraintBuilder builder(data->register_allocation_data()); |
| 881 | builder.ResolvePhis(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 882 | } |
| 883 | }; |
| 884 | |
| 885 | |
| 886 | struct BuildLiveRangesPhase { |
| 887 | static const char* phase_name() { return "build live ranges"; } |
| 888 | |
| 889 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 890 | LiveRangeBuilder builder(data->register_allocation_data(), temp_zone); |
| 891 | builder.BuildLiveRanges(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 892 | } |
| 893 | }; |
| 894 | |
| 895 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 896 | struct SplinterLiveRangesPhase { |
| 897 | static const char* phase_name() { return "splinter live ranges"; } |
| 898 | |
| 899 | void Run(PipelineData* data, Zone* temp_zone) { |
| 900 | LiveRangeSeparator live_range_splinterer(data->register_allocation_data(), |
| 901 | temp_zone); |
| 902 | live_range_splinterer.Splinter(); |
| 903 | } |
| 904 | }; |
| 905 | |
| 906 | |
| 907 | template <typename RegAllocator> |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 908 | struct AllocateGeneralRegistersPhase { |
| 909 | static const char* phase_name() { return "allocate general registers"; } |
| 910 | |
| 911 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 912 | RegAllocator allocator(data->register_allocation_data(), GENERAL_REGISTERS, |
| 913 | temp_zone); |
| 914 | allocator.AllocateRegisters(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 915 | } |
| 916 | }; |
| 917 | |
| 918 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 919 | template <typename RegAllocator> |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 920 | struct AllocateDoubleRegistersPhase { |
| 921 | static const char* phase_name() { return "allocate double registers"; } |
| 922 | |
| 923 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 924 | RegAllocator allocator(data->register_allocation_data(), DOUBLE_REGISTERS, |
| 925 | temp_zone); |
| 926 | allocator.AllocateRegisters(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 927 | } |
| 928 | }; |
| 929 | |
| 930 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 931 | struct MergeSplintersPhase { |
| 932 | static const char* phase_name() { return "merge splintered ranges"; } |
| 933 | void Run(PipelineData* pipeline_data, Zone* temp_zone) { |
| 934 | RegisterAllocationData* data = pipeline_data->register_allocation_data(); |
| 935 | LiveRangeMerger live_range_merger(data, temp_zone); |
| 936 | live_range_merger.Merge(); |
| 937 | } |
| 938 | }; |
| 939 | |
| 940 | |
| 941 | struct LocateSpillSlotsPhase { |
| 942 | static const char* phase_name() { return "locate spill slots"; } |
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 | SpillSlotLocator locator(data->register_allocation_data()); |
| 946 | locator.LocateSpillSlots(); |
| 947 | } |
| 948 | }; |
| 949 | |
| 950 | |
| 951 | struct AssignSpillSlotsPhase { |
| 952 | static const char* phase_name() { return "assign spill slots"; } |
| 953 | |
| 954 | void Run(PipelineData* data, Zone* temp_zone) { |
| 955 | OperandAssigner assigner(data->register_allocation_data()); |
| 956 | assigner.AssignSpillSlots(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 957 | } |
| 958 | }; |
| 959 | |
| 960 | |
| 961 | struct CommitAssignmentPhase { |
| 962 | static const char* phase_name() { return "commit assignment"; } |
| 963 | |
| 964 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 965 | OperandAssigner assigner(data->register_allocation_data()); |
| 966 | assigner.CommitAssignment(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 967 | } |
| 968 | }; |
| 969 | |
| 970 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 971 | struct PopulateReferenceMapsPhase { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 972 | static const char* phase_name() { return "populate pointer maps"; } |
| 973 | |
| 974 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 975 | ReferenceMapPopulator populator(data->register_allocation_data()); |
| 976 | populator.PopulateReferenceMaps(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 977 | } |
| 978 | }; |
| 979 | |
| 980 | |
| 981 | struct ConnectRangesPhase { |
| 982 | static const char* phase_name() { return "connect ranges"; } |
| 983 | |
| 984 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 985 | LiveRangeConnector connector(data->register_allocation_data()); |
| 986 | connector.ConnectRanges(temp_zone); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 987 | } |
| 988 | }; |
| 989 | |
| 990 | |
| 991 | struct ResolveControlFlowPhase { |
| 992 | static const char* phase_name() { return "resolve control flow"; } |
| 993 | |
| 994 | void Run(PipelineData* data, Zone* temp_zone) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 995 | LiveRangeConnector connector(data->register_allocation_data()); |
| 996 | connector.ResolveControlFlow(temp_zone); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 997 | } |
| 998 | }; |
| 999 | |
| 1000 | |
| 1001 | struct OptimizeMovesPhase { |
| 1002 | static const char* phase_name() { return "optimize moves"; } |
| 1003 | |
| 1004 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1005 | MoveOptimizer move_optimizer(temp_zone, data->sequence()); |
| 1006 | move_optimizer.Run(); |
| 1007 | } |
| 1008 | }; |
| 1009 | |
| 1010 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1011 | struct FrameElisionPhase { |
| 1012 | static const char* phase_name() { return "frame elision"; } |
| 1013 | |
| 1014 | void Run(PipelineData* data, Zone* temp_zone) { |
| 1015 | FrameElider(data->sequence()).Run(); |
| 1016 | } |
| 1017 | }; |
| 1018 | |
| 1019 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1020 | struct JumpThreadingPhase { |
| 1021 | static const char* phase_name() { return "jump threading"; } |
| 1022 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1023 | void Run(PipelineData* data, Zone* temp_zone, bool frame_at_start) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1024 | ZoneVector<RpoNumber> result(temp_zone); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1025 | if (JumpThreading::ComputeForwarding(temp_zone, result, data->sequence(), |
| 1026 | frame_at_start)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1027 | JumpThreading::ApplyForwarding(result, data->sequence()); |
| 1028 | } |
| 1029 | } |
| 1030 | }; |
| 1031 | |
| 1032 | |
| 1033 | struct GenerateCodePhase { |
| 1034 | static const char* phase_name() { return "generate code"; } |
| 1035 | |
| 1036 | void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { |
| 1037 | CodeGenerator generator(data->frame(), linkage, data->sequence(), |
| 1038 | data->info()); |
| 1039 | data->set_code(generator.GenerateCode()); |
| 1040 | } |
| 1041 | }; |
| 1042 | |
| 1043 | |
| 1044 | struct PrintGraphPhase { |
| 1045 | static const char* phase_name() { return nullptr; } |
| 1046 | |
| 1047 | void Run(PipelineData* data, Zone* temp_zone, const char* phase) { |
| 1048 | CompilationInfo* info = data->info(); |
| 1049 | Graph* graph = data->graph(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1050 | |
| 1051 | { // Print JSON. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1052 | FILE* json_file = OpenVisualizerLogFile(info, nullptr, "json", "a+"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1053 | if (json_file == nullptr) return; |
| 1054 | OFStream json_of(json_file); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1055 | json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" |
| 1056 | << AsJSON(*graph, data->source_positions()) << "},\n"; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1057 | fclose(json_file); |
| 1058 | } |
| 1059 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1060 | if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1061 | OFStream os(stdout); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1062 | os << "-- Graph after " << phase << " -- " << std::endl; |
| 1063 | os << AsRPO(*graph); |
| 1064 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1065 | } |
| 1066 | }; |
| 1067 | |
| 1068 | |
| 1069 | struct VerifyGraphPhase { |
| 1070 | static const char* phase_name() { return nullptr; } |
| 1071 | |
| 1072 | void Run(PipelineData* data, Zone* temp_zone, const bool untyped) { |
| 1073 | Verifier::Run(data->graph(), FLAG_turbo_types && !untyped |
| 1074 | ? Verifier::TYPED |
| 1075 | : Verifier::UNTYPED); |
| 1076 | } |
| 1077 | }; |
| 1078 | |
| 1079 | |
| 1080 | void Pipeline::BeginPhaseKind(const char* phase_kind_name) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1081 | if (data_->pipeline_statistics() != nullptr) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1082 | data_->pipeline_statistics()->BeginPhaseKind(phase_kind_name); |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | |
| 1087 | void Pipeline::RunPrintAndVerify(const char* phase, bool untyped) { |
| 1088 | if (FLAG_trace_turbo) { |
| 1089 | Run<PrintGraphPhase>(phase); |
| 1090 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1091 | if (FLAG_turbo_verify) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1092 | Run<VerifyGraphPhase>(untyped); |
| 1093 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | Handle<Code> Pipeline::GenerateCode() { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1098 | ZonePool zone_pool(isolate()->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1099 | base::SmartPointer<PipelineStatistics> pipeline_statistics; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1100 | |
| 1101 | if (FLAG_turbo_stats) { |
| 1102 | pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); |
| 1103 | pipeline_statistics->BeginPhaseKind("initializing"); |
| 1104 | } |
| 1105 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1106 | if (FLAG_trace_turbo) { |
| 1107 | FILE* json_file = OpenVisualizerLogFile(info(), nullptr, "json", "w+"); |
| 1108 | if (json_file != nullptr) { |
| 1109 | OFStream json_of(json_file); |
| 1110 | Handle<Script> script = info()->script(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1111 | base::SmartArrayPointer<char> function_name = info()->GetDebugName(); |
| 1112 | int pos = info()->shared_info()->start_position(); |
| 1113 | json_of << "{\"function\":\"" << function_name.get() |
| 1114 | << "\", \"sourcePosition\":" << pos << ", \"source\":\""; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1115 | if (info()->has_literal() && !script->IsUndefined() && |
| 1116 | !script->source()->IsUndefined()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1117 | DisallowHeapAllocation no_allocation; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1118 | FunctionLiteral* function = info()->literal(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1119 | int start = function->start_position(); |
| 1120 | int len = function->end_position() - start; |
| 1121 | String::SubStringRange source(String::cast(script->source()), start, |
| 1122 | len); |
| 1123 | for (const auto& c : source) { |
| 1124 | json_of << AsEscapedUC16ForJSON(c); |
| 1125 | } |
| 1126 | } |
| 1127 | json_of << "\",\n\"phases\":["; |
| 1128 | fclose(json_file); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | PipelineData data(&zone_pool, info(), pipeline_statistics.get()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1133 | this->data_ = &data; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1134 | |
| 1135 | BeginPhaseKind("graph creation"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1136 | |
| 1137 | if (FLAG_trace_turbo) { |
| 1138 | OFStream os(stdout); |
| 1139 | os << "---------------------------------------------------\n" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1140 | << "Begin compiling method " << info()->GetDebugName().get() |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1141 | << " using Turbofan" << std::endl; |
| 1142 | TurboCfgFile tcf(isolate()); |
| 1143 | tcf << AsC1VCompilation(info()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1146 | data.source_positions()->AddDecorator(); |
| 1147 | |
| 1148 | if (FLAG_loop_assignment_analysis) { |
| 1149 | Run<LoopAssignmentAnalysisPhase>(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1152 | if (info()->is_typing_enabled()) { |
| 1153 | Run<TypeHintAnalysisPhase>(); |
| 1154 | } |
| 1155 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1156 | Run<GraphBuilderPhase>(); |
| 1157 | if (data.compilation_failed()) return Handle<Code>::null(); |
| 1158 | RunPrintAndVerify("Initial untyped", true); |
| 1159 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1160 | // Perform OSR deconstruction. |
| 1161 | if (info()->is_osr()) { |
| 1162 | Run<OsrDeconstructionPhase>(); |
| 1163 | RunPrintAndVerify("OSR deconstruction", true); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1166 | // Perform function context specialization and inlining (if enabled). |
| 1167 | Run<InliningPhase>(); |
| 1168 | RunPrintAndVerify("Inlined", true); |
| 1169 | |
| 1170 | // Remove dead->live edges from the graph. |
| 1171 | Run<EarlyGraphTrimmingPhase>(); |
| 1172 | RunPrintAndVerify("Early trimmed", true); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1173 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1174 | if (FLAG_print_turbo_replay) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1175 | // Print a replay of the initial graph. |
| 1176 | GraphReplayPrinter::PrintReplay(data.graph()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1179 | base::SmartPointer<Typer> typer; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1180 | if (info()->is_typing_enabled()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1181 | // Type the graph. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1182 | typer.Reset(new Typer(isolate(), data.graph(), |
| 1183 | info()->is_deoptimization_enabled() |
| 1184 | ? Typer::kDeoptimizationEnabled |
| 1185 | : Typer::kNoFlags, |
| 1186 | info()->dependencies())); |
| 1187 | Run<TyperPhase>(typer.get()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1188 | RunPrintAndVerify("Typed"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1191 | BeginPhaseKind("lowering"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1192 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1193 | if (info()->is_typing_enabled()) { |
| 1194 | // Lower JSOperators where we can determine types. |
| 1195 | Run<TypedLoweringPhase>(); |
| 1196 | RunPrintAndVerify("Lowered typed"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1197 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1198 | if (FLAG_turbo_stress_loop_peeling) { |
| 1199 | Run<StressLoopPeelingPhase>(); |
| 1200 | RunPrintAndVerify("Loop peeled"); |
| 1201 | } |
| 1202 | |
| 1203 | if (FLAG_turbo_escape) { |
| 1204 | Run<EscapeAnalysisPhase>(); |
| 1205 | RunPrintAndVerify("Escape Analysed"); |
| 1206 | } |
| 1207 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1208 | // Lower simplified operators and insert changes. |
| 1209 | Run<SimplifiedLoweringPhase>(); |
| 1210 | RunPrintAndVerify("Lowered simplified"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1211 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1212 | Run<BranchEliminationPhase>(); |
| 1213 | RunPrintAndVerify("Branch conditions eliminated"); |
| 1214 | |
| 1215 | // Optimize control flow. |
| 1216 | if (FLAG_turbo_cf_optimization) { |
| 1217 | Run<ControlFlowOptimizationPhase>(); |
| 1218 | RunPrintAndVerify("Control flow optimized"); |
| 1219 | } |
| 1220 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1221 | // Lower changes that have been inserted before. |
| 1222 | Run<ChangeLoweringPhase>(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1223 | // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1224 | RunPrintAndVerify("Lowered changes", true); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1227 | // Lower any remaining generic JSOperators. |
| 1228 | Run<GenericLoweringPhase>(); |
| 1229 | // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
| 1230 | RunPrintAndVerify("Lowered generic", true); |
| 1231 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1232 | Run<LateGraphTrimmingPhase>(); |
| 1233 | // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
| 1234 | RunPrintAndVerify("Late trimmed", true); |
| 1235 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1236 | BeginPhaseKind("block building"); |
| 1237 | |
| 1238 | data.source_positions()->RemoveDecorator(); |
| 1239 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1240 | // Kill the Typer and thereby uninstall the decorator (if any). |
| 1241 | typer.Reset(nullptr); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1242 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1243 | // TODO(bmeurer): See comment on SimplifiedLowering::abort_compilation_. |
| 1244 | if (data.compilation_failed()) return Handle<Code>::null(); |
| 1245 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1246 | return ScheduleAndGenerateCode( |
| 1247 | Linkage::ComputeIncoming(data.instruction_zone(), info())); |
| 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, |
| 1252 | CallDescriptor* call_descriptor, |
| 1253 | Graph* graph, Schedule* schedule, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1254 | Code::Flags flags, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1255 | const char* debug_name) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1256 | CompilationInfo info(debug_name, isolate, graph->zone(), flags); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1257 | |
| 1258 | // Construct a pipeline for scheduling and code generation. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1259 | ZonePool zone_pool(isolate->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1260 | PipelineData data(&zone_pool, &info, graph, schedule); |
| 1261 | base::SmartPointer<PipelineStatistics> pipeline_statistics; |
| 1262 | if (FLAG_turbo_stats) { |
| 1263 | pipeline_statistics.Reset(new PipelineStatistics(&info, &zone_pool)); |
| 1264 | pipeline_statistics->BeginPhaseKind("stub codegen"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1265 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1266 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1267 | Pipeline pipeline(&info); |
| 1268 | pipeline.data_ = &data; |
| 1269 | DCHECK_NOT_NULL(data.schedule()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1270 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1271 | if (FLAG_trace_turbo) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1272 | FILE* json_file = OpenVisualizerLogFile(&info, nullptr, "json", "w+"); |
| 1273 | if (json_file != nullptr) { |
| 1274 | OFStream json_of(json_file); |
| 1275 | json_of << "{\"function\":\"" << info.GetDebugName().get() |
| 1276 | << "\", \"source\":\"\",\n\"phases\":["; |
| 1277 | fclose(json_file); |
| 1278 | } |
| 1279 | pipeline.Run<PrintGraphPhase>("Machine"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1282 | return pipeline.ScheduleAndGenerateCode(call_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1286 | Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
| 1287 | Graph* graph, |
| 1288 | Schedule* schedule) { |
| 1289 | CallDescriptor* call_descriptor = |
| 1290 | Linkage::ComputeIncoming(info->zone(), info); |
| 1291 | return GenerateCodeForTesting(info, call_descriptor, graph, schedule); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1295 | Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
| 1296 | CallDescriptor* call_descriptor, |
| 1297 | Graph* graph, |
| 1298 | Schedule* schedule) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1299 | // Construct a pipeline for scheduling and code generation. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1300 | ZonePool zone_pool(info->isolate()->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1301 | PipelineData data(&zone_pool, info, graph, schedule); |
| 1302 | base::SmartPointer<PipelineStatistics> pipeline_statistics; |
| 1303 | if (FLAG_turbo_stats) { |
| 1304 | pipeline_statistics.Reset(new PipelineStatistics(info, &zone_pool)); |
| 1305 | pipeline_statistics->BeginPhaseKind("test codegen"); |
| 1306 | } |
| 1307 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1308 | Pipeline pipeline(info); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1309 | pipeline.data_ = &data; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1310 | if (data.schedule() == nullptr) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1311 | // TODO(rossberg): Should this really be untyped? |
| 1312 | pipeline.RunPrintAndVerify("Machine", true); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1313 | } |
| 1314 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1315 | return pipeline.ScheduleAndGenerateCode(call_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1319 | bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, |
| 1320 | InstructionSequence* sequence, |
| 1321 | bool run_verifier) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1322 | CompilationInfo info("testing", sequence->isolate(), sequence->zone()); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1323 | ZonePool zone_pool(sequence->isolate()->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1324 | PipelineData data(&zone_pool, &info, sequence); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1325 | Pipeline pipeline(&info); |
| 1326 | pipeline.data_ = &data; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1327 | pipeline.data_->InitializeFrameData(nullptr); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1328 | pipeline.AllocateRegisters(config, nullptr, run_verifier); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1329 | return !data.compilation_failed(); |
| 1330 | } |
| 1331 | |
| 1332 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1333 | Handle<Code> Pipeline::ScheduleAndGenerateCode( |
| 1334 | CallDescriptor* call_descriptor) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1335 | PipelineData* data = this->data_; |
| 1336 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1337 | DCHECK_NOT_NULL(data->graph()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1338 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1339 | if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); |
| 1340 | TraceSchedule(data->info(), data->schedule()); |
| 1341 | |
| 1342 | BasicBlockProfiler::Data* profiler_data = nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1343 | if (FLAG_turbo_profiling) { |
| 1344 | profiler_data = BasicBlockInstrumentor::Instrument(info(), data->graph(), |
| 1345 | data->schedule()); |
| 1346 | } |
| 1347 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1348 | data->InitializeInstructionSequence(call_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1349 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1350 | data->InitializeFrameData(call_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1351 | // Select and schedule instructions covering the scheduled graph. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1352 | Linkage linkage(call_descriptor); |
| 1353 | Run<InstructionSelectionPhase>(&linkage); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1354 | |
| 1355 | if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { |
| 1356 | TurboCfgFile tcf(isolate()); |
| 1357 | tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(), |
| 1358 | data->sequence()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1361 | std::ostringstream source_position_output; |
| 1362 | if (FLAG_trace_turbo) { |
| 1363 | // Output source position information before the graph is deleted. |
| 1364 | data_->source_positions()->Print(source_position_output); |
| 1365 | } |
| 1366 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1367 | data->DeleteGraphZone(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1368 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1369 | BeginPhaseKind("register allocation"); |
| 1370 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1371 | bool run_verifier = FLAG_turbo_verify_allocation; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1372 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1373 | // Allocate registers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1374 | AllocateRegisters( |
| 1375 | RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN), |
| 1376 | call_descriptor, run_verifier); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1377 | Run<FrameElisionPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1378 | if (data->compilation_failed()) { |
| 1379 | info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1380 | return Handle<Code>(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1383 | BeginPhaseKind("code generation"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1384 | // TODO(mtrofin): move this off to the register allocator. |
| 1385 | bool generate_frame_at_start = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1386 | data_->sequence()->instruction_blocks().front()->must_construct_frame(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1387 | // Optimimize jumps. |
| 1388 | if (FLAG_turbo_jt) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1389 | Run<JumpThreadingPhase>(generate_frame_at_start); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | // Generate final machine code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1393 | Run<GenerateCodePhase>(&linkage); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1394 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1395 | Handle<Code> code = data->code(); |
| 1396 | if (profiler_data != nullptr) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1397 | #if ENABLE_DISASSEMBLER |
| 1398 | std::ostringstream os; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1399 | code->Disassemble(nullptr, os); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1400 | profiler_data->SetCode(&os); |
| 1401 | #endif |
| 1402 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1403 | |
| 1404 | info()->SetCode(code); |
| 1405 | v8::internal::CodeGenerator::PrintCode(code, info()); |
| 1406 | |
| 1407 | if (FLAG_trace_turbo) { |
| 1408 | FILE* json_file = OpenVisualizerLogFile(info(), nullptr, "json", "a+"); |
| 1409 | if (json_file != nullptr) { |
| 1410 | OFStream json_of(json_file); |
| 1411 | json_of |
| 1412 | << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\""; |
| 1413 | #if ENABLE_DISASSEMBLER |
| 1414 | std::stringstream disassembly_stream; |
| 1415 | code->Disassemble(nullptr, disassembly_stream); |
| 1416 | std::string disassembly_string(disassembly_stream.str()); |
| 1417 | for (const auto& c : disassembly_string) { |
| 1418 | json_of << AsEscapedUC16ForJSON(c); |
| 1419 | } |
| 1420 | #endif // ENABLE_DISASSEMBLER |
| 1421 | json_of << "\"}\n],\n"; |
| 1422 | json_of << "\"nodePositions\":"; |
| 1423 | json_of << source_position_output.str(); |
| 1424 | json_of << "}"; |
| 1425 | fclose(json_file); |
| 1426 | } |
| 1427 | OFStream os(stdout); |
| 1428 | os << "---------------------------------------------------\n" |
| 1429 | << "Finished compiling method " << info()->GetDebugName().get() |
| 1430 | << " using Turbofan" << std::endl; |
| 1431 | } |
| 1432 | |
| 1433 | return code; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | |
| 1437 | void Pipeline::AllocateRegisters(const RegisterConfiguration* config, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1438 | CallDescriptor* descriptor, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1439 | bool run_verifier) { |
| 1440 | PipelineData* data = this->data_; |
| 1441 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1442 | // Don't track usage for this zone in compiler stats. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1443 | base::SmartPointer<Zone> verifier_zone; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1444 | RegisterAllocatorVerifier* verifier = nullptr; |
| 1445 | if (run_verifier) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1446 | verifier_zone.Reset(new Zone(isolate()->allocator())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1447 | verifier = new (verifier_zone.get()) RegisterAllocatorVerifier( |
| 1448 | verifier_zone.get(), config, data->sequence()); |
| 1449 | } |
| 1450 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1451 | base::SmartArrayPointer<char> debug_name; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1452 | #ifdef DEBUG |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1453 | debug_name = info()->GetDebugName(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1454 | data_->sequence()->ValidateEdgeSplitForm(); |
| 1455 | data_->sequence()->ValidateDeferredBlockExitPaths(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1456 | #endif |
| 1457 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1458 | data->InitializeRegisterAllocationData(config, descriptor, debug_name.get()); |
| 1459 | if (info()->is_osr()) { |
| 1460 | OsrHelper osr_helper(info()); |
| 1461 | osr_helper.SetupFrame(data->frame()); |
| 1462 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1463 | |
| 1464 | Run<MeetRegisterConstraintsPhase>(); |
| 1465 | Run<ResolvePhisPhase>(); |
| 1466 | Run<BuildLiveRangesPhase>(); |
| 1467 | if (FLAG_trace_turbo_graph) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1468 | OFStream os(stdout); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1469 | PrintableInstructionSequence printable = {config, data->sequence()}; |
| 1470 | os << "----- Instruction sequence before register allocation -----\n" |
| 1471 | << printable; |
| 1472 | } |
| 1473 | if (verifier != nullptr) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1474 | CHECK(!data->register_allocation_data()->ExistsUseWithoutDefinition()); |
| 1475 | CHECK(data->register_allocation_data() |
| 1476 | ->RangesDefinedInDeferredStayInDeferred()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1477 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1478 | |
| 1479 | if (FLAG_turbo_preprocess_ranges) { |
| 1480 | Run<SplinterLiveRangesPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1481 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1482 | |
| 1483 | if (FLAG_turbo_greedy_regalloc) { |
| 1484 | Run<AllocateGeneralRegistersPhase<GreedyAllocator>>(); |
| 1485 | Run<AllocateDoubleRegistersPhase<GreedyAllocator>>(); |
| 1486 | } else { |
| 1487 | Run<AllocateGeneralRegistersPhase<LinearScanAllocator>>(); |
| 1488 | Run<AllocateDoubleRegistersPhase<LinearScanAllocator>>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1489 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1490 | |
| 1491 | if (FLAG_turbo_preprocess_ranges) { |
| 1492 | Run<MergeSplintersPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1493 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1494 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1495 | Run<AssignSpillSlotsPhase>(); |
| 1496 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1497 | Run<CommitAssignmentPhase>(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1498 | Run<PopulateReferenceMapsPhase>(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1499 | Run<ConnectRangesPhase>(); |
| 1500 | Run<ResolveControlFlowPhase>(); |
| 1501 | if (FLAG_turbo_move_optimization) { |
| 1502 | Run<OptimizeMovesPhase>(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1505 | Run<LocateSpillSlotsPhase>(); |
| 1506 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1507 | if (FLAG_trace_turbo_graph) { |
| 1508 | OFStream os(stdout); |
| 1509 | PrintableInstructionSequence printable = {config, data->sequence()}; |
| 1510 | os << "----- Instruction sequence after register allocation -----\n" |
| 1511 | << printable; |
| 1512 | } |
| 1513 | |
| 1514 | if (verifier != nullptr) { |
| 1515 | verifier->VerifyAssignment(); |
| 1516 | verifier->VerifyGapMoves(); |
| 1517 | } |
| 1518 | |
| 1519 | if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { |
| 1520 | TurboCfgFile tcf(data->isolate()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1521 | tcf << AsC1VRegisterAllocationData("CodeGen", |
| 1522 | data->register_allocation_data()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1523 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1524 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1525 | data->DeleteRegisterAllocationZone(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1528 | Isolate* Pipeline::isolate() const { return info()->isolate(); } |
| 1529 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1530 | } // namespace compiler |
| 1531 | } // namespace internal |
| 1532 | } // namespace v8 |