Mercurial > projects > ldc
comparison gen/functions.cpp @ 724:6de2ed4f0abe
Disabled parameter reversing by default, it broke mini/typeinfo10.d
Fixed 'inreg' property placement for functions with reversed parameters.
Made parameter reversal and inreg passing of first arg configurable in premake.lua
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sat, 25 Oct 2008 18:12:07 +0200 |
parents | 55f6c2e454d7 |
children | 1ae94fb1dbbd |
comparison
equal
deleted
inserted
replaced
723:55f6c2e454d7 | 724:6de2ed4f0abe |
---|---|
106 types.push_back(getPtrToType(getPtrToType(ti->ir.irStruct->constInit->getType()))); | 106 types.push_back(getPtrToType(getPtrToType(ti->ir.irStruct->constInit->getType()))); |
107 const LLType* t1 = llvm::StructType::get(types); | 107 const LLType* t1 = llvm::StructType::get(types); |
108 paramvec.push_back(t1); | 108 paramvec.push_back(t1); |
109 paramvec.push_back(getPtrToType(LLType::Int8Ty)); | 109 paramvec.push_back(getPtrToType(LLType::Int8Ty)); |
110 } | 110 } |
111 else if (arrayVararg) | |
112 { | |
113 // do nothing? | |
114 } | |
115 | 111 |
116 // number of formal params | 112 // number of formal params |
117 size_t n = Argument::dim(f->parameters); | 113 size_t n = Argument::dim(f->parameters); |
118 | 114 |
115 #if X86_REVERSE_PARAMS | |
119 // on x86 we need to reverse the formal params in some cases to match the ABI | 116 // on x86 we need to reverse the formal params in some cases to match the ABI |
120 if (global.params.cpu == ARCHx86) | 117 if (global.params.cpu == ARCHx86) |
121 { | 118 { |
122 // more than one formal arg, | 119 // more than one formal arg, |
123 // extern(D) linkage | 120 // extern(D) linkage |
126 { | 123 { |
127 f->reverseParams = true; | 124 f->reverseParams = true; |
128 f->reverseIndex = paramvec.size(); | 125 f->reverseIndex = paramvec.size(); |
129 } | 126 } |
130 } | 127 } |
128 #endif // X86_REVERSE_PARAMS | |
131 | 129 |
132 | 130 |
133 for (int i=0; i < n; ++i) { | 131 for (int i=0; i < n; ++i) { |
134 Argument* arg = Argument::getNth(f->parameters, i); | 132 Argument* arg = Argument::getNth(f->parameters, i); |
135 // ensure scalar | 133 // ensure scalar |
192 | 190 |
193 // construct function type | 191 // construct function type |
194 bool isvararg = !(typesafeVararg || arrayVararg) && f->varargs; | 192 bool isvararg = !(typesafeVararg || arrayVararg) && f->varargs; |
195 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg); | 193 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg); |
196 | 194 |
195 #if X86_PASS_IN_EAX | |
197 // tell first param to be passed in a register if we can | 196 // tell first param to be passed in a register if we can |
198 // ONLY extern(D) functions ! | 197 // ONLY extern(D) functions ! |
199 if ((n > 0 || usesthis || usesnest) && f->linkage == LINKd) | 198 if ((n > 0 || usesthis || usesnest) && f->linkage == LINKd) |
200 { | 199 { |
201 // FIXME: Only x86 right now ... | 200 // FIXME: Only x86 right now ... |
211 } | 210 } |
212 // otherwise check the first formal parameter | 211 // otherwise check the first formal parameter |
213 else | 212 else |
214 { | 213 { |
215 int inreg = f->reverseParams ? n - 1 : 0; | 214 int inreg = f->reverseParams ? n - 1 : 0; |
216 Argument* arg = Argument::getNth(f->parameters, 0); | 215 Argument* arg = Argument::getNth(f->parameters, inreg); |
217 Type* t = arg->type->toBasetype(); | 216 Type* t = arg->type->toBasetype(); |
218 | 217 |
219 // 32bit ints, pointers, classes and static arrays are candidate for being passed in EAX | 218 // 32bit ints, pointers, classes, static arrays and AAs |
219 // are candidate for being passed in EAX | |
220 if ((arg->storageClass & STCin) && | 220 if ((arg->storageClass & STCin) && |
221 ((t->isscalar() && !t->isfloating()) || t->ty == Tclass || t->ty == Tsarray) && | 221 ((t->isscalar() && !t->isfloating()) || |
222 t->ty == Tclass || t->ty == Tsarray || t->ty == Taarray) && | |
222 (t->size() <= PTRSIZE)) | 223 (t->size() <= PTRSIZE)) |
223 { | 224 { |
224 arg->llvmAttrs |= llvm::Attribute::InReg; | 225 arg->llvmAttrs |= llvm::Attribute::InReg; |
225 } | 226 } |
226 } | 227 } |
227 } | 228 } |
228 } | 229 } |
230 #endif // X86_PASS_IN_EAX | |
229 | 231 |
230 // done | 232 // done |
231 f->retInPtr = retinptr; | 233 f->retInPtr = retinptr; |
232 f->usesThis = usesthis; | 234 f->usesThis = usesthis; |
233 f->usesNest = usesnest; | 235 f->usesNest = usesnest; |