Mercurial > projects > ldc
diff gen/functions.cpp @ 1047:6bb04dbee21f
Some calling convention work for x86-64:
- Implement x86-64 extern(C), hopefully correctly.
- Tried to be a bit smarter about extern(D) while I was there.
Interestingly, this code seems to be generating more efficient code than
gcc and llvm-gcc in some edge cases, like returning a `{ [7 x i8] }` loaded from
a stack slot from an extern(C) function. (gcc generates 7 1-byte loads, while
this code generates a 4-byte, a 2-byte and a 1-byte load)
I also added some changes to make sure structs being returned from functions or
passed in as parameters are stored in memory where the rest of the backend seems
to expect them to be. These should be removed when support for first-class
aggregates improves.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Fri, 06 Mar 2009 16:00:47 +0100 |
parents | a91d6fc600cd |
children | afe271b0e271 |
line wrap: on
line diff
--- a/gen/functions.cpp Thu Mar 05 21:32:18 2009 +0100 +++ b/gen/functions.cpp Fri Mar 06 16:00:47 2009 +0100 @@ -24,6 +24,9 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain) { + if (Logger::enabled()) + Logger::println("DtoFunctionType(%s)", type->toChars()); + LOG_SCOPE // sanity check assert(type->ty == Tfunction); TypeFunction* f = (TypeFunction*)type; @@ -34,6 +37,9 @@ return llvm::cast<llvm::FunctionType>(type->ir.type->get()); } + // Tell the ABI we're resolving a new function type + gABI->newFunctionType(f); + // create new ir funcTy assert(f->fty == NULL); f->fty = new IrFuncTy(); @@ -158,6 +164,9 @@ // let the abi rewrite the types as necesary gABI->rewriteFunctionType(f); + // Tell the ABI we're done with this function type + gABI->doneWithFunctionType(); + // build the function type std::vector<const LLType*> argtypes; argtypes.reserve(lidx); @@ -184,6 +193,8 @@ llvm::FunctionType* functype = llvm::FunctionType::get(f->fty->ret->ltype, argtypes, f->fty->c_vararg); f->ir.type = new llvm::PATypeHolder(functype); + Logger::cout() << "Final function type: " << *functype << "\n"; + return functype; } @@ -571,7 +582,8 @@ assert(fd->ir.declared); - Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars()); + if (Logger::enabled()) + Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars()); LOG_SCOPE; // if this function is naked, we take over right away! no standard processing!