bool HValue::IsInteger32Constant() {
- HValue* value_to_check = IsForceRepresentation()
- ? HForceRepresentation::cast(this)->value()
- : this;
- return value_to_check->IsConstant() &&
- HConstant::cast(value_to_check)->HasInteger32Value();
+ return IsConstant() && HConstant::cast(this)->HasInteger32Value();
}
int32_t HValue::GetInteger32Constant() {
- HValue* constant_value = IsForceRepresentation()
- ? HForceRepresentation::cast(this)->value()
- : this;
- return HConstant::cast(constant_value)->Integer32Value();
+ return HConstant::cast(this)->Integer32Value();
}
}
+HInstruction* HForceRepresentation::New(Zone* zone, HValue* context,
+ HValue* value, Representation required_representation) {
+ if (FLAG_fold_constants && value->IsConstant()) {
+ HConstant* c = HConstant::cast(value);
+ if (c->HasNumberValue()) {
+ double double_res = c->DoubleValue();
+ if (TypeInfo::IsInt32Double(double_res)) {
+ return HConstant::New(zone, context,
+ static_cast<int32_t>(double_res),
+ required_representation);
+ }
+ }
+ }
+ return new(zone) HForceRepresentation(value, required_representation);
+}
+
+
void HForceRepresentation::PrintDataTo(StringStream* stream) {
stream->Add("%s ", representation().Mnemonic());
value()->PrintNameTo(stream);
// deopt, leaving the backing store in an invalid state.
if (is_store && IsFastSmiElementsKind(elements_kind) &&
!val->type().IsSmi()) {
- val = Add<HForceRepresentation>(val, Representation::Smi());
+ val = AddUncasted<HForceRepresentation>(val, Representation::Smi());
}
if (IsGrowStoreMode(store_mode)) {
HValue* capacity) {
// The HForceRepresentation is to prevent possible deopt on int-smi
// conversion after allocation but before the new object fields are set.
- capacity = Add<HForceRepresentation>(capacity, Representation::Smi());
+ capacity = AddUncasted<HForceRepresentation>(capacity, Representation::Smi());
HValue* new_elements = BuildAllocateElements(kind, capacity);
BuildInitializeElementsHeader(new_elements, kind, capacity);
return new_elements;
// These HForceRepresentations are because we store these as fields in the
// objects we construct, and an int32-to-smi HChange could deopt. Accept
// the deopt possibility now, before allocation occurs.
- capacity = builder()->Add<HForceRepresentation>(capacity,
- Representation::Smi());
- length_field = builder()->Add<HForceRepresentation>(length_field,
- Representation::Smi());
+ capacity =
+ builder()->AddUncasted<HForceRepresentation>(capacity,
+ Representation::Smi());
+ length_field =
+ builder()->AddUncasted<HForceRepresentation>(length_field,
+ Representation::Smi());
// Allocate (dealing with failure appropriately)
HAllocate* new_object = builder()->Add<HAllocate>(size_in_bytes,
HType::JSArray(), NOT_TENURED, JS_ARRAY_TYPE);
// actual HChange instruction we need is (sometimes) added in a later
// phase, so it is not available now to be used as an input to HAdd and
// as the return value.
- HInstruction* number_input = Add<HForceRepresentation>(Pop(), rep);
+ HInstruction* number_input = AddUncasted<HForceRepresentation>(Pop(), rep);
if (!rep.IsDouble()) {
number_input->SetFlag(HInstruction::kFlexibleRepresentation);
number_input->SetFlag(HInstruction::kCannotBeTagged);
HValue* HGraphBuilder::EnforceNumberType(HValue* number,
Handle<Type> expected) {
if (expected->Is(Type::Smi())) {
- return Add<HForceRepresentation>(number, Representation::Smi());
+ return AddUncasted<HForceRepresentation>(number, Representation::Smi());
}
if (expected->Is(Type::Signed32())) {
- return Add<HForceRepresentation>(number, Representation::Integer32());
+ return AddUncasted<HForceRepresentation>(number,
+ Representation::Integer32());
}
return number;
}