mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-12 05:47:11 +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 {
|
||||
if (DtoIsPassedByRef(v->getType())) {
|
||||
if (DtoIsInMemoryOnly(v->getType())) {
|
||||
LLValue *originalPointer = v->getRVal();
|
||||
LLType *type = originalPointer->getType()->getPointerElementType();
|
||||
LLValue *copyForCallee =
|
||||
|
|
|
@ -38,7 +38,7 @@ void ABIRewrite::getL(Type *dty, LLValue *v, LLValue *lval) {
|
|||
|
||||
LLValue *ABIRewrite::getAddressOf(DValue *v) {
|
||||
Type *dty = v->getType();
|
||||
if (DtoIsPassedByRef(dty)) {
|
||||
if (DtoIsInMemoryOnly(dty)) {
|
||||
// v is lowered to a LL pointer to the struct/static array
|
||||
return v->getRVal();
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ LLValue *DVarValue::getRVal() {
|
|||
storage = DtoLoad(storage);
|
||||
}
|
||||
|
||||
if (DtoIsPassedByRef(type->toBasetype())) {
|
||||
if (DtoIsInMemoryOnly(type->toBasetype())) {
|
||||
return storage;
|
||||
}
|
||||
|
||||
|
|
|
@ -951,7 +951,7 @@ DValue *DtoArgument(Parameter *fnarg, Expression *argexp) {
|
|||
}
|
||||
|
||||
// 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");
|
||||
auto vv = new DVarValue(argexp->type, alloc);
|
||||
DtoAssign(argexp->loc, vv, arg);
|
||||
|
|
|
@ -1346,7 +1346,7 @@ LLValue *makeLValue(Loc &loc, DValue *value) {
|
|||
LLValue *valuePointer;
|
||||
if (value->isIm()) {
|
||||
valuePointer = value->getRVal();
|
||||
needsMemory = !DtoIsPassedByRef(valueType);
|
||||
needsMemory = !DtoIsInMemoryOnly(valueType);
|
||||
} else if (value->isVar()) {
|
||||
valuePointer = value->getLVal();
|
||||
needsMemory = false;
|
||||
|
@ -1533,7 +1533,7 @@ DValue *DtoSymbolAddress(Loc &loc, Type *type, Declaration *decl) {
|
|||
assert(type->ty == Tdelegate);
|
||||
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))) {
|
||||
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:
|
||||
// If the function wants a struct, and the argument value is a
|
||||
// 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 && !irArg->byref && !irArg->isByVal()))) {
|
||||
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 *vaArgArg = gABI->prepareVaArg(pAp);
|
||||
LLType *llType = DtoType(e->type);
|
||||
if (DtoIsPassedByRef(e->type)) {
|
||||
if (DtoIsInMemoryOnly(e->type)) {
|
||||
llType = getPtrToType(llType);
|
||||
}
|
||||
result = new DImValue(e->type, p->ir->CreateVAArg(vaArgArg, llType));
|
||||
|
|
|
@ -2822,7 +2822,7 @@ public:
|
|||
Expression *el = (*e->exps)[i];
|
||||
DValue *ep = toElem(el);
|
||||
LLValue *gep = DtoGEPi(val, 0, i);
|
||||
if (DtoIsPassedByRef(el->type)) {
|
||||
if (DtoIsInMemoryOnly(el->type)) {
|
||||
DtoStore(DtoLoad(ep->getRVal()), gep);
|
||||
} else if (el->type->ty != Tvoid) {
|
||||
DtoStoreZextI8(ep->getRVal(), gep);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "ir/irtypefunction.h"
|
||||
#include "ir/irtypestruct.h"
|
||||
|
||||
bool DtoIsPassedByRef(Type *type) {
|
||||
bool DtoIsInMemoryOnly(Type *type) {
|
||||
Type *typ = type->toBasetype();
|
||||
TY t = typ->ty;
|
||||
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 *i1ToI8(LLType *t);
|
||||
|
||||
// returns true if the type must be passed by pointer
|
||||
bool DtoIsPassedByRef(Type *type);
|
||||
// Returns true if the type is a value type which LDC keeps exclusively in
|
||||
// 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
|
||||
// is passed in a register
|
||||
// Returns true if the callee uses sret (struct return).
|
||||
// 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);
|
||||
|
||||
// should argument be zero or sign extended
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue