Add a new MergeFunctions pass. It finds identical functions and merges them.
[oota-llvm.git] / lib / Analysis / AliasAnalysisEvaluator.cpp
index f2631cb8ba658106562fd448922ac0f7a4612d6c..c7a86d3506fc3e92a9dadf80409692f2aa3111a8 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     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 file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Streams.h"
 #include <set>
+#include <sstream>
 using namespace llvm;
 
-namespace {
-  cl::opt<bool> PrintAll("print-all-alias-modref-info", cl::ReallyHidden);
+static cl::opt<bool> PrintAll("print-all-alias-modref-info", cl::ReallyHidden);
 
-  cl::opt<bool> PrintNoAlias("print-no-aliases", cl::ReallyHidden);
-  cl::opt<bool> PrintMayAlias("print-may-aliases", cl::ReallyHidden);
-  cl::opt<bool> PrintMustAlias("print-must-aliases", cl::ReallyHidden);
+static cl::opt<bool> PrintNoAlias("print-no-aliases", cl::ReallyHidden);
+static cl::opt<bool> PrintMayAlias("print-may-aliases", cl::ReallyHidden);
+static cl::opt<bool> PrintMustAlias("print-must-aliases", cl::ReallyHidden);
 
-  cl::opt<bool> PrintNoModRef("print-no-modref", cl::ReallyHidden);
-  cl::opt<bool> PrintMod("print-mod", cl::ReallyHidden);
-  cl::opt<bool> PrintRef("print-ref", cl::ReallyHidden);
-  cl::opt<bool> PrintModRef("print-modref", cl::ReallyHidden);
+static cl::opt<bool> PrintNoModRef("print-no-modref", cl::ReallyHidden);
+static cl::opt<bool> PrintMod("print-mod", cl::ReallyHidden);
+static cl::opt<bool> PrintRef("print-ref", cl::ReallyHidden);
+static cl::opt<bool> PrintModRef("print-modref", cl::ReallyHidden);
 
+namespace {
   class VISIBILITY_HIDDEN AAEval : public FunctionPass {
     unsigned NoAlias, MayAlias, MustAlias;
     unsigned NoModRef, Mod, Ref, ModRef;
 
   public:
-    static const int ID; // Pass identifcation, replacement for typeid
-    AAEval() : FunctionPass((intptr_t)&ID) {}
+    static char ID; // Pass identification, replacement for typeid
+    AAEval() : FunctionPass(&ID) {}
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.addRequired<AliasAnalysis>();
@@ -72,20 +73,26 @@ namespace {
     bool runOnFunction(Function &F);
     bool doFinalization(Module &M);
   };
-
-  const int AAEval::ID = 0;
-  RegisterPass<AAEval>
-  X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator");
 }
 
+char AAEval::ID = 0;
+static RegisterPass<AAEval>
+X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator", false, true);
+
 FunctionPass *llvm::createAAEvalPass() { return new AAEval(); }
 
-static inline void PrintResults(const char *Msg, bool P, Value *V1, Value *V2,
-                                Module *M) {
+static void PrintResults(const char *Msg, bool P, const Value *V1, const Value *V2,
+                         const Module *M) {
   if (P) {
-    cerr << "  " << Msg << ":\t";
-    WriteAsOperand(*cerr.stream(), V1, true, M) << ", ";
-    WriteAsOperand(*cerr.stream(), V2, true, M) << "\n";
+    std::stringstream s1, s2;
+    WriteAsOperand(s1, V1, true, M);
+    WriteAsOperand(s2, V2, true, M);
+    std::string o1(s1.str()), o2(s2.str());
+    if (o2 < o1)
+        std::swap(o1, o2);
+    cerr << "  " << Msg << ":\t"
+         << o1 << ", "
+         << o2 << "\n";
   }
 }
 
@@ -137,12 +144,12 @@ bool AAEval::runOnFunction(Function &F) {
        I1 != E; ++I1) {
     unsigned I1Size = 0;
     const Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType();
-    if (I1ElTy->isSized()) I1Size = TD.getTypeSize(I1ElTy);
+    if (I1ElTy->isSized()) I1Size = TD.getTypeStoreSize(I1ElTy);
 
     for (std::set<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
       unsigned I2Size = 0;
       const Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType();
-      if (I2ElTy->isSized()) I2Size = TD.getTypeSize(I2ElTy);
+      if (I2ElTy->isSized()) I2Size = TD.getTypeStoreSize(I2ElTy);
 
       switch (AA.alias(*I1, I1Size, *I2, I2Size)) {
       case AliasAnalysis::NoAlias:
@@ -169,7 +176,7 @@ bool AAEval::runOnFunction(Function &F) {
          V != Ve; ++V) {
       unsigned Size = 0;
       const Type *ElTy = cast<PointerType>((*V)->getType())->getElementType();
-      if (ElTy->isSized()) Size = TD.getTypeSize(ElTy);
+      if (ElTy->isSized()) Size = TD.getTypeStoreSize(ElTy);
 
       switch (AA.getModRefInfo(*C, *V, Size)) {
       case AliasAnalysis::NoModRef: