[llvm-commits] CVS: llvm/lib/Transforms/IPO/LoopExtractor.cpp RaiseAllocations.cpp StripSymbols.cpp

Reid Spencer reid at x10sys.com
Mon Feb 5 12:48:29 PST 2007



Changes in directory llvm/lib/Transforms/IPO:

LoopExtractor.cpp updated: 1.21 -> 1.22
RaiseAllocations.cpp updated: 1.36 -> 1.37
StripSymbols.cpp updated: 1.10 -> 1.11
---
Log message:

For PR411: http://llvm.org/PR411 :
This patch replaces the SymbolTable class with ValueSymbolTable which does
not support types planes. This means that all symbol names in LLVM must now
be unique. The patch addresses the necessary changes to deal with this and
removes code no longer needed as a result. This completes the bulk of the
changes for this PR. Some cleanup patches will follow.


---
Diffs of the changes:  (+57 -38)

 LoopExtractor.cpp    |    3 +
 RaiseAllocations.cpp |   90 ++++++++++++++++++++++++++++++---------------------
 StripSymbols.cpp     |    2 -
 3 files changed, 57 insertions(+), 38 deletions(-)


Index: llvm/lib/Transforms/IPO/LoopExtractor.cpp
diff -u llvm/lib/Transforms/IPO/LoopExtractor.cpp:1.21 llvm/lib/Transforms/IPO/LoopExtractor.cpp:1.22
--- llvm/lib/Transforms/IPO/LoopExtractor.cpp:1.21	Tue Dec 19 16:09:18 2006
+++ llvm/lib/Transforms/IPO/LoopExtractor.cpp	Mon Feb  5 14:47:20 2007
@@ -167,7 +167,8 @@
     Function *F = BB->getParent();
 
     // Map the corresponding function in this module.
-    Function *MF = M.getFunction(F->getName(), F->getFunctionType());
+    Function *MF = M.getFunction(F->getName());
+    assert(MF->getFunctionType() == F->getFunctionType() && "Wrong function?");
 
     // Figure out which index the basic block is in its function.
     Function::iterator BBI = MF->begin();


Index: llvm/lib/Transforms/IPO/RaiseAllocations.cpp
diff -u llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.36 llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.37
--- llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.36	Tue Jan 30 14:08:38 2007
+++ llvm/lib/Transforms/IPO/RaiseAllocations.cpp	Mon Feb  5 14:47:20 2007
@@ -65,47 +65,65 @@
 // function into the appropriate instruction.
 //
 void RaiseAllocations::doInitialization(Module &M) {
-  const FunctionType *MallocType =   // Get the type for malloc
-    FunctionType::get(PointerType::get(Type::Int8Ty),
-                    std::vector<const Type*>(1, Type::Int64Ty), false);
-
-  const FunctionType *FreeType =     // Get the type for free
-    FunctionType::get(Type::VoidTy,
-                   std::vector<const Type*>(1, PointerType::get(Type::Int8Ty)),
-                      false);
 
   // Get Malloc and free prototypes if they exist!
-  MallocFunc = M.getFunction("malloc", MallocType);
-  FreeFunc   = M.getFunction("free"  , FreeType);
-
-  // Check to see if the prototype is wrong, giving us sbyte*(uint) * malloc
-  // This handles the common declaration of: 'void *malloc(unsigned);'
-  if (MallocFunc == 0) {
-    MallocType = FunctionType::get(PointerType::get(Type::Int8Ty),
-                            std::vector<const Type*>(1, Type::Int32Ty), false);
-    MallocFunc = M.getFunction("malloc", MallocType);
-  }
-
-  // Check to see if the prototype is missing, giving us sbyte*(...) * malloc
-  // This handles the common declaration of: 'void *malloc();'
-  if (MallocFunc == 0) {
-    MallocType = FunctionType::get(PointerType::get(Type::Int8Ty),
-                                   std::vector<const Type*>(), true);
-    MallocFunc = M.getFunction("malloc", MallocType);
-  }
+  MallocFunc = M.getFunction("malloc");
+  if (MallocFunc) {
+    const FunctionType* TyWeHave = MallocFunc->getFunctionType();
 
-  // Check to see if the prototype was forgotten, giving us void (...) * free
-  // This handles the common forward declaration of: 'void free();'
-  if (FreeFunc == 0) {
-    FreeType = FunctionType::get(Type::VoidTy, std::vector<const Type*>(),true);
-    FreeFunc = M.getFunction("free", FreeType);
+    // Get the expected prototype for malloc
+    const FunctionType *Malloc1Type = 
+      FunctionType::get(PointerType::get(Type::Int8Ty),
+                      std::vector<const Type*>(1, Type::Int64Ty), false);
+
+    // Chck to see if we got the expected malloc
+    if (TyWeHave != Malloc1Type) {
+      // 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),
+                          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),
+                            std::vector<const Type*>(), true);
+        if (TyWeHave != Malloc3Type)
+          // Give up
+          MallocFunc = 0;
+      }
+    }
   }
 
-  // One last try, check to see if we can find free as 'int (...)* free'.  This
-  // handles the case where NOTHING was declared.
-  if (FreeFunc == 0) {
-    FreeType = FunctionType::get(Type::Int32Ty, std::vector<const Type*>(),true);
-    FreeFunc = M.getFunction("free", FreeType);
+  FreeFunc = M.getFunction("free");
+  if (FreeFunc) {
+    const FunctionType* TyWeHave = FreeFunc->getFunctionType();
+    
+    // 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);
+
+    if (TyWeHave != Free1Type) {
+      // Check to see if the prototype was forgotten, giving us 
+      // void (...) * free
+      // This handles the common forward declaration of: 'void free();'
+      const FunctionType* Free2Type = FunctionType::get(Type::VoidTy, 
+        std::vector<const Type*>(),true);
+
+      if (TyWeHave != Free2Type) {
+        // One last try, check to see if we can find free as 
+        // int (...)* free.  This handles the case where NOTHING was declared.
+        const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty, 
+          std::vector<const Type*>(),true);
+        
+        if (TyWeHave != Free3Type) {
+          // Give up.
+          FreeFunc = 0;
+        }
+      }
+    }
   }
 
   // Don't mess with locally defined versions of these functions...


Index: llvm/lib/Transforms/IPO/StripSymbols.cpp
diff -u llvm/lib/Transforms/IPO/StripSymbols.cpp:1.10 llvm/lib/Transforms/IPO/StripSymbols.cpp:1.11
--- llvm/lib/Transforms/IPO/StripSymbols.cpp:1.10	Sat Jan  6 01:24:44 2007
+++ llvm/lib/Transforms/IPO/StripSymbols.cpp	Mon Feb  5 14:47:20 2007
@@ -28,7 +28,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
 #include "llvm/TypeSymbolTable.h"
 using namespace llvm;
 






More information about the llvm-commits mailing list