From 819955b278315af750fdc417e90be3bbcb7844c1 Mon Sep 17 00:00:00 2001 From: titzer Date: Tue, 25 Nov 2014 21:16:31 -0800 Subject: [PATCH] [turbofan] Use special constant type for RPO block number operands. R=dcarney@chromium.org BUG= Review URL: https://codereview.chromium.org/758073002 Cr-Commit-Position: refs/heads/master@{#25508} --- src/compiler/arm/code-generator-arm.cc | 4 +++ src/compiler/arm64/code-generator-arm64.cc | 3 ++ src/compiler/code-generator-impl.h | 35 ++++++++++++-------- src/compiler/ia32/code-generator-ia32.cc | 2 ++ src/compiler/instruction-selector-impl.h | 4 +-- src/compiler/instruction.cc | 2 ++ src/compiler/instruction.h | 11 ++++-- src/compiler/mips/code-generator-mips.cc | 6 ++++ src/compiler/mips64/code-generator-mips64.cc | 6 ++++ src/compiler/x64/code-generator-x64.cc | 3 ++ 10 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/compiler/arm/code-generator-arm.cc b/src/compiler/arm/code-generator-arm.cc index 8934b187d5..28584259a9 100644 --- a/src/compiler/arm/code-generator-arm.cc +++ b/src/compiler/arm/code-generator-arm.cc @@ -77,6 +77,7 @@ class ArmOperandConverter FINAL : public InstructionOperandConverter { case Constant::kInt64: case Constant::kExternalReference: case Constant::kHeapObject: + case Constant::kRpoNumber: break; } UNREACHABLE(); @@ -821,6 +822,9 @@ void CodeGenerator::AssembleMove(InstructionOperand* source, case Constant::kHeapObject: __ Move(dst, src.ToHeapObject()); break; + case Constant::kRpoNumber: + UNREACHABLE(); // TODO(dcarney): loading RPO constants on arm. + break; } if (destination->IsStackSlot()) __ str(dst, g.ToMemOperand(destination)); } else if (src.type() == Constant::kFloat32) { diff --git a/src/compiler/arm64/code-generator-arm64.cc b/src/compiler/arm64/code-generator-arm64.cc index 2b8d40917b..d1d6a6d087 100644 --- a/src/compiler/arm64/code-generator-arm64.cc +++ b/src/compiler/arm64/code-generator-arm64.cc @@ -142,6 +142,9 @@ class Arm64OperandConverter FINAL : public InstructionOperandConverter { return Operand(constant.ToExternalReference()); case Constant::kHeapObject: return Operand(constant.ToHeapObject()); + case Constant::kRpoNumber: + UNREACHABLE(); // TODO(dcarney): RPO immediates on arm64. + break; } UNREACHABLE(); return Operand(-1); diff --git a/src/compiler/code-generator-impl.h b/src/compiler/code-generator-impl.h index 0dc919ad6b..914e1e8c91 100644 --- a/src/compiler/code-generator-impl.h +++ b/src/compiler/code-generator-impl.h @@ -25,6 +25,8 @@ class InstructionOperandConverter { InstructionOperandConverter(CodeGenerator* gen, Instruction* instr) : gen_(gen), instr_(instr) {} + // -- Instruction operand accesses with conversions -------------------------- + Register InputRegister(int index) { return ToRegister(instr_->InputAt(index)); } @@ -57,22 +59,31 @@ class InstructionOperandConverter { return ToHeapObject(instr_->InputAt(index)); } - Label* InputLabel(int index) { return gen_->GetLabel(InputRpo(index)); } + Label* InputLabel(int index) { return ToLabel(instr_->InputAt(index)); } BasicBlock::RpoNumber InputRpo(int index) { - int rpo_number = InputInt32(index); - return BasicBlock::RpoNumber::FromInt(rpo_number); + return ToRpoNumber(instr_->InputAt(index)); } Register OutputRegister(int index = 0) { return ToRegister(instr_->OutputAt(index)); } + Register TempRegister(int index) { return ToRegister(instr_->TempAt(index)); } + DoubleRegister OutputDoubleRegister() { return ToDoubleRegister(instr_->Output()); } - Register TempRegister(int index) { return ToRegister(instr_->TempAt(index)); } + // -- Conversions for operands ----------------------------------------------- + + Label* ToLabel(InstructionOperand* op) { + return gen_->GetLabel(ToRpoNumber(op)); + } + + BasicBlock::RpoNumber ToRpoNumber(InstructionOperand* op) { + return ToConstant(op).ToRpoNumber(); + } Register ToRegister(InstructionOperand* op) { DCHECK(op->IsRegister()); @@ -84,19 +95,17 @@ class InstructionOperandConverter { return DoubleRegister::FromAllocationIndex(op->index()); } - Constant ToConstant(InstructionOperand* operand) { - if (operand->IsImmediate()) { - return gen_->code()->GetImmediate(operand->index()); + Constant ToConstant(InstructionOperand* op) { + if (op->IsImmediate()) { + return gen_->code()->GetImmediate(op->index()); } - return gen_->code()->GetConstant(operand->index()); + return gen_->code()->GetConstant(op->index()); } - double ToDouble(InstructionOperand* operand) { - return ToConstant(operand).ToFloat64(); - } + double ToDouble(InstructionOperand* op) { return ToConstant(op).ToFloat64(); } - Handle ToHeapObject(InstructionOperand* operand) { - return ToConstant(operand).ToHeapObject(); + Handle ToHeapObject(InstructionOperand* op) { + return ToConstant(op).ToHeapObject(); } Frame* frame() const { return gen_->frame(); } diff --git a/src/compiler/ia32/code-generator-ia32.cc b/src/compiler/ia32/code-generator-ia32.cc index 8c619f826c..17d7a8e042 100644 --- a/src/compiler/ia32/code-generator-ia32.cc +++ b/src/compiler/ia32/code-generator-ia32.cc @@ -69,6 +69,8 @@ class IA32OperandConverter : public InstructionOperandConverter { return Immediate(constant.ToHeapObject()); case Constant::kInt64: break; + case Constant::kRpoNumber: + return Immediate::CodeRelativeOffset(ToLabel(operand)); } UNREACHABLE(); return Immediate(-1); diff --git a/src/compiler/instruction-selector-impl.h b/src/compiler/instruction-selector-impl.h index 5e4c09055e..7813e9b6b9 100644 --- a/src/compiler/instruction-selector-impl.h +++ b/src/compiler/instruction-selector-impl.h @@ -137,8 +137,8 @@ class OperandGenerator { } InstructionOperand* Label(BasicBlock* block) { - // TODO(bmeurer): We misuse ImmediateOperand here. - return TempImmediate(block->rpo_number()); + int index = sequence()->AddImmediate(Constant(block->GetRpoNumber())); + return ImmediateOperand::Create(index, zone()); } protected: diff --git a/src/compiler/instruction.cc b/src/compiler/instruction.cc index 3c617327f4..aa0739e406 100644 --- a/src/compiler/instruction.cc +++ b/src/compiler/instruction.cc @@ -332,6 +332,8 @@ std::ostream& operator<<(std::ostream& os, const Constant& constant) { constant.ToExternalReference().address()); case Constant::kHeapObject: return os << Brief(*constant.ToHeapObject()); + case Constant::kRpoNumber: + return os << "RPO" << constant.ToRpoNumber().ToInt(); } UNREACHABLE(); return os; diff --git a/src/compiler/instruction.h b/src/compiler/instruction.h index 1740dfbf25..bcd25b2eb8 100644 --- a/src/compiler/instruction.h +++ b/src/compiler/instruction.h @@ -692,7 +692,8 @@ class Constant FINAL { kFloat32, kFloat64, kExternalReference, - kHeapObject + kHeapObject, + kRpoNumber }; explicit Constant(int32_t v) : type_(kInt32), value_(v) {} @@ -703,6 +704,8 @@ class Constant FINAL { : type_(kExternalReference), value_(bit_cast(ref)) {} explicit Constant(Handle obj) : type_(kHeapObject), value_(bit_cast(obj)) {} + explicit Constant(BasicBlock::RpoNumber rpo) + : type_(kRpoNumber), value_(rpo.ToInt()) {} Type type() const { return type_; } @@ -735,6 +738,11 @@ class Constant FINAL { return bit_cast(static_cast(value_)); } + BasicBlock::RpoNumber ToRpoNumber() const { + DCHECK_EQ(kRpoNumber, type()); + return BasicBlock::RpoNumber::FromInt(static_cast(value_)); + } + Handle ToHeapObject() const { DCHECK_EQ(kHeapObject, type()); return bit_cast >(static_cast(value_)); @@ -891,7 +899,6 @@ class InstructionBlock FINAL : public ZoneObject { PhiInstructions phis_; const BasicBlock::Id id_; const BasicBlock::RpoNumber ao_number_; // Assembly order number. - // TODO(dcarney): probably dont't need this. const BasicBlock::RpoNumber rpo_number_; const BasicBlock::RpoNumber loop_header_; const BasicBlock::RpoNumber loop_end_; diff --git a/src/compiler/mips/code-generator-mips.cc b/src/compiler/mips/code-generator-mips.cc index 4eb372a780..6fb0a30edd 100644 --- a/src/compiler/mips/code-generator-mips.cc +++ b/src/compiler/mips/code-generator-mips.cc @@ -70,6 +70,9 @@ class MipsOperandConverter FINAL : public InstructionOperandConverter { // TODO(plind): Maybe we should handle ExtRef & HeapObj here? // maybe not done on arm due to const pool ?? break; + case Constant::kRpoNumber: + UNREACHABLE(); // TODO(titzer): RPO immediates on mips? + break; } UNREACHABLE(); return Operand(zero_reg); @@ -796,6 +799,9 @@ void CodeGenerator::AssembleMove(InstructionOperand* source, case Constant::kHeapObject: __ li(dst, src.ToHeapObject()); break; + case Constant::kRpoNumber: + UNREACHABLE(); // TODO(titzer): loading RPO numbers on mips. + break; } if (destination->IsStackSlot()) __ sw(dst, g.ToMemOperand(destination)); } else if (src.type() == Constant::kFloat32) { diff --git a/src/compiler/mips64/code-generator-mips64.cc b/src/compiler/mips64/code-generator-mips64.cc index 332afb8af3..2b59bc7036 100644 --- a/src/compiler/mips64/code-generator-mips64.cc +++ b/src/compiler/mips64/code-generator-mips64.cc @@ -71,6 +71,9 @@ class MipsOperandConverter FINAL : public InstructionOperandConverter { // TODO(plind): Maybe we should handle ExtRef & HeapObj here? // maybe not done on arm due to const pool ?? break; + case Constant::kRpoNumber: + UNREACHABLE(); // TODO(titzer): RPO immediates on mips? + break; } UNREACHABLE(); return Operand(zero_reg); @@ -1071,6 +1074,9 @@ void CodeGenerator::AssembleMove(InstructionOperand* source, case Constant::kHeapObject: __ li(dst, src.ToHeapObject()); break; + case Constant::kRpoNumber: + UNREACHABLE(); // TODO(titzer): loading RPO numbers on mips64. + break; } if (destination->IsStackSlot()) __ sd(dst, g.ToMemOperand(destination)); } else if (src.type() == Constant::kFloat32) { diff --git a/src/compiler/x64/code-generator-x64.cc b/src/compiler/x64/code-generator-x64.cc index 174160c02c..f085c3e404 100644 --- a/src/compiler/x64/code-generator-x64.cc +++ b/src/compiler/x64/code-generator-x64.cc @@ -919,6 +919,9 @@ void CodeGenerator::AssembleMove(InstructionOperand* source, case Constant::kHeapObject: __ Move(dst, src.ToHeapObject()); break; + case Constant::kRpoNumber: + UNREACHABLE(); // TODO(dcarney): load of labels on x64. + break; } if (destination->IsStackSlot()) { __ movq(g.ToOperand(destination), kScratchRegister);