Don't explicitly pass requested representations to constants; implement ConstantS

R=jkummerow@chromium.org

Review URL: https://chromiumcodereview.appspot.com/15932011

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14874 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
verwaest@chromium.org 2013-05-29 10:47:55 +00:00
parent 9b6aa9568d
commit 7d32e7451f
14 changed files with 104 additions and 91 deletions

View File

@ -2053,11 +2053,13 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation();
if (r.IsInteger32()) {
if (r.IsSmi()) {
return DefineAsRegister(new(zone()) LConstantS);
} else if (r.IsInteger32()) {
return DefineAsRegister(new(zone()) LConstantI);
} else if (r.IsDouble()) {
return DefineAsRegister(new(zone()) LConstantD);
} else if (r.IsSmiOrTagged()) {
} else if (r.IsTagged()) {
return DefineAsRegister(new(zone()) LConstantT);
} else {
UNREACHABLE();

View File

@ -87,6 +87,7 @@ class LCodeGen;
V(CmpT) \
V(ConstantD) \
V(ConstantI) \
V(ConstantS) \
V(ConstantT) \
V(Context) \
V(DebugBreak) \
@ -1206,6 +1207,15 @@ class LConstantI: public LTemplateInstruction<1, 0, 0> {
};
class LConstantS: public LTemplateInstruction<1, 0, 0> {
public:
DECLARE_CONCRETE_INSTRUCTION(ConstantS, "constant-s")
DECLARE_HYDROGEN_ACCESSOR(Constant)
Smi* value() const { return Smi::FromInt(hydrogen()->Integer32Value()); }
};
class LConstantD: public LTemplateInstruction<1, 0, 0> {
public:
DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")

View File

@ -1900,7 +1900,11 @@ void LCodeGen::DoRSubI(LRSubI* instr) {
void LCodeGen::DoConstantI(LConstantI* instr) {
ASSERT(instr->result()->IsRegister());
__ mov(ToRegister(instr->result()), Operand(instr->value()));
}
void LCodeGen::DoConstantS(LConstantS* instr) {
__ mov(ToRegister(instr->result()), Operand(instr->value()));
}

View File

@ -564,16 +564,13 @@ HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>::
new(zone()) HAccessArgumentsAt(elements, constant_one, constant_zero));
HConstant* max_alloc_length =
new(zone()) HConstant(JSObject::kInitialMaxFastElementArray,
Representation::Tagged());
new(zone()) HConstant(JSObject::kInitialMaxFastElementArray);
AddInstruction(max_alloc_length);
const int initial_capacity = JSArray::kPreallocatedArrayElements;
HConstant* initial_capacity_node =
new(zone()) HConstant(initial_capacity, Representation::Tagged());
HConstant* initial_capacity_node = new(zone()) HConstant(initial_capacity);
AddInstruction(initial_capacity_node);
HBoundsCheck* checked_arg = AddBoundsCheck(
argument, max_alloc_length, ALLOW_SMI_KEY);
HBoundsCheck* checked_arg = AddBoundsCheck(argument, max_alloc_length);
IfBuilder if_builder(this);
if_builder.IfCompare(checked_arg, constant_zero, Token::EQ);
if_builder.Then();

View File

@ -1142,17 +1142,16 @@ void HBoundsCheck::PrintDataTo(StringStream* stream) {
void HBoundsCheck::InferRepresentation(HInferRepresentation* h_infer) {
ASSERT(CheckFlag(kFlexibleRepresentation));
Representation r;
HValue* actual_length = length()->ActualValue();
HValue* actual_index = index()->ActualValue();
if (key_mode_ == DONT_ALLOW_SMI_KEY ||
!actual_length->representation().IsSmiOrTagged()) {
HValue* actual_length = length()->ActualValue();
Representation index_rep = actual_index->representation();
if (!actual_length->representation().IsSmiOrTagged()) {
r = Representation::Integer32();
} else if (actual_index->representation().IsSmiOrTagged() ||
(actual_index->IsConstant() &&
HConstant::cast(actual_index)->HasSmiValue())) {
// If the index is smi, or a constant that holds a Smi, allow the length to
// be smi, since it is usually already smi from loading it out of the length
// field of a JSArray. This allows for direct comparison without untagging.
} else if ((index_rep.IsTagged() && actual_index->type().IsSmi()) ||
index_rep.IsSmi()) {
// If the index is smi, allow the length to be smi, since it is usually
// already smi from loading it out of the length field of a JSArray. This
// allows for direct comparison without untagging.
r = Representation::Smi();
} else {
r = Representation::Integer32();
@ -3250,7 +3249,7 @@ HInstruction* HStringLength::New(Zone* zone, HValue* string) {
if (FLAG_fold_constants && string->IsConstant()) {
HConstant* c_string = HConstant::cast(string);
if (c_string->HasStringValue()) {
return H_CONSTANT_INT32(c_string->StringValue()->length());
return new(zone) HConstant(c_string->StringValue()->length());
}
}
return new(zone) HStringLength(string);

View File

@ -3124,11 +3124,11 @@ class HConstant: public HTemplateInstruction<0> {
public:
HConstant(Handle<Object> handle, Representation r);
HConstant(int32_t value,
Representation r,
Representation r = Representation::None(),
bool is_not_in_new_space = true,
Handle<Object> optional_handle = Handle<Object>::null());
HConstant(double value,
Representation r,
Representation r = Representation::None(),
bool is_not_in_new_space = true,
Handle<Object> optional_handle = Handle<Object>::null());
HConstant(Handle<Object> handle,
@ -3527,12 +3527,6 @@ class HAccessArgumentsAt: public HTemplateInstruction<3> {
};
enum BoundsCheckKeyMode {
DONT_ALLOW_SMI_KEY,
ALLOW_SMI_KEY
};
class HBoundsCheckBaseIndexInformation;
@ -3542,10 +3536,8 @@ class HBoundsCheck: public HTemplateInstruction<2> {
// HGraphBuilder::AddBoundsCheck() helper.
// However when building stubs, where we know that the arguments are Int32,
// it makes sense to invoke this constructor directly.
HBoundsCheck(HValue* index,
HValue* length,
BoundsCheckKeyMode key_mode = DONT_ALLOW_SMI_KEY)
: key_mode_(key_mode), skip_check_(false),
HBoundsCheck(HValue* index, HValue* length)
: skip_check_(false),
base_(NULL), offset_(0), scale_(0),
responsibility_direction_(DIRECTION_NONE) {
SetOperandAt(0, index);
@ -3618,7 +3610,6 @@ class HBoundsCheck: public HTemplateInstruction<2> {
virtual bool DataEquals(HValue* other) { return true; }
virtual void TryGuaranteeRangeChanging(RangeEvaluationContext* context);
BoundsCheckKeyMode key_mode_;
bool skip_check_;
HValue* base_;
int offset_;

View File

@ -593,11 +593,10 @@ void HGraph::Verify(bool do_full_verify) const {
#endif
HConstant* HGraph::GetConstantInt32(SetOncePointer<HConstant>* pointer,
int32_t value) {
HConstant* HGraph::GetConstant(SetOncePointer<HConstant>* pointer,
int32_t value) {
if (!pointer->is_set()) {
HConstant* constant =
new(zone()) HConstant(value, Representation::Integer32());
HConstant* constant = new(zone()) HConstant(value);
constant->InsertAfter(GetConstantUndefined());
pointer->set(constant);
}
@ -606,17 +605,17 @@ HConstant* HGraph::GetConstantInt32(SetOncePointer<HConstant>* pointer,
HConstant* HGraph::GetConstant0() {
return GetConstantInt32(&constant_0_, 0);
return GetConstant(&constant_0_, 0);
}
HConstant* HGraph::GetConstant1() {
return GetConstantInt32(&constant_1_, 1);
return GetConstant(&constant_1_, 1);
}
HConstant* HGraph::GetConstantMinus1() {
return GetConstantInt32(&constant_minus1_, -1);
return GetConstant(&constant_minus1_, -1);
}
@ -648,7 +647,7 @@ DEFINE_GET_CONSTANT(Null, null, HType::Tagged(), false)
HConstant* HGraph::GetInvalidContext() {
return GetConstantInt32(&constant_invalid_context_, 0xFFFFC0C7);
return GetConstant(&constant_invalid_context_, 0xFFFFC0C7);
}
@ -979,11 +978,8 @@ void HGraphBuilder::AddSimulate(BailoutId id,
}
HBoundsCheck* HGraphBuilder::AddBoundsCheck(HValue* index,
HValue* length,
BoundsCheckKeyMode key_mode) {
HBoundsCheck* result = new(graph()->zone()) HBoundsCheck(
index, length, key_mode);
HBoundsCheck* HGraphBuilder::AddBoundsCheck(HValue* index, HValue* length) {
HBoundsCheck* result = new(graph()->zone()) HBoundsCheck(index, length);
AddInstruction(result);
return result;
}
@ -1169,7 +1165,7 @@ HValue* HGraphBuilder::BuildCheckForCapacityGrow(HValue* object,
length_checker.Else();
AddBoundsCheck(key, length, ALLOW_SMI_KEY);
AddBoundsCheck(key, length);
environment()->Push(elements);
length_checker.End();
@ -1274,7 +1270,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
return result;
} else {
ASSERT(store_mode == STANDARD_STORE);
checked_key = AddBoundsCheck(key, length, ALLOW_SMI_KEY);
checked_key = AddBoundsCheck(key, length);
HLoadExternalArrayPointer* external_elements =
new(zone) HLoadExternalArrayPointer(elements);
AddInstruction(external_elements);
@ -1302,7 +1298,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
length, key, is_js_array);
checked_key = key;
} else {
checked_key = AddBoundsCheck(key, length, ALLOW_SMI_KEY);
checked_key = AddBoundsCheck(key, length);
if (is_store && (fast_elements || fast_smi_only_elements)) {
if (store_mode == STORE_NO_TRANSITION_HANDLE_COW) {
@ -1470,13 +1466,11 @@ void HGraphBuilder::BuildNewSpaceArrayCheck(HValue* length, ElementsKind kind) {
: kPointerSize;
int max_size = heap->MaxRegularSpaceAllocationSize() / element_size;
max_size -= JSArray::kSize / element_size;
HConstant* max_size_constant =
new(zone) HConstant(max_size, Representation::Integer32());
HConstant* max_size_constant = new(zone) HConstant(max_size);
AddInstruction(max_size_constant);
// Since we're forcing Integer32 representation for this HBoundsCheck,
// there's no need to Smi-check the index.
AddInstruction(new(zone) HBoundsCheck(
length, max_size_constant, DONT_ALLOW_SMI_KEY));
AddInstruction(new(zone) HBoundsCheck(length, max_size_constant));
}
@ -1544,8 +1538,7 @@ void HGraphBuilder::BuildFillElementsWithHole(HValue* context,
if (unfold_loop) {
for (int i = 0; i < initial_capacity; i++) {
HInstruction* key = AddInstruction(new(zone)
HConstant(i, Representation::Integer32()));
HInstruction* key = AddInstruction(new(zone) HConstant(i));
AddInstruction(new(zone) HStoreKeyed(elements, key, hole, elements_kind));
}
} else {
@ -1668,8 +1661,7 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context,
// copying loops with constant length up to a given boundary and use this
// helper here instead.
for (int i = 0; i < length; i++) {
HValue* key_constant =
AddInstruction(new(zone) HConstant(i, Representation::Integer32()));
HValue* key_constant = AddInstruction(new(zone) HConstant(i));
HInstruction* value =
AddInstruction(new(zone) HLoadKeyed(boilerplate_elements,
key_constant,
@ -5347,8 +5339,7 @@ void HOptimizedGraphBuilder::VisitForInStatement(ForInStatement* stmt) {
HInstruction* enum_length = AddInstruction(new(zone()) HMapEnumLength(map));
HInstruction* start_index = AddInstruction(new(zone()) HConstant(
Handle<Object>(Smi::FromInt(0), isolate()), Representation::Integer32()));
HInstruction* start_index = AddInstruction(new(zone()) HConstant(0));
Push(map);
Push(array);
@ -6085,9 +6076,7 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
elements = AddLoadElements(literal);
HValue* key = AddInstruction(
new(zone()) HConstant(Handle<Object>(Smi::FromInt(i), isolate()),
Representation::Integer32()));
HValue* key = AddInstruction(new(zone()) HConstant(i));
switch (boilerplate_elements_kind) {
case FAST_SMI_ELEMENTS:
@ -7282,7 +7271,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
typecheck, Representation::Smi());
length->set_type(HType::Smi());
checked_key = AddBoundsCheck(key, length, ALLOW_SMI_KEY);
checked_key = AddBoundsCheck(key, length);
access = AddInstruction(BuildFastElementAccess(
elements, checked_key, val, elements_kind_branch,
elements_kind, is_store, NEVER_RETURN_HOLE, STANDARD_STORE));
@ -7300,7 +7289,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
set_current_block(if_fastobject);
length = AddInstruction(new(zone()) HFixedArrayBaseLength(elements));
checked_key = AddBoundsCheck(key, length, ALLOW_SMI_KEY);
checked_key = AddBoundsCheck(key, length);
access = AddInstruction(BuildFastElementAccess(
elements, checked_key, val, elements_kind_branch,
elements_kind, is_store, NEVER_RETURN_HOLE, STANDARD_STORE));
@ -7438,9 +7427,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) {
// Number of arguments without receiver.
int argument_count = environment()->
arguments_environment()->parameter_count() - 1;
result = new(zone()) HConstant(
Handle<Object>(Smi::FromInt(argument_count), isolate()),
Representation::Integer32());
result = new(zone()) HConstant(argument_count);
}
} else {
Push(graph()->GetArgumentsObject());
@ -7463,8 +7450,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) {
int argument_count = environment()->
arguments_environment()->parameter_count() - 1;
HInstruction* length = AddInstruction(new(zone()) HConstant(
Handle<Object>(Smi::FromInt(argument_count), isolate()),
Representation::Integer32()));
argument_count));
HInstruction* checked_key = AddBoundsCheck(key, length);
result = new(zone()) HAccessArgumentsAt(elements, length, checked_key);
}
@ -8334,10 +8320,8 @@ bool HOptimizedGraphBuilder::TryInlineBuiltinMethodCall(
result =
HUnaryMathOperation::New(zone(), context, left, kMathPowHalf);
} else if (exponent == -0.5) {
HConstant* double_one =
new(zone()) HConstant(Handle<Object>(Smi::FromInt(1),
isolate()),
Representation::Double());
HConstant* double_one = new(zone()) HConstant(
1, Representation::Double());
AddInstruction(double_one);
HInstruction* sqrt =
HUnaryMathOperation::New(zone(), context, left, kMathPowHalf);
@ -9291,7 +9275,7 @@ HInstruction* HOptimizedGraphBuilder::BuildStringCharCodeAt(
if (i < 0 || i >= s->length()) {
return new(zone()) HConstant(OS::nan_value(), Representation::Double());
}
return new(zone()) HConstant(s->Get(i), Representation::Integer32());
return new(zone()) HConstant(s->Get(i));
}
}
BuildCheckNonSmi(string);
@ -10093,8 +10077,7 @@ void HOptimizedGraphBuilder::BuildEmitElements(
int elements_length = elements->length();
HValue* object_elements_length =
AddInstruction(new(zone) HConstant(
elements_length, Representation::Integer32()));
AddInstruction(new(zone) HConstant(elements_length));
BuildInitializeElementsHeader(object_elements, kind, object_elements_length);
@ -10119,8 +10102,7 @@ void HOptimizedGraphBuilder::BuildEmitFixedDoubleArray(
elements, Representation::Tagged()));
int elements_length = elements->length();
for (int i = 0; i < elements_length; i++) {
HValue* key_constant =
AddInstruction(new(zone) HConstant(i, Representation::Integer32()));
HValue* key_constant = AddInstruction(new(zone) HConstant(i));
HInstruction* value_instruction =
AddInstruction(new(zone) HLoadKeyed(
boilerplate_elements, key_constant, NULL, kind, ALLOW_RETURN_HOLE));
@ -10147,8 +10129,7 @@ void HOptimizedGraphBuilder::BuildEmitFixedArray(
Handle<FixedArray>::cast(original_elements);
for (int i = 0; i < elements_length; i++) {
Handle<Object> value(fast_elements->get(i), isolate());
HValue* key_constant =
AddInstruction(new(zone) HConstant(i, Representation::Integer32()));
HValue* key_constant = AddInstruction(new(zone) HConstant(i));
if (value->IsJSObject()) {
Handle<JSObject> value_object = Handle<JSObject>::cast(value);
Handle<JSObject> original_value_object = Handle<JSObject>::cast(

View File

@ -400,8 +400,8 @@ class HGraph: public ZoneObject {
}
private:
HConstant* GetConstantInt32(SetOncePointer<HConstant>* pointer,
int32_t integer_value);
HConstant* GetConstant(SetOncePointer<HConstant>* pointer,
int32_t integer_value);
void MarkLive(HValue* ref, HValue* instr, ZoneList<HValue*>* worklist);
void MarkLiveInstructions();
@ -952,10 +952,7 @@ class HGraphBuilder {
HInstruction* AddInstruction(HInstruction* instr);
void AddSimulate(BailoutId id,
RemovableSimulate removable = FIXED_SIMULATE);
HBoundsCheck* AddBoundsCheck(
HValue* index,
HValue* length,
BoundsCheckKeyMode key_mode = DONT_ALLOW_SMI_KEY);
HBoundsCheck* AddBoundsCheck(HValue* index, HValue* length);
HReturn* AddReturn(HValue* value);

View File

@ -1751,7 +1751,11 @@ void LCodeGen::DoSubI(LSubI* instr) {
void LCodeGen::DoConstantI(LConstantI* instr) {
ASSERT(instr->result()->IsRegister());
__ Set(ToRegister(instr->result()), Immediate(instr->value()));
}
void LCodeGen::DoConstantS(LConstantS* instr) {
__ Set(ToRegister(instr->result()), Immediate(instr->value()));
}

View File

@ -2108,7 +2108,9 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation();
if (r.IsInteger32()) {
if (r.IsSmi()) {
return DefineAsRegister(new(zone()) LConstantS);
} else if (r.IsInteger32()) {
return DefineAsRegister(new(zone()) LConstantI);
} else if (r.IsDouble()) {
double value = instr->DoubleValue();
@ -2119,7 +2121,7 @@ LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
} else {
return DefineX87TOS(new(zone()) LConstantD(NULL));
}
} else if (r.IsSmiOrTagged()) {
} else if (r.IsTagged()) {
return DefineAsRegister(new(zone()) LConstantT);
} else {
UNREACHABLE();

View File

@ -82,6 +82,7 @@ class LCodeGen;
V(CmpConstantEqAndBranch) \
V(ConstantD) \
V(ConstantI) \
V(ConstantS) \
V(ConstantT) \
V(Context) \
V(DebugBreak) \
@ -1152,6 +1153,15 @@ class LConstantI: public LTemplateInstruction<1, 0, 0> {
};
class LConstantS: public LTemplateInstruction<1, 0, 0> {
public:
DECLARE_CONCRETE_INSTRUCTION(ConstantS, "constant-s")
DECLARE_HYDROGEN_ACCESSOR(Constant)
Smi* value() const { return Smi::FromInt(hydrogen()->Integer32Value()); }
};
class LConstantD: public LTemplateInstruction<1, 0, 1> {
public:
explicit LConstantD(LOperand* temp) {

View File

@ -1560,11 +1560,15 @@ void LCodeGen::DoSubI(LSubI* instr) {
void LCodeGen::DoConstantI(LConstantI* instr) {
ASSERT(instr->result()->IsRegister());
__ Set(ToRegister(instr->result()), instr->value());
}
void LCodeGen::DoConstantS(LConstantS* instr) {
__ Move(ToRegister(instr->result()), instr->value());
}
void LCodeGen::DoConstantD(LConstantD* instr) {
ASSERT(instr->result()->IsDoubleRegister());
XMMRegister res = ToDoubleRegister(instr->result());

View File

@ -1969,12 +1969,14 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation();
if (r.IsInteger32()) {
if (r.IsSmi()) {
return DefineAsRegister(new(zone()) LConstantS);
} else if (r.IsInteger32()) {
return DefineAsRegister(new(zone()) LConstantI);
} else if (r.IsDouble()) {
LOperand* temp = TempRegister();
return DefineAsRegister(new(zone()) LConstantD(temp));
} else if (r.IsSmiOrTagged()) {
} else if (r.IsTagged()) {
return DefineAsRegister(new(zone()) LConstantT);
} else {
UNREACHABLE();

View File

@ -87,6 +87,7 @@ class LCodeGen;
V(CmpT) \
V(ConstantD) \
V(ConstantI) \
V(ConstantS) \
V(ConstantT) \
V(Context) \
V(DebugBreak) \
@ -1136,6 +1137,15 @@ class LConstantI: public LTemplateInstruction<1, 0, 0> {
};
class LConstantS: public LTemplateInstruction<1, 0, 0> {
public:
DECLARE_CONCRETE_INSTRUCTION(ConstantS, "constant-s")
DECLARE_HYDROGEN_ACCESSOR(Constant)
Smi* value() const { return Smi::FromInt(hydrogen()->Integer32Value()); }
};
class LConstantD: public LTemplateInstruction<1, 0, 1> {
public:
explicit LConstantD(LOperand* temp) {