[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp LowerInvoke.cpp ScalarReplAggregates.cpp

Nate Begeman natebegeman at mac.com
Sat Nov 5 01:21:43 PST 2005



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.405 -> 1.406
LowerInvoke.cpp updated: 1.34 -> 1.35
ScalarReplAggregates.cpp updated: 1.31 -> 1.32
---
Log message:

Add support alignment of allocation instructions.
Add support for specifying alignment and size of setjmp jmpbufs.

No targets currently do anything with this information, nor is it presrved
in the bytecode representation.  That's coming up next.


---
Diffs of the changes:  (+19 -15)

 InstructionCombining.cpp |    8 ++++----
 LowerInvoke.cpp          |   21 ++++++++++++---------
 ScalarReplAggregates.cpp |    5 +++--
 3 files changed, 19 insertions(+), 15 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.405 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.406
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.405	Sat Nov  5 01:40:31 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sat Nov  5 03:21:28 2005
@@ -3936,9 +3936,9 @@
   std::string Name = AI.getName(); AI.setName("");
   AllocationInst *New;
   if (isa<MallocInst>(AI))
-    New = new MallocInst(CastElTy, Amt, Name);
+    New = new MallocInst(CastElTy, Amt, AI.getAlignment(), Name);
   else
-    New = new AllocaInst(CastElTy, Amt, Name);
+    New = new AllocaInst(CastElTy, Amt, AI.getAlignment(), Name);
   InsertNewInstBefore(New, AI);
   
   // If the allocation has multiple uses, insert a cast and change all things
@@ -5266,10 +5266,10 @@
 
       // Create and insert the replacement instruction...
       if (isa<MallocInst>(AI))
-        New = new MallocInst(NewTy, 0, AI.getName());
+        New = new MallocInst(NewTy, 0, AI.getAlignment(), AI.getName());
       else {
         assert(isa<AllocaInst>(AI) && "Unknown type of allocation inst!");
-        New = new AllocaInst(NewTy, 0, AI.getName());
+        New = new AllocaInst(NewTy, 0, AI.getAlignment(), AI.getName());
       }
 
       InsertNewInstBefore(New, AI);


Index: llvm/lib/Transforms/Scalar/LowerInvoke.cpp
diff -u llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.34 llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.35
--- llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.34	Sat Oct 22 23:37:20 2005
+++ llvm/lib/Transforms/Scalar/LowerInvoke.cpp	Sat Nov  5 03:21:28 2005
@@ -67,6 +67,8 @@
     GlobalVariable *JBListHead;
     Function *SetJmpFn, *LongJmpFn;
   public:
+    LowerInvoke(unsigned Size = 200, unsigned Align = 0) : JumpBufSize(Size),
+      JumpBufAlign(Align) {}
     bool doInitialization(Module &M);
     bool runOnFunction(Function &F);
     
@@ -78,6 +80,9 @@
     void rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
                                 AllocaInst *InvokeNum, SwitchInst *CatchSwitch);
     bool insertExpensiveEHSupport(Function &F);
+    
+    unsigned JumpBufSize;
+    unsigned JumpBufAlign;
   };
 
   RegisterOpt<LowerInvoke>
@@ -87,7 +92,10 @@
 const PassInfo *llvm::LowerInvokePassID = X.getPassInfo();
 
 // Public Interface To the LowerInvoke pass.
-FunctionPass *llvm::createLowerInvokePass() { return new LowerInvoke(); }
+FunctionPass *llvm::createLowerInvokePass(unsigned JumpBufSize, 
+                                          unsigned JumpBufAlign) { 
+  return new LowerInvoke(JumpBufSize, JumpBufAlign); 
+}
 
 // doInitialization - Make sure that there is a prototype for abort in the
 // current module.
@@ -95,13 +103,8 @@
   const Type *VoidPtrTy = PointerType::get(Type::SByteTy);
   AbortMessage = 0;
   if (ExpensiveEHSupport) {
-    // Insert a type for the linked list of jump buffers.  Unfortunately, we
-    // don't know the size of the target's setjmp buffer, so we make a guess.
-    // If this guess turns out to be too small, bad stuff could happen.
-    unsigned JmpBufSize = 200;  // PPC has 192 words
-    assert(sizeof(jmp_buf) <= JmpBufSize*sizeof(void*) &&
-       "LowerInvoke doesn't know about targets with jmp_buf size > 200 words!");
-    const Type *JmpBufTy = ArrayType::get(VoidPtrTy, JmpBufSize);
+    // Insert a type for the linked list of jump buffers.
+    const Type *JmpBufTy = ArrayType::get(VoidPtrTy, JumpBufSize);
 
     { // The type is recursive, so use a type holder.
       std::vector<const Type*> Elements;
@@ -441,7 +444,7 @@
     // that needs to be restored on all exits from the function.  This is an
     // alloca because the value needs to be live across invokes.
     AllocaInst *JmpBuf = 
-      new AllocaInst(JBLinkTy, 0, "jblink", F.begin()->begin());
+      new AllocaInst(JBLinkTy, 0, JumpBufAlign, "jblink", F.begin()->begin());
     
     std::vector<Value*> Idx;
     Idx.push_back(Constant::getNullValue(Type::IntTy));


Index: llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp
diff -u llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.31 llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.32
--- llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.31	Thu Apr 21 18:45:12 2005
+++ llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp	Sat Nov  5 03:21:28 2005
@@ -159,7 +159,8 @@
     if (const StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) {
       ElementAllocas.reserve(ST->getNumContainedTypes());
       for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i) {
-        AllocaInst *NA = new AllocaInst(ST->getContainedType(i), 0,
+        AllocaInst *NA = new AllocaInst(ST->getContainedType(i), 0, 
+                                        AI->getAlignment(),
                                         AI->getName() + "." + utostr(i), AI);
         ElementAllocas.push_back(NA);
         WorkList.push_back(NA);  // Add to worklist for recursive processing
@@ -169,7 +170,7 @@
       ElementAllocas.reserve(AT->getNumElements());
       const Type *ElTy = AT->getElementType();
       for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
-        AllocaInst *NA = new AllocaInst(ElTy, 0,
+        AllocaInst *NA = new AllocaInst(ElTy, 0, AI->getAlignment(),
                                         AI->getName() + "." + utostr(i), AI);
         ElementAllocas.push_back(NA);
         WorkList.push_back(NA);  // Add to worklist for recursive processing






More information about the llvm-commits mailing list