Mercurial > projects > ldc
diff gen/asmstmt.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 | 545f54041d91 |
children | e048e36bc155 |
line wrap: on
line diff
--- a/gen/asmstmt.cpp Sun Feb 08 05:14:24 2009 +0100 +++ b/gen/asmstmt.cpp Sun Feb 08 05:26:54 2009 +0100 @@ -26,6 +26,7 @@ #include "gen/logger.h" #include "gen/todebug.h" #include "gen/llvmhelpers.h" +#include "gen/functions.h" typedef enum { Arg_Integer, @@ -400,6 +401,8 @@ { enclosinghandler = NULL; tf = NULL; + + abiret = NULL; } // rewrite argument indices to the block scope indices @@ -452,18 +455,21 @@ } } +LLValue* DtoAggrPairSwap(LLValue* aggr); + void AsmBlockStatement::toIR(IRState* p) { Logger::println("AsmBlockStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; Logger::println("BEGIN ASM"); - // disable inlining - gIR->func()->setNeverInline(); + // disable inlining by default + if (!p->func()->decl->allowInlining) + p->func()->setNeverInline(); // create asm block structure assert(!p->asmBlock); - IRAsmBlock* asmblock = new IRAsmBlock; + IRAsmBlock* asmblock = new IRAsmBlock(this); assert(asmblock); p->asmBlock = asmblock; @@ -562,6 +568,20 @@ } + // build a fall-off-end-properly asm statement + + FuncDeclaration* thisfunc = p->func()->decl; + bool useabiret = false; + p->asmBlock->asmBlock->abiret = NULL; + if (thisfunc->fbody->endsWithAsm() == this && thisfunc->type->nextOf()->ty != Tvoid) + { + // there can't be goto forwarders in this case + assert(gotoToVal.empty()); + emitABIReturnAsmStmt(asmblock, loc, thisfunc); + useabiret = true; + } + + // build asm block std::vector<LLValue*> outargs; std::vector<LLValue*> inargs; @@ -571,8 +591,9 @@ std::string in_c; std::string clobbers; std::string code; - size_t asmIdx = 0; + size_t asmIdx = asmblock->retn; + Logger::println("do outputs"); size_t n = asmblock->s.size(); for (size_t i=0; i<n; ++i) { @@ -590,6 +611,8 @@ } remap_outargs(a->code, onn+a->in.size(), asmIdx); } + + Logger::println("do inputs"); for (size_t i=0; i<n; ++i) { IRAsmStmt* a = asmblock->s[i]; @@ -628,10 +651,18 @@ Logger::println("code = \"%s\"", code.c_str()); Logger::println("constraints = \"%s\"", out_c.c_str()); + // build return types + const LLType* retty; + if (asmblock->retn) + retty = asmblock->retty; + else + retty = llvm::Type::VoidTy; + + // build argument types std::vector<const LLType*> types; types.insert(types.end(), outtypes.begin(), outtypes.end()); types.insert(types.end(), intypes.begin(), intypes.end()); - llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::VoidTy, types, false); + llvm::FunctionType* fty = llvm::FunctionType::get(retty, types, false); if (Logger::enabled()) Logger::cout() << "function type = " << *fty << '\n'; llvm::InlineAsm* ia = llvm::InlineAsm::get(fty, code, out_c, true); @@ -640,6 +671,10 @@ args.insert(args.end(), outargs.begin(), outargs.end()); args.insert(args.end(), inargs.begin(), inargs.end()); llvm::CallInst* call = p->ir->CreateCall(ia, args.begin(), args.end(), ""); + if (useabiret) + { + p->asmBlock->asmBlock->abiret = call; + } p->asmBlock = NULL; Logger::println("END ASM");