Add a clear() method to PriorityQueue.
[oota-llvm.git] / lib / Transforms / IPO / IndMemRemoval.cpp
index eeddad71a9795e66d97305ba2cf9f6f5ae4aed8f..84483748594b89ac74a5cadb0b45a5fed2bb3f5a 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.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -32,11 +32,16 @@ STATISTIC(NumBounce     , "Number of bounce functions created");
 namespace {
   class VISIBILITY_HIDDEN IndMemRemPass : public ModulePass {
   public:
+    static char ID; // Pass identification, replacement for typeid
+    IndMemRemPass() : ModulePass((intptr_t)&ID) {}
+
     virtual bool runOnModule(Module &M);
   };
-  RegisterPass<IndMemRemPass> X("indmemrem","Indirect Malloc and Free Removal");
 } // end anonymous namespace
 
+char IndMemRemPass::ID = 0;
+static RegisterPass<IndMemRemPass>
+X("indmemrem","Indirect Malloc and Free Removal");
 
 bool IndMemRemPass::runOnModule(Module &M) {
   //in Theory, all direct calls of malloc and free should be promoted
@@ -48,11 +53,11 @@ bool IndMemRemPass::runOnModule(Module &M) {
   if (Function* F = M.getFunction("free")) {
     assert(F->isDeclaration() && "free not external?");
     if (!F->use_empty()) {
-      Function* FN = new Function(F->getFunctionType(), 
-                                  GlobalValue::LinkOnceLinkage, 
-                                  "free_llvm_bounce", &M);
-      BasicBlock* bb = new BasicBlock("entry",FN);
-      Instruction* R = new ReturnInst(bb);
+      Function* FN = Function::Create(F->getFunctionType(),
+                                      GlobalValue::LinkOnceLinkage,
+                                      "free_llvm_bounce", &M);
+      BasicBlock* bb = BasicBlock::Create("entry",FN);
+      Instruction* R = ReturnInst::Create(bb);
       new FreeInst(FN->arg_begin(), R);
       ++NumBounce;
       NumBounceSites += F->getNumUses();
@@ -63,14 +68,14 @@ bool IndMemRemPass::runOnModule(Module &M) {
   if (Function* F = M.getFunction("malloc")) {
     assert(F->isDeclaration() && "malloc not external?");
     if (!F->use_empty()) {
-      Function* FN = new Function(F->getFunctionType(), 
-                                  GlobalValue::LinkOnceLinkage, 
-                                  "malloc_llvm_bounce", &M);
-      BasicBlock* bb = new BasicBlock("entry",FN);
-      Instruction* c = CastInst::createIntegerCast(
+      Function* FN = Function::Create(F->getFunctionType(), 
+                                      GlobalValue::LinkOnceLinkage, 
+                                      "malloc_llvm_bounce", &M);
+      BasicBlock* bb = BasicBlock::Create("entry",FN);
+      Instruction* c = CastInst::CreateIntegerCast(
           FN->arg_begin(), Type::Int32Ty, false, "c", bb);
       Instruction* a = new MallocInst(Type::Int8Ty, c, "m", bb);
-      new ReturnInst(a, bb);
+      ReturnInst::Create(a, bb);
       ++NumBounce;
       NumBounceSites += F->getNumUses();
       F->replaceAllUsesWith(FN);