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 {
// Encode type, copied, synced and data in one 32 bit integer.
uint32_t value_;
// Declare BitFields with template parameters <type, start, size>.
class TypeField: public BitField<Type, 0, 3> {};
class CopiedField: public BitField<bool, 3, 1> {};
class SyncedField: public BitField<bool, 4, 1> {};
class UntaggedInt32Field: public BitField<bool, 5, 1> {};
class NumberInfoField: public BitField<int, 6, 4> {};
class DataField: public BitField<uint32_t, 10, 32 - 10> {};
class NumberInfoField: public BitField<int, 6, 6> {};
class DataField: public BitField<uint32_t, 12, 32 - 12> {};
friend class VirtualFrame;
};
......
......@@ -33,19 +33,23 @@ namespace internal {
// Unknown
// |
// Number
// / |
// HeapNumber Integer32
// | |
// | Smi
// | /
// Uninitialized.
// PrimitiveType
// | \--------|
// Number String
// / | |
// HeapNumber Integer32 |
// | | /
// | Smi /
// | / /
// Uninitialized.
class NumberInfo {
public:
NumberInfo() { }
static inline NumberInfo Unknown();
// We know it's a primitive type.
static inline NumberInfo Primitive();
// We know it's a number of some sort.
static inline NumberInfo Number();
// We know it's signed or unsigned 32 bit integer.
......@@ -54,13 +58,18 @@ class NumberInfo {
static inline NumberInfo Smi();
// We know it's a heap number.
static inline NumberInfo HeapNumber();
// We know it's a string.
static inline NumberInfo String();
// We haven't started collecting info yet.
static inline NumberInfo Uninitialized();
// 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() {
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 <= 7);
return answer;
......@@ -71,6 +80,7 @@ class NumberInfo {
Type t = static_cast<Type>(three_bit_representation >= 6 ?
three_bit_representation + 2 :
three_bit_representation);
t = (t == kUnknownType) ? t : static_cast<Type>(t | kPrimitiveType);
ASSERT(t == kUnknownType ||
t == kNumberType ||
t == kInteger32Type ||
......@@ -86,10 +96,12 @@ class NumberInfo {
static NumberInfo FromInt(int bit_representation) {
Type t = static_cast<Type>(bit_representation);
ASSERT(t == kUnknownType ||
t == kPrimitiveType ||
t == kNumberType ||
t == kInteger32Type ||
t == kSmiType ||
t == kHeapNumberType);
t == kHeapNumberType ||
t == kStringType);
return NumberInfo(t);
}
......@@ -129,10 +141,12 @@ class NumberInfo {
const char* ToString() {
switch (type_) {
case kUnknownType: return "UnknownType";
case kPrimitiveType: return "PrimitiveType";
case kNumberType: return "NumberType";
case kInteger32Type: return "Integer32Type";
case kSmiType: return "SmiType";
case kHeapNumberType: return "HeapNumberType";
case kInteger32Type: return "Integer32Type";
case kStringType: return "StringType";
case kUninitializedType:
UNREACHABLE();
return "UninitializedType";
......@@ -142,13 +156,16 @@ class NumberInfo {
}
private:
// We use 6 bits to represent the types.
enum Type {
kUnknownType = 0,
kNumberType = 1,
kInteger32Type = 3,
kSmiType = 7,
kHeapNumberType = 9,
kUninitializedType = 15
kUnknownType = 0, // 000000
kPrimitiveType = 0x10, // 010000
kNumberType = 0x11, // 010001
kInteger32Type = 0x13, // 010011
kSmiType = 0x17, // 010111
kHeapNumberType = 0x19, // 011001
kStringType = 0x30, // 110000
kUninitializedType = 0x3f // 111111
};
explicit inline NumberInfo(Type t) : type_(t) { }
......@@ -161,6 +178,11 @@ NumberInfo NumberInfo::Unknown() {
}
NumberInfo NumberInfo::Primitive() {
return NumberInfo(kPrimitiveType);
}
NumberInfo NumberInfo::Number() {
return NumberInfo(kNumberType);
}
......@@ -181,6 +203,11 @@ NumberInfo NumberInfo::HeapNumber() {
}
NumberInfo NumberInfo::String() {
return NumberInfo(kStringType);
}
NumberInfo NumberInfo::Uninitialized() {
return NumberInfo(kUninitializedType);
}
......
......@@ -152,10 +152,11 @@ class Result BASE_EMBEDDED {
private:
uint32_t value_;
// Declare BitFields with template parameters <type, start, size>.
class TypeField: public BitField<Type, 0, 2> {};
class NumberInfoField : public BitField<int, 2, 4> {};
class IsUntaggedInt32Field : public BitField<bool, 6, 1> {};
class DataField: public BitField<uint32_t, 7, 32 - 7> {};
class NumberInfoField : public BitField<int, 2, 6> {};
class IsUntaggedInt32Field : public BitField<bool, 8, 1> {};
class DataField: public BitField<uint32_t, 9, 32 - 9> {};
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