comparison gen/functions.cpp @ 945:03d7c4aac654

SWITCHED TO LLVM 2.5 ! Applied patch from ticket #129 to compile against latest LLVM. Thanks Frits van Bommel. Fixed implicit return by asm block at the end of a function on x86-32. Other architectures will produce an error at the moment. Adding support for new targets is fairly simple. Fixed return calling convention for complex numbers, ST and ST(1) were switched around. Added some testcases. I've run a dstress test and there are no regressions. However, the runtime does not seem to compile with symbolic debug information. -O3 -release -inline works well and is what I used for the dstress run. Tango does not compile, a small workaround is needed in tango.io.digest.Digest.Digest.hexDigest. See ticket #206 .
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sun, 08 Feb 2009 05:26:54 +0100
parents 39519a1ff603
children 1714836f2c0b
comparison
equal deleted inserted replaced
944:eb310635d80e 945:03d7c4aac654
905 } 905 }
906 906
907 // output function body 907 // output function body
908 fd->fbody->toIR(gIR); 908 fd->fbody->toIR(gIR);
909 909
910 // TODO: clean up this mess
911
912 // std::cout << *func << std::endl;
913
910 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement 914 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement
911 // in automatically, so we do it here. 915 // in automatically, so we do it here.
912 if (!gIR->scopereturned()) { 916 if (!gIR->scopereturned()) {
913 // pass the previous block into this block 917 // pass the previous block into this block
914 if (global.params.symdebug) DtoDwarfFuncEnd(fd); 918 if (global.params.symdebug) DtoDwarfFuncEnd(fd);
915 if (func->getReturnType() == LLType::VoidTy) { 919 if (func->getReturnType() == LLType::VoidTy) {
916 llvm::ReturnInst::Create(gIR->scopebb()); 920 llvm::ReturnInst::Create(gIR->scopebb());
917 } 921 }
918 else { 922 else {
919 if (!fd->isMain()) 923 if (!fd->isMain())
920 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb()); 924 {
925 AsmBlockStatement* asmb = fd->fbody->endsWithAsm();
926 if (asmb) {
927 assert(asmb->abiret);
928 llvm::ReturnInst::Create(asmb->abiret, gIR->scopebb());
929 }
930 else {
931 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb());
932 }
933 }
921 else 934 else
922 llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), gIR->scopebb()); 935 llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), gIR->scopebb());
923 } 936 }
924 } 937 }
938
939 // std::cout << *func << std::endl;
925 940
926 // erase alloca point 941 // erase alloca point
927 allocaPoint->eraseFromParent(); 942 allocaPoint->eraseFromParent();
928 allocaPoint = 0; 943 allocaPoint = 0;
929 gIR->func()->allocapoint = 0; 944 gIR->func()->allocapoint = 0;
932 947
933 // get rid of the endentry block, it's never used 948 // get rid of the endentry block, it's never used
934 assert(!func->getBasicBlockList().empty()); 949 assert(!func->getBasicBlockList().empty());
935 func->getBasicBlockList().pop_back(); 950 func->getBasicBlockList().pop_back();
936 951
937 // if the last block is empty now, it must be unreachable or it's a bug somewhere else
938 // would be nice to figure out how to assert that this is correct
939 llvm::BasicBlock* lastbb = &func->getBasicBlockList().back();
940 if (lastbb->empty())
941 {
942 new llvm::UnreachableInst(lastbb);
943 }
944
945 // if the last block is not terminated we return a null value or void
946 // for some unknown reason this is needed when a void main() has a inline asm block ...
947 // this should be harmless for well formed code!
948 lastbb = &func->getBasicBlockList().back();
949 if (!lastbb->getTerminator())
950 {
951 Logger::println("adding missing return statement");
952 if (func->getReturnType() == LLType::VoidTy)
953 llvm::ReturnInst::Create(lastbb);
954 else
955 llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), lastbb);
956 }
957
958 gIR->functions.pop_back(); 952 gIR->functions.pop_back();
953
954 // std::cout << *func << std::endl;
959 } 955 }
960 956
961 ////////////////////////////////////////////////////////////////////////////////////////// 957 //////////////////////////////////////////////////////////////////////////////////////////
962 958
963 const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl) 959 const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl)