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

Unified Diff: src/compiler/machine-type.h

Issue 470593002: Unify MachineType and RepType. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rename tXXX to kTypeXXX, rXXX to kRepXXX, and mXXX to kMachXXX to conform to style guide. Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/machine-operator.h ('k') | src/compiler/representation-change.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/machine-type.h
diff --git a/src/compiler/machine-type.h b/src/compiler/machine-type.h
index 716ca2236d958b4efabe2866ae5e6716573390a3..6e30bec8a56b88073de8aa7f229baf2f3d2b5e41 100644
--- a/src/compiler/machine-type.h
+++ b/src/compiler/machine-type.h
@@ -5,30 +5,121 @@
#ifndef V8_COMPILER_MACHINE_TYPE_H_
#define V8_COMPILER_MACHINE_TYPE_H_
+#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.
+#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.
+
namespace v8 {
namespace internal {
namespace compiler {
-// An enumeration of the storage representations at the machine level.
-// - Words are uninterpreted bits of a given fixed size that can be used
-// to store integers and pointers. They are normally allocated to general
-// purpose registers by the backend and are not tracked for GC.
-// - Floats are bits of a given fixed size that are used to store floating
-// point numbers. They are normally allocated to the floating point
-// registers of the machine and are not tracked for the GC.
-// - Tagged values are the size of a reference into the heap and can store
-// small words or references into the heap using a language and potentially
-// machine-dependent tagging scheme. These values are tracked by the code
-// generator for precise GC.
+// Machine-level types and representations.
+// TODO(titzer): Use the real type system instead of MachineType.
enum MachineType {
- kMachineWord8,
- kMachineWord16,
- kMachineWord32,
- kMachineWord64,
- kMachineFloat64,
- kMachineTagged,
- kMachineLast
+ // Representations.
+ kRepBit = 1 << 0,
+ kRepWord8 = 1 << 1,
+ kRepWord16 = 1 << 2,
+ kRepWord32 = 1 << 3,
+ kRepWord64 = 1 << 4,
+ kRepFloat64 = 1 << 5,
+ kRepTagged = 1 << 6,
+
+ // Types.
+ kTypeBool = 1 << 7,
+ kTypeInt32 = 1 << 8,
+ kTypeUint32 = 1 << 9,
+ kTypeInt64 = 1 << 10,
+ kTypeUint64 = 1 << 11,
+ kTypeNumber = 1 << 12,
+ kTypeAny = 1 << 13
};
+
+typedef uint16_t MachineTypeUnion;
+
+#define PRINT(bit) \
+ if (type & bit) { \
+ if (before) os << "|"; \
+ os << #bit; \
+ before = true; \
+ }
+
+// Print a machine type or machine type union to a stream.
+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.
+ bool before = false;
+ PRINT(kRepBit);
+ PRINT(kRepWord8);
+ PRINT(kRepWord16);
+ PRINT(kRepWord32);
+ PRINT(kRepWord64);
+ PRINT(kRepFloat64);
+ PRINT(kRepTagged);
+
+ PRINT(kTypeBool);
+ PRINT(kTypeInt32);
+ PRINT(kTypeUint32);
+ PRINT(kTypeInt64);
+ PRINT(kTypeUint64);
+ PRINT(kTypeNumber);
+ PRINT(kTypeAny);
+}
+
+// Globally useful machine types and constants.
+const MachineTypeUnion kRepMask = kRepBit | kRepWord8 | kRepWord16 |
+ kRepWord32 | kRepWord64 | kRepFloat64 |
+ kRepTagged;
+const MachineTypeUnion kTypeMask = kTypeBool | kTypeInt32 | kTypeUint32 |
+ kTypeInt64 | kTypeUint64 | kTypeNumber |
+ kTypeAny;
+
+const MachineType kMachNone = static_cast<MachineType>(0);
+const MachineType kMachFloat64 =
+ static_cast<MachineType>(kRepFloat64 | kTypeNumber);
+const MachineType kMachInt8 = static_cast<MachineType>(kRepWord8 | kTypeInt32);
+const MachineType kMachUint8 =
+ static_cast<MachineType>(kRepWord8 | kTypeUint32);
+const MachineType kMachInt16 =
+ static_cast<MachineType>(kRepWord16 | kTypeInt32);
+const MachineType kMachUint16 =
+ static_cast<MachineType>(kRepWord16 | kTypeUint32);
+const MachineType kMachInt32 =
+ static_cast<MachineType>(kRepWord32 | kTypeInt32);
+const MachineType kMachUint32 =
+ static_cast<MachineType>(kRepWord32 | kTypeUint32);
+const MachineType kMachInt64 =
+ static_cast<MachineType>(kRepWord64 | kTypeInt64);
+const MachineType kMachUint64 =
+ static_cast<MachineType>(kRepWord64 | kTypeUint64);
+const MachineType kMachPtr = kPointerSize == 4 ? kRepWord32 : kRepWord64;
+const MachineType kMachAnyTagged =
+ static_cast<MachineType>(kRepTagged | kTypeAny);
+
+// Gets only the representation of the given type.
+inline MachineType RepresentationOf(MachineType machine_type) {
+ int result = machine_type & kRepMask;
+ CHECK(IsPowerOf2(result));
+ return static_cast<MachineType>(result);
+}
+
+// Gets the element size in bytes of the machine type.
+inline int ElementSizeOf(MachineType machine_type) {
+ switch (RepresentationOf(machine_type)) {
+ case kRepBit:
+ case kRepWord8:
+ return 1;
+ case kRepWord16:
+ return 2;
+ case kRepWord32:
+ return 4;
+ case kRepWord64:
+ case kRepFloat64:
+ return 8;
+ case kRepTagged:
+ return kPointerSize;
+ default:
+ UNREACHABLE();
+ return kPointerSize;
+ }
+}
}
}
} // namespace v8::internal::compiler
« no previous file with comments | « src/compiler/machine-operator.h ('k') | src/compiler/representation-change.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698