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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 | 10 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 } | 382 } |
383 | 383 |
384 Node* WasmGraphBuilder::Int32Constant(int32_t value) { | 384 Node* WasmGraphBuilder::Int32Constant(int32_t value) { |
385 return jsgraph()->Int32Constant(value); | 385 return jsgraph()->Int32Constant(value); |
386 } | 386 } |
387 | 387 |
388 Node* WasmGraphBuilder::Int64Constant(int64_t value) { | 388 Node* WasmGraphBuilder::Int64Constant(int64_t value) { |
389 return jsgraph()->Int64Constant(value); | 389 return jsgraph()->Int64Constant(value); |
390 } | 390 } |
391 | 391 |
392 void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) { | |
393 // We do not generate stack checks for cctests. | |
394 if (module_ && !module_->instance->context.is_null()) { | |
395 Node* limit = graph()->NewNode( | |
396 jsgraph()->machine()->Load(MachineType::Pointer()), | |
397 jsgraph()->ExternalConstant( | |
398 ExternalReference::address_of_stack_limit(jsgraph()->isolate())), | |
399 jsgraph()->IntPtrConstant(0), *effect_, *control_); | |
400 Node* pointer = graph()->NewNode(jsgraph()->machine()->LoadStackPointer()); | |
401 | |
402 Node* check = | |
403 graph()->NewNode(jsgraph()->machine()->UintLessThan(), limit, pointer); | |
404 | |
405 Diamond stack_check(graph(), jsgraph()->common(), check, BranchHint::kTrue); | |
406 | |
407 Node* effect_true = *effect_; | |
408 | |
409 Node* effect_false; | |
410 // Generate a call to the runtime if there is a stack overflow. | |
titzer
2016/08/18 10:55:09
s/stack overflow/stack check failure/
Since, as m
ahaas
2016/08/18 17:10:49
Done.
| |
411 { | |
412 // Use the module context to call the runtime to throw an exception. | |
413 Runtime::FunctionId f = Runtime::kStackGuard; | |
414 const Runtime::Function* fun = Runtime::FunctionForId(f); | |
415 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
416 jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties, | |
417 CallDescriptor::kNoFlags); | |
418 // CEntryStubConstant nodes have to be created and cached in the main | |
419 // thread. At the moment this is only done for CEntryStubConstant(1). | |
420 Node* inputs[] = { | |
421 jsgraph()->CEntryStubConstant(fun->result_size), // C entry | |
422 jsgraph()->ExternalConstant( | |
423 ExternalReference(f, jsgraph()->isolate())), // ref | |
424 jsgraph()->Int32Constant(fun->nargs), // arity | |
425 HeapConstant(module_->instance->context), // context | |
426 *effect_, | |
427 stack_check.if_false}; | |
428 | |
429 Node* node = | |
430 graph()->NewNode(jsgraph()->common()->Call(desc), | |
431 static_cast<int>(arraysize(inputs)), inputs); | |
432 effect_false = node; | |
433 } | |
434 | |
435 Node* ephi = graph()->NewNode(jsgraph()->common()->EffectPhi(2), | |
436 effect_true, effect_false, stack_check.merge); | |
437 | |
438 *control_ = stack_check.merge; | |
439 *effect_ = ephi; | |
440 } | |
441 } | |
442 | |
392 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, | 443 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, |
393 wasm::WasmCodePosition position) { | 444 wasm::WasmCodePosition position) { |
394 const Operator* op; | 445 const Operator* op; |
395 MachineOperatorBuilder* m = jsgraph()->machine(); | 446 MachineOperatorBuilder* m = jsgraph()->machine(); |
396 switch (opcode) { | 447 switch (opcode) { |
397 case wasm::kExprI32Add: | 448 case wasm::kExprI32Add: |
398 op = m->Int32Add(); | 449 op = m->Int32Add(); |
399 break; | 450 break; |
400 case wasm::kExprI32Sub: | 451 case wasm::kExprI32Sub: |
401 op = m->Int32Sub(); | 452 op = m->Int32Sub(); |
(...skipping 2836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3238 function_->code_start_offset), | 3289 function_->code_start_offset), |
3239 compile_ms); | 3290 compile_ms); |
3240 } | 3291 } |
3241 | 3292 |
3242 return code; | 3293 return code; |
3243 } | 3294 } |
3244 | 3295 |
3245 } // namespace compiler | 3296 } // namespace compiler |
3246 } // namespace internal | 3297 } // namespace internal |
3247 } // namespace v8 | 3298 } // namespace v8 |
OLD | NEW |