comparison gen/functions.cpp @ 454:283d113d4753

Added generation of the llvm 'sret' parameter attribute where applicable. Fixed some wrong argument handling code when setting parameter attributes. Updated the tango unittest script in the tango patch, does not work yet, all modules don't compile...
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 02 Aug 2008 02:54:57 +0200
parents 30ef3c7bddca
children d3d3519b72e8
comparison
equal deleted inserted replaced
453:60332cd85308 454:283d113d4753
156 TypeFunction *ltf = new TypeFunction(NULL, arg->type, 0, LINKd); 156 TypeFunction *ltf = new TypeFunction(NULL, arg->type, 0, LINKd);
157 TypeDelegate *ltd = new TypeDelegate(ltf); 157 TypeDelegate *ltd = new TypeDelegate(ltf);
158 at = getPtrToType(DtoType(ltd)); 158 at = getPtrToType(DtoType(ltd));
159 Logger::cout() << "lazy updated to: " << *at << '\n'; 159 Logger::cout() << "lazy updated to: " << *at << '\n';
160 paramvec.back() = at; 160 paramvec.back() = at;
161 } 161 // lazy doesn't need byval as the delegate is not visible to the user
162 } 162 }
163 163 }
164 //warning("set %d byval args for type: %s", nbyval, f->toChars());
165 164
166 // construct function type 165 // construct function type
167 bool isvararg = !(typesafeVararg || arrayVararg) && f->varargs; 166 bool isvararg = !(typesafeVararg || arrayVararg) && f->varargs;
168 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg); 167 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg);
169 168
304 303
305 ////////////////////////////////////////////////////////////////////////////////////////// 304 //////////////////////////////////////////////////////////////////////////////////////////
306 305
307 static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl) 306 static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl)
308 { 307 {
309 assert(f->parameters);
310
311 int llidx = 1; 308 int llidx = 1;
312 if (f->llvmRetInPtr) ++llidx; 309 if (f->llvmRetInPtr) ++llidx;
313 if (f->llvmUsesThis) ++llidx; 310 if (f->llvmUsesThis) ++llidx;
314 if (f->linkage == LINKd && f->varargs == 1) 311 if (f->linkage == LINKd && f->varargs == 1)
315 llidx += 2; 312 llidx += 2;
326 PAWI.Index = 0; 323 PAWI.Index = 0;
327 PAWI.Attrs = f->llvmRetAttrs; 324 PAWI.Attrs = f->llvmRetAttrs;
328 attrs.push_back(PAWI); 325 attrs.push_back(PAWI);
329 } 326 }
330 327
328 // set sret param
329 if (f->llvmRetInPtr)
330 {
331 PAWI.Index = 1;
332 PAWI.Attrs = llvm::ParamAttr::StructRet;
333 attrs.push_back(PAWI);
334 }
335
331 // set byval attrs on implicit main arg 336 // set byval attrs on implicit main arg
332 if (fdecl->isMain() && Argument::dim(f->parameters) == 0) 337 if (fdecl->isMain() && Argument::dim(f->parameters) == 0)
333 { 338 {
334 PAWI.Index = llidx; 339 PAWI.Index = llidx;
335 PAWI.Attrs = llvm::ParamAttr::ByVal; 340 PAWI.Attrs = llvm::ParamAttr::ByVal;
336 attrs.push_back(PAWI); 341 attrs.push_back(PAWI);
337 llidx++; 342 llidx++;
338 } 343 }
339 344
340 // set attrs on the rest of the arguments 345 // set attrs on the rest of the arguments
341 for (; llidx <= funcNumArgs && f->parameters->dim > k; ++llidx,++k) 346 for (; llidx <= funcNumArgs && Argument::dim(f->parameters) > k; ++llidx,++k)
342 { 347 {
343 Argument* fnarg = (Argument*)f->parameters->data[k]; 348 Argument* fnarg = Argument::getNth(f->parameters, k);
344 assert(fnarg); 349 assert(fnarg);
345 350
346 PAWI.Index = llidx; 351 PAWI.Index = llidx;
347 PAWI.Attrs = fnarg->llvmAttrs; 352 PAWI.Attrs = fnarg->llvmAttrs;
348 353
426 431
427 fdecl->ir.irFunc->func = func; 432 fdecl->ir.irFunc->func = func;
428 assert(llvm::isa<llvm::FunctionType>(f->ir.type->get())); 433 assert(llvm::isa<llvm::FunctionType>(f->ir.type->get()));
429 434
430 // parameter attributes 435 // parameter attributes
431 if (f->parameters && !fdecl->isIntrinsic()) { 436 if (!fdecl->isIntrinsic()) {
432 set_param_attrs(f, func, fdecl); 437 set_param_attrs(f, func, fdecl);
433 } 438 }
434 439
435 // main 440 // main
436 if (fdecl->isMain()) { 441 if (fdecl->isMain()) {
456 iarg->setName("retval"); 461 iarg->setName("retval");
457 fdecl->ir.irFunc->retArg = iarg; 462 fdecl->ir.irFunc->retArg = iarg;
458 ++iarg; 463 ++iarg;
459 } 464 }
460 if (f->llvmUsesThis) { 465 if (f->llvmUsesThis) {
461 iarg->setName("this"); 466 iarg->setName(fdecl->isNested()?".context":"this");
462 fdecl->ir.irFunc->thisVar = iarg; 467 fdecl->ir.irFunc->thisVar = iarg;
463 assert(fdecl->ir.irFunc->thisVar); 468 assert(fdecl->ir.irFunc->thisVar);
464 ++iarg; 469 ++iarg;
465 } 470 }
466 471