Skip to content

Commit

Permalink
DFuncValue: Add explicit funcPtr field
Browse files Browse the repository at this point in the history
As preparation for using a LL pair as rvalue if the expression type
is Tdelegate.
  • Loading branch information
kinke committed Sep 25, 2024
1 parent 4220a1b commit 521f29c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
11 changes: 6 additions & 5 deletions gen/dvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ LLValue *DSliceValue::getPtr() {

////////////////////////////////////////////////////////////////////////////////

DFuncValue::DFuncValue(Type *t, FuncDeclaration *fd, LLValue *v, LLValue *vt,
LLValue *vtable)
: DRValue(t, v), func(fd), vthis(vt), vtable(vtable) {}
DFuncValue::DFuncValue(Type *t, FuncDeclaration *fd, LLValue *funcPtr,
LLValue *vt, LLValue *vtable)
: DRValue(t, funcPtr), func(fd), funcPtr(funcPtr), vthis(vt),
vtable(vtable) {}

DFuncValue::DFuncValue(FuncDeclaration *fd, LLValue *v, LLValue *vt,
DFuncValue::DFuncValue(FuncDeclaration *fd, LLValue *funcPtr, LLValue *vt,
LLValue *vtable)
: DFuncValue(fd->type, fd, v, vt, vtable) {}
: DFuncValue(fd->type, fd, funcPtr, vt, vtable) {}

bool DFuncValue::definedInFuncEntryBB() {
return isDefinedInFuncEntryBB(val) &&
Expand Down
9 changes: 5 additions & 4 deletions gen/dvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ class DSliceValue : public DRValue {
class DFuncValue : public DRValue {
public:
FuncDeclaration *func;
llvm::Value *vthis;
llvm::Value *const funcPtr;
llvm::Value *const vthis;
llvm::Value *vtable;

DFuncValue(Type *t, FuncDeclaration *fd, llvm::Value *v,
DFuncValue(Type *t, FuncDeclaration *fd, llvm::Value *funcPtr,
llvm::Value *vt = nullptr, llvm::Value *vtable = nullptr);
DFuncValue(FuncDeclaration *fd, llvm::Value *funcPtr,
llvm::Value *vt = nullptr, llvm::Value *vtable = nullptr);
DFuncValue(FuncDeclaration *fd, llvm::Value *v, llvm::Value *vt = nullptr,
llvm::Value *vtable = nullptr);

bool definedInFuncEntryBB() override;

Expand Down
2 changes: 1 addition & 1 deletion gen/llvmhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ DValue *DtoPaintType(const Loc &loc, DValue *val, Type *to) {
}
} else if (auto func = val->isFunc()) {
if (tb->ty == TY::Tdelegate) {
return new DFuncValue(to, func->func, DtoRVal(func), func->vthis);
return new DFuncValue(to, func->func, func->funcPtr, func->vthis);
}
} else { // generic rvalue
LLValue *rval = DtoRVal(val);
Expand Down
15 changes: 7 additions & 8 deletions gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,11 +984,10 @@ class ToElemVisitor : public Visitor {
// function pointers are special
if (e->type->toBasetype()->ty == TY::Tfunction) {
DValue *dv = toElem(e->e1);
LLValue *llVal = DtoRVal(dv);
if (DFuncValue *dfv = dv->isFunc()) {
result = new DFuncValue(e->type, dfv->func, llVal);
result = new DFuncValue(e->type, dfv->func, dfv->funcPtr);
} else {
result = new DImValue(e->type, llVal);
result = new DImValue(e->type, DtoRVal(dv));
}
return;
}
Expand Down Expand Up @@ -1072,18 +1071,18 @@ class ToElemVisitor : public Visitor {
fdecl->visibility.kind != Visibility::package_;

// Get the actual function value to call.
LLValue *funcval = nullptr;
LLValue *funcPtr = nullptr;
LLValue *vtable = nullptr;
if (nonFinal) {
DtoResolveFunction(fdecl);
std::tie(funcval, vtable) = DtoVirtualFunctionPointer(l, fdecl);
std::tie(funcPtr, vtable) = DtoVirtualFunctionPointer(l, fdecl);
} else {
funcval = DtoCallee(fdecl);
funcPtr = DtoCallee(fdecl);
}
assert(funcval);
assert(funcPtr);

LLValue *vthis = (DtoIsInMemoryOnly(l->type) ? DtoLVal(l) : DtoRVal(l));
result = new DFuncValue(fdecl, funcval, vthis, vtable);
result = new DFuncValue(fdecl, funcPtr, vthis, vtable);
} else {
llvm_unreachable("Unknown target for VarDeclaration.");
}
Expand Down

0 comments on commit 521f29c

Please sign in to comment.