Commit 9a05aea8 by Jim Stichnoth

Subzero: Fix/improve -asm-verbose output.

Fixes a bug where a num-uses counter wasn't being updated because of C operator && semantics. The code was something like "if (A && --B) ..." but we want --B to happen even when A is false. Sorts the LiveIn and LiveOut lists by regnum so that the lists always display the set of registers in a consistent/familiar order. BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/1152813003
parent 55500dbc
...@@ -794,21 +794,31 @@ void emitRegisterUsage(Ostream &Str, const Cfg *Func, const CfgNode *Node, ...@@ -794,21 +794,31 @@ void emitRegisterUsage(Ostream &Str, const Cfg *Func, const CfgNode *Node,
Str << "\t\t\t\t# LiveOut="; Str << "\t\t\t\t# LiveOut=";
} }
if (!Live->empty()) { if (!Live->empty()) {
bool First = true; std::vector<Variable *> LiveRegs;
for (SizeT i = 0; i < Live->size(); ++i) { for (SizeT i = 0; i < Live->size(); ++i) {
if ((*Live)[i]) { if ((*Live)[i]) {
Variable *Var = Liveness->getVariable(i, Node); Variable *Var = Liveness->getVariable(i, Node);
if (Var->hasReg()) { if (Var->hasReg()) {
if (IsLiveIn) if (IsLiveIn)
++LiveRegCount[Var->getRegNum()]; ++LiveRegCount[Var->getRegNum()];
LiveRegs.push_back(Var);
}
}
}
// Sort the variables by regnum so they are always printed in a
// familiar order.
std::sort(LiveRegs.begin(), LiveRegs.end(),
[](const Variable *V1, const Variable *V2) {
return V1->getRegNum() < V2->getRegNum();
});
bool First = true;
for (Variable *Var : LiveRegs) {
if (!First) if (!First)
Str << ","; Str << ",";
First = false; First = false;
Var->emit(Func); Var->emit(Func);
} }
} }
}
}
Str << "\n"; Str << "\n";
} }
...@@ -825,8 +835,14 @@ void emitLiveRangesEnded(Ostream &Str, const Cfg *Func, const Inst *Instr, ...@@ -825,8 +835,14 @@ void emitLiveRangesEnded(Ostream &Str, const Cfg *Func, const Inst *Instr,
SizeT NumVars = Src->getNumVars(); SizeT NumVars = Src->getNumVars();
for (SizeT J = 0; J < NumVars; ++J) { for (SizeT J = 0; J < NumVars; ++J) {
const Variable *Var = Src->getVar(J); const Variable *Var = Src->getVar(J);
if (Instr->isLastUse(Var) && bool ShouldEmit = Instr->isLastUse(Var);
(!Var->hasReg() || --LiveRegCount[Var->getRegNum()] == 0)) { if (Var->hasReg()) {
// Don't report end of live range until the live count reaches 0.
SizeT NewCount = --LiveRegCount[Var->getRegNum()];
if (NewCount)
ShouldEmit = false;
}
if (ShouldEmit) {
if (First) if (First)
Str << " \t# END="; Str << " \t# END=";
else else
...@@ -884,12 +900,8 @@ void CfgNode::emit(Cfg *Func) const { ...@@ -884,12 +900,8 @@ void CfgNode::emit(Cfg *Func) const {
for (const Inst &I : Insts) { for (const Inst &I : Insts) {
if (I.isDeleted()) if (I.isDeleted())
continue; continue;
if (I.isRedundantAssign()) { if (I.isRedundantAssign())
Variable *Dest = I.getDest();
if (DecorateAsm && Dest->hasReg() && !I.isLastUse(I.getSrc(0)))
++LiveRegCount[Dest->getRegNum()];
continue; continue;
}
I.emit(Func); I.emit(Func);
if (DecorateAsm) if (DecorateAsm)
emitLiveRangesEnded(Str, Func, &I, LiveRegCount); emitLiveRangesEnded(Str, Func, &I, LiveRegCount);
......
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