2011-04-07 09:51:25 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2010-02-15 14:24:38 +00:00
|
|
|
// 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.
|
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
#ifndef V8_TYPE_INFO_H_
|
|
|
|
#define V8_TYPE_INFO_H_
|
2010-02-15 14:24:38 +00:00
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
2010-03-24 15:55:15 +00:00
|
|
|
#include "globals.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "zone.h"
|
|
|
|
#include "zone-inl.h"
|
2010-03-24 15:55:15 +00:00
|
|
|
|
2010-02-15 14:24:38 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2011-06-20 10:19:00 +00:00
|
|
|
const int kMaxKeyedPolymorphism = 4;
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Unknown
|
2011-04-27 15:02:59 +00:00
|
|
|
// | \____________
|
|
|
|
// | |
|
|
|
|
// Primitive Non-primitive
|
|
|
|
// | \_______ |
|
|
|
|
// | | |
|
|
|
|
// Number String |
|
|
|
|
// / \ | |
|
|
|
|
// Double Integer32 | /
|
|
|
|
// | | / /
|
|
|
|
// | Smi / /
|
|
|
|
// | | / __/
|
|
|
|
// Uninitialized.
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
class TypeInfo {
|
2010-02-15 14:24:38 +00:00
|
|
|
public:
|
2010-12-07 11:31:57 +00:00
|
|
|
TypeInfo() : type_(kUninitialized) { }
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Unknown() { return TypeInfo(kUnknown); }
|
2010-03-24 12:34:27 +00:00
|
|
|
// We know it's a primitive type.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Primitive() { return TypeInfo(kPrimitive); }
|
2010-03-05 23:54:13 +00:00
|
|
|
// We know it's a number of some sort.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Number() { return TypeInfo(kNumber); }
|
|
|
|
// We know it's a signed 32 bit integer.
|
|
|
|
static TypeInfo Integer32() { return TypeInfo(kInteger32); }
|
2010-03-05 23:54:13 +00:00
|
|
|
// We know it's a Smi.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Smi() { return TypeInfo(kSmi); }
|
2010-03-05 23:54:13 +00:00
|
|
|
// We know it's a heap number.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Double() { return TypeInfo(kDouble); }
|
2010-03-24 12:34:27 +00:00
|
|
|
// We know it's a string.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo String() { return TypeInfo(kString); }
|
|
|
|
// We know it's a non-primitive (object) type.
|
|
|
|
static TypeInfo NonPrimitive() { return TypeInfo(kNonPrimitive); }
|
2010-03-05 23:54:13 +00:00
|
|
|
// We haven't started collecting info yet.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Uninitialized() { return TypeInfo(kUninitialized); }
|
2010-03-05 23:54:13 +00:00
|
|
|
|
|
|
|
int ToInt() {
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
static TypeInfo FromInt(int bit_representation) {
|
2010-03-05 23:54:13 +00:00
|
|
|
Type t = static_cast<Type>(bit_representation);
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(t == kUnknown ||
|
|
|
|
t == kPrimitive ||
|
|
|
|
t == kNumber ||
|
|
|
|
t == kInteger32 ||
|
|
|
|
t == kSmi ||
|
|
|
|
t == kDouble ||
|
|
|
|
t == kString ||
|
|
|
|
t == kNonPrimitive);
|
2010-03-25 12:44:15 +00:00
|
|
|
return TypeInfo(t);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
2010-02-15 14:24:38 +00:00
|
|
|
|
|
|
|
// Return the weakest (least precise) common type.
|
2010-03-25 12:44:15 +00:00
|
|
|
static TypeInfo Combine(TypeInfo a, TypeInfo b) {
|
|
|
|
return TypeInfo(static_cast<Type>(a.type_ & b.type_));
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 15:29:41 +00:00
|
|
|
|
2011-02-03 15:36:44 +00:00
|
|
|
// Integer32 is an integer that can be represented as a signed
|
|
|
|
// 32-bit integer. It has to be
|
|
|
|
// in the range [-2^31, 2^31 - 1]. We also have to check for negative 0
|
2010-12-07 11:31:57 +00:00
|
|
|
// as it is not an Integer32.
|
2010-03-24 15:29:41 +00:00
|
|
|
static inline bool IsInt32Double(double value) {
|
2010-03-24 16:37:27 +00:00
|
|
|
const DoubleRepresentation minus_zero(-0.0);
|
|
|
|
DoubleRepresentation rep(value);
|
|
|
|
if (rep.bits == minus_zero.bits) return false;
|
2010-12-07 11:31:57 +00:00
|
|
|
if (value >= kMinInt && value <= kMaxInt &&
|
|
|
|
value == static_cast<int32_t>(value)) {
|
|
|
|
return true;
|
2010-03-24 15:29:41 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-26 11:34:00 +00:00
|
|
|
static TypeInfo TypeFromValue(Handle<Object> value);
|
2010-03-24 15:29:41 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool Equals(const TypeInfo& other) {
|
|
|
|
return type_ == other.type_;
|
|
|
|
}
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
inline bool IsUnknown() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return type_ == kUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsPrimitive() {
|
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kPrimitive) == kPrimitive);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsNumber() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kNumber) == kNumber);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsSmi() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kSmi) == kSmi);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsInteger32() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kInteger32) == kInteger32);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 15:29:41 +00:00
|
|
|
inline bool IsDouble() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kDouble) == kDouble);
|
2010-02-15 14:24:38 +00:00
|
|
|
}
|
2010-02-16 13:03:16 +00:00
|
|
|
|
2010-03-29 11:48:57 +00:00
|
|
|
inline bool IsString() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kString) == kString);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsNonPrimitive() {
|
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kNonPrimitive) == kNonPrimitive);
|
2010-03-29 11:48:57 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
inline bool IsUninitialized() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return type_ == kUninitialized;
|
2010-02-16 13:03:16 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
const char* ToString() {
|
|
|
|
switch (type_) {
|
2010-12-07 11:31:57 +00:00
|
|
|
case kUnknown: return "Unknown";
|
|
|
|
case kPrimitive: return "Primitive";
|
|
|
|
case kNumber: return "Number";
|
|
|
|
case kInteger32: return "Integer32";
|
|
|
|
case kSmi: return "Smi";
|
|
|
|
case kDouble: return "Double";
|
|
|
|
case kString: return "String";
|
|
|
|
case kNonPrimitive: return "Object";
|
|
|
|
case kUninitialized: return "Uninitialized";
|
2010-02-16 13:03:16 +00:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return "Unreachable code";
|
|
|
|
}
|
2010-03-05 23:54:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum Type {
|
2010-12-07 11:31:57 +00:00
|
|
|
kUnknown = 0, // 0000000
|
|
|
|
kPrimitive = 0x10, // 0010000
|
|
|
|
kNumber = 0x11, // 0010001
|
|
|
|
kInteger32 = 0x13, // 0010011
|
|
|
|
kSmi = 0x17, // 0010111
|
|
|
|
kDouble = 0x19, // 0011001
|
|
|
|
kString = 0x30, // 0110000
|
|
|
|
kNonPrimitive = 0x40, // 1000000
|
|
|
|
kUninitialized = 0x7f // 1111111
|
2010-03-05 23:54:13 +00:00
|
|
|
};
|
2010-03-25 12:44:15 +00:00
|
|
|
explicit inline TypeInfo(Type t) : type_(t) { }
|
2010-03-05 23:54:13 +00:00
|
|
|
|
|
|
|
Type type_;
|
2010-02-15 14:24:38 +00:00
|
|
|
};
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2011-01-18 16:54:48 +00:00
|
|
|
enum StringStubFeedback {
|
|
|
|
DEFAULT_STRING_STUB = 0,
|
|
|
|
STRING_INDEX_OUT_OF_BOUNDS = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Forward declarations.
|
|
|
|
class Assignment;
|
2011-04-28 17:49:55 +00:00
|
|
|
class UnaryOperation;
|
2010-12-07 11:31:57 +00:00
|
|
|
class BinaryOperation;
|
|
|
|
class Call;
|
|
|
|
class CompareOperation;
|
2011-04-29 09:21:18 +00:00
|
|
|
class CountOperation;
|
2010-12-07 11:31:57 +00:00
|
|
|
class CompilationInfo;
|
|
|
|
class Property;
|
|
|
|
class CaseClause;
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
class TypeFeedbackOracle BASE_EMBEDDED {
|
|
|
|
public:
|
2011-01-13 14:16:08 +00:00
|
|
|
TypeFeedbackOracle(Handle<Code> code, Handle<Context> global_context);
|
2010-03-24 12:34:27 +00:00
|
|
|
|
2011-06-16 06:37:49 +00:00
|
|
|
bool LoadIsMonomorphicNormal(Property* expr);
|
2011-06-20 10:19:00 +00:00
|
|
|
bool LoadIsMegamorphicWithTypeInfo(Property* expr);
|
2011-06-16 06:37:49 +00:00
|
|
|
bool StoreIsMonomorphicNormal(Expression* expr);
|
2011-06-20 10:19:00 +00:00
|
|
|
bool StoreIsMegamorphicWithTypeInfo(Expression* expr);
|
2010-12-07 11:31:57 +00:00
|
|
|
bool CallIsMonomorphic(Call* expr);
|
2010-03-24 12:34:27 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<Map> LoadMonomorphicReceiverType(Property* expr);
|
2011-04-07 09:51:25 +00:00
|
|
|
Handle<Map> StoreMonomorphicReceiverType(Expression* expr);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
ZoneMapList* LoadReceiverTypes(Property* expr, Handle<String> name);
|
|
|
|
ZoneMapList* StoreReceiverTypes(Assignment* expr, Handle<String> name);
|
2011-05-24 14:01:36 +00:00
|
|
|
ZoneMapList* CallReceiverTypes(Call* expr,
|
|
|
|
Handle<String> name,
|
|
|
|
CallKind call_kind);
|
2011-06-20 10:19:00 +00:00
|
|
|
void CollectKeyedReceiverTypes(unsigned ast_id,
|
|
|
|
ZoneMapList* types);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2011-01-13 14:16:08 +00:00
|
|
|
CheckType GetCallCheckType(Call* expr);
|
|
|
|
Handle<JSObject> GetPrototypeForPrimitiveCheck(CheckType check);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool LoadIsBuiltin(Property* expr, Builtins::Name id);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Get type information for arithmetic operations and compares.
|
2011-04-28 17:49:55 +00:00
|
|
|
TypeInfo UnaryType(UnaryOperation* expr);
|
2011-01-27 14:04:07 +00:00
|
|
|
TypeInfo BinaryType(BinaryOperation* expr);
|
|
|
|
TypeInfo CompareType(CompareOperation* expr);
|
2011-05-11 12:50:04 +00:00
|
|
|
bool IsSymbolCompare(CompareOperation* expr);
|
2010-12-07 11:31:57 +00:00
|
|
|
TypeInfo SwitchType(CaseClause* clause);
|
2011-04-29 09:21:18 +00:00
|
|
|
TypeInfo IncrementType(CountOperation* expr);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
private:
|
2011-04-27 15:02:59 +00:00
|
|
|
ZoneMapList* CollectReceiverTypes(unsigned ast_id,
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<String> name,
|
|
|
|
Code::Flags flags);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2011-04-27 15:02:59 +00:00
|
|
|
void SetInfo(unsigned ast_id, Object* target);
|
2011-03-30 15:31:16 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void PopulateMap(Handle<Code> code);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2011-04-27 15:02:59 +00:00
|
|
|
void CollectIds(Code* code,
|
|
|
|
List<int>* code_positions,
|
|
|
|
List<unsigned>* ast_ids);
|
2010-03-24 12:34:27 +00:00
|
|
|
|
2011-03-07 16:09:56 +00:00
|
|
|
// Returns an element from the backing store. Returns undefined if
|
|
|
|
// there is no information.
|
2011-04-27 15:02:59 +00:00
|
|
|
Handle<Object> GetInfo(unsigned ast_id);
|
2011-03-07 16:09:56 +00:00
|
|
|
|
2011-01-13 14:16:08 +00:00
|
|
|
Handle<Context> global_context_;
|
2011-03-07 16:09:56 +00:00
|
|
|
Handle<NumberDictionary> dictionary_;
|
2010-03-24 12:34:27 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
|
|
|
|
};
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-02-15 14:24:38 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
#endif // V8_TYPE_INFO_H_
|