LLVM Discussion Forums

MLIR tablegen question

I’m looking to write an llvmBuilder set to a createIntrinsicCall for an intrinsic which takes 6 args. I can’t find an example like this that already exists in the code base.

So for example:

class ROCDL_XXX<string mnemonic, list traits = []> :
ROCDL_Op<mnemonic, !listconcat(traits, [NoSideEffect])>,
Results<(outs LLVM_Type:$res)>, Arguments<(ins LLVM_Type:$src1,
LLVM_Type:$src2,
LLVM_Type:$src3,
LLVM_Type:$src4,
LLVM_Type:$src5,
LLVM_Type:$src6)> {
string llvmBuilder = “$res = createIntrinsicCall(builder,”
# “llvm::Intrinsic::amdgcn_XXX_” # !subst(".","_", mnemonic) # “,
{$src1, $src2, $src3, $src4, $src5, $src6});”;
let parser = [{ return parseROCDLOp(parser, result); }];
let printer = [{ printROCDLOp(p, this->getOperation()); }];
}

This doesn’t compile nor would it work. Is it not possible to generate the intrinsic from type directly in tablegen in MLIR? Do I have to have an accompanying cpp function call, like getShflBflyIntrinsicId where I pass each argument and have to check each argument and return the intId for each possible argument? This seems rather ugly.

mlir-tblgen has a mode in which it is able to parse LLVM intrinsic files and produce MLIR tablegen definitions that should be immediately usable. Take a look at this test https://github.com/llvm/llvm-project/blob/master/mlir/test/mlir-tblgen/llvm-intrinsics.td to see how it is used.

Is that what is being used in the LLVMAVX512.td?

I suppose the contents of that file was adapted from the mlir-tblgen output. You can also see the documentation on the LLVM_IntrOpBase tablegen class https://github.com/llvm/llvm-project/blob/69040d5b0bfa59edacc2ad10d517b4270bf76845/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td#L145 if you want to use it directly.

Thanks, this was helpful.