comparison gen/functions.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 854e86eaa022
children 34f2fd925de3
comparison
equal deleted inserted replaced
1349:a376776e2301 1350:15e9762bb620
681 681
682 //assert(gIR->scopes.empty()); 682 //assert(gIR->scopes.empty());
683 gIR->scopes.push_back(IRScope(beginbb, endbb)); 683 gIR->scopes.push_back(IRScope(beginbb, endbb));
684 684
685 // create alloca point 685 // create alloca point
686 // this gets erased when the function is complete, so alignment etc does not matter at all
686 llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::Int32Ty, "alloca point", beginbb); 687 llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::Int32Ty, "alloca point", beginbb);
687 irfunction->allocapoint = allocaPoint; 688 irfunction->allocapoint = allocaPoint;
688 689
689 // debug info - after all allocas, but before any llvm.dbg.declare etc 690 // debug info - after all allocas, but before any llvm.dbg.declare etc
690 if (global.params.symdebug) DtoDwarfFuncStart(fd); 691 if (global.params.symdebug) DtoDwarfFuncStart(fd);
702 if (f->fty.arg_this) 703 if (f->fty.arg_this)
703 { 704 {
704 LLValue* thisvar = irfunction->thisArg; 705 LLValue* thisvar = irfunction->thisArg;
705 assert(thisvar); 706 assert(thisvar);
706 707
707 LLValue* thismem = DtoAlloca(thisvar->getType(), "this"); 708 LLValue* thismem = DtoRawAlloca(thisvar->getType(), 0, "this"); // FIXME: align?
708 DtoStore(thisvar, thismem); 709 DtoStore(thisvar, thismem);
709 irfunction->thisArg = thismem; 710 irfunction->thisArg = thismem;
710 711
711 assert(!fd->vthis->ir.irLocal); 712 assert(!fd->vthis->ir.irLocal);
712 fd->vthis->ir.irLocal = new IrLocal(fd->vthis); 713 fd->vthis->ir.irLocal = new IrLocal(fd->vthis);
758 const LLType* argt; 759 const LLType* argt;
759 if (lazy) 760 if (lazy)
760 argt = irloc->value->getType(); 761 argt = irloc->value->getType();
761 else 762 else
762 argt = DtoType(vd->type); 763 argt = DtoType(vd->type);
763 LLValue* mem = DtoAlloca(argt, vd->ident->toChars()); 764 LLValue* mem = DtoRawAlloca(argt, 0, vd->ident->toChars());
764 765
765 // let the abi transform the argument back first 766 // let the abi transform the argument back first
766 DImValue arg_dval(vd->type, irloc->value); 767 DImValue arg_dval(vd->type, irloc->value);
767 f->fty.getParam(vd->type, i, &arg_dval, mem); 768 f->fty.getParam(vd->type, i, &arg_dval, mem);
768 769
794 #endif 795 #endif
795 { 796 {
796 DtoNestedInit(fd->vresult); 797 DtoNestedInit(fd->vresult);
797 } else if (fd->vresult) { 798 } else if (fd->vresult) {
798 fd->vresult->ir.irLocal = new IrLocal(fd->vresult); 799 fd->vresult->ir.irLocal = new IrLocal(fd->vresult);
799 fd->vresult->ir.irLocal->value = DtoAlloca(DtoType(fd->vresult->type), fd->vresult->toChars()); 800 fd->vresult->ir.irLocal->value = DtoAlloca(fd->vresult->type, fd->vresult->toChars());
800 } 801 }
801 802
802 // copy _argptr and _arguments to a memory location 803 // copy _argptr and _arguments to a memory location
803 if (f->linkage == LINKd && f->varargs == 1) 804 if (f->linkage == LINKd && f->varargs == 1)
804 { 805 {
805 // _argptr 806 // _argptr
806 LLValue* argptrmem = DtoAlloca(fd->ir.irFunc->_argptr->getType(), "_argptr_mem"); 807 LLValue* argptrmem = DtoRawAlloca(fd->ir.irFunc->_argptr->getType(), 0, "_argptr_mem");
807 new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb()); 808 new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb());
808 fd->ir.irFunc->_argptr = argptrmem; 809 fd->ir.irFunc->_argptr = argptrmem;
809 810
810 // _arguments 811 // _arguments
811 LLValue* argumentsmem = DtoAlloca(fd->ir.irFunc->_arguments->getType(), "_arguments_mem"); 812 LLValue* argumentsmem = DtoRawAlloca(fd->ir.irFunc->_arguments->getType(), 0, "_arguments_mem");
812 new llvm::StoreInst(fd->ir.irFunc->_arguments, argumentsmem, gIR->scopebb()); 813 new llvm::StoreInst(fd->ir.irFunc->_arguments, argumentsmem, gIR->scopebb());
813 fd->ir.irFunc->_arguments = argumentsmem; 814 fd->ir.irFunc->_arguments = argumentsmem;
814 } 815 }
815 816
816 // output function body 817 // output function body
916 return arg; 917 return arg;
917 } 918 }
918 // byval arg, but expr has no storage yet 919 // byval arg, but expr has no storage yet
919 else if (DtoIsPassedByRef(argexp->type) && (arg->isSlice() || arg->isNull())) 920 else if (DtoIsPassedByRef(argexp->type) && (arg->isSlice() || arg->isNull()))
920 { 921 {
921 LLValue* alloc = DtoAlloca(DtoType(argexp->type), ".tmp_arg"); 922 LLValue* alloc = DtoAlloca(argexp->type, ".tmp_arg");
922 DVarValue* vv = new DVarValue(argexp->type, alloc); 923 DVarValue* vv = new DVarValue(argexp->type, alloc);
923 DtoAssign(argexp->loc, vv, arg); 924 DtoAssign(argexp->loc, vv, arg);
924 arg = vv; 925 arg = vv;
925 } 926 }
926 927