1// Copyright 2021 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_BRANCH_HINT_MAP_H_
6#define V8_WASM_BRANCH_HINT_MAP_H_
7
8#include <unordered_map>
9
10#include "src/base/macros.h"
11
12namespace v8 {
13namespace internal {
14
15namespace wasm {
16
17enum class WasmBranchHint : uint8_t {
18  kNoHint = 0,
19  kUnlikely = 1,
20  kLikely = 2,
21};
22
23class V8_EXPORT_PRIVATE BranchHintMap {
24 public:
25  void insert(uint32_t offset, WasmBranchHint hint) {
26    map_.emplace(offset, hint);
27  }
28  WasmBranchHint GetHintFor(uint32_t offset) const {
29    auto it = map_.find(offset);
30    if (it == map_.end()) {
31      return WasmBranchHint::kNoHint;
32    }
33    return it->second;
34  }
35
36 private:
37  std::unordered_map<uint32_t, WasmBranchHint> map_;
38};
39
40using BranchHintInfo = std::unordered_map<uint32_t, BranchHintMap>;
41
42}  // namespace wasm
43}  // namespace internal
44}  // namespace v8
45
46#endif  // V8_WASM_BRANCH_HINT_MAP_H_
47