Store type information with constants.

Instead of testing the value of a constant frame element to determine
the type we compute its type information at construction time.

This speeds up querying the type information during code generation.

This change also adds support for Integer32 constants and sets 
the type information accordingly.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4256 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c0c1ebca
......@@ -28,7 +28,7 @@
#ifndef V8_FRAME_ELEMENT_H_
#define V8_FRAME_ELEMENT_H_
#include "number-info.h"
#include "number-info-inl.h"
#include "macro-assembler.h"
#include "zone.h"
......@@ -58,13 +58,7 @@ class FrameElement BASE_EMBEDDED {
// Copied elements do not have number info. Instead
// we have to inspect their backing element in the frame.
ASSERT(!is_copy());
if (!is_constant()) {
return NumberInfo::FromInt(NumberInfoField::decode(value_));
}
Handle<Object> value = handle();
if (value->IsSmi()) return NumberInfo::Smi();
if (value->IsHeapNumber()) return NumberInfo::HeapNumber();
return NumberInfo::Unknown();
return NumberInfo::FromInt(NumberInfoField::decode(value_));
}
inline void set_number_info(NumberInfo info) {
......@@ -107,7 +101,8 @@ class FrameElement BASE_EMBEDDED {
// compile time.
static FrameElement ConstantElement(Handle<Object> value,
SyncFlag is_synced) {
FrameElement result(value, is_synced);
NumberInfo info = NumberInfo::TypeFromValue(value);
FrameElement result(value, is_synced, info);
return result;
}
......@@ -232,11 +227,11 @@ class FrameElement BASE_EMBEDDED {
}
// Used to construct constant elements.
FrameElement(Handle<Object> value, SyncFlag is_synced) {
FrameElement(Handle<Object> value, SyncFlag is_synced, NumberInfo info) {
value_ = TypeField::encode(CONSTANT)
| CopiedField::encode(false)
| SyncedField::encode(is_synced != NOT_SYNCED)
| NumberInfoField::encode(NumberInfo::Uninitialized().ToInt())
| NumberInfoField::encode(info.ToInt())
| DataField::encode(ConstantList()->length());
ConstantList()->Add(value);
}
......
......@@ -9728,7 +9728,7 @@ void FloatingPointHelper::LoadNumbersAsIntegers(MacroAssembler* masm,
Label arg2_is_object, check_undefined_arg2;
Label load_arg2, done;
if (!number_info.IsHeapNumber()) {
if (!number_info.IsDouble()) {
if (!number_info.IsSmi()) {
__ test(edx, Immediate(kSmiTagMask));
__ j(not_zero, &arg1_is_object);
......@@ -9747,7 +9747,7 @@ void FloatingPointHelper::LoadNumbersAsIntegers(MacroAssembler* masm,
// Here edx has the untagged integer, eax has a Smi or a heap number.
__ bind(&load_arg2);
if (!number_info.IsHeapNumber()) {
if (!number_info.IsDouble()) {
// Test if arg2 is a Smi.
if (!number_info.IsSmi()) {
__ test(eax, Immediate(kSmiTagMask));
......
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_NUMBER_INFO_INL_H_
#define V8_NUMBER_INFO_INL_H_
#include "number-info.h"
#include "objects-inl.h"
namespace v8 {
namespace internal {
NumberInfo NumberInfo::TypeFromValue(Handle<Object> value) {
NumberInfo info;
if (value->IsSmi()) {
info = NumberInfo::Smi();
} else if (value->IsHeapNumber()) {
info = NumberInfo::IsInt32Double(HeapNumber::cast(*value)->value())
? NumberInfo::Integer32()
: NumberInfo::Double();
} else {
info = NumberInfo::Unknown();
}
return info;
}
} } // namespace v8::internal
#endif // V8_NUMBER_INFO_INL_H_
......@@ -37,7 +37,7 @@ namespace internal {
// | \--------|
// Number String
// / | |
// HeapNumber Integer32 |
// Double Integer32 |
// | | /
// | Smi /
// | / /
......@@ -57,7 +57,7 @@ class NumberInfo {
// We know it's a Smi.
static inline NumberInfo Smi();
// We know it's a heap number.
static inline NumberInfo HeapNumber();
static inline NumberInfo Double();
// We know it's a string.
static inline NumberInfo String();
// We haven't started collecting info yet.
......@@ -85,7 +85,7 @@ class NumberInfo {
t == kNumberType ||
t == kInteger32Type ||
t == kSmiType ||
t == kHeapNumberType);
t == kDoubleType);
return NumberInfo(t);
}
......@@ -100,7 +100,7 @@ class NumberInfo {
t == kNumberType ||
t == kInteger32Type ||
t == kSmiType ||
t == kHeapNumberType ||
t == kDoubleType ||
t == kStringType);
return NumberInfo(t);
}
......@@ -110,6 +110,22 @@ class NumberInfo {
return NumberInfo(static_cast<Type>(a.type_ & b.type_));
}
// Integer32 is an integer that can be represented as either a signed
// 32-bit integer or as an unsigned 32-bit integer. It has to be
// in the range [-2^31, 2^32 - 1].
static inline bool IsInt32Double(double value) {
if (value >= -0x80000000 && value <= 0xffffffffu) {
if (value <= 0x7fffffff && value == static_cast<int32_t>(value)) {
return true;
}
if (value == static_cast<uint32_t>(value)) return true;
}
return false;
}
static inline NumberInfo TypeFromValue(Handle<Object> value);
inline bool IsUnknown() {
return type_ == kUnknownType;
}
......@@ -129,9 +145,9 @@ class NumberInfo {
return ((type_ & kInteger32Type) == kInteger32Type);
}
inline bool IsHeapNumber() {
inline bool IsDouble() {
ASSERT(type_ != kUninitializedType);
return ((type_ & kHeapNumberType) == kHeapNumberType);
return ((type_ & kDoubleType) == kDoubleType);
}
inline bool IsUninitialized() {
......@@ -145,7 +161,7 @@ class NumberInfo {
case kNumberType: return "NumberType";
case kInteger32Type: return "Integer32Type";
case kSmiType: return "SmiType";
case kHeapNumberType: return "HeapNumberType";
case kDoubleType: return "DoubleType";
case kStringType: return "StringType";
case kUninitializedType:
UNREACHABLE();
......@@ -163,7 +179,7 @@ class NumberInfo {
kNumberType = 0x11, // 010001
kInteger32Type = 0x13, // 010011
kSmiType = 0x17, // 010111
kHeapNumberType = 0x19, // 011001
kDoubleType = 0x19, // 011001
kStringType = 0x30, // 110000
kUninitializedType = 0x3f // 111111
};
......@@ -198,8 +214,8 @@ NumberInfo NumberInfo::Smi() {
}
NumberInfo NumberInfo::HeapNumber() {
return NumberInfo(kHeapNumberType);
NumberInfo NumberInfo::Double() {
return NumberInfo(kDoubleType);
}
......
......@@ -106,13 +106,7 @@ void RegisterAllocator::Unuse(Register reg) {
NumberInfo Result::number_info() const {
ASSERT(is_valid());
if (!is_constant()) {
return NumberInfo::FromInt(NumberInfoField::decode(value_));
}
Handle<Object> value = handle();
if (value->IsSmi()) return NumberInfo::Smi();
if (value->IsHeapNumber()) return NumberInfo::HeapNumber();
return NumberInfo::Unknown();
return NumberInfo::FromInt(NumberInfoField::decode(value_));
}
......@@ -138,8 +132,8 @@ bool Result::is_integer32() const {
}
bool Result::is_heap_number() const {
return number_info().IsHeapNumber();
bool Result::is_double() const {
return number_info().IsDouble();
}
} } // namespace v8::internal
......
......@@ -29,7 +29,7 @@
#define V8_REGISTER_ALLOCATOR_H_
#include "macro-assembler.h"
#include "number-info.h"
#include "number-info-inl.h"
#if V8_TARGET_ARCH_IA32
#include "ia32/register-allocator-ia32.h"
......@@ -69,8 +69,9 @@ class Result BASE_EMBEDDED {
// Construct a Result whose value is a compile-time constant.
explicit Result(Handle<Object> value) {
NumberInfo info = NumberInfo::TypeFromValue(value);
value_ = TypeField::encode(CONSTANT)
| NumberInfoField::encode(NumberInfo::Uninitialized().ToInt())
| NumberInfoField::encode(info.ToInt())
| IsUntaggedInt32Field::encode(false)
| DataField::encode(ConstantList()->length());
ConstantList()->Add(value);
......@@ -107,7 +108,7 @@ class Result BASE_EMBEDDED {
inline bool is_number() const;
inline bool is_smi() const;
inline bool is_integer32() const;
inline bool is_heap_number() const;
inline bool is_double() const;
bool is_valid() const { return type() != INVALID; }
bool is_register() const { return type() == REGISTER; }
......
......@@ -211,12 +211,7 @@ void VirtualFrame::EmitPush(Smi* smi_value) {
void VirtualFrame::EmitPush(Handle<Object> value) {
ASSERT(stack_pointer_ == element_count() - 1);
NumberInfo info = NumberInfo::Unknown();
if (value->IsSmi()) {
info = NumberInfo::Smi();
} else if (value->IsHeapNumber()) {
info = NumberInfo::HeapNumber();
}
NumberInfo info = NumberInfo::TypeFromValue(value);
elements_.Add(FrameElement::MemoryElement(info));
stack_pointer_++;
__ Push(value);
......
......@@ -330,6 +330,7 @@
'../../src/messages.cc',
'../../src/messages.h',
'../../src/natives.h',
'../../src/number-info-inl.h',
'../../src/number-info.h',
'../../src/objects-debug.cc',
'../../src/objects-inl.h',
......
......@@ -688,6 +688,10 @@
RelativePath="..\..\src\natives.h"
>
</File>
<File
RelativePath="..\..\src\number-info-inl.h"
>
</File>
<File
RelativePath="..\..\src\number-info.h"
>
......
......@@ -668,6 +668,10 @@
RelativePath="..\..\src\natives.h"
>
</File>
<File
RelativePath="..\..\src\number-info-inl.h"
>
</File>
<File
RelativePath="..\..\src\number-info.h"
>
......
......@@ -665,6 +665,10 @@
RelativePath="..\..\src\natives.h"
>
</File>
<File
RelativePath="..\..\src\number-info-inl.h"
>
</File>
<File
RelativePath="..\..\src\number-info.h"
>
......
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