Line data Source code
1 : // Copyright 2018 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_WASM_FUNCTION_COMPILER_H_
6 : #define V8_WASM_FUNCTION_COMPILER_H_
7 :
8 : #include "src/code-desc.h"
9 : #include "src/trap-handler/trap-handler.h"
10 : #include "src/wasm/compilation-environment.h"
11 : #include "src/wasm/function-body-decoder.h"
12 : #include "src/wasm/wasm-limits.h"
13 : #include "src/wasm/wasm-module.h"
14 : #include "src/wasm/wasm-tier.h"
15 :
16 : namespace v8 {
17 : namespace internal {
18 :
19 : class AssemblerBuffer;
20 : class Counters;
21 :
22 : namespace compiler {
23 : class InterpreterCompilationUnit;
24 : class Pipeline;
25 : class TurbofanWasmCompilationUnit;
26 : } // namespace compiler
27 :
28 : namespace wasm {
29 :
30 : class LiftoffCompilationUnit;
31 : class NativeModule;
32 : class WasmCode;
33 : class WasmCompilationUnit;
34 : class WasmEngine;
35 : struct WasmFunction;
36 :
37 : class WasmInstructionBuffer final {
38 : public:
39 : ~WasmInstructionBuffer();
40 : std::unique_ptr<AssemblerBuffer> CreateView();
41 : std::unique_ptr<uint8_t[]> ReleaseBuffer();
42 :
43 : static std::unique_ptr<WasmInstructionBuffer> New();
44 :
45 : private:
46 : WasmInstructionBuffer() = delete;
47 : DISALLOW_COPY_AND_ASSIGN(WasmInstructionBuffer);
48 : };
49 :
50 12915087 : struct WasmCompilationResult {
51 : public:
52 8802025 : MOVE_ONLY_WITH_DEFAULT_CONSTRUCTORS(WasmCompilationResult);
53 :
54 : bool succeeded() const { return code_desc.buffer != nullptr; }
55 : operator bool() const { return succeeded(); }
56 :
57 : CodeDesc code_desc;
58 : std::unique_ptr<uint8_t[]> instr_buffer;
59 : uint32_t frame_slot_count = 0;
60 : uint32_t tagged_parameter_slots = 0;
61 : OwnedVector<byte> source_positions;
62 : OwnedVector<trap_handler::ProtectedInstructionData> protected_instructions;
63 : int func_index;
64 : ExecutionTier requested_tier;
65 : ExecutionTier result_tier;
66 : };
67 :
68 3233003 : class WasmCompilationUnit final {
69 : public:
70 : static ExecutionTier GetDefaultExecutionTier(const WasmModule*);
71 :
72 : WasmCompilationUnit(WasmEngine*, int index, ExecutionTier);
73 :
74 : ~WasmCompilationUnit();
75 :
76 : WasmCompilationResult ExecuteCompilation(
77 : CompilationEnv*, const std::shared_ptr<WireBytesStorage>&, Counters*,
78 : WasmFeatures* detected);
79 :
80 : ExecutionTier tier() const { return tier_; }
81 :
82 : static void CompileWasmFunction(Isolate*, NativeModule*,
83 : WasmFeatures* detected, const WasmFunction*,
84 : ExecutionTier);
85 :
86 : private:
87 : friend class LiftoffCompilationUnit;
88 : friend class compiler::TurbofanWasmCompilationUnit;
89 : friend class compiler::InterpreterCompilationUnit;
90 :
91 : WasmEngine* const wasm_engine_;
92 : const int func_index_;
93 : ExecutionTier tier_;
94 :
95 : // LiftoffCompilationUnit, set if {tier_ == kLiftoff}.
96 : std::unique_ptr<LiftoffCompilationUnit> liftoff_unit_;
97 : // TurbofanWasmCompilationUnit, set if {tier_ == kTurbofan}.
98 : std::unique_ptr<compiler::TurbofanWasmCompilationUnit> turbofan_unit_;
99 : // InterpreterCompilationUnit, set if {tier_ == kInterpreter}.
100 : std::unique_ptr<compiler::InterpreterCompilationUnit> interpreter_unit_;
101 :
102 : void SwitchTier(ExecutionTier new_tier);
103 :
104 : DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit);
105 : };
106 :
107 : } // namespace wasm
108 : } // namespace internal
109 : } // namespace v8
110 :
111 : #endif // V8_WASM_FUNCTION_COMPILER_H_
|