• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BASELINE_LIFTOFF_COMPILER_H_
6 #define V8_WASM_BASELINE_LIFTOFF_COMPILER_H_
7 
8 #include "src/wasm/function-compiler.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 class AccountingAllocator;
14 class Counters;
15 
16 namespace wasm {
17 
18 struct CompilationEnv;
19 class DebugSideTable;
20 struct FunctionBody;
21 class WasmFeatures;
22 
23 // Note: If this list changes, also the histogram "V8.LiftoffBailoutReasons"
24 // on the chromium side needs to be updated.
25 // Deprecating entries is always fine. Repurposing works if you don't care about
26 // temporary mix-ups. Increasing the number of reasons {kNumBailoutReasons} is
27 // more tricky, and might require introducing a new (updated) histogram.
28 enum LiftoffBailoutReason : int8_t {
29   // Nothing actually failed.
30   kSuccess = 0,
31   // Compilation failed, but not because of Liftoff.
32   kDecodeError = 1,
33   // Liftoff is not implemented on that architecture.
34   kUnsupportedArchitecture = 2,
35   // More complex code would be needed because a CPU feature is not present.
36   kMissingCPUFeature = 3,
37   // Liftoff does not implement a complex (and rare) instruction.
38   kComplexOperation = 4,
39   // Unimplemented proposals:
40   kSimd = 5,
41   kRefTypes = 6,
42   kExceptionHandling = 7,
43   kMultiValue = 8,
44   kTailCall = 9,
45   kAtomics = 10,
46   kBulkMemory = 11,
47   kNonTrappingFloatToInt = 12,
48   kGC = 13,
49   // A little gap, for forward compatibility.
50   // Any other reason (use rarely; introduce new reasons if this spikes).
51   kOtherReason = 20,
52   // Marker:
53   kNumBailoutReasons
54 };
55 
56 struct LiftoffOptions {
57   Counters* counters = nullptr;
58   WasmFeatures* detected_features = nullptr;
59   base::Vector<const int> breakpoints = {};
60   std::unique_ptr<DebugSideTable>* debug_sidetable = nullptr;
61   int dead_breakpoint = 0;
62   int32_t* max_steps = nullptr;
63   int32_t* nondeterminism = nullptr;
64 
65   // We keep the macro as small as possible by offloading the actual DCHECK and
66   // assignment to another function. This makes debugging easier.
67 #define SETTER(field)                               \
68   template <typename T>                             \
69   LiftoffOptions& set_##field(T new_value) {        \
70     return Set<decltype(field)>(&field, new_value); \
71   }
72 
73   SETTER(counters)
SETTERLiftoffOptions74   SETTER(detected_features)
75   SETTER(breakpoints)
76   SETTER(debug_sidetable)
77   SETTER(dead_breakpoint)
78   SETTER(max_steps)
79   SETTER(nondeterminism)
80 
81 #undef SETTER
82 
83  private:
84   template <typename T>
85   LiftoffOptions& Set(T* ptr, T new_value) {
86     // The field must still have its default value.
87     DCHECK_EQ(*ptr, T{});
88     *ptr = new_value;
89     return *this;
90   }
91 };
92 
93 V8_EXPORT_PRIVATE WasmCompilationResult
94 ExecuteLiftoffCompilation(CompilationEnv*, const FunctionBody&, int func_index,
95                           ForDebugging, const LiftoffOptions& = {});
96 
97 V8_EXPORT_PRIVATE std::unique_ptr<DebugSideTable> GenerateLiftoffDebugSideTable(
98     const WasmCode*);
99 
100 }  // namespace wasm
101 }  // namespace internal
102 }  // namespace v8
103 
104 #endif  // V8_WASM_BASELINE_LIFTOFF_COMPILER_H_
105