[llvm-commits] [poolalloc] r128653 - /poolalloc/trunk/lib/DSA/StdLibPass.cpp
Arushi Aggarwal
aggarwa4 at illinois.edu
Thu Mar 31 11:42:36 PDT 2011
Author: aggarwa4
Date: Thu Mar 31 13:42:36 2011
New Revision: 128653
URL: http://llvm.org/viewvc/llvm-project?rev=128653&view=rev
Log:
Move the processing into a separate function.
Modified:
poolalloc/trunk/lib/DSA/StdLibPass.cpp
Modified: poolalloc/trunk/lib/DSA/StdLibPass.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/StdLibPass.cpp?rev=128653&r1=128652&r2=128653&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/StdLibPass.cpp (original)
+++ poolalloc/trunk/lib/DSA/StdLibPass.cpp Thu Mar 31 13:42:36 2011
@@ -431,85 +431,198 @@
//
// Scan through the function summaries and process functions by summary.
//
- for (int x = 0; recFuncs[x].name; ++x)
+ for (int x = 0; recFuncs[x].name; ++x)
if (Function* F = M.getFunction(recFuncs[x].name))
if (F->isDeclaration()) {
- for (Value::use_iterator ii = F->use_begin(), ee = F->use_end();
- ii != ee; ++ii)
- if (CallInst* CI = dyn_cast<CallInst>(ii)){
- if (CI->getOperand(0) == F) {
- DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
+ processFunction(x, F);
+ }
- //
- // Set the read, write, and heap markers on the return value
- // as appropriate.
- //
- if(isa<PointerType>((CI)->getType())){
- if(Graph->hasNodeForValue(CI)){
- if (recFuncs[x].action.read[0])
- Graph->getNodeForValue(CI).getNode()->setReadMarker();
- if (recFuncs[x].action.write[0])
- Graph->getNodeForValue(CI).getNode()->setModifiedMarker();
- if (recFuncs[x].action.heap[0])
- Graph->getNodeForValue(CI).getNode()->setHeapMarker();
- }
+ //
+ // Merge return values and checked pointer values for SAFECode run-time
+ // checks.
+ //
+ processRuntimeCheck (M, "sc.boundscheck", 3);
+ processRuntimeCheck (M, "sc.boundscheckui", 3);
+ processRuntimeCheck (M, "sc.exactcheck2", 2);
+ processRuntimeCheck (M, "sc.get_actual_val", 2);
+
+ //
+ // In the Local DSA Pass, we marked nodes passed to/returned from 'StdLib'
+ // functions as External because, at that point, they were. However, they no
+ // longer are necessarily External, and we need to update accordingly.
+ //
+ GlobalsGraph->computeExternalFlags(DSGraph::ResetExternal);
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ if (!I->isDeclaration()) {
+ DSGraph * G = getDSGraph(*I);
+ unsigned EFlags = 0
+ | DSGraph::ResetExternal
+ | DSGraph::DontMarkFormalsExternal
+ | DSGraph::ProcessCallSites;
+ G->computeExternalFlags(EFlags);
+ DEBUG(G->AssertGraphOK());
+ }
+ GlobalsGraph->computeExternalFlags(DSGraph::ProcessCallSites);
+ DEBUG(GlobalsGraph->AssertGraphOK());
+
+ return false;
+}
+
+
+void StdLibDataStructures::processFunction(int x, Function *F) {
+ for (Value::use_iterator ii = F->use_begin(), ee = F->use_end();
+ ii != ee; ++ii)
+ if (CallInst* CI = dyn_cast<CallInst>(ii)){
+ if (CI->getOperand(0) == F) {
+ DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
+
+ //
+ // Set the read, write, and heap markers on the return value
+ // as appropriate.
+ //
+ if(isa<PointerType>((CI)->getType())){
+ if(Graph->hasNodeForValue(CI)){
+ if (recFuncs[x].action.read[0])
+ Graph->getNodeForValue(CI).getNode()->setReadMarker();
+ if (recFuncs[x].action.write[0])
+ Graph->getNodeForValue(CI).getNode()->setModifiedMarker();
+ if (recFuncs[x].action.heap[0])
+ Graph->getNodeForValue(CI).getNode()->setHeapMarker();
+ }
+ }
+
+ //
+ // Set the read, write, and heap markers on the actual arguments
+ // as appropriate.
+ //
+ for (unsigned y = 1; y < CI->getNumOperands(); ++y)
+ if (isa<PointerType>(CI->getOperand(y)->getType())){
+ if (Graph->hasNodeForValue(CI->getOperand(y))){
+ if (recFuncs[x].action.read[y])
+ Graph->getNodeForValue(CI->getOperand(y)).getNode()->setReadMarker();
+ if (recFuncs[x].action.write[y])
+ Graph->getNodeForValue(CI->getOperand(y)).getNode()->setModifiedMarker();
+ if (recFuncs[x].action.heap[y])
+ Graph->getNodeForValue(CI->getOperand(y)).getNode()->setHeapMarker();
+ }
+ }
+
+ //
+ // Merge the DSNoes for return values and parameters as
+ // appropriate.
+ //
+ std::vector<DSNodeHandle> toMerge;
+ if (recFuncs[x].action.mergeNodes[0])
+ if (isa<PointerType>(CI->getType()))
+ if (Graph->hasNodeForValue(CI))
+ toMerge.push_back(Graph->getNodeForValue(CI));
+ for (unsigned y = 1; y < CI->getNumOperands(); ++y)
+ if (recFuncs[x].action.mergeNodes[y])
+ if (isa<PointerType>(CI->getOperand(y)->getType()))
+ if (Graph->hasNodeForValue(CI->getOperand(y)))
+ toMerge.push_back(Graph->getNodeForValue(CI->getOperand(y)));
+ for (unsigned y = 1; y < toMerge.size(); ++y)
+ toMerge[0].mergeWith(toMerge[y]);
+
+ //
+ // Collapse (fold) the DSNode of the return value and the actual
+ // arguments if directed to do so.
+ //
+ if (!noStdLibFold && recFuncs[x].action.collapse) {
+ if (isa<PointerType>(CI->getType())){
+ if (Graph->hasNodeForValue(CI))
+ Graph->getNodeForValue(CI).getNode()->foldNodeCompletely();
+ NumNodesFoldedInStdLib++;
+ }
+ for (unsigned y = 1; y < CI->getNumOperands(); ++y){
+ if (isa<PointerType>(CI->getOperand(y)->getType())){
+ if (Graph->hasNodeForValue(CI->getOperand(y))){
+ Graph->getNodeForValue(CI->getOperand(y)).getNode()->foldNodeCompletely();
+ NumNodesFoldedInStdLib++;
}
+ }
+ }
+ }
+ }
+ } else if (InvokeInst* CI = dyn_cast<InvokeInst>(ii)){
+ if (CI->getOperand(0) == F) {
+ DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
- //
- // Set the read, write, and heap markers on the actual arguments
- // as appropriate.
- //
- for (unsigned y = 1; y < CI->getNumOperands(); ++y)
- if (isa<PointerType>(CI->getOperand(y)->getType())){
- if (Graph->hasNodeForValue(CI->getOperand(y))){
- if (recFuncs[x].action.read[y])
- Graph->getNodeForValue(CI->getOperand(y)).getNode()->setReadMarker();
- if (recFuncs[x].action.write[y])
- Graph->getNodeForValue(CI->getOperand(y)).getNode()->setModifiedMarker();
- if (recFuncs[x].action.heap[y])
- Graph->getNodeForValue(CI->getOperand(y)).getNode()->setHeapMarker();
- }
- }
+ //
+ // Set the read, write, and heap markers on the return value
+ // as appropriate.
+ //
+ if(isa<PointerType>((CI)->getType())){
+ if(Graph->hasNodeForValue(CI)){
+ if (recFuncs[x].action.read[0])
+ Graph->getNodeForValue(CI).getNode()->setReadMarker();
+ if (recFuncs[x].action.write[0])
+ Graph->getNodeForValue(CI).getNode()->setModifiedMarker();
+ if (recFuncs[x].action.heap[0])
+ Graph->getNodeForValue(CI).getNode()->setHeapMarker();
+ }
+ }
- //
- // Merge the DSNoes for return values and parameters as
- // appropriate.
- //
- std::vector<DSNodeHandle> toMerge;
- if (recFuncs[x].action.mergeNodes[0])
- if (isa<PointerType>(CI->getType()))
- if (Graph->hasNodeForValue(CI))
- toMerge.push_back(Graph->getNodeForValue(CI));
- for (unsigned y = 1; y < CI->getNumOperands(); ++y)
- if (recFuncs[x].action.mergeNodes[y])
- if (isa<PointerType>(CI->getOperand(y)->getType()))
- if (Graph->hasNodeForValue(CI->getOperand(y)))
- toMerge.push_back(Graph->getNodeForValue(CI->getOperand(y)));
- for (unsigned y = 1; y < toMerge.size(); ++y)
- toMerge[0].mergeWith(toMerge[y]);
+ //
+ // Set the read, write, and heap markers on the actual arguments
+ // as appropriate.
+ //
+ for (unsigned y = 1; y < CI->getNumOperands(); ++y)
+ if (isa<PointerType>(CI->getOperand(y)->getType())){
+ if (Graph->hasNodeForValue(CI->getOperand(y))){
+ if (recFuncs[x].action.read[y])
+ Graph->getNodeForValue(CI->getOperand(y)).getNode()->setReadMarker();
+ if (recFuncs[x].action.write[y])
+ Graph->getNodeForValue(CI->getOperand(y)).getNode()->setModifiedMarker();
+ if (recFuncs[x].action.heap[y])
+ Graph->getNodeForValue(CI->getOperand(y)).getNode()->setHeapMarker();
+ }
+ }
- //
- // Collapse (fold) the DSNode of the return value and the actual
- // arguments if directed to do so.
- //
- if (!noStdLibFold && recFuncs[x].action.collapse) {
- if (isa<PointerType>(CI->getType())){
- if (Graph->hasNodeForValue(CI))
- Graph->getNodeForValue(CI).getNode()->foldNodeCompletely();
- NumNodesFoldedInStdLib++;
- }
- for (unsigned y = 1; y < CI->getNumOperands(); ++y){
- if (isa<PointerType>(CI->getOperand(y)->getType())){
- if (Graph->hasNodeForValue(CI->getOperand(y))){
- Graph->getNodeForValue(CI->getOperand(y)).getNode()->foldNodeCompletely();
- NumNodesFoldedInStdLib++;
- }
- }
- }
+ //
+ // Merge the DSNoes for return values and parameters as
+ // appropriate.
+ //
+ std::vector<DSNodeHandle> toMerge;
+ if (recFuncs[x].action.mergeNodes[0])
+ if (isa<PointerType>(CI->getType()))
+ if (Graph->hasNodeForValue(CI))
+ toMerge.push_back(Graph->getNodeForValue(CI));
+ for (unsigned y = 1; y < CI->getNumOperands(); ++y)
+ if (recFuncs[x].action.mergeNodes[y])
+ if (isa<PointerType>(CI->getOperand(y)->getType()))
+ if (Graph->hasNodeForValue(CI->getOperand(y)))
+ toMerge.push_back(Graph->getNodeForValue(CI->getOperand(y)));
+ for (unsigned y = 1; y < toMerge.size(); ++y)
+ toMerge[0].mergeWith(toMerge[y]);
+
+ //
+ // Collapse (fold) the DSNode of the return value and the actual
+ // arguments if directed to do so.
+ //
+ if (!noStdLibFold && recFuncs[x].action.collapse) {
+ if (isa<PointerType>(CI->getType())){
+ if (Graph->hasNodeForValue(CI))
+ Graph->getNodeForValue(CI).getNode()->foldNodeCompletely();
+ NumNodesFoldedInStdLib++;
+ }
+ for (unsigned y = 1; y < CI->getNumOperands(); ++y){
+ if (isa<PointerType>(CI->getOperand(y)->getType())){
+ if (Graph->hasNodeForValue(CI->getOperand(y))){
+ Graph->getNodeForValue(CI->getOperand(y)).getNode()->foldNodeCompletely();
+ NumNodesFoldedInStdLib++;
}
}
- } else if (InvokeInst* CI = dyn_cast<InvokeInst>(ii)){
- if (CI->getOperand(0) == F) {
+ }
+ }
+ }
+ } else if(ConstantExpr *CE = dyn_cast<ConstantExpr>(ii)) {
+ if(CE->isCast())
+ for (Value::use_iterator ci = CE->use_begin(), ce = CE->use_end();
+ ci != ce; ++ci) {
+
+ if (CallInst* CI = dyn_cast<CallInst>(ci)){
+ if (CI->getOperand(0) == CE) {
DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
//
@@ -532,13 +645,13 @@
// as appropriate.
//
for (unsigned y = 1; y < CI->getNumOperands(); ++y)
- if (isa<PointerType>(CI->getOperand(y)->getType())){
- if (Graph->hasNodeForValue(CI->getOperand(y))){
- if (recFuncs[x].action.read[y])
+ if (recFuncs[x].action.read[y]){
+ if (isa<PointerType>(CI->getOperand(y)->getType())){
+ if (Graph->hasNodeForValue(CI->getOperand(y)))
Graph->getNodeForValue(CI->getOperand(y)).getNode()->setReadMarker();
- if (recFuncs[x].action.write[y])
+ if (Graph->hasNodeForValue(CI->getOperand(y)))
Graph->getNodeForValue(CI->getOperand(y)).getNode()->setModifiedMarker();
- if (recFuncs[x].action.heap[y])
+ if (Graph->hasNodeForValue(CI->getOperand(y)))
Graph->getNodeForValue(CI->getOperand(y)).getNode()->setHeapMarker();
}
}
@@ -551,9 +664,9 @@
if (recFuncs[x].action.mergeNodes[0])
if (isa<PointerType>(CI->getType()))
if (Graph->hasNodeForValue(CI))
- toMerge.push_back(Graph->getNodeForValue(CI));
- for (unsigned y = 1; y < CI->getNumOperands(); ++y)
- if (recFuncs[x].action.mergeNodes[y])
+ toMerge.push_back(Graph->getNodeForValue(CI));
+ for (unsigned y = 1; y < CI->getNumOperands(); ++y)
+ if (recFuncs[x].action.mergeNodes[y])
if (isa<PointerType>(CI->getOperand(y)->getType()))
if (Graph->hasNodeForValue(CI->getOperand(y)))
toMerge.push_back(Graph->getNodeForValue(CI->getOperand(y)));
@@ -570,142 +683,33 @@
Graph->getNodeForValue(CI).getNode()->foldNodeCompletely();
NumNodesFoldedInStdLib++;
}
- for (unsigned y = 1; y < CI->getNumOperands(); ++y){
+ for (unsigned y = 1; y < CI->getNumOperands(); ++y)
if (isa<PointerType>(CI->getOperand(y)->getType())){
if (Graph->hasNodeForValue(CI->getOperand(y))){
- Graph->getNodeForValue(CI->getOperand(y)).getNode()->foldNodeCompletely();
+ DSNode * Node=Graph->getNodeForValue(CI->getOperand(y)).getNode();
+ Node->foldNodeCompletely();
NumNodesFoldedInStdLib++;
}
}
- }
}
}
- } else if(ConstantExpr *CE = dyn_cast<ConstantExpr>(ii)) {
- if(CE->isCast())
- for (Value::use_iterator ci = CE->use_begin(), ce = CE->use_end();
- ci != ce; ++ci) {
-
- if (CallInst* CI = dyn_cast<CallInst>(ci)){
- if (CI->getOperand(0) == CE) {
- DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
-
- //
- // Set the read, write, and heap markers on the return value
- // as appropriate.
- //
- if(isa<PointerType>((CI)->getType())){
- if(Graph->hasNodeForValue(CI)){
- if (recFuncs[x].action.read[0])
- Graph->getNodeForValue(CI).getNode()->setReadMarker();
- if (recFuncs[x].action.write[0])
- Graph->getNodeForValue(CI).getNode()->setModifiedMarker();
- if (recFuncs[x].action.heap[0])
- Graph->getNodeForValue(CI).getNode()->setHeapMarker();
- }
- }
-
- //
- // Set the read, write, and heap markers on the actual arguments
- // as appropriate.
- //
- for (unsigned y = 1; y < CI->getNumOperands(); ++y)
- if (recFuncs[x].action.read[y]){
- if (isa<PointerType>(CI->getOperand(y)->getType())){
- if (Graph->hasNodeForValue(CI->getOperand(y)))
- Graph->getNodeForValue(CI->getOperand(y)).getNode()->setReadMarker();
- if (Graph->hasNodeForValue(CI->getOperand(y)))
- Graph->getNodeForValue(CI->getOperand(y)).getNode()->setModifiedMarker();
- if (Graph->hasNodeForValue(CI->getOperand(y)))
- Graph->getNodeForValue(CI->getOperand(y)).getNode()->setHeapMarker();
- }
- }
-
- //
- // Merge the DSNoes for return values and parameters as
- // appropriate.
- //
- std::vector<DSNodeHandle> toMerge;
- if (recFuncs[x].action.mergeNodes[0])
- if (isa<PointerType>(CI->getType()))
- if (Graph->hasNodeForValue(CI))
- toMerge.push_back(Graph->getNodeForValue(CI));
- for (unsigned y = 1; y < CI->getNumOperands(); ++y)
- if (recFuncs[x].action.mergeNodes[y])
- if (isa<PointerType>(CI->getOperand(y)->getType()))
- if (Graph->hasNodeForValue(CI->getOperand(y)))
- toMerge.push_back(Graph->getNodeForValue(CI->getOperand(y)));
- for (unsigned y = 1; y < toMerge.size(); ++y)
- toMerge[0].mergeWith(toMerge[y]);
-
- //
- // Collapse (fold) the DSNode of the return value and the actual
- // arguments if directed to do so.
- //
- if (!noStdLibFold && recFuncs[x].action.collapse) {
- if (isa<PointerType>(CI->getType())){
- if (Graph->hasNodeForValue(CI))
- Graph->getNodeForValue(CI).getNode()->foldNodeCompletely();
- NumNodesFoldedInStdLib++;
- }
- for (unsigned y = 1; y < CI->getNumOperands(); ++y)
- if (isa<PointerType>(CI->getOperand(y)->getType())){
- if (Graph->hasNodeForValue(CI->getOperand(y))){
- DSNode * Node=Graph->getNodeForValue(CI->getOperand(y)).getNode();
- Node->foldNodeCompletely();
- NumNodesFoldedInStdLib++;
- }
- }
- }
- }
- }
- }
}
-
- //
- // Pretend that this call site does not call this function anymore.
- //
- eraseCallsTo(F);
- }
-
- //
- // Merge return values and checked pointer values for SAFECode run-time
- // checks.
- //
- processRuntimeCheck (M, "sc.boundscheck", 3);
- processRuntimeCheck (M, "sc.boundscheckui", 3);
- processRuntimeCheck (M, "sc.exactcheck2", 2);
- processRuntimeCheck (M, "sc.get_actual_val", 2);
+ }
+ }
//
- // In the Local DSA Pass, we marked nodes passed to/returned from 'StdLib'
- // functions as External because, at that point, they were. However, they no
- // longer are necessarily External, and we need to update accordingly.
+ // Pretend that this call site does not call this function anymore.
//
- GlobalsGraph->computeExternalFlags(DSGraph::ResetExternal);
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
- if (!I->isDeclaration()) {
- DSGraph * G = getDSGraph(*I);
- unsigned EFlags = 0
- | DSGraph::ResetExternal
- | DSGraph::DontMarkFormalsExternal
- | DSGraph::ProcessCallSites;
- G->computeExternalFlags(EFlags);
- DEBUG(G->AssertGraphOK());
- }
- GlobalsGraph->computeExternalFlags(DSGraph::ProcessCallSites);
- DEBUG(GlobalsGraph->AssertGraphOK());
-
- return false;
+ eraseCallsTo(F);
}
-
/*
- functions to add
- freopen
- strftime
- strtoul
- strtol
- strtoll
- ctype family
- open64/fopen64/lseek64
- */
+ functions to add
+ freopen
+ strftime
+ strtoul
+ strtol
+ strtoll
+ ctype family
+ open64/fopen64/lseek64
+ */
More information about the llvm-commits
mailing list