Index: src/compiler/ast-graph-builder.cc |
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc |
index d33b05ac18fcd74b2ffe485b6bdc120659e18e95..570a220e7ddeeff428646d720de48afce7774623 100644 |
--- a/src/compiler/ast-graph-builder.cc |
+++ b/src/compiler/ast-graph-builder.cc |
@@ -86,8 +86,8 @@ bool AstGraphBuilder::CreateGraph() { |
// Visit declarations within the function scope. |
VisitDeclarations(scope->declarations()); |
- // TODO(mstarzinger): This should do an inlined stack check. |
- Node* node = NewNode(javascript()->CallRuntime(Runtime::kStackGuard, 0)); |
+ // Build a stack-check before the body. |
+ Node* node = BuildStackCheck(); |
PrepareFrameState(node, BailoutId::FunctionEntry()); |
// Visit statements in the function body. |
@@ -2060,6 +2060,24 @@ Node* AstGraphBuilder::BuildBinaryOp(Node* left, Node* right, Token::Value op) { |
} |
+Node* AstGraphBuilder::BuildStackCheck() { |
+ IfBuilder stack_check(this); |
+ Node* limit = |
+ NewNode(jsgraph()->machine()->Load(kMachPtr), |
+ jsgraph()->ExternalConstant( |
+ ExternalReference::address_of_stack_limit(isolate())), |
+ jsgraph()->ZeroConstant()); |
+ Node* stack = NewNode(jsgraph()->machine()->LoadStackPointer()); |
+ Node* tag = NewNode(jsgraph()->machine()->UintLessThan(), limit, stack); |
+ stack_check.If(tag); |
+ stack_check.Then(); |
+ stack_check.Else(); |
+ Node* guard = NewNode(javascript()->CallRuntime(Runtime::kStackGuard, 0)); |
+ stack_check.End(); |
+ return guard; |
+} |
+ |
+ |
void AstGraphBuilder::PrepareFrameState(Node* node, BailoutId ast_id, |
OutputFrameStateCombine combine) { |
if (OperatorProperties::HasFrameStateInput(node->op())) { |