OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
6 | 6 |
7 #include "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 if (traps_[reason] == nullptr) { | 190 if (traps_[reason] == nullptr) { |
191 // Create trap code for the first time this trap is used. | 191 // Create trap code for the first time this trap is used. |
192 return BuildTrapCode(reason); | 192 return BuildTrapCode(reason); |
193 } | 193 } |
194 // Connect the current control and effect to the existing trap code. | 194 // Connect the current control and effect to the existing trap code. |
195 builder_->AppendToMerge(traps_[reason], builder_->Control()); | 195 builder_->AppendToMerge(traps_[reason], builder_->Control()); |
196 builder_->AppendToPhi(traps_[reason], effects_[reason], builder_->Effect()); | 196 builder_->AppendToPhi(traps_[reason], effects_[reason], builder_->Effect()); |
197 } | 197 } |
198 | 198 |
199 void BuildTrapCode(wasm::TrapReason reason) { | 199 void BuildTrapCode(wasm::TrapReason reason) { |
200 Node* exception = | 200 Node* message_id = builder_->NumberConstant( |
201 builder_->String(wasm::WasmOpcodes::TrapReasonMessage(reason)); | 201 wasm::WasmOpcodes::TrapReasonToMessageId(reason)); |
202 Node* end; | 202 Node* end; |
203 Node** control_ptr = builder_->control_; | 203 Node** control_ptr = builder_->control_; |
204 Node** effect_ptr = builder_->effect_; | 204 Node** effect_ptr = builder_->effect_; |
205 wasm::ModuleEnv* module = builder_->module_; | 205 wasm::ModuleEnv* module = builder_->module_; |
| 206 DCHECK(traps_[reason] == NULL); |
206 *control_ptr = traps_[reason] = | 207 *control_ptr = traps_[reason] = |
207 graph()->NewNode(common()->Merge(1), *control_ptr); | 208 graph()->NewNode(common()->Merge(1), *control_ptr); |
208 *effect_ptr = effects_[reason] = | 209 *effect_ptr = effects_[reason] = |
209 graph()->NewNode(common()->EffectPhi(1), *effect_ptr, *control_ptr); | 210 graph()->NewNode(common()->EffectPhi(1), *effect_ptr, *control_ptr); |
210 | 211 |
211 if (module && !module->instance->context.is_null()) { | 212 if (module && !module->instance->context.is_null()) { |
212 // Use the module context to call the runtime to throw an exception. | 213 // Use the module context to call the runtime to throw an exception. |
213 Runtime::FunctionId f = Runtime::kThrow; | 214 Runtime::FunctionId f = Runtime::kThrowWasmError; |
214 const Runtime::Function* fun = Runtime::FunctionForId(f); | 215 const Runtime::Function* fun = Runtime::FunctionForId(f); |
215 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 216 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
216 jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties, | 217 jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties, |
217 CallDescriptor::kNoFlags); | 218 CallDescriptor::kNoFlags); |
218 Node* inputs[] = { | 219 Node* inputs[] = { |
219 jsgraph()->CEntryStubConstant(fun->result_size), // C entry | 220 jsgraph()->CEntryStubConstant(fun->result_size), // C entry |
220 exception, // exception | 221 message_id, // message id |
221 jsgraph()->ExternalConstant( | 222 jsgraph()->ExternalConstant( |
222 ExternalReference(f, jsgraph()->isolate())), // ref | 223 ExternalReference(f, jsgraph()->isolate())), // ref |
223 jsgraph()->Int32Constant(fun->nargs), // arity | 224 jsgraph()->Int32Constant(fun->nargs), // arity |
224 jsgraph()->Constant(module->instance->context), // context | 225 jsgraph()->Constant(module->instance->context), // context |
225 *effect_ptr, | 226 *effect_ptr, |
226 *control_ptr}; | 227 *control_ptr}; |
227 | 228 |
228 Node* node = graph()->NewNode( | 229 Node* node = graph()->NewNode( |
229 common()->Call(desc), static_cast<int>(arraysize(inputs)), inputs); | 230 common()->Call(desc), static_cast<int>(arraysize(inputs)), inputs); |
230 *control_ptr = node; | 231 *control_ptr = node; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 342 |
342 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, | 343 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, |
343 Node* control) { | 344 Node* control) { |
344 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); | 345 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); |
345 Node** buf = Realloc(effects, count, count + 1); | 346 Node** buf = Realloc(effects, count, count + 1); |
346 buf[count] = control; | 347 buf[count] = control; |
347 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, | 348 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, |
348 buf); | 349 buf); |
349 } | 350 } |
350 | 351 |
| 352 Node* WasmGraphBuilder::NumberConstant(int32_t value) { |
| 353 return jsgraph()->Constant(value); |
| 354 } |
351 | 355 |
352 Node* WasmGraphBuilder::Int32Constant(int32_t value) { | 356 Node* WasmGraphBuilder::Int32Constant(int32_t value) { |
353 return jsgraph()->Int32Constant(value); | 357 return jsgraph()->Int32Constant(value); |
354 } | 358 } |
355 | 359 |
356 | 360 |
357 Node* WasmGraphBuilder::Int64Constant(int64_t value) { | 361 Node* WasmGraphBuilder::Int64Constant(int64_t value) { |
358 return jsgraph()->Int64Constant(value); | 362 return jsgraph()->Int64Constant(value); |
359 } | 363 } |
360 | 364 |
(...skipping 2417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2778 static_cast<int>(function.code_end_offset - function.code_start_offset), | 2782 static_cast<int>(function.code_end_offset - function.code_start_offset), |
2779 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms); | 2783 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms); |
2780 } | 2784 } |
2781 return code; | 2785 return code; |
2782 } | 2786 } |
2783 | 2787 |
2784 | 2788 |
2785 } // namespace compiler | 2789 } // namespace compiler |
2786 } // namespace internal | 2790 } // namespace internal |
2787 } // namespace v8 | 2791 } // namespace v8 |
OLD | NEW |