Commit eb00c530 authored by dcarney@chromium.org's avatar dcarney@chromium.org

[turbofan] map vregs early

R=bmeurer@chromium.org, jarin@chromium.org

BUG=

Review URL: https://codereview.chromium.org/623313003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24414 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0a95f898
...@@ -45,8 +45,8 @@ class OperandGenerator { ...@@ -45,8 +45,8 @@ class OperandGenerator {
InstructionOperand* DefineAsConstant(Node* node) { InstructionOperand* DefineAsConstant(Node* node) {
selector()->MarkAsDefined(node); selector()->MarkAsDefined(node);
sequence()->AddConstant(node->id(), ToConstant(node)); int virtual_register = sequence()->AddConstant(node, ToConstant(node));
return ConstantOperand::Create(node->id(), zone()); return ConstantOperand::Create(virtual_register, zone());
} }
InstructionOperand* DefineAsLocation(Node* node, LinkageLocation location, InstructionOperand* DefineAsLocation(Node* node, LinkageLocation location,
...@@ -166,7 +166,8 @@ class OperandGenerator { ...@@ -166,7 +166,8 @@ class OperandGenerator {
UnallocatedOperand* Define(Node* node, UnallocatedOperand* operand) { UnallocatedOperand* Define(Node* node, UnallocatedOperand* operand) {
DCHECK_NOT_NULL(node); DCHECK_NOT_NULL(node);
DCHECK_NOT_NULL(operand); DCHECK_NOT_NULL(operand);
operand->set_virtual_register(node->id()); operand->set_virtual_register(
selector_->sequence()->GetVirtualRegister(node));
selector()->MarkAsDefined(node); selector()->MarkAsDefined(node);
return operand; return operand;
} }
...@@ -174,7 +175,8 @@ class OperandGenerator { ...@@ -174,7 +175,8 @@ class OperandGenerator {
UnallocatedOperand* Use(Node* node, UnallocatedOperand* operand) { UnallocatedOperand* Use(Node* node, UnallocatedOperand* operand) {
DCHECK_NOT_NULL(node); DCHECK_NOT_NULL(node);
DCHECK_NOT_NULL(operand); DCHECK_NOT_NULL(operand);
operand->set_virtual_register(node->id()); operand->set_virtual_register(
selector_->sequence()->GetVirtualRegister(node));
selector()->MarkAsUsed(node); selector()->MarkAsUsed(node);
return operand; return operand;
} }
......
...@@ -190,27 +190,27 @@ void InstructionSelector::MarkAsUsed(Node* node) { ...@@ -190,27 +190,27 @@ void InstructionSelector::MarkAsUsed(Node* node) {
bool InstructionSelector::IsDouble(const Node* node) const { bool InstructionSelector::IsDouble(const Node* node) const {
DCHECK_NOT_NULL(node); DCHECK_NOT_NULL(node);
return sequence()->IsDouble(node->id()); return sequence()->IsDouble(sequence()->GetVirtualRegister(node));
} }
void InstructionSelector::MarkAsDouble(Node* node) { void InstructionSelector::MarkAsDouble(Node* node) {
DCHECK_NOT_NULL(node); DCHECK_NOT_NULL(node);
DCHECK(!IsReference(node)); DCHECK(!IsReference(node));
sequence()->MarkAsDouble(node->id()); sequence()->MarkAsDouble(sequence()->GetVirtualRegister(node));
} }
bool InstructionSelector::IsReference(const Node* node) const { bool InstructionSelector::IsReference(const Node* node) const {
DCHECK_NOT_NULL(node); DCHECK_NOT_NULL(node);
return sequence()->IsReference(node->id()); return sequence()->IsReference(sequence()->GetVirtualRegister(node));
} }
void InstructionSelector::MarkAsReference(Node* node) { void InstructionSelector::MarkAsReference(Node* node) {
DCHECK_NOT_NULL(node); DCHECK_NOT_NULL(node);
DCHECK(!IsDouble(node)); DCHECK(!IsDouble(node));
sequence()->MarkAsReference(node->id()); sequence()->MarkAsReference(sequence()->GetVirtualRegister(node));
} }
......
...@@ -316,6 +316,35 @@ std::ostream& operator<<(std::ostream& os, const Constant& constant) { ...@@ -316,6 +316,35 @@ std::ostream& operator<<(std::ostream& os, const Constant& constant) {
} }
InstructionSequence::InstructionSequence(Linkage* linkage, Graph* graph,
Schedule* schedule)
: graph_(graph),
node_map_(zone()->NewArray<int>(graph->NodeCount())),
linkage_(linkage),
schedule_(schedule),
constants_(ConstantMap::key_compare(),
ConstantMap::allocator_type(zone())),
immediates_(zone()),
instructions_(zone()),
next_virtual_register_(0),
pointer_maps_(zone()),
doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())),
references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())),
deoptimization_entries_(zone()) {
for (int i = 0; i < graph->NodeCount(); ++i) {
node_map_[i] = -1;
}
}
int InstructionSequence::GetVirtualRegister(const Node* node) {
if (node_map_[node->id()] == -1) {
node_map_[node->id()] = NextVirtualRegister();
}
return node_map_[node->id()];
}
Label* InstructionSequence::GetLabel(BasicBlock* block) { Label* InstructionSequence::GetLabel(BasicBlock* block) {
return GetBlockStart(block)->label(); return GetBlockStart(block)->label();
} }
......
...@@ -34,8 +34,8 @@ const InstructionCode kSourcePositionInstruction = -3; ...@@ -34,8 +34,8 @@ const InstructionCode kSourcePositionInstruction = -3;
#define INSTRUCTION_OPERAND_LIST(V) \ #define INSTRUCTION_OPERAND_LIST(V) \
V(Constant, CONSTANT, 128) \ V(Constant, CONSTANT, 0) \
V(Immediate, IMMEDIATE, 128) \ V(Immediate, IMMEDIATE, 0) \
V(StackSlot, STACK_SLOT, 128) \ V(StackSlot, STACK_SLOT, 128) \
V(DoubleStackSlot, DOUBLE_STACK_SLOT, 128) \ V(DoubleStackSlot, DOUBLE_STACK_SLOT, 128) \
V(Register, REGISTER, Register::kNumRegisters) \ V(Register, REGISTER, Register::kNumRegisters) \
...@@ -804,20 +804,7 @@ typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; ...@@ -804,20 +804,7 @@ typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector;
// TODO(titzer): s/IsDouble/IsFloat64/ // TODO(titzer): s/IsDouble/IsFloat64/
class InstructionSequence FINAL { class InstructionSequence FINAL {
public: public:
InstructionSequence(Linkage* linkage, Graph* graph, Schedule* schedule) InstructionSequence(Linkage* linkage, Graph* graph, Schedule* schedule);
: graph_(graph),
linkage_(linkage),
schedule_(schedule),
constants_(ConstantMap::key_compare(),
ConstantMap::allocator_type(zone())),
immediates_(zone()),
instructions_(zone()),
next_virtual_register_(graph->NodeCount()),
pointer_maps_(zone()),
doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())),
references_(std::less<int>(),
VirtualRegisterSet::allocator_type(zone())),
deoptimization_entries_(zone()) {}
int NextVirtualRegister() { return next_virtual_register_++; } int NextVirtualRegister() { return next_virtual_register_++; }
int VirtualRegisterCount() const { return next_virtual_register_; } int VirtualRegisterCount() const { return next_virtual_register_; }
...@@ -840,7 +827,7 @@ class InstructionSequence FINAL { ...@@ -840,7 +827,7 @@ class InstructionSequence FINAL {
BasicBlock* GetBasicBlock(int instruction_index); BasicBlock* GetBasicBlock(int instruction_index);
int GetVirtualRegister(Node* node) const { return node->id(); } int GetVirtualRegister(const Node* node);
bool IsReference(int virtual_register) const; bool IsReference(int virtual_register) const;
bool IsDouble(int virtual_register) const; bool IsDouble(int virtual_register) const;
...@@ -880,9 +867,11 @@ class InstructionSequence FINAL { ...@@ -880,9 +867,11 @@ class InstructionSequence FINAL {
void StartBlock(BasicBlock* block); void StartBlock(BasicBlock* block);
void EndBlock(BasicBlock* block); void EndBlock(BasicBlock* block);
void AddConstant(int virtual_register, Constant constant) { int AddConstant(Node* node, Constant constant) {
int virtual_register = GetVirtualRegister(node);
DCHECK(constants_.find(virtual_register) == constants_.end()); DCHECK(constants_.find(virtual_register) == constants_.end());
constants_.insert(std::make_pair(virtual_register, constant)); constants_.insert(std::make_pair(virtual_register, constant));
return virtual_register;
} }
Constant GetConstant(int virtual_register) const { Constant GetConstant(int virtual_register) const {
ConstantMap::const_iterator it = constants_.find(virtual_register); ConstantMap::const_iterator it = constants_.find(virtual_register);
...@@ -926,6 +915,7 @@ class InstructionSequence FINAL { ...@@ -926,6 +915,7 @@ class InstructionSequence FINAL {
typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet;
Graph* graph_; Graph* graph_;
int* node_map_;
Linkage* linkage_; Linkage* linkage_;
Schedule* schedule_; Schedule* schedule_;
ConstantMap constants_; ConstantMap constants_;
......
...@@ -548,10 +548,9 @@ BitVector* RegisterAllocator::ComputeLiveOut(BasicBlock* block) { ...@@ -548,10 +548,9 @@ BitVector* RegisterAllocator::ComputeLiveOut(BasicBlock* block) {
Node* phi = *j; Node* phi = *j;
if (phi->opcode() != IrOpcode::kPhi) continue; if (phi->opcode() != IrOpcode::kPhi) continue;
Node* input = phi->InputAt(static_cast<int>(index)); Node* input = phi->InputAt(static_cast<int>(index));
live_out->Add(input->id()); live_out->Add(code()->GetVirtualRegister(input));
} }
} }
return live_out; return live_out;
} }
...@@ -1066,7 +1065,8 @@ void RegisterAllocator::ResolvePhis(BasicBlock* block) { ...@@ -1066,7 +1065,8 @@ void RegisterAllocator::ResolvePhis(BasicBlock* block) {
UnallocatedOperand* phi_operand = UnallocatedOperand* phi_operand =
new (code_zone()) UnallocatedOperand(UnallocatedOperand::NONE); new (code_zone()) UnallocatedOperand(UnallocatedOperand::NONE);
phi_operand->set_virtual_register(phi->id()); int phi_vreg = code()->GetVirtualRegister(phi);
phi_operand->set_virtual_register(phi_vreg);
size_t j = 0; size_t j = 0;
Node::Inputs inputs = phi->inputs(); Node::Inputs inputs = phi->inputs();
...@@ -1077,7 +1077,7 @@ void RegisterAllocator::ResolvePhis(BasicBlock* block) { ...@@ -1077,7 +1077,7 @@ void RegisterAllocator::ResolvePhis(BasicBlock* block) {
if (j >= block->PredecessorCount()) continue; if (j >= block->PredecessorCount()) continue;
UnallocatedOperand* operand = UnallocatedOperand* operand =
new (code_zone()) UnallocatedOperand(UnallocatedOperand::ANY); new (code_zone()) UnallocatedOperand(UnallocatedOperand::ANY);
operand->set_virtual_register(op->id()); operand->set_virtual_register(code()->GetVirtualRegister(op));
BasicBlock* cur_block = block->PredecessorAt(j); BasicBlock* cur_block = block->PredecessorAt(j);
// The gap move must be added without any special processing as in // The gap move must be added without any special processing as in
// the AddConstraintsGapMove. // the AddConstraintsGapMove.
...@@ -1089,7 +1089,7 @@ void RegisterAllocator::ResolvePhis(BasicBlock* block) { ...@@ -1089,7 +1089,7 @@ void RegisterAllocator::ResolvePhis(BasicBlock* block) {
USE(branch); USE(branch);
} }
LiveRange* live_range = LiveRangeFor(phi->id()); LiveRange* live_range = LiveRangeFor(phi_vreg);
BlockStartInstruction* block_start = code()->GetBlockStart(block); BlockStartInstruction* block_start = code()->GetBlockStart(block);
block_start->GetOrCreateParallelMove(GapInstruction::START, code_zone()) block_start->GetOrCreateParallelMove(GapInstruction::START, code_zone())
->AddMove(phi_operand, live_range->GetSpillOperand(), code_zone()); ->AddMove(phi_operand, live_range->GetSpillOperand(), code_zone());
...@@ -1298,7 +1298,8 @@ void RegisterAllocator::BuildLiveRanges() { ...@@ -1298,7 +1298,8 @@ void RegisterAllocator::BuildLiveRanges() {
// The live range interval already ends at the first instruction of the // The live range interval already ends at the first instruction of the
// block. // block.
live->Remove(phi->id()); int phi_vreg = code()->GetVirtualRegister(phi);
live->Remove(phi_vreg);
InstructionOperand* hint = NULL; InstructionOperand* hint = NULL;
InstructionOperand* phi_operand = NULL; InstructionOperand* phi_operand = NULL;
...@@ -1310,7 +1311,7 @@ void RegisterAllocator::BuildLiveRanges() { ...@@ -1310,7 +1311,7 @@ void RegisterAllocator::BuildLiveRanges() {
for (int j = 0; j < move->move_operands()->length(); ++j) { for (int j = 0; j < move->move_operands()->length(); ++j) {
InstructionOperand* to = move->move_operands()->at(j).destination(); InstructionOperand* to = move->move_operands()->at(j).destination();
if (to->IsUnallocated() && if (to->IsUnallocated() &&
UnallocatedOperand::cast(to)->virtual_register() == phi->id()) { UnallocatedOperand::cast(to)->virtual_register() == phi_vreg) {
hint = move->move_operands()->at(j).source(); hint = move->move_operands()->at(j).source();
phi_operand = to; phi_operand = to;
break; break;
......
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