11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_WASM_BRANCH_HINT_MAP_H_
61cb0ef41Sopenharmony_ci#define V8_WASM_BRANCH_HINT_MAP_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <unordered_map>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "src/base/macros.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cinamespace wasm {
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cienum class WasmBranchHint : uint8_t {
181cb0ef41Sopenharmony_ci  kNoHint = 0,
191cb0ef41Sopenharmony_ci  kUnlikely = 1,
201cb0ef41Sopenharmony_ci  kLikely = 2,
211cb0ef41Sopenharmony_ci};
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE BranchHintMap {
241cb0ef41Sopenharmony_ci public:
251cb0ef41Sopenharmony_ci  void insert(uint32_t offset, WasmBranchHint hint) {
261cb0ef41Sopenharmony_ci    map_.emplace(offset, hint);
271cb0ef41Sopenharmony_ci  }
281cb0ef41Sopenharmony_ci  WasmBranchHint GetHintFor(uint32_t offset) const {
291cb0ef41Sopenharmony_ci    auto it = map_.find(offset);
301cb0ef41Sopenharmony_ci    if (it == map_.end()) {
311cb0ef41Sopenharmony_ci      return WasmBranchHint::kNoHint;
321cb0ef41Sopenharmony_ci    }
331cb0ef41Sopenharmony_ci    return it->second;
341cb0ef41Sopenharmony_ci  }
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci private:
371cb0ef41Sopenharmony_ci  std::unordered_map<uint32_t, WasmBranchHint> map_;
381cb0ef41Sopenharmony_ci};
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ciusing BranchHintInfo = std::unordered_map<uint32_t, BranchHintMap>;
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci}  // namespace wasm
431cb0ef41Sopenharmony_ci}  // namespace internal
441cb0ef41Sopenharmony_ci}  // namespace v8
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci#endif  // V8_WASM_BRANCH_HINT_MAP_H_
47