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

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

Issue 1890803002: [wasm] Generate source position information (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-throw-error
Patch Set: minor Created 4 years, 8 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
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/adapters.h" 10 #include "src/base/adapters.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 class PipelineData { 76 class PipelineData {
77 public: 77 public:
78 // For main entry point. 78 // For main entry point.
79 PipelineData(ZonePool* zone_pool, CompilationInfo* info, 79 PipelineData(ZonePool* zone_pool, CompilationInfo* info,
80 PipelineStatistics* pipeline_statistics) 80 PipelineStatistics* pipeline_statistics)
81 : isolate_(info->isolate()), 81 : isolate_(info->isolate()),
82 info_(info), 82 info_(info),
83 outer_zone_(info_->zone()), 83 outer_zone_(info_->zone()),
84 zone_pool_(zone_pool), 84 zone_pool_(zone_pool),
85 pipeline_statistics_(pipeline_statistics), 85 pipeline_statistics_(pipeline_statistics),
86 compilation_failed_(false),
87 code_(Handle<Code>::null()),
88 graph_zone_scope_(zone_pool_), 86 graph_zone_scope_(zone_pool_),
89 graph_zone_(graph_zone_scope_.zone()), 87 graph_zone_(graph_zone_scope_.zone()),
90 graph_(nullptr),
91 loop_assignment_(nullptr),
92 simplified_(nullptr),
93 machine_(nullptr),
94 common_(nullptr),
95 javascript_(nullptr),
96 jsgraph_(nullptr),
97 schedule_(nullptr),
98 instruction_zone_scope_(zone_pool_), 88 instruction_zone_scope_(zone_pool_),
99 instruction_zone_(instruction_zone_scope_.zone()), 89 instruction_zone_(instruction_zone_scope_.zone()),
100 sequence_(nullptr),
101 frame_(nullptr),
102 register_allocation_zone_scope_(zone_pool_), 90 register_allocation_zone_scope_(zone_pool_),
103 register_allocation_zone_(register_allocation_zone_scope_.zone()), 91 register_allocation_zone_(register_allocation_zone_scope_.zone()) {
104 register_allocation_data_(nullptr) {
105 PhaseScope scope(pipeline_statistics, "init pipeline data"); 92 PhaseScope scope(pipeline_statistics, "init pipeline data");
106 graph_ = new (graph_zone_) Graph(graph_zone_); 93 graph_ = new (graph_zone_) Graph(graph_zone_);
107 source_positions_.Reset(new SourcePositionTable(graph_)); 94 source_positions_ = new SourcePositionTable(graph_);
95 source_positions_owned_ = true;
108 simplified_ = new (graph_zone_) SimplifiedOperatorBuilder(graph_zone_); 96 simplified_ = new (graph_zone_) SimplifiedOperatorBuilder(graph_zone_);
109 machine_ = new (graph_zone_) MachineOperatorBuilder( 97 machine_ = new (graph_zone_) MachineOperatorBuilder(
110 graph_zone_, MachineType::PointerRepresentation(), 98 graph_zone_, MachineType::PointerRepresentation(),
111 InstructionSelector::SupportedMachineOperatorFlags()); 99 InstructionSelector::SupportedMachineOperatorFlags());
112 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); 100 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_);
113 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); 101 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_);
114 jsgraph_ = new (graph_zone_) 102 jsgraph_ = new (graph_zone_)
115 JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_); 103 JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_);
116 } 104 }
117 105
106 // For WASM compile entry point.
107 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph,
108 SourcePositionTable* source_positions)
109 : isolate_(info->isolate()),
110 info_(info),
111 zone_pool_(zone_pool),
112 graph_zone_scope_(zone_pool_),
113 graph_(graph),
114 source_positions_(source_positions),
115 instruction_zone_scope_(zone_pool_),
116 instruction_zone_(instruction_zone_scope_.zone()),
117 register_allocation_zone_scope_(zone_pool_),
118 register_allocation_zone_(register_allocation_zone_scope_.zone()) {}
119
118 // For machine graph testing entry point. 120 // For machine graph testing entry point.
119 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, 121 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph,
120 Schedule* schedule) 122 Schedule* schedule)
121 : isolate_(info->isolate()), 123 : isolate_(info->isolate()),
122 info_(info), 124 info_(info),
123 outer_zone_(nullptr),
124 zone_pool_(zone_pool), 125 zone_pool_(zone_pool),
125 pipeline_statistics_(nullptr),
126 compilation_failed_(false),
127 code_(Handle<Code>::null()),
128 graph_zone_scope_(zone_pool_), 126 graph_zone_scope_(zone_pool_),
129 graph_zone_(nullptr),
130 graph_(graph), 127 graph_(graph),
131 source_positions_(new SourcePositionTable(graph_)), 128 source_positions_(new SourcePositionTable(graph_)),
132 loop_assignment_(nullptr), 129 source_positions_owned_(true),
133 simplified_(nullptr),
134 machine_(nullptr),
135 common_(nullptr),
136 javascript_(nullptr),
137 jsgraph_(nullptr),
138 schedule_(schedule), 130 schedule_(schedule),
139 instruction_zone_scope_(zone_pool_), 131 instruction_zone_scope_(zone_pool_),
140 instruction_zone_(instruction_zone_scope_.zone()), 132 instruction_zone_(instruction_zone_scope_.zone()),
141 sequence_(nullptr),
142 frame_(nullptr),
143 register_allocation_zone_scope_(zone_pool_), 133 register_allocation_zone_scope_(zone_pool_),
144 register_allocation_zone_(register_allocation_zone_scope_.zone()), 134 register_allocation_zone_(register_allocation_zone_scope_.zone()) {}
145 register_allocation_data_(nullptr) {}
146 135
147 // For register allocation testing entry point. 136 // For register allocation testing entry point.
148 PipelineData(ZonePool* zone_pool, CompilationInfo* info, 137 PipelineData(ZonePool* zone_pool, CompilationInfo* info,
149 InstructionSequence* sequence) 138 InstructionSequence* sequence)
150 : isolate_(info->isolate()), 139 : isolate_(info->isolate()),
151 info_(info), 140 info_(info),
152 outer_zone_(nullptr),
153 zone_pool_(zone_pool), 141 zone_pool_(zone_pool),
154 pipeline_statistics_(nullptr),
155 compilation_failed_(false),
156 code_(Handle<Code>::null()),
157 graph_zone_scope_(zone_pool_), 142 graph_zone_scope_(zone_pool_),
158 graph_zone_(nullptr),
159 graph_(nullptr),
160 loop_assignment_(nullptr),
161 simplified_(nullptr),
162 machine_(nullptr),
163 common_(nullptr),
164 javascript_(nullptr),
165 jsgraph_(nullptr),
166 schedule_(nullptr),
167 instruction_zone_scope_(zone_pool_), 143 instruction_zone_scope_(zone_pool_),
168 instruction_zone_(sequence->zone()), 144 instruction_zone_(sequence->zone()),
169 sequence_(sequence), 145 sequence_(sequence),
170 frame_(nullptr),
171 register_allocation_zone_scope_(zone_pool_), 146 register_allocation_zone_scope_(zone_pool_),
172 register_allocation_zone_(register_allocation_zone_scope_.zone()), 147 register_allocation_zone_(register_allocation_zone_scope_.zone()) {}
173 register_allocation_data_(nullptr) {}
174 148
175 ~PipelineData() { 149 ~PipelineData() {
176 DeleteRegisterAllocationZone(); 150 DeleteRegisterAllocationZone();
177 DeleteInstructionZone(); 151 DeleteInstructionZone();
178 DeleteGraphZone(); 152 DeleteGraphZone();
179 } 153 }
180 154
181 Isolate* isolate() const { return isolate_; } 155 Isolate* isolate() const { return isolate_; }
182 CompilationInfo* info() const { return info_; } 156 CompilationInfo* info() const { return info_; }
183 ZonePool* zone_pool() const { return zone_pool_; } 157 ZonePool* zone_pool() const { return zone_pool_; }
184 PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } 158 PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; }
185 bool compilation_failed() const { return compilation_failed_; } 159 bool compilation_failed() const { return compilation_failed_; }
186 void set_compilation_failed() { compilation_failed_ = true; } 160 void set_compilation_failed() { compilation_failed_ = true; }
187 Handle<Code> code() { return code_; } 161 Handle<Code> code() { return code_; }
188 void set_code(Handle<Code> code) { 162 void set_code(Handle<Code> code) {
189 DCHECK(code_.is_null()); 163 DCHECK(code_.is_null());
190 code_ = code; 164 code_ = code;
191 } 165 }
192 166
193 // RawMachineAssembler generally produces graphs which cannot be verified. 167 // RawMachineAssembler generally produces graphs which cannot be verified.
194 bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } 168 bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; }
195 169
196 Zone* graph_zone() const { return graph_zone_; } 170 Zone* graph_zone() const { return graph_zone_; }
197 Graph* graph() const { return graph_; } 171 Graph* graph() const { return graph_; }
198 SourcePositionTable* source_positions() const { 172 SourcePositionTable* source_positions() const {
199 return source_positions_.get(); 173 DCHECK_NOT_NULL(source_positions_);
174 return source_positions_;
200 } 175 }
201 MachineOperatorBuilder* machine() const { return machine_; } 176 MachineOperatorBuilder* machine() const { return machine_; }
202 CommonOperatorBuilder* common() const { return common_; } 177 CommonOperatorBuilder* common() const { return common_; }
203 JSOperatorBuilder* javascript() const { return javascript_; } 178 JSOperatorBuilder* javascript() const { return javascript_; }
204 JSGraph* jsgraph() const { return jsgraph_; } 179 JSGraph* jsgraph() const { return jsgraph_; }
205 MaybeHandle<Context> native_context() const { 180 MaybeHandle<Context> native_context() const {
206 if (info()->is_native_context_specializing()) { 181 if (info()->is_native_context_specializing()) {
207 return handle(info()->native_context(), isolate()); 182 return handle(info()->native_context(), isolate());
208 } 183 }
209 return MaybeHandle<Context>(); 184 return MaybeHandle<Context>();
(...skipping 22 matching lines...) Expand all
232 InstructionSequence* sequence() const { return sequence_; } 207 InstructionSequence* sequence() const { return sequence_; }
233 Frame* frame() const { return frame_; } 208 Frame* frame() const { return frame_; }
234 209
235 Zone* register_allocation_zone() const { return register_allocation_zone_; } 210 Zone* register_allocation_zone() const { return register_allocation_zone_; }
236 RegisterAllocationData* register_allocation_data() const { 211 RegisterAllocationData* register_allocation_data() const {
237 return register_allocation_data_; 212 return register_allocation_data_;
238 } 213 }
239 214
240 void DeleteGraphZone() { 215 void DeleteGraphZone() {
241 // Destroy objects with destructors first. 216 // Destroy objects with destructors first.
242 source_positions_.Reset(nullptr); 217 if (source_positions_owned_ && source_positions_) delete source_positions_;
218 source_positions_ = nullptr;
219 source_positions_owned_ = false;
243 if (graph_zone_ == nullptr) return; 220 if (graph_zone_ == nullptr) return;
244 // Destroy zone and clear pointers. 221 // Destroy zone and clear pointers.
245 graph_zone_scope_.Destroy(); 222 graph_zone_scope_.Destroy();
246 graph_zone_ = nullptr; 223 graph_zone_ = nullptr;
247 graph_ = nullptr; 224 graph_ = nullptr;
248 loop_assignment_ = nullptr; 225 loop_assignment_ = nullptr;
249 type_hint_analysis_ = nullptr; 226 type_hint_analysis_ = nullptr;
250 simplified_ = nullptr; 227 simplified_ = nullptr;
251 machine_ = nullptr; 228 machine_ = nullptr;
252 common_ = nullptr; 229 common_ = nullptr;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 const char* debug_name) { 276 const char* debug_name) {
300 DCHECK(register_allocation_data_ == nullptr); 277 DCHECK(register_allocation_data_ == nullptr);
301 register_allocation_data_ = new (register_allocation_zone()) 278 register_allocation_data_ = new (register_allocation_zone())
302 RegisterAllocationData(config, register_allocation_zone(), frame(), 279 RegisterAllocationData(config, register_allocation_zone(), frame(),
303 sequence(), debug_name); 280 sequence(), debug_name);
304 } 281 }
305 282
306 private: 283 private:
307 Isolate* isolate_; 284 Isolate* isolate_;
308 CompilationInfo* info_; 285 CompilationInfo* info_;
309 Zone* outer_zone_; 286 Zone* outer_zone_ = nullptr;
310 ZonePool* const zone_pool_; 287 ZonePool* const zone_pool_;
311 PipelineStatistics* pipeline_statistics_; 288 PipelineStatistics* pipeline_statistics_ = nullptr;
312 bool compilation_failed_; 289 bool compilation_failed_ = false;
313 Handle<Code> code_; 290 Handle<Code> code_;
314 291
315 // All objects in the following group of fields are allocated in graph_zone_. 292 // All objects in the following group of fields are allocated in graph_zone_.
316 // They are all set to nullptr when the graph_zone_ is destroyed. 293 // They are all set to nullptr when the graph_zone_ is destroyed.
317 ZonePool::Scope graph_zone_scope_; 294 ZonePool::Scope graph_zone_scope_;
318 Zone* graph_zone_; 295 Zone* graph_zone_ = nullptr;
319 Graph* graph_; 296 Graph* graph_ = nullptr;
320 // TODO(dcarney): make this into a ZoneObject. 297 // TODO(dcarney): make this into a ZoneObject.
321 base::SmartPointer<SourcePositionTable> source_positions_; 298 SourcePositionTable* source_positions_ = nullptr;
322 LoopAssignmentAnalysis* loop_assignment_; 299 // remember whether we allocated the SourcePositionTable ourselves.
300 bool source_positions_owned_ = false;
301 LoopAssignmentAnalysis* loop_assignment_ = nullptr;
323 TypeHintAnalysis* type_hint_analysis_ = nullptr; 302 TypeHintAnalysis* type_hint_analysis_ = nullptr;
324 SimplifiedOperatorBuilder* simplified_; 303 SimplifiedOperatorBuilder* simplified_ = nullptr;
325 MachineOperatorBuilder* machine_; 304 MachineOperatorBuilder* machine_ = nullptr;
326 CommonOperatorBuilder* common_; 305 CommonOperatorBuilder* common_ = nullptr;
327 JSOperatorBuilder* javascript_; 306 JSOperatorBuilder* javascript_ = nullptr;
328 JSGraph* jsgraph_; 307 JSGraph* jsgraph_ = nullptr;
329 Schedule* schedule_; 308 Schedule* schedule_ = nullptr;
330 309
331 // All objects in the following group of fields are allocated in 310 // All objects in the following group of fields are allocated in
332 // instruction_zone_. They are all set to nullptr when the instruction_zone_ 311 // instruction_zone_. They are all set to nullptr when the instruction_zone_
333 // is 312 // is
334 // destroyed. 313 // destroyed.
335 ZonePool::Scope instruction_zone_scope_; 314 ZonePool::Scope instruction_zone_scope_;
336 Zone* instruction_zone_; 315 Zone* instruction_zone_;
337 InstructionSequence* sequence_; 316 InstructionSequence* sequence_ = nullptr;
338 Frame* frame_; 317 Frame* frame_ = nullptr;
339 318
340 // All objects in the following group of fields are allocated in 319 // All objects in the following group of fields are allocated in
341 // register_allocation_zone_. They are all set to nullptr when the zone is 320 // register_allocation_zone_. They are all set to nullptr when the zone is
342 // destroyed. 321 // destroyed.
343 ZonePool::Scope register_allocation_zone_scope_; 322 ZonePool::Scope register_allocation_zone_scope_;
344 Zone* register_allocation_zone_; 323 Zone* register_allocation_zone_;
345 RegisterAllocationData* register_allocation_data_; 324 RegisterAllocationData* register_allocation_data_ = nullptr;
346 325
347 int CalculateFixedFrameSize(CallDescriptor* descriptor) { 326 int CalculateFixedFrameSize(CallDescriptor* descriptor) {
348 if (descriptor->IsJSFunctionCall()) { 327 if (descriptor->IsJSFunctionCall()) {
349 return StandardFrameConstants::kFixedSlotCount; 328 return StandardFrameConstants::kFixedSlotCount;
350 } 329 }
351 return descriptor->IsCFunctionCall() 330 return descriptor->IsCFunctionCall()
352 ? (CommonFrameConstants::kFixedSlotCountAboveFp + 331 ? (CommonFrameConstants::kFixedSlotCountAboveFp +
353 CommonFrameConstants::kCPSlotCount) 332 CommonFrameConstants::kCPSlotCount)
354 : TypedFrameConstants::kFixedSlotCount; 333 : TypedFrameConstants::kFixedSlotCount;
355 } 334 }
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 1286
1308 data.source_positions()->RemoveDecorator(); 1287 data.source_positions()->RemoveDecorator();
1309 1288
1310 // Kill the Typer and thereby uninstall the decorator (if any). 1289 // Kill the Typer and thereby uninstall the decorator (if any).
1311 typer.Reset(nullptr); 1290 typer.Reset(nullptr);
1312 1291
1313 return ScheduleAndGenerateCode( 1292 return ScheduleAndGenerateCode(
1314 Linkage::ComputeIncoming(data.instruction_zone(), info())); 1293 Linkage::ComputeIncoming(data.instruction_zone(), info()));
1315 } 1294 }
1316 1295
1296 Handle<Code> Pipeline::GenerateWASMCode(CompilationInfo* info,
1297 CallDescriptor* call_descriptor,
1298 Graph* graph,
1299 SourcePositionTable* source_positions) {
1300 // Construct a pipeline for scheduling and code generation.
1301 ZonePool zone_pool(info->isolate()->allocator());
1302 PipelineData data(&zone_pool, info, graph, source_positions);
1303 base::SmartPointer<PipelineStatistics> pipeline_statistics;
1304 if (FLAG_turbo_stats) {
1305 pipeline_statistics.Reset(new PipelineStatistics(info, &zone_pool));
1306 pipeline_statistics->BeginPhaseKind("test codegen");
1307 }
1308
1309 Pipeline pipeline(info);
1310 pipeline.data_ = &data;
1311 if (data.schedule() == nullptr) {
1312 // TODO(rossberg): Should this really be untyped?
1313 pipeline.RunPrintAndVerify("Machine", true);
1314 }
1315
1316 Handle<Code> code = pipeline.ScheduleAndGenerateCode(call_descriptor);
1317 return code;
1318 }
1317 1319
1318 Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, 1320 Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate,
1319 CallDescriptor* call_descriptor, 1321 CallDescriptor* call_descriptor,
1320 Graph* graph, Schedule* schedule, 1322 Graph* graph, Schedule* schedule,
1321 Code::Flags flags, 1323 Code::Flags flags,
1322 const char* debug_name) { 1324 const char* debug_name) {
1323 CompilationInfo info(debug_name, isolate, graph->zone(), flags); 1325 CompilationInfo info(debug_name, isolate, graph->zone(), flags);
1324 1326
1325 // Construct a pipeline for scheduling and code generation. 1327 // Construct a pipeline for scheduling and code generation.
1326 ZonePool zone_pool(isolate->allocator()); 1328 ZonePool zone_pool(isolate->allocator());
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 } 1594 }
1593 1595
1594 data->DeleteRegisterAllocationZone(); 1596 data->DeleteRegisterAllocationZone();
1595 } 1597 }
1596 1598
1597 Isolate* Pipeline::isolate() const { return info()->isolate(); } 1599 Isolate* Pipeline::isolate() const { return info()->isolate(); }
1598 1600
1599 } // namespace compiler 1601 } // namespace compiler
1600 } // namespace internal 1602 } // namespace internal
1601 } // namespace v8 1603 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698