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

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2256603002: [wasm] Add stack checks at the beginning of each function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use the BuildCallToRuntime function. Created 4 years, 4 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
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/wasm/ast-decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 381 }
382 382
383 Node* WasmGraphBuilder::Int32Constant(int32_t value) { 383 Node* WasmGraphBuilder::Int32Constant(int32_t value) {
384 return jsgraph()->Int32Constant(value); 384 return jsgraph()->Int32Constant(value);
385 } 385 }
386 386
387 Node* WasmGraphBuilder::Int64Constant(int64_t value) { 387 Node* WasmGraphBuilder::Int64Constant(int64_t value) {
388 return jsgraph()->Int64Constant(value); 388 return jsgraph()->Int64Constant(value);
389 } 389 }
390 390
391 void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) {
392 // We do not generate stack checks for cctests.
393 if (module_ && !module_->instance->context.is_null()) {
394 Node* limit = graph()->NewNode(
395 jsgraph()->machine()->Load(MachineType::Pointer()),
396 jsgraph()->ExternalConstant(
397 ExternalReference::address_of_stack_limit(jsgraph()->isolate())),
398 jsgraph()->IntPtrConstant(0), *effect_, *control_);
399 Node* pointer = graph()->NewNode(jsgraph()->machine()->LoadStackPointer());
400
401 Node* check =
402 graph()->NewNode(jsgraph()->machine()->UintLessThan(), limit, pointer);
403
404 Diamond stack_check(graph(), jsgraph()->common(), check, BranchHint::kTrue);
405
406 Node* effect_true = *effect_;
407
408 Node* effect_false;
409 // Generate a call to the runtime if there is a stack check failure.
410 {
411 Node* node = BuildCallToRuntime(Runtime::kStackGuard, jsgraph(),
412 module_->instance->context, nullptr, 0,
413 effect_, control_);
Michael Starzinger 2016/08/18 17:22:48 This should be s/control_/diamond.if_false/ here,
ahaas 2016/08/19 07:13:42 Thanks for noticing this. I fixed it now.
414 effect_false = node;
415 }
416
417 Node* ephi = graph()->NewNode(jsgraph()->common()->EffectPhi(2),
418 effect_true, effect_false, stack_check.merge);
419
420 *control_ = stack_check.merge;
421 *effect_ = ephi;
422 }
423 }
424
391 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, 425 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right,
392 wasm::WasmCodePosition position) { 426 wasm::WasmCodePosition position) {
393 const Operator* op; 427 const Operator* op;
394 MachineOperatorBuilder* m = jsgraph()->machine(); 428 MachineOperatorBuilder* m = jsgraph()->machine();
395 switch (opcode) { 429 switch (opcode) {
396 case wasm::kExprI32Add: 430 case wasm::kExprI32Add:
397 op = m->Int32Add(); 431 op = m->Int32Add();
398 break; 432 break;
399 case wasm::kExprI32Sub: 433 case wasm::kExprI32Sub:
400 op = m->Int32Sub(); 434 op = m->Int32Sub();
(...skipping 2831 matching lines...) Expand 10 before | Expand all | Expand 10 after
3232 function_->code_start_offset), 3266 function_->code_start_offset),
3233 compile_ms); 3267 compile_ms);
3234 } 3268 }
3235 3269
3236 return code; 3270 return code;
3237 } 3271 }
3238 3272
3239 } // namespace compiler 3273 } // namespace compiler
3240 } // namespace internal 3274 } // namespace internal
3241 } // namespace v8 3275 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/wasm/ast-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698