-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[LLVM-Tablegen] Pretty Printing Arguments in LLVM Intrinsics #162629
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
Open
DharuniRAcharya
wants to merge
1
commit into
llvm:main
Choose a base branch
from
DharuniRAcharya:dev/dharunira/pretty_printing_immargs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+350
−9
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 | ||
; NOTE: This sample test demonstrates the pretty print feature for NVPTX intrinsics | ||
; RUN: llvm-as < %s | llvm-dis | FileCheck %s | ||
|
||
target triple = "nvptx64-nvidia-cuda" | ||
|
||
define void @tcgen05_mma_fp16_cta1(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d) { | ||
; CHECK-LABEL: define void @tcgen05_mma_fp16_cta1( | ||
; CHECK: call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, /* kind=f16 */ i32 0, /* cta_group= */ i32 1, /* collector=discard */ i32 0) | ||
call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, i32 0, i32 1, i32 0) | ||
|
||
; CHECK: call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, /* kind=f16 */ i32 0, /* cta_group= */ i32 1, /* collector=lastuse */ i32 1) | ||
call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, i32 0, i32 1, i32 1) | ||
|
||
; CHECK: call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, /* kind=f16 */ i32 0, /* cta_group= */ i32 1, /* collector=fill */ i32 2) | ||
call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, i32 0, i32 1, i32 2) | ||
|
||
; CHECK: call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, /* kind=f16 */ i32 0, /* cta_group= */ i32 1, /* collector=use */ i32 3) | ||
call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, i32 0, i32 1, i32 3) | ||
|
||
ret void | ||
} | ||
|
||
define void @tcgen05_mma_f8f6f4_cta2(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d) { | ||
; CHECK-LABEL: define void @tcgen05_mma_f8f6f4_cta2( | ||
; CHECK: call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, /* kind=f8f6f4 */ i32 2, /* cta_group= */ i32 2, /* collector=discard */ i32 0) | ||
call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, i32 2, i32 2, i32 0) | ||
|
||
; CHECK: call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, /* kind=f8f6f4 */ i32 2, /* cta_group= */ i32 2, /* collector=lastuse */ i32 1) | ||
call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, i32 2, i32 2, i32 1) | ||
|
||
; CHECK: call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, /* kind=f8f6f4 */ i32 2, /* cta_group= */ i32 2, /* collector=fill */ i32 2) | ||
call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, i32 2, i32 2, i32 2) | ||
|
||
; CHECK: call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, /* kind=f8f6f4 */ i32 2, /* cta_group= */ i32 2, /* collector=use */ i32 3) | ||
call void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6) %dtmem, ptr addrspace(6) %atensor, i64 %b, i32 %idesc, i1 %enable_inp_d, i32 2, i32 2, i32 3) | ||
|
||
ret void | ||
} | ||
|
||
declare void @llvm.nvvm.tcgen05.mma.tensor(ptr addrspace(6), ptr addrspace(6), i64, i32, i1, i32, i32, i32) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// RUN: llvm-tblgen -gen-intrinsic-impl -I %p/../../include %s | FileCheck %s | ||
|
||
// Test ArgInfo property for pretty-printing intrinsic arguments. | ||
// This test verifies that TableGen generates the correct pretty-printing code | ||
// for intrinsics that use the ArgInfo property. | ||
|
||
include "llvm/IR/Intrinsics.td" | ||
|
||
// Simple intrinsic with two arguments that have ArgInfo. | ||
def int_dummy_foo_bar : DefaultAttrsIntrinsic< | ||
[llvm_i32_ty], | ||
[llvm_i32_ty, // data | ||
llvm_i32_ty, // mode | ||
llvm_i32_ty], // stride | ||
[IntrNoMem, | ||
ImmArg<ArgIndex<1>>, | ||
ArgInfo<ArgIndex<1>, "mode", "printDummyMode">, | ||
ArgInfo<ArgIndex<2>, "stride">]>; | ||
|
||
// A custom floating point add with rounding and sat mode. | ||
def int_my_fadd_f32 : DefaultAttrsIntrinsic< | ||
[llvm_float_ty], | ||
[llvm_float_ty, // a | ||
llvm_float_ty, // b | ||
llvm_i32_ty, // rounding_mode | ||
llvm_i1_ty], // saturation_mode | ||
[IntrNoMem, | ||
ImmArg<ArgIndex<2>>, | ||
ImmArg<ArgIndex<3>>, | ||
ArgInfo<ArgIndex<2>, "rounding_mode", "printRoundingMode">, | ||
ArgInfo<ArgIndex<3>, "saturation_mode">]>; | ||
|
||
// CHECK: #ifdef GET_INTRINSIC_PRETTY_PRINT_TABLE | ||
// CHECK-NEXT: static constexpr uint8_t PPTable[] = { | ||
|
||
// CHECK: #endif // GET_INTRINSIC_PRETTY_PRINT_TABLE | ||
|
||
// CHECK: #ifdef GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS | ||
// CHECK: void Intrinsic::printImmArg(ID IID, unsigned ArgIdx, raw_ostream &OS, const Constant *ImmArgVal) { | ||
|
||
// CHECK: case dummy_foo_bar: | ||
// CHECK-NEXT: switch (ArgIdx) { | ||
|
||
// CHECK-NEXT: case 1: | ||
// CHECK-NEXT: OS << "mode="; | ||
// CHECK-NEXT: printDummyMode(OS, ImmArgVal); | ||
// CHECK-NEXT: return; | ||
|
||
// CHECK-NEXT: case 2: | ||
// CHECK-NEXT: OS << "stride="; | ||
// CHECK-NEXT: return; | ||
|
||
// CHECK-NEXT: } | ||
// CHECK-NEXT: break; | ||
|
||
// CHECK: case my_fadd_f32: | ||
// CHECK-NEXT: switch (ArgIdx) { | ||
|
||
// CHECK-NEXT: case 2: | ||
// CHECK-NEXT: OS << "rounding_mode="; | ||
// CHECK-NEXT: printRoundingMode(OS, ImmArgVal); | ||
// CHECK-NEXT: return; | ||
|
||
// CHECK-NEXT: case 3: | ||
// CHECK-NEXT: OS << "saturation_mode="; | ||
// CHECK-NEXT: return; | ||
|
||
// CHECK-NEXT: } | ||
// CHECK-NEXT: break; | ||
|
||
// CHECK: #endif // GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we want to go with a generic ArgInfo in future where we list all the properties of a particular arg for an intrinsic, it seems we would need something like
And then we can have something like
where
ImmArg
andNoCapture
can be used without any ArgIndex in them. To be able to do that, does it make sense to atleast start with such a scheme for ArgName and ImmArgPrinter<>? So you'd define a ArgProperty class and subclass from it ArgName<> and ImmArgPrinter<>.Then we can extend these for other properties in future. @nikic does that direction sound ok?