diff gen/tollvm.cpp @ 1210:3d4581761b4c

Add some alignment info where LLVM might otherwise be more pessimistic. In particular, %.nest_arg is always aligned even though it's bitcast from i8*. Pointers in vtables are also guaranteed to be stored at aligned addresses.
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 12 Apr 2009 21:56:43 +0200
parents 3251ce06c820
children 7e5547d8e59f
line wrap: on
line diff
--- a/gen/tollvm.cpp	Sun Apr 12 20:23:00 2009 +0200
+++ b/gen/tollvm.cpp	Sun Apr 12 21:56:43 2009 +0200
@@ -426,7 +426,7 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes)
+void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes, unsigned align)
 {
     dst = DtoBitCast(dst,getVoidPtrType());
     src = DtoBitCast(src,getVoidPtrType());
@@ -435,7 +435,7 @@
     llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module,
         llvm::Intrinsic::memcpy, &intTy, 1);
 
-    gIR->ir->CreateCall4(fn, dst, src, nbytes, DtoConstUint(0), "");
+    gIR->ir->CreateCall4(fn, dst, src, nbytes, DtoConstUint(align), "");
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -573,11 +573,20 @@
 {
 //     if (Logger::enabled())
 //         Logger::cout() << "loading " << *src <<  '\n';
-    LLValue* ld = gIR->ir->CreateLoad(src, name ? name : "tmp");
+    llvm::LoadInst* ld = gIR->ir->CreateLoad(src, name ? name : "tmp");
     //ld->setVolatile(gIR->func()->inVolatile);
     return ld;
 }
 
+// Like DtoLoad, but the pointer is guaranteed to be aligned appropriately for the type.
+LLValue* DtoAlignedLoad(LLValue* src, const char* name)
+{
+    llvm::LoadInst* ld = gIR->ir->CreateLoad(src, name ? name : "tmp");
+    ld->setAlignment(getABITypeAlign(ld->getType()));
+    return ld;
+}
+
+
 void DtoStore(LLValue* src, LLValue* dst)
 {
 //     if (Logger::enabled())
@@ -586,6 +595,13 @@
     //st->setVolatile(gIR->func()->inVolatile);
 }
 
+// Like DtoStore, but the pointer is guaranteed to be aligned appropriately for the type.
+void DtoAlignedStore(LLValue* src, LLValue* dst)
+{
+    llvm::StoreInst* st = gIR->ir->CreateStore(src,dst);
+    st->setAlignment(getABITypeAlign(src->getType()));
+}
+
 //////////////////////////////////////////////////////////////////////////////////////////
 
 LLValue* DtoBitCast(LLValue* v, const LLType* t, const char* name)