Do not use typeinfo to identify pass in pass manager.
[oota-llvm.git] / lib / Transforms / Instrumentation / EdgeProfiling.cpp
index 40a8faaf507f4682a5af209a05f41c634158b618..ff7d4270ba492244c7a7975cede5151a3a4f4247 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#include "ProfilingUtils.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Instrumentation.h"
-#include "ProfilingUtils.h"
 #include <set>
 using namespace llvm;
 
 namespace {
-  class EdgeProfiler : public ModulePass {
+  class VISIBILITY_HIDDEN EdgeProfiler : public ModulePass {
     bool runOnModule(Module &M);
+  public:
+    static const int ID; // Pass identifcation, replacement for typeid
+    EdgeProfiler() : ModulePass((intptr_t)&ID) {}
   };
 
+  const int EdgeProfiler::ID = 0;
   RegisterPass<EdgeProfiler> X("insert-edge-profiling",
                                "Insert instrumentation for edge profiling");
 }
@@ -40,10 +45,10 @@ namespace {
 ModulePass *llvm::createEdgeProfilerPass() { return new EdgeProfiler(); }
 
 bool EdgeProfiler::runOnModule(Module &M) {
-  Function *Main = M.getMainFunction();
+  Function *Main = M.getFunction("main");
   if (Main == 0) {
-    llvm_cerr << "WARNING: cannot insert edge profiling into a module"
-              << " with no main function!\n";
+    cerr << "WARNING: cannot insert edge profiling into a module"
+         << " with no main function!\n";
     return false;  // No main, no instrumentation!
   }
 
@@ -58,7 +63,7 @@ bool EdgeProfiler::runOnModule(Module &M) {
       NumEdges += BB->getTerminator()->getNumSuccessors();
     }
 
-  const Type *ATy = ArrayType::get(Type::UIntTy, NumEdges);
+  const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges);
   GlobalVariable *Counters =
     new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
                        Constant::getNullValue(ATy), "EdgeProfCounters", &M);