Skip to content

Commit 83f183e

Browse files
ArgInfo with ArgName and ImmArgPrinter
1 parent 1104388 commit 83f183e

File tree

4 files changed

+47
-14
lines changed

4 files changed

+47
-14
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ class NoUndef<AttrIndex idx> : IntrinsicProperty {
8787
int ArgNo = idx.Value;
8888
}
8989

90-
// ArgInfo - The specified argument has an argument name and an optional argument printing
91-
// function for diagnostic output.
92-
class ArgInfo<AttrIndex idx, string argname, string funcname = ""> : IntrinsicProperty {
93-
int ArgNo = idx.Value;
94-
string ArgName = argname;
95-
string FunctionName = funcname;
96-
}
97-
9890
// NonNull - The return value or specified argument is not null.
9991
class NonNull<AttrIndex idx> : IntrinsicProperty {
10092
int ArgNo = idx.Value;
@@ -150,6 +142,25 @@ class Range<AttrIndex idx, int lower, int upper> : IntrinsicProperty {
150142
int Upper = upper;
151143
}
152144

145+
// ArgProperty - Base class for argument properties that can be specified in ArgInfo.
146+
class ArgProperty;
147+
148+
// ArgName - Specifies the name of an argument for pretty-printing.
149+
class ArgName<string name> : ArgProperty {
150+
string Name = name;
151+
}
152+
153+
// ImmArgPrinter - Specifies a custom printer function for immediate arguments.
154+
class ImmArgPrinter<string funcname> : ArgProperty {
155+
string FuncName = funcname;
156+
}
157+
158+
// ArgInfo - The specified argument has properties defined by a list of ArgProperty objects.
159+
class ArgInfo<AttrIndex idx, list<ArgProperty> arg_properties> : IntrinsicProperty {
160+
int ArgNo = idx.Value;
161+
list<ArgProperty> Properties = arg_properties;
162+
}
163+
153164
def IntrNoReturn : IntrinsicProperty;
154165

155166
// Applied by default.

llvm/include/llvm/IR/IntrinsicsNVVM.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,13 @@ foreach sp = [0, 1] in {
29042904
]
29052905
);
29062906

2907+
defvar intrinsic_properties = !if(is_target_intrinsic,
2908+
!listconcat(base_properties,
2909+
[ArgInfo<ArgIndex<nargs>, [ArgName<"kind">, ImmArgPrinter<"printTcgen05MMAKind">]>,
2910+
ArgInfo<ArgIndex<!add(nargs, 1)>, [ArgName<"cta_group">]>,
2911+
ArgInfo<ArgIndex<!add(nargs, 2)>, [ArgName<"collector">, ImmArgPrinter<"printTcgen05CollectorUsageOp">]>]),
2912+
base_properties);
2913+
29072914
def mma.record_name:
29082915
DefaultAttrsIntrinsicFlags<[], args, flags, intrinsic_properties,
29092916
mma.intr_name>;

llvm/test/TableGen/intrinsic-arginfo.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def int_dummy_foo_bar : DefaultAttrsIntrinsic<
1414
llvm_i32_ty], // stride
1515
[IntrNoMem,
1616
ImmArg<ArgIndex<1>>,
17-
ArgInfo<ArgIndex<1>, "mode", "printDummyMode">,
18-
ArgInfo<ArgIndex<2>, "stride">]>;
17+
ArgInfo<ArgIndex<1>, [ArgName<"mode">, ImmArgPrinter<"printDummyMode">]>,
18+
ArgInfo<ArgIndex<2>, [ArgName<"stride">]>]>;
1919

2020
// A custom floating point add with rounding and sat mode.
2121
def int_my_fadd_f32 : DefaultAttrsIntrinsic<
@@ -27,8 +27,8 @@ def int_my_fadd_f32 : DefaultAttrsIntrinsic<
2727
[IntrNoMem,
2828
ImmArg<ArgIndex<2>>,
2929
ImmArg<ArgIndex<3>>,
30-
ArgInfo<ArgIndex<2>, "rounding_mode", "printRoundingMode">,
31-
ArgInfo<ArgIndex<3>, "saturation_mode">]>;
30+
ArgInfo<ArgIndex<2>, [ArgName<"rounding_mode">, ImmArgPrinter<"printRoundingMode">]>,
31+
ArgInfo<ArgIndex<3>, [ArgName<"saturation_mode">]>]>;
3232

3333
// CHECK: #ifdef GET_INTRINSIC_PRETTY_PRINT_TABLE
3434
// CHECK-NEXT: static constexpr uint8_t PPTable[] = {

llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,23 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
452452
if (ArgNo < 1)
453453
PrintFatalError(R->getLoc(),
454454
"ArgInfo requires ArgNo >= 1 (0 is return value)");
455-
StringRef ArgName = R->getValueAsString("ArgName");
456-
StringRef FuncName = R->getValueAsString("FunctionName");
455+
const ListInit *Properties = R->getValueAsListInit("Properties");
456+
StringRef ArgName;
457+
StringRef FuncName;
458+
459+
for (const Init *PropInit : Properties->getElements()) {
460+
if (const DefInit *PropDef = dyn_cast<DefInit>(PropInit)) {
461+
const Record *PropRec = PropDef->getDef();
462+
463+
if (PropRec->isSubClassOf("ArgName"))
464+
ArgName = PropRec->getValueAsString("Name");
465+
else if (PropRec->isSubClassOf("ImmArgPrinter"))
466+
FuncName = PropRec->getValueAsString("FuncName");
467+
else
468+
PrintFatalError(PropRec->getLoc(),
469+
"Unknown ArgProperty type: " + PropRec->getName());
470+
}
471+
}
457472
addPrettyPrintFunction(ArgNo - 1, ArgName, FuncName);
458473
} else {
459474
llvm_unreachable("Unknown property!");

0 commit comments

Comments
 (0)