V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
function-compiler.h
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/wasm/compilation-environment.h"
9 #include "src/wasm/function-body-decoder.h"
10 #include "src/wasm/wasm-limits.h"
11 #include "src/wasm/wasm-module.h"
12 #include "src/wasm/wasm-tier.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 class Counters;
18 
19 namespace compiler {
20 class TurbofanWasmCompilationUnit;
21 } // namespace compiler
22 
23 namespace wasm {
24 
25 class LiftoffCompilationUnit;
26 class NativeModule;
27 class WasmCode;
28 class WasmEngine;
29 struct WasmFunction;
30 
31 class WasmCompilationUnit final {
32  public:
33  static ExecutionTier GetDefaultExecutionTier();
34 
35  // If constructing from a background thread, pass in a Counters*, and ensure
36  // that the Counters live at least as long as this compilation unit (which
37  // typically means to hold a std::shared_ptr<Counters>).
38  // If used exclusively from a foreground thread, Isolate::counters() may be
39  // used by callers to pass Counters.
41  ExecutionTier = GetDefaultExecutionTier());
42 
44 
45  void ExecuteCompilation(CompilationEnv*, std::shared_ptr<WireBytesStorage>,
46  Counters*, WasmFeatures* detected);
47 
48  NativeModule* native_module() const { return native_module_; }
49  ExecutionTier tier() const { return tier_; }
50  bool failed() const { return result_ == nullptr; } // TODO(clemensh): Remove.
51  WasmCode* result() const { return result_; }
52 
53  static bool CompileWasmFunction(Isolate* isolate, NativeModule* native_module,
54  WasmFeatures* detected,
55  const WasmFunction* function,
56  ExecutionTier = GetDefaultExecutionTier());
57 
58  private:
59  friend class LiftoffCompilationUnit;
61 
62  WasmEngine* const wasm_engine_;
63  const int func_index_;
64  NativeModule* const native_module_;
65  ExecutionTier tier_;
66  WasmCode* result_ = nullptr;
67 
68  // LiftoffCompilationUnit, set if {tier_ == kLiftoff}.
69  std::unique_ptr<LiftoffCompilationUnit> liftoff_unit_;
70  // TurbofanWasmCompilationUnit, set if {tier_ == kTurbofan}.
71  std::unique_ptr<compiler::TurbofanWasmCompilationUnit> turbofan_unit_;
72 
73  void SwitchTier(ExecutionTier new_tier);
74 
75  // Called from {ExecuteCompilation} to set the result of compilation.
76  void SetResult(WasmCode*, Counters*);
77 
78  DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit);
79 };
80 
81 } // namespace wasm
82 } // namespace internal
83 } // namespace v8
84 
85 #endif // V8_WASM_FUNCTION_COMPILER_H_
Definition: libplatform.h:13