-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CIR][CIRGen] Add CIRGen support for pointer-to-member-functions #722
base: main
Are you sure you want to change the base?
Conversation
Sorry for the delay here, taking a look next week! |
This patch adds the initial CIRGen support for pointer-to-member-functions. It contains the following new types, attributes, and operations: - `!cir.method`, which represents the pointer-to-member-function type. - `#cir.method`, which represents a literal pointer-to-member-function value that points to non-virtual member functions. - `#cir.virtual_method`, which represents a literal pointer-to-member-function value that points to virtual member functions. - `cir.get_method_callee`, which resolves a pointer-to-member-function to a function pointer as the callee. See the new test at `clang/test/CIR/CIRGen/pointer-to-member-func.cpp` for how these new CIR stuff works to support pointer-to-member-functions.
Rebased onto the latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool, a nice missing feature!
Some comments inline. Should I assume lowering prepare + LLVM comes next?
// %arg = ... | ||
// %method = ... | ||
%callee, %this_adj = cir.get_method_callee %method, %object | ||
%this = cir.ptr_stride %object, %this_adj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to cir.get_method
. Is there any purpose in keeping the %this_adj
around? I wonder if we should hide the ptr_stride and return the adjusted this point instead.
|
||
// Assume: | ||
// - objectTy is !cir.ptr<!T> | ||
// - methodFuncTy is !cir.func<!Ret (!Args)> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3 first lines of this should be above mlir::cast
s.
// | ||
// We verify at here that: | ||
// - calleeTy is !cir.func<!Ret (!cir.ptr<!T>, !Args)> | ||
if (methodFuncTy.getReturnType() != calleeTy.getReturnType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this possible to constrain this in tablegen?
if (calleeArgsTy.slice(1) != methodFuncArgsTy) { | ||
emitError() << "callee parameters and method parameters do not match"; | ||
return mlir::failure(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constraints should be mentioned in the documentation.
methodFuncInputTypes.end()); | ||
auto calleeFuncTy = | ||
methodFuncTy.clone(calleeFuncInputTypes, methodFuncTy.getReturnType()); | ||
// TODO(cir): consider the address space of the callee. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A missing feature here.
}]; | ||
|
||
let parameters = (ins AttributeSelfTypeParameter< | ||
"", "mlir::cir::MethodType">:$type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we encode if it's virtual in the MethodType
instead? One MethodAttr
seems enough. It should then have two optionals and verifier ensure some of the semantics.
llvm::TypeSize | ||
MethodType::getTypeSizeInBits(const mlir::DataLayout &dataLayout, | ||
mlir::DataLayoutEntryListRef params) const { | ||
// TODO: consider size differences under different ABIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have a better ABI infra, you should implement what's necessary here, at least for one target.
This PR adds the initial CIRGen support for pointer-to-member-functions. It contains the following new types, attributes, and operations:
!cir.method
, which represents the pointer-to-member-function type.#cir.method
, which represents a literal pointer-to-member-function value that points to non-virtual member functions.#cir.virtual_method
, which represents a literal pointer-to-member-function value that points to virtual member functions.cir.get_method_callee
, which resolves a pointer-to-member-function to a function pointer as the callee.See the new test at
clang/test/CIR/CIRGen/pointer-to-member-func.cpp
for how these new CIR stuff works to support pointer-to-member-functions.