Skip to content

Commit 6077776

Browse files
committed
DFuncValue: Add explicit funcPtr field
As preparation for using a LL pair as rvalue if the expression type is Tdelegate.
1 parent 4220a1b commit 6077776

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

gen/dvalue.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ LLValue *DSliceValue::getPtr() {
105105

106106
////////////////////////////////////////////////////////////////////////////////
107107

108-
DFuncValue::DFuncValue(Type *t, FuncDeclaration *fd, LLValue *v, LLValue *vt,
109-
LLValue *vtable)
110-
: DRValue(t, v), func(fd), vthis(vt), vtable(vtable) {}
108+
DFuncValue::DFuncValue(Type *t, FuncDeclaration *fd, LLValue *funcPtr,
109+
LLValue *vt, LLValue *vtable)
110+
: DRValue(t, funcPtr), funcPtr(funcPtr), func(fd), vthis(vt),
111+
vtable(vtable) {}
111112

112-
DFuncValue::DFuncValue(FuncDeclaration *fd, LLValue *v, LLValue *vt,
113+
DFuncValue::DFuncValue(FuncDeclaration *fd, LLValue *funcPtr, LLValue *vt,
113114
LLValue *vtable)
114-
: DFuncValue(fd->type, fd, v, vt, vtable) {}
115+
: DFuncValue(fd->type, fd, funcPtr, vt, vtable) {}
115116

116117
bool DFuncValue::definedInFuncEntryBB() {
117118
return isDefinedInFuncEntryBB(val) &&

gen/dvalue.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,14 @@ class DSliceValue : public DRValue {
142142
class DFuncValue : public DRValue {
143143
public:
144144
FuncDeclaration *func;
145-
llvm::Value *vthis;
145+
llvm::Value *const funcPtr;
146+
llvm::Value *const vthis;
146147
llvm::Value *vtable;
147148

148-
DFuncValue(Type *t, FuncDeclaration *fd, llvm::Value *v,
149+
DFuncValue(Type *t, FuncDeclaration *fd, llvm::Value *funcPtr,
150+
llvm::Value *vt = nullptr, llvm::Value *vtable = nullptr);
151+
DFuncValue(FuncDeclaration *fd, llvm::Value *funcPtr,
149152
llvm::Value *vt = nullptr, llvm::Value *vtable = nullptr);
150-
DFuncValue(FuncDeclaration *fd, llvm::Value *v, llvm::Value *vt = nullptr,
151-
llvm::Value *vtable = nullptr);
152153

153154
bool definedInFuncEntryBB() override;
154155

gen/llvmhelpers.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ DValue *DtoPaintType(const Loc &loc, DValue *val, Type *to) {
767767
}
768768
} else if (auto func = val->isFunc()) {
769769
if (tb->ty == TY::Tdelegate) {
770-
return new DFuncValue(to, func->func, DtoRVal(func), func->vthis);
770+
return new DFuncValue(to, func->func, func->funcPtr, func->vthis);
771771
}
772772
} else { // generic rvalue
773773
LLValue *rval = DtoRVal(val);

gen/toir.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -984,11 +984,10 @@ class ToElemVisitor : public Visitor {
984984
// function pointers are special
985985
if (e->type->toBasetype()->ty == TY::Tfunction) {
986986
DValue *dv = toElem(e->e1);
987-
LLValue *llVal = DtoRVal(dv);
988987
if (DFuncValue *dfv = dv->isFunc()) {
989-
result = new DFuncValue(e->type, dfv->func, llVal);
988+
result = new DFuncValue(e->type, dfv->func, dfv->funcPtr);
990989
} else {
991-
result = new DImValue(e->type, llVal);
990+
result = new DImValue(e->type, DtoRVal(dv));
992991
}
993992
return;
994993
}
@@ -1072,18 +1071,18 @@ class ToElemVisitor : public Visitor {
10721071
fdecl->visibility.kind != Visibility::package_;
10731072

10741073
// Get the actual function value to call.
1075-
LLValue *funcval = nullptr;
1074+
LLValue *funcPtr = nullptr;
10761075
LLValue *vtable = nullptr;
10771076
if (nonFinal) {
10781077
DtoResolveFunction(fdecl);
1079-
std::tie(funcval, vtable) = DtoVirtualFunctionPointer(l, fdecl);
1078+
std::tie(funcPtr, vtable) = DtoVirtualFunctionPointer(l, fdecl);
10801079
} else {
1081-
funcval = DtoCallee(fdecl);
1080+
funcPtr = DtoCallee(fdecl);
10821081
}
1083-
assert(funcval);
1082+
assert(funcPtr);
10841083

10851084
LLValue *vthis = (DtoIsInMemoryOnly(l->type) ? DtoLVal(l) : DtoRVal(l));
1086-
result = new DFuncValue(fdecl, funcval, vthis, vtable);
1085+
result = new DFuncValue(fdecl, funcPtr, vthis, vtable);
10871086
} else {
10881087
llvm_unreachable("Unknown target for VarDeclaration.");
10891088
}

0 commit comments

Comments
 (0)