OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 14 matching lines...) Expand all Loading... | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_DATAFLOW_H_ | 28 #ifndef V8_DATAFLOW_H_ |
29 #define V8_DATAFLOW_H_ | 29 #define V8_DATAFLOW_H_ |
30 | 30 |
31 #include "v8.h" | 31 #include "v8.h" |
32 | 32 |
33 #include "ast.h" | 33 #include "ast.h" |
34 #include "compiler.h" | 34 #include "compiler.h" |
35 #include "zone-inl.h" | |
35 | 36 |
36 namespace v8 { | 37 namespace v8 { |
37 namespace internal { | 38 namespace internal { |
38 | 39 |
39 class BitVector BASE_EMBEDDED { | 40 class BitVector: public ZoneObject { |
40 public: | 41 public: |
41 explicit BitVector(int length) | 42 explicit BitVector(int length) |
42 : length_(length), bits_(Vector<uint32_t>::New(1 + length / 32)) { | 43 : length_(length), |
44 data_length_(SizeFor(length)), | |
45 data_(Zone::NewArray<uint32_t>(data_length_)) { | |
43 ASSERT(length > 0); | 46 ASSERT(length > 0); |
44 for (int i = 0; i < bits_.length(); i++) { | 47 Clear(); |
45 bits_[i] = 0; | |
46 } | |
47 } | 48 } |
48 | 49 |
49 BitVector(const BitVector& other) | 50 BitVector(const BitVector& other) |
50 : length_(other.length()), | 51 : length_(other.length()), |
51 bits_(Vector<uint32_t>::New(1 + other.length() / 32)) { | 52 data_length_(SizeFor(length_)), |
53 data_(Zone::NewArray<uint32_t>(data_length_)) { | |
52 CopyFrom(other); | 54 CopyFrom(other); |
53 } | 55 } |
54 | 56 |
55 ~BitVector() { bits_.Dispose(); } | 57 static int SizeFor(int length) { |
58 return 1 + ((length - 1) / 32); | |
59 } | |
56 | 60 |
57 BitVector& operator=(const BitVector& rhs) { | 61 BitVector& operator=(const BitVector& rhs) { |
58 if (this != &rhs) CopyFrom(rhs); | 62 if (this != &rhs) CopyFrom(rhs); |
59 return *this; | 63 return *this; |
60 } | 64 } |
61 | 65 |
62 void CopyFrom(const BitVector& other) { | 66 void CopyFrom(const BitVector& other) { |
63 ASSERT(other.length() == length()); | 67 ASSERT(other.length() == length()); |
64 for (int i = 0; i < bits_.length(); i++) { | 68 for (int i = 0; i < data_length_; i++) { |
65 bits_[i] = other.bits_[i]; | 69 data_[i] = other.data_[i]; |
66 } | 70 } |
67 } | 71 } |
68 | 72 |
69 bool Contains(int i) { | 73 bool Contains(int i) { |
fschneider
2010/03/09 16:52:30
Should Contains be const too?
| |
70 ASSERT(i >= 0 && i < length()); | 74 ASSERT(i >= 0 && i < length()); |
71 uint32_t block = bits_[i / 32]; | 75 uint32_t block = data_[i / 32]; |
72 return (block & (1U << (i % 32))) != 0; | 76 return (block & (1U << (i % 32))) != 0; |
73 } | 77 } |
74 | 78 |
75 void Add(int i) { | 79 void Add(int i) { |
76 ASSERT(i >= 0 && i < length()); | 80 ASSERT(i >= 0 && i < length()); |
77 bits_[i / 32] |= (1U << (i % 32)); | 81 data_[i / 32] |= (1U << (i % 32)); |
78 } | 82 } |
79 | 83 |
80 void Remove(int i) { | 84 void Remove(int i) { |
81 ASSERT(i >= 0 && i < length()); | 85 ASSERT(i >= 0 && i < length()); |
82 bits_[i / 32] &= ~(1U << (i % 32)); | 86 data_[i / 32] &= ~(1U << (i % 32)); |
83 } | 87 } |
84 | 88 |
85 void Union(const BitVector& other) { | 89 void Union(const BitVector& other) { |
86 ASSERT(other.length() == length()); | 90 ASSERT(other.length() == length()); |
87 for (int i = 0; i < bits_.length(); i++) { | 91 for (int i = 0; i < data_length_; i++) { |
88 bits_[i] |= other.bits_[i]; | 92 data_[i] |= other.data_[i]; |
89 } | 93 } |
90 } | 94 } |
91 | 95 |
92 void Intersect(const BitVector& other) { | 96 void Intersect(const BitVector& other) { |
93 ASSERT(other.length() == length()); | 97 ASSERT(other.length() == length()); |
94 for (int i = 0; i < bits_.length(); i++) { | 98 for (int i = 0; i < data_length_; i++) { |
95 bits_[i] &= other.bits_[i]; | 99 data_[i] &= other.data_[i]; |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
99 void Clear() { | 103 void Clear() { |
100 for (int i = 0; i < bits_.length(); i++) { | 104 for (int i = 0; i < data_length_; i++) { |
101 bits_[i] = 0; | 105 data_[i] = 0; |
102 } | 106 } |
103 } | 107 } |
104 | 108 |
105 bool IsEmpty() { | 109 bool IsEmpty() const { |
106 for (int i = 0; i < bits_.length(); i++) { | 110 for (int i = 0; i < data_length_; i++) { |
107 if (bits_[i] != 0) return false; | 111 if (data_[i] != 0) return false; |
108 } | 112 } |
109 return true; | 113 return true; |
110 } | 114 } |
111 | 115 |
112 int length() const { return length_; } | 116 int length() const { return length_; } |
113 | 117 |
114 private: | 118 private: |
115 int length_; | 119 int length_; |
116 Vector<uint32_t> bits_; | 120 int data_length_; |
121 uint32_t* data_; | |
117 }; | 122 }; |
118 | 123 |
119 | 124 |
120 // Forward declarations of Node types. | 125 // Forward declarations of Node types. |
121 class Node; | 126 class Node; |
122 class BranchNode; | 127 class BranchNode; |
123 class JoinNode; | 128 class JoinNode; |
124 | 129 |
125 // Flow graphs have a single entry and single exit. The empty flowgraph is | 130 // Flow graphs have a single entry and single exit. The empty flowgraph is |
126 // represented by both entry and exit being NULL. | 131 // represented by both entry and exit being NULL. |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 VarUseMap live_vars_; | 499 VarUseMap live_vars_; |
495 | 500 |
496 DISALLOW_COPY_AND_ASSIGN(LivenessAnalyzer); | 501 DISALLOW_COPY_AND_ASSIGN(LivenessAnalyzer); |
497 }; | 502 }; |
498 | 503 |
499 | 504 |
500 } } // namespace v8::internal | 505 } } // namespace v8::internal |
501 | 506 |
502 | 507 |
503 #endif // V8_DATAFLOW_H_ | 508 #endif // V8_DATAFLOW_H_ |
OLD | NEW |