#include "llvm/Module.h"
#include "Support/Statistic.h"
-namespace {
- Statistic<> NumNoAlias ("steens", "Number of 'no alias' replies");
- Statistic<> NumMayAlias ("steens", "Number of 'may alias' replies");
-};
-
namespace {
class Steens : public Pass, public AliasAnalysis {
DSGraph *ResultGraph;
// Register the pass...
RegisterOpt<Steens> X("steens-aa",
- "Steensgaard's FlowInsensitive/ConIns alias analysis");
+ "Steensgaard's alias analysis (DSGraph based)");
// Register as an implementation of AliasAnalysis
RegisterAnalysisGroup<AliasAnalysis, Steens> Y;
if (I != ValMap.end()) // If its a pointer argument...
I->second.mergeWith(Call.getPtrArg(PtrArgIdx++));
}
-
- assert(PtrArgIdx == Call.getNumPtrArgs() && "Argument resolution mismatch!");
}
ResultGraph = new DSGraph();
GlobalsGraph = new DSGraph();
ResultGraph->setGlobalsGraph(GlobalsGraph);
+ ResultGraph->setPrintAuxCalls();
+
// RetValMap - Keep track of the return values for all functions that return
// valid pointers.
//
// Loop over the rest of the module, merging graphs for non-external functions
// into this graph.
//
+ unsigned Count = 0;
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isExternal()) {
hash_map<Value*, DSNodeHandle> ValMap;
for (hash_map<Value*, DSNodeHandle>::iterator I = ValMap.begin(),
E = ValMap.end(); I != E; ++I)
GVM[I->first].mergeWith(I->second);
+
+ if ((++Count & 1) == 0) // Prune nodes out every other time...
+ ResultGraph->removeTriviallyDeadNodes();
}
// FIXME: Must recalculate and use the Incomplete markers!!
DSCallSite &CurCall = Calls[i];
// Loop over the called functions, eliminating as many as possible...
- std::vector<GlobalValue*> CallTargets =
- CurCall.getCallee().getNode()->getGlobals();
+ std::vector<GlobalValue*> CallTargets;
+ if (CurCall.isDirectCall())
+ CallTargets.push_back(CurCall.getCalleeFunc());
+ else
+ CallTargets = CurCall.getCalleeNode()->getGlobals();
+
for (unsigned c = 0; c != CallTargets.size(); ) {
// If we can eliminate this function call, do so!
bool Eliminated = false;
ResolveFunctionCall(F, CurCall, RetValMap[F]);
Eliminated = true;
}
- if (Eliminated)
- CallTargets.erase(CallTargets.begin()+c);
- else
+ if (Eliminated) {
+ CallTargets[c] = CallTargets.back();
+ CallTargets.pop_back();
+ } else
++c; // Cannot eliminate this call, skip over it...
}
- if (CallTargets.empty()) // Eliminated all calls?
- Calls.erase(Calls.begin()+i); // Remove from call list...
- else
+ if (CallTargets.empty()) { // Eliminated all calls?
+ CurCall = Calls.back(); // Remove entry
+ Calls.pop_back();
+ } else
++i; // Skip this call site...
}
DSNodeHandle &V2H = J->second;
// If the two pointers point to different data structure graph nodes, they
// cannot alias!
- if (V1H.getNode() != V2H.getNode()) { // FIXME: Handle incompleteness!
- ++NumNoAlias;
+ if (V1H.getNode() != V2H.getNode()) // FIXME: Handle incompleteness!
return NoAlias;
- }
+
// FIXME: If the two pointers point to the same node, and the offsets are
// different, and the LinkIndex vector doesn't alias the section, then the
// two pointers do not alias. We need access size information for the two
}
}
- // Since Steensgaard cannot do any better, count it as a 'may alias'
- ++NumMayAlias;
-
// If we cannot determine alias properties based on our graph, fall back on
// some other AA implementation.
//