[llvm-commits] [poolalloc] r80134 - in /poolalloc/trunk: include/poolalloc/PoolAllocate.h lib/DSA/Basic.cpp lib/DSA/DataStructure.cpp lib/PoolAllocate/AccessTrace.cpp lib/PoolAllocate/Heuristic.cpp lib/PoolAllocate/PAMultipleGlobalPool.cpp lib/PoolAllocate/PASimple.cpp lib/PoolAllocate/PointerCompress.cpp lib/PoolAllocate/PoolAllocate.cpp lib/PoolAllocate/PoolOptimize.cpp lib/PoolAllocate/TransformFunctionBody.cpp

John Criswell criswell at uiuc.edu
Wed Aug 26 13:31:19 PDT 2009


Author: criswell
Date: Wed Aug 26 15:31:19 2009
New Revision: 80134

URL: http://llvm.org/viewvc/llvm-project?rev=80134&view=rev
Log:
Update to the LLVM 2.6 API.

Modified:
    poolalloc/trunk/include/poolalloc/PoolAllocate.h
    poolalloc/trunk/lib/DSA/Basic.cpp
    poolalloc/trunk/lib/DSA/DataStructure.cpp
    poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp
    poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp
    poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp
    poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
    poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp
    poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
    poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp
    poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp

Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original)
+++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Wed Aug 26 15:31:19 2009
@@ -111,6 +111,9 @@
 class PoolAllocateGroup {
 protected:
   DataStructures *Graphs;
+  const Type * VoidType;
+  const Type * Int8Type;
+  const Type * Int32Type;
 
 public:
   static char ID;
@@ -271,7 +274,8 @@
 
   /// getPoolType - Return the type of a pool descriptor
   const Type * getPoolType() {
-    Type * VoidPtrType = PointerType::getUnqual(Type::Int8Ty);
+    const IntegerType * IT = IntegerType::getInt8Ty(getGlobalContext());
+    Type * VoidPtrType = PointerType::getUnqual(IT);
     if (SAFECodeEnabled)
       return ArrayType::get(VoidPtrType, 92);
     else

Modified: poolalloc/trunk/lib/DSA/Basic.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Basic.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/Basic.cpp (original)
+++ poolalloc/trunk/lib/DSA/Basic.cpp Wed Aug 26 15:31:19 2009
@@ -23,6 +23,7 @@
 #include "llvm/Support/InstIterator.h"
 #include "llvm/Support/InstVisitor.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
+#include "llvm/Support/TypeBuilder.h"
 
 using namespace llvm;
 
@@ -34,8 +35,14 @@
 bool BasicDataStructures::runOnModule(Module &M) {
   init(&getAnalysis<TargetData>());
 
-  DSNode * GVNodeInternal = new DSNode(PointerType::getUnqual(Type::Int8Ty), GlobalsGraph);
-  DSNode * GVNodeExternal = new DSNode(PointerType::getUnqual(Type::Int8Ty), GlobalsGraph);
+  //
+  // Create a void pointer type.  This is simply a pointer to an 8 bit value.
+  //
+  const IntegerType * IT = IntegerType::getInt8Ty(getGlobalContext());
+  const PointerType * VoidPtrTy = PointerType::getUnqual(IT);
+
+  DSNode * GVNodeInternal = new DSNode(VoidPtrTy, GlobalsGraph);
+  DSNode * GVNodeExternal = new DSNode(VoidPtrTy, GlobalsGraph);
   for (Module::global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I) {
     if (I->isDeclaration()) {
@@ -57,7 +64,7 @@
   for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
     if (!F->isDeclaration()) {
       DSGraph* G = new DSGraph(GlobalECs, getTargetData(), GlobalsGraph);
-      DSNode * Node = new DSNode(PointerType::getUnqual(Type::Int8Ty), G);
+      DSNode * Node = new DSNode(VoidPtrTy, G);
           
       if (!F->hasInternalLinkage())
         Node->setExternalMarker();

Modified: poolalloc/trunk/lib/DSA/DataStructure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DataStructure.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/DataStructure.cpp (original)
+++ poolalloc/trunk/lib/DSA/DataStructure.cpp Wed Aug 26 15:31:19 2009
@@ -142,7 +142,7 @@
 //===----------------------------------------------------------------------===//
 
 DSNode::DSNode(const Type *T, DSGraph *G)
-  : NumReferrers(0), Size(0), ParentGraph(G), Ty(Type::VoidTy), NodeType(0) {
+  : NumReferrers(0), Size(0), ParentGraph(G), Ty(Type::getVoidTy(getGlobalContext())), NodeType(0) {
   // Add the type entry if it is specified...
   if (T) mergeTypeInfo(T, 0);
   if (G) G->addNode(this);
@@ -184,8 +184,9 @@
 }
 
 void DSNode::assertOK() const {
-  assert((Ty != Type::VoidTy ||
-          (Ty == Type::VoidTy && (Size == 0 ||
+  const Type * VoidType = Type::getVoidTy(getGlobalContext());
+  assert((Ty != VoidType ||
+          (Ty == VoidType && (Size == 0 ||
                                   (NodeType & DSNode::ArrayNode)))) &&
          "Node not OK!");
 
@@ -209,7 +210,7 @@
   ForwardNH.setTo(To, Offset);
   NodeType = DeadNode;
   Size = 0;
-  Ty = Type::VoidTy;
+  Ty = Type::getVoidTy(getGlobalContext());
 
   // Remove this node from the parent graph's Nodes list.
   ParentGraph->unlinkNode(this);
@@ -257,7 +258,7 @@
   // node.
   if (getSize() <= 1) {
     NodeType |= DSNode::ArrayNode;
-    Ty = Type::VoidTy;
+    Ty = Type::getVoidTy(getGlobalContext());
     Size = 1;
     assert(Links.size() <= 1 && "Size is 1, but has more links?");
     Links.resize(1);
@@ -267,7 +268,7 @@
     // forward, the forwarder has the opportunity to correct the offset.
     DSNode *DestNode = new DSNode(0, ParentGraph);
     DestNode->NodeType = NodeType|DSNode::ArrayNode;
-    DestNode->Ty = Type::VoidTy;
+    DestNode->Ty = Type::getVoidTy(getGlobalContext());
     DestNode->Size = 1;
     DestNode->Globals.swap(Globals);
     
@@ -309,7 +310,8 @@
 /// all of the field sensitivity that may be present in the node.
 ///
 bool DSNode::isNodeCompletelyFolded() const {
-  return getSize() == 1 && Ty == Type::VoidTy && isArray();
+  const Type * VoidType = Type::getVoidTy(getGlobalContext());
+  return getSize() == 1 && Ty == VoidType && isArray();
 }
 
 /// addFullGlobalsList - Compute the full set of global values that are
@@ -488,13 +490,14 @@
   //  Size = 1, Ty = Void, Array = 1: The node is collapsed
   //  Otherwise, sizeof(Ty) = Size
   //
-  assert(((Size == 0 && Ty == Type::VoidTy && !isArray()) ||
+  const Type * VoidType = Type::getVoidTy(getGlobalContext());
+  assert(((Size == 0 && Ty == VoidType && !isArray()) ||
           (Size == 0 && !Ty->isSized() && !isArray()) ||
-          (Size == 1 && Ty == Type::VoidTy && isArray()) ||
+          (Size == 1 && Ty == VoidType && isArray()) ||
           (Size == 0 && !Ty->isSized() && !isArray()) ||
           (TD.getTypeAllocSize(Ty) == Size)) &&
          "Size member of DSNode doesn't match the type structure!");
-  assert(NewTy != Type::VoidTy && "Cannot merge void type into DSNode!");
+  assert(NewTy != VoidType && "Cannot merge void type into DSNode!");
 
   if (Offset == 0 && NewTy == Ty)
     return false;  // This should be a common case, handle it efficiently
@@ -521,7 +524,7 @@
   // we can't, we fold the node completely, if we can, we potentially update our
   // internal state.
   //
-  if (Ty == Type::VoidTy) {
+  if (Ty == VoidType) {
     // If this is the first type that this node has seen, just accept it without
     // question....
     assert(Offset == 0 && !isArray() &&
@@ -906,7 +909,8 @@
   }
 #endif  
   // Merge the type entries of the two nodes together...
-  if (NH.getNode()->Ty != Type::VoidTy)
+  const Type * VoidType = Type::getVoidTy(getGlobalContext());
+  if (NH.getNode()->Ty != VoidType)
     CurNodeH.getNode()->mergeTypeInfo(NH.getNode()->Ty, NOffset);
   assert(!CurNodeH.getNode()->isDeadNode());
 
@@ -1168,7 +1172,8 @@
       }
 
       // Merge the type entries of the two nodes together...
-      if (SN->getType() != Type::VoidTy && !DN->isNodeCompletelyFolded()) {
+      const Type * VoidType = Type::getVoidTy(getGlobalContext());
+      if (SN->getType() != VoidType && !DN->isNodeCompletelyFolded()) {
         DN->mergeTypeInfo(SN->getType(), NH.getOffset()-SrcNH.getOffset());
         DN = NH.getNode();
       }
@@ -1997,11 +2002,12 @@
 }
 
 static inline void killIfUselessEdge(DSNodeHandle &Edge) {
+  const Type * VoidType = Type::getVoidTy(getGlobalContext());
   if (DSNode *N = Edge.getNode())  // Is there an edge?
     if (N->getNumReferrers() == 1)  // Does it point to a lonely node?
       // No interesting info?
       if ((N->getNodeFlags() & ~DSNode::IncompleteNode) == 0 &&
-          N->getType() == Type::VoidTy && !N->isNodeCompletelyFolded())
+          N->getType() == VoidType && !N->isNodeCompletelyFolded())
         Edge.setTo(0, 0);  // Kill the edge!
 }
 

Modified: poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp Wed Aug 26 15:31:19 2009
@@ -63,11 +63,13 @@
 }
 
 void PoolAccessTrace::InitializeLibraryFunctions(Module &M) {
-  VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+  const IntegerType * IT = IntegerType::getInt8Ty(getGlobalContext());
+  const Type * VoidType = Type::getVoidTy(getGlobalContext());
+  VoidPtrTy = PointerType::getUnqual(IT);
 
   AccessTraceInitFn = M.getOrInsertFunction("poolaccesstraceinit",
-                                            Type::VoidTy,NULL);
-  PoolAccessTraceFn = M.getOrInsertFunction("poolaccesstrace", Type::VoidTy,
+                                            VoidType, NULL);
+  PoolAccessTraceFn = M.getOrInsertFunction("poolaccesstrace", VoidType,
                                             VoidPtrTy, VoidPtrTy, NULL);
 }
 

Modified: poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp Wed Aug 26 15:31:19 2009
@@ -69,8 +69,19 @@
   if (DisableAlignOpt) return true;
 
   if ((Offs & 7) == 0) {
+    //
+    // Note:
+    //  The LLVM API has changed, and I do not know how to tell if a type is
+    //  is a double integer.  Furthermore, the alignment of a double to 8 bits
+    //  appears to be a hack, and it is not clear as to why.  Therefore, we
+    //  will simply align all floating point types on an 8 bit boundary.
+    //
+#if 0
     // Doubles always want to be 8-byte aligned.
     if (Ty == Type::DoubleTy) return true;
+#else
+    if (Ty->isFloatingPoint()) return true;
+#endif
     
     // If we are on a 64-bit system, we want to align 8-byte integers and
     // pointers.
@@ -99,7 +110,8 @@
 
 unsigned Heuristic::getRecommendedAlignment(const Type *Ty,
                                             const TargetData &TD) {
-  if (Ty == Type::VoidTy)  // Is this void or collapsed?
+  const Type * VoidType = Type::getVoidTy(getGlobalContext());
+  if (Ty == VoidType)  // Is this void or collapsed?
     return 0;  // No known alignment, let runtime decide.
 
   return Wants8ByteAlignment(Ty, 0, TD) ? 8 : 4;
@@ -109,7 +121,8 @@
 /// DSNode.
 ///
 unsigned Heuristic::getRecommendedAlignment(const DSNode *N) {
-  if (N->getType() == Type::VoidTy)  // Is this void or collapsed?
+  const Type * VoidType = Type::getVoidTy(getGlobalContext());
+  if (N->getType() == VoidType)  // Is this void or collapsed?
     return 0;  // No known alignment, let runtime decide.
 
   const TargetData &TD = N->getParentGraph()->getTargetData();

Modified: poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp Wed Aug 26 15:31:19 2009
@@ -25,6 +25,7 @@
 #include "llvm/Module.h"
 #include "llvm/Constants.h"
 #include "llvm/Support/CFG.h"
+#include "llvm/Support/TypeBuilder.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -82,6 +83,13 @@
   currentModule = &M;
   if (M.begin() == M.end()) return false;
 
+  //
+  // Get pointers to 8 and 32 bit LLVM integer types.
+  //
+  VoidType  = Type::getVoidTy(getGlobalContext());
+  Int8Type  = IntegerType::getInt8Ty(getGlobalContext());
+  Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+
   Graphs = &getAnalysis<SteensgaardDataStructures>();
   assert (Graphs && "No DSA pass available!\n");
 
@@ -141,7 +149,7 @@
         Value * AllocSize;
         if (MI->isArrayAllocation()) {
           Value * NumElements = MI->getArraySize();
-          Value * ElementSize = ConstantInt::get(Type::Int32Ty,
+          Value * ElementSize = ConstantInt::get(Int32Type,
 						 TD.getTypeAllocSize(MI->getAllocatedType()));
           AllocSize = BinaryOperator::Create (Instruction::Mul,
                                               ElementSize,
@@ -149,7 +157,7 @@
                                               "sizetmp",
                                               MI);
         } else {
-          AllocSize = ConstantInt::get(Type::Int32Ty,
+          AllocSize = ConstantInt::get(Int32Type,
 				       TD.getTypeAllocSize(MI->getAllocatedType()));
         }
 
@@ -186,14 +194,14 @@
           Value *Size = CS.getArgument(1);
 
           // Ensure the size and pointer arguments are of the correct type
-          if (Size->getType() != Type::Int32Ty)
+          if (Size->getType() != Int32Type)
             Size = CastInst::CreateIntegerCast (Size,
-                                                Type::Int32Ty,
+                                                Int32Type,
                                                 false,
                                                 Size->getName(),
                                                 InsertPt);
 
-          static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+          static Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
           if (OldPtr->getType() != VoidPtrTy)
             OldPtr = CastInst::CreatePointerCast (OldPtr,
                                                   VoidPtrTy,
@@ -231,16 +239,16 @@
           Value *Size        = CS.getArgument(1);
 
           // Ensure the size and pointer arguments are of the correct type
-          if (Size->getType() != Type::Int32Ty)
+          if (Size->getType() != Int32Type)
             Size = CastInst::CreateIntegerCast (Size,
-                                                Type::Int32Ty,
+                                                Int32Type,
                                                 false,
                                                 Size->getName(),
                                                 InsertPt);
 
-          if (NumElements->getType() != Type::Int32Ty)
+          if (NumElements->getType() != Int32Type)
             NumElements = CastInst::CreateIntegerCast (Size,
-                                                Type::Int32Ty,
+                                                Int32Type,
                                                 false,
                                                 NumElements->getName(),
                                                 InsertPt);
@@ -276,7 +284,7 @@
           Value *OldPtr = CS.getArgument(0);
 
           // Ensure the size and pointer arguments are of the correct type
-          static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+          static Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
           if (OldPtr->getType() != VoidPtrTy)
             OldPtr = CastInst::CreatePointerCast (OldPtr,
                                                   VoidPtrTy,
@@ -301,7 +309,7 @@
           SM[Casted] = SM[V] = NH;
         }
       } else if (FreeInst * FI = dyn_cast<FreeInst>(ii)) {
-        Type * VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+        Type * VoidPtrTy = PointerType::getUnqual(Int8Type);
         Value * FreedNode = castTo (FI->getPointerOperand(), VoidPtrTy, "cast", ii);
         DSNode * Node = ECG->getNodeForValue(FI->getPointerOperand()).getNode();
         GlobalVariable * Pool = PoolMap[Node];
@@ -331,12 +339,12 @@
                                       Module& M) {
 
   Function *InitFunc = Function::Create
-    (FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false),
+    (FunctionType::get(VoidType, std::vector<const Type*>(), false),
     GlobalValue::ExternalLinkage, "__poolalloc_init", &M);
 
   // put it into llvm.used so that it won't get killed.
 
-  Type * VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+  Type * VoidPtrTy = PointerType::getUnqual(Int8Type);
   ArrayType * LLVMUsedTy = ArrayType::get(VoidPtrTy, 1);
   Constant * C = ConstantExpr::getBitCast (cast<Constant>(InitFunc), VoidPtrTy);
   std::vector<Constant*> UsedFunctions(1,C);
@@ -347,7 +355,7 @@
       NewInit, "llvm.used");
 
 
-  BasicBlock * BB = BasicBlock::Create("entry", InitFunc);
+  BasicBlock * BB = BasicBlock::Create(getGlobalContext(), "entry", InitFunc);
   
   SteensgaardDataStructures * DS = dynamic_cast<SteensgaardDataStructures*>(Graphs);
   
@@ -376,7 +384,7 @@
     }
   }
 
-  ReturnInst::Create(BB);
+  ReturnInst::Create(getGlobalContext(), BB);
 }
 
 void
@@ -393,8 +401,8 @@
        getPoolType(), false, GlobalValue::ExternalLinkage, 
        ConstantAggregateZero::get(getPoolType()), "__poolalloc_GlobalPool");
 
-    Value *ElSize = ConstantInt::get(Type::Int32Ty, RecSize);
-    Value *AlignV = ConstantInt::get(Type::Int32Ty, Align);
+    Value *ElSize = ConstantInt::get(Int32Type, RecSize);
+    Value *AlignV = ConstantInt::get(Int32Type, Align);
     Value* Opts[3] = {GV, ElSize, AlignV};
     
     CallInst::Create(PoolInit, Opts, Opts + 3, "", InsertAtEnd);

Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Wed Aug 26 15:31:19 2009
@@ -104,6 +104,13 @@
 bool PoolAllocateSimple::runOnModule(Module &M) {
   if (M.begin() == M.end()) return false;
 
+  //
+  // Get pointers to 8 and 32 bit LLVM integer types.
+  //
+  VoidType  = Type::getVoidTy(getGlobalContext());
+  Int8Type  = IntegerType::getInt8Ty(getGlobalContext());
+  Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+
   // Get the Target Data information and the Graphs
   if (CompleteDSA) {
     Graphs = &getAnalysis<EQTDDataStructures>();
@@ -179,7 +186,7 @@
         Value * AllocSize;
         if (MI->isArrayAllocation()) {
           Value * NumElements = MI->getArraySize();
-          Value * ElementSize = ConstantInt::get(Type::Int32Ty,
+          Value * ElementSize = ConstantInt::get(Int32Type,
 						 TD.getTypeAllocSize(MI->getAllocatedType()));
           AllocSize = BinaryOperator::Create (Instruction::Mul,
                                               ElementSize,
@@ -187,7 +194,7 @@
                                               "sizetmp",
                                               MI);
         } else {
-          AllocSize = ConstantInt::get(Type::Int32Ty,
+          AllocSize = ConstantInt::get(Int32Type,
 				       TD.getTypeAllocSize(MI->getAllocatedType()));
         }
 
@@ -215,14 +222,14 @@
           Value *Size = CS.getArgument(1);
 
           // Ensure the size and pointer arguments are of the correct type
-          if (Size->getType() != Type::Int32Ty)
+          if (Size->getType() != Int32Type)
             Size = CastInst::CreateIntegerCast (Size,
-                                                Type::Int32Ty,
+                                                Int32Type,
                                                 false,
                                                 Size->getName(),
                                                 InsertPt);
 
-          static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+          static Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
           if (OldPtr->getType() != VoidPtrTy)
             OldPtr = CastInst::CreatePointerCast (OldPtr,
                                                   VoidPtrTy,
@@ -256,16 +263,16 @@
           Value *Size        = CS.getArgument(1);
 
           // Ensure the size and pointer arguments are of the correct type
-          if (Size->getType() != Type::Int32Ty)
+          if (Size->getType() != Int32Type)
             Size = CastInst::CreateIntegerCast (Size,
-                                                Type::Int32Ty,
+                                                Int32Type,
                                                 false,
                                                 Size->getName(),
                                                 InsertPt);
 
-          if (NumElements->getType() != Type::Int32Ty)
+          if (NumElements->getType() != Int32Type)
             NumElements = CastInst::CreateIntegerCast (Size,
-                                                Type::Int32Ty,
+                                                Int32Type,
                                                 false,
                                                 NumElements->getName(),
                                                 InsertPt);
@@ -297,7 +304,7 @@
           Value *OldPtr = CS.getArgument(0);
 
           // Ensure the size and pointer arguments are of the correct type
-          static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+          static Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
           if (OldPtr->getType() != VoidPtrTy)
             OldPtr = CastInst::CreatePointerCast (OldPtr,
                                                   VoidPtrTy,
@@ -319,7 +326,7 @@
           CI->replaceAllUsesWith(Casted);
         }
       } else if (FreeInst * FI = dyn_cast<FreeInst>(ii)) {
-        Type * VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+        Type * VoidPtrTy = PointerType::getUnqual(Int8Type);
         Value * FreedNode = castTo (FI->getPointerOperand(), VoidPtrTy, "cast", ii);
         toDelete.push_back(ii);
         Value* args[] = {TheGlobalPool, FreedNode};
@@ -359,15 +366,15 @@
 		       "__poolalloc_GlobalPool");
 
   Function *InitFunc = Function::Create
-    (FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false),
+    (FunctionType::get(VoidType, std::vector<const Type*>(), false),
     GlobalValue::ExternalLinkage, "__poolalloc_init", &M);
 
-  BasicBlock * BB = BasicBlock::Create("entry", InitFunc);
-  Value *ElSize = ConstantInt::get(Type::Int32Ty, RecSize);
-  Value *AlignV = ConstantInt::get(Type::Int32Ty, Align);
+  BasicBlock * BB = BasicBlock::Create(getGlobalContext(), "entry", InitFunc);
+  Value *ElSize = ConstantInt::get(Int32Type, RecSize);
+  Value *AlignV = ConstantInt::get(Int32Type, Align);
   Value* Opts[3] = {GV, ElSize, AlignV};
   CallInst::Create(PoolInit, Opts, Opts + 3, "", BB);
 
-  ReturnInst::Create(BB);
+  ReturnInst::Create(getGlobalContext(), BB);
   return GV;
 }

Modified: poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp Wed Aug 26 15:31:19 2009
@@ -42,6 +42,12 @@
 /// system (e.g. 64-bits), only keeping memory objects in MEMUINTTYPE.
 static const Type *SCALARUINTTYPE;
 
+static const Type * VoidType  = 0;
+static const Type * Int8Type  = 0;
+static const Type * Int16Type = 0;
+static const Type * Int32Type = 0;
+static const Type * Int64Type = 0;
+
 namespace {
   cl::opt<bool>
   SmallIntCompress("compress-to-16-bits",
@@ -251,7 +257,7 @@
       return MEMUINTTYPE;
     // Otherwise, it points to a non-compressed node.
     return OrigTy;
-  } else if (OrigTy->isFirstClassType() || OrigTy == Type::VoidTy)
+  } else if (OrigTy->isFirstClassType() || OrigTy == VoidType)
     return OrigTy;
 
 
@@ -287,7 +293,7 @@
     assert(PoolBase == 0 && "Mixing and matching optimized vs not!");
     
     // Get the pool base pointer.
-    Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
+    Constant *Zero = ConstantInt::get(Int32Type, 0);
     Value *Opts[2] = {Zero, Zero};
     Value *BasePtrPtr = GetElementPtrInst::Create(getPoolDesc(), Opts, Opts + 2,
                                               "poolbaseptrptr", &I);
@@ -299,7 +305,7 @@
                           isa<GlobalVariable>(PoolDesc))) {
       BasicBlock::iterator IP = I.getParent()->getParent()->begin()->begin();
       while (isa<AllocaInst>(IP)) ++IP;
-      Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
+      Constant *Zero = ConstantInt::get(Int32Type, 0);
       Value *Opts[2] = {Zero, Zero};
       Value *BasePtrPtr = GetElementPtrInst::Create(getPoolDesc(), Opts, Opts + 2,
                                                 "poolbaseptrptr", IP);
@@ -575,7 +581,8 @@
   if (RI.getNumOperands() && isa<PointerType>(RI.getOperand(0)->getType()))
     if (!isa<PointerType>(RI.getParent()->getParent()->getReturnType())) {
       // Compressing the return value.  
-      ReturnInst::Create(getTransformedValue(RI.getOperand(0)), &RI);
+      ReturnInst::Create(getGlobalContext(),
+                         getTransformedValue(RI.getOperand(0)), &RI);
       RI.eraseFromParent();
     }
 }
@@ -771,8 +778,8 @@
 
   // Get the pointer to load from.
   Value* Ops = getTransformedValue(LI.getOperand(0));
-  if (Ops->getType() == Type::Int16Ty)
-    Ops = CastInst::CreateZExtOrBitCast(Ops, Type::Int32Ty, "extend_idx", &LI);
+  if (Ops->getType() == Int16Type)
+    Ops = CastInst::CreateZExtOrBitCast(Ops, Int32Type, "extend_idx", &LI);
   Value *SrcPtr = GetElementPtrInst::Create(BasePtr, Ops,
                                         LI.getOperand(0)->getName()+".pp", &LI);
   const Type *DestTy = LoadingCompressedPtr ? MEMUINTTYPE : LI.getType();
@@ -836,8 +843,8 @@
 
   // Get the pointer to store to.
   Value* Ops = getTransformedValue(SI.getOperand(1));
-  if (Ops->getType() == Type::Int16Ty)
-    Ops = CastInst::CreateZExtOrBitCast(Ops, Type::Int32Ty, "extend_idx", &SI);
+  if (Ops->getType() == Int16Type)
+    Ops = CastInst::CreateZExtOrBitCast(Ops, Int32Type, "extend_idx", &SI);
 
   Value *DestPtr = GetElementPtrInst::Create(BasePtr, Ops,
                                          SI.getOperand(1)->getName()+".pp",
@@ -862,11 +869,11 @@
   std::vector<Value*> Ops;
   Ops.push_back(CI.getOperand(1));
   // Transform to pass in the compressed size.
-  Ops.push_back(ConstantInt::get(Type::Int32Ty, PI->getNewSize()));
+  Ops.push_back(ConstantInt::get(Int32Type, PI->getNewSize()));
 
   // Pointer compression can reduce the alignment restriction to 4 bytes from 8.
   // Reevaluate the desired alignment.
-  Ops.push_back(ConstantInt::get(Type::Int32Ty,
+  Ops.push_back(ConstantInt::get(Int32Type,
              PA::Heuristic::getRecommendedAlignment(PI->getNewType(), TD)));
   // TODO: Compression could reduce the alignment restriction for the pool!
   Value *PB = CallInst::Create(PtrComp.PoolInitPC, Ops.begin(), Ops.end(), "", &CI);
@@ -901,11 +908,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::Int32Ty, OldSizeV);
-      Value *NewSize = ConstantInt::get(Type::Int32Ty, PI->getNewSize());
+      Value *OldSize = ConstantInt::get(Int32Type, OldSizeV);
+      Value *NewSize = ConstantInt::get(Int32Type, PI->getNewSize());
 
       Size = BinaryOperator::CreateAdd(Size,
-				       ConstantInt::get(Type::Int32Ty, 
+				       ConstantInt::get(Int32Type, 
 							OldSizeV-1),
                                        "roundup", &CI);
       Size = BinaryOperator::CreateUDiv(Size, OldSize, "numnodes", &CI);
@@ -1043,7 +1050,7 @@
     if (NC->getType() != CI.getType())      // Compressing return value?
       setTransformedValue(CI, NC);
     else {
-      if (CI.getType() != Type::VoidTy)
+      if (CI.getType() != VoidType)
         CI.replaceAllUsesWith(NC);
       ValueReplaced(CI, NC);
       CI.eraseFromParent();
@@ -1120,7 +1127,7 @@
   if (NC->getType() != CI.getType())      // Compressing return value?
     setTransformedValue(CI, NC);
   else {
-    if (CI.getType() != Type::VoidTy)
+    if (CI.getType() != VoidType)
       CI.replaceAllUsesWith(NC);
     ValueReplaced(CI, NC);
     CI.eraseFromParent();
@@ -1502,29 +1509,38 @@
 /// InitializePoolLibraryFunctions - Create the function prototypes for pointer
 /// compress runtime library functions.
 void PointerCompress::InitializePoolLibraryFunctions(Module &M) {
-  const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+  const Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
   const Type *PoolDescPtrTy = PointerType::getUnqual(ArrayType::get(VoidPtrTy, 16));
 
   PoolInitPC = M.getOrInsertFunction("poolinit_pc", VoidPtrTy, PoolDescPtrTy, 
-                                     Type::Int32Ty, Type::Int32Ty, NULL);
-  PoolDestroyPC = M.getOrInsertFunction("pooldestroy_pc", Type::VoidTy,
+                                     Int32Type, Int32Type, NULL);
+  PoolDestroyPC = M.getOrInsertFunction("pooldestroy_pc", VoidType,
                                         PoolDescPtrTy, NULL);
   PoolAllocPC = M.getOrInsertFunction("poolalloc_pc", SCALARUINTTYPE,
-                                      PoolDescPtrTy, Type::Int32Ty, NULL);
+                                      PoolDescPtrTy, Int32Type, NULL);
   // FIXME: Need bumppointer versions as well as realloc??/memalign??
 }
 
 bool PointerCompress::runOnModule(Module &M) {
+  //
+  // Get pointers to 8 and 32 bit LLVM integer types.
+  //
+  VoidType  = Type::getVoidTy(getGlobalContext());
+  Int8Type  = IntegerType::getInt8Ty(getGlobalContext());
+  Int16Type = IntegerType::getInt16Ty(getGlobalContext());
+  Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+  Int64Type = IntegerType::getInt64Ty(getGlobalContext());
+
   PoolAlloc = &getAnalysis<PoolAllocatePassAllPools>();
   ECG = &getAnalysis<CompleteBUDataStructures>();
   
   if (SmallIntCompress)
-    MEMUINTTYPE = Type::Int16Ty;
+    MEMUINTTYPE = Int16Type;
   else 
-    MEMUINTTYPE = Type::Int32Ty;
+    MEMUINTTYPE = Int32Type;
 
   // FIXME: make this IntPtrTy.
-  SCALARUINTTYPE = Type::Int64Ty;
+  SCALARUINTTYPE = Int64Type;
 
   // Create the function prototypes for pointer compress runtime library
   // functions.

Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Wed Aug 26 15:31:19 2009
@@ -111,6 +111,13 @@
   CurModule = &M;
 
   //
+  // Get pointers to 8 and 32 bit LLVM integer types.
+  //
+  VoidType  = Type::getVoidTy(getGlobalContext());
+  Int8Type  = IntegerType::getInt8Ty(getGlobalContext());
+  Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+
+  //
   // Get references to the DSA information.  For SAFECode, we need Top-Down
   // DSA.  For Automatic Pool Allocation only, we need Bottom-Up DSA.  In all
   // cases, we need to use the Equivalence-Class version of DSA.
@@ -225,7 +232,7 @@
 void PoolAllocate::AddPoolPrototypes(Module* M) {
   if (VoidPtrTy == 0) {
     // NOTE: If these are changed, make sure to update PoolOptimize.cpp as well!
-    VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+    VoidPtrTy = PointerType::getUnqual(Int8Type);
     PoolDescType = getPoolType();
     PoolDescPtrTy = PointerType::getUnqual(PoolDescType);
   }
@@ -233,33 +240,33 @@
   M->addTypeName("PoolDescriptor", PoolDescType);
   
   // Get poolinit function.
-  PoolInit = M->getOrInsertFunction("poolinit", Type::VoidTy,
-                                            PoolDescPtrTy, Type::Int32Ty,
-                                            Type::Int32Ty, NULL);
+  PoolInit = M->getOrInsertFunction("poolinit", VoidType,
+                                            PoolDescPtrTy, Int32Type,
+                                            Int32Type, NULL);
 
   // Get pooldestroy function.
-  PoolDestroy = M->getOrInsertFunction("pooldestroy", Type::VoidTy,
+  PoolDestroy = M->getOrInsertFunction("pooldestroy", VoidType,
                                                PoolDescPtrTy, NULL);
   
   // The poolalloc function.
   PoolAlloc = M->getOrInsertFunction("poolalloc", 
                                              VoidPtrTy, PoolDescPtrTy,
-                                             Type::Int32Ty, NULL);
+                                             Int32Type, NULL);
   
   // The poolrealloc function.
   PoolRealloc = M->getOrInsertFunction("poolrealloc",
                                                VoidPtrTy, PoolDescPtrTy,
-                                               VoidPtrTy, Type::Int32Ty, NULL);
+                                               VoidPtrTy, Int32Type, NULL);
 
   // The poolcalloc function.
   PoolCalloc = M->getOrInsertFunction("poolcalloc",
                                       VoidPtrTy, PoolDescPtrTy,
-                                      Type::Int32Ty, Type::Int32Ty, NULL);
+                                      Int32Type, Int32Type, NULL);
 
   // The poolmemalign function.
   PoolMemAlign = M->getOrInsertFunction("poolmemalign",
                                                 VoidPtrTy, PoolDescPtrTy,
-                                                Type::Int32Ty, Type::Int32Ty, 
+                                                Int32Type, Int32Type, 
                                                 NULL);
 
   // The poolstrdup function.
@@ -268,11 +275,11 @@
                                                VoidPtrTy, NULL);
   // The poolmemalign function.
   // Get the poolfree function.
-  PoolFree = M->getOrInsertFunction("poolfree", Type::VoidTy,
+  PoolFree = M->getOrInsertFunction("poolfree", VoidType,
                                             PoolDescPtrTy, VoidPtrTy, NULL);
   //Get the poolregister function
-  PoolRegister = M->getOrInsertFunction("poolregister", Type::VoidTy,
-                                 PoolDescPtrTy, VoidPtrTy, Type::Int32Ty, NULL);
+  PoolRegister = M->getOrInsertFunction("poolregister", VoidType,
+                                 PoolDescPtrTy, VoidPtrTy, Int32Type, NULL);
 }
 
 static void getCallsOf(Constant *C, std::vector<CallInst*> &Calls) {
@@ -307,7 +314,8 @@
       if (isa<Constant>(User->getOperand(1)) && 
           cast<Constant>(User->getOperand(1))->isNullValue()) {
         bool CondIsTrue = ICI->getPredicate() == ICmpInst::ICMP_NE;
-        User->replaceAllUsesWith(ConstantInt::get(Type::Int1Ty, CondIsTrue));
+        const Type * Int1Type  = IntegerType::getInt1Ty(getGlobalContext());
+        User->replaceAllUsesWith(ConstantInt::get(Int1Type, CondIsTrue));
       }
     } else if ((User->getOpcode() == Instruction::Trunc) ||
                (User->getOpcode() == Instruction::ZExt) ||
@@ -630,8 +638,8 @@
     while (isa<AllocaInst>(InsertPt)) ++InsertPt;
   }
 
-  Value *ElSize = ConstantInt::get(Type::Int32Ty, RecSize);
-  Value *AlignV = ConstantInt::get(Type::Int32Ty, Align);
+  Value *ElSize = ConstantInt::get(Int32Type, RecSize);
+  Value *AlignV = ConstantInt::get(Int32Type, Align);
   Value* Opts[3] = {GV, ElSize, AlignV};
   CallInst::Create(PoolInit, Opts, Opts + 3, "", InsertPt);
   ++NumPools;
@@ -961,9 +969,9 @@
 
   // Insert the calls to initialize the pool.
   unsigned ElSizeV = Heuristic::getRecommendedSize(Node);
-  Value *ElSize = ConstantInt::get(Type::Int32Ty, ElSizeV);
+  Value *ElSize = ConstantInt::get(Int32Type, ElSizeV);
   unsigned AlignV = Heuristic::getRecommendedAlignment(Node);
-  Value *Align  = ConstantInt::get(Type::Int32Ty, AlignV);
+  Value *Align  = ConstantInt::get(Int32Type, AlignV);
 
   for (unsigned i = 0, e = PoolInitPoints.size(); i != e; ++i) {
     Value* Opts[3] = {PD, ElSize, Align};

Modified: poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp Wed Aug 26 15:31:19 2009
@@ -21,6 +21,10 @@
 #include <set>
 using namespace llvm;
 
+static const Type * VoidType  = 0;
+static const Type * Int8Type  = 0;
+static const Type * Int32Type = 0;
+
 namespace {
   STATISTIC (NumBumpPtr, "Number of bump pointer pools");
 
@@ -55,7 +59,17 @@
 }
 
 bool PoolOptimize::runOnModule(Module &M) {
-  const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+  //
+  // Get pointers to 8 and 32 bit LLVM integer types.
+  //
+  VoidType  = Type::getVoidTy(getGlobalContext());
+  Int8Type  = IntegerType::getInt8Ty(getGlobalContext());
+  Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+
+  //
+  // Create LLVM types used by the pool allocation passes.
+  //
+  const Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
   const Type *PoolDescPtrTy;
   if (SAFECodeEnabled)
     PoolDescPtrTy = PointerType::getUnqual(ArrayType::get(VoidPtrTy, 50));
@@ -63,54 +77,54 @@
     PoolDescPtrTy = PointerType::getUnqual(ArrayType::get(VoidPtrTy, 16));
 
   // Get poolinit function.
-  Constant *PoolInit = M.getOrInsertFunction("poolinit", Type::VoidTy,
-                                             PoolDescPtrTy, Type::Int32Ty,
-                                             Type::Int32Ty, NULL);
+  Constant *PoolInit = M.getOrInsertFunction("poolinit", VoidType,
+                                             PoolDescPtrTy, Int32Type,
+                                             Int32Type, NULL);
 
   // Get pooldestroy function.
-  Constant *PoolDestroy = M.getOrInsertFunction("pooldestroy", Type::VoidTy,
+  Constant *PoolDestroy = M.getOrInsertFunction("pooldestroy", VoidType,
                                                 PoolDescPtrTy, NULL);
   
   // The poolalloc function.
   Constant *PoolAlloc = M.getOrInsertFunction("poolalloc", 
                                               VoidPtrTy, PoolDescPtrTy,
-                                              Type::Int32Ty, NULL);
+                                              Int32Type, NULL);
   
   // The poolrealloc function.
   Constant *PoolRealloc = M.getOrInsertFunction("poolrealloc",
                                                 VoidPtrTy, PoolDescPtrTy,
-                                                VoidPtrTy, Type::Int32Ty, NULL);
+                                                VoidPtrTy, Int32Type, NULL);
   // The poolmemalign function.
   Constant *PoolMemAlign = M.getOrInsertFunction("poolmemalign",
                                                  VoidPtrTy, PoolDescPtrTy,
-                                                 Type::Int32Ty, Type::Int32Ty, 
+                                                 Int32Type, Int32Type, 
                                                  NULL);
 
   // Get the poolfree function.
-  Constant *PoolFree = M.getOrInsertFunction("poolfree", Type::VoidTy,
+  Constant *PoolFree = M.getOrInsertFunction("poolfree", VoidType,
                                              PoolDescPtrTy, VoidPtrTy, NULL);  
 
 
   // Get poolinit_bp function.
-  Constant *PoolInitBP = M.getOrInsertFunction("poolinit_bp", Type::VoidTy,
-                                               PoolDescPtrTy, Type::Int32Ty, 
+  Constant *PoolInitBP = M.getOrInsertFunction("poolinit_bp", VoidType,
+                                               PoolDescPtrTy, Int32Type, 
                                                NULL);
   
   // Get pooldestroy_bp function.
-  Constant *PoolDestroyBP = M.getOrInsertFunction("pooldestroy_bp",Type::VoidTy,
+  Constant *PoolDestroyBP = M.getOrInsertFunction("pooldestroy_bp",VoidType,
                                                  PoolDescPtrTy, NULL);
   
   // The poolalloc_bp function.
   Constant *PoolAllocBP = M.getOrInsertFunction("poolalloc_bp", 
                                                 VoidPtrTy, PoolDescPtrTy,
-                                                Type::Int32Ty, NULL);
+                                                Int32Type, NULL);
 
   Constant *Realloc = M.getOrInsertFunction("realloc",
-                                            VoidPtrTy, VoidPtrTy, Type::Int32Ty,
+                                            VoidPtrTy, VoidPtrTy, Int32Type,
                                             NULL);
   Constant *MemAlign = M.getOrInsertFunction("memalign",
-                                             VoidPtrTy, Type::Int32Ty,
-                                             Type::Int32Ty, NULL);
+                                             VoidPtrTy, Int32Type,
+                                             Int32Type, NULL);
 
 
   // Optimize poolreallocs
@@ -151,7 +165,7 @@
     // poolalloc(null, X) -> malloc(X)
     if (isa<Constant>(CI->getOperand(1)) && 
         cast<Constant>(CI->getOperand(1))->isNullValue()) {
-      Value *New = new MallocInst(Type::Int8Ty, CI->getOperand(2),
+      Value *New = new MallocInst(Int8Type, CI->getOperand(2),
                                   CI->getName(), CI);
       CI->replaceAllUsesWith(New);
       CI->eraseFromParent();

Modified: poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp?rev=80134&r1=80133&r2=80134&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp Wed Aug 26 15:31:19 2009
@@ -38,6 +38,14 @@
 //
 static bool UsingBugpoint = false;
 
+//
+// Variables for referencing LLVM basic types.
+//
+static const Type * VoidType  = 0;
+static const Type * Int8Type  = 0;
+static const Type * Int32Type = 0;
+static const Type * Int64Type = 0;
+
 namespace {
   /// FuncTransform - This class implements transformation required of pool
   /// allocated functions.
@@ -61,6 +69,13 @@
                   std::multimap<AllocaInst*, CallInst*> &poolFrees)
       : PAInfo(P), G(g), FI(fi), 
         PoolUses(poolUses), PoolFrees(poolFrees) {
+      //
+      // Get pointers to 8 and 32 bit LLVM integer types.
+      //
+      VoidType  = Type::getVoidTy(getGlobalContext());
+      Int8Type  = IntegerType::getInt8Ty(getGlobalContext());
+      Int32Type = IntegerType::getInt32Ty(getGlobalContext());
+      Int64Type = IntegerType::getInt64Ty(getGlobalContext());
     }
 
     template <typename InstType, typename SetType>
@@ -163,8 +178,8 @@
                                                      Value *Size) {
   std::string Name = I->getName(); I->setName("");
 
-  if (Size->getType() != Type::Int32Ty)
-    Size = CastInst::CreateIntegerCast(Size, Type::Int32Ty, false, Size->getName(), I);
+  if (Size->getType() != Int32Type)
+    Size = CastInst::CreateIntegerCast(Size, Int32Type, false, Size->getName(), I);
 
   // Insert a call to poolalloc
   Value *PH = getPoolHandle(I);
@@ -215,7 +230,7 @@
   if (PH == 0 || isa<ConstantPointerNull>(PH)) return;
 
   TargetData &TD = PAInfo.getAnalysis<TargetData>();
-  Value *AllocSize = ConstantInt::get(Type::Int32Ty,
+  Value *AllocSize = ConstantInt::get(Int32Type,
 				      TD.getTypeAllocSize(MI.getAllocatedType()));
 
   if (MI.isArrayAllocation())
@@ -247,8 +262,8 @@
       MI.getParent()->getInstList().erase(&MI);
       Value *Casted = AI;
       Instruction *aiNext = AI->getNext();
-      if (AI->getType() != PointerType::getUnqual(Type::Int8Ty))
-        Casted = CastInst::CreatePointerCast(AI, PointerType::getUnqual(Type::Int8Ty),
+      if (AI->getType() != PointerType::getUnqual(Int8Type))
+        Casted = CastInst::CreatePointerCast(AI, PointerType::getUnqual(Int8Type),
               AI->getName()+".casted",aiNext);
       
       Instruction *V = CallInst::Create(PAInfo.PoolRegister,
@@ -273,7 +288,7 @@
     Value *PH = getPoolHandle(&MI);
     if (PH == 0 || isa<ConstantPointerNull>(PH)) return;
     TargetData &TD = PAInfo.getAnalysis<TargetData>();
-    Value *AllocSize = ConstantInt::get(Type::Int32Ty, TD.getTypeAllocSize(MI.getAllocatedType()));
+    Value *AllocSize = ConstantInt::get(Int32Type, TD.getTypeAllocSize(MI.getAllocatedType()));
     
     if (MI.isArrayAllocation())
       AllocSize = BinaryOperator::Create(Instruction::Mul, AllocSize,
@@ -282,7 +297,7 @@
     //  TransformAllocationInstr(&MI, AllocSize);
     BasicBlock::iterator InsertPt(MI);
     ++InsertPt;
-    Instruction *Casted = CastInst::CreatePointerCast(&MI, PointerType::getUnqual(Type::Int8Ty),
+    Instruction *Casted = CastInst::CreatePointerCast(&MI, PointerType::getUnqual(Int8Type),
 				       MI.getName()+".casted", InsertPt);
     std::vector<Value *> args;
     args.push_back (PH);
@@ -301,8 +316,8 @@
 
   // Insert a cast and a call to poolfree...
   Value *Casted = Arg;
-  if (Arg->getType() != PointerType::getUnqual(Type::Int8Ty)) {
-    Casted = CastInst::CreatePointerCast(Arg, PointerType::getUnqual(Type::Int8Ty),
+  if (Arg->getType() != PointerType::getUnqual(Int8Type)) {
+    Casted = CastInst::CreatePointerCast(Arg, PointerType::getUnqual(Int8Type),
 				 Arg->getName()+".casted", Where);
     G->getScalarMap()[Casted] = G->getScalarMap()[Arg];
   }
@@ -334,21 +349,21 @@
 
 void FuncTransform::visitCallocCall(CallSite CS) {
   TargetData& TD = PAInfo.getAnalysis<TargetData>();
-  bool useLong = TD.getTypeAllocSize(PointerType::getUnqual(Type::Int8Ty)) != 4;
+  bool useLong = TD.getTypeAllocSize(PointerType::getUnqual(Int8Type)) != 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::Int64Ty : Type::Int32Ty, V1->getName(), CS.getInstruction());
-    V2 = CastInst::CreateZExtOrBitCast(V2, useLong ? Type::Int64Ty : Type::Int32Ty, V2->getName(), CS.getInstruction());
+    V1 = CastInst::CreateZExtOrBitCast(V1, useLong ? Int64Type : Int32Type, V1->getName(), CS.getInstruction());
+    V2 = CastInst::CreateZExtOrBitCast(V2, useLong ? Int64Type : Int32Type, V2->getName(), CS.getInstruction());
   }
 
   V2 = BinaryOperator::Create(Instruction::Mul, V1, V2, "size",
                               CS.getInstruction());
-  if (V2->getType() != (useLong ? Type::Int64Ty : Type::Int32Ty))
-    V2 = CastInst::CreateZExtOrBitCast(V2, useLong ? Type::Int64Ty : Type::Int32Ty, V2->getName(), CS.getInstruction());
+  if (V2->getType() != (useLong ? Int64Type : Int32Type))
+    V2 = CastInst::CreateZExtOrBitCast(V2, useLong ? Int64Type : Int32Type, V2->getName(), CS.getInstruction());
 
   BasicBlock::iterator BBI =
     TransformAllocationInstr(CS.getInstruction(), V2);
@@ -357,18 +372,18 @@
   // We just turned the call of 'calloc' into the equivalent of malloc.  To
   // finish calloc, we need to zero out the memory.
   Constant *MemSet =  M->getOrInsertFunction((useLong ? "llvm.memset.i64" : "llvm.memset.i32"),
-                                             Type::VoidTy,
-                                             PointerType::getUnqual(Type::Int8Ty),
-                                             Type::Int8Ty, (useLong ? Type::Int64Ty : Type::Int32Ty),
-                                             Type::Int32Ty, NULL);
+                                             VoidType,
+                                             PointerType::getUnqual(Int8Type),
+                                             Int8Type, (useLong ? Int64Type : Int32Type),
+                                             Int32Type, NULL);
 
-  if (Ptr->getType() != PointerType::getUnqual(Type::Int8Ty))
-    Ptr = CastInst::CreatePointerCast(Ptr, PointerType::getUnqual(Type::Int8Ty), Ptr->getName(),
+  if (Ptr->getType() != PointerType::getUnqual(Int8Type))
+    Ptr = CastInst::CreatePointerCast(Ptr, PointerType::getUnqual(Int8Type), Ptr->getName(),
                        BBI);
   
   // We know that the memory returned by poolalloc is at least 4 byte aligned.
-  Value* Opts[4] = {Ptr, ConstantInt::get(Type::Int8Ty, 0),
-                    V2,  ConstantInt::get(Type::Int32Ty, 4)};
+  Value* Opts[4] = {Ptr, ConstantInt::get(Int8Type, 0),
+                    V2,  ConstantInt::get(Int32Type, 4)};
   CallInst::Create(MemSet, Opts, Opts + 4, "", BBI);
 }
 
@@ -383,10 +398,10 @@
   // Don't poolallocate if we have no pool handle
   if (PH == 0 || isa<ConstantPointerNull>(PH)) return;
 
-  if (Size->getType() != Type::Int32Ty)
-    Size = CastInst::CreateIntegerCast(Size, Type::Int32Ty, false, Size->getName(), I);
+  if (Size->getType() != Int32Type)
+    Size = CastInst::CreateIntegerCast(Size, Int32Type, false, Size->getName(), I);
 
-  static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+  static Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
   if (OldPtr->getType() != VoidPtrTy)
     OldPtr = CastInst::CreatePointerCast(OldPtr, VoidPtrTy, OldPtr->getName(), I);
 
@@ -450,15 +465,15 @@
     Value *RetVal = ConstantPointerNull::get(PT);
     I->replaceAllUsesWith(RetVal);
 
-    static const Type *PtrPtr=PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty));
+    static const Type *PtrPtr=PointerType::getUnqual(PointerType::getUnqual(Int8Type));
     if (ResultDest->getType() != PtrPtr)
       ResultDest = CastInst::CreatePointerCast(ResultDest, PtrPtr, ResultDest->getName(), I);
   }
 
-  if (Align->getType() != Type::Int32Ty)
-    Align = CastInst::CreateIntegerCast(Align, Type::Int32Ty, false, Align->getName(), I);
-  if (Size->getType() != Type::Int32Ty)
-    Size = CastInst::CreateIntegerCast(Size, Type::Int32Ty, false, Size->getName(), I);
+  if (Align->getType() != Int32Type)
+    Align = CastInst::CreateIntegerCast(Align, Int32Type, false, Align->getName(), I);
+  if (Size->getType() != Int32Type)
+    Size = CastInst::CreateIntegerCast(Size, Int32Type, false, Size->getName(), I);
 
   std::string Name = I->getName(); I->setName("");
   Value* Opts[3] = {PH, Align, Size};
@@ -511,7 +526,7 @@
 #endif
   Value *OldPtr = CS.getArgument(0);
 
-  static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+  static Type *VoidPtrTy = PointerType::getUnqual(Int8Type);
   if (OldPtr->getType() != VoidPtrTy)
     OldPtr = CastInst::CreatePointerCast(OldPtr, VoidPtrTy, OldPtr->getName(), I);
 
@@ -743,8 +758,8 @@
                                    0,
                                    "PD",
                                    InsertPt);
-          Value *ElSize = ConstantInt::get(Type::Int32Ty,0);
-          Value *Align  = ConstantInt::get(Type::Int32Ty,0);
+          Value *ElSize = ConstantInt::get(Int32Type,0);
+          Value *Align  = ConstantInt::get(Int32Type,0);
           Value* Opts[3] = {ArgVal, ElSize, Align};
           CallInst::Create(PAInfo.PoolInit, Opts, Opts + 3,"", TheCall);
           BasicBlock::iterator BBI = TheCall;
@@ -796,7 +811,7 @@
   TheCall->replaceAllUsesWith(NewCall);
   DEBUG(std::cerr << "  Result Call: " << *NewCall);
 
-  if (TheCall->getType() != Type::VoidTy) {
+  if (TheCall->getType() != VoidType) {
     // If we are modifying the original function, update the DSGraph... 
     DSGraph::ScalarMapTy &SM = G->getScalarMap();
     DSGraph::ScalarMapTy::iterator CII = SM.find(TheCall);





More information about the llvm-commits mailing list