Add primitive type and string type to the number info.

This change adds two new type attributes to  the lattice
defined in the class NumberInfo. Currently the new types
are not used yet.

I plan to rename NumberInfo into TypeInfo as a separate change.

Review URL: http://codereview.chromium.org/1249002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4250 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 71e792a8
...@@ -262,12 +262,13 @@ class FrameElement BASE_EMBEDDED { ...@@ -262,12 +262,13 @@ class FrameElement BASE_EMBEDDED {
// Encode type, copied, synced and data in one 32 bit integer. // Encode type, copied, synced and data in one 32 bit integer.
uint32_t value_; uint32_t value_;
// Declare BitFields with template parameters <type, start, size>.
class TypeField: public BitField<Type, 0, 3> {}; class TypeField: public BitField<Type, 0, 3> {};
class CopiedField: public BitField<bool, 3, 1> {}; class CopiedField: public BitField<bool, 3, 1> {};
class SyncedField: public BitField<bool, 4, 1> {}; class SyncedField: public BitField<bool, 4, 1> {};
class UntaggedInt32Field: public BitField<bool, 5, 1> {}; class UntaggedInt32Field: public BitField<bool, 5, 1> {};
class NumberInfoField: public BitField<int, 6, 4> {}; class NumberInfoField: public BitField<int, 6, 6> {};
class DataField: public BitField<uint32_t, 10, 32 - 10> {}; class DataField: public BitField<uint32_t, 12, 32 - 12> {};
friend class VirtualFrame; friend class VirtualFrame;
}; };
......
...@@ -33,19 +33,23 @@ namespace internal { ...@@ -33,19 +33,23 @@ namespace internal {
// Unknown // Unknown
// | // |
// Number // PrimitiveType
// / | // | \--------|
// HeapNumber Integer32 // Number String
// | | // / | |
// | Smi // HeapNumber Integer32 |
// | / // | | /
// Uninitialized. // | Smi /
// | / /
// Uninitialized.
class NumberInfo { class NumberInfo {
public: public:
NumberInfo() { } NumberInfo() { }
static inline NumberInfo Unknown(); static inline NumberInfo Unknown();
// We know it's a primitive type.
static inline NumberInfo Primitive();
// We know it's a number of some sort. // We know it's a number of some sort.
static inline NumberInfo Number(); static inline NumberInfo Number();
// We know it's signed or unsigned 32 bit integer. // We know it's signed or unsigned 32 bit integer.
...@@ -54,13 +58,18 @@ class NumberInfo { ...@@ -54,13 +58,18 @@ class NumberInfo {
static inline NumberInfo Smi(); static inline NumberInfo Smi();
// We know it's a heap number. // We know it's a heap number.
static inline NumberInfo HeapNumber(); static inline NumberInfo HeapNumber();
// We know it's a string.
static inline NumberInfo String();
// We haven't started collecting info yet. // We haven't started collecting info yet.
static inline NumberInfo Uninitialized(); static inline NumberInfo Uninitialized();
// Return compact representation. Very sensitive to enum values below! // Return compact representation. Very sensitive to enum values below!
// Compacting drops information about primtive types and strings types.
// We use the compact representation when we only care about number types.
int ThreeBitRepresentation() { int ThreeBitRepresentation() {
ASSERT(type_ != kUninitializedType); ASSERT(type_ != kUninitializedType);
int answer = type_ > 6 ? type_ -2 : type_; int answer = type_ & 0xf;
answer = answer > 6 ? answer - 2 : answer;
ASSERT(answer >= 0); ASSERT(answer >= 0);
ASSERT(answer <= 7); ASSERT(answer <= 7);
return answer; return answer;
...@@ -71,6 +80,7 @@ class NumberInfo { ...@@ -71,6 +80,7 @@ class NumberInfo {
Type t = static_cast<Type>(three_bit_representation >= 6 ? Type t = static_cast<Type>(three_bit_representation >= 6 ?
three_bit_representation + 2 : three_bit_representation + 2 :
three_bit_representation); three_bit_representation);
t = (t == kUnknownType) ? t : static_cast<Type>(t | kPrimitiveType);
ASSERT(t == kUnknownType || ASSERT(t == kUnknownType ||
t == kNumberType || t == kNumberType ||
t == kInteger32Type || t == kInteger32Type ||
...@@ -86,10 +96,12 @@ class NumberInfo { ...@@ -86,10 +96,12 @@ class NumberInfo {
static NumberInfo FromInt(int bit_representation) { static NumberInfo FromInt(int bit_representation) {
Type t = static_cast<Type>(bit_representation); Type t = static_cast<Type>(bit_representation);
ASSERT(t == kUnknownType || ASSERT(t == kUnknownType ||
t == kPrimitiveType ||
t == kNumberType || t == kNumberType ||
t == kInteger32Type || t == kInteger32Type ||
t == kSmiType || t == kSmiType ||
t == kHeapNumberType); t == kHeapNumberType ||
t == kStringType);
return NumberInfo(t); return NumberInfo(t);
} }
...@@ -129,10 +141,12 @@ class NumberInfo { ...@@ -129,10 +141,12 @@ class NumberInfo {
const char* ToString() { const char* ToString() {
switch (type_) { switch (type_) {
case kUnknownType: return "UnknownType"; case kUnknownType: return "UnknownType";
case kPrimitiveType: return "PrimitiveType";
case kNumberType: return "NumberType"; case kNumberType: return "NumberType";
case kInteger32Type: return "Integer32Type";
case kSmiType: return "SmiType"; case kSmiType: return "SmiType";
case kHeapNumberType: return "HeapNumberType"; case kHeapNumberType: return "HeapNumberType";
case kInteger32Type: return "Integer32Type"; case kStringType: return "StringType";
case kUninitializedType: case kUninitializedType:
UNREACHABLE(); UNREACHABLE();
return "UninitializedType"; return "UninitializedType";
...@@ -142,13 +156,16 @@ class NumberInfo { ...@@ -142,13 +156,16 @@ class NumberInfo {
} }
private: private:
// We use 6 bits to represent the types.
enum Type { enum Type {
kUnknownType = 0, kUnknownType = 0, // 000000
kNumberType = 1, kPrimitiveType = 0x10, // 010000
kInteger32Type = 3, kNumberType = 0x11, // 010001
kSmiType = 7, kInteger32Type = 0x13, // 010011
kHeapNumberType = 9, kSmiType = 0x17, // 010111
kUninitializedType = 15 kHeapNumberType = 0x19, // 011001
kStringType = 0x30, // 110000
kUninitializedType = 0x3f // 111111
}; };
explicit inline NumberInfo(Type t) : type_(t) { } explicit inline NumberInfo(Type t) : type_(t) { }
...@@ -161,6 +178,11 @@ NumberInfo NumberInfo::Unknown() { ...@@ -161,6 +178,11 @@ NumberInfo NumberInfo::Unknown() {
} }
NumberInfo NumberInfo::Primitive() {
return NumberInfo(kPrimitiveType);
}
NumberInfo NumberInfo::Number() { NumberInfo NumberInfo::Number() {
return NumberInfo(kNumberType); return NumberInfo(kNumberType);
} }
...@@ -181,6 +203,11 @@ NumberInfo NumberInfo::HeapNumber() { ...@@ -181,6 +203,11 @@ NumberInfo NumberInfo::HeapNumber() {
} }
NumberInfo NumberInfo::String() {
return NumberInfo(kStringType);
}
NumberInfo NumberInfo::Uninitialized() { NumberInfo NumberInfo::Uninitialized() {
return NumberInfo(kUninitializedType); return NumberInfo(kUninitializedType);
} }
......
...@@ -152,10 +152,11 @@ class Result BASE_EMBEDDED { ...@@ -152,10 +152,11 @@ class Result BASE_EMBEDDED {
private: private:
uint32_t value_; uint32_t value_;
// Declare BitFields with template parameters <type, start, size>.
class TypeField: public BitField<Type, 0, 2> {}; class TypeField: public BitField<Type, 0, 2> {};
class NumberInfoField : public BitField<int, 2, 4> {}; class NumberInfoField : public BitField<int, 2, 6> {};
class IsUntaggedInt32Field : public BitField<bool, 6, 1> {}; class IsUntaggedInt32Field : public BitField<bool, 8, 1> {};
class DataField: public BitField<uint32_t, 7, 32 - 7> {}; class DataField: public BitField<uint32_t, 9, 32 - 9> {};
inline void CopyTo(Result* destination) const; inline void CopyTo(Result* destination) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment