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

Unified Diff: runtime/vm/intermediate_language.h

Issue 12330072: Ensure that compile time types for comparisons are recomputed once comparison are specialized. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « runtime/vm/il_printer.cc ('k') | runtime/vm/intermediate_language_arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language.h
diff --git a/runtime/vm/intermediate_language.h b/runtime/vm/intermediate_language.h
index d4d057193d20e751085d60c876f6de3068997fb4..8e1b84c19d11925bf48b8ec8efbf9378c0231d79 100644
--- a/runtime/vm/intermediate_language.h
+++ b/runtime/vm/intermediate_language.h
@@ -113,7 +113,7 @@ RECOGNIZED_LIST(DEFINE_ENUM_LIST)
// Values of CompileType form a lattice with a None type as a bottom and a
// nullable Dynamic type as a top element. Method Union provides a join
// operation for the lattice.
-class CompileType : public ZoneAllocated {
+class CompileType {
srdjan 2013/02/22 21:01:41 This should be subclass of ValueObject?
Vyacheslav Egorov (Google) 2013/02/22 22:22:33 I can make it, but our ValueObject is a strange be
public:
static const bool kNullable = true;
static const bool kNonNullable = false;
@@ -150,34 +150,34 @@ class CompileType : public ZoneAllocated {
// Create a new CompileType representing given combination of class id and
// abstract type. The pair is assumed to be coherent.
- static CompileType* New(intptr_t cid, const AbstractType& type);
+ static CompileType Create(intptr_t cid, const AbstractType& type);
// Create a new CompileType representing given abstract type. By default
// values as assumed to be nullable.
- static CompileType* FromAbstractType(const AbstractType& type,
+ static CompileType FromAbstractType(const AbstractType& type,
bool is_nullable = kNullable);
// Create a new CompileType representing an value with the given class id.
// Resulting CompileType is nullable only if cid is kDynamicCid or kNullCid.
- static CompileType* FromCid(intptr_t cid);
+ static CompileType FromCid(intptr_t cid);
// Create None CompileType. It is the bottom of the lattice and is used to
// represent type of the phi that was not yet inferred.
- static CompileType* None() {
- return new CompileType(true, kIllegalCid, NULL);
+ static CompileType None() {
+ return CompileType(true, kIllegalCid, NULL);
}
// Create Dynamic CompileType. It is the top of the lattice and is used to
// represent unknown type.
- static CompileType* Dynamic();
+ static CompileType Dynamic();
- static CompileType* Null();
+ static CompileType Null();
// Create non-nullable Bool type.
- static CompileType* Bool();
+ static CompileType Bool();
// Create non-nullable Int type.
- static CompileType* Int();
+ static CompileType Int();
// Perform a join operation over the type lattice.
void Union(CompileType* other);
@@ -189,13 +189,6 @@ class CompileType : public ZoneAllocated {
(ToAbstractType()->Equals(*other->ToAbstractType()));
}
- // Replaces this type with other.
- void ReplaceWith(CompileType* other) {
- is_nullable_ = other->is_nullable_;
- cid_ = other->cid_;
- type_ = other->type_;
- }
-
bool IsNone() const {
return (cid_ == kIllegalCid) && (type_ == NULL);
}
@@ -217,6 +210,21 @@ class CompileType : public ZoneAllocated {
};
+// Zone allocated wrapper for the CompileType value.
+class ZoneCompileType : public ZoneAllocated {
+ public:
+ static CompileType* Wrap(const CompileType& type) {
+ ZoneCompileType* zone_type = new ZoneCompileType(type);
+ return &zone_type->type_;
+ }
+
+ private:
+ explicit ZoneCompileType(const CompileType& type) : type_(type) { }
+
+ CompileType type_;
+};
+
+
class Value : public ZoneAllocated {
public:
// A forward iterator that allows removing the current value from the
@@ -1245,10 +1253,14 @@ class Definition : public Instruction {
return type_;
}
- // Compute initial compile type for this definition. It is safe to use this
+ virtual CompileType* ComputeInitialType() const {
+ return ZoneCompileType::Wrap(ComputeType());
+ }
+
+ // Compute compile type for this definition. It is safe to use this
// approximation even before type propagator was run (e.g. during graph
// building).
- virtual CompileType* ComputeInitialType() const {
+ virtual CompileType ComputeType() const {
return CompileType::Dynamic();
}
@@ -1257,6 +1269,20 @@ class Definition : public Instruction {
return false;
}
+ bool UpdateType(CompileType new_type) {
+ if (type_ == NULL) {
+ type_ = ZoneCompileType::Wrap(new_type);
+ return true;
+ }
+
+ if (type_->IsNone() || !type_->IsEqualTo(&new_type)) {
+ *type_ = new_type;
+ return true;
+ }
+
+ return false;
+ }
+
bool HasUses() const {
return (input_use_list_ != NULL) || (env_use_list_ != NULL);
}
@@ -1356,7 +1382,7 @@ class PhiInstr : public Definition {
virtual BlockEntryInstr* GetBlock() const { return block(); }
JoinEntryInstr* block() const { return block_; }
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual bool RecomputeType();
virtual intptr_t ArgumentCount() const { return 0; }
@@ -1453,7 +1479,7 @@ class ParameterInstr : public Definition {
virtual void PrintOperandsTo(BufferFormatter* f) const;
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
private:
const intptr_t index_;
@@ -1484,7 +1510,7 @@ class PushArgumentInstr : public Definition {
virtual intptr_t ArgumentCount() const { return 0; }
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
Value* value() const { return value_; }
@@ -1928,7 +1954,7 @@ class ConstraintInstr : public TemplateDefinition<2> {
return (inputs_[1] == NULL) ? 1 : 2;
}
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual bool CanDeoptimize() const { return false; }
@@ -1975,7 +2001,7 @@ class ConstantInstr : public TemplateDefinition<0> {
: value_(value) { }
DECLARE_INSTRUCTION(Constant)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
const Object& value() const { return value_; }
@@ -2062,7 +2088,7 @@ class AssertBooleanInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(AssertBoolean)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
intptr_t token_pos() const { return token_pos_; }
Value* value() const { return inputs_[0]; }
@@ -2095,7 +2121,7 @@ class ArgumentDefinitionTestInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(ArgumentDefinitionTest)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
intptr_t token_pos() const { return ast_node_.token_pos(); }
intptr_t formal_parameter_index() const {
@@ -2127,7 +2153,7 @@ class CurrentContextInstr : public TemplateDefinition<0> {
CurrentContextInstr() { }
DECLARE_INSTRUCTION(CurrentContext)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual bool CanDeoptimize() const { return false; }
@@ -2364,7 +2390,7 @@ class StrictCompareInstr : public ComparisonInstr {
StrictCompareInstr(Token::Kind kind, Value* left, Value* right);
DECLARE_INSTRUCTION(StrictCompare)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual void PrintOperandsTo(BufferFormatter* f) const;
@@ -2407,7 +2433,8 @@ class EqualityCompareInstr : public ComparisonInstr {
}
DECLARE_INSTRUCTION(EqualityCompare)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
+ virtual bool RecomputeType();
const ICData* ic_data() const { return ic_data_; }
bool HasICData() const {
@@ -2476,7 +2503,8 @@ class RelationalOpInstr : public ComparisonInstr {
}
DECLARE_INSTRUCTION(RelationalOp)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
+ virtual bool RecomputeType();
const ICData* ic_data() const { return ic_data_; }
bool HasICData() const {
@@ -2549,7 +2577,7 @@ class StaticCallInstr : public TemplateDefinition<0> {
}
DECLARE_INSTRUCTION(StaticCall)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
// Accessors forwarded to the AST node.
const Function& function() const { return function_; }
@@ -2595,7 +2623,7 @@ class LoadLocalInstr : public TemplateDefinition<0> {
context_level_(context_level) { }
DECLARE_INSTRUCTION(LoadLocal)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
const LocalVariable& local() const { return local_; }
intptr_t context_level() const { return context_level_; }
@@ -2730,7 +2758,7 @@ class LoadStaticFieldInstr : public TemplateDefinition<0> {
explicit LoadStaticFieldInstr(const Field& field) : field_(field) {}
DECLARE_INSTRUCTION(LoadStaticField);
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
const Field& field() const { return field_; }
@@ -2794,7 +2822,7 @@ class LoadIndexedInstr : public TemplateDefinition<2> {
}
DECLARE_INSTRUCTION(LoadIndexed)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
Value* array() const { return inputs_[0]; }
Value* index() const { return inputs_[1]; }
@@ -2835,7 +2863,7 @@ class StringFromCharCodeInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(StringFromCharCode)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
Value* char_code() const { return inputs_[0]; }
@@ -2914,7 +2942,7 @@ class BooleanNegateInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(BooleanNegate)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
Value* value() const { return inputs_[0]; }
@@ -2948,7 +2976,7 @@ class InstanceOfInstr : public TemplateDefinition<3> {
}
DECLARE_INSTRUCTION(InstanceOf)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
Value* value() const { return inputs_[0]; }
Value* instantiator() const { return inputs_[1]; }
@@ -2988,7 +3016,7 @@ class AllocateObjectInstr : public TemplateDefinition<0> {
}
DECLARE_INSTRUCTION(AllocateObject)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual intptr_t ArgumentCount() const { return arguments_->length(); }
virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const {
@@ -3062,7 +3090,7 @@ class CreateArrayInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(CreateArray)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
intptr_t num_elements() const { return num_elements_; }
@@ -3095,7 +3123,7 @@ class CreateClosureInstr : public TemplateDefinition<0> {
token_pos_(token_pos) { }
DECLARE_INSTRUCTION(CreateClosure)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
intptr_t token_pos() const { return token_pos_; }
const Function& function() const { return function_; }
@@ -3137,7 +3165,7 @@ class LoadFieldInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(LoadField)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
Value* value() const { return inputs_[0]; }
intptr_t offset_in_bytes() const { return offset_in_bytes_; }
@@ -3323,7 +3351,7 @@ class AllocateContextInstr : public TemplateDefinition<0> {
num_context_variables_(num_context_variables) {}
DECLARE_INSTRUCTION(AllocateContext);
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
intptr_t token_pos() const { return token_pos_; }
intptr_t num_context_variables() const { return num_context_variables_; }
@@ -3376,7 +3404,7 @@ class CloneContextInstr : public TemplateDefinition<1> {
Value* context_value() const { return inputs_[0]; }
DECLARE_INSTRUCTION(CloneContext)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual bool CanDeoptimize() const { return true; }
@@ -3476,7 +3504,7 @@ class BoxDoubleInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(BoxDouble)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
private:
const intptr_t token_pos_;
@@ -3507,7 +3535,7 @@ class BoxIntegerInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(BoxInteger)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
private:
DISALLOW_COPY_AND_ASSIGN(BoxIntegerInstr);
@@ -3539,7 +3567,7 @@ class UnboxDoubleInstr : public TemplateDefinition<1> {
virtual bool AttributesEqual(Instruction* other) const { return true; }
DECLARE_INSTRUCTION(UnboxDouble)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
private:
DISALLOW_COPY_AND_ASSIGN(UnboxDoubleInstr);
@@ -3563,7 +3591,7 @@ class UnboxIntegerInstr : public TemplateDefinition<1> {
virtual bool HasSideEffect() const { return false; }
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual Representation representation() const {
return kUnboxedMint;
@@ -3614,7 +3642,7 @@ class MathSqrtInstr : public TemplateDefinition<1> {
}
DECLARE_INSTRUCTION(MathSqrt)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
private:
DISALLOW_COPY_AND_ASSIGN(MathSqrtInstr);
@@ -3668,7 +3696,7 @@ class BinaryDoubleOpInstr : public TemplateDefinition<2> {
}
DECLARE_INSTRUCTION(BinaryDoubleOp)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual Definition* Canonicalize(FlowGraphOptimizer* optimizer);
@@ -3712,7 +3740,7 @@ class BinaryMintOpInstr : public TemplateDefinition<2> {
return op_kind() == other->AsBinaryMintOp()->op_kind();
}
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual Representation representation() const {
return kUnboxedMint;
@@ -3772,7 +3800,7 @@ class ShiftMintOpInstr : public TemplateDefinition<2> {
return op_kind() == other->AsShiftMintOp()->op_kind();
}
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual Representation representation() const {
return kUnboxedMint;
@@ -3826,7 +3854,7 @@ class UnaryMintOpInstr : public TemplateDefinition<1> {
return op_kind() == other->AsUnaryMintOp()->op_kind();
}
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual Representation representation() const {
return kUnboxedMint;
@@ -3881,7 +3909,7 @@ class BinarySmiOpInstr : public TemplateDefinition<2> {
DECLARE_INSTRUCTION(BinarySmiOp)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual bool CanDeoptimize() const;
@@ -3932,7 +3960,7 @@ class UnarySmiOpInstr : public TemplateDefinition<1> {
virtual void PrintOperandsTo(BufferFormatter* f) const;
DECLARE_INSTRUCTION(UnarySmiOp)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual bool CanDeoptimize() const { return op_kind() == Token::kNEGATE; }
@@ -3975,7 +4003,7 @@ class SmiToDoubleInstr : public TemplateDefinition<0> {
InstanceCallInstr* instance_call() const { return instance_call_; }
DECLARE_INSTRUCTION(SmiToDouble)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual intptr_t ArgumentCount() const { return 1; }
@@ -4002,7 +4030,7 @@ class DoubleToIntegerInstr : public TemplateDefinition<1> {
InstanceCallInstr* instance_call() const { return instance_call_; }
DECLARE_INSTRUCTION(DoubleToInteger)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual intptr_t ArgumentCount() const { return 1; }
@@ -4030,7 +4058,7 @@ class DoubleToSmiInstr : public TemplateDefinition<1> {
Value* value() const { return inputs_[0]; }
DECLARE_INSTRUCTION(DoubleToSmi)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual bool CanDeoptimize() const { return true; }
@@ -4064,7 +4092,7 @@ class DoubleToDoubleInstr : public TemplateDefinition<1> {
MethodRecognizer::Kind recognized_kind() const { return recognized_kind_; }
DECLARE_INSTRUCTION(DoubleToDouble)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual bool CanDeoptimize() const { return false; }
@@ -4105,7 +4133,7 @@ class InvokeMathCFunctionInstr : public Definition {
MethodRecognizer::Kind recognized_kind() const { return recognized_kind_; }
DECLARE_INSTRUCTION(InvokeMathCFunction)
- virtual CompileType* ComputeInitialType() const;
+ virtual CompileType ComputeType() const;
virtual void PrintOperandsTo(BufferFormatter* f) const;
virtual bool CanDeoptimize() const { return false; }
« no previous file with comments | « runtime/vm/il_printer.cc ('k') | runtime/vm/intermediate_language_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698