Commit 1502e59a by Jim Stichnoth

Subzero: Use llvm::ilist<> for PhiList and AssignList.

This is toward the goal of pulling non-POD fields out of the CfgNode class so that CfgNode can be arena-allocated and not leak memory. For now, PhiList and AssignList are defined as InstList. Ideally, they would be ilist<> of InstPhi and InstAssign, but SFINAE happens. BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/794923002
parent 668a7a33
...@@ -57,7 +57,7 @@ void CfgNode::appendInst(Inst *Inst) { ...@@ -57,7 +57,7 @@ void CfgNode::appendInst(Inst *Inst) {
// overlap with the range of any other block. // overlap with the range of any other block.
void CfgNode::renumberInstructions() { void CfgNode::renumberInstructions() {
InstNumberT FirstNumber = Func->getNextInstNumber(); InstNumberT FirstNumber = Func->getNextInstNumber();
for (InstPhi *I : Phis) for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I)
I->renumber(Func); I->renumber(Func);
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I)
I->renumber(Func); I->renumber(Func);
...@@ -86,8 +86,10 @@ void CfgNode::computePredecessors() { ...@@ -86,8 +86,10 @@ void CfgNode::computePredecessors() {
// instructions and appends assignment instructions to predecessor // instructions and appends assignment instructions to predecessor
// blocks. Note that this transformation preserves SSA form. // blocks. Note that this transformation preserves SSA form.
void CfgNode::placePhiLoads() { void CfgNode::placePhiLoads() {
for (InstPhi *I : Phis) for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
Insts.insert(Insts.begin(), I->lower(Func)); auto Phi = llvm::dyn_cast<InstPhi>(I);
Insts.insert(Insts.begin(), Phi->lower(Func));
}
} }
// This does part 2 of Phi lowering. For each Phi instruction at each // This does part 2 of Phi lowering. For each Phi instruction at each
...@@ -184,8 +186,9 @@ void CfgNode::placePhiStores() { ...@@ -184,8 +186,9 @@ void CfgNode::placePhiStores() {
// Consider every out-edge. // Consider every out-edge.
for (CfgNode *Succ : OutEdges) { for (CfgNode *Succ : OutEdges) {
// Consider every Phi instruction at the out-edge. // Consider every Phi instruction at the out-edge.
for (InstPhi *I : Succ->Phis) { for (auto I = Succ->Phis.begin(), E = Succ->Phis.end(); I != E; ++I) {
Operand *Operand = I->getOperandForTarget(this); auto Phi = llvm::dyn_cast<InstPhi>(I);
Operand *Operand = Phi->getOperandForTarget(this);
assert(Operand); assert(Operand);
Variable *Dest = I->getDest(); Variable *Dest = I->getDest();
assert(Dest); assert(Dest);
...@@ -200,7 +203,7 @@ void CfgNode::placePhiStores() { ...@@ -200,7 +203,7 @@ void CfgNode::placePhiStores() {
// Deletes the phi instructions after the loads and stores are placed. // Deletes the phi instructions after the loads and stores are placed.
void CfgNode::deletePhis() { void CfgNode::deletePhis() {
for (InstPhi *I : Phis) for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I)
I->setDeleted(); I->setDeleted();
} }
...@@ -316,7 +319,8 @@ void CfgNode::advancedPhiLowering() { ...@@ -316,7 +319,8 @@ void CfgNode::advancedPhiLowering() {
} Desc[getPhis().size()]; } Desc[getPhis().size()];
size_t NumPhis = 0; size_t NumPhis = 0;
for (InstPhi *Inst : getPhis()) { for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
auto Inst = llvm::dyn_cast<InstPhi>(I);
if (!Inst->isDeleted()) { if (!Inst->isDeleted()) {
Desc[NumPhis].Phi = Inst; Desc[NumPhis].Phi = Inst;
Desc[NumPhis].Dest = Inst->getDest(); Desc[NumPhis].Dest = Inst->getDest();
...@@ -470,8 +474,8 @@ void CfgNode::advancedPhiLowering() { ...@@ -470,8 +474,8 @@ void CfgNode::advancedPhiLowering() {
Func->getVMetadata()->addNode(Split); Func->getVMetadata()->addNode(Split);
} }
for (InstPhi *Inst : getPhis()) for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I)
Inst->setDeleted(); I->setDeleted();
} }
// Does address mode optimization. Pass each instruction to the // Does address mode optimization. Pass each instruction to the
...@@ -534,7 +538,7 @@ void CfgNode::livenessLightweight() { ...@@ -534,7 +538,7 @@ void CfgNode::livenessLightweight() {
continue; continue;
I->livenessLightweight(Func, Live); I->livenessLightweight(Func, Live);
} }
for (InstPhi *I : Phis) { for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
if (I->isDeleted()) if (I->isDeleted())
continue; continue;
I->livenessLightweight(Func, Live); I->livenessLightweight(Func, Live);
...@@ -566,8 +570,10 @@ bool CfgNode::liveness(Liveness *Liveness) { ...@@ -566,8 +570,10 @@ bool CfgNode::liveness(Liveness *Liveness) {
for (CfgNode *Succ : OutEdges) { for (CfgNode *Succ : OutEdges) {
Live |= Liveness->getLiveIn(Succ); Live |= Liveness->getLiveIn(Succ);
// Mark corresponding argument of phis in successor as live. // Mark corresponding argument of phis in successor as live.
for (InstPhi *I : Succ->Phis) for (auto I = Succ->Phis.begin(), E = Succ->Phis.end(); I != E; ++I) {
I->livenessPhiOperand(Live, this, Liveness); auto Phi = llvm::dyn_cast<InstPhi>(I);
Phi->livenessPhiOperand(Live, this, Liveness);
}
} }
Liveness->getLiveOut(this) = Live; Liveness->getLiveOut(this) = Live;
...@@ -582,7 +588,7 @@ bool CfgNode::liveness(Liveness *Liveness) { ...@@ -582,7 +588,7 @@ bool CfgNode::liveness(Liveness *Liveness) {
// the block. // the block.
SizeT NumNonDeadPhis = 0; SizeT NumNonDeadPhis = 0;
InstNumberT FirstPhiNumber = Inst::NumberSentinel; InstNumberT FirstPhiNumber = Inst::NumberSentinel;
for (InstPhi *I : Phis) { for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
if (I->isDeleted()) if (I->isDeleted())
continue; continue;
if (FirstPhiNumber == Inst::NumberSentinel) if (FirstPhiNumber == Inst::NumberSentinel)
...@@ -644,7 +650,7 @@ void CfgNode::livenessPostprocess(LivenessMode Mode, Liveness *Liveness) { ...@@ -644,7 +650,7 @@ void CfgNode::livenessPostprocess(LivenessMode Mode, Liveness *Liveness) {
InstNumberT FirstInstNum = Inst::NumberSentinel; InstNumberT FirstInstNum = Inst::NumberSentinel;
InstNumberT LastInstNum = Inst::NumberSentinel; InstNumberT LastInstNum = Inst::NumberSentinel;
// Process phis in any order. Process only Dest operands. // Process phis in any order. Process only Dest operands.
for (InstPhi *I : Phis) { for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
I->deleteIfDead(); I->deleteIfDead();
if (I->isDeleted()) if (I->isDeleted())
continue; continue;
...@@ -889,12 +895,11 @@ void CfgNode::emit(Cfg *Func) const { ...@@ -889,12 +895,11 @@ void CfgNode::emit(Cfg *Func) const {
if (DecorateAsm) if (DecorateAsm)
emitRegisterUsage(Str, Func, this, true, LiveRegCount); emitRegisterUsage(Str, Func, this, true, LiveRegCount);
for (InstPhi *Phi : Phis) { for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
if (Phi->isDeleted()) if (I->isDeleted())
continue; continue;
// Emitting a Phi instruction should cause an error. // Emitting a Phi instruction should cause an error.
Inst *Instr = Phi; I->emit(Func);
Instr->emit(Func);
} }
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) { for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) {
if (I->isDeleted()) if (I->isDeleted())
...@@ -919,12 +924,11 @@ void CfgNode::emitIAS(Cfg *Func) const { ...@@ -919,12 +924,11 @@ void CfgNode::emitIAS(Cfg *Func) const {
Func->setCurrentNode(this); Func->setCurrentNode(this);
Assembler *Asm = Func->getAssembler<Assembler>(); Assembler *Asm = Func->getAssembler<Assembler>();
Asm->BindCfgNodeLabel(getIndex()); Asm->BindCfgNodeLabel(getIndex());
for (InstPhi *Phi : Phis) { for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
if (Phi->isDeleted()) if (I->isDeleted())
continue; continue;
// Emitting a Phi instruction should cause an error. // Emitting a Phi instruction should cause an error.
Inst *Instr = Phi; I->emitIAS(Func);
Instr->emitIAS(Func);
} }
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) { for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) {
if (I->isDeleted()) if (I->isDeleted())
...@@ -977,7 +981,7 @@ void CfgNode::dump(Cfg *Func) const { ...@@ -977,7 +981,7 @@ void CfgNode::dump(Cfg *Func) const {
} }
// Dump each instruction. // Dump each instruction.
if (Func->getContext()->isVerbose(IceV_Instructions)) { if (Func->getContext()->isVerbose(IceV_Instructions)) {
for (InstPhi *I : Phis) for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I)
I->dumpDecorated(Func); I->dumpDecorated(Func);
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I)
I->dumpDecorated(Func); I->dumpDecorated(Func);
......
...@@ -60,10 +60,11 @@ class VariablesMetadata; ...@@ -60,10 +60,11 @@ class VariablesMetadata;
// http://llvm.org/docs/ProgrammersManual.html#picking-the-right-data-structure-for-a-task // http://llvm.org/docs/ProgrammersManual.html#picking-the-right-data-structure-for-a-task
typedef std::string IceString; typedef std::string IceString;
typedef llvm::ilist<Inst> InstList; typedef llvm::ilist<Inst> InstList;
typedef std::list<InstAssign *> AssignList; // Ideally PhiList would be llvm::ilist<InstPhi>, and similar for
typedef std::list<InstPhi *> PhiList; // AssignList, but this runs into issues with SFINAE.
typedef InstList PhiList;
typedef InstList AssignList;
typedef std::vector<Variable *> VarList; typedef std::vector<Variable *> VarList;
typedef std::vector<Operand *> OperandList;
typedef std::vector<CfgNode *> NodeList; typedef std::vector<CfgNode *> NodeList;
typedef std::vector<Constant *> ConstantList; typedef std::vector<Constant *> ConstantList;
......
...@@ -293,7 +293,8 @@ void VariablesMetadata::addNode(CfgNode *Node) { ...@@ -293,7 +293,8 @@ void VariablesMetadata::addNode(CfgNode *Node) {
if (Func->getNumVariables() >= Metadata.size()) if (Func->getNumVariables() >= Metadata.size())
Metadata.resize(Func->getNumVariables()); Metadata.resize(Func->getNumVariables());
for (InstPhi *I : Node->getPhis()) { for (auto I = Node->getPhis().begin(), E = Node->getPhis().end(); I != E;
++I) {
if (I->isDeleted()) if (I->isDeleted())
continue; continue;
if (Variable *Dest = I->getDest()) { if (Variable *Dest = I->getDest()) {
......
...@@ -1775,6 +1775,7 @@ void TargetX8632::lowerCall(const InstCall *Instr) { ...@@ -1775,6 +1775,7 @@ void TargetX8632::lowerCall(const InstCall *Instr) {
// Apple. // Apple.
NeedsStackAlignment = true; NeedsStackAlignment = true;
typedef std::vector<Operand *> OperandList;
OperandList XmmArgs; OperandList XmmArgs;
OperandList StackArgs, StackArgLocations; OperandList StackArgs, StackArgLocations;
uint32_t ParameterAreaSizeBytes = 0; uint32_t ParameterAreaSizeBytes = 0;
...@@ -4148,7 +4149,9 @@ void TargetX8632::lowerUnreachable(const InstUnreachable * /*Inst*/) { ...@@ -4148,7 +4149,9 @@ void TargetX8632::lowerUnreachable(const InstUnreachable * /*Inst*/) {
// Undef input. // Undef input.
void TargetX8632::prelowerPhis() { void TargetX8632::prelowerPhis() {
CfgNode *Node = Context.getNode(); CfgNode *Node = Context.getNode();
for (InstPhi *Phi : Node->getPhis()) { for (auto I = Node->getPhis().begin(), E = Node->getPhis().end(); I != E;
++I) {
auto Phi = llvm::dyn_cast<InstPhi>(I);
if (Phi->isDeleted()) if (Phi->isDeleted())
continue; continue;
Variable *Dest = Phi->getDest(); Variable *Dest = Phi->getDest();
...@@ -4212,11 +4215,11 @@ void TargetX8632::lowerPhiAssignments(CfgNode *Node, ...@@ -4212,11 +4215,11 @@ void TargetX8632::lowerPhiAssignments(CfgNode *Node,
// set. TODO(stichnot): This work is being repeated for every split // set. TODO(stichnot): This work is being repeated for every split
// edge to the successor, so consider updating LiveIn just once // edge to the successor, so consider updating LiveIn just once
// after all the edges are split. // after all the edges are split.
for (InstAssign *Assign : Assignments) { for (auto I = Assignments.begin(), E = Assignments.end(); I != E; ++I) {
Variable *Dest = Assign->getDest(); Variable *Dest = I->getDest();
if (Dest->hasReg()) { if (Dest->hasReg()) {
Available[Dest->getRegNum()] = false; Available[Dest->getRegNum()] = false;
} else if (isMemoryOperand(Assign->getSrc(0))) { } else if (isMemoryOperand(I->getSrc(0))) {
NeedsRegs = true; // Src and Dest are both in memory NeedsRegs = true; // Src and Dest are both in memory
} }
} }
...@@ -4237,7 +4240,7 @@ void TargetX8632::lowerPhiAssignments(CfgNode *Node, ...@@ -4237,7 +4240,7 @@ void TargetX8632::lowerPhiAssignments(CfgNode *Node,
// afterwards if necessary. // afterwards if necessary.
for (auto I = Assignments.rbegin(), E = Assignments.rend(); I != E; ++I) { for (auto I = Assignments.rbegin(), E = Assignments.rend(); I != E; ++I) {
Context.rewind(); Context.rewind();
InstAssign *Assign = *I; auto Assign = llvm::dyn_cast<InstAssign>(&*I);
Variable *Dest = Assign->getDest(); Variable *Dest = Assign->getDest();
Operand *Src = Assign->getSrc(0); Operand *Src = Assign->getSrc(0);
Variable *SrcVar = llvm::dyn_cast<Variable>(Src); Variable *SrcVar = llvm::dyn_cast<Variable>(Src);
......
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