[llvm-branch-commits] [llvm-branch] r100701 - /llvm/branches/ggreif/CallInst-operands/lib/Analysis/AliasAnalysisEvaluator.cpp

Gabor Greif ggreif at gmail.com
Wed Apr 7 15:30:41 PDT 2010


Author: ggreif
Date: Wed Apr  7 17:30:41 2010
New Revision: 100701

URL: http://llvm.org/viewvc/llvm-project?rev=100701&view=rev
Log:
Rewrite pointer gatherer to not make hidden
assumptions on where the callee is in a CallInst/InvokeInst.

Do not consider successor BasicBlocks in InvokeInsts.

The algorithm looks a bit more tidy this way :-)

Modified:
    llvm/branches/ggreif/CallInst-operands/lib/Analysis/AliasAnalysisEvaluator.cpp

Modified: llvm/branches/ggreif/CallInst-operands/lib/Analysis/AliasAnalysisEvaluator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/CallInst-operands/lib/Analysis/AliasAnalysisEvaluator.cpp?rev=100701&r1=100700&r2=100701&view=diff
==============================================================================
--- llvm/branches/ggreif/CallInst-operands/lib/Analysis/AliasAnalysisEvaluator.cpp (original)
+++ llvm/branches/ggreif/CallInst-operands/lib/Analysis/AliasAnalysisEvaluator.cpp Wed Apr  7 17:30:41 2010
@@ -108,6 +108,11 @@
   }
 }
 
+static inline bool isProperPointer(Value *V) {
+  return V->getType()->isPointerTy()
+      && !isa<ConstantPointerNull>(V);
+}
+
 bool AAEval::runOnFunction(Function &F) {
   AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
 
@@ -115,21 +120,31 @@
   SetVector<CallSite> CallSites;
 
   for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
-    if (I->getType()->isPointerTy())    // Add all pointer arguments
+    if (I->getType()->isPointerTy())    // Add all pointer arguments.
       Pointers.insert(I);
 
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
-    if (I->getType()->isPointerTy()) // Add all pointer instructions
+    if (I->getType()->isPointerTy()) // Add all pointer instructions.
       Pointers.insert(&*I);
     Instruction &Inst = *I;
-    User::op_iterator OI = Inst.op_begin();
     CallSite CS = CallSite::get(&Inst);
-    if (CS.getInstruction() &&
-        isa<Function>(CS.getCalledValue()))
-      ++OI;  // Skip actual functions for direct function calls.
-    for (; OI != Inst.op_end(); ++OI)
-      if ((*OI)->getType()->isPointerTy() && !isa<ConstantPointerNull>(*OI))
-        Pointers.insert(*OI);
+    if (CS) {
+      Value *Callee = CS.getCalledValue();
+      // Skip actual functions for direct function calls.
+      if (!isa<Function>(Callee) && isProperPointer(Callee))
+        Pointers.insert(Callee);
+      // Consider formals.
+      for (CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
+           AI != AE; ++AI)
+        if (isProperPointer(*AI))
+          Pointers.insert(*AI);
+    } else {
+      // Consider all operands.
+      for (Instruction::op_iterator OI = Inst.op_begin(), OE = Inst.op_end();
+           OI != OE; ++OI)
+        if (isProperPointer(*OI))
+          Pointers.insert(*OI);
+    }
 
     if (CS.getInstruction()) CallSites.insert(CS);
   }





More information about the llvm-branch-commits mailing list