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

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

Issue 770373003: Make loop assignment analysis a separate phase. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix compilation. Created 6 years 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/ast-graph-builder.cc ('k') | no next file » | 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"
11 #include "src/compiler/ast-graph-builder.h" 11 #include "src/compiler/ast-graph-builder.h"
12 #include "src/compiler/ast-loop-assignment-analyzer.h"
12 #include "src/compiler/basic-block-instrumentor.h" 13 #include "src/compiler/basic-block-instrumentor.h"
13 #include "src/compiler/change-lowering.h" 14 #include "src/compiler/change-lowering.h"
14 #include "src/compiler/code-generator.h" 15 #include "src/compiler/code-generator.h"
15 #include "src/compiler/control-reducer.h" 16 #include "src/compiler/control-reducer.h"
16 #include "src/compiler/graph-replay.h" 17 #include "src/compiler/graph-replay.h"
17 #include "src/compiler/graph-visualizer.h" 18 #include "src/compiler/graph-visualizer.h"
18 #include "src/compiler/instruction.h" 19 #include "src/compiler/instruction.h"
19 #include "src/compiler/instruction-selector.h" 20 #include "src/compiler/instruction-selector.h"
20 #include "src/compiler/js-context-specialization.h" 21 #include "src/compiler/js-context-specialization.h"
21 #include "src/compiler/js-generic-lowering.h" 22 #include "src/compiler/js-generic-lowering.h"
(...skipping 28 matching lines...) Expand all
50 : isolate_(info->zone()->isolate()), 51 : isolate_(info->zone()->isolate()),
51 info_(info), 52 info_(info),
52 outer_zone_(nullptr), 53 outer_zone_(nullptr),
53 zone_pool_(zone_pool), 54 zone_pool_(zone_pool),
54 pipeline_statistics_(nullptr), 55 pipeline_statistics_(nullptr),
55 compilation_failed_(false), 56 compilation_failed_(false),
56 code_(Handle<Code>::null()), 57 code_(Handle<Code>::null()),
57 graph_zone_scope_(zone_pool_), 58 graph_zone_scope_(zone_pool_),
58 graph_zone_(nullptr), 59 graph_zone_(nullptr),
59 graph_(nullptr), 60 graph_(nullptr),
61 loop_assignment_(nullptr),
60 machine_(nullptr), 62 machine_(nullptr),
61 common_(nullptr), 63 common_(nullptr),
62 javascript_(nullptr), 64 javascript_(nullptr),
63 jsgraph_(nullptr), 65 jsgraph_(nullptr),
64 typer_(nullptr), 66 typer_(nullptr),
65 context_node_(nullptr), 67 context_node_(nullptr),
66 schedule_(nullptr), 68 schedule_(nullptr),
67 instruction_zone_scope_(zone_pool_), 69 instruction_zone_scope_(zone_pool_),
68 instruction_zone_(nullptr), 70 instruction_zone_(nullptr),
69 sequence_(nullptr), 71 sequence_(nullptr),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 Graph* graph() const { return graph_; } 129 Graph* graph() const { return graph_; }
128 SourcePositionTable* source_positions() const { 130 SourcePositionTable* source_positions() const {
129 return source_positions_.get(); 131 return source_positions_.get();
130 } 132 }
131 MachineOperatorBuilder* machine() const { return machine_; } 133 MachineOperatorBuilder* machine() const { return machine_; }
132 CommonOperatorBuilder* common() const { return common_; } 134 CommonOperatorBuilder* common() const { return common_; }
133 JSOperatorBuilder* javascript() const { return javascript_; } 135 JSOperatorBuilder* javascript() const { return javascript_; }
134 JSGraph* jsgraph() const { return jsgraph_; } 136 JSGraph* jsgraph() const { return jsgraph_; }
135 Typer* typer() const { return typer_.get(); } 137 Typer* typer() const { return typer_.get(); }
136 138
139 LoopAssignmentAnalysis* loop_assignment() const { return loop_assignment_; }
140 void set_loop_assignment(LoopAssignmentAnalysis* loop_assignment) {
141 DCHECK_EQ(nullptr, loop_assignment_);
142 loop_assignment_ = loop_assignment;
143 }
144
137 Node* context_node() const { return context_node_; } 145 Node* context_node() const { return context_node_; }
138 void set_context_node(Node* context_node) { 146 void set_context_node(Node* context_node) {
139 DCHECK_EQ(nullptr, context_node_); 147 DCHECK_EQ(nullptr, context_node_);
140 context_node_ = context_node; 148 context_node_ = context_node;
141 } 149 }
142 150
143 Schedule* schedule() const { return schedule_; } 151 Schedule* schedule() const { return schedule_; }
144 void set_schedule(Schedule* schedule) { 152 void set_schedule(Schedule* schedule) {
145 DCHECK_EQ(nullptr, schedule_); 153 DCHECK_EQ(nullptr, schedule_);
146 schedule_ = schedule; 154 schedule_ = schedule;
147 } 155 }
148 156
149 Zone* instruction_zone() const { return instruction_zone_; } 157 Zone* instruction_zone() const { return instruction_zone_; }
150 InstructionSequence* sequence() const { return sequence_; } 158 InstructionSequence* sequence() const { return sequence_; }
151 Frame* frame() const { return frame_; } 159 Frame* frame() const { return frame_; }
152 RegisterAllocator* register_allocator() const { return register_allocator_; } 160 RegisterAllocator* register_allocator() const { return register_allocator_; }
153 161
154 void DeleteGraphZone() { 162 void DeleteGraphZone() {
155 // Destroy objects with destructors first. 163 // Destroy objects with destructors first.
156 source_positions_.Reset(nullptr); 164 source_positions_.Reset(nullptr);
157 typer_.Reset(nullptr); 165 typer_.Reset(nullptr);
158 if (graph_zone_ == nullptr) return; 166 if (graph_zone_ == nullptr) return;
159 // Destroy zone and clear pointers. 167 // Destroy zone and clear pointers.
160 graph_zone_scope_.Destroy(); 168 graph_zone_scope_.Destroy();
161 graph_zone_ = nullptr; 169 graph_zone_ = nullptr;
162 graph_ = nullptr; 170 graph_ = nullptr;
171 loop_assignment_ = nullptr;
163 machine_ = nullptr; 172 machine_ = nullptr;
164 common_ = nullptr; 173 common_ = nullptr;
165 javascript_ = nullptr; 174 javascript_ = nullptr;
166 jsgraph_ = nullptr; 175 jsgraph_ = nullptr;
167 context_node_ = nullptr; 176 context_node_ = nullptr;
168 schedule_ = nullptr; 177 schedule_ = nullptr;
169 } 178 }
170 179
171 void DeleteInstructionZone() { 180 void DeleteInstructionZone() {
172 if (instruction_zone_ == nullptr) return; 181 if (instruction_zone_ == nullptr) return;
(...skipping 25 matching lines...) Expand all
198 207
199 private: 208 private:
200 Isolate* isolate_; 209 Isolate* isolate_;
201 CompilationInfo* info_; 210 CompilationInfo* info_;
202 Zone* outer_zone_; 211 Zone* outer_zone_;
203 ZonePool* const zone_pool_; 212 ZonePool* const zone_pool_;
204 PipelineStatistics* pipeline_statistics_; 213 PipelineStatistics* pipeline_statistics_;
205 bool compilation_failed_; 214 bool compilation_failed_;
206 Handle<Code> code_; 215 Handle<Code> code_;
207 216
217 // All objects in the following group of fields are allocated in graph_zone_.
218 // They are all set to NULL when the graph_zone_ is destroyed.
208 ZonePool::Scope graph_zone_scope_; 219 ZonePool::Scope graph_zone_scope_;
209 Zone* graph_zone_; 220 Zone* graph_zone_;
210 // All objects in the following group of fields are allocated in graph_zone_.
211 // They are all set to NULL when the graph_zone_ is destroyed.
212 Graph* graph_; 221 Graph* graph_;
213 // TODO(dcarney): make this into a ZoneObject. 222 // TODO(dcarney): make this into a ZoneObject.
214 SmartPointer<SourcePositionTable> source_positions_; 223 SmartPointer<SourcePositionTable> source_positions_;
224 LoopAssignmentAnalysis* loop_assignment_;
215 MachineOperatorBuilder* machine_; 225 MachineOperatorBuilder* machine_;
216 CommonOperatorBuilder* common_; 226 CommonOperatorBuilder* common_;
217 JSOperatorBuilder* javascript_; 227 JSOperatorBuilder* javascript_;
218 JSGraph* jsgraph_; 228 JSGraph* jsgraph_;
219 // TODO(dcarney): make this into a ZoneObject. 229 // TODO(dcarney): make this into a ZoneObject.
220 SmartPointer<Typer> typer_; 230 SmartPointer<Typer> typer_;
221 Node* context_node_; 231 Node* context_node_;
222 Schedule* schedule_; 232 Schedule* schedule_;
223 233
224 // All objects in the following group of fields are allocated in 234 // All objects in the following group of fields are allocated in
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } else { 280 } else {
271 AllowHandleDereference allow_deref; 281 AllowHandleDereference allow_deref;
272 name = info->function()->debug_name()->ToCString(); 282 name = info->function()->debug_name()->ToCString();
273 } 283 }
274 return name; 284 return name;
275 } 285 }
276 286
277 287
278 class AstGraphBuilderWithPositions : public AstGraphBuilder { 288 class AstGraphBuilderWithPositions : public AstGraphBuilder {
279 public: 289 public:
280 explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, 290 AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info,
281 JSGraph* jsgraph, 291 JSGraph* jsgraph,
282 SourcePositionTable* source_positions) 292 LoopAssignmentAnalysis* loop_assignment,
283 : AstGraphBuilder(local_zone, info, jsgraph), 293 SourcePositionTable* source_positions)
294 : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment),
284 source_positions_(source_positions) {} 295 source_positions_(source_positions) {}
285 296
286 bool CreateGraph() { 297 bool CreateGraph() {
287 SourcePositionTable::Scope pos(source_positions_, 298 SourcePositionTable::Scope pos(source_positions_,
288 SourcePosition::Unknown()); 299 SourcePosition::Unknown());
289 return AstGraphBuilder::CreateGraph(); 300 return AstGraphBuilder::CreateGraph();
290 } 301 }
291 302
292 #define DEF_VISIT(type) \ 303 #define DEF_VISIT(type) \
293 virtual void Visit##type(type* node) OVERRIDE { \ 304 virtual void Visit##type(type* node) OVERRIDE { \
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 341
331 342
332 template <typename Phase, typename Arg0> 343 template <typename Phase, typename Arg0>
333 void Pipeline::Run(Arg0 arg_0) { 344 void Pipeline::Run(Arg0 arg_0) {
334 PipelineRunScope scope(this->data_, Phase::phase_name()); 345 PipelineRunScope scope(this->data_, Phase::phase_name());
335 Phase phase; 346 Phase phase;
336 phase.Run(this->data_, scope.zone(), arg_0); 347 phase.Run(this->data_, scope.zone(), arg_0);
337 } 348 }
338 349
339 350
351 struct LoopAssignmentAnalysisPhase {
352 static const char* phase_name() { return "loop assignment analysis"; }
353
354 void Run(PipelineData* data, Zone* temp_zone) {
355 AstLoopAssignmentAnalyzer analyzer(data->graph_zone(), data->info());
356 LoopAssignmentAnalysis* loop_assignment = analyzer.Analyze();
357 data->set_loop_assignment(loop_assignment);
358 }
359 };
360
361
340 struct GraphBuilderPhase { 362 struct GraphBuilderPhase {
341 static const char* phase_name() { return "graph builder"; } 363 static const char* phase_name() { return "graph builder"; }
342 364
343 void Run(PipelineData* data, Zone* temp_zone) { 365 void Run(PipelineData* data, Zone* temp_zone) {
344 AstGraphBuilderWithPositions graph_builder( 366 AstGraphBuilderWithPositions graph_builder(
345 temp_zone, data->info(), data->jsgraph(), data->source_positions()); 367 temp_zone, data->info(), data->jsgraph(), data->loop_assignment(),
368 data->source_positions());
346 if (graph_builder.CreateGraph()) { 369 if (graph_builder.CreateGraph()) {
347 data->set_context_node(graph_builder.GetFunctionContext()); 370 data->set_context_node(graph_builder.GetFunctionContext());
348 } else { 371 } else {
349 data->set_compilation_failed(); 372 data->set_compilation_failed();
350 } 373 }
351 } 374 }
352 }; 375 };
353 376
354 377
355 struct ContextSpecializerPhase { 378 struct ContextSpecializerPhase {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 OFStream os(stdout); 759 OFStream os(stdout);
737 os << "---------------------------------------------------\n" 760 os << "---------------------------------------------------\n"
738 << "Begin compiling method " << GetDebugName(info()).get() 761 << "Begin compiling method " << GetDebugName(info()).get()
739 << " using Turbofan" << std::endl; 762 << " using Turbofan" << std::endl;
740 TurboCfgFile tcf(isolate()); 763 TurboCfgFile tcf(isolate());
741 tcf << AsC1VCompilation(info()); 764 tcf << AsC1VCompilation(info());
742 } 765 }
743 766
744 data.source_positions()->AddDecorator(); 767 data.source_positions()->AddDecorator();
745 768
769 if (FLAG_loop_assignment_analysis) {
770 Run<LoopAssignmentAnalysisPhase>();
771 }
772
746 Run<GraphBuilderPhase>(); 773 Run<GraphBuilderPhase>();
747 if (data.compilation_failed()) return Handle<Code>::null(); 774 if (data.compilation_failed()) return Handle<Code>::null();
748 RunPrintAndVerify("Initial untyped", true); 775 RunPrintAndVerify("Initial untyped", true);
749 776
750 Run<EarlyControlReductionPhase>(); 777 Run<EarlyControlReductionPhase>();
751 RunPrintAndVerify("Early Control reduced", true); 778 RunPrintAndVerify("Early Control reduced", true);
752 779
753 if (info()->is_context_specializing()) { 780 if (info()->is_context_specializing()) {
754 // Specialize the code to the context as aggressively as possible. 781 // Specialize the code to the context as aggressively as possible.
755 Run<ContextSpecializerPhase>(); 782 Run<ContextSpecializerPhase>();
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 } 1060 }
1034 1061
1035 1062
1036 void Pipeline::TearDown() { 1063 void Pipeline::TearDown() {
1037 InstructionOperand::TearDownCaches(); 1064 InstructionOperand::TearDownCaches();
1038 } 1065 }
1039 1066
1040 } // namespace compiler 1067 } // namespace compiler
1041 } // namespace internal 1068 } // namespace internal
1042 } // namespace v8 1069 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/ast-graph-builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698