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 3393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3404 graph_zone(), MachineType::PointerRepresentation(), | 3404 graph_zone(), MachineType::PointerRepresentation(), |
3405 InstructionSelector::SupportedMachineOperatorFlags(), | 3405 InstructionSelector::SupportedMachineOperatorFlags(), |
3406 InstructionSelector::AlignmentRequirements()))), | 3406 InstructionSelector::AlignmentRequirements()))), |
3407 compilation_zone_(isolate->allocator(), ZONE_NAME), | 3407 compilation_zone_(isolate->allocator(), ZONE_NAME), |
3408 info_(function->name_length != 0 ? module_env->GetNameOrNull(function) | 3408 info_(function->name_length != 0 ? module_env->GetNameOrNull(function) |
3409 : ArrayVector("wasm"), | 3409 : ArrayVector("wasm"), |
3410 isolate, &compilation_zone_, | 3410 isolate, &compilation_zone_, |
3411 Code::ComputeFlags(Code::WASM_FUNCTION)), | 3411 Code::ComputeFlags(Code::WASM_FUNCTION)), |
3412 job_(), | 3412 job_(), |
3413 index_(index), | 3413 index_(index), |
3414 ok_(true) { | 3414 ok_(true), |
| 3415 protected_instructions_(&compilation_zone_) { |
3415 // Create and cache this node in the main thread. | 3416 // Create and cache this node in the main thread. |
3416 jsgraph_->CEntryStubConstant(1); | 3417 jsgraph_->CEntryStubConstant(1); |
3417 } | 3418 } |
3418 | 3419 |
3419 void WasmCompilationUnit::ExecuteCompilation() { | 3420 void WasmCompilationUnit::ExecuteCompilation() { |
3420 // TODO(ahaas): The counters are not thread-safe at the moment. | 3421 // TODO(ahaas): The counters are not thread-safe at the moment. |
3421 // HistogramTimerScope wasm_compile_function_time_scope( | 3422 // HistogramTimerScope wasm_compile_function_time_scope( |
3422 // isolate_->counters()->wasm_compile_function_time()); | 3423 // isolate_->counters()->wasm_compile_function_time()); |
3423 if (FLAG_trace_wasm_compiler) { | 3424 if (FLAG_trace_wasm_compiler) { |
3424 OFStream os(stdout); | 3425 OFStream os(stdout); |
(...skipping 20 matching lines...) Expand all Loading... |
3445 } | 3446 } |
3446 | 3447 |
3447 // Run the compiler pipeline to generate machine code. | 3448 // Run the compiler pipeline to generate machine code. |
3448 CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor( | 3449 CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor( |
3449 &compilation_zone_, function_->sig); | 3450 &compilation_zone_, function_->sig); |
3450 if (jsgraph_->machine()->Is32()) { | 3451 if (jsgraph_->machine()->Is32()) { |
3451 descriptor = | 3452 descriptor = |
3452 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); | 3453 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); |
3453 } | 3454 } |
3454 job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_, descriptor, | 3455 job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_, descriptor, |
3455 source_positions)); | 3456 source_positions, |
| 3457 &protected_instructions_)); |
3456 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; | 3458 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; |
3457 // TODO(bradnelson): Improve histogram handling of size_t. | 3459 // TODO(bradnelson): Improve histogram handling of size_t. |
3458 // TODO(ahaas): The counters are not thread-safe at the moment. | 3460 // TODO(ahaas): The counters are not thread-safe at the moment. |
3459 // isolate_->counters()->wasm_compile_function_peak_memory_bytes() | 3461 // isolate_->counters()->wasm_compile_function_peak_memory_bytes() |
3460 // ->AddSample( | 3462 // ->AddSample( |
3461 // static_cast<int>(jsgraph->graph()->zone()->allocation_size())); | 3463 // static_cast<int>(jsgraph->graph()->zone()->allocation_size())); |
3462 | 3464 |
3463 if (FLAG_trace_wasm_decode_time) { | 3465 if (FLAG_trace_wasm_decode_time) { |
3464 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); | 3466 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); |
3465 PrintF( | 3467 PrintF( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3503 } | 3505 } |
3504 | 3506 |
3505 if (FLAG_trace_wasm_decode_time) { | 3507 if (FLAG_trace_wasm_decode_time) { |
3506 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); | 3508 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); |
3507 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n", | 3509 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n", |
3508 static_cast<int>(function_->code_end_offset - | 3510 static_cast<int>(function_->code_end_offset - |
3509 function_->code_start_offset), | 3511 function_->code_start_offset), |
3510 compile_ms); | 3512 compile_ms); |
3511 } | 3513 } |
3512 | 3514 |
| 3515 Handle<FixedArray> protected_instructions = PackProtectedInstructions(); |
| 3516 code->set_protected_instructions(*protected_instructions); |
| 3517 |
3513 return code; | 3518 return code; |
3514 } | 3519 } |
3515 | 3520 |
| 3521 Handle<FixedArray> WasmCompilationUnit::PackProtectedInstructions() const { |
| 3522 const int num_instructions = static_cast<int>(protected_instructions_.size()); |
| 3523 Handle<FixedArray> fn_protected = isolate_->factory()->NewFixedArray( |
| 3524 num_instructions * Code::kTrapDataSize, TENURED); |
| 3525 for (unsigned i = 0; i < protected_instructions_.size(); ++i) { |
| 3526 const trap_handler::ProtectedInstructionData& instruction = |
| 3527 protected_instructions_[i]; |
| 3528 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapCodeOffset, |
| 3529 Smi::FromInt(instruction.instr_offset)); |
| 3530 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, |
| 3531 Smi::FromInt(instruction.landing_offset)); |
| 3532 } |
| 3533 return fn_protected; |
| 3534 } |
| 3535 |
3516 } // namespace compiler | 3536 } // namespace compiler |
3517 } // namespace internal | 3537 } // namespace internal |
3518 } // namespace v8 | 3538 } // namespace v8 |
OLD | NEW |