Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_COMPILER_MACHINE_TYPE_H_ | 5 #ifndef V8_COMPILER_MACHINE_TYPE_H_ |
| 6 #define V8_COMPILER_MACHINE_TYPE_H_ | 6 #define V8_COMPILER_MACHINE_TYPE_H_ |
| 7 | 7 |
| 8 #include "src/ostreams.h" | |
|
Benedikt Meurer
2014/08/14 07:57:02
Please avoid including "src/ostreams.h" in headers
titzer
2014/08/14 08:26:46
Done.
| |
| 9 #include "src/v8.h" | |
|
Benedikt Meurer
2014/08/14 07:57:01
Same for "src/v8.h". Include what you need instead
titzer
2014/08/14 08:26:46
It needs kPointerSize to define the kMachPtr type.
Benedikt Meurer
2014/08/14 08:28:46
Then include "src/globals.h" which defines it.
| |
| 10 | |
| 8 namespace v8 { | 11 namespace v8 { |
| 9 namespace internal { | 12 namespace internal { |
| 10 namespace compiler { | 13 namespace compiler { |
| 11 | 14 |
| 12 // An enumeration of the storage representations at the machine level. | 15 // Machine-level types and representations. |
| 13 // - Words are uninterpreted bits of a given fixed size that can be used | 16 // TODO(titzer): Use the real type system instead of MachineType. |
| 14 // to store integers and pointers. They are normally allocated to general | |
| 15 // purpose registers by the backend and are not tracked for GC. | |
| 16 // - Floats are bits of a given fixed size that are used to store floating | |
| 17 // point numbers. They are normally allocated to the floating point | |
| 18 // registers of the machine and are not tracked for the GC. | |
| 19 // - Tagged values are the size of a reference into the heap and can store | |
| 20 // small words or references into the heap using a language and potentially | |
| 21 // machine-dependent tagging scheme. These values are tracked by the code | |
| 22 // generator for precise GC. | |
| 23 enum MachineType { | 17 enum MachineType { |
| 24 kMachineWord8, | 18 // Representations. |
| 25 kMachineWord16, | 19 kRepBit = 1 << 0, |
| 26 kMachineWord32, | 20 kRepWord8 = 1 << 1, |
| 27 kMachineWord64, | 21 kRepWord16 = 1 << 2, |
| 28 kMachineFloat64, | 22 kRepWord32 = 1 << 3, |
| 29 kMachineTagged, | 23 kRepWord64 = 1 << 4, |
| 30 kMachineLast | 24 kRepFloat64 = 1 << 5, |
| 25 kRepTagged = 1 << 6, | |
| 26 | |
| 27 // Types. | |
| 28 kTypeBool = 1 << 7, | |
| 29 kTypeInt32 = 1 << 8, | |
| 30 kTypeUint32 = 1 << 9, | |
| 31 kTypeInt64 = 1 << 10, | |
| 32 kTypeUint64 = 1 << 11, | |
| 33 kTypeNumber = 1 << 12, | |
| 34 kTypeAny = 1 << 13 | |
| 31 }; | 35 }; |
| 36 | |
| 37 typedef uint16_t MachineTypeUnion; | |
| 38 | |
| 39 #define PRINT(bit) \ | |
| 40 if (type & bit) { \ | |
| 41 if (before) os << "|"; \ | |
| 42 os << #bit; \ | |
| 43 before = true; \ | |
| 44 } | |
| 45 | |
| 46 // Print a machine type or machine type union to a stream. | |
| 47 inline void PrintMachineTypeUnionTo(OStream& os, MachineTypeUnion type) { | |
|
Benedikt Meurer
2014/08/14 07:57:02
Please use regular stream syntax:
OStream& operat
titzer
2014/08/14 08:26:46
Done.
| |
| 48 bool before = false; | |
| 49 PRINT(kRepBit); | |
| 50 PRINT(kRepWord8); | |
| 51 PRINT(kRepWord16); | |
| 52 PRINT(kRepWord32); | |
| 53 PRINT(kRepWord64); | |
| 54 PRINT(kRepFloat64); | |
| 55 PRINT(kRepTagged); | |
| 56 | |
| 57 PRINT(kTypeBool); | |
| 58 PRINT(kTypeInt32); | |
| 59 PRINT(kTypeUint32); | |
| 60 PRINT(kTypeInt64); | |
| 61 PRINT(kTypeUint64); | |
| 62 PRINT(kTypeNumber); | |
| 63 PRINT(kTypeAny); | |
| 64 } | |
| 65 | |
| 66 // Globally useful machine types and constants. | |
| 67 const MachineTypeUnion kRepMask = kRepBit | kRepWord8 | kRepWord16 | | |
| 68 kRepWord32 | kRepWord64 | kRepFloat64 | | |
| 69 kRepTagged; | |
| 70 const MachineTypeUnion kTypeMask = kTypeBool | kTypeInt32 | kTypeUint32 | | |
| 71 kTypeInt64 | kTypeUint64 | kTypeNumber | | |
| 72 kTypeAny; | |
| 73 | |
| 74 const MachineType kMachNone = static_cast<MachineType>(0); | |
| 75 const MachineType kMachFloat64 = | |
| 76 static_cast<MachineType>(kRepFloat64 | kTypeNumber); | |
| 77 const MachineType kMachInt8 = static_cast<MachineType>(kRepWord8 | kTypeInt32); | |
| 78 const MachineType kMachUint8 = | |
| 79 static_cast<MachineType>(kRepWord8 | kTypeUint32); | |
| 80 const MachineType kMachInt16 = | |
| 81 static_cast<MachineType>(kRepWord16 | kTypeInt32); | |
| 82 const MachineType kMachUint16 = | |
| 83 static_cast<MachineType>(kRepWord16 | kTypeUint32); | |
| 84 const MachineType kMachInt32 = | |
| 85 static_cast<MachineType>(kRepWord32 | kTypeInt32); | |
| 86 const MachineType kMachUint32 = | |
| 87 static_cast<MachineType>(kRepWord32 | kTypeUint32); | |
| 88 const MachineType kMachInt64 = | |
| 89 static_cast<MachineType>(kRepWord64 | kTypeInt64); | |
| 90 const MachineType kMachUint64 = | |
| 91 static_cast<MachineType>(kRepWord64 | kTypeUint64); | |
| 92 const MachineType kMachPtr = kPointerSize == 4 ? kRepWord32 : kRepWord64; | |
| 93 const MachineType kMachAnyTagged = | |
| 94 static_cast<MachineType>(kRepTagged | kTypeAny); | |
| 95 | |
| 96 // Gets only the representation of the given type. | |
| 97 inline MachineType RepresentationOf(MachineType machine_type) { | |
| 98 int result = machine_type & kRepMask; | |
| 99 CHECK(IsPowerOf2(result)); | |
| 100 return static_cast<MachineType>(result); | |
| 101 } | |
| 102 | |
| 103 // Gets the element size in bytes of the machine type. | |
| 104 inline int ElementSizeOf(MachineType machine_type) { | |
| 105 switch (RepresentationOf(machine_type)) { | |
| 106 case kRepBit: | |
| 107 case kRepWord8: | |
| 108 return 1; | |
| 109 case kRepWord16: | |
| 110 return 2; | |
| 111 case kRepWord32: | |
| 112 return 4; | |
| 113 case kRepWord64: | |
| 114 case kRepFloat64: | |
| 115 return 8; | |
| 116 case kRepTagged: | |
| 117 return kPointerSize; | |
| 118 default: | |
| 119 UNREACHABLE(); | |
| 120 return kPointerSize; | |
| 121 } | |
| 122 } | |
| 32 } | 123 } |
| 33 } | 124 } |
| 34 } // namespace v8::internal::compiler | 125 } // namespace v8::internal::compiler |
| 35 | 126 |
| 36 #endif // V8_COMPILER_MACHINE_TYPE_H_ | 127 #endif // V8_COMPILER_MACHINE_TYPE_H_ |
| OLD | NEW |