[llvm-commits] CVS: llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp Heuristic.cpp PointerCompress.cpp PoolAllocate.cpp PoolOptimize.cpp TransformFunctionBody.cpp

John Criswell criswell at cs.uiuc.edu
Wed Jan 10 12:45:02 PST 2007



Changes in directory llvm-poolalloc/lib/PoolAllocate:

AccessTrace.cpp updated: 1.8 -> 1.9
Heuristic.cpp updated: 1.16 -> 1.17
PointerCompress.cpp updated: 1.75 -> 1.76
PoolAllocate.cpp updated: 1.131 -> 1.132
PoolOptimize.cpp updated: 1.10 -> 1.11
TransformFunctionBody.cpp updated: 1.60 -> 1.61
---
Log message:

Updated to the latest version of LLVM:
  a) Updated all types to the new integer types.
  b) Updated to the new ICmp and FCmp instructions.


---
Diffs of the changes:  (+143 -103)

 AccessTrace.cpp           |    4 +-
 Heuristic.cpp             |    4 +-
 PointerCompress.cpp       |   75 ++++++++++++++++++++++++++++++----------------
 PoolAllocate.cpp          |   40 ++++++++++++++----------
 PoolOptimize.cpp          |   57 ++++++++++++++++++++--------------
 TransformFunctionBody.cpp |   66 ++++++++++++++++++++--------------------
 6 files changed, 143 insertions(+), 103 deletions(-)


Index: llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp:1.8 llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp:1.9
--- llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp:1.8	Wed Dec 13 23:51:06 2006
+++ llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp	Wed Jan 10 14:44:31 2007
@@ -28,7 +28,7 @@
   class PoolAccessTrace : public ModulePass {
     PoolAllocate *PoolAlloc;
     EquivClassGraphs *ECG;
-    Function *AccessTraceInitFn, *PoolAccessTraceFn;
+    Constant *AccessTraceInitFn, *PoolAccessTraceFn;
     const Type *VoidPtrTy;
   public:
 
@@ -59,7 +59,7 @@
 }
 
 void PoolAccessTrace::InitializeLibraryFunctions(Module &M) {
-  VoidPtrTy = PointerType::get(Type::SByteTy);
+  VoidPtrTy = PointerType::get(Type::Int8Ty);
 
   AccessTraceInitFn = M.getOrInsertFunction("poolaccesstraceinit",
                                             Type::VoidTy,NULL);


Index: llvm-poolalloc/lib/PoolAllocate/Heuristic.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/Heuristic.cpp:1.16 llvm-poolalloc/lib/PoolAllocate/Heuristic.cpp:1.17
--- llvm-poolalloc/lib/PoolAllocate/Heuristic.cpp:1.16	Wed Dec 13 23:51:07 2006
+++ llvm-poolalloc/lib/PoolAllocate/Heuristic.cpp	Wed Jan 10 14:44:31 2007
@@ -456,8 +456,8 @@
 void OnlyOverheadHeuristic::HackFunctionBody(Function &F,
                                              std::map<const DSNode*,
                                              Value*> &PDs) {
-  Function *PoolInit = PA->PoolInit;
-  Function *PoolDestroy = PA->PoolDestroy;
+  Constant *PoolInit = PA->PoolInit;
+  Constant *PoolDestroy = PA->PoolDestroy;
 
   Value *NullPD = getDynamicallyNullPool(F.front().begin());
   for (std::map<const DSNode*, Value*>::iterator PDI = PDs.begin(),


Index: llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.75 llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.76
--- llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.75	Wed Jan 10 12:10:32 2007
+++ llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp	Wed Jan 10 14:44:31 2007
@@ -34,8 +34,8 @@
 using namespace llvm;
 
 /// MEMUINTTYPE - This is the actual type we are compressing to.  This is really
-/// only capable of being UIntTy, except when we are doing tests for 16-bit
-/// integers, when it's UShortTy.
+/// only capable of being Int32Ty, except when we are doing tests for 16-bit
+/// integers, when it's Int16Ty.
 static const Type *MEMUINTTYPE;
 
 /// SCALARUINTTYPE - We keep scalars the same size as the machine word on the
@@ -115,7 +115,7 @@
     std::map<const DSNode*, GlobalValue*> CompressedGlobalPools;
 
   public:
-    Function *PoolInitPC, *PoolDestroyPC, *PoolAllocPC;
+    Constant *PoolInitPC, *PoolDestroyPC, *PoolAllocPC;
     typedef std::map<const DSNode*, CompressedPoolInfo> PoolInfoMap;
 
     /// NoArgFunctionsCalled - When we are walking the call graph, keep track of
@@ -284,7 +284,7 @@
     assert(PoolBase == 0 && "Mixing and matching optimized vs not!");
     
     // Get the pool base pointer.
-    Constant *Zero = Constant::getNullValue(Type::UIntTy);
+    Constant *Zero = Constant::getNullValue(Type::Int32Ty);
     Value *BasePtrPtr = new GetElementPtrInst(getPoolDesc(), Zero, Zero,
                                               "poolbaseptrptr", &I);
     return new LoadInst(BasePtrPtr, "poolbaseptr", &I);
@@ -295,7 +295,7 @@
                           isa<GlobalVariable>(PoolDesc))) {
       BasicBlock::iterator IP = I.getParent()->getParent()->begin()->begin();
       while (isa<AllocaInst>(IP)) ++IP;
-      Constant *Zero = Constant::getNullValue(Type::UIntTy);
+      Constant *Zero = Constant::getNullValue(Type::Int32Ty);
       Value *BasePtrPtr = new GetElementPtrInst(getPoolDesc(), Zero, Zero,
                                                 "poolbaseptrptr", IP);
       PoolBase = new LoadInst(BasePtrPtr, "poolbaseptr", IP);
@@ -515,7 +515,8 @@
     void visitCastInst(CastInst &CI);
     void visitPHINode(PHINode &PN);
     void visitSelectInst(SelectInst &SI);
-    void visitSetCondInst(SetCondInst &SCI);
+    void visitICmpInst(ICmpInst &I);
+    void visitFCmpInst(FCmpInst &I);
     void visitGetElementPtrInst(GetElementPtrInst &GEPI);
     void visitLoadInst(LoadInst &LI);
     void visitStoreInst(StoreInst &SI);
@@ -617,7 +618,7 @@
                                          SI.getName(), &SI));
 }
 
-void InstructionRewriter::visitSetCondInst(SetCondInst &SCI) {
+void InstructionRewriter::visitICmpInst(ICmpInst &SCI) {
   if (!isa<PointerType>(SCI.getOperand(0)->getType())) return;
   Value *NonNullPtr = SCI.getOperand(0);
   if (isa<ConstantPointerNull>(NonNullPtr)) {
@@ -630,10 +631,32 @@
   if (SrcPI == 0) return;   // comparing non-compressed pointers.
  
   std::string Name = SCI.getName(); SCI.setName("");
-  Value *New = new SetCondInst(SCI.getOpcode(),
-                               getTransformedValue(SCI.getOperand(0)),
-                               getTransformedValue(SCI.getOperand(1)),
-                               Name, &SCI);
+  Value *New = new ICmpInst(SCI.getPredicate(),
+                            getTransformedValue(SCI.getOperand(0)),
+                            getTransformedValue(SCI.getOperand(1)),
+                            Name, &SCI);
+  SCI.replaceAllUsesWith(New);
+  ValueReplaced(SCI, New);
+  SCI.eraseFromParent();
+}
+
+void InstructionRewriter::visitFCmpInst(FCmpInst &SCI) {
+  if (!isa<PointerType>(SCI.getOperand(0)->getType())) return;
+  Value *NonNullPtr = SCI.getOperand(0);
+  if (isa<ConstantPointerNull>(NonNullPtr)) {
+    NonNullPtr = SCI.getOperand(1);
+    if (isa<ConstantPointerNull>(NonNullPtr))
+      return;  // setcc null, null
+  }
+
+  const CompressedPoolInfo *SrcPI = getPoolInfo(NonNullPtr);
+  if (SrcPI == 0) return;   // comparing non-compressed pointers.
+ 
+  std::string Name = SCI.getName(); SCI.setName("");
+  Value *New = new FCmpInst(SCI.getPredicate(),
+                            getTransformedValue(SCI.getOperand(0)),
+                            getTransformedValue(SCI.getOperand(1)),
+                            Name, &SCI);
   SCI.replaceAllUsesWith(New);
   ValueReplaced(SCI, New);
   SCI.eraseFromParent();
@@ -744,8 +767,8 @@
   // Get the pointer to load from.
   std::vector<Value*> Ops;
   Ops.push_back(getTransformedValue(LI.getOperand(0)));
-  if (Ops[0]->getType() == Type::UShortTy)
-    Ops[0] = CastInst::createZExtOrBitCast(Ops[0], Type::UIntTy, "extend_idx", &LI);
+  if (Ops[0]->getType() == Type::Int16Ty)
+    Ops[0] = CastInst::createZExtOrBitCast(Ops[0], Type::Int32Ty, "extend_idx", &LI);
   Value *SrcPtr = new GetElementPtrInst(BasePtr, Ops,
                                         LI.getOperand(0)->getName()+".pp", &LI);
   const Type *DestTy = LoadingCompressedPtr ? MEMUINTTYPE : LI.getType();
@@ -810,8 +833,8 @@
   // Get the pointer to store to.
   std::vector<Value*> Ops;
   Ops.push_back(getTransformedValue(SI.getOperand(1)));
-  if (Ops[0]->getType() == Type::UShortTy)
-    Ops[0] = CastInst::createZExtOrBitCast(Ops[0], Type::UIntTy, "extend_idx", &SI);
+  if (Ops[0]->getType() == Type::Int16Ty)
+    Ops[0] = CastInst::createZExtOrBitCast(Ops[0], Type::Int32Ty, "extend_idx", &SI);
 
   Value *DestPtr = new GetElementPtrInst(BasePtr, Ops,
                                          SI.getOperand(1)->getName()+".pp",
@@ -836,11 +859,11 @@
   std::vector<Value*> Ops;
   Ops.push_back(CI.getOperand(1));
   // Transform to pass in the compressed size.
-  Ops.push_back(ConstantInt::get(Type::UIntTy, PI->getNewSize()));
+  Ops.push_back(ConstantInt::get(Type::Int32Ty, PI->getNewSize()));
 
   // Pointer compression can reduce the alignment restriction to 4 bytes from 8.
   // Reevaluate the desired alignment.
-  Ops.push_back(ConstantInt::get(Type::UIntTy,
+  Ops.push_back(ConstantInt::get(Type::Int32Ty,
              PA::Heuristic::getRecommendedAlignment(PI->getNewType(), TD)));
   // TODO: Compression could reduce the alignment restriction for the pool!
   Value *PB = new CallInst(PtrComp.PoolInitPC, Ops, "", &CI);
@@ -880,11 +903,11 @@
     if (OldSizeV != PI->getNewSize()) {
       // Emit code to scale the allocated size down by the old size then up by
       // the new size.  We actually compute (N+OS-1)/OS * NS.
-      Value *OldSize = ConstantInt::get(Type::UIntTy, OldSizeV);
-      Value *NewSize = ConstantInt::get(Type::UIntTy, PI->getNewSize());
+      Value *OldSize = ConstantInt::get(Type::Int32Ty, OldSizeV);
+      Value *NewSize = ConstantInt::get(Type::Int32Ty, PI->getNewSize());
 
       Size = BinaryOperator::createAdd(Size,
-                                  ConstantInt::get(Type::UIntTy, OldSizeV-1),
+                                  ConstantInt::get(Type::Int32Ty, OldSizeV-1),
                                        "roundup", &CI);
       Size = BinaryOperator::createUDiv(Size, OldSize, "numnodes", &CI);
       Size = BinaryOperator::createMul(Size, NewSize, "newbytes", &CI);
@@ -1487,15 +1510,15 @@
 /// InitializePoolLibraryFunctions - Create the function prototypes for pointer
 /// compress runtime library functions.
 void PointerCompress::InitializePoolLibraryFunctions(Module &M) {
-  const Type *VoidPtrTy = PointerType::get(Type::SByteTy);
+  const Type *VoidPtrTy = PointerType::get(Type::Int8Ty);
   const Type *PoolDescPtrTy = PointerType::get(ArrayType::get(VoidPtrTy, 16));
 
   PoolInitPC = M.getOrInsertFunction("poolinit_pc", VoidPtrTy, PoolDescPtrTy, 
-                                     Type::UIntTy, Type::UIntTy, NULL);
+                                     Type::Int32Ty, Type::Int32Ty, NULL);
   PoolDestroyPC = M.getOrInsertFunction("pooldestroy_pc", Type::VoidTy,
                                         PoolDescPtrTy, NULL);
   PoolAllocPC = M.getOrInsertFunction("poolalloc_pc", SCALARUINTTYPE,
-                                      PoolDescPtrTy, Type::UIntTy, NULL);
+                                      PoolDescPtrTy, Type::Int32Ty, NULL);
   // FIXME: Need bumppointer versions as well as realloc??/memalign??
 }
 
@@ -1504,12 +1527,12 @@
   ECG = &getAnalysis<EquivClassGraphs>();
   
   if (SmallIntCompress)
-    MEMUINTTYPE = Type::UShortTy;
+    MEMUINTTYPE = Type::Int16Ty;
   else 
-    MEMUINTTYPE = Type::UIntTy;
+    MEMUINTTYPE = Type::Int32Ty;
 
   // FIXME: make this IntPtrTy.
-  SCALARUINTTYPE = Type::ULongTy;
+  SCALARUINTTYPE = Type::Int64Ty;
 
   // Create the function prototypes for pointer compress runtime library
   // functions.


Index: llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.131 llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.132
--- llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.131	Wed Jan 10 12:10:32 2007
+++ llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp	Wed Jan 10 14:44:31 2007
@@ -180,7 +180,7 @@
 void PoolAllocate::AddPoolPrototypes() {
   if (VoidPtrTy == 0) {
     // NOTE: If these are changed, make sure to update PoolOptimize.cpp as well!
-    VoidPtrTy = PointerType::get(Type::SByteTy);
+    VoidPtrTy = PointerType::get(Type::Int8Ty);
 #ifdef SAFECODE    
     PoolDescType = ArrayType::get(VoidPtrTy, 50);
 #else
@@ -193,8 +193,8 @@
   
   // Get poolinit function.
   PoolInit = CurModule->getOrInsertFunction("poolinit", Type::VoidTy,
-                                            PoolDescPtrTy, Type::UIntTy,
-                                            Type::UIntTy, NULL);
+                                            PoolDescPtrTy, Type::Int32Ty,
+                                            Type::Int32Ty, NULL);
 
   // Get pooldestroy function.
   PoolDestroy = CurModule->getOrInsertFunction("pooldestroy", Type::VoidTy,
@@ -203,16 +203,16 @@
   // The poolalloc function.
   PoolAlloc = CurModule->getOrInsertFunction("poolalloc", 
                                              VoidPtrTy, PoolDescPtrTy,
-                                             Type::UIntTy, NULL);
+                                             Type::Int32Ty, NULL);
   
   // The poolrealloc function.
   PoolRealloc = CurModule->getOrInsertFunction("poolrealloc",
                                                VoidPtrTy, PoolDescPtrTy,
-                                               VoidPtrTy, Type::UIntTy, NULL);
+                                               VoidPtrTy, Type::Int32Ty, NULL);
   // The poolmemalign function.
   PoolMemAlign = CurModule->getOrInsertFunction("poolmemalign",
                                                 VoidPtrTy, PoolDescPtrTy,
-                                                Type::UIntTy, Type::UIntTy, 
+                                                Type::Int32Ty, Type::Int32Ty, 
                                                 NULL);
 
   // Get the poolfree function.
@@ -221,15 +221,23 @@
 #ifdef SAFECODE
   //Get the poolregister function
   PoolRegister = CurModule->getOrInsertFunction("poolregister", Type::VoidTy,
-                                   PoolDescPtrTy, Type::UIntTy, VoidPtrTy, NULL);
+                                   PoolDescPtrTy, Type::Int32Ty, VoidPtrTy, NULL);
 #endif
 #ifdef BOUNDS_CHECK
   PoolRegister = CurModule->getOrInsertFunction("poolregister", Type::VoidTy,
-                                   PoolDescPtrTy, VoidPtrTy, Type::UIntTy, NULL);
+                                   PoolDescPtrTy, VoidPtrTy, Type::Int32Ty, NULL);
 #endif  
 }
 
-static void getCallsOf(Function *F, std::vector<CallInst*> &Calls) {
+static void getCallsOf(Constant *C, std::vector<CallInst*> &Calls) {
+  // Get the Function out of the constant
+  Function * F;
+  ConstantExpr * CE;
+  if (!(F=dyn_cast<Function>(C)))
+    if ((CE = dyn_cast<ConstantExpr>(C)) && (CE->isCast()))
+      F = dyn_cast<Function>(CE->getOperand(0));
+    else
+      assert (0 && "Constant is not a Function of ConstantExpr!"); 
   Calls.clear();
   for (Value::use_iterator UI = F->use_begin(), E = F->use_end(); UI != E; ++UI)
     Calls.push_back(cast<CallInst>(*UI));
@@ -238,11 +246,11 @@
 static void OptimizePointerNotNull(Value *V) {
   for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
     Instruction *User = cast<Instruction>(*I);
-    if (User->getOpcode() == Instruction::SetEQ ||
-        User->getOpcode() == Instruction::SetNE) {
+    if (isa<ICmpInst>(User) && cast<ICmpInst>(User)->isEquality()) {
+      ICmpInst * ICI = cast<ICmpInst>(User);
       if (isa<Constant>(User->getOperand(1)) && 
           cast<Constant>(User->getOperand(1))->isNullValue()) {
-        bool CondIsTrue = User->getOpcode() == Instruction::SetNE;
+        bool CondIsTrue = ICI->getPredicate() == ICmpInst::ICMP_NE;
         User->replaceAllUsesWith(ConstantBool::get(CondIsTrue));
       }
     } else if ((User->getOpcode() == Instruction::Trunc) ||
@@ -535,8 +543,8 @@
     while (isa<AllocaInst>(InsertPt)) ++InsertPt;
   }
 
-  Value *ElSize = ConstantInt::get(Type::UIntTy, RecSize);
-  Value *AlignV = ConstantInt::get(Type::UIntTy, Align);
+  Value *ElSize = ConstantInt::get(Type::Int32Ty, RecSize);
+  Value *AlignV = ConstantInt::get(Type::Int32Ty, Align);
   new CallInst(PoolInit, make_vector((Value*)GV, ElSize, AlignV, 0),
                "", InsertPt);
   ++NumPools;
@@ -873,9 +881,9 @@
 
   // Insert the calls to initialize the pool.
   unsigned ElSizeV = Heuristic::getRecommendedSize(Node);
-  Value *ElSize = ConstantInt::get(Type::UIntTy, ElSizeV);
+  Value *ElSize = ConstantInt::get(Type::Int32Ty, ElSizeV);
   unsigned AlignV = Heuristic::getRecommendedAlignment(Node);
-  Value *Align  = ConstantInt::get(Type::UIntTy, AlignV);
+  Value *Align  = ConstantInt::get(Type::Int32Ty, AlignV);
 
   for (unsigned i = 0, e = PoolInitPoints.size(); i != e; ++i) {
     new CallInst(PoolInit, make_vector((Value*)PD, ElSize, Align, 0),


Index: llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp:1.10 llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp:1.11
--- llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp:1.10	Wed Jan 10 12:10:32 2007
+++ llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp	Wed Jan 10 14:44:32 2007
@@ -17,6 +17,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Support/Debug.h"
 using namespace llvm;
 
 namespace {
@@ -30,66 +31,74 @@
   X("pooloptimize", "Optimize a pool allocated program");
 }
 
-static void getCallsOf(Function *F, std::vector<CallInst*> &Calls) {
+static void getCallsOf(Constant *C, std::vector<CallInst*> &Calls) {
+  // Get the Function out of the constant
+  Function * F;
+  ConstantExpr * CE;
+  if (!(F=dyn_cast<Function>(C)))
+    if ((CE = dyn_cast<ConstantExpr>(C)) && (CE->isCast()))
+      F = dyn_cast<Function>(CE->getOperand(0));
+    else
+      assert (0 && "Constant is not a Function of ConstantExpr!"); 
   Calls.clear();
   for (Value::use_iterator UI = F->use_begin(), E = F->use_end(); UI != E; ++UI)
     Calls.push_back(cast<CallInst>(*UI));
 }
 
 bool PoolOptimize::runOnModule(Module &M) {
-  const Type *VoidPtrTy = PointerType::get(Type::SByteTy);
+  const Type *VoidPtrTy = PointerType::get(Type::Int8Ty);
   const Type *PoolDescPtrTy = PointerType::get(ArrayType::get(VoidPtrTy, 16));
 
 
   // Get poolinit function.
-  Function *PoolInit = M.getOrInsertFunction("poolinit", Type::VoidTy,
-                                             PoolDescPtrTy, Type::UIntTy,
-                                             Type::UIntTy, NULL);
+  Constant *PoolInit = M.getOrInsertFunction("poolinit", Type::VoidTy,
+                                             PoolDescPtrTy, Type::Int32Ty,
+                                             Type::Int32Ty, NULL);
 
   // Get pooldestroy function.
-  Function *PoolDestroy = M.getOrInsertFunction("pooldestroy", Type::VoidTy,
+  Constant *PoolDestroy = M.getOrInsertFunction("pooldestroy", Type::VoidTy,
                                                 PoolDescPtrTy, NULL);
   
   // The poolalloc function.
-  Function *PoolAlloc = M.getOrInsertFunction("poolalloc", 
+  Constant *PoolAlloc = M.getOrInsertFunction("poolalloc", 
                                               VoidPtrTy, PoolDescPtrTy,
-                                              Type::UIntTy, NULL);
+                                              Type::Int32Ty, NULL);
   
   // The poolrealloc function.
-  Function *PoolRealloc = M.getOrInsertFunction("poolrealloc",
+  Constant *PoolRealloc = M.getOrInsertFunction("poolrealloc",
                                                 VoidPtrTy, PoolDescPtrTy,
-                                                VoidPtrTy, Type::UIntTy, NULL);
+                                                VoidPtrTy, Type::Int32Ty, NULL);
   // The poolmemalign function.
-  Function *PoolMemAlign = M.getOrInsertFunction("poolmemalign",
+  Constant *PoolMemAlign = M.getOrInsertFunction("poolmemalign",
                                                  VoidPtrTy, PoolDescPtrTy,
-                                                 Type::UIntTy, Type::UIntTy, 
+                                                 Type::Int32Ty, Type::Int32Ty, 
                                                  NULL);
 
   // Get the poolfree function.
-  Function *PoolFree = M.getOrInsertFunction("poolfree", Type::VoidTy,
+  Constant *PoolFree = M.getOrInsertFunction("poolfree", Type::VoidTy,
                                              PoolDescPtrTy, VoidPtrTy, NULL);  
 
 
   // Get poolinit_bp function.
-  Function *PoolInitBP = M.getOrInsertFunction("poolinit_bp", Type::VoidTy,
-                                               PoolDescPtrTy, Type::UIntTy, 
+  Constant *PoolInitBP = M.getOrInsertFunction("poolinit_bp", Type::VoidTy,
+                                               PoolDescPtrTy, Type::Int32Ty, 
                                                NULL);
   
   // Get pooldestroy_bp function.
-  Function *PoolDestroyBP = M.getOrInsertFunction("pooldestroy_bp",Type::VoidTy,
+  Constant *PoolDestroyBP = M.getOrInsertFunction("pooldestroy_bp",Type::VoidTy,
                                                  PoolDescPtrTy, NULL);
   
   // The poolalloc_bp function.
-  Function *PoolAllocBP = M.getOrInsertFunction("poolalloc_bp", 
+  Constant *PoolAllocBP = M.getOrInsertFunction("poolalloc_bp", 
                                                 VoidPtrTy, PoolDescPtrTy,
-                                                Type::UIntTy, NULL);
+                                                Type::Int32Ty, NULL);
 
-  Function *Realloc = M.getOrInsertFunction("realloc",
-                                            VoidPtrTy, VoidPtrTy, Type::UIntTy,
+  Constant *Realloc = M.getOrInsertFunction("realloc",
+                                            VoidPtrTy, VoidPtrTy, Type::Int32Ty,
                                             NULL);
-  Function *MemAlign = M.getOrInsertFunction("memalign",
-                                             VoidPtrTy, Type::UIntTy,
-                                             Type::UIntTy, NULL);
+  Constant *MemAlign = M.getOrInsertFunction("memalign",
+                                             VoidPtrTy, Type::Int32Ty,
+                                             Type::Int32Ty, NULL);
 
 
   // Optimize poolreallocs
@@ -132,7 +141,7 @@
     // poolalloc(null, X) -> malloc(X)
     if (isa<Constant>(CI->getOperand(1)) && 
         cast<Constant>(CI->getOperand(1))->isNullValue()) {
-      Value *New = new MallocInst(Type::SByteTy, CI->getOperand(2),
+      Value *New = new MallocInst(Type::Int8Ty, CI->getOperand(2),
                                   CI->getName(), CI);
       CI->replaceAllUsesWith(New);
       CI->eraseFromParent();


Index: llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.60 llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.61
--- llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.60	Tue Dec 19 17:10:34 2006
+++ llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp	Wed Jan 10 14:44:32 2007
@@ -149,8 +149,8 @@
                                                      Value *Size) {
   std::string Name = I->getName(); I->setName("");
 
-  if (Size->getType() != Type::UIntTy)
-    Size = CastInst::createZExtOrBitCast(Size, Type::UIntTy, Size->getName(), I);
+  if (Size->getType() != Type::Int32Ty)
+    Size = CastInst::createZExtOrBitCast(Size, Type::Int32Ty, Size->getName(), I);
 
   // Insert a call to poolalloc
   Value *PH = getPoolHandle(I);
@@ -198,7 +198,7 @@
 
   TargetData &TD = PAInfo.getAnalysis<TargetData>();
   Value *AllocSize =
-    ConstantInt::get(Type::UIntTy, TD.getTypeSize(MI.getAllocatedType()));
+    ConstantInt::get(Type::Int32Ty, TD.getTypeSize(MI.getAllocatedType()));
 
   if (MI.isArrayAllocation())
     AllocSize = BinaryOperator::create(Instruction::Mul, AllocSize,
@@ -218,8 +218,8 @@
     MI.getParent()->getInstList().erase(&MI);
     Value *Casted = AI;
     Instruction *aiNext = AI->getNext();
-    if (AI->getType() != PointerType::get(Type::SByteTy))
-      Casted = CastInst::createPointerCast(AI, PointerType::get(Type::SByteTy),
+    if (AI->getType() != PointerType::get(Type::Int8Ty))
+      Casted = CastInst::createPointerCast(AI, PointerType::get(Type::Int8Ty),
 			      AI->getName()+".casted",aiNext);
     
     Instruction *V = new CallInst(PAInfo.PoolRegister,
@@ -240,14 +240,14 @@
     if (PH == 0 || isa<ConstantPointerNull>(PH)) return;
     TargetData &TD = PAInfo.getAnalysis<TargetData>();
     Value *AllocSize =
-      ConstantInt::get(Type::UIntTy, TD.getTypeSize(MI.getAllocatedType()));
+      ConstantInt::get(Type::Int32Ty, TD.getTypeSize(MI.getAllocatedType()));
     
     if (MI.isArrayAllocation())
       AllocSize = BinaryOperator::create(Instruction::Mul, AllocSize,
 					 MI.getOperand(0), "sizetmp", &MI);
     
     //  TransformAllocationInstr(&MI, AllocSize);
-    Instruction *Casted = CastInst::createPointerCast(&MI, PointerType::get(Type::SByteTy),
+    Instruction *Casted = CastInst::createPointerCast(&MI, PointerType::get(Type::Int8Ty),
 				       MI.getName()+".casted", MI.getNext());
     Instruction *V = new CallInst(PAInfo.PoolRegister,
 				  make_vector(PH, Casted, AllocSize, 0), "", Casted->getNext());
@@ -263,8 +263,8 @@
 
   // Insert a cast and a call to poolfree...
   Value *Casted = Arg;
-  if (Arg->getType() != PointerType::get(Type::SByteTy)) {
-    Casted = CastInst::createPointerCast(Arg, PointerType::get(Type::SByteTy),
+  if (Arg->getType() != PointerType::get(Type::Int8Ty)) {
+    Casted = CastInst::createPointerCast(Arg, PointerType::get(Type::Int8Ty),
 				 Arg->getName()+".casted", Where);
     G.getScalarMap()[Casted] = G.getScalarMap()[Arg];
   }
@@ -296,21 +296,21 @@
 
 void FuncTransform::visitCallocCall(CallSite CS) {
   TargetData& TD = PAInfo.getAnalysis<TargetData>();
-  bool useLong = TD.getTypeSize(PointerType::get(Type::SByteTy)) != 4;
+  bool useLong = TD.getTypeSize(PointerType::get(Type::Int8Ty)) != 4;
   
   Module *M = CS.getInstruction()->getParent()->getParent()->getParent();
   assert(CS.arg_end()-CS.arg_begin() == 2 && "calloc takes two arguments!");
   Value *V1 = CS.getArgument(0);
   Value *V2 = CS.getArgument(1);
   if (V1->getType() != V2->getType()) {
-    V1 = CastInst::createZExtOrBitCast(V1, useLong ? Type::ULongTy : Type::UIntTy, V1->getName(), CS.getInstruction());
-    V2 = CastInst::createZExtOrBitCast(V2, useLong ? Type::ULongTy : Type::UIntTy, V2->getName(), CS.getInstruction());
+    V1 = CastInst::createZExtOrBitCast(V1, useLong ? Type::Int64Ty : Type::Int32Ty, V1->getName(), CS.getInstruction());
+    V2 = CastInst::createZExtOrBitCast(V2, useLong ? Type::Int64Ty : Type::Int32Ty, V2->getName(), CS.getInstruction());
   }
 
   V2 = BinaryOperator::create(Instruction::Mul, V1, V2, "size",
                               CS.getInstruction());
-  if (V2->getType() != (useLong ? Type::ULongTy : Type::UIntTy))
-    V2 = CastInst::createZExtOrBitCast(V2, useLong ? Type::ULongTy : Type::UIntTy, V2->getName(), CS.getInstruction());
+  if (V2->getType() != (useLong ? Type::Int64Ty : Type::Int32Ty))
+    V2 = CastInst::createZExtOrBitCast(V2, useLong ? Type::Int64Ty : Type::Int32Ty, V2->getName(), CS.getInstruction());
 
   BasicBlock::iterator BBI =
     TransformAllocationInstr(CS.getInstruction(), V2);
@@ -318,19 +318,19 @@
 
   // We just turned the call of 'calloc' into the equivalent of malloc.  To
   // finish calloc, we need to zero out the memory.
-  Function *MemSet =  M->getOrInsertFunction((useLong ? "llvm.memset.i64" : "llvm.memset.i32"),
+  Constant *MemSet =  M->getOrInsertFunction((useLong ? "llvm.memset.i64" : "llvm.memset.i32"),
                                              Type::VoidTy,
-                                             PointerType::get(Type::SByteTy),
-                                             Type::UByteTy, (useLong ? Type::ULongTy : Type::UIntTy),
-                                             Type::UIntTy, NULL);
+                                             PointerType::get(Type::Int8Ty),
+                                             Type::Int8Ty, (useLong ? Type::Int64Ty : Type::Int32Ty),
+                                             Type::Int32Ty, NULL);
 
-  if (Ptr->getType() != PointerType::get(Type::SByteTy))
-    Ptr = CastInst::createPointerCast(Ptr, PointerType::get(Type::SByteTy), Ptr->getName(),
+  if (Ptr->getType() != PointerType::get(Type::Int8Ty))
+    Ptr = CastInst::createPointerCast(Ptr, PointerType::get(Type::Int8Ty), Ptr->getName(),
                        BBI);
   
   // We know that the memory returned by poolalloc is at least 4 byte aligned.
-  new CallInst(MemSet, make_vector(Ptr, ConstantInt::get(Type::UByteTy, 0),
-                                   V2,  ConstantInt::get(Type::UIntTy, 4), 0),
+  new CallInst(MemSet, make_vector(Ptr, ConstantInt::get(Type::Int8Ty, 0),
+                                   V2,  ConstantInt::get(Type::Int32Ty, 4), 0),
                "", BBI);
 }
 
@@ -342,10 +342,10 @@
   Value *OldPtr = CS.getArgument(0);
   Value *Size = CS.getArgument(1);
 
-  if (Size->getType() != Type::UIntTy)
-    Size = CastInst::createZExtOrBitCast(Size, Type::UIntTy, Size->getName(), I);
+  if (Size->getType() != Type::Int32Ty)
+    Size = CastInst::createZExtOrBitCast(Size, Type::Int32Ty, Size->getName(), I);
 
-  static Type *VoidPtrTy = PointerType::get(Type::SByteTy);
+  static Type *VoidPtrTy = PointerType::get(Type::Int8Ty);
   if (OldPtr->getType() != VoidPtrTy)
     OldPtr = CastInst::createPointerCast(OldPtr, VoidPtrTy, OldPtr->getName(), I);
 
@@ -408,15 +408,15 @@
     Value *RetVal = Constant::getNullValue(I->getType());
     I->replaceAllUsesWith(RetVal);
 
-    static const Type *PtrPtr=PointerType::get(PointerType::get(Type::SByteTy));
+    static const Type *PtrPtr=PointerType::get(PointerType::get(Type::Int8Ty));
     if (ResultDest->getType() != PtrPtr)
       ResultDest = CastInst::createPointerCast(ResultDest, PtrPtr, ResultDest->getName(), I);
   }
 
-  if (Align->getType() != Type::UIntTy)
-    Align = CastInst::createZExtOrBitCast(Align, Type::UIntTy, Align->getName(), I);
-  if (Size->getType() != Type::UIntTy)
-    Size = CastInst::createZExtOrBitCast(Size, Type::UIntTy, Size->getName(), I);
+  if (Align->getType() != Type::Int32Ty)
+    Align = CastInst::createZExtOrBitCast(Align, Type::Int32Ty, Align->getName(), I);
+  if (Size->getType() != Type::Int32Ty)
+    Size = CastInst::createZExtOrBitCast(Size, Type::Int32Ty, Size->getName(), I);
 
   std::string Name = I->getName(); I->setName("");
   Instruction *V = new CallInst(PAInfo.PoolMemAlign,
@@ -651,10 +651,10 @@
 	if (!isa<InvokeInst>(TheCall)) {
 	  //Dinakar we need pooldescriptors for allocas in the callee if it escapes
 	  BasicBlock::iterator InsertPt = TheCall->getParent()->getParent()->front().begin();
-	  Type *VoidPtrTy = PointerType::get(Type::SByteTy);
+	  Type *VoidPtrTy = PointerType::get(Type::Int8Ty);
 	  ArgVal =  new AllocaInst(ArrayType::get(VoidPtrTy, 16), 0, "PD", InsertPt);
-	  Value *ElSize = ConstantInt::get(Type::UIntTy,0);
-	  Value *Align  = ConstantInt::get(Type::UIntTy,0);
+	  Value *ElSize = ConstantInt::get(Type::Int32Ty,0);
+	  Value *Align  = ConstantInt::get(Type::Int32Ty,0);
 	  new CallInst(PAInfo.PoolInit, make_vector(ArgVal, ElSize, Align, 0),"", TheCall);
 	    new CallInst(PAInfo.PoolDestroy, make_vector(ArgVal, 0), "",
 		       TheCall->getNext());






More information about the llvm-commits mailing list