v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
bytecode-liveness-map.h
Go to the documentation of this file.
1// Copyright 2016 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_COMPILER_BYTECODE_LIVENESS_MAP_H_
6#define V8_COMPILER_BYTECODE_LIVENESS_MAP_H_
7
8#include <string>
9
11#include "src/zone/zone.h"
12
13namespace v8 {
14namespace internal {
15
16class Zone;
17
18namespace compiler {
19
21 public:
22 class Iterator {
23 public:
24 int operator*() const {
25 // Subtract one to compensate for the accumulator at the start of the
26 // bit vector.
27 return *it_ - 1;
28 }
29
30 void operator++() { return ++it_; }
31
32 bool operator!=(const Iterator& other) const { return it_ != other.it_; }
33
34 private:
35 static constexpr struct StartTag {
36 } kStartTag = {};
37 static constexpr struct EndTag {
38 } kEndTag = {};
39 explicit Iterator(const BytecodeLivenessState& liveness, StartTag)
40 : it_(liveness.bit_vector_.begin()) {
41 // If we're not at the end, and the current value is the accumulator, skip
42 // over it.
43 if (it_ != liveness.bit_vector_.end() && *it_ == 0) {
44 ++it_;
45 }
46 }
47 explicit Iterator(const BytecodeLivenessState& liveness, EndTag)
48 : it_(liveness.bit_vector_.end()) {}
49
52 };
53
58
60 : bit_vector_(other.bit_vector_, zone) {}
61
62 bool RegisterIsLive(int index) const {
63 DCHECK_GE(index, 0);
64 DCHECK_LT(index, bit_vector_.length() - 1);
65 return bit_vector_.Contains(index + 1);
66 }
67
68 bool AccumulatorIsLive() const { return bit_vector_.Contains(0); }
69
70 bool Equals(const BytecodeLivenessState& other) const {
71 return bit_vector_.Equals(other.bit_vector_);
72 }
73
74 void MarkRegisterLive(int index) {
75 DCHECK_GE(index, 0);
76 DCHECK_LT(index, bit_vector_.length() - 1);
77 bit_vector_.Add(index + 1);
78 }
79
80 void MarkRegisterDead(int index) {
81 DCHECK_GE(index, 0);
82 DCHECK_LT(index, bit_vector_.length() - 1);
83 bit_vector_.Remove(index + 1);
84 }
85
87
89
91
92 void Union(const BytecodeLivenessState& other) {
93 bit_vector_.Union(other.bit_vector_);
94 }
95
97 return bit_vector_.UnionIsChanged(other.bit_vector_);
98 }
99
100 void CopyFrom(const BytecodeLivenessState& other) {
101 bit_vector_.CopyFrom(other.bit_vector_);
102 }
103
104 int register_count() const { return bit_vector_.length() - 1; }
105
106 // Number of live values, including the accumulator.
107 int live_value_count() const { return bit_vector_.Count(); }
108
109 Iterator begin() const { return Iterator(*this, Iterator::kStartTag); }
110
111 Iterator end() const { return Iterator(*this, Iterator::kEndTag); }
112
113 private:
115};
116
121
123 public:
124 BytecodeLivenessMap(int bytecode_size, Zone* zone)
125 : liveness_(zone->AllocateArray<BytecodeLiveness>(bytecode_size))
126#ifdef DEBUG
127 ,
128 size_(bytecode_size)
129#endif
130 {
131 }
132
134 DCHECK_GE(offset, 0);
136#ifdef DEBUG
137 // Null out the in/out liveness, so that later DCHECKs know whether these
138 // have been correctly initialised or not. That code does initialise them
139 // unconditionally though, so we can skip the nulling out in release.
140 liveness_[offset].in = nullptr;
141 liveness_[offset].out = nullptr;
142#endif
143 return liveness_[offset];
144 }
145
147 DCHECK_GE(offset, 0);
149 return liveness_[offset];
150 }
152 DCHECK_GE(offset, 0);
154 return liveness_[offset];
155 }
156
158 return GetLiveness(offset).in;
159 }
161 return GetLiveness(offset).in;
162 }
163
165 return GetLiveness(offset).out;
166 }
168 return GetLiveness(offset).out;
169 }
170
171 private:
173#ifdef DEBUG
174 size_t size_;
175#endif
176};
177
178V8_EXPORT_PRIVATE std::string ToString(const BytecodeLivenessState& liveness);
179
180} // namespace compiler
181} // namespace internal
182} // namespace v8
183
184#endif // V8_COMPILER_BYTECODE_LIVENESS_MAP_H_
friend Zone
Definition asm-types.cc:195
Iterator end() const
Definition bit-vector.h:261
bool UnionIsChanged(const BitVector &other)
Definition bit-vector.h:209
void CopyFrom(const BitVector &other)
Definition bit-vector.h:155
bool Contains(int i) const
Definition bit-vector.h:180
void Union(const BitVector &other)
Definition bit-vector.h:202
bool Equals(const BitVector &other) const
Definition bit-vector.h:251
const BytecodeLivenessState * GetInLiveness(int offset) const
BytecodeLivenessState * GetInLiveness(int offset)
const BytecodeLivenessState * GetOutLiveness(int offset) const
const BytecodeLiveness & GetLiveness(int offset) const
BytecodeLivenessMap(int bytecode_size, Zone *zone)
BytecodeLivenessState * GetOutLiveness(int offset)
Iterator(const BytecodeLivenessState &liveness, StartTag)
static constexpr struct v8::internal::compiler::BytecodeLivenessState::Iterator::EndTag kEndTag
Iterator(const BytecodeLivenessState &liveness, EndTag)
static constexpr struct v8::internal::compiler::BytecodeLivenessState::Iterator::StartTag kStartTag
void CopyFrom(const BytecodeLivenessState &other)
void Union(const BytecodeLivenessState &other)
BytecodeLivenessState(int register_count, Zone *zone)
BytecodeLivenessState & operator=(const BytecodeLivenessState &)=delete
bool Equals(const BytecodeLivenessState &other) const
bool UnionIsChanged(const BytecodeLivenessState &other)
BytecodeLivenessState(const BytecodeLivenessState &)=delete
BytecodeLivenessState(const BytecodeLivenessState &other, Zone *zone)
const int size_
Definition assembler.cc:132
int32_t offset
std::string ToString(const BytecodeLivenessState &liveness)
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define V8_EXPORT_PRIVATE
Definition macros.h:460