Chromium Code Reviews| Index: src/IceCfgNode.cpp |
| diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp |
| index 661dd7320229d2405d4e8c4d787c49568d807e7c..0337cab4b063fb9b5ad05230d35162f19a8a35a3 100644 |
| --- a/src/IceCfgNode.cpp |
| +++ b/src/IceCfgNode.cpp |
| @@ -756,9 +756,10 @@ void CfgNode::contractIfEmpty() { |
| return; |
| Inst *Branch = NULL; |
| for (Inst *I : Insts) { |
| - if (!I->isDeleted() && !I->isUnconditionalBranch()) |
| + if (I->isUnconditionalBranch()) |
|
jvoung (off chromium)
2014/10/31 16:56:42
This doesn't seem to check anymore if the Uncondit
Jim Stichnoth
2014/11/01 14:49:40
Ouch, done.
I should try to make InstList into a
|
| + Branch = I; |
| + else if (!I->isDeleted() && !I->isRedundantAssign()) |
| return; |
| - Branch = I; |
| } |
| Branch->setDeleted(); |
| assert(OutEdges.size() == 1); |
| @@ -798,9 +799,46 @@ void CfgNode::doBranchOpt(const CfgNode *NextNode) { |
| // ======================== Dump routines ======================== // |
| +namespace { |
| + |
| +// Helper function for emit(). |
| +void emitRegisterUsage(Ostream &Str, Cfg *Func, const CfgNode *Node, |
|
jvoung (off chromium)
2014/10/31 16:56:42
Func can be const?
Jim Stichnoth
2014/11/01 14:49:40
Done.
|
| + bool IsLiveIn, std::vector<SizeT> &LiveRegCount) { |
| + Liveness *Liveness = Func->getLiveness(); |
| + const LivenessBV *Live; |
| + if (IsLiveIn) { |
| + Live = &Liveness->getLiveIn(Node); |
| + Str << "\t\t\t\t# LiveIn="; |
| + } else { |
| + Live = &Liveness->getLiveOut(Node); |
| + Str << "\t\t\t\t# LiveOut="; |
| + } |
| + if (!Live->empty()) { |
| + bool First = true; |
| + for (SizeT i = 0; i < Live->size(); ++i) { |
| + if ((*Live)[i]) { |
| + Variable *Var = Liveness->getVariable(i, Node); |
| + if (Var->hasReg()) { |
| + if (IsLiveIn) |
| + ++LiveRegCount[Var->getRegNum()]; |
| + if (!First) |
| + Str << ","; |
| + First = false; |
| + Var->emit(Func); |
| + } |
| + } |
| + } |
| + } |
| + Str << "\n"; |
| +} |
| + |
| +} // end of anonymous namespace |
| + |
| void CfgNode::emit(Cfg *Func) const { |
| Func->setCurrentNode(this); |
| Ostream &Str = Func->getContext()->getStrEmit(); |
| + Liveness *Liveness = Func->getLiveness(); |
| + bool DecorateAsm = Liveness && Func->getContext()->getFlags().DecorateAsm; |
| if (Func->getEntryNode() == this) { |
| Str << Func->getContext()->mangleName(Func->getFunctionName()) << ":\n"; |
| } |
| @@ -809,6 +847,10 @@ void CfgNode::emit(Cfg *Func) const { |
| Assembler *Asm = Func->getAssembler<Assembler>(); |
| Asm->BindCfgNodeLabel(getIndex()); |
| } |
| + std::vector<SizeT> LiveRegCount(Func->getTarget()->getNumRegisters()); |
| + if (DecorateAsm) |
| + emitRegisterUsage(Str, Func, this, true, LiveRegCount); |
| + |
| for (InstPhi *Phi : Phis) { |
| if (Phi->isDeleted()) |
| continue; |
| @@ -819,10 +861,42 @@ void CfgNode::emit(Cfg *Func) const { |
| for (Inst *I : Insts) { |
| if (I->isDeleted()) |
| continue; |
| + if (I->isRedundantAssign()) { |
| + Variable *Dest = I->getDest(); |
| + if (DecorateAsm && Dest->hasReg() && !I->isLastUse(I->getSrc(0))) |
| + ++LiveRegCount[Dest->getRegNum()]; |
| + continue; |
| + } |
| if (Func->useIntegratedAssembler()) { |
| I->emitIAS(Func); |
| } else { |
| I->emit(Func); |
| + if (DecorateAsm) { |
| + // Add end-of-live-range comment. |
| + bool First = true; |
| + Inst *Instr = I; |
|
jvoung (off chromium)
2014/10/31 16:56:42
Can this be factored out into a function too?
At
Jim Stichnoth
2014/11/01 14:49:40
Done.
|
| + Variable *Dest = Instr->getDest(); |
| + if (Dest && Dest->hasReg()) |
| + ++LiveRegCount[Dest->getRegNum()]; |
| + for (SizeT I = 0; I < Instr->getSrcSize(); ++I) { |
| + Operand *Src = Instr->getSrc(I); |
| + SizeT NumVars = Src->getNumVars(); |
| + for (SizeT J = 0; J < NumVars; ++J) { |
| + const Variable *Var = Src->getVar(J); |
| + if (Var->hasReg()) { |
| + if (Instr->isLastUse(Var) && |
| + --LiveRegCount[Var->getRegNum()] == 0) { |
| + if (First) |
| + Str << " \t# END="; |
| + else |
| + Str << ","; |
| + Var->emit(Func); |
| + First = false; |
| + } |
| + } |
| + } |
| + } |
| + } |
| Str << "\n"; |
| } |
| // Update emitted instruction count, plus fill/spill count for |
| @@ -841,6 +915,8 @@ void CfgNode::emit(Cfg *Func) const { |
| } |
| } |
| } |
| + if (DecorateAsm) |
| + emitRegisterUsage(Str, Func, this, false, LiveRegCount); |
| } |
| void CfgNode::dump(Cfg *Func) const { |