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

Side by Side Diff: src/types-inl.h

Issue 251753005: Establish distributivity for type union & intersection (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Eps Created 6 years, 7 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_TYPES_INL_H_ 5 #ifndef V8_TYPES_INL_H_
6 #define V8_TYPES_INL_H_ 6 #define V8_TYPES_INL_H_
7 7
8 #include "types.h" 8 #include "types.h"
9 9
10 #include "factory.h" 10 #include "factory.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 64
65 // static 65 // static
66 bool ZoneTypeConfig::is_struct(Type* type, int tag) { 66 bool ZoneTypeConfig::is_struct(Type* type, int tag) {
67 return !is_bitset(type) && struct_tag(as_struct(type)) == tag; 67 return !is_bitset(type) && struct_tag(as_struct(type)) == tag;
68 } 68 }
69 69
70 70
71 // static 71 // static
72 bool ZoneTypeConfig::is_class(Type* type) { 72 bool ZoneTypeConfig::is_class(Type* type) {
73 return is_struct(type, Type::StructuralType::kClassTag); 73 return false;
74 } 74 }
75 75
76 76
77 // static
78 bool ZoneTypeConfig::is_constant(Type* type) {
79 return is_struct(type, Type::StructuralType::kConstantTag);
80 }
81
82
83 // static 77 // static
84 int ZoneTypeConfig::as_bitset(Type* type) { 78 int ZoneTypeConfig::as_bitset(Type* type) {
85 ASSERT(is_bitset(type)); 79 ASSERT(is_bitset(type));
86 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); 80 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1);
87 } 81 }
88 82
89 83
90 // static 84 // static
91 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { 85 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) {
92 ASSERT(!is_bitset(type)); 86 ASSERT(!is_bitset(type));
93 return reinterpret_cast<Struct*>(type); 87 return reinterpret_cast<Struct*>(type);
94 } 88 }
95 89
96 90
97 // static 91 // static
98 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { 92 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
99 ASSERT(is_class(type)); 93 UNREACHABLE();
100 return i::Handle<i::Map>(static_cast<i::Map**>(as_struct(type)[3])); 94 return i::Handle<i::Map>();
101 } 95 }
102 96
103 97
104 // static
105 i::Handle<i::Object> ZoneTypeConfig::as_constant(Type* type) {
106 ASSERT(is_constant(type));
107 return i::Handle<i::Object>(
108 static_cast<i::Object**>(as_struct(type)[3]));
109 }
110
111
112 // static 98 // static
113 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) { 99 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) {
114 return reinterpret_cast<Type*>((bitset << 1) | 1); 100 return reinterpret_cast<Type*>((bitset << 1) | 1);
115 } 101 }
116 102
117 103
118 // static 104 // static
119 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) { 105 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) {
120 return from_bitset(bitset); 106 return from_bitset(bitset);
121 } 107 }
122 108
123 109
124 // static 110 // static
125 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) { 111 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structure) {
126 return reinterpret_cast<Type*>(structured); 112 return reinterpret_cast<Type*>(structure);
127 } 113 }
128 114
129 115
130 // static 116 // static
131 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( 117 ZoneTypeConfig::Type* ZoneTypeConfig::from_class(
132 i::Handle<i::Map> map, int lub, Zone* zone) { 118 i::Handle<i::Map> map, Zone* zone) {
133 Struct* structured = struct_create(Type::StructuralType::kClassTag, 2, zone); 119 return from_bitset(0);
134 structured[2] = from_bitset(lub);
135 structured[3] = map.location();
136 return from_struct(structured);
137 }
138
139
140 // static
141 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant(
142 i::Handle<i::Object> value, int lub, Zone* zone) {
143 Struct* structured =
144 struct_create(Type::StructuralType::kConstantTag, 2, zone);
145 structured[2] = from_bitset(lub);
146 structured[3] = value.location();
147 return from_struct(structured);
148 } 120 }
149 121
150 122
151 // static 123 // static
152 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create( 124 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create(
153 int tag, int length, Zone* zone) { 125 int tag, int length, Zone* zone) {
154 Struct* structured = reinterpret_cast<Struct*>( 126 Struct* structure = reinterpret_cast<Struct*>(
155 zone->New(sizeof(void*) * (length + 2))); // NOLINT 127 zone->New(sizeof(void*) * (length + 2))); // NOLINT
156 structured[0] = reinterpret_cast<void*>(tag); 128 structure[0] = reinterpret_cast<void*>(tag);
157 structured[1] = reinterpret_cast<void*>(length); 129 structure[1] = reinterpret_cast<void*>(length);
158 return structured; 130 return structure;
159 } 131 }
160 132
161 133
162 // static 134 // static
163 void ZoneTypeConfig::struct_shrink(Struct* structured, int length) { 135 void ZoneTypeConfig::struct_shrink(Struct* structure, int length) {
164 ASSERT(0 <= length && length <= struct_length(structured)); 136 ASSERT(0 <= length && length <= struct_length(structure));
165 structured[1] = reinterpret_cast<void*>(length); 137 structure[1] = reinterpret_cast<void*>(length);
166 } 138 }
167 139
168 140
169 // static 141 // static
170 int ZoneTypeConfig::struct_tag(Struct* structured) { 142 int ZoneTypeConfig::struct_tag(Struct* structure) {
171 return static_cast<int>(reinterpret_cast<intptr_t>(structured[0])); 143 return static_cast<int>(reinterpret_cast<intptr_t>(structure[0]));
172 } 144 }
173 145
174 146
175 // static 147 // static
176 int ZoneTypeConfig::struct_length(Struct* structured) { 148 int ZoneTypeConfig::struct_length(Struct* structure) {
177 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1])); 149 return static_cast<int>(reinterpret_cast<intptr_t>(structure[1]));
178 } 150 }
179 151
180 152
181 // static 153 // static
182 Type* ZoneTypeConfig::struct_get(Struct* structured, int i) { 154 Type* ZoneTypeConfig::struct_get(Struct* structure, int i) {
183 ASSERT(0 <= i && i <= struct_length(structured)); 155 ASSERT(0 <= i && i <= struct_length(structure));
184 return static_cast<Type*>(structured[2 + i]); 156 return static_cast<Type*>(structure[2 + i]);
185 } 157 }
186 158
187 159
188 // static 160 // static
189 void ZoneTypeConfig::struct_set(Struct* structured, int i, Type* type) { 161 void ZoneTypeConfig::struct_set(Struct* structure, int i, Type* x) {
190 ASSERT(0 <= i && i <= struct_length(structured)); 162 ASSERT(0 <= i && i <= struct_length(structure));
191 structured[2 + i] = type; 163 structure[2 + i] = x;
192 } 164 }
193 165
194 166
195 // static 167 // static
196 int ZoneTypeConfig::lub_bitset(Type* type) { 168 template<class O>
197 ASSERT(is_class(type) || is_constant(type)); 169 i::Handle<O> ZoneTypeConfig::struct_get_heap(Struct* structure, int i) {
198 return as_bitset(struct_get(as_struct(type), 0)); 170 ASSERT(0 <= i && i <= struct_length(structure));
171 return i::Handle<O>(static_cast<O**>(structure[2 + i]));
199 } 172 }
200 173
201 174
175 // static
176 template<class O>
177 void ZoneTypeConfig::struct_set_heap(Struct* structure, int i, i::Handle<O> x) {
178 ASSERT(0 <= i && i <= struct_length(structure));
179 structure[2 + i] = x.location();
180 }
181
182
202 // -------------------------------------------------------------------------- // 183 // -------------------------------------------------------------------------- //
203 // HeapTypeConfig 184 // HeapTypeConfig
204 185
205 // static 186 // static
206 template<class T> 187 template<class T>
207 i::Handle<T> HeapTypeConfig::handle(T* type) { 188 i::Handle<T> HeapTypeConfig::handle(T* type) {
208 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); 189 return i::handle(type, i::HeapObject::cast(type)->GetIsolate());
209 } 190 }
210 191
211 192
(...skipping 10 matching lines...) Expand all
222 } 203 }
223 204
224 205
225 // static 206 // static
226 bool HeapTypeConfig::is_class(Type* type) { 207 bool HeapTypeConfig::is_class(Type* type) {
227 return type->IsMap(); 208 return type->IsMap();
228 } 209 }
229 210
230 211
231 // static 212 // static
232 bool HeapTypeConfig::is_constant(Type* type) {
233 return type->IsBox();
234 }
235
236
237 // static
238 bool HeapTypeConfig::is_struct(Type* type, int tag) { 213 bool HeapTypeConfig::is_struct(Type* type, int tag) {
239 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag; 214 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag;
240 } 215 }
241 216
242 217
243 // static 218 // static
244 int HeapTypeConfig::as_bitset(Type* type) { 219 int HeapTypeConfig::as_bitset(Type* type) {
245 return i::Smi::cast(type)->value(); 220 return i::Smi::cast(type)->value();
246 } 221 }
247 222
248 223
249 // static 224 // static
250 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { 225 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) {
251 return i::handle(i::Map::cast(type)); 226 return i::handle(i::Map::cast(type));
252 } 227 }
253 228
254 229
255 // static 230 // static
256 i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) {
257 i::Box* box = i::Box::cast(type);
258 return i::handle(box->value(), box->GetIsolate());
259 }
260
261
262 // static
263 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) { 231 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
264 return i::handle(Struct::cast(type)); 232 return i::handle(Struct::cast(type));
265 } 233 }
266 234
267 235
268 // static 236 // static
269 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { 237 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) {
270 return Type::cast(i::Smi::FromInt(bitset)); 238 return Type::cast(i::Smi::FromInt(bitset));
271 } 239 }
272 240
273 241
274 // static 242 // static
275 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset( 243 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset(
276 int bitset, Isolate* isolate) { 244 int bitset, Isolate* isolate) {
277 return i::handle(from_bitset(bitset), isolate); 245 return i::handle(from_bitset(bitset), isolate);
278 } 246 }
279 247
280 248
281 // static 249 // static
282 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class( 250 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class(
283 i::Handle<i::Map> map, int lub, Isolate* isolate) { 251 i::Handle<i::Map> map, Isolate* isolate) {
284 return i::Handle<Type>::cast(i::Handle<Object>::cast(map)); 252 return i::Handle<Type>::cast(i::Handle<Object>::cast(map));
285 } 253 }
286 254
287 255
288 // static 256 // static
289 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant(
290 i::Handle<i::Object> value, int lub, Isolate* isolate) {
291 i::Handle<Box> box = isolate->factory()->NewBox(value);
292 return i::Handle<Type>::cast(i::Handle<Object>::cast(box));
293 }
294
295
296 // static
297 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct( 257 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct(
298 i::Handle<Struct> structured) { 258 i::Handle<Struct> structure) {
299 return i::Handle<Type>::cast(i::Handle<Object>::cast(structured)); 259 return i::Handle<Type>::cast(i::Handle<Object>::cast(structure));
300 } 260 }
301 261
302 262
303 // static 263 // static
304 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create( 264 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create(
305 int tag, int length, Isolate* isolate) { 265 int tag, int length, Isolate* isolate) {
306 i::Handle<Struct> structured = isolate->factory()->NewFixedArray(length + 1); 266 i::Handle<Struct> structure = isolate->factory()->NewFixedArray(length + 1);
307 structured->set(0, i::Smi::FromInt(tag)); 267 structure->set(0, i::Smi::FromInt(tag));
308 return structured; 268 return structure;
309 } 269 }
310 270
311 271
312 // static 272 // static
313 void HeapTypeConfig::struct_shrink(i::Handle<Struct> structured, int length) { 273 void HeapTypeConfig::struct_shrink(i::Handle<Struct> structure, int length) {
314 structured->Shrink(length + 1); 274 structure->Shrink(length + 1);
315 } 275 }
316 276
317 277
318 // static 278 // static
319 int HeapTypeConfig::struct_tag(i::Handle<Struct> structured) { 279 int HeapTypeConfig::struct_tag(i::Handle<Struct> structure) {
320 return static_cast<i::Smi*>(structured->get(0))->value(); 280 return static_cast<i::Smi*>(structure->get(0))->value();
321 } 281 }
322 282
323 283
324 // static 284 // static
325 int HeapTypeConfig::struct_length(i::Handle<Struct> structured) { 285 int HeapTypeConfig::struct_length(i::Handle<Struct> structure) {
326 return structured->length() - 1; 286 return structure->length() - 1;
327 } 287 }
328 288
329 289
330 // static 290 // static
331 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::struct_get( 291 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::struct_get(
332 i::Handle<Struct> structured, int i) { 292 i::Handle<Struct> structure, int i) {
333 Type* type = static_cast<Type*>(structured->get(i + 1)); 293 Type* type = static_cast<Type*>(structure->get(i + 1));
334 return i::handle(type, structured->GetIsolate()); 294 return i::handle(type, structure->GetIsolate());
335 } 295 }
336 296
337 297
338 // static 298 // static
339 void HeapTypeConfig::struct_set( 299 void HeapTypeConfig::struct_set(
340 i::Handle<Struct> structured, int i, i::Handle<Type> type) { 300 i::Handle<Struct> structure, int i, i::Handle<Type> type) {
341 structured->set(i + 1, *type); 301 structure->set(i + 1, *type);
342 } 302 }
343 303
344 304
345 // static 305 // static
346 int HeapTypeConfig::lub_bitset(Type* type) { 306 template<class O>
347 return 0; // kNone, which causes recomputation. 307 i::Handle<O> HeapTypeConfig::struct_get_heap(
308 i::Handle<Struct> structure, int i) {
309 O* x = static_cast<O*>(structure->get(i + 1));
310 return i::handle(x, structure->GetIsolate());
311 }
312
313
314 // static
315 template<class O>
316 void HeapTypeConfig::struct_set_heap(
317 i::Handle<Struct> structure, int i, i::Handle<O> x) {
318 structure->set(i + 1, *x);
348 } 319 }
349 320
350 } } // namespace v8::internal 321 } } // namespace v8::internal
351 322
352 #endif // V8_TYPES_INL_H_ 323 #endif // V8_TYPES_INL_H_
OLDNEW
« src/types.cc ('K') | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698