OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 17 matching lines...) Expand all Loading... |
28 #ifndef V8_LITHIUM_H_ | 28 #ifndef V8_LITHIUM_H_ |
29 #define V8_LITHIUM_H_ | 29 #define V8_LITHIUM_H_ |
30 | 30 |
31 #include "allocation.h" | 31 #include "allocation.h" |
32 #include "hydrogen.h" | 32 #include "hydrogen.h" |
33 #include "safepoint-table.h" | 33 #include "safepoint-table.h" |
34 | 34 |
35 namespace v8 { | 35 namespace v8 { |
36 namespace internal { | 36 namespace internal { |
37 | 37 |
38 #define LITHIUM_OPERAND_LIST(V) \ | 38 #define LITHIUM_OPERAND_LIST(V) \ |
39 V(ConstantOperand, CONSTANT_OPERAND) \ | 39 V(ConstantOperand, CONSTANT_OPERAND, 128) \ |
40 V(StackSlot, STACK_SLOT) \ | 40 V(StackSlot, STACK_SLOT, 128) \ |
41 V(DoubleStackSlot, DOUBLE_STACK_SLOT) \ | 41 V(DoubleStackSlot, DOUBLE_STACK_SLOT, 128) \ |
42 V(Register, REGISTER) \ | 42 V(Register, REGISTER, 16) \ |
43 V(DoubleRegister, DOUBLE_REGISTER) | 43 V(DoubleRegister, DOUBLE_REGISTER, 16) |
44 | 44 |
45 | 45 |
46 class LOperand : public ZoneObject { | 46 class LOperand : public ZoneObject { |
47 public: | 47 public: |
48 enum Kind { | 48 enum Kind { |
49 INVALID, | 49 INVALID, |
50 UNALLOCATED, | 50 UNALLOCATED, |
51 CONSTANT_OPERAND, | 51 CONSTANT_OPERAND, |
52 STACK_SLOT, | 52 STACK_SLOT, |
53 DOUBLE_STACK_SLOT, | 53 DOUBLE_STACK_SLOT, |
54 REGISTER, | 54 REGISTER, |
55 DOUBLE_REGISTER, | 55 DOUBLE_REGISTER, |
56 ARGUMENT | 56 ARGUMENT |
57 }; | 57 }; |
58 | 58 |
59 LOperand() : value_(KindField::encode(INVALID)) { } | 59 LOperand() : value_(KindField::encode(INVALID)) { } |
60 | 60 |
61 Kind kind() const { return KindField::decode(value_); } | 61 Kind kind() const { return KindField::decode(value_); } |
62 int index() const { return static_cast<int>(value_) >> kKindFieldWidth; } | 62 int index() const { return static_cast<int>(value_) >> kKindFieldWidth; } |
63 #define LITHIUM_OPERAND_PREDICATE(name, type) \ | 63 #define LITHIUM_OPERAND_PREDICATE(name, type, number) \ |
64 bool Is##name() const { return kind() == type; } | 64 bool Is##name() const { return kind() == type; } |
65 LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE) | 65 LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE) |
66 LITHIUM_OPERAND_PREDICATE(Argument, ARGUMENT) | 66 LITHIUM_OPERAND_PREDICATE(Argument, ARGUMENT, 0) |
67 LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED) | 67 LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED, 0) |
68 LITHIUM_OPERAND_PREDICATE(Ignored, INVALID) | 68 LITHIUM_OPERAND_PREDICATE(Ignored, INVALID, 0) |
69 #undef LITHIUM_OPERAND_PREDICATE | 69 #undef LITHIUM_OPERAND_PREDICATE |
70 bool Equals(LOperand* other) const { return value_ == other->value_; } | 70 bool Equals(LOperand* other) const { return value_ == other->value_; } |
71 | 71 |
72 void PrintTo(StringStream* stream); | 72 void PrintTo(StringStream* stream); |
73 void ConvertTo(Kind kind, int index) { | 73 void ConvertTo(Kind kind, int index) { |
74 value_ = KindField::encode(kind); | 74 value_ = KindField::encode(kind); |
75 value_ |= index << kKindFieldWidth; | 75 value_ |= index << kKindFieldWidth; |
76 ASSERT(this->index() == index); | 76 ASSERT(this->index() == index); |
77 } | 77 } |
78 | 78 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 ASSERT(source_ != NULL || destination_ == NULL); | 310 ASSERT(source_ != NULL || destination_ == NULL); |
311 return source_ == NULL; | 311 return source_ == NULL; |
312 } | 312 } |
313 | 313 |
314 private: | 314 private: |
315 LOperand* source_; | 315 LOperand* source_; |
316 LOperand* destination_; | 316 LOperand* destination_; |
317 }; | 317 }; |
318 | 318 |
319 | 319 |
320 class LConstantOperand V8_FINAL : public LOperand { | 320 template<LOperand::Kind kOperandKind, int kNumCachedOperands> |
| 321 class LSubKindOperand V8_FINAL : public LOperand { |
321 public: | 322 public: |
322 static LConstantOperand* Create(int index, Zone* zone) { | 323 static LSubKindOperand* Create(int index, Zone* zone) { |
323 ASSERT(index >= 0); | 324 ASSERT(index >= 0); |
324 if (index < kNumCachedOperands) return &cache[index]; | 325 if (index < kNumCachedOperands) return &cache[index]; |
325 return new(zone) LConstantOperand(index); | 326 return new(zone) LSubKindOperand(index); |
326 } | 327 } |
327 | 328 |
328 static LConstantOperand* cast(LOperand* op) { | 329 static LSubKindOperand* cast(LOperand* op) { |
329 ASSERT(op->IsConstantOperand()); | 330 ASSERT(op->kind() == kOperandKind); |
330 return reinterpret_cast<LConstantOperand*>(op); | 331 return reinterpret_cast<LSubKindOperand*>(op); |
331 } | 332 } |
332 | 333 |
333 static void SetUpCache(); | 334 static void SetUpCache(); |
334 static void TearDownCache(); | 335 static void TearDownCache(); |
335 | 336 |
336 private: | 337 private: |
337 static const int kNumCachedOperands = 128; | 338 static LSubKindOperand* cache; |
338 static LConstantOperand* cache; | |
339 | 339 |
340 LConstantOperand() : LOperand() { } | 340 LSubKindOperand() : LOperand() { } |
341 explicit LConstantOperand(int index) : LOperand(CONSTANT_OPERAND, index) { } | 341 explicit LSubKindOperand(int index) : LOperand(kOperandKind, index) { } |
342 }; | 342 }; |
343 | 343 |
344 | 344 |
| 345 #define LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS(name, type, number) \ |
| 346 typedef LSubKindOperand<LOperand::type, number> L##name; |
| 347 LITHIUM_OPERAND_LIST(LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS) |
| 348 #undef LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS |
| 349 |
| 350 |
345 class LArgument V8_FINAL : public LOperand { | 351 class LArgument V8_FINAL : public LOperand { |
346 public: | 352 public: |
347 explicit LArgument(int index) : LOperand(ARGUMENT, index) { } | 353 explicit LArgument(int index) : LOperand(ARGUMENT, index) { } |
348 | 354 |
349 static LArgument* cast(LOperand* op) { | 355 static LArgument* cast(LOperand* op) { |
350 ASSERT(op->IsArgument()); | 356 ASSERT(op->IsArgument()); |
351 return reinterpret_cast<LArgument*>(op); | 357 return reinterpret_cast<LArgument*>(op); |
352 } | 358 } |
353 }; | 359 }; |
354 | 360 |
355 | 361 |
356 class LStackSlot V8_FINAL : public LOperand { | |
357 public: | |
358 static LStackSlot* Create(int index, Zone* zone) { | |
359 ASSERT(index >= 0); | |
360 if (index < kNumCachedOperands) return &cache[index]; | |
361 return new(zone) LStackSlot(index); | |
362 } | |
363 | |
364 static LStackSlot* cast(LOperand* op) { | |
365 ASSERT(op->IsStackSlot()); | |
366 return reinterpret_cast<LStackSlot*>(op); | |
367 } | |
368 | |
369 static void SetUpCache(); | |
370 static void TearDownCache(); | |
371 | |
372 private: | |
373 static const int kNumCachedOperands = 128; | |
374 static LStackSlot* cache; | |
375 | |
376 LStackSlot() : LOperand() { } | |
377 explicit LStackSlot(int index) : LOperand(STACK_SLOT, index) { } | |
378 }; | |
379 | |
380 | |
381 class LDoubleStackSlot V8_FINAL : public LOperand { | |
382 public: | |
383 static LDoubleStackSlot* Create(int index, Zone* zone) { | |
384 ASSERT(index >= 0); | |
385 if (index < kNumCachedOperands) return &cache[index]; | |
386 return new(zone) LDoubleStackSlot(index); | |
387 } | |
388 | |
389 static LDoubleStackSlot* cast(LOperand* op) { | |
390 ASSERT(op->IsStackSlot()); | |
391 return reinterpret_cast<LDoubleStackSlot*>(op); | |
392 } | |
393 | |
394 static void SetUpCache(); | |
395 static void TearDownCache(); | |
396 | |
397 private: | |
398 static const int kNumCachedOperands = 128; | |
399 static LDoubleStackSlot* cache; | |
400 | |
401 LDoubleStackSlot() : LOperand() { } | |
402 explicit LDoubleStackSlot(int index) : LOperand(DOUBLE_STACK_SLOT, index) { } | |
403 }; | |
404 | |
405 | |
406 class LRegister V8_FINAL : public LOperand { | |
407 public: | |
408 static LRegister* Create(int index, Zone* zone) { | |
409 ASSERT(index >= 0); | |
410 if (index < kNumCachedOperands) return &cache[index]; | |
411 return new(zone) LRegister(index); | |
412 } | |
413 | |
414 static LRegister* cast(LOperand* op) { | |
415 ASSERT(op->IsRegister()); | |
416 return reinterpret_cast<LRegister*>(op); | |
417 } | |
418 | |
419 static void SetUpCache(); | |
420 static void TearDownCache(); | |
421 | |
422 private: | |
423 static const int kNumCachedOperands = 16; | |
424 static LRegister* cache; | |
425 | |
426 LRegister() : LOperand() { } | |
427 explicit LRegister(int index) : LOperand(REGISTER, index) { } | |
428 }; | |
429 | |
430 | |
431 class LDoubleRegister V8_FINAL : public LOperand { | |
432 public: | |
433 static LDoubleRegister* Create(int index, Zone* zone) { | |
434 ASSERT(index >= 0); | |
435 if (index < kNumCachedOperands) return &cache[index]; | |
436 return new(zone) LDoubleRegister(index); | |
437 } | |
438 | |
439 static LDoubleRegister* cast(LOperand* op) { | |
440 ASSERT(op->IsDoubleRegister()); | |
441 return reinterpret_cast<LDoubleRegister*>(op); | |
442 } | |
443 | |
444 static void SetUpCache(); | |
445 static void TearDownCache(); | |
446 | |
447 private: | |
448 static const int kNumCachedOperands = 16; | |
449 static LDoubleRegister* cache; | |
450 | |
451 LDoubleRegister() : LOperand() { } | |
452 explicit LDoubleRegister(int index) : LOperand(DOUBLE_REGISTER, index) { } | |
453 }; | |
454 | |
455 | |
456 class LParallelMove V8_FINAL : public ZoneObject { | 362 class LParallelMove V8_FINAL : public ZoneObject { |
457 public: | 363 public: |
458 explicit LParallelMove(Zone* zone) : move_operands_(4, zone) { } | 364 explicit LParallelMove(Zone* zone) : move_operands_(4, zone) { } |
459 | 365 |
460 void AddMove(LOperand* from, LOperand* to, Zone* zone) { | 366 void AddMove(LOperand* from, LOperand* to, Zone* zone) { |
461 move_operands_.Add(LMoveOperands(from, to), zone); | 367 move_operands_.Add(LMoveOperands(from, to), zone); |
462 } | 368 } |
463 | 369 |
464 bool IsRedundant() const; | 370 bool IsRedundant() const; |
465 | 371 |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 private: | 744 private: |
839 LChunk* chunk_; | 745 LChunk* chunk_; |
840 | 746 |
841 DISALLOW_COPY_AND_ASSIGN(LPhase); | 747 DISALLOW_COPY_AND_ASSIGN(LPhase); |
842 }; | 748 }; |
843 | 749 |
844 | 750 |
845 } } // namespace v8::internal | 751 } } // namespace v8::internal |
846 | 752 |
847 #endif // V8_LITHIUM_H_ | 753 #endif // V8_LITHIUM_H_ |
OLD | NEW |