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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 } | 367 } |
368 | 368 |
369 Node* WasmGraphBuilder::Int32Constant(int32_t value) { | 369 Node* WasmGraphBuilder::Int32Constant(int32_t value) { |
370 return jsgraph()->Int32Constant(value); | 370 return jsgraph()->Int32Constant(value); |
371 } | 371 } |
372 | 372 |
373 Node* WasmGraphBuilder::Int64Constant(int64_t value) { | 373 Node* WasmGraphBuilder::Int64Constant(int64_t value) { |
374 return jsgraph()->Int64Constant(value); | 374 return jsgraph()->Int64Constant(value); |
375 } | 375 } |
376 | 376 |
377 void WasmGraphBuilder::InitStackCheck(wasm::WasmCodePosition position) { | |
378 // We do not generate stack checks for cctests. | |
379 if (module_ && !module_->instance->context.is_null()) { | |
380 Node* limit = graph()->NewNode( | |
381 jsgraph()->machine()->Load(MachineType::Pointer()), | |
382 jsgraph()->ExternalConstant( | |
383 ExternalReference::address_of_stack_limit(jsgraph()->isolate())), | |
384 jsgraph()->IntPtrConstant(0), *effect_, *control_); | |
385 Node* pointer = graph()->NewNode(jsgraph()->machine()->LoadStackPointer()); | |
386 | |
387 Node* check = | |
388 graph()->NewNode(jsgraph()->machine()->UintLessThan(), limit, pointer); | |
389 | |
390 Node* branch = graph()->NewNode( | |
titzer
2016/08/17 11:17:23
Can use a Diamond here?
ahaas
2016/08/17 16:12:57
Done.
| |
391 jsgraph()->common()->Branch(BranchHint::kTrue), check, *control_); | |
392 | |
393 Node* if_true = graph()->NewNode(jsgraph()->common()->IfTrue(), branch); | |
394 Node* effect_true = *effect_; | |
395 | |
396 Node* if_false = graph()->NewNode(jsgraph()->common()->IfFalse(), branch); | |
397 Node* effect_false; | |
398 | |
399 // Generate a call to the runtime if there is a stack overflow. | |
400 { | |
401 // Use the module context to call the runtime to throw an exception. | |
402 Runtime::FunctionId f = Runtime::kStackGuard; | |
403 const Runtime::Function* fun = Runtime::FunctionForId(f); | |
404 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
405 jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties, | |
406 CallDescriptor::kNoFlags); | |
407 // CEntryStubConstant nodes have to be created and cached in the main | |
408 // thread. At the moment this is only done for CEntryStubConstant(1). | |
409 Node* inputs[] = { | |
410 jsgraph()->CEntryStubConstant(fun->result_size), // C entry | |
411 jsgraph()->ExternalConstant( | |
412 ExternalReference(f, jsgraph()->isolate())), // ref | |
413 jsgraph()->Int32Constant(fun->nargs), // arity | |
414 HeapConstant(module_->instance->context), // context | |
415 *effect_, | |
416 if_false}; | |
417 | |
418 Node* node = | |
419 graph()->NewNode(jsgraph()->common()->Call(desc), | |
420 static_cast<int>(arraysize(inputs)), inputs); | |
421 effect_false = node; | |
422 } | |
423 | |
424 Node* merge = | |
425 graph()->NewNode(jsgraph()->common()->Merge(2), if_true, if_false); | |
426 Node* ephi = graph()->NewNode(jsgraph()->common()->EffectPhi(2), | |
427 effect_true, effect_false, merge); | |
428 | |
429 *control_ = merge; | |
430 *effect_ = ephi; | |
431 } | |
432 } | |
433 | |
377 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, | 434 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, |
378 wasm::WasmCodePosition position) { | 435 wasm::WasmCodePosition position) { |
379 const Operator* op; | 436 const Operator* op; |
380 MachineOperatorBuilder* m = jsgraph()->machine(); | 437 MachineOperatorBuilder* m = jsgraph()->machine(); |
381 switch (opcode) { | 438 switch (opcode) { |
382 case wasm::kExprI32Add: | 439 case wasm::kExprI32Add: |
383 op = m->Int32Add(); | 440 op = m->Int32Add(); |
384 break; | 441 break; |
385 case wasm::kExprI32Sub: | 442 case wasm::kExprI32Sub: |
386 op = m->Int32Sub(); | 443 op = m->Int32Sub(); |
(...skipping 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3227 function_->code_start_offset), | 3284 function_->code_start_offset), |
3228 compile_ms); | 3285 compile_ms); |
3229 } | 3286 } |
3230 | 3287 |
3231 return code; | 3288 return code; |
3232 } | 3289 } |
3233 | 3290 |
3234 } // namespace compiler | 3291 } // namespace compiler |
3235 } // namespace internal | 3292 } // namespace internal |
3236 } // namespace v8 | 3293 } // namespace v8 |
OLD | NEW |