diff gen/llvmhelpers.cpp @ 1350:15e9762bb620

Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Thu, 14 May 2009 13:26:40 +0200
parents 04c36605feb9
children 8d501abecd24
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Wed May 13 18:08:40 2009 +0200
+++ b/gen/llvmhelpers.cpp	Thu May 14 13:26:40 2009 +0200
@@ -95,14 +95,29 @@
 ////////////////////////////////////////////////////////////////////////////////////////*/
 
 
-llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name)
+llvm::AllocaInst* DtoAlloca(Type* type, const char* name)
 {
-    return new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
+    const llvm::Type* lltype = DtoType(type);
+    llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
+    ai->setAlignment(type->alignsize());
+    return ai;
 }
 
-llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name)
+llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name)
 {
-    return new llvm::AllocaInst(lltype, arraysize, name, gIR->topallocapoint());
+    const llvm::Type* lltype = DtoType(type);
+    llvm::AllocaInst* ai = new llvm::AllocaInst(
+        lltype, DtoConstUint(arraysize), name, gIR->topallocapoint());
+    ai->setAlignment(type->alignsize());
+    return ai;
+}
+
+llvm::AllocaInst* DtoRawAlloca(const llvm::Type* lltype, size_t alignment, const char* name)
+{
+    llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
+    if (alignment)
+        ai->setAlignment(alignment);
+    return ai;
 }
 
 
@@ -894,7 +909,7 @@
                 if(gTargetData->getTypeSizeInBits(lltype) == 0) 
                     allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype));
                 else
-                    allocainst = DtoAlloca(lltype, vd->toChars());
+                    allocainst = DtoAlloca(vd->type, vd->toChars());
 
                 //allocainst->setAlignment(vd->type->alignsize()); // TODO
                 vd->ir.irLocal = new IrLocal(vd);
@@ -1010,7 +1025,7 @@
     LLValue* allocaval = NULL;
     if (!addr && (!var->ir.irLocal || !var->ir.irLocal->value))
     {
-        addr = DtoAlloca(DtoType(var->type), var->toChars());
+        addr = DtoAlloca(var->type, var->toChars());
         
         // add debug info
         if (global.params.symdebug)