summaryrefslogtreecommitdiff
path: root/chromium/v8/src/codegen/safepoint-table-base.h
blob: 59eeb8e59ff19c8f0a93b6c3bc5d53d79d38c325 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_CODEGEN_SAFEPOINT_TABLE_BASE_H_
#define V8_CODEGEN_SAFEPOINT_TABLE_BASE_H_

#include <cstdint>

#include "src/base/logging.h"

namespace v8 {
namespace internal {

class SafepointEntryBase {
 public:
  static constexpr int kNoDeoptIndex = -1;
  static constexpr int kNoTrampolinePC = -1;

  SafepointEntryBase() = default;

  SafepointEntryBase(int pc, int deopt_index, int trampoline_pc)
      : pc_(pc), deopt_index_(deopt_index), trampoline_pc_(trampoline_pc) {
    DCHECK(is_initialized());
  }

  bool is_initialized() const { return pc_ != 0; }

  int pc() const {
    DCHECK(is_initialized());
    return pc_;
  }

  int trampoline_pc() const { return trampoline_pc_; }

  bool has_deoptimization_index() const {
    return deopt_index_ != kNoDeoptIndex;
  }

  int deoptimization_index() const {
    DCHECK(has_deoptimization_index());
    return deopt_index_;
  }

  void Reset() { pc_ = 0; }

 protected:
  bool operator==(const SafepointEntryBase& other) const {
    return pc_ == other.pc_ && deopt_index_ == other.deopt_index_ &&
           trampoline_pc_ == other.trampoline_pc_;
  }

 private:
  int pc_ = 0;
  int deopt_index_ = kNoDeoptIndex;
  int trampoline_pc_ = kNoTrampolinePC;
};

class SafepointTableBuilderBase {
 public:
  bool emitted() const {
    return safepoint_table_offset_ != kNoSafepointTableOffset;
  }

  int safepoint_table_offset() const {
    DCHECK(emitted());
    return safepoint_table_offset_;
  }

 protected:
  void set_safepoint_table_offset(int offset) {
    DCHECK(!emitted());
    safepoint_table_offset_ = offset;
    DCHECK(emitted());
  }

 private:
  static constexpr int kNoSafepointTableOffset = -1;
  int safepoint_table_offset_ = kNoSafepointTableOffset;
};

}  // namespace internal
}  // namespace v8

#endif  // V8_CODEGEN_SAFEPOINT_TABLE_BASE_H_