[mlir][openmp] Add an interface for Outlineable OpenMP ops
authorKiran Chandramohan <kiran.chandramohan@arm.com>
Thu, 7 Oct 2021 18:52:15 +0000 (20:52 +0200)
committerValentin Clement <clementval@gmail.com>
Thu, 7 Oct 2021 18:53:48 +0000 (20:53 +0200)
Add an interface for outlineable OpenMP operations.
This patch was initially done in fir-dev and is now needed
for the upstreaming.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111310

mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td [new file with mode: 0644]
mlir/lib/Dialect/OpenMP/CMakeLists.txt

index a0aa8ba8ab0300021166709078d08e47b0669281..a558eb45e077d11ccf520ee5c0c139ebd3918f0a 100644 (file)
@@ -14,3 +14,4 @@ mlir_tablegen(OpenMPTypeInterfaces.cpp.inc -gen-type-interface-defs)
 add_mlir_doc(OpenMPOps OpenMPDialect Dialects/ -gen-dialect-doc)
 add_public_tablegen_target(MLIROpenMPOpsIncGen)
 add_dependencies(OpenMPDialectDocGen omp_common_td)
+add_mlir_interface(OpenMPOpsInterfaces)
index 7e916f7fec7c0748846a9e11290a216d05b920ab..375276180c9f7dad2426ddeda58dcb5b8f03b907 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc"
 #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc"
+#include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.h.inc"
 #include "mlir/Dialect/OpenMP/OpenMPTypeInterfaces.h.inc"
 
 #define GET_OP_CLASSES
index 05d406d09fc6779caca5d0152a8adda623522589..73ee9df406c9a6e118f1c3c18dfa885751715ba8 100644 (file)
@@ -20,6 +20,7 @@ include "mlir/Interfaces/ControlFlowInterfaces.td"
 include "mlir/IR/SymbolInterfaces.td"
 include "mlir/Dialect/OpenMP/OmpCommon.td"
 include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
+include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td"
 
 def OpenMP_Dialect : Dialect {
   let name = "omp";
@@ -72,7 +73,8 @@ def ClauseDefault : StrEnumAttr<
   let cppNamespace = "::mlir::omp";
 }
 
-def ParallelOp : OpenMP_Op<"parallel", [AttrSizedOperandSegments]> {
+def ParallelOp : OpenMP_Op<"parallel", [AttrSizedOperandSegments,
+                 DeclareOpInterfaceMethods<OutlineableOpenMPOpInterface>]> {
   let summary = "parallel construct";
   let description = [{
     The parallel construct includes a region of code which is to be executed
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
new file mode 100644 (file)
index 0000000..a99e496
--- /dev/null
@@ -0,0 +1,34 @@
+//===-- OpenMPOpsInterfaces.td - OpenMP op interfaces ------*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is the OpenMP Dialect interfaces definition file.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OpenMP_OPS_INTERFACES
+#define OpenMP_OPS_INTERFACES
+
+include "mlir/IR/OpBase.td"
+
+def OutlineableOpenMPOpInterface : OpInterface<"OutlineableOpenMPOpInterface"> {
+  let description = [{
+    OpenMP operations whose region will be outlined will implement this
+    interface. These operations will
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+    InterfaceMethod<"Get alloca block", "::mlir::Block*", "getAllocaBlock",
+      (ins), [{
+      return &$_op.getRegion().front();
+      }]>,
+  ];
+}
+
+#endif // OpenMP_OPS_INTERFACES
index 6fd75c611542f7a80c96af5748f279d943416a76..7882b0fa832c114d88aedc10d20eb54b074d6991 100644 (file)
@@ -6,6 +6,7 @@ add_mlir_dialect_library(MLIROpenMP
 
   DEPENDS
   MLIROpenMPOpsIncGen
+  MLIROpenMPOpsInterfacesIncGen
 
   LINK_LIBS PUBLIC
   MLIRIR