Index: src/compiler/wasm-compiler.cc |
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc |
index 3fe64ce8a6a84fe253e61e9b5af6f3bb55d0e648..192a0593c61bdc71692b38f5ca936ac6a5b2ee68 100644 |
--- a/src/compiler/wasm-compiler.cc |
+++ b/src/compiler/wasm-compiler.cc |
@@ -389,6 +389,57 @@ Node* WasmGraphBuilder::Int64Constant(int64_t value) { |
return jsgraph()->Int64Constant(value); |
} |
+void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) { |
+ // We do not generate stack checks for cctests. |
+ if (module_ && !module_->instance->context.is_null()) { |
+ Node* limit = graph()->NewNode( |
+ jsgraph()->machine()->Load(MachineType::Pointer()), |
+ jsgraph()->ExternalConstant( |
+ ExternalReference::address_of_stack_limit(jsgraph()->isolate())), |
+ jsgraph()->IntPtrConstant(0), *effect_, *control_); |
+ Node* pointer = graph()->NewNode(jsgraph()->machine()->LoadStackPointer()); |
+ |
+ Node* check = |
+ graph()->NewNode(jsgraph()->machine()->UintLessThan(), limit, pointer); |
+ |
+ Diamond stack_check(graph(), jsgraph()->common(), check, BranchHint::kTrue); |
+ |
+ Node* effect_true = *effect_; |
+ |
+ Node* effect_false; |
+ // 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.
|
+ { |
+ // Use the module context to call the runtime to throw an exception. |
+ Runtime::FunctionId f = Runtime::kStackGuard; |
+ const Runtime::Function* fun = Runtime::FunctionForId(f); |
+ CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
+ jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties, |
+ CallDescriptor::kNoFlags); |
+ // CEntryStubConstant nodes have to be created and cached in the main |
+ // thread. At the moment this is only done for CEntryStubConstant(1). |
+ Node* inputs[] = { |
+ jsgraph()->CEntryStubConstant(fun->result_size), // C entry |
+ jsgraph()->ExternalConstant( |
+ ExternalReference(f, jsgraph()->isolate())), // ref |
+ jsgraph()->Int32Constant(fun->nargs), // arity |
+ HeapConstant(module_->instance->context), // context |
+ *effect_, |
+ stack_check.if_false}; |
+ |
+ Node* node = |
+ graph()->NewNode(jsgraph()->common()->Call(desc), |
+ static_cast<int>(arraysize(inputs)), inputs); |
+ effect_false = node; |
+ } |
+ |
+ Node* ephi = graph()->NewNode(jsgraph()->common()->EffectPhi(2), |
+ effect_true, effect_false, stack_check.merge); |
+ |
+ *control_ = stack_check.merge; |
+ *effect_ = ephi; |
+ } |
+} |
+ |
Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, |
wasm::WasmCodePosition position) { |
const Operator* op; |