[llvm-commits] [poolalloc] r122440 - in /poolalloc/trunk: include/dsa/AddressTakenAnalysis.h include/dsa/DataStructure.h lib/DSA/AddressTakenAnalysis.cpp lib/DSA/Local.cpp

Arushi Aggarwal aggarwa4 at illinois.edu
Wed Dec 22 13:21:04 PST 2010


Author: aggarwa4
Date: Wed Dec 22 15:21:03 2010
New Revision: 122440

URL: http://llvm.org/viewvc/llvm-project?rev=122440&view=rev
Log:
Add an analysis pass to figure out which functions
are address taken. Query this pass in Local DSA.

Added:
    poolalloc/trunk/include/dsa/AddressTakenAnalysis.h
    poolalloc/trunk/lib/DSA/AddressTakenAnalysis.cpp
Modified:
    poolalloc/trunk/include/dsa/DataStructure.h
    poolalloc/trunk/lib/DSA/Local.cpp

Added: poolalloc/trunk/include/dsa/AddressTakenAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/AddressTakenAnalysis.h?rev=122440&view=auto
==============================================================================
--- poolalloc/trunk/include/dsa/AddressTakenAnalysis.h (added)
+++ poolalloc/trunk/include/dsa/AddressTakenAnalysis.h Wed Dec 22 15:21:03 2010
@@ -0,0 +1,48 @@
+//===-- AddressTakenAnalysis.h - Entry point Finding Pass -------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass helps find which functions are address taken in a module.
+// Functions are considered to be address taken if they are either stored,
+// or passed as arguments to functions.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ADDRESSTAKENANALYSIS_H
+#define	_ADDRESSTAKENANALYSIS_H
+
+namespace llvm {
+class Function;
+class Module;
+class Instruction;
+
+
+#include <string>
+#include "llvm/Pass.h"
+
+class AddressTakenAnalysis : public llvm::ModulePass {
+  std::set<Function*> addressTakenFunctions;
+public:
+  static char ID;
+  AddressTakenAnalysis();
+  virtual ~AddressTakenAnalysis();
+
+  bool runOnModule(llvm::Module&);
+
+  virtual void getAnalysisUsage(llvm::AnalysisUsage &Info) const;
+
+  bool hasAddressTaken(llvm::Function *);
+
+};
+
+}
+
+
+
+#endif	/* _ADDRESSTAKENANALYSIS_H */
+

Modified: poolalloc/trunk/include/dsa/DataStructure.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=122440&r1=122439&r2=122440&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Wed Dec 22 15:21:03 2010
@@ -22,6 +22,7 @@
 #include "dsa/DSCallGraph.h"
 #include "dsa/svset.h"
 #include "dsa/super_set.h"
+#include "dsa/AddressTakenAnalysis.h"
 
 #include <map>
 
@@ -174,6 +175,7 @@
 // be automatically preserved.  Until we can do that, this is a Pass.
 //
 class LocalDataStructures : public DataStructures {
+  AddressTakenAnalysis* addrAnalysis;
 public:
   static char ID;
   LocalDataStructures() : DataStructures((intptr_t)&ID, "local.") {}
@@ -185,6 +187,7 @@
   ///
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
     AU.addRequired<TargetData>();
+    AU.addRequired<AddressTakenAnalysis>();
     AU.setPreservesAll();
   }
 };

Added: poolalloc/trunk/lib/DSA/AddressTakenAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/AddressTakenAnalysis.cpp?rev=122440&view=auto
==============================================================================
--- poolalloc/trunk/lib/DSA/AddressTakenAnalysis.cpp (added)
+++ poolalloc/trunk/lib/DSA/AddressTakenAnalysis.cpp Wed Dec 22 15:21:03 2010
@@ -0,0 +1,82 @@
+//===-- AddressTakenAnalysis.cpp - Address Taken Functions Finding Pass ---===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass helps find which functions are address taken in a module.
+// Functions are considered to be address taken if they are either stored,
+// or passed as arguments to functions.
+// 
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Pass.h"
+#include "llvm/Module.h"
+#include "llvm/Function.h"
+#include "llvm/Instructions.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/CallSite.h"
+
+#include <fstream>
+#include <set>
+
+#include "dsa/AddressTakenAnalysis.h"
+
+using namespace llvm;
+
+
+AddressTakenAnalysis::AddressTakenAnalysis() :ModulePass(&ID) {
+}
+
+AddressTakenAnalysis::~AddressTakenAnalysis() {}
+
+static bool isAddressTaken(Value* V) {
+  for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
+    User *U = *I;
+    if (!isa<CallInst>(U) && !isa<InvokeInst>(U)) {
+      if(isa<GlobalAlias>(U)) {
+        if(isAddressTaken(U))
+          return true;
+      } else {
+        // FIXME handle bitcasts to see if the resultant value
+        // is ever used in an address taken fashion
+        return true;
+      }
+
+      // FIXME: Can be more robust here for weak aliases that 
+      // are never used
+    } else {
+      llvm::CallSite CS(cast<Instruction>(U));
+      if (!CS.isCallee(I)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+bool AddressTakenAnalysis::runOnModule(llvm::Module& M) {
+  for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI){
+    if(isAddressTaken(FI)) {
+      addressTakenFunctions.insert(FI);
+    }
+  }
+
+  return false;
+}
+bool AddressTakenAnalysis::hasAddressTaken(llvm::Function *F){
+  return addressTakenFunctions.find(F) != addressTakenFunctions.end();
+}
+
+void AddressTakenAnalysis::getAnalysisUsage(llvm::AnalysisUsage &AU) const {
+  AU.setPreservesAll();
+}
+
+char AddressTakenAnalysis::ID;
+static RegisterPass<AddressTakenAnalysis> A("ata", "Identify Address Taken Functions");

Modified: poolalloc/trunk/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Local.cpp?rev=122440&r1=122439&r2=122440&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Local.cpp (original)
+++ poolalloc/trunk/lib/DSA/Local.cpp Wed Dec 22 15:21:03 2010
@@ -1180,6 +1180,7 @@
 
 bool LocalDataStructures::runOnModule(Module &M) {
   init(&getAnalysis<TargetData>());
+  addrAnalysis = &getAnalysis<AddressTakenAnalysis>();
 
   // First step, build the globals graph.
   {
@@ -1197,7 +1198,7 @@
     // Add Functions to the globals graph.
     // FIXME: Write a separate pass to handle address taken property better.
     for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI){
-      if(FI->hasAddressTaken()) {
+      if(addrAnalysis->hasAddressTaken(FI)) {
           GGB.mergeFunction(FI);
       }
     }





More information about the llvm-commits mailing list