mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-05 11:17:53 +00:00
Switch to use the new interface for the EquivalenceClasses class, and fix
a bug involving SCC's who have multiple members that are part of an EC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20678 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -171,7 +171,7 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
|
|||||||
CallSite CS = CallSite::get(I->first);
|
CallSite CS = CallSite::get(I->first);
|
||||||
|
|
||||||
if (CS.getCalledFunction()) { // Direct call:
|
if (CS.getCalledFunction()) { // Direct call:
|
||||||
FuncECs.addElement(I->second); // -- Make sure function has equiv class
|
FuncECs.insert(I->second); // -- Make sure function has equiv class
|
||||||
FirstFunc = I->second; // -- First callee at this site
|
FirstFunc = I->second; // -- First callee at this site
|
||||||
} else { // Else indirect call
|
} else { // Else indirect call
|
||||||
// DEBUG(std::cerr << "CALLEE: " << I->second->getName()
|
// DEBUG(std::cerr << "CALLEE: " << I->second->getName()
|
||||||
@@ -186,11 +186,11 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
|
|||||||
DSGraph &TFG = CBU->getDSGraph(*thisFunc);
|
DSGraph &TFG = CBU->getDSGraph(*thisFunc);
|
||||||
DSNode *calleeNode = TFG.getNodeForValue(CS.getCalledValue()).getNode();
|
DSNode *calleeNode = TFG.getNodeForValue(CS.getCalledValue()).getNode();
|
||||||
OneCalledFunction[calleeNode] = FirstFunc;
|
OneCalledFunction[calleeNode] = FirstFunc;
|
||||||
FuncECs.addElement(I->second);
|
FuncECs.insert(I->second);
|
||||||
} else {
|
} else {
|
||||||
// This is not the first possible callee from a particular call site.
|
// This is not the first possible callee from a particular call site.
|
||||||
// Union the callee in with the other functions.
|
// Union the callee in with the other functions.
|
||||||
FuncECs.unionSetsWith(FirstFunc, I->second);
|
FuncECs.unionSets(FirstFunc, I->second);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
Function *thisFunc = LastInst->getParent()->getParent();
|
Function *thisFunc = LastInst->getParent()->getParent();
|
||||||
DSGraph &TFG = CBU->getDSGraph(*thisFunc);
|
DSGraph &TFG = CBU->getDSGraph(*thisFunc);
|
||||||
@@ -208,26 +208,31 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
|
|||||||
DSGraph& funcDSGraph = CBU->getDSGraph(*I->second);
|
DSGraph& funcDSGraph = CBU->getDSGraph(*I->second);
|
||||||
for (DSGraph::retnodes_iterator RI = funcDSGraph.retnodes_begin(),
|
for (DSGraph::retnodes_iterator RI = funcDSGraph.retnodes_begin(),
|
||||||
RE = funcDSGraph.retnodes_end(); RI != RE; ++RI)
|
RE = funcDSGraph.retnodes_end(); RI != RE; ++RI)
|
||||||
FuncECs.unionSetsWith(FirstFunc, RI->first);
|
FuncECs.unionSets(FirstFunc, RI->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that all of the equivalences have been built, merge the graphs for
|
// Now that all of the equivalences have been built, merge the graphs for
|
||||||
// each equivalence class.
|
// each equivalence class.
|
||||||
//
|
//
|
||||||
std::set<Function*> &leaderSet = FuncECs.getLeaderSet();
|
|
||||||
DEBUG(std::cerr << "\nIndirect Function Equivalence Sets:\n");
|
DEBUG(std::cerr << "\nIndirect Function Equivalence Sets:\n");
|
||||||
for (std::set<Function*>::iterator LI = leaderSet.begin(),
|
for (EquivalenceClasses<Function*>::iterator EQSI = FuncECs.begin(), E =
|
||||||
LE = leaderSet.end(); LI != LE; ++LI) {
|
FuncECs.end(); EQSI != E; ++EQSI) {
|
||||||
|
if (!EQSI->isLeader()) continue;
|
||||||
|
|
||||||
Function* LF = *LI;
|
EquivalenceClasses<Function*>::member_iterator SI =
|
||||||
const std::set<Function*>& EqClass = FuncECs.getEqClass(LF);
|
FuncECs.member_begin(EQSI);
|
||||||
|
assert(SI != FuncECs.member_end() && "Empty equiv set??");
|
||||||
|
EquivalenceClasses<Function*>::member_iterator SN = SI;
|
||||||
|
++SN;
|
||||||
|
if (SN == FuncECs.member_end())
|
||||||
|
continue; // Single function equivalence set, no merging to do.
|
||||||
|
|
||||||
|
Function* LF = *SI;
|
||||||
|
|
||||||
if (EqClass.size() > 1) {
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
DEBUG(std::cerr <<" Equivalence set for leader " <<LF->getName()<<" = ");
|
DEBUG(std::cerr <<" Equivalence set for leader " << LF->getName() <<" = ");
|
||||||
for (std::set<Function*>::const_iterator EqI = EqClass.begin(),
|
for (SN = SI; SN != FuncECs.member_end(); ++SN)
|
||||||
EqEnd = EqClass.end(); EqI != EqEnd; ++EqI)
|
DEBUG(std::cerr << " " << (*SN)->getName() << "," );
|
||||||
DEBUG(std::cerr << " " << (*EqI)->getName() << ",");
|
|
||||||
DEBUG(std::cerr << "\n");
|
DEBUG(std::cerr << "\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -239,9 +244,10 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
|
|||||||
// Record the argument nodes for use in merging later below.
|
// Record the argument nodes for use in merging later below.
|
||||||
std::vector<DSNodeHandle> ArgNodes;
|
std::vector<DSNodeHandle> ArgNodes;
|
||||||
|
|
||||||
for (Function::arg_iterator AI1 = LF->arg_begin(); AI1 != LF->arg_end(); ++AI1)
|
for (Function::arg_iterator AI = LF->arg_begin(), E = LF->arg_end();
|
||||||
if (DS::isPointerType(AI1->getType()))
|
AI != E; ++AI)
|
||||||
ArgNodes.push_back(MergedG.getNodeForValue(AI1));
|
if (DS::isPointerType(AI->getType()))
|
||||||
|
ArgNodes.push_back(MergedG.getNodeForValue(AI));
|
||||||
|
|
||||||
// Merge in the graphs of all other functions in this equiv. class. Note
|
// Merge in the graphs of all other functions in this equiv. class. Note
|
||||||
// that two or more functions may have the same graph, and it only needs
|
// that two or more functions may have the same graph, and it only needs
|
||||||
@@ -249,15 +255,12 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
|
|||||||
std::set<DSGraph*> GraphsMerged;
|
std::set<DSGraph*> GraphsMerged;
|
||||||
GraphsMerged.insert(&CBU->getDSGraph(*LF));
|
GraphsMerged.insert(&CBU->getDSGraph(*LF));
|
||||||
|
|
||||||
for (std::set<Function*>::const_iterator EqI = EqClass.begin(),
|
for (++SI; SI != FuncECs.member_end(); ++SI) {
|
||||||
E = EqClass.end(); EqI != E; ++EqI) {
|
Function *F = *SI;
|
||||||
Function *F = *EqI;
|
|
||||||
DSGraph *&FG = DSInfo[F];
|
DSGraph *&FG = DSInfo[F];
|
||||||
|
|
||||||
DSGraph &CBUGraph = CBU->getDSGraph(*F);
|
DSGraph &CBUGraph = CBU->getDSGraph(*F);
|
||||||
if (!GraphsMerged.insert(&CBUGraph).second)
|
if (GraphsMerged.insert(&CBUGraph).second) {
|
||||||
continue;
|
|
||||||
|
|
||||||
// Record the "folded" graph for the function.
|
// Record the "folded" graph for the function.
|
||||||
for (DSGraph::retnodes_iterator I = CBUGraph.retnodes_begin(),
|
for (DSGraph::retnodes_iterator I = CBUGraph.retnodes_begin(),
|
||||||
E = CBUGraph.retnodes_end(); I != E; ++I) {
|
E = CBUGraph.retnodes_end(); I != E; ++I) {
|
||||||
@@ -266,10 +269,12 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clone this member of the equivalence class into MergedG.
|
// Clone this member of the equivalence class into MergedG.
|
||||||
|
{
|
||||||
DSGraph::NodeMapTy NodeMap;
|
DSGraph::NodeMapTy NodeMap;
|
||||||
|
|
||||||
MergedG.cloneInto(CBUGraph, MergedG.getScalarMap(),
|
MergedG.cloneInto(CBUGraph, MergedG.getScalarMap(),
|
||||||
MergedG.getReturnNodes(), NodeMap, 0);
|
MergedG.getReturnNodes(), NodeMap, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Merge the return nodes of all functions together.
|
// Merge the return nodes of all functions together.
|
||||||
MergedG.getReturnNodes()[LF].mergeWith(MergedG.getReturnNodes()[F]);
|
MergedG.getReturnNodes()[LF].mergeWith(MergedG.getReturnNodes()[F]);
|
||||||
@@ -277,7 +282,7 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
|
|||||||
// Merge the function arguments with all argument nodes found so far.
|
// Merge the function arguments with all argument nodes found so far.
|
||||||
// If there are extra function args, add them to the vector of argNodes
|
// If there are extra function args, add them to the vector of argNodes
|
||||||
Function::arg_iterator AI2 = F->arg_begin(), AI2end = F->arg_end();
|
Function::arg_iterator AI2 = F->arg_begin(), AI2end = F->arg_end();
|
||||||
for (unsigned arg=0, numArgs = ArgNodes.size();
|
for (unsigned arg = 0, numArgs = ArgNodes.size();
|
||||||
arg != numArgs && AI2 != AI2end; ++AI2, ++arg)
|
arg != numArgs && AI2 != AI2end; ++AI2, ++arg)
|
||||||
if (DS::isPointerType(AI2->getType()))
|
if (DS::isPointerType(AI2->getType()))
|
||||||
ArgNodes[arg].mergeWith(MergedG.getNodeForValue(AI2));
|
ArgNodes[arg].mergeWith(MergedG.getNodeForValue(AI2));
|
||||||
@@ -288,7 +293,6 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
|
|||||||
DEBUG(MergedG.AssertGraphOK());
|
DEBUG(MergedG.AssertGraphOK());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
DEBUG(std::cerr << "\n");
|
DEBUG(std::cerr << "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user