fix pasto
[oota-llvm.git] / lib / Transforms / IPO / RaiseAllocations.cpp
index 7b338b1d1d0ba063fc8f55d2fb8b8a9d131180fb..e28400924738b4fe1133bdc1612257b4506e026b 100644 (file)
@@ -1,9 +1,9 @@
-//===- RaiseAllocations.cpp - Convert %malloc & %free calls to insts ------===//
+//===- RaiseAllocations.cpp - Convert @malloc & @free calls to insts ------===//
 //
 //                     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.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -28,14 +28,14 @@ using namespace llvm;
 STATISTIC(NumRaised, "Number of allocations raised");
 
 namespace {
-  // RaiseAllocations - Turn %malloc and %free calls into the appropriate
+  // RaiseAllocations - Turn @malloc and @free calls into the appropriate
   // instruction.
   //
   class VISIBILITY_HIDDEN RaiseAllocations : public ModulePass {
     Function *MallocFunc;   // Functions in the module we are processing
     Function *FreeFunc;     // Initialized by doPassInitializationVirt
   public:
-    static const char ID; // Pass identifcation, replacement for typeid
+    static char ID; // Pass identification, replacement for typeid
     RaiseAllocations() 
       : ModulePass((intptr_t)&ID), MallocFunc(0), FreeFunc(0) {}
 
@@ -49,7 +49,7 @@ namespace {
     bool runOnModule(Module &M);
   };
 
-  const char RaiseAllocations::ID = 0;
+  char RaiseAllocations::ID = 0;
   RegisterPass<RaiseAllocations>
   X("raiseallocs", "Raise allocations from calls to instructions");
 }  // end anonymous namespace
@@ -65,7 +65,7 @@ ModulePass *llvm::createRaiseAllocationsPass() {
 // free functions.  If this is the case, grab the method pointers that the
 // module is using.
 //
-// Lookup %malloc and %free in the symbol table, for later use.  If they don't
+// Lookup @malloc and @free in the symbol table, for later use.  If they don't
 // exist, or are not external, we do not worry about converting calls to that
 // function into the appropriate instruction.
 //
@@ -78,7 +78,7 @@ void RaiseAllocations::doInitialization(Module &M) {
 
     // Get the expected prototype for malloc
     const FunctionType *Malloc1Type = 
-      FunctionType::get(PointerType::get(Type::Int8Ty),
+      FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
                       std::vector<const Type*>(1, Type::Int64Ty), false);
 
     // Chck to see if we got the expected malloc
@@ -86,14 +86,14 @@ void RaiseAllocations::doInitialization(Module &M) {
       // Check to see if the prototype is wrong, giving us sbyte*(uint) * malloc
       // This handles the common declaration of: 'void *malloc(unsigned);'
       const FunctionType *Malloc2Type = 
-        FunctionType::get(PointerType::get(Type::Int8Ty),
+        FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
                           std::vector<const Type*>(1, Type::Int32Ty), false);
       if (TyWeHave != Malloc2Type) {
         // Check to see if the prototype is missing, giving us 
         // sbyte*(...) * malloc
         // This handles the common declaration of: 'void *malloc();'
         const FunctionType *Malloc3Type = 
-          FunctionType::get(PointerType::get(Type::Int8Ty),
+          FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
                             std::vector<const Type*>(), true);
         if (TyWeHave != Malloc3Type)
           // Give up
@@ -108,7 +108,7 @@ void RaiseAllocations::doInitialization(Module &M) {
     
     // Get the expected prototype for void free(i8*)
     const FunctionType *Free1Type = FunctionType::get(Type::VoidTy,
-        std::vector<const Type*>(1, PointerType::get(Type::Int8Ty)), false);
+      std::vector<const Type*>(1, PointerType::getUnqual(Type::Int8Ty)), false);
 
     if (TyWeHave != Free1Type) {
       // Check to see if the prototype was forgotten, giving us 
@@ -154,7 +154,7 @@ bool RaiseAllocations::runOnModule(Module &M) {
 
       if (Instruction *I = dyn_cast<Instruction>(U)) {
         CallSite CS = CallSite::get(I);
-        if (CS.getInstruction() && CS.arg_begin() != CS.arg_end() &&
+        if (CS.getInstruction() && !CS.arg_empty() &&
             (CS.getCalledFunction() == MallocFunc ||
              std::find(EqPointers.begin(), EqPointers.end(),
                        CS.getCalledValue()) != EqPointers.end())) {
@@ -204,8 +204,10 @@ bool RaiseAllocations::runOnModule(Module &M) {
       Users.pop_back();
 
       if (Instruction *I = dyn_cast<Instruction>(U)) {
+        if (isa<InvokeInst>(I))
+          continue;
         CallSite CS = CallSite::get(I);
-        if (CS.getInstruction() && CS.arg_begin() != CS.arg_end() &&
+        if (CS.getInstruction() && !CS.arg_empty() &&
             (CS.getCalledFunction() == FreeFunc ||
              std::find(EqPointers.begin(), EqPointers.end(),
                        CS.getCalledValue()) != EqPointers.end())) {
@@ -217,7 +219,8 @@ bool RaiseAllocations::runOnModule(Module &M) {
           //
           Value *Source = *CS.arg_begin();
           if (!isa<PointerType>(Source->getType()))
-            Source = new IntToPtrInst(Source, PointerType::get(Type::Int8Ty), 
+            Source = new IntToPtrInst(Source,           
+                                      PointerType::getUnqual(Type::Int8Ty), 
                                       "FreePtrCast", I);
           new FreeInst(Source, I);