ldc/ir/irfuncty.cpp
David Nadlinger ee50259dfd C ABI: Do not pass empty structs as parameters at all
This is most visible on x86 (32-bit), where the stack
alignment is off otherwise.

This change is quite messy because many places assumed
that there was always exactly one LLVM parameter per
TypeFunction::parameters entry.
2015-08-22 23:41:56 +02:00

93 lines
2.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//===-- irfuncty.cpp ------------------------------------------------------===//
//
// LDC the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
#include "ir/irfuncty.h"
#include "mtype.h"
#include "gen/abi.h"
#include "gen/dvalue.h"
#include "gen/llvm.h"
#include "gen/logger.h"
#include "gen/tollvm.h"
IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, const AttrBuilder& a)
: type(t), parametersIdx(0),
ltype(t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t)),
attrs(a), byref(bref), rewrite(0)
{
}
bool IrFuncTyArg::isInReg() const { return attrs.contains(LDC_ATTRIBUTE(InReg)); }
bool IrFuncTyArg::isSRet() const { return attrs.contains(LDC_ATTRIBUTE(StructRet)); }
bool IrFuncTyArg::isByVal() const { return attrs.contains(LDC_ATTRIBUTE(ByVal)); }
llvm::Value* IrFuncTy::putRet(Type* dty, DValue* val)
{
assert(!arg_sret);
if (ret->rewrite) {
Logger::println("Rewrite: putRet");
LOG_SCOPE
return ret->rewrite->put(dty, val);
}
return val->getRVal();
}
llvm::Value* IrFuncTy::getRet(Type* dty, DValue* val)
{
assert(!arg_sret);
if (ret->rewrite) {
Logger::println("Rewrite: getRet");
LOG_SCOPE
return ret->rewrite->get(dty, val);
}
return val->getRVal();
}
void IrFuncTy::getRet(Type* dty, DValue* val, llvm::Value* lval)
{
assert(!arg_sret);
if (ret->rewrite) {
Logger::println("Rewrite: getRet (getL)");
LOG_SCOPE
ret->rewrite->getL(dty, val, lval);
return;
}
DtoStoreZextI8(val->getRVal(), lval);
}
llvm::Value* IrFuncTy::putParam(Type* dty, size_t idx, DValue* val)
{
assert(idx < args.size() && "invalid putParam");
return putParam(dty, *args[idx], val);
}
llvm::Value* IrFuncTy::putParam(Type* dty, const IrFuncTyArg& arg, DValue* val)
{
if (arg.rewrite) {
Logger::println("Rewrite: putParam");
LOG_SCOPE
return arg.rewrite->put(dty, val);
}
return val->getRVal();
}
void IrFuncTy::getParam(Type* dty, size_t idx, DValue* val, llvm::Value* lval)
{
assert(idx < args.size() && "invalid getParam");
if (args[idx]->rewrite)
{
Logger::println("Rewrite: getParam (getL)");
LOG_SCOPE
args[idx]->rewrite->getL(dty, val, lval);
return;
}
DtoStoreZextI8(val->getRVal(), lval);
}