Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: src/number-info.h

Issue 1249002: Add primitive type and string type to the number info.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/frame-element.h ('k') | src/register-allocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
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_NUMBER_INFO_H_ 28 #ifndef V8_NUMBER_INFO_H_
29 #define V8_NUMBER_INFO_H_ 29 #define V8_NUMBER_INFO_H_
30 30
31 namespace v8 { 31 namespace v8 {
32 namespace internal { 32 namespace internal {
33 33
34 // Unknown 34 // Unknown
35 // | 35 // |
36 // Number 36 // PrimitiveType
37 // / | 37 // | \--------|
38 // HeapNumber Integer32 38 // Number String
39 // | | 39 // / | |
40 // | Smi 40 // HeapNumber Integer32 |
41 // | / 41 // | | /
42 // Uninitialized. 42 // | Smi /
43 // | / /
44 // Uninitialized.
43 45
44 class NumberInfo { 46 class NumberInfo {
45 public: 47 public:
46 NumberInfo() { } 48 NumberInfo() { }
47 49
48 static inline NumberInfo Unknown(); 50 static inline NumberInfo Unknown();
51 // We know it's a primitive type.
52 static inline NumberInfo Primitive();
49 // We know it's a number of some sort. 53 // We know it's a number of some sort.
50 static inline NumberInfo Number(); 54 static inline NumberInfo Number();
51 // We know it's signed or unsigned 32 bit integer. 55 // We know it's signed or unsigned 32 bit integer.
52 static inline NumberInfo Integer32(); 56 static inline NumberInfo Integer32();
53 // We know it's a Smi. 57 // We know it's a Smi.
54 static inline NumberInfo Smi(); 58 static inline NumberInfo Smi();
55 // We know it's a heap number. 59 // We know it's a heap number.
56 static inline NumberInfo HeapNumber(); 60 static inline NumberInfo HeapNumber();
61 // We know it's a string.
62 static inline NumberInfo String();
57 // We haven't started collecting info yet. 63 // We haven't started collecting info yet.
58 static inline NumberInfo Uninitialized(); 64 static inline NumberInfo Uninitialized();
59 65
60 // Return compact representation. Very sensitive to enum values below! 66 // Return compact representation. Very sensitive to enum values below!
67 // Compacting drops information about primtive types and strings types.
68 // We use the compact representation when we only care about number types.
61 int ThreeBitRepresentation() { 69 int ThreeBitRepresentation() {
62 ASSERT(type_ != kUninitializedType); 70 ASSERT(type_ != kUninitializedType);
63 int answer = type_ > 6 ? type_ -2 : type_; 71 int answer = type_ & 0xf;
72 answer = answer > 6 ? answer - 2 : answer;
64 ASSERT(answer >= 0); 73 ASSERT(answer >= 0);
65 ASSERT(answer <= 7); 74 ASSERT(answer <= 7);
66 return answer; 75 return answer;
67 } 76 }
68 77
69 // Decode compact representation. Very sensitive to enum values below! 78 // Decode compact representation. Very sensitive to enum values below!
70 static NumberInfo ExpandedRepresentation(int three_bit_representation) { 79 static NumberInfo ExpandedRepresentation(int three_bit_representation) {
71 Type t = static_cast<Type>(three_bit_representation >= 6 ? 80 Type t = static_cast<Type>(three_bit_representation >= 6 ?
72 three_bit_representation + 2 : 81 three_bit_representation + 2 :
73 three_bit_representation); 82 three_bit_representation);
83 t = (t == kUnknownType) ? t : static_cast<Type>(t | kPrimitiveType);
74 ASSERT(t == kUnknownType || 84 ASSERT(t == kUnknownType ||
75 t == kNumberType || 85 t == kNumberType ||
76 t == kInteger32Type || 86 t == kInteger32Type ||
77 t == kSmiType || 87 t == kSmiType ||
78 t == kHeapNumberType); 88 t == kHeapNumberType);
79 return NumberInfo(t); 89 return NumberInfo(t);
80 } 90 }
81 91
82 int ToInt() { 92 int ToInt() {
83 return type_; 93 return type_;
84 } 94 }
85 95
86 static NumberInfo FromInt(int bit_representation) { 96 static NumberInfo FromInt(int bit_representation) {
87 Type t = static_cast<Type>(bit_representation); 97 Type t = static_cast<Type>(bit_representation);
88 ASSERT(t == kUnknownType || 98 ASSERT(t == kUnknownType ||
99 t == kPrimitiveType ||
89 t == kNumberType || 100 t == kNumberType ||
90 t == kInteger32Type || 101 t == kInteger32Type ||
91 t == kSmiType || 102 t == kSmiType ||
92 t == kHeapNumberType); 103 t == kHeapNumberType ||
104 t == kStringType);
93 return NumberInfo(t); 105 return NumberInfo(t);
94 } 106 }
95 107
96 // Return the weakest (least precise) common type. 108 // Return the weakest (least precise) common type.
97 static NumberInfo Combine(NumberInfo a, NumberInfo b) { 109 static NumberInfo Combine(NumberInfo a, NumberInfo b) {
98 return NumberInfo(static_cast<Type>(a.type_ & b.type_)); 110 return NumberInfo(static_cast<Type>(a.type_ & b.type_));
99 } 111 }
100 112
101 inline bool IsUnknown() { 113 inline bool IsUnknown() {
102 return type_ == kUnknownType; 114 return type_ == kUnknownType;
(...skipping 19 matching lines...) Expand all
122 return ((type_ & kHeapNumberType) == kHeapNumberType); 134 return ((type_ & kHeapNumberType) == kHeapNumberType);
123 } 135 }
124 136
125 inline bool IsUninitialized() { 137 inline bool IsUninitialized() {
126 return type_ == kUninitializedType; 138 return type_ == kUninitializedType;
127 } 139 }
128 140
129 const char* ToString() { 141 const char* ToString() {
130 switch (type_) { 142 switch (type_) {
131 case kUnknownType: return "UnknownType"; 143 case kUnknownType: return "UnknownType";
144 case kPrimitiveType: return "PrimitiveType";
132 case kNumberType: return "NumberType"; 145 case kNumberType: return "NumberType";
146 case kInteger32Type: return "Integer32Type";
133 case kSmiType: return "SmiType"; 147 case kSmiType: return "SmiType";
134 case kHeapNumberType: return "HeapNumberType"; 148 case kHeapNumberType: return "HeapNumberType";
135 case kInteger32Type: return "Integer32Type"; 149 case kStringType: return "StringType";
136 case kUninitializedType: 150 case kUninitializedType:
137 UNREACHABLE(); 151 UNREACHABLE();
138 return "UninitializedType"; 152 return "UninitializedType";
139 } 153 }
140 UNREACHABLE(); 154 UNREACHABLE();
141 return "Unreachable code"; 155 return "Unreachable code";
142 } 156 }
143 157
144 private: 158 private:
159 // We use 6 bits to represent the types.
145 enum Type { 160 enum Type {
146 kUnknownType = 0, 161 kUnknownType = 0, // 000000
147 kNumberType = 1, 162 kPrimitiveType = 0x10, // 010000
148 kInteger32Type = 3, 163 kNumberType = 0x11, // 010001
149 kSmiType = 7, 164 kInteger32Type = 0x13, // 010011
150 kHeapNumberType = 9, 165 kSmiType = 0x17, // 010111
151 kUninitializedType = 15 166 kHeapNumberType = 0x19, // 011001
167 kStringType = 0x30, // 110000
168 kUninitializedType = 0x3f // 111111
152 }; 169 };
153 explicit inline NumberInfo(Type t) : type_(t) { } 170 explicit inline NumberInfo(Type t) : type_(t) { }
154 171
155 Type type_; 172 Type type_;
156 }; 173 };
157 174
158 175
159 NumberInfo NumberInfo::Unknown() { 176 NumberInfo NumberInfo::Unknown() {
160 return NumberInfo(kUnknownType); 177 return NumberInfo(kUnknownType);
161 } 178 }
162 179
163 180
181 NumberInfo NumberInfo::Primitive() {
182 return NumberInfo(kPrimitiveType);
183 }
184
185
164 NumberInfo NumberInfo::Number() { 186 NumberInfo NumberInfo::Number() {
165 return NumberInfo(kNumberType); 187 return NumberInfo(kNumberType);
166 } 188 }
167 189
168 190
169 NumberInfo NumberInfo::Integer32() { 191 NumberInfo NumberInfo::Integer32() {
170 return NumberInfo(kInteger32Type); 192 return NumberInfo(kInteger32Type);
171 } 193 }
172 194
173 195
174 NumberInfo NumberInfo::Smi() { 196 NumberInfo NumberInfo::Smi() {
175 return NumberInfo(kSmiType); 197 return NumberInfo(kSmiType);
176 } 198 }
177 199
178 200
179 NumberInfo NumberInfo::HeapNumber() { 201 NumberInfo NumberInfo::HeapNumber() {
180 return NumberInfo(kHeapNumberType); 202 return NumberInfo(kHeapNumberType);
181 } 203 }
182 204
183 205
206 NumberInfo NumberInfo::String() {
207 return NumberInfo(kStringType);
208 }
209
210
184 NumberInfo NumberInfo::Uninitialized() { 211 NumberInfo NumberInfo::Uninitialized() {
185 return NumberInfo(kUninitializedType); 212 return NumberInfo(kUninitializedType);
186 } 213 }
187 214
188 } } // namespace v8::internal 215 } } // namespace v8::internal
189 216
190 #endif // V8_NUMBER_INFO_H_ 217 #endif // V8_NUMBER_INFO_H_
OLDNEW
« no previous file with comments | « src/frame-element.h ('k') | src/register-allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698