-
Notifications
You must be signed in to change notification settings - Fork 171
[CIR][Dialect][Lowering] Add calling convention attribute to FuncOp #760
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
Conversation
The CodeGen stuff will come later. The newly defined |
def CC_C : I32EnumAttrCase<"C", 1, "cc_c">; | ||
def CC_SpirKernel : I32EnumAttrCase<"SpirKernel", 75, "cc_spir_kernel">; | ||
def CC_SpirFunction : I32EnumAttrCase<"SpirFunction", 76, "cc_spir_function">; |
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.
Not sure about the names in asm. The func op has many keywords right after the mnemonic. We do not have hint to tell "this is a calling convention keyword". Meanwhile it's hard to name the short "c" case. Therefore the prefix cc_
was prepended accordingly.
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 do not have hint to tell "this is a calling convention keyword"
Why not add this hint and design the assembly like:
cir.func @foo() cc(c)
cir.func @foo() cc(spir_kernel)
cir.func @foo() cc(spir_function)
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.
Thanks for pointing it out! That's also a very nice option. Other FYI:
- We already have assembly format like
cir.func internal private @_ZL4funcv() extra(#fn_attr)
. Hereinternal
is linkage andprivate
is symbol visibility. (it's generated by a static function) - I'm assuming the postpositional attribute here is in order to align with our existing form
extra(#fn_attr)
. But we may also consider that the conventional position for call conv is always before the name, no matter in the source code, LLVM MLIR dialect or LLVM IR.
Two more schemes here:
cir.func callconv(c) @foo()
cir.func callconv(spir_kernel) @foo()
cir.func callconv(spir_function) @foo()
cir.func callconv_c @foo()
cir.func spir_kernel @foo()
cir.func spir_function @foo()
Edit: callconv_c
-> cdecl
is also a good name I think!
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.
Two more schemes here:
I'm down for the first one. We have attributes that specifies what "kind" the function is:
cir.func coroutine @foo()
The spir_kernel
and spir_function
looks too similar to these kind of attributes and it's better to be explicit about their actual usage.
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.
- +1 for having the CC before the symbol name.
- LLVM uses
ccc
for the C calling convention. They use the no-separator-'cc'-suffix for others as well, though not forspir_function
andspir_kernel
.
The spir_kernel and spir_function looks too similar to these kind of attributes and it's better to be explicit about their actual usage.
- I get where you're coming from, but I'd argue that the assembly format is not user-facing/only consumed by computers and compiler devs, so as long as it can be parsed unambiguously, wouldn't it be fine?
- I think wrapping the keyword in
cc(...)
,cconv(...)
,callconv(...)
, etc. is also fine, but then we probably should wrap linkage and visibility as well.
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.
I'm more driven towards @Lancern idea:
cir.func @foo() cc(c)
cir.func @foo() cc(spir_kernel)
cir.func @foo() cc(spir_function)
My thoughts:
- As someone always looking into CIR output, I rather not have to wait more into finding the symbol.
visibility(internal)
is quite a big name, so I think it justifies being different. Adding alinkage(...)
would also be fair, but I feel like linkage information is something you usually also want in the face. I'm also not that worried about being super consistent if there are good reasons to deviate.cc
is so tiny that begs to be used hehe.- I also think that the most common CC should not be printed (i.e. we should have a default) in order not to look at that when we don't need to.
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.
Thank you for all the suggestions. Updated accordingly.
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.
Thanks for adding this!
def CC_C : I32EnumAttrCase<"C", 1, "cc_c">; | ||
def CC_SpirKernel : I32EnumAttrCase<"SpirKernel", 75, "cc_spir_kernel">; | ||
def CC_SpirFunction : I32EnumAttrCase<"SpirFunction", 76, "cc_spir_function">; |
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.
I'm more driven towards @Lancern idea:
cir.func @foo() cc(c)
cir.func @foo() cc(spir_kernel)
cir.func @foo() cc(spir_function)
My thoughts:
- As someone always looking into CIR output, I rather not have to wait more into finding the symbol.
visibility(internal)
is quite a big name, so I think it justifies being different. Adding alinkage(...)
would also be fair, but I feel like linkage information is something you usually also want in the face. I'm also not that worried about being super consistent if there are good reasons to deviate.cc
is so tiny that begs to be used hehe.- I also think that the most common CC should not be printed (i.e. we should have a default) in order not to look at that when we don't need to.
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.
Neat!
|
||
/// Parse an enum from the keyword, return failure if the keyword is not found. | ||
template <typename EnumTy, typename RetTy = EnumTy> | ||
static ParseResult parseCIRKeyword(AsmParser &parser, RetTy &result) { |
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.
Neat, probably we can reuse that for other things in this file, can you create an issue so we can track it?
…lvm#760) This PR simply adds the calling convention attribute to FuncOp with LLVM Lowering support. The overall approach follows `GlobalLinkageKind`: Extend the ODS, parser, printer and lowering pass. When the call conv is C call conv, it's omitted in the output assembly. --------- Co-authored-by: Bruno Cardoso Lopes <[email protected]>
…lvm#760) This PR simply adds the calling convention attribute to FuncOp with LLVM Lowering support. The overall approach follows `GlobalLinkageKind`: Extend the ODS, parser, printer and lowering pass. When the call conv is C call conv, it's omitted in the output assembly. --------- Co-authored-by: Bruno Cardoso Lopes <[email protected]>
…lvm#760) This PR simply adds the calling convention attribute to FuncOp with LLVM Lowering support. The overall approach follows `GlobalLinkageKind`: Extend the ODS, parser, printer and lowering pass. When the call conv is C call conv, it's omitted in the output assembly. --------- Co-authored-by: Bruno Cardoso Lopes <[email protected]>
…lvm#760) This PR simply adds the calling convention attribute to FuncOp with LLVM Lowering support. The overall approach follows `GlobalLinkageKind`: Extend the ODS, parser, printer and lowering pass. When the call conv is C call conv, it's omitted in the output assembly. --------- Co-authored-by: Bruno Cardoso Lopes <[email protected]>
…760) This PR simply adds the calling convention attribute to FuncOp with LLVM Lowering support. The overall approach follows `GlobalLinkageKind`: Extend the ODS, parser, printer and lowering pass. When the call conv is C call conv, it's omitted in the output assembly. --------- Co-authored-by: Bruno Cardoso Lopes <[email protected]>
…760) This PR simply adds the calling convention attribute to FuncOp with LLVM Lowering support. The overall approach follows `GlobalLinkageKind`: Extend the ODS, parser, printer and lowering pass. When the call conv is C call conv, it's omitted in the output assembly. --------- Co-authored-by: Bruno Cardoso Lopes <[email protected]>
…lvm#760) This PR simply adds the calling convention attribute to FuncOp with LLVM Lowering support. The overall approach follows `GlobalLinkageKind`: Extend the ODS, parser, printer and lowering pass. When the call conv is C call conv, it's omitted in the output assembly. --------- Co-authored-by: Bruno Cardoso Lopes <[email protected]>
This PR simply adds the calling convention attribute to FuncOp with LLVM Lowering support.
The overall approach follows
GlobalLinkageKind
: Extend the ODS, parser, printer and lowering pass. When the call conv is C call conv, it's omitted in the output assembly.