Line data Source code
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 "src/base/hashmap.h"
9 : #include "src/bit-vector.h"
10 : #include "src/zone/zone.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : class Zone;
16 :
17 : namespace compiler {
18 :
19 : class BytecodeLivenessState : public ZoneObject {
20 : public:
21 : BytecodeLivenessState(int register_count, Zone* zone)
22 30407756 : : bit_vector_(register_count + 1, zone) {}
23 :
24 6667502 : const BitVector& bit_vector() const { return bit_vector_; }
25 :
26 : BitVector& bit_vector() { return bit_vector_; }
27 :
28 : bool RegisterIsLive(int index) const {
29 : DCHECK_GE(index, 0);
30 : DCHECK_LT(index, bit_vector_.length() - 1);
31 : return bit_vector_.Contains(index);
32 : }
33 :
34 : bool AccumulatorIsLive() const {
35 7811413 : return bit_vector_.Contains(bit_vector_.length() - 1);
36 : }
37 :
38 : bool Equals(const BytecodeLivenessState& other) const {
39 : return bit_vector_.Equals(other.bit_vector_);
40 : }
41 :
42 : void MarkRegisterLive(int index) {
43 : DCHECK_GE(index, 0);
44 : DCHECK_LT(index, bit_vector_.length() - 1);
45 : bit_vector_.Add(index);
46 : }
47 :
48 : void MarkRegisterDead(int index) {
49 : DCHECK_GE(index, 0);
50 : DCHECK_LT(index, bit_vector_.length() - 1);
51 : bit_vector_.Remove(index);
52 : }
53 :
54 8745977 : void MarkAccumulatorLive() { bit_vector_.Add(bit_vector_.length() - 1); }
55 :
56 18220022 : void MarkAccumulatorDead() { bit_vector_.Remove(bit_vector_.length() - 1); }
57 :
58 : void MarkAllLive() { bit_vector_.AddAll(); }
59 :
60 : void Union(const BytecodeLivenessState& other) {
61 : bit_vector_.Union(other.bit_vector_);
62 : }
63 :
64 : bool UnionIsChanged(const BytecodeLivenessState& other) {
65 63611 : return bit_vector_.UnionIsChanged(other.bit_vector_);
66 : }
67 :
68 : void CopyFrom(const BytecodeLivenessState& other) {
69 17147363 : bit_vector_.CopyFrom(other.bit_vector_);
70 : }
71 :
72 : private:
73 : BitVector bit_vector_;
74 :
75 : DISALLOW_COPY_AND_ASSIGN(BytecodeLivenessState);
76 : };
77 :
78 : struct BytecodeLiveness {
79 : BytecodeLivenessState* in;
80 : BytecodeLivenessState* out;
81 :
82 : BytecodeLiveness(int register_count, Zone* zone);
83 : };
84 :
85 530219 : class V8_EXPORT_PRIVATE BytecodeLivenessMap {
86 : public:
87 : BytecodeLivenessMap(int size, Zone* zone);
88 :
89 : BytecodeLiveness& InitializeLiveness(int offset, int register_count,
90 : Zone* zone);
91 :
92 : BytecodeLiveness& GetLiveness(int offset);
93 : const BytecodeLiveness& GetLiveness(int offset) const;
94 :
95 : BytecodeLivenessState* GetInLiveness(int offset) {
96 6473 : return GetLiveness(offset).in;
97 : }
98 : const BytecodeLivenessState* GetInLiveness(int offset) const {
99 6597290 : return GetLiveness(offset).in;
100 : }
101 :
102 : BytecodeLivenessState* GetOutLiveness(int offset) {
103 : return GetLiveness(offset).out;
104 : }
105 : const BytecodeLivenessState* GetOutLiveness(int offset) const {
106 3536278 : return GetLiveness(offset).out;
107 : }
108 :
109 : private:
110 : base::TemplateHashMapImpl<int, BytecodeLiveness,
111 : base::KeyEqualityMatcher<int>, ZoneAllocationPolicy>
112 : liveness_map_;
113 : };
114 :
115 : } // namespace compiler
116 : } // namespace internal
117 : } // namespace v8
118 :
119 : #endif // V8_COMPILER_BYTECODE_LIVENESS_MAP_H_
|