Commit d2df943b authored by lrn@chromium.org's avatar lrn@chromium.org

Merge changes to LTemplateInstruction to X64 (Issue 1048).

Implement ConstantD and ConstantI.

BUG=1048

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6352 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5cc7b5c2
...@@ -996,7 +996,8 @@ HConstant::HConstant(Handle<Object> handle, Representation r) ...@@ -996,7 +996,8 @@ HConstant::HConstant(Handle<Object> handle, Representation r)
SetFlag(kUseGVN); SetFlag(kUseGVN);
if (handle_->IsNumber()) { if (handle_->IsNumber()) {
double n = handle_->Number(); double n = handle_->Number();
has_int32_value_ = static_cast<double>(static_cast<int32_t>(n)) == n; double roundtrip_value = static_cast<double>(static_cast<int32_t>(n));
has_int32_value_ = BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(n);
if (has_int32_value_) int32_value_ = static_cast<int32_t>(n); if (has_int32_value_) int32_value_ = static_cast<int32_t>(n);
double_value_ = n; double_value_ = n;
has_double_value_ = true; has_double_value_ = true;
......
...@@ -825,12 +825,31 @@ void LCodeGen::DoSubI(LSubI* instr) { ...@@ -825,12 +825,31 @@ void LCodeGen::DoSubI(LSubI* instr) {
void LCodeGen::DoConstantI(LConstantI* instr) { void LCodeGen::DoConstantI(LConstantI* instr) {
Abort("Unimplemented: %s", "DoConstantI"); ASSERT(instr->result()->IsRegister());
__ movl(ToRegister(instr->result()), Immediate(instr->value()));
} }
void LCodeGen::DoConstantD(LConstantD* instr) { void LCodeGen::DoConstantD(LConstantD* instr) {
Abort("Unimplemented: %s", "DoConstantI"); ASSERT(instr->result()->IsDoubleRegister());
XMMRegister res = ToDoubleRegister(instr->result());
double v = instr->value();
// Use xor to produce +0.0 in a fast and compact way, but avoid to
// do so if the constant is -0.0.
if (BitCast<uint64_t, double>(v) == 0) {
__ xorpd(res, res);
} else {
Register tmp = ToRegister(instr->TempAt(0));
int32_t v_int32 = static_cast<int32_t>(v);
if (static_cast<double>(v_int32) == v) {
__ movl(tmp, Immediate(v_int32));
__ cvtlsi2sd(res, tmp);
} else {
uint64_t int_val = BitCast<uint64_t, double>(v);
__ Set(tmp, int_val);
__ movd(res, tmp);
}
}
} }
...@@ -1032,27 +1051,6 @@ void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { ...@@ -1032,27 +1051,6 @@ void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) {
} }
InstanceType LHasInstanceType::TestType() {
InstanceType from = hydrogen()->from();
InstanceType to = hydrogen()->to();
if (from == FIRST_TYPE) return to;
ASSERT(from == to || to == LAST_TYPE);
return from;
}
Condition LHasInstanceType::BranchCondition() {
InstanceType from = hydrogen()->from();
InstanceType to = hydrogen()->to();
if (from == to) return equal;
if (to == LAST_TYPE) return above_equal;
if (from == FIRST_TYPE) return below_equal;
UNREACHABLE();
return equal;
}
void LCodeGen::DoHasInstanceType(LHasInstanceType* instr) { void LCodeGen::DoHasInstanceType(LHasInstanceType* instr) {
Abort("Unimplemented: %s", "DoHasInstanceType"); Abort("Unimplemented: %s", "DoHasInstanceType");
} }
......
...@@ -90,18 +90,22 @@ void LInstruction::PrintTo(StringStream* stream) { ...@@ -90,18 +90,22 @@ void LInstruction::PrintTo(StringStream* stream) {
template<int R, int I, int T> template<int R, int I, int T>
void LTemplateInstruction<R, I, T>::PrintDataTo(StringStream* stream) { void LTemplateInstruction<R, I, T>::PrintDataTo(StringStream* stream) {
for (int i = 0; i < I; i++) { stream->Add("= ");
stream->Add(i == 0 ? "= " : " "); inputs_.PrintOperandsTo(stream);
inputs_.at(i)->PrintTo(stream);
}
} }
template<int R, int I, int T> template<int R, int I, int T>
void LTemplateInstruction<R, I, T>::PrintOutputOperandTo(StringStream* stream) { void LTemplateInstruction<R, I, T>::PrintOutputOperandTo(StringStream* stream) {
if (this->HasResult()) { results_.PrintOperandsTo(stream);
this->result()->PrintTo(stream); }
stream->Add(" ");
template<typename T, int N>
void OperandContainer<T, N>::PrintOperandsTo(StringStream* stream) {
for (int i = 0; i < N; i++) {
if (i > 0) stream->Add(" ");
elems_[i]->PrintTo(stream);
} }
} }
...@@ -172,22 +176,22 @@ void LGoto::PrintDataTo(StringStream* stream) { ...@@ -172,22 +176,22 @@ void LGoto::PrintDataTo(StringStream* stream) {
void LBranch::PrintDataTo(StringStream* stream) { void LBranch::PrintDataTo(StringStream* stream) {
stream->Add("B%d | B%d on ", true_block_id(), false_block_id()); stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
} }
void LCmpIDAndBranch::PrintDataTo(StringStream* stream) { void LCmpIDAndBranch::PrintDataTo(StringStream* stream) {
stream->Add("if "); stream->Add("if ");
left()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(" %s ", Token::String(op())); stream->Add(" %s ", Token::String(op()));
right()->PrintTo(stream); InputAt(1)->PrintTo(stream);
stream->Add(" then B%d else B%d", true_block_id(), false_block_id()); stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
} }
void LIsNullAndBranch::PrintDataTo(StringStream* stream) { void LIsNullAndBranch::PrintDataTo(StringStream* stream) {
stream->Add("if "); stream->Add("if ");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(is_strict() ? " === null" : " == null"); stream->Add(is_strict() ? " === null" : " == null");
stream->Add(" then B%d else B%d", true_block_id(), false_block_id()); stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
} }
...@@ -195,35 +199,35 @@ void LIsNullAndBranch::PrintDataTo(StringStream* stream) { ...@@ -195,35 +199,35 @@ void LIsNullAndBranch::PrintDataTo(StringStream* stream) {
void LIsObjectAndBranch::PrintDataTo(StringStream* stream) { void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
stream->Add("if is_object("); stream->Add("if is_object(");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
} }
void LIsSmiAndBranch::PrintDataTo(StringStream* stream) { void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
stream->Add("if is_smi("); stream->Add("if is_smi(");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
} }
void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) { void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
stream->Add("if has_instance_type("); stream->Add("if has_instance_type(");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
} }
void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) { void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
stream->Add("if has_cached_array_index("); stream->Add("if has_cached_array_index(");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
} }
void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) { void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
stream->Add("if class_of_test("); stream->Add("if class_of_test(");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(", \"%o\") then B%d else B%d", stream->Add(", \"%o\") then B%d else B%d",
*hydrogen()->class_name(), *hydrogen()->class_name(),
true_block_id(), true_block_id(),
...@@ -232,14 +236,14 @@ void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) { ...@@ -232,14 +236,14 @@ void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
void LTypeofIs::PrintDataTo(StringStream* stream) { void LTypeofIs::PrintDataTo(StringStream* stream) {
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(" == \"%s\"", *hydrogen()->type_literal()->ToCString()); stream->Add(" == \"%s\"", *hydrogen()->type_literal()->ToCString());
} }
void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) { void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
stream->Add("if typeof "); stream->Add("if typeof ");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(" == \"%s\" then B%d else B%d", stream->Add(" == \"%s\" then B%d else B%d",
*hydrogen()->type_literal()->ToCString(), *hydrogen()->type_literal()->ToCString(),
true_block_id(), false_block_id()); true_block_id(), false_block_id());
...@@ -253,7 +257,7 @@ void LCallConstantFunction::PrintDataTo(StringStream* stream) { ...@@ -253,7 +257,7 @@ void LCallConstantFunction::PrintDataTo(StringStream* stream) {
void LUnaryMathOperation::PrintDataTo(StringStream* stream) { void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
stream->Add("/%s ", hydrogen()->OpName()); stream->Add("/%s ", hydrogen()->OpName());
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
} }
...@@ -263,7 +267,7 @@ void LLoadContextSlot::PrintDataTo(StringStream* stream) { ...@@ -263,7 +267,7 @@ void LLoadContextSlot::PrintDataTo(StringStream* stream) {
void LCallKeyed::PrintDataTo(StringStream* stream) { void LCallKeyed::PrintDataTo(StringStream* stream) {
stream->Add("[rcx] #%d / ", arity()); stream->Add("[ecx] #%d / ", arity());
} }
...@@ -286,14 +290,14 @@ void LCallKnownGlobal::PrintDataTo(StringStream* stream) { ...@@ -286,14 +290,14 @@ void LCallKnownGlobal::PrintDataTo(StringStream* stream) {
void LCallNew::PrintDataTo(StringStream* stream) { void LCallNew::PrintDataTo(StringStream* stream) {
stream->Add("= "); stream->Add("= ");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(" #%d / ", arity()); stream->Add(" #%d / ", arity());
} }
void LClassOfTest::PrintDataTo(StringStream* stream) { void LClassOfTest::PrintDataTo(StringStream* stream) {
stream->Add("= class_of_test("); stream->Add("= class_of_test(");
input()->PrintTo(stream); InputAt(0)->PrintTo(stream);
stream->Add(", \"%o\")", *hydrogen()->class_name()); stream->Add(", \"%o\")", *hydrogen()->class_name());
} }
...@@ -832,8 +836,17 @@ void LChunkBuilder::VisitInstruction(HInstruction* current) { ...@@ -832,8 +836,17 @@ void LChunkBuilder::VisitInstruction(HInstruction* current) {
if (FLAG_stress_environments && !instr->HasEnvironment()) { if (FLAG_stress_environments && !instr->HasEnvironment()) {
instr = AssignEnvironment(instr); instr = AssignEnvironment(instr);
} }
if (current->IsBranch()) { if (current->IsBranch() && !instr->IsGoto()) {
instr->set_hydrogen_value(HBranch::cast(current)->value()); // TODO(fschneider): Handle branch instructions uniformly like
// other instructions. This requires us to generate the right
// branch instruction already at the HIR level.
ASSERT(instr->IsControl());
HBranch* branch = HBranch::cast(current);
instr->set_hydrogen_value(branch->value());
HBasicBlock* first = branch->FirstSuccessor();
HBasicBlock* second = branch->SecondSuccessor();
ASSERT(first != NULL && second != NULL);
instr->SetBranchTargets(first->block_id(), second->block_id());
} else { } else {
instr->set_hydrogen_value(current); instr->set_hydrogen_value(current);
} }
...@@ -1217,7 +1230,8 @@ LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { ...@@ -1217,7 +1230,8 @@ LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
return DefineAsRegister(new LConstantI(value)); return DefineAsRegister(new LConstantI(value));
} else if (r.IsDouble()) { } else if (r.IsDouble()) {
double value = instr->DoubleValue(); double value = instr->DoubleValue();
return DefineAsRegister(new LConstantD(value)); LOperand* temp = TempRegister();
return DefineAsRegister(new LConstantD(value, temp));
} else if (r.IsTagged()) { } else if (r.IsTagged()) {
return DefineAsRegister(new LConstantT(instr->handle())); return DefineAsRegister(new LConstantT(instr->handle()));
} else { } else {
......
This diff is collapsed.
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