mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-08 11:56:12 +03:00
Rename DtoIsPassedByRef() to DtoIsInMemoryOnly()
Motivation: issue #937
This commit is contained in:
parent
f976bcb467
commit
740a21eb8f
9 changed files with 16 additions and 14 deletions
|
@ -203,7 +203,7 @@ struct ExplicitByvalRewrite : ABIRewrite {
|
||||||
}
|
}
|
||||||
|
|
||||||
LLValue *put(DValue *v) override {
|
LLValue *put(DValue *v) override {
|
||||||
if (DtoIsPassedByRef(v->getType())) {
|
if (DtoIsInMemoryOnly(v->getType())) {
|
||||||
LLValue *originalPointer = v->getRVal();
|
LLValue *originalPointer = v->getRVal();
|
||||||
LLType *type = originalPointer->getType()->getPointerElementType();
|
LLType *type = originalPointer->getType()->getPointerElementType();
|
||||||
LLValue *copyForCallee =
|
LLValue *copyForCallee =
|
||||||
|
|
|
@ -38,7 +38,7 @@ void ABIRewrite::getL(Type *dty, LLValue *v, LLValue *lval) {
|
||||||
|
|
||||||
LLValue *ABIRewrite::getAddressOf(DValue *v) {
|
LLValue *ABIRewrite::getAddressOf(DValue *v) {
|
||||||
Type *dty = v->getType();
|
Type *dty = v->getType();
|
||||||
if (DtoIsPassedByRef(dty)) {
|
if (DtoIsInMemoryOnly(dty)) {
|
||||||
// v is lowered to a LL pointer to the struct/static array
|
// v is lowered to a LL pointer to the struct/static array
|
||||||
return v->getRVal();
|
return v->getRVal();
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ LLValue *DVarValue::getRVal() {
|
||||||
storage = DtoLoad(storage);
|
storage = DtoLoad(storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DtoIsPassedByRef(type->toBasetype())) {
|
if (DtoIsInMemoryOnly(type->toBasetype())) {
|
||||||
return storage;
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -951,7 +951,7 @@ DValue *DtoArgument(Parameter *fnarg, Expression *argexp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// byval arg, but expr has no storage yet
|
// byval arg, but expr has no storage yet
|
||||||
if (DtoIsPassedByRef(argexp->type) && (arg->isSlice() || arg->isNull())) {
|
if (DtoIsInMemoryOnly(argexp->type) && (arg->isSlice() || arg->isNull())) {
|
||||||
LLValue *alloc = DtoAlloca(argexp->type, ".tmp_arg");
|
LLValue *alloc = DtoAlloca(argexp->type, ".tmp_arg");
|
||||||
auto vv = new DVarValue(argexp->type, alloc);
|
auto vv = new DVarValue(argexp->type, alloc);
|
||||||
DtoAssign(argexp->loc, vv, arg);
|
DtoAssign(argexp->loc, vv, arg);
|
||||||
|
|
|
@ -1346,7 +1346,7 @@ LLValue *makeLValue(Loc &loc, DValue *value) {
|
||||||
LLValue *valuePointer;
|
LLValue *valuePointer;
|
||||||
if (value->isIm()) {
|
if (value->isIm()) {
|
||||||
valuePointer = value->getRVal();
|
valuePointer = value->getRVal();
|
||||||
needsMemory = !DtoIsPassedByRef(valueType);
|
needsMemory = !DtoIsInMemoryOnly(valueType);
|
||||||
} else if (value->isVar()) {
|
} else if (value->isVar()) {
|
||||||
valuePointer = value->getLVal();
|
valuePointer = value->getLVal();
|
||||||
needsMemory = false;
|
needsMemory = false;
|
||||||
|
@ -1533,7 +1533,7 @@ DValue *DtoSymbolAddress(Loc &loc, Type *type, Declaration *decl) {
|
||||||
assert(type->ty == Tdelegate);
|
assert(type->ty == Tdelegate);
|
||||||
return new DVarValue(type, getIrValue(vd));
|
return new DVarValue(type, getIrValue(vd));
|
||||||
}
|
}
|
||||||
if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) ||
|
if (vd->isRef() || vd->isOut() || DtoIsInMemoryOnly(vd->type) ||
|
||||||
llvm::isa<llvm::AllocaInst>(getIrValue(vd))) {
|
llvm::isa<llvm::AllocaInst>(getIrValue(vd))) {
|
||||||
return new DVarValue(type, vd, getIrValue(vd));
|
return new DVarValue(type, vd, getIrValue(vd));
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ static void addExplicitArguments(std::vector<LLValue *> &args, AttrSet &attrs,
|
||||||
// Hack around LDC assuming structs and static arrays are in memory:
|
// Hack around LDC assuming structs and static arrays are in memory:
|
||||||
// If the function wants a struct, and the argument value is a
|
// If the function wants a struct, and the argument value is a
|
||||||
// pointer to a struct, load from it before passing it in.
|
// pointer to a struct, load from it before passing it in.
|
||||||
if (isaPointer(llVal) && DtoIsPassedByRef(argType) &&
|
if (isaPointer(llVal) && DtoIsInMemoryOnly(argType) &&
|
||||||
((!isVararg && !isaPointer(callableArgType)) ||
|
((!isVararg && !isaPointer(callableArgType)) ||
|
||||||
(isVararg && !irArg->byref && !irArg->isByVal()))) {
|
(isVararg && !irArg->byref && !irArg->isByVal()))) {
|
||||||
Logger::println("Loading struct type for function argument");
|
Logger::println("Loading struct type for function argument");
|
||||||
|
@ -297,7 +297,7 @@ bool DtoLowerMagicIntrinsic(IRState *p, FuncDeclaration *fndecl, CallExp *e,
|
||||||
LLValue *pAp = toElem((*e->arguments)[0])->getLVal(); // va_list*
|
LLValue *pAp = toElem((*e->arguments)[0])->getLVal(); // va_list*
|
||||||
LLValue *vaArgArg = gABI->prepareVaArg(pAp);
|
LLValue *vaArgArg = gABI->prepareVaArg(pAp);
|
||||||
LLType *llType = DtoType(e->type);
|
LLType *llType = DtoType(e->type);
|
||||||
if (DtoIsPassedByRef(e->type)) {
|
if (DtoIsInMemoryOnly(e->type)) {
|
||||||
llType = getPtrToType(llType);
|
llType = getPtrToType(llType);
|
||||||
}
|
}
|
||||||
result = new DImValue(e->type, p->ir->CreateVAArg(vaArgArg, llType));
|
result = new DImValue(e->type, p->ir->CreateVAArg(vaArgArg, llType));
|
||||||
|
|
|
@ -2822,7 +2822,7 @@ public:
|
||||||
Expression *el = (*e->exps)[i];
|
Expression *el = (*e->exps)[i];
|
||||||
DValue *ep = toElem(el);
|
DValue *ep = toElem(el);
|
||||||
LLValue *gep = DtoGEPi(val, 0, i);
|
LLValue *gep = DtoGEPi(val, 0, i);
|
||||||
if (DtoIsPassedByRef(el->type)) {
|
if (DtoIsInMemoryOnly(el->type)) {
|
||||||
DtoStore(DtoLoad(ep->getRVal()), gep);
|
DtoStore(DtoLoad(ep->getRVal()), gep);
|
||||||
} else if (el->type->ty != Tvoid) {
|
} else if (el->type->ty != Tvoid) {
|
||||||
DtoStoreZextI8(ep->getRVal(), gep);
|
DtoStoreZextI8(ep->getRVal(), gep);
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include "ir/irtypefunction.h"
|
#include "ir/irtypefunction.h"
|
||||||
#include "ir/irtypestruct.h"
|
#include "ir/irtypestruct.h"
|
||||||
|
|
||||||
bool DtoIsPassedByRef(Type *type) {
|
bool DtoIsInMemoryOnly(Type *type) {
|
||||||
Type *typ = type->toBasetype();
|
Type *typ = type->toBasetype();
|
||||||
TY t = typ->ty;
|
TY t = typ->ty;
|
||||||
return (t == Tstruct || t == Tsarray);
|
return (t == Tstruct || t == Tsarray);
|
||||||
|
|
10
gen/tollvm.h
10
gen/tollvm.h
|
@ -41,11 +41,13 @@ LLPointerType *DtoPtrToType(Type *t);
|
||||||
LLType *voidToI8(LLType *t);
|
LLType *voidToI8(LLType *t);
|
||||||
LLType *i1ToI8(LLType *t);
|
LLType *i1ToI8(LLType *t);
|
||||||
|
|
||||||
// returns true if the type must be passed by pointer
|
// Returns true if the type is a value type which LDC keeps exclusively in
|
||||||
bool DtoIsPassedByRef(Type *type);
|
// memory, referencing all values via LL pointers (structs and static arrays).
|
||||||
|
bool DtoIsInMemoryOnly(Type *type);
|
||||||
|
|
||||||
// returns true if the return value of the call expression
|
// Returns true if the callee uses sret (struct return).
|
||||||
// is passed in a register
|
// In that case, the caller needs to allocate the return value and pass its
|
||||||
|
// address as additional parameter to the callee, which will set it up.
|
||||||
bool DtoIsReturnInArg(CallExp *ce);
|
bool DtoIsReturnInArg(CallExp *ce);
|
||||||
|
|
||||||
// should argument be zero or sign extended
|
// should argument be zero or sign extended
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue