Mercurial > projects > ldc
comparison gen/functions.cpp @ 938:a904cc9bc064
Convert struct arg to integer when passing inreg to make sure LLVM doesn't
ignore the attribute!
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Wed, 04 Feb 2009 18:39:33 +0100 |
parents | 7985bb036db4 |
children | cac9895be400 |
comparison
equal
deleted
inserted
replaced
931:b6647328d11e | 938:a904cc9bc064 |
---|---|
218 ) | 218 ) |
219 { | 219 { |
220 arg->llvmAttrs |= llvm::Attribute::InReg; | 220 arg->llvmAttrs |= llvm::Attribute::InReg; |
221 assert((f->thisAttrs & llvm::Attribute::InReg) == 0 && "can't have two inreg args!"); | 221 assert((f->thisAttrs & llvm::Attribute::InReg) == 0 && "can't have two inreg args!"); |
222 | 222 |
223 // structs need to go from {...}* byval to {...} inreg | 223 // structs need to go from {...}* byval to i8/i16/i32 inreg |
224 if ((arg->storageClass & STCin) && t->ty == Tstruct) | 224 if ((arg->storageClass & STCin) && t->ty == Tstruct) |
225 { | 225 { |
226 int n_param = f->reverseParams ? f->firstRealArg + n - 1 - n_inreg : f->firstRealArg + n_inreg; | 226 int n_param = f->reverseParams ? f->firstRealArg + n - 1 - n_inreg : f->firstRealArg + n_inreg; |
227 assert(isaPointer(paramvec[n_param]) && (arg->llvmAttrs & llvm::Attribute::ByVal) | 227 assert(isaPointer(paramvec[n_param]) && (arg->llvmAttrs & llvm::Attribute::ByVal) |
228 && "struct parameter expected to be {...}* byval before inreg is applied"); | 228 && "struct parameter expected to be {...}* byval before inreg is applied"); |
229 paramvec[n_param] = paramvec[n_param]->getContainedType(0); | 229 f->structInregArg = paramvec[n_param]->getContainedType(0); |
230 paramvec[n_param] = LLIntegerType::get(8*t->size()); | |
230 arg->llvmAttrs &= ~llvm::Attribute::ByVal; | 231 arg->llvmAttrs &= ~llvm::Attribute::ByVal; |
231 f->structInregArg = true; | |
232 } | 232 } |
233 } | 233 } |
234 } | 234 } |
235 } | 235 } |
236 } | 236 } |
757 | 757 |
758 // if it's inreg struct arg, allocate storage | 758 // if it's inreg struct arg, allocate storage |
759 if (f->structInregArg && i == (f->reverseParams ? n - 1 : 0)) | 759 if (f->structInregArg && i == (f->reverseParams ? n - 1 : 0)) |
760 { | 760 { |
761 int n_param = f->reverseParams ? f->firstRealArg + n - 1 - i : f->firstRealArg + i; | 761 int n_param = f->reverseParams ? f->firstRealArg + n - 1 - i : f->firstRealArg + i; |
762 assert(!f->usesNest && !f->usesThis && isaStruct(functype->getParamType(n_param)) | 762 const LLType* paramty = functype->getParamType(n_param); |
763 assert(!f->usesNest && !f->usesThis && | |
764 llvm::isa<LLIntegerType>(paramty) && isaStruct(f->structInregArg) | |
763 && "Preconditions for inreg struct arg not met!"); | 765 && "Preconditions for inreg struct arg not met!"); |
764 | 766 |
765 LLValue* mem = DtoAlloca(functype->getParamType(n_param), "inregstructarg"); | 767 LLValue* mem = DtoAlloca(f->structInregArg, "inregstructarg"); |
766 DtoStore(irloc->value, mem); | 768 |
769 DtoStore(irloc->value, DtoBitCast(mem, getPtrToType(paramty))); | |
767 irloc->value = mem; | 770 irloc->value = mem; |
768 } | 771 } |
769 | 772 |
770 #if DMDV2 | 773 #if DMDV2 |
771 if (vd->nestedrefs.dim) | 774 if (vd->nestedrefs.dim) |