Mercurial > projects > ldc
comparison 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 |
comparison
equal
deleted
inserted
replaced
1349:a376776e2301 | 1350:15e9762bb620 |
---|---|
93 /*//////////////////////////////////////////////////////////////////////////////////////// | 93 /*//////////////////////////////////////////////////////////////////////////////////////// |
94 // ALLOCA HELPERS | 94 // ALLOCA HELPERS |
95 ////////////////////////////////////////////////////////////////////////////////////////*/ | 95 ////////////////////////////////////////////////////////////////////////////////////////*/ |
96 | 96 |
97 | 97 |
98 llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name) | 98 llvm::AllocaInst* DtoAlloca(Type* type, const char* name) |
99 { | 99 { |
100 return new llvm::AllocaInst(lltype, name, gIR->topallocapoint()); | 100 const llvm::Type* lltype = DtoType(type); |
101 } | 101 llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint()); |
102 | 102 ai->setAlignment(type->alignsize()); |
103 llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name) | 103 return ai; |
104 { | 104 } |
105 return new llvm::AllocaInst(lltype, arraysize, name, gIR->topallocapoint()); | 105 |
106 llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name) | |
107 { | |
108 const llvm::Type* lltype = DtoType(type); | |
109 llvm::AllocaInst* ai = new llvm::AllocaInst( | |
110 lltype, DtoConstUint(arraysize), name, gIR->topallocapoint()); | |
111 ai->setAlignment(type->alignsize()); | |
112 return ai; | |
113 } | |
114 | |
115 llvm::AllocaInst* DtoRawAlloca(const llvm::Type* lltype, size_t alignment, const char* name) | |
116 { | |
117 llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint()); | |
118 if (alignment) | |
119 ai->setAlignment(alignment); | |
120 return ai; | |
106 } | 121 } |
107 | 122 |
108 | 123 |
109 /****************************************************************************************/ | 124 /****************************************************************************************/ |
110 /*//////////////////////////////////////////////////////////////////////////////////////// | 125 /*//////////////////////////////////////////////////////////////////////////////////////// |
892 | 907 |
893 llvm::Value* allocainst; | 908 llvm::Value* allocainst; |
894 if(gTargetData->getTypeSizeInBits(lltype) == 0) | 909 if(gTargetData->getTypeSizeInBits(lltype) == 0) |
895 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); | 910 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); |
896 else | 911 else |
897 allocainst = DtoAlloca(lltype, vd->toChars()); | 912 allocainst = DtoAlloca(vd->type, vd->toChars()); |
898 | 913 |
899 //allocainst->setAlignment(vd->type->alignsize()); // TODO | 914 //allocainst->setAlignment(vd->type->alignsize()); // TODO |
900 vd->ir.irLocal = new IrLocal(vd); | 915 vd->ir.irLocal = new IrLocal(vd); |
901 vd->ir.irLocal->value = allocainst; | 916 vd->ir.irLocal->value = allocainst; |
902 | 917 |
1008 | 1023 |
1009 // alloca if necessary | 1024 // alloca if necessary |
1010 LLValue* allocaval = NULL; | 1025 LLValue* allocaval = NULL; |
1011 if (!addr && (!var->ir.irLocal || !var->ir.irLocal->value)) | 1026 if (!addr && (!var->ir.irLocal || !var->ir.irLocal->value)) |
1012 { | 1027 { |
1013 addr = DtoAlloca(DtoType(var->type), var->toChars()); | 1028 addr = DtoAlloca(var->type, var->toChars()); |
1014 | 1029 |
1015 // add debug info | 1030 // add debug info |
1016 if (global.params.symdebug) | 1031 if (global.params.symdebug) |
1017 DtoDwarfLocalVariable(addr, var); | 1032 DtoDwarfLocalVariable(addr, var); |
1018 } | 1033 } |