Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: src/compiler/pipeline.cc

Issue 934293002: [turbofan] Simply context specialization and fix for OSR. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/osr.cc ('k') | src/compiler/verifier.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/pipeline.h" 5 #include "src/compiler/pipeline.h"
6 6
7 #include <fstream> // NOLINT(readability/streams) 7 #include <fstream> // NOLINT(readability/streams)
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "src/base/platform/elapsed-timer.h" 10 #include "src/base/platform/elapsed-timer.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 code_(Handle<Code>::null()), 67 code_(Handle<Code>::null()),
68 graph_zone_scope_(zone_pool_), 68 graph_zone_scope_(zone_pool_),
69 graph_zone_(graph_zone_scope_.zone()), 69 graph_zone_(graph_zone_scope_.zone()),
70 graph_(nullptr), 70 graph_(nullptr),
71 loop_assignment_(nullptr), 71 loop_assignment_(nullptr),
72 machine_(nullptr), 72 machine_(nullptr),
73 common_(nullptr), 73 common_(nullptr),
74 javascript_(nullptr), 74 javascript_(nullptr),
75 jsgraph_(nullptr), 75 jsgraph_(nullptr),
76 typer_(nullptr), 76 typer_(nullptr),
77 context_node_(nullptr),
78 schedule_(nullptr), 77 schedule_(nullptr),
79 instruction_zone_scope_(zone_pool_), 78 instruction_zone_scope_(zone_pool_),
80 instruction_zone_(instruction_zone_scope_.zone()), 79 instruction_zone_(instruction_zone_scope_.zone()),
81 sequence_(nullptr), 80 sequence_(nullptr),
82 frame_(nullptr), 81 frame_(nullptr),
83 register_allocator_(nullptr) { 82 register_allocator_(nullptr) {
84 PhaseScope scope(pipeline_statistics, "init pipeline data"); 83 PhaseScope scope(pipeline_statistics, "init pipeline data");
85 graph_ = new (graph_zone_) Graph(graph_zone_); 84 graph_ = new (graph_zone_) Graph(graph_zone_);
86 source_positions_.Reset(new SourcePositionTable(graph_)); 85 source_positions_.Reset(new SourcePositionTable(graph_));
87 machine_ = new (graph_zone_) MachineOperatorBuilder( 86 machine_ = new (graph_zone_) MachineOperatorBuilder(
(...skipping 19 matching lines...) Expand all
107 graph_zone_scope_(zone_pool_), 106 graph_zone_scope_(zone_pool_),
108 graph_zone_(nullptr), 107 graph_zone_(nullptr),
109 graph_(graph), 108 graph_(graph),
110 source_positions_(new SourcePositionTable(graph_)), 109 source_positions_(new SourcePositionTable(graph_)),
111 loop_assignment_(nullptr), 110 loop_assignment_(nullptr),
112 machine_(nullptr), 111 machine_(nullptr),
113 common_(nullptr), 112 common_(nullptr),
114 javascript_(nullptr), 113 javascript_(nullptr),
115 jsgraph_(nullptr), 114 jsgraph_(nullptr),
116 typer_(nullptr), 115 typer_(nullptr),
117 context_node_(nullptr),
118 schedule_(schedule), 116 schedule_(schedule),
119 instruction_zone_scope_(zone_pool_), 117 instruction_zone_scope_(zone_pool_),
120 instruction_zone_(instruction_zone_scope_.zone()), 118 instruction_zone_(instruction_zone_scope_.zone()),
121 sequence_(nullptr), 119 sequence_(nullptr),
122 frame_(nullptr), 120 frame_(nullptr),
123 register_allocator_(nullptr) {} 121 register_allocator_(nullptr) {}
124 122
125 // For register allocation testing entry point. 123 // For register allocation testing entry point.
126 PipelineData(ZonePool* zone_pool, CompilationInfo* info, 124 PipelineData(ZonePool* zone_pool, CompilationInfo* info,
127 InstructionSequence* sequence) 125 InstructionSequence* sequence)
128 : isolate_(info->isolate()), 126 : isolate_(info->isolate()),
129 info_(info), 127 info_(info),
130 outer_zone_(nullptr), 128 outer_zone_(nullptr),
131 zone_pool_(zone_pool), 129 zone_pool_(zone_pool),
132 pipeline_statistics_(nullptr), 130 pipeline_statistics_(nullptr),
133 compilation_failed_(false), 131 compilation_failed_(false),
134 code_(Handle<Code>::null()), 132 code_(Handle<Code>::null()),
135 graph_zone_scope_(zone_pool_), 133 graph_zone_scope_(zone_pool_),
136 graph_zone_(nullptr), 134 graph_zone_(nullptr),
137 graph_(nullptr), 135 graph_(nullptr),
138 loop_assignment_(nullptr), 136 loop_assignment_(nullptr),
139 machine_(nullptr), 137 machine_(nullptr),
140 common_(nullptr), 138 common_(nullptr),
141 javascript_(nullptr), 139 javascript_(nullptr),
142 jsgraph_(nullptr), 140 jsgraph_(nullptr),
143 typer_(nullptr), 141 typer_(nullptr),
144 context_node_(nullptr),
145 schedule_(nullptr), 142 schedule_(nullptr),
146 instruction_zone_scope_(zone_pool_), 143 instruction_zone_scope_(zone_pool_),
147 instruction_zone_(sequence->zone()), 144 instruction_zone_(sequence->zone()),
148 sequence_(sequence), 145 sequence_(sequence),
149 frame_(nullptr), 146 frame_(nullptr),
150 register_allocator_(nullptr) {} 147 register_allocator_(nullptr) {}
151 148
152 ~PipelineData() { 149 ~PipelineData() {
153 DeleteInstructionZone(); 150 DeleteInstructionZone();
154 DeleteGraphZone(); 151 DeleteGraphZone();
(...skipping 24 matching lines...) Expand all
179 JSOperatorBuilder* javascript() const { return javascript_; } 176 JSOperatorBuilder* javascript() const { return javascript_; }
180 JSGraph* jsgraph() const { return jsgraph_; } 177 JSGraph* jsgraph() const { return jsgraph_; }
181 Typer* typer() const { return typer_.get(); } 178 Typer* typer() const { return typer_.get(); }
182 179
183 LoopAssignmentAnalysis* loop_assignment() const { return loop_assignment_; } 180 LoopAssignmentAnalysis* loop_assignment() const { return loop_assignment_; }
184 void set_loop_assignment(LoopAssignmentAnalysis* loop_assignment) { 181 void set_loop_assignment(LoopAssignmentAnalysis* loop_assignment) {
185 DCHECK(!loop_assignment_); 182 DCHECK(!loop_assignment_);
186 loop_assignment_ = loop_assignment; 183 loop_assignment_ = loop_assignment;
187 } 184 }
188 185
189 Node* context_node() const { return context_node_; }
190 void set_context_node(Node* context_node) {
191 DCHECK(!context_node_);
192 context_node_ = context_node;
193 }
194
195 Schedule* schedule() const { return schedule_; } 186 Schedule* schedule() const { return schedule_; }
196 void set_schedule(Schedule* schedule) { 187 void set_schedule(Schedule* schedule) {
197 DCHECK(!schedule_); 188 DCHECK(!schedule_);
198 schedule_ = schedule; 189 schedule_ = schedule;
199 } 190 }
200 191
201 Zone* instruction_zone() const { return instruction_zone_; } 192 Zone* instruction_zone() const { return instruction_zone_; }
202 InstructionSequence* sequence() const { return sequence_; } 193 InstructionSequence* sequence() const { return sequence_; }
203 Frame* frame() const { return frame_; } 194 Frame* frame() const { return frame_; }
204 RegisterAllocator* register_allocator() const { return register_allocator_; } 195 RegisterAllocator* register_allocator() const { return register_allocator_; }
205 196
206 void DeleteGraphZone() { 197 void DeleteGraphZone() {
207 // Destroy objects with destructors first. 198 // Destroy objects with destructors first.
208 source_positions_.Reset(nullptr); 199 source_positions_.Reset(nullptr);
209 typer_.Reset(nullptr); 200 typer_.Reset(nullptr);
210 if (graph_zone_ == nullptr) return; 201 if (graph_zone_ == nullptr) return;
211 // Destroy zone and clear pointers. 202 // Destroy zone and clear pointers.
212 graph_zone_scope_.Destroy(); 203 graph_zone_scope_.Destroy();
213 graph_zone_ = nullptr; 204 graph_zone_ = nullptr;
214 graph_ = nullptr; 205 graph_ = nullptr;
215 loop_assignment_ = nullptr; 206 loop_assignment_ = nullptr;
216 machine_ = nullptr; 207 machine_ = nullptr;
217 common_ = nullptr; 208 common_ = nullptr;
218 javascript_ = nullptr; 209 javascript_ = nullptr;
219 jsgraph_ = nullptr; 210 jsgraph_ = nullptr;
220 context_node_ = nullptr;
221 schedule_ = nullptr; 211 schedule_ = nullptr;
222 } 212 }
223 213
224 void DeleteInstructionZone() { 214 void DeleteInstructionZone() {
225 if (instruction_zone_ == nullptr) return; 215 if (instruction_zone_ == nullptr) return;
226 instruction_zone_scope_.Destroy(); 216 instruction_zone_scope_.Destroy();
227 instruction_zone_ = nullptr; 217 instruction_zone_ = nullptr;
228 sequence_ = nullptr; 218 sequence_ = nullptr;
229 frame_ = nullptr; 219 frame_ = nullptr;
230 register_allocator_ = nullptr; 220 register_allocator_ = nullptr;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 Graph* graph_; 255 Graph* graph_;
266 // TODO(dcarney): make this into a ZoneObject. 256 // TODO(dcarney): make this into a ZoneObject.
267 SmartPointer<SourcePositionTable> source_positions_; 257 SmartPointer<SourcePositionTable> source_positions_;
268 LoopAssignmentAnalysis* loop_assignment_; 258 LoopAssignmentAnalysis* loop_assignment_;
269 MachineOperatorBuilder* machine_; 259 MachineOperatorBuilder* machine_;
270 CommonOperatorBuilder* common_; 260 CommonOperatorBuilder* common_;
271 JSOperatorBuilder* javascript_; 261 JSOperatorBuilder* javascript_;
272 JSGraph* jsgraph_; 262 JSGraph* jsgraph_;
273 // TODO(dcarney): make this into a ZoneObject. 263 // TODO(dcarney): make this into a ZoneObject.
274 SmartPointer<Typer> typer_; 264 SmartPointer<Typer> typer_;
275 Node* context_node_;
276 Schedule* schedule_; 265 Schedule* schedule_;
277 266
278 // All objects in the following group of fields are allocated in 267 // All objects in the following group of fields are allocated in
279 // instruction_zone_. They are all set to NULL when the instruction_zone_ is 268 // instruction_zone_. They are all set to NULL when the instruction_zone_ is
280 // destroyed. 269 // destroyed.
281 ZonePool::Scope instruction_zone_scope_; 270 ZonePool::Scope instruction_zone_scope_;
282 Zone* instruction_zone_; 271 Zone* instruction_zone_;
283 InstructionSequence* sequence_; 272 InstructionSequence* sequence_;
284 Frame* frame_; 273 Frame* frame_;
285 RegisterAllocator* register_allocator_; 274 RegisterAllocator* register_allocator_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 class AstGraphBuilderWithPositions : public AstGraphBuilder { 312 class AstGraphBuilderWithPositions : public AstGraphBuilder {
324 public: 313 public:
325 AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, 314 AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info,
326 JSGraph* jsgraph, 315 JSGraph* jsgraph,
327 LoopAssignmentAnalysis* loop_assignment, 316 LoopAssignmentAnalysis* loop_assignment,
328 SourcePositionTable* source_positions) 317 SourcePositionTable* source_positions)
329 : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment), 318 : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment),
330 source_positions_(source_positions), 319 source_positions_(source_positions),
331 start_position_(info->shared_info()->start_position()) {} 320 start_position_(info->shared_info()->start_position()) {}
332 321
333 bool CreateGraph() { 322 bool CreateGraph(bool constant_context) {
334 SourcePositionTable::Scope pos_scope(source_positions_, start_position_); 323 SourcePositionTable::Scope pos_scope(source_positions_, start_position_);
335 return AstGraphBuilder::CreateGraph(); 324 return AstGraphBuilder::CreateGraph(constant_context);
336 } 325 }
337 326
338 #define DEF_VISIT(type) \ 327 #define DEF_VISIT(type) \
339 void Visit##type(type* node) OVERRIDE { \ 328 void Visit##type(type* node) OVERRIDE { \
340 SourcePositionTable::Scope pos(source_positions_, \ 329 SourcePositionTable::Scope pos(source_positions_, \
341 SourcePosition(node->position())); \ 330 SourcePosition(node->position())); \
342 AstGraphBuilder::Visit##type(node); \ 331 AstGraphBuilder::Visit##type(node); \
343 } 332 }
344 AST_NODE_LIST(DEF_VISIT) 333 AST_NODE_LIST(DEF_VISIT)
345 #undef DEF_VISIT 334 #undef DEF_VISIT
346 335
347 Node* GetFunctionContext() { return AstGraphBuilder::GetFunctionContext(); }
348
349 private: 336 private:
350 SourcePositionTable* source_positions_; 337 SourcePositionTable* source_positions_;
351 SourcePosition start_position_; 338 SourcePosition start_position_;
352 }; 339 };
353 340
354 341
355 namespace { 342 namespace {
356 343
357 class SourcePositionWrapper : public Reducer { 344 class SourcePositionWrapper : public Reducer {
358 public: 345 public:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 AstLoopAssignmentAnalyzer analyzer(data->graph_zone(), data->info()); 413 AstLoopAssignmentAnalyzer analyzer(data->graph_zone(), data->info());
427 LoopAssignmentAnalysis* loop_assignment = analyzer.Analyze(); 414 LoopAssignmentAnalysis* loop_assignment = analyzer.Analyze();
428 data->set_loop_assignment(loop_assignment); 415 data->set_loop_assignment(loop_assignment);
429 } 416 }
430 }; 417 };
431 418
432 419
433 struct GraphBuilderPhase { 420 struct GraphBuilderPhase {
434 static const char* phase_name() { return "graph builder"; } 421 static const char* phase_name() { return "graph builder"; }
435 422
436 void Run(PipelineData* data, Zone* temp_zone) { 423 void Run(PipelineData* data, Zone* temp_zone, bool constant_context) {
437 AstGraphBuilderWithPositions graph_builder( 424 AstGraphBuilderWithPositions graph_builder(
438 temp_zone, data->info(), data->jsgraph(), data->loop_assignment(), 425 temp_zone, data->info(), data->jsgraph(), data->loop_assignment(),
439 data->source_positions()); 426 data->source_positions());
440 if (graph_builder.CreateGraph()) { 427 if (!graph_builder.CreateGraph(constant_context)) {
441 data->set_context_node(graph_builder.GetFunctionContext());
442 } else {
443 data->set_compilation_failed(); 428 data->set_compilation_failed();
444 } 429 }
445 } 430 }
446 }; 431 };
447 432
448 433
449 struct ContextSpecializerPhase { 434 struct ContextSpecializerPhase {
450 static const char* phase_name() { return "context specializing"; } 435 static const char* phase_name() { return "context specializing"; }
451 436
452 void Run(PipelineData* data, Zone* temp_zone) { 437 void Run(PipelineData* data, Zone* temp_zone) {
453 SourcePositionTable::Scope pos(data->source_positions(), 438 SourcePositionTable::Scope pos(data->source_positions(),
454 SourcePosition::Unknown()); 439 SourcePosition::Unknown());
455 JSContextSpecializer spec(data->info()->context(), data->jsgraph(), 440 JSContextSpecializer spec(data->jsgraph());
456 data->context_node());
457 GraphReducer graph_reducer(data->graph(), temp_zone); 441 GraphReducer graph_reducer(data->graph(), temp_zone);
458 AddReducer(data, &graph_reducer, &spec); 442 AddReducer(data, &graph_reducer, &spec);
459 graph_reducer.ReduceGraph(); 443 graph_reducer.ReduceGraph();
460 } 444 }
461 }; 445 };
462 446
463 447
464 struct InliningPhase { 448 struct InliningPhase {
465 static const char* phase_name() { return "inlining"; } 449 static const char* phase_name() { return "inlining"; }
466 450
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 TurboCfgFile tcf(isolate()); 895 TurboCfgFile tcf(isolate());
912 tcf << AsC1VCompilation(info()); 896 tcf << AsC1VCompilation(info());
913 } 897 }
914 898
915 data.source_positions()->AddDecorator(); 899 data.source_positions()->AddDecorator();
916 900
917 if (FLAG_loop_assignment_analysis) { 901 if (FLAG_loop_assignment_analysis) {
918 Run<LoopAssignmentAnalysisPhase>(); 902 Run<LoopAssignmentAnalysisPhase>();
919 } 903 }
920 904
921 Run<GraphBuilderPhase>(); 905 Run<GraphBuilderPhase>(info()->is_context_specializing());
922 if (data.compilation_failed()) return Handle<Code>::null(); 906 if (data.compilation_failed()) return Handle<Code>::null();
923 RunPrintAndVerify("Initial untyped", true); 907 RunPrintAndVerify("Initial untyped", true);
924 908
925 Run<EarlyControlReductionPhase>(); 909 Run<EarlyControlReductionPhase>();
926 RunPrintAndVerify("Early Control reduced", true); 910 RunPrintAndVerify("Early Control reduced", true);
927 911
928 if (info()->is_context_specializing()) { 912 if (info()->is_context_specializing()) {
929 // Specialize the code to the context as aggressively as possible. 913 // Specialize the code to the context as aggressively as possible.
930 Run<ContextSpecializerPhase>(); 914 Run<ContextSpecializerPhase>();
931 RunPrintAndVerify("Context specialized", true); 915 RunPrintAndVerify("Context specialized", true);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 1195
1212 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { 1196 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) {
1213 TurboCfgFile tcf(data->isolate()); 1197 TurboCfgFile tcf(data->isolate());
1214 tcf << AsC1VAllocator("CodeGen", data->register_allocator()); 1198 tcf << AsC1VAllocator("CodeGen", data->register_allocator());
1215 } 1199 }
1216 } 1200 }
1217 1201
1218 } // namespace compiler 1202 } // namespace compiler
1219 } // namespace internal 1203 } // namespace internal
1220 } // namespace v8 1204 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/osr.cc ('k') | src/compiler/verifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698