mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-13 14:36:18 +03:00
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.
This commit is contained in:
parent
79bc6230df
commit
27d3ab4546
10 changed files with 749 additions and 118 deletions
|
@ -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 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
|
|||
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 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
|
|||
// 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 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
|
|||
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 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
|||
|
||||
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!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue