[PATCH] D73233: [mlir] Add option to use custom base class for dialect in LLVMIRIntrinsicGen.

Marcello Maggioni via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 14:31:41 PST 2020


kariddi created this revision.
kariddi added reviewers: rriddle, andydavis1, antiagainst, nicolasvasilache, ftynse.
Herald added subscribers: llvm-commits, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, shauheen, burmako, jpienaar, mehdi_amini, jdoerfert.
Herald added a project: LLVM.

LLVMIRIntrinsicGen is using LLVM_Op as the base class for intrinsics.
This works for LLVM intrinsics in the LLVM Dialect, but when we are
trying to convert custom intrinsics that originate from a custom
LLVM dialect (like NVVM or ROCDL) these usually have a different
"cppNamespace" that needs to be applied to these dialect.

These dialect specific characteristics (like "cppNamespace")
are typically organized by creating a custom op (like NVVM_Op or
ROCDL_Op) that passes the correct dialect to the LLVM_OpBase class.

It seems natural to allow LLVMIRIntrinsicGen to take that into
consideration when generating the conversion code from one of these
dialect to a set of target specific intrinsics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73233

Files:
  mlir/test/mlir-tblgen/llvm-intrinsics.td
  mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp


Index: mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp
===================================================================
--- mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp
+++ mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp
@@ -32,6 +32,12 @@
                               "substring in their record name"),
                llvm::cl::cat(IntrinsicGenCat));
 
+static llvm::cl::opt<std::string>
+    opBaseClass("dialect-opclass-base",
+                llvm::cl::desc("The base class for the ops in the dialect we "
+                               "are planning to emit"),
+                llvm::cl::init("LLVM_Op"), llvm::cl::cat(IntrinsicGenCat));
+
 // Used to represent the indices of overloadable operands/results.
 using IndicesTy = llvm::SmallBitVector;
 
@@ -205,8 +211,8 @@
                                                  "LLVM_Type");
 
   // Emit the definition.
-  os << "def LLVM_" << intr.getProperRecordName() << " : LLVM_Op<\"intr."
-     << intr.getOperationName() << "\", [";
+  os << "def LLVM_" << intr.getProperRecordName() << " : " << opBaseClass
+     << "<\"intr." << intr.getOperationName() << "\", [";
   mlir::interleaveComma(traits, os);
   os << "]>, Arguments<(ins" << (operands.empty() ? "" : " ");
   mlir::interleaveComma(operands, os);
Index: mlir/test/mlir-tblgen/llvm-intrinsics.td
===================================================================
--- mlir/test/mlir-tblgen/llvm-intrinsics.td
+++ mlir/test/mlir-tblgen/llvm-intrinsics.td
@@ -36,3 +36,11 @@
 // RUN: | FileCheck --check-prefix=ODS %s
 
 // ODS-LABEL: class vastart
+
+// RUN: cat %S/../../../llvm/include/llvm/IR/Intrinsics.td \
+// RUN: | grep -v "llvm/IR/Intrinsics" \
+// RUN: | mlir-tblgen -gen-llvmir-intrinsics -I %S/../../../llvm/include/ --llvmir-intrinsics-filter=is_constant -dialect-opclass-base My_OpBase \
+// RUN: | FileCheck %s --check-prefix=DIALECT-OPBASE
+
+// DIALECT-OPBASE-LABEL: def LLVM_is_constant
+// DIALECT-OPBASE: My_OpBase<"intr


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73233.239705.patch
Type: text/x-patch
Size: 1961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200122/00d8683b/attachment.bin>


More information about the llvm-commits mailing list