Commit ca5ea2e2 authored by Chen, Weiyu's avatar Chen, Weiyu Committed by gbsbuild

Fix a bug in hierarhical IPA when computing def-in/def-out

Change-Id: I8180b88e36ffd3f8a82d060f227559c582454320
parent 9b202cf0
......@@ -1568,11 +1568,13 @@ void LivenessAnalysis::defAnalysis(FuncInfo* subroutine)
auto phyPredBB = (bb == fg.getEntryBB()) ? nullptr : bb->getPhysicalPred();
if (phyPredBB && (phyPredBB->getBBType() & G4_BB_CALL_TYPE))
{
// this is the return BB
// this is the return BB, we take the def_out of the callBB + the predecessors
G4_BB* callBB = bb->getPhysicalPred();
G4_BB* calleeExitBB = bb->Preds.front();
def_in[bbid] |= def_out[callBB->getId()];
def_in[bbid] |= def_out[calleeExitBB->getId()];
for (auto&& pred : bb->Preds)
{
def_in[bbid] |= def_out[pred->getId()];
}
}
else if (bb->getBBType() & G4_BB_INIT_TYPE)
{
......@@ -1585,6 +1587,7 @@ void LivenessAnalysis::defAnalysis(FuncInfo* subroutine)
def_in[bbid] |= def_out[pred->getId()];
}
}
if (def_in[bbid] != oldDefIn)
{
changed = true;
......@@ -1694,6 +1697,46 @@ void LivenessAnalysis::hierarchicalIPA(const BitSet& kernelInput, const BitSet&
}
}
maydefAnalysis(); // must be done before defAnalysis!
// algorithm sketch for def-in/def-out:
// In reverse topological order :
// -- Run def analysis on subroutine
// -- at each call site:
// def_in[ret-BB] |= def_out[call-BB] U def_out[exit-BB]
// In topological order :
// -- At each call site:
// add def_out[call-BB] to all of callee's BBs
def_in[fg.getEntryBB()->getId()] = kernelInput;
for (auto FI = fg.sortedFuncTable.begin(), FE = fg.sortedFuncTable.end(); FI != FE; ++FI)
{
auto subroutine = *FI;
defAnalysis(subroutine);
}
// FIXME: I assume we consider all caller's defs to be callee's defs too?
for (auto FI = fg.sortedFuncTable.rbegin(), FE = fg.sortedFuncTable.rend(); FI != FE; ++FI)
{
auto subroutine = *FI;
if (subroutine->getCallees().size() == 0)
{
continue;
}
for (auto&& bb : subroutine->getBBList())
{
if (bb->getBBType() & G4_BB_CALL_TYPE)
{
auto callee = bb->getCalleeInfo();
for (auto&& calleeBB : callee->getBBList())
{
def_in[calleeBB->getId()] |= def_out[bb->getId()];
def_out[calleeBB->getId()] |= def_out[bb->getId()];
}
}
}
}
#if 0
std::vector<G4_Declare*> idToDecl;
idToDecl.resize(numVarId);
......@@ -1720,7 +1763,7 @@ void LivenessAnalysis::hierarchicalIPA(const BitSet& kernelInput, const BitSet&
};
subroutine->dump();
if (subroutine != fg.kernelInfo)
{
std::cerr << "\tArgs: ";
......@@ -1734,60 +1777,16 @@ void LivenessAnalysis::hierarchicalIPA(const BitSet& kernelInput, const BitSet&
BitSet liveThrough = use_in[subroutine->getInitBB()->getId()];
liveThrough &= use_out[subroutine->getExitBB()->getId()];
printVal(liveThrough);
//std::cerr << "\n";
//std::cerr << "\tDef in: ";
//printVal(def_in[subroutine->getInitBB()->getId()]);
//std::cerr << "\n";
//std::cerr << "\tDef out: ";
//printVal(def_out[subroutine->getInitBB()->getId()]);
std::cerr << "\n";
}
}
#endif
maydefAnalysis(); // must be done before defAnalysis!
// algorithm sketch for def-in/def-out:
// In reverse topological order :
// -- Run def analysis on subroutine
// -- at each call site:
// def_in[ret-BB] |= def_out[call-BB] U def_out[exit-BB]
// In topological order :
// -- At each call site:
// add def_out[call-BB] to all of callee's BBs
def_in[fg.getEntryBB()->getId()] = kernelInput;
for (auto FI = fg.sortedFuncTable.begin(), FE = fg.sortedFuncTable.end(); FI != FE; ++FI)
{
auto subroutine = *FI;
defAnalysis(subroutine);
}
// FIXME: I assume we consider all caller's defs to be callee's defs too?
for (auto FI = fg.sortedFuncTable.rbegin(), FE = fg.sortedFuncTable.rend(); FI != FE; ++FI)
{
auto subroutine = *FI;
if (subroutine->getCallees().size() == 0)
{
continue;
}
for (auto&& bb : subroutine->getBBList())
{
if (bb->getBBType() & G4_BB_CALL_TYPE)
{
auto callee = bb->getCalleeInfo();
for (auto&& calleeBB : callee->getBBList())
{
def_in[calleeBB->getId()] |= def_out[bb->getId()];
def_out[calleeBB->getId()] |= def_out[bb->getId()];
}
}
}
}
//
// dump vectors for debugging
//
#if 0
dump_bb_vector("DEF IN", fg.BBs, def_in);
dump_bb_vector("DEF OUT", fg.BBs, def_out);
dump_bb_vector("USE IN", fg.BBs, use_in);
dump_bb_vector("USE OUT", fg.BBs, use_out);
#endif
}
//
......
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