[llvm-branch-commits] [mlir] cf50f4f - [mlir] Link mlir_runner_utils statically into cuda/rocm-runtime-wrappers.

2021-01-20 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-20T12:10:16+01:00
New Revision: cf50f4f764566a78da8c0551f853118fe604d8d7

URL: 
https://github.com/llvm/llvm-project/commit/cf50f4f764566a78da8c0551f853118fe604d8d7
DIFF: 
https://github.com/llvm/llvm-project/commit/cf50f4f764566a78da8c0551f853118fe604d8d7.diff

LOG: [mlir] Link mlir_runner_utils statically into cuda/rocm-runtime-wrappers.

The runtime-wrappers depend on LLVMSupport, pulling in static initialization 
code (e.g. command line arguments). Dynamically loading multiple such libraries 
results in ODR violoations.

So far this has not been an issue, but in D94421, I would like to load both the 
async-runtime and the cuda-runtime-wrappers as part of a cuda-runner 
integration test. When doing this, code that asserts that an option category is 
only registered once fails (note that I've only experienced this in Google's 
bazel where the async-runtime depends on LLVMSupport, but a similar issue would 
happen in cmake if more than one runtime-wrapper starts to depend on 
LLVMSupport).

The underlying issue is that we have a mix of static and dynamic linking. If 
all dependencies were loaded as shared objects (i.e. if LLVMSupport was linked 
dynamically to the runtime wrappers), each dependency would only get loaded 
once. However, linking dependencies dynamically would require special attention 
to paths (one could dynamically load the dependencies first given explicit 
paths). The simpler approach seems to be to link all dependencies statically 
into a single shared object.

This change basically applies the same logic that we have in the 
c_runner_utils: we have a shared object target that can be loaded dynamically, 
and we have a static library target that can be linked to other runtime-wrapper 
shared object targets.

Reviewed By: herhut

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

Added: 


Modified: 
mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
mlir/lib/ExecutionEngine/CMakeLists.txt
mlir/test/mlir-cuda-runner/all-reduce-and.mlir
mlir/test/mlir-cuda-runner/all-reduce-max.mlir
mlir/test/mlir-cuda-runner/all-reduce-min.mlir
mlir/test/mlir-cuda-runner/all-reduce-op.mlir
mlir/test/mlir-cuda-runner/all-reduce-or.mlir
mlir/test/mlir-cuda-runner/all-reduce-region.mlir
mlir/test/mlir-cuda-runner/all-reduce-xor.mlir
mlir/test/mlir-cuda-runner/gpu-to-cubin.mlir
mlir/test/mlir-cuda-runner/multiple-all-reduce.mlir
mlir/test/mlir-cuda-runner/shuffle.mlir
mlir/test/mlir-cuda-runner/two-modules.mlir
mlir/test/mlir-rocm-runner/gpu-to-hsaco.mlir
mlir/test/mlir-rocm-runner/two-modules.mlir
mlir/test/mlir-rocm-runner/vecadd.mlir
mlir/test/mlir-rocm-runner/vector-transferops.mlir
mlir/tools/mlir-cuda-runner/CMakeLists.txt
mlir/tools/mlir-rocm-runner/CMakeLists.txt

Removed: 




diff  --git a/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h 
b/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
index 2d0608a8656b..272058d7b387 100644
--- a/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
+++ b/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
@@ -26,7 +26,7 @@
 #define MLIR_CRUNNERUTILS_EXPORT __declspec(dllimport)
 #endif // mlir_c_runner_utils_EXPORTS
 #endif // MLIR_CRUNNERUTILS_EXPORT
-#else
+#else  // _WIN32
 #define MLIR_CRUNNERUTILS_EXPORT
 #define MLIR_CRUNNERUTILS_DEFINE_FUNCTIONS
 #endif // _WIN32

diff  --git a/mlir/lib/ExecutionEngine/CMakeLists.txt 
b/mlir/lib/ExecutionEngine/CMakeLists.txt
index 7d86811fe4fd..f995ad0266d7 100644
--- a/mlir/lib/ExecutionEngine/CMakeLists.txt
+++ b/mlir/lib/ExecutionEngine/CMakeLists.txt
@@ -80,6 +80,7 @@ add_mlir_library(mlir_c_runner_utils
   EXCLUDE_FROM_LIBMLIR
   )
 set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 11)
+target_compile_definitions(mlir_c_runner_utils PRIVATE 
mlir_c_runner_utils_EXPORTS)
 
 add_mlir_library(mlir_c_runner_utils_static
   CRunnerUtils.cpp
@@ -88,7 +89,6 @@ add_mlir_library(mlir_c_runner_utils_static
   EXCLUDE_FROM_LIBMLIR
   )
 set_property(TARGET mlir_c_runner_utils_static PROPERTY CXX_STANDARD 11)
-target_compile_definitions(mlir_c_runner_utils PRIVATE 
mlir_c_runner_utils_EXPORTS)
 
 add_mlir_library(mlir_runner_utils
   SHARED
@@ -101,6 +101,15 @@ add_mlir_library(mlir_runner_utils
 )
 target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
 
+add_mlir_library(mlir_runner_utils_static
+  RunnerUtils.cpp
+
+  EXCLUDE_FROM_LIBMLIR
+
+  LINK_LIBS PUBLIC
+  mlir_c_runner_utils_static
+)
+
 add_mlir_library(mlir_async_runtime
   SHARED
   AsyncRuntime.cpp
@@ -113,3 +122,13 @@ add_mlir_library(mlir_async_runtime
 )
 set_property(TARGET mlir_async_runtime PROPERTY CXX_VISIBILITY_PRESET hidden)
 target_compile_definitions(mlir_async_runtime PRIVATE 
mlir_async_runtime_EXPORTS)
+
+add_mlir_library(mlir_async_runtime_static
+  AsyncRuntime.cpp
+
+  EXCLUDE_FROM_LIBMLIR
+
+  LINK_LIBS PUBLIC
+ 

[llvm-branch-commits] [mlir] cba1ca9 - Fix cuda-runner tests.

2021-01-20 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-20T13:14:27+01:00
New Revision: cba1ca9025899b1f6681ac824a7db60349d575f7

URL: 
https://github.com/llvm/llvm-project/commit/cba1ca9025899b1f6681ac824a7db60349d575f7
DIFF: 
https://github.com/llvm/llvm-project/commit/cba1ca9025899b1f6681ac824a7db60349d575f7.diff

LOG: Fix cuda-runner tests.

Added: 


Modified: 
mlir/test/mlir-cuda-runner/all-reduce-and.mlir
mlir/test/mlir-cuda-runner/all-reduce-max.mlir
mlir/test/mlir-cuda-runner/all-reduce-min.mlir
mlir/test/mlir-cuda-runner/all-reduce-op.mlir
mlir/test/mlir-cuda-runner/all-reduce-or.mlir
mlir/test/mlir-cuda-runner/all-reduce-region.mlir
mlir/test/mlir-cuda-runner/all-reduce-xor.mlir
mlir/test/mlir-cuda-runner/gpu-to-cubin.mlir
mlir/test/mlir-cuda-runner/multiple-all-reduce.mlir
mlir/test/mlir-cuda-runner/shuffle.mlir
mlir/test/mlir-cuda-runner/two-modules.mlir
mlir/test/mlir-rocm-runner/gpu-to-hsaco.mlir
mlir/test/mlir-rocm-runner/two-modules.mlir
mlir/test/mlir-rocm-runner/vecadd.mlir
mlir/test/mlir-rocm-runner/vector-transferops.mlir

Removed: 




diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-and.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-and.mlir
index 205f4e7fca2d..8df20401cfba 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-and.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-and.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-max.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-max.mlir
index 32f4511a22bf..66a35e25988f 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-max.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-max.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-min.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-min.mlir
index 39c62b0628a2..7f7bf6921c85 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-min.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-min.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-op.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-op.mlir
index e20e386d9ffa..d4857e3e6ea6 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-op.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-op.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-or.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-or.mlir
index 175fda6e1f89..dfc015a65f1a 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-or.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-or.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-region.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-region.mlir
index dd70a5bc359e..988ed2a2320e 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-region.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-region.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-xor.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-xor.mlir
index cf0d409ed28f..917140ba52fc 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-xor.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-xor.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
 // RUN:   --entry-point-result=void \
 // RUN: |

[llvm-branch-commits] [mlir] 8827e07 - Remove deprecated methods from OpState.

2021-01-21 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-21T21:29:08+01:00
New Revision: 8827e07aaf2114b7f09e229e22481cd58137ea6a

URL: 
https://github.com/llvm/llvm-project/commit/8827e07aaf2114b7f09e229e22481cd58137ea6a
DIFF: 
https://github.com/llvm/llvm-project/commit/8827e07aaf2114b7f09e229e22481cd58137ea6a.diff

LOG: Remove deprecated methods from OpState.

Reviewed By: rriddle

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

Added: 


Modified: 
mlir/include/mlir/IR/OpDefinition.h
mlir/lib/IR/Operation.cpp

Removed: 




diff  --git a/mlir/include/mlir/IR/OpDefinition.h 
b/mlir/include/mlir/IR/OpDefinition.h
index c021bdc8ee9d..1180938e858b 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -104,34 +104,6 @@ class OpState {
   /// Return the operation that this refers to.
   Operation *getOperation() { return state; }
 
-  /// Return the dialect that this refers to.
-  LLVM_ATTRIBUTE_DEPRECATED(
-  Dialect *getDialect(),
-  "Use Operation::getDialect() instead (replace '.' with '->').");
-
-  /// Return the parent Region of this operation.
-  LLVM_ATTRIBUTE_DEPRECATED(
-  Region *getParentRegion(),
-  "Use Operation::getParentRegion() instead (replace '.' with '->').");
-
-  /// Returns the closest surrounding operation that contains this operation
-  /// or nullptr if this is a top-level operation.
-  LLVM_ATTRIBUTE_DEPRECATED(
-  Operation *getParentOp(),
-  "Use Operation::getParentOp() instead (replace '.' with '->').");
-
-  /// Return the closest surrounding parent operation that is of type 'OpTy'.
-  template 
-  LLVM_ATTRIBUTE_DEPRECATED(
-  OpTy getParentOfType(),
-  "Use Operation::getParentOfType() instead (replace '.' with '->').");
-
-  /// Returns the closest surrounding parent operation with trait `Trait`.
-  template  class Trait>
-  LLVM_ATTRIBUTE_DEPRECATED(
-  Operation *getParentWithTrait(),
-  "Use Operation::getParentWithTrait() instead (replace '.' with '->').");
-
   /// Return the context this operation belongs to.
   MLIRContext *getContext() { return getOperation()->getContext(); }
 
@@ -158,45 +130,6 @@ class OpState {
   using dialect_attr_iterator = Operation::dialect_attr_iterator;
   using dialect_attr_range = Operation::dialect_attr_range;
 
-  /// Return a range corresponding to the dialect attributes for this 
operation.
-  LLVM_ATTRIBUTE_DEPRECATED(
-  dialect_attr_range getDialectAttrs(),
-  "Use Operation::getDialectAttrs() instead (replace '.' with '->').");
-  LLVM_ATTRIBUTE_DEPRECATED(
-  dialect_attr_iterator dialect_attr_begin(),
-  "Use Operation::dialect_attr_begin() instead (replace '.' with '->').");
-  LLVM_ATTRIBUTE_DEPRECATED(
-  dialect_attr_iterator dialect_attr_end(),
-  "Use Operation::dialect_attr_end() instead (replace '.' with '->').");
-
-  /// Return an attribute with the specified name.
-  LLVM_ATTRIBUTE_DEPRECATED(
-  Attribute getAttr(StringRef name),
-  "Use Operation::getAttr() instead (replace '.' with '->').");
-
-  /// If the operation has an attribute of the specified type, return it.
-  template 
-  LLVM_ATTRIBUTE_DEPRECATED(
-  AttrClass getAttrOfType(StringRef name),
-  "Use Operation::getAttrOfType() instead (replace '.' with '->').");
-
-  /// If the an attribute exists with the specified name, change it to the new
-  /// value.  Otherwise, add a new attribute with the specified name/value.
-  LLVM_ATTRIBUTE_DEPRECATED(
-  void setAttr(Identifier name, Attribute value),
-  "Use Operation::setAttr() instead (replace '.' with '->').");
-  LLVM_ATTRIBUTE_DEPRECATED(
-  void setAttr(StringRef name, Attribute value),
-  "Use Operation::setAttr() instead (replace '.' with '->').");
-
-  /// Set the attributes held by this operation.
-  LLVM_ATTRIBUTE_DEPRECATED(
-  void setAttrs(ArrayRef attributes),
-  "Use Operation::setAttrs() instead (replace '.' with '->').");
-  LLVM_ATTRIBUTE_DEPRECATED(
-  void setAttrs(DictionaryAttr newAttrs),
-  "Use Operation::setAttrs() instead (replace '.' with '->').");
-
   /// Set the dialect attributes for this operation, and preserve all 
dependent.
   template 
   void setDialectAttrs(DialectAttrs &&attrs) {
@@ -272,19 +205,6 @@ class OpState {
   friend AbstractOperation;
 };
 
-template 
-OpTy OpState::getParentOfType() {
-  return getOperation()->getParentOfType();
-}
-template  class Trait>
-Operation *OpState::getParentWithTrait() {
-  return getOperation()->getParentWithTrait();
-}
-template 
-AttrClass OpState::getAttrOfType(StringRef name) {
-  return getAttr(name).dyn_cast_or_null();
-}
-
 // Allow comparing operators.
 inline bool operator==(OpState lhs, OpState rhs) {
   return lhs.getOperation() == rhs.getOperation();

diff  --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index ba1d1e5109cc..b4fe9f854dda 100644
--- a/mlir/lib/IR/Operati

[llvm-branch-commits] [mlir] bd3a387 - Revert [mlir] Link mlir_runner_utils statically into cuda/rocm-runtime-wrappers (cf50f4f76456)

2021-01-21 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-21T22:38:59+01:00
New Revision: bd3a387ee76f58caa0d7901f3f84e9bb3d006f27

URL: 
https://github.com/llvm/llvm-project/commit/bd3a387ee76f58caa0d7901f3f84e9bb3d006f27
DIFF: 
https://github.com/llvm/llvm-project/commit/bd3a387ee76f58caa0d7901f3f84e9bb3d006f27.diff

LOG: Revert [mlir] Link mlir_runner_utils statically into 
cuda/rocm-runtime-wrappers (cf50f4f76456)

There are cmake failures that I do not know how to fix.

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

Added: 


Modified: 
mlir/lib/ExecutionEngine/CMakeLists.txt
mlir/test/mlir-cuda-runner/all-reduce-and.mlir
mlir/test/mlir-cuda-runner/all-reduce-max.mlir
mlir/test/mlir-cuda-runner/all-reduce-min.mlir
mlir/test/mlir-cuda-runner/all-reduce-op.mlir
mlir/test/mlir-cuda-runner/all-reduce-or.mlir
mlir/test/mlir-cuda-runner/all-reduce-region.mlir
mlir/test/mlir-cuda-runner/all-reduce-xor.mlir
mlir/test/mlir-cuda-runner/gpu-to-cubin.mlir
mlir/test/mlir-cuda-runner/multiple-all-reduce.mlir
mlir/test/mlir-cuda-runner/shuffle.mlir
mlir/test/mlir-cuda-runner/two-modules.mlir
mlir/test/mlir-rocm-runner/gpu-to-hsaco.mlir
mlir/test/mlir-rocm-runner/two-modules.mlir
mlir/test/mlir-rocm-runner/vecadd.mlir
mlir/test/mlir-rocm-runner/vector-transferops.mlir
mlir/tools/mlir-cuda-runner/CMakeLists.txt
mlir/tools/mlir-rocm-runner/CMakeLists.txt

Removed: 




diff  --git a/mlir/lib/ExecutionEngine/CMakeLists.txt 
b/mlir/lib/ExecutionEngine/CMakeLists.txt
index f995ad0266d7..b8e486ca47db 100644
--- a/mlir/lib/ExecutionEngine/CMakeLists.txt
+++ b/mlir/lib/ExecutionEngine/CMakeLists.txt
@@ -80,7 +80,6 @@ add_mlir_library(mlir_c_runner_utils
   EXCLUDE_FROM_LIBMLIR
   )
 set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 11)
-target_compile_definitions(mlir_c_runner_utils PRIVATE 
mlir_c_runner_utils_EXPORTS)
 
 add_mlir_library(mlir_c_runner_utils_static
   CRunnerUtils.cpp
@@ -89,6 +88,7 @@ add_mlir_library(mlir_c_runner_utils_static
   EXCLUDE_FROM_LIBMLIR
   )
 set_property(TARGET mlir_c_runner_utils_static PROPERTY CXX_STANDARD 11)
+target_compile_definitions(mlir_c_runner_utils PRIVATE 
mlir_c_runner_utils_EXPORTS)
 
 add_mlir_library(mlir_runner_utils
   SHARED
@@ -101,15 +101,6 @@ add_mlir_library(mlir_runner_utils
 )
 target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
 
-add_mlir_library(mlir_runner_utils_static
-  RunnerUtils.cpp
-
-  EXCLUDE_FROM_LIBMLIR
-
-  LINK_LIBS PUBLIC
-  mlir_c_runner_utils_static
-)
-
 add_mlir_library(mlir_async_runtime
   SHARED
   AsyncRuntime.cpp
@@ -123,12 +114,3 @@ add_mlir_library(mlir_async_runtime
 set_property(TARGET mlir_async_runtime PROPERTY CXX_VISIBILITY_PRESET hidden)
 target_compile_definitions(mlir_async_runtime PRIVATE 
mlir_async_runtime_EXPORTS)
 
-add_mlir_library(mlir_async_runtime_static
-  AsyncRuntime.cpp
-
-  EXCLUDE_FROM_LIBMLIR
-
-  LINK_LIBS PUBLIC
-  mlir_c_runner_utils_static
-  ${LLVM_PTHREAD_LIB}
-)

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-and.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-and.mlir
index 8df20401cfba..617097e2977a 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-and.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-and.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext
 \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-max.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-max.mlir
index 66a35e25988f..4d082498ee1f 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-max.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-max.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext
 \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-min.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce-min.mlir
index 7f7bf6921c85..43a782e64287 100644
--- a/mlir/test/mlir-cuda-runner/all-reduce-min.mlir
+++ b/mlir/test/mlir-cuda-runner/all-reduce-min.mlir
@@ -1,5 +1,5 @@
 // RUN: mlir-cuda-runner %s \
-// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext \
+// RUN:   
--shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext
 \
 // RUN:   --entry-point-result=void \
 // RUN: | FileCheck %s
 

diff  --git a/mlir/test/mlir-cuda-runner/all-reduce-op.mlir 
b/mlir/test/mlir-cuda-runner/all-reduce

[llvm-branch-commits] [mlir] badc760 - [mlir] Remove a number of methods from mlir::OpState that just forward to mlir::Operation. All call sites have been converted in previous changes.

2021-01-06 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-06T21:36:38+01:00
New Revision: badc7606b0f622f06efc466c86fecc8b45a165fd

URL: 
https://github.com/llvm/llvm-project/commit/badc7606b0f622f06efc466c86fecc8b45a165fd
DIFF: 
https://github.com/llvm/llvm-project/commit/badc7606b0f622f06efc466c86fecc8b45a165fd.diff

LOG: [mlir] Remove a number of methods from mlir::OpState that just forward to 
mlir::Operation. All call sites have been converted in previous changes.

Added: 


Modified: 
mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp

Removed: 




diff  --git a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp 
b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
index 8721e6b96ed7..896fc411bcdd 100644
--- a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
+++ b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
@@ -334,7 +334,7 @@ class AffineYieldOpLowering : public 
OpRewritePattern {
 
   LogicalResult matchAndRewrite(AffineYieldOp op,
 PatternRewriter &rewriter) const override {
-if (isa(op.getParentOp())) {
+if (isa(op->getParentOp())) {
   // scf.parallel does not yield any values via its terminator scf.yield 
but
   // models reductions 
diff erently using additional ops in its region.
   rewriter.replaceOpWithNewOp(op);

diff  --git a/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp 
b/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp
index 4477eb1eda6d..a8851832d881 100644
--- a/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp
+++ b/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp
@@ -49,7 +49,7 @@ void ReportShapeFnPass::runOnOperation() {
 
   // Lookup shape function library.
   SmallVector libraries;
-  auto attr = module.getAttr("shape.lib");
+  auto attr = module->getAttr("shape.lib");
   if (attr) {
 auto lookup = [&](Attribute attr) {
   return cast(



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] c3529a5 - [mlir] Mark methods from mlir::OpState that just forward to mlir::Operation as deprecated.

2021-01-07 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-07T09:08:47+01:00
New Revision: c3529a5b0806843e75f0b6d9a83bb36de70b5ae6

URL: 
https://github.com/llvm/llvm-project/commit/c3529a5b0806843e75f0b6d9a83bb36de70b5ae6
DIFF: 
https://github.com/llvm/llvm-project/commit/c3529a5b0806843e75f0b6d9a83bb36de70b5ae6.diff

LOG: [mlir] Mark methods from mlir::OpState that just forward to 
mlir::Operation as deprecated.

The functions will be removed by January 20th.

All call sites within MLIR have been converted in previous changes.

Reviewed By: rriddle

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

Added: 


Modified: 
mlir/include/mlir/IR/OpDefinition.h
mlir/lib/IR/Operation.cpp

Removed: 




diff  --git a/mlir/include/mlir/IR/OpDefinition.h 
b/mlir/include/mlir/IR/OpDefinition.h
index 11dc4b77b677..e698ced314a1 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -105,26 +105,32 @@ class OpState {
   Operation *getOperation() { return state; }
 
   /// Return the dialect that this refers to.
-  Dialect *getDialect() { return getOperation()->getDialect(); }
+  LLVM_ATTRIBUTE_DEPRECATED(
+  Dialect *getDialect(),
+  "Use Operation::getDialect() instead (replace '.' with '->').");
 
   /// Return the parent Region of this operation.
-  Region *getParentRegion() { return getOperation()->getParentRegion(); }
+  LLVM_ATTRIBUTE_DEPRECATED(
+  Region *getParentRegion(),
+  "Use Operation::getParentRegion() instead (replace '.' with '->').");
 
   /// Returns the closest surrounding operation that contains this operation
   /// or nullptr if this is a top-level operation.
-  Operation *getParentOp() { return getOperation()->getParentOp(); }
+  LLVM_ATTRIBUTE_DEPRECATED(
+  Operation *getParentOp(),
+  "Use Operation::getParentOp() instead (replace '.' with '->').");
 
   /// Return the closest surrounding parent operation that is of type 'OpTy'.
   template 
-  OpTy getParentOfType() {
-return getOperation()->getParentOfType();
-  }
+  LLVM_ATTRIBUTE_DEPRECATED(
+  OpTy getParentOfType(),
+  "Use Operation::getParentOfType() instead (replace '.' with '->').");
 
   /// Returns the closest surrounding parent operation with trait `Trait`.
   template  class Trait>
-  Operation *getParentWithTrait() {
-return getOperation()->getParentWithTrait();
-  }
+  LLVM_ATTRIBUTE_DEPRECATED(
+  Operation *getParentWithTrait(),
+  "Use Operation::getParentWithTrait() instead (replace '.' with '->').");
 
   /// Return the context this operation belongs to.
   MLIRContext *getContext() { return getOperation()->getContext(); }
@@ -153,35 +159,43 @@ class OpState {
   using dialect_attr_range = Operation::dialect_attr_range;
 
   /// Return a range corresponding to the dialect attributes for this 
operation.
-  dialect_attr_range getDialectAttrs() { return state->getDialectAttrs(); }
-  dialect_attr_iterator dialect_attr_begin() {
-return state->dialect_attr_begin();
-  }
-  dialect_attr_iterator dialect_attr_end() { return state->dialect_attr_end(); 
}
+  LLVM_ATTRIBUTE_DEPRECATED(
+  dialect_attr_range getDialectAttrs(),
+  "Use Operation::getDialectAttrs() instead (replace '.' with '->').");
+  LLVM_ATTRIBUTE_DEPRECATED(
+  dialect_attr_iterator dialect_attr_begin(),
+  "Use Operation::dialect_attr_begin() instead (replace '.' with '->').");
+  LLVM_ATTRIBUTE_DEPRECATED(
+  dialect_attr_iterator dialect_attr_end(),
+  "Use Operation::dialect_attr_end() instead (replace '.' with '->').");
 
   /// Return an attribute with the specified name.
-  Attribute getAttr(StringRef name) { return state->getAttr(name); }
+  LLVM_ATTRIBUTE_DEPRECATED(
+  Attribute getAttr(StringRef name),
+  "Use Operation::getAttr() instead (replace '.' with '->').");
 
   /// If the operation has an attribute of the specified type, return it.
   template 
-  AttrClass getAttrOfType(StringRef name) {
-return getAttr(name).dyn_cast_or_null();
-  }
+  LLVM_ATTRIBUTE_DEPRECATED(
+  AttrClass getAttrOfType(StringRef name),
+  "Use Operation::getAttrOfType() instead (replace '.' with '->').");
 
   /// If the an attribute exists with the specified name, change it to the new
   /// value.  Otherwise, add a new attribute with the specified name/value.
-  void setAttr(Identifier name, Attribute value) {
-state->setAttr(name, value);
-  }
-  void setAttr(StringRef name, Attribute value) {
-setAttr(Identifier::get(name, getContext()), value);
-  }
+  LLVM_ATTRIBUTE_DEPRECATED(
+  void setAttr(Identifier name, Attribute value),
+  "Use Operation::setAttr() instead (replace '.' with '->').");
+  LLVM_ATTRIBUTE_DEPRECATED(
+  void setAttr(StringRef name, Attribute value),
+  "Use Operation::setAttr() instead (replace '.' with '->').");
 
   /// Set the attributes held by this operation.
-  void setAttrs(ArrayRef attributes) {
-

[llvm-branch-commits] [mlir] 2fe625e - Fix two pessimizing moves.

2021-01-08 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-08T11:44:29+01:00
New Revision: 2fe625e9abd037b8721977e9736c822ef872487f

URL: 
https://github.com/llvm/llvm-project/commit/2fe625e9abd037b8721977e9736c822ef872487f
DIFF: 
https://github.com/llvm/llvm-project/commit/2fe625e9abd037b8721977e9736c822ef872487f.diff

LOG: Fix two pessimizing moves.

See 
https://en.cppreference.com/w/cpp/language/return#Automatic_move_from_local_variables_and_parameters

Reviewed By: rriddle

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

Added: 


Modified: 
llvm/include/llvm/Support/TaskQueue.h
mlir/include/mlir/Parser.h

Removed: 




diff  --git a/llvm/include/llvm/Support/TaskQueue.h 
b/llvm/include/llvm/Support/TaskQueue.h
index 4ceb056391af..6901a550b62f 100644
--- a/llvm/include/llvm/Support/TaskQueue.h
+++ b/llvm/include/llvm/Support/TaskQueue.h
@@ -98,7 +98,7 @@ class TaskQueue {
 IsTaskInFlight = true;
   }
 }
-return std::move(F);
+return F;
   }
 
 private:

diff  --git a/mlir/include/mlir/Parser.h b/mlir/include/mlir/Parser.h
index b9e4d170a044..cec60474d23d 100644
--- a/mlir/include/mlir/Parser.h
+++ b/mlir/include/mlir/Parser.h
@@ -67,7 +67,7 @@ inline OwningOpRef 
constructContainerOpForParserIfNecessary(
   // contain the operations inside of it.
   if (failed(op.verify()))
 return OwningOpRef();
-  return std::move(opRef);
+  return opRef;
 }
 } // end namespace detail
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 4fe7b16 - [mlir] Remove unnecessary llvm.mlir.cast in AsyncToLLVM lowering.

2021-01-11 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-11T14:41:07+01:00
New Revision: 4fe7b16ae3f48a36967e58ab753381cb34295962

URL: 
https://github.com/llvm/llvm-project/commit/4fe7b16ae3f48a36967e58ab753381cb34295962
DIFF: 
https://github.com/llvm/llvm-project/commit/4fe7b16ae3f48a36967e58ab753381cb34295962.diff

LOG: [mlir] Remove unnecessary llvm.mlir.cast in AsyncToLLVM lowering.

Reviewed By: ftynse

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

Added: 


Modified: 
mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp

Removed: 




diff  --git a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp 
b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
index 92b01cea6fca..488432722959 100644
--- a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
+++ b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
@@ -945,13 +945,7 @@ class AwaitValueOpLowering : public 
AwaitOpLoweringBase {
 loc, LLVM::LLVMPointerType::get(llvmValueType), storage.getResult(0));
 
 // Load from the async value storage.
-auto loaded = rewriter.create(loc, 
castedStorage.getResult());
-
-// Cast from LLVM type to the expected value type if necessary. This cast
-// will become no-op after lowering to LLVM.
-if (valueType == loaded.getType())
-  return loaded;
-return rewriter.create(loc, valueType, loaded);
+return rewriter.create(loc, castedStorage.getResult());
   }
 };
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 4c372a3 - [mlir] Make GpuAsyncRegion pass depend on async dialect.

2021-01-11 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-11T14:43:07+01:00
New Revision: 4c372a35cd892c0847da45540057447633a31d99

URL: 
https://github.com/llvm/llvm-project/commit/4c372a35cd892c0847da45540057447633a31d99
DIFF: 
https://github.com/llvm/llvm-project/commit/4c372a35cd892c0847da45540057447633a31d99.diff

LOG: [mlir] Make GpuAsyncRegion pass depend on async dialect.

Do not cache gpu.async.token type so that the pass can be created before the 
GPU dialect is registered.

Reviewed By: ftynse

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

Added: 


Modified: 
mlir/include/mlir/Dialect/GPU/Passes.td
mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
mlir/lib/Dialect/GPU/Transforms/PassDetail.h

Removed: 




diff  --git a/mlir/include/mlir/Dialect/GPU/Passes.td 
b/mlir/include/mlir/Dialect/GPU/Passes.td
index b9a83f7ef534..da1899c325fc 100644
--- a/mlir/include/mlir/Dialect/GPU/Passes.td
+++ b/mlir/include/mlir/Dialect/GPU/Passes.td
@@ -19,6 +19,7 @@ def GpuKernelOutlining : Pass<"gpu-kernel-outlining", 
"ModuleOp"> {
 def GpuAsyncRegionPass : FunctionPass<"gpu-async-region"> {
   let summary = "Make GPU ops async";
   let constructor = "mlir::createGpuAsyncRegionPass()";
+  let dependentDialects = ["async::AsyncDialect"];
 }
 
 #endif // MLIR_DIALECT_GPU_PASSES

diff  --git a/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp 
b/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
index 4f0eefb05931..37e0b9373d42 100644
--- a/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
@@ -78,6 +78,8 @@ struct GpuAsyncRegionPass::ThreadTokenCallback {
 if (op->getNumRegions() > 0)
   return op->emitOpError("regions are not supported");
 
+auto tokenType = builder.getType();
+
 // If there is no current token, insert a `gpu.wait async` without
 // dependencies to create one.
 if (!currentToken)
@@ -108,7 +110,7 @@ struct GpuAsyncRegionPass::ThreadTokenCallback {
   }
 
   OpBuilder builder;
-  const Type tokenType = builder.getType();
+
   // The token that represents the current asynchronous dependency. It's valid
   // range starts with a `gpu.wait async` op, and ends with a `gpu.wait` op.
   // In between, each gpu::AsyncOpInterface depends on the current token and

diff  --git a/mlir/lib/Dialect/GPU/Transforms/PassDetail.h 
b/mlir/lib/Dialect/GPU/Transforms/PassDetail.h
index 2e6fb9217189..c83ac3035a40 100644
--- a/mlir/lib/Dialect/GPU/Transforms/PassDetail.h
+++ b/mlir/lib/Dialect/GPU/Transforms/PassDetail.h
@@ -9,6 +9,7 @@
 #ifndef DIALECT_GPU_TRANSFORMS_PASSDETAIL_H_
 #define DIALECT_GPU_TRANSFORMS_PASSDETAIL_H_
 
+#include "mlir/Dialect/Async/IR/Async.h"
 #include "mlir/Pass/Pass.h"
 
 namespace mlir {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] d59ddba - [mlir] Fix gpu-to-llvm lowering for gpu.alloc with dynamic sizes.

2021-01-11 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-11T15:55:48+01:00
New Revision: d59ddba777251c59a667d03021900c72f9882a4b

URL: 
https://github.com/llvm/llvm-project/commit/d59ddba777251c59a667d03021900c72f9882a4b
DIFF: 
https://github.com/llvm/llvm-project/commit/d59ddba777251c59a667d03021900c72f9882a4b.diff

LOG: [mlir] Fix gpu-to-llvm lowering for gpu.alloc with dynamic sizes.

Reviewed By: ftynse

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

Added: 


Modified: 
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/test/Conversion/GPUCommon/lower-alloc-to-gpu-runtime-calls.mlir

Removed: 




diff  --git 
a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h 
b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index 82cf7e772afe..357bd2f021b1 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -533,7 +533,7 @@ class ConvertToLLVMPattern : public ConversionPattern {
   ///  : (!llvm.ptr, i64) -> !llvm.ptr
   /// `sizeBytes`  = llvm.ptrtoint %gep : !llvm.ptr to i64
   void getMemRefDescriptorSizes(Location loc, MemRefType memRefType,
-ArrayRef dynamicSizes,
+ValueRange dynamicSizes,
 ConversionPatternRewriter &rewriter,
 SmallVectorImpl &sizes,
 SmallVectorImpl &strides,

diff  --git a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp 
b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
index 8c89b6d20099..cee1d7ba20e3 100644
--- a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
+++ b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
@@ -373,19 +373,19 @@ LogicalResult 
ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite(
 return failure();
 
   auto loc = allocOp.getLoc();
+  auto adaptor = gpu::AllocOpAdaptor(operands, allocOp->getAttrDictionary());
 
   // Get shape of the memref as values: static sizes are constant
   // values and dynamic sizes are passed to 'alloc' as operands.
   SmallVector shape;
   SmallVector strides;
   Value sizeBytes;
-  getMemRefDescriptorSizes(loc, memRefType, operands, rewriter, shape, strides,
-   sizeBytes);
+  getMemRefDescriptorSizes(loc, memRefType, adaptor.dynamicSizes(), rewriter,
+   shape, strides, sizeBytes);
 
   // Allocate the underlying buffer and store a pointer to it in the MemRef
   // descriptor.
   Type elementPtrType = this->getElementPtrType(memRefType);
-  auto adaptor = gpu::AllocOpAdaptor(operands, allocOp->getAttrDictionary());
   auto stream = adaptor.asyncDependencies().front();
   Value allocatedPtr =
   allocCallBuilder.create(loc, rewriter, {sizeBytes, stream}).getResult(0);

diff  --git a/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp 
b/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp
index 0978e8cf756a..604b4576fc1b 100644
--- a/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp
+++ b/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp
@@ -212,8 +212,8 @@ class GPULaunchLowering : public 
ConvertOpToLLVMPattern {
   SmallVector sizes;
   SmallVector strides;
   Value sizeBytes;
-  getMemRefDescriptorSizes(loc, memRefType, operand.value(), rewriter,
-   sizes, strides, sizeBytes);
+  getMemRefDescriptorSizes(loc, memRefType, {}, rewriter, sizes, strides,
+   sizeBytes);
   MemRefDescriptor descriptor(operand.value());
   Value src = descriptor.allocatedPtr(rewriter, loc);
 

diff  --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp 
b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
index 53ebd6721863..512273347e4b 100644
--- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
@@ -1083,11 +1083,14 @@ Type ConvertToLLVMPattern::getElementPtrType(MemRefType 
type) const {
 }
 
 void ConvertToLLVMPattern::getMemRefDescriptorSizes(
-Location loc, MemRefType memRefType, ArrayRef dynamicSizes,
+Location loc, MemRefType memRefType, ValueRange dynamicSizes,
 ConversionPatternRewriter &rewriter, SmallVectorImpl &sizes,
 SmallVectorImpl &strides, Value &sizeBytes) const {
   assert(isConvertibleAndHasIdentityMaps(memRefType) &&
  "layout maps must have been normalized away");
+  assert(count(memRefType.getShape(), ShapedType::kDynamicSize) ==
+ static_cast

[llvm-branch-commits] [mlir] 195728c - [mlir] Add structural conversion to async dialect lowering.

2021-01-11 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-11T20:36:49+01:00
New Revision: 195728c75aa41d80254175c5d7ac2f881333b139

URL: 
https://github.com/llvm/llvm-project/commit/195728c75aa41d80254175c5d7ac2f881333b139
DIFF: 
https://github.com/llvm/llvm-project/commit/195728c75aa41d80254175c5d7ac2f881333b139.diff

LOG: [mlir] Add structural conversion to async dialect lowering.

Lowering of async dialect uses a fixed type converter and therefore does not 
support lowering non-standard types.

This revision adds a structural conversion so that non-standard types in 
`!async.value`s can be lowered to LLVM before lowering the async dialect itself.

Reviewed By: ezhulenev

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

Added: 


Modified: 
mlir/include/mlir/Conversion/AsyncToLLVM/AsyncToLLVM.h
mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp

Removed: 




diff  --git a/mlir/include/mlir/Conversion/AsyncToLLVM/AsyncToLLVM.h 
b/mlir/include/mlir/Conversion/AsyncToLLVM/AsyncToLLVM.h
index abb5d216028f..938c5cbbebce 100644
--- a/mlir/include/mlir/Conversion/AsyncToLLVM/AsyncToLLVM.h
+++ b/mlir/include/mlir/Conversion/AsyncToLLVM/AsyncToLLVM.h
@@ -13,13 +13,29 @@
 
 namespace mlir {
 
+class ConversionTarget;
 class ModuleOp;
 template 
 class OperationPass;
+class MLIRContext;
+class OwningRewritePatternList;
+class TypeConverter;
 
 /// Create a pass to convert Async operations to the LLVM dialect.
 std::unique_ptr> createConvertAsyncToLLVMPass();
 
+/// Populates patterns for async structural type conversions.
+///
+/// A "structural" type conversion is one where the underlying ops are
+/// completely agnostic to the actual types involved and simply need to update
+/// their types. An example of this is async.execute -- the async.execute op 
and
+/// the corresponding async.yield ops need to update their types accordingly to
+/// the TypeConverter, but otherwise don't care what type conversions are
+/// happening.
+void populateAsyncStructuralTypeConversionsAndLegality(
+MLIRContext *context, TypeConverter &typeConverter,
+OwningRewritePatternList &patterns, ConversionTarget &target);
+
 } // namespace mlir
 
 #endif // MLIR_CONVERSION_ASYNCTOLLVM_ASYNCTOLLVM_H

diff  --git a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp 
b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
index 488432722959..587f49754446 100644
--- a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
+++ b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
@@ -1132,6 +1132,71 @@ void ConvertAsyncToLLVMPass::runOnOperation() {
 }
 } // namespace
 
+namespace {
+class ConvertExecuteOpTypes : public OpConversionPattern {
+public:
+  using OpConversionPattern::OpConversionPattern;
+  LogicalResult
+  matchAndRewrite(ExecuteOp op, ArrayRef operands,
+  ConversionPatternRewriter &rewriter) const override {
+ExecuteOp newOp =
+cast(rewriter.cloneWithoutRegions(*op.getOperation()));
+rewriter.inlineRegionBefore(op.getRegion(), newOp.getRegion(),
+newOp.getRegion().end());
+
+// Set operands and update block argument and result types.
+newOp->setOperands(operands);
+if (failed(rewriter.convertRegionTypes(&newOp.getRegion(), 
*typeConverter)))
+  return failure();
+for (auto result : newOp.getResults())
+  result.setType(typeConverter->convertType(result.getType()));
+
+rewriter.replaceOp(op, newOp.getResults());
+return success();
+  }
+};
+
+// Dummy pattern to trigger the appropriate type conversion / materialization.
+class ConvertAwaitOpTypes : public OpConversionPattern {
+public:
+  using OpConversionPattern::OpConversionPattern;
+  LogicalResult
+  matchAndRewrite(AwaitOp op, ArrayRef operands,
+  ConversionPatternRewriter &rewriter) const override {
+rewriter.replaceOpWithNewOp(op, operands.front());
+return success();
+  }
+};
+
+// Dummy pattern to trigger the appropriate type conversion / materialization.
+class ConvertYieldOpTypes : public OpConversionPattern {
+public:
+  using OpConversionPattern::OpConversionPattern;
+  LogicalResult
+  matchAndRewrite(async::YieldOp op, ArrayRef operands,
+  ConversionPatternRewriter &rewriter) const override {
+rewriter.replaceOpWithNewOp(op, operands);
+return success();
+  }
+};
+} // namespace
+
 std::unique_ptr> mlir::createConvertAsyncToLLVMPass() {
   return std::make_unique();
 }
+
+void mlir::populateAsyncStructuralTypeConversionsAndLegality(
+MLIRContext *context, TypeConverter &typeConverter,
+OwningRewritePatternList &patterns, ConversionTarget &target) {
+  typeConverter.addConversion([&](TokenType type) { return type; });
+  typeConverter.addConversion([&](ValueType type) {
+return ValueType::get(typeConverter.convertType(type.getValueType()));
+  });
+
+  patterns
+  .insert(
+  typeConverter, context);
+
+  target.addDynamicallyLegal

[llvm-branch-commits] [llvm] ace516f - Change the LLVM_ATTRIBUTE_DEPRECATED macro to use C++14 attribute.

2021-01-12 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2021-01-12T12:41:00+01:00
New Revision: ace516fb33d1f3de85f046e96efc1048b4ee8c08

URL: 
https://github.com/llvm/llvm-project/commit/ace516fb33d1f3de85f046e96efc1048b4ee8c08
DIFF: 
https://github.com/llvm/llvm-project/commit/ace516fb33d1f3de85f046e96efc1048b4ee8c08.diff

LOG: Change the LLVM_ATTRIBUTE_DEPRECATED macro to use C++14 attribute.

C++14 attributes are superior because they can be applied to functions with 
inline definition and the syntax is cleaner.

I intend to convert all uses and then remove the macro.

One issue that might hold back switching uses to C++14  attributes is that
clang-format does not put long attributes on separate lines and formatted code 
will look like:

```
template 
[[deprecated("blah blah")]] void
f() {
  ...
}
```

Putting long attributes on a separate line would be prettier.
See 
https://stackoverflow.com/questions/45740466/clang-format-setting-to-control-c-attributes

AttributeMacros probably won't help because it can't match the custom message.
https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Reviewed By: rriddle, MaskRay

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

Added: 


Modified: 
llvm/include/llvm/Support/Compiler.h

Removed: 




diff  --git a/llvm/include/llvm/Support/Compiler.h 
b/llvm/include/llvm/Support/Compiler.h
index a9e4f7f8353d..9348ada91325 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -314,19 +314,9 @@
 #endif
 
 // LLVM_ATTRIBUTE_DEPRECATED(decl, "message")
-#if __has_feature(attribute_deprecated_with_message)
-# define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
-  decl __attribute__((deprecated(message)))
-#elif defined(__GNUC__)
-# define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
-  decl __attribute__((deprecated))
-#elif defined(_MSC_VER)
-# define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
-  __declspec(deprecated(message)) decl
-#else
-# define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
-  decl
-#endif
+// This macro will be removed.
+// Use C++14's attribute instead: [[deprecated("message")]]
+#define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl
 
 /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
 /// to an expression which states that it is undefined behavior for the



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] a1eb154 - [flang] Use mlir::OpState::operator->() to get to methods of mlir::Operation.

2020-12-14 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-14T20:04:53+01:00
New Revision: a1eb154421a00d62f3a25057d262e1cac747e266

URL: 
https://github.com/llvm/llvm-project/commit/a1eb154421a00d62f3a25057d262e1cac747e266
DIFF: 
https://github.com/llvm/llvm-project/commit/a1eb154421a00d62f3a25057d262e1cac747e266.diff

LOG: [flang] Use mlir::OpState::operator->() to get to methods of 
mlir::Operation.

This is a preparation step to remove those methods from OpState.

Reviewed By: ftynse

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

Added: 


Modified: 
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
flang/lib/Lower/CharacterRuntime.cpp
flang/lib/Lower/IO.cpp
flang/lib/Lower/IntrinsicCall.cpp
flang/lib/Lower/OpenACC.cpp
flang/lib/Optimizer/Dialect/FIROps.cpp
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/test/mlir-tblgen/op-attribute.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/unittests/Pass/PassManagerTest.cpp

Removed: 




diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.td 
b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 4ffca0395804..8d7a6d4af950 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -249,7 +249,7 @@ class fir_AllocatableOp 
traits = []> :
   }];
 
   let printer = [{
-p << getOperationName() << ' ' << getAttr(inType());
+p << getOperationName() << ' ' << (*this)->getAttr(inType());
 if (hasLenParams()) {
   // print the LEN parameters to a derived type in parens
   p << '(' << getLenParams() << " : " << getLenParams().getTypes() << ')';
@@ -267,7 +267,7 @@ class fir_AllocatableOp 
traits = []> :
 static constexpr llvm::StringRef lenpName() { return "len_param_count"; }
 mlir::Type getAllocatedType();
 
-bool hasLenParams() { return bool{getAttr(lenpName())}; }
+bool hasLenParams() { return bool{(*this)->getAttr(lenpName())}; }
 
 unsigned numLenParams() {
   if (auto val = (*this)->getAttrOfType(lenpName()))
@@ -688,7 +688,7 @@ class fir_IntegralSwitchTerminatorOp(getCasesAttr()).getValue();
+auto cases = 
(*this)->getAttrOfType(getCasesAttr()).getValue();
 auto count = getNumConditions();
 for (decltype(count) i = 0; i != count; ++i) {
   if (i)
@@ -711,7 +711,7 @@ class fir_IntegralSwitchTerminatorOp() ||
   getSelector().getType().isa()))
   return emitOpError("must be an integer");
-auto cases = getAttrOfType(getCasesAttr()).getValue();
+auto cases = 
(*this)->getAttrOfType(getCasesAttr()).getValue();
 auto count = getNumDest();
 if (count == 0)
   return emitOpError("must have at least one successor");
@@ -810,7 +810,7 @@ def fir_SelectCaseOp : 
fir_SwitchTerminatorOp<"select_case"> {
 p << getOperationName() << ' ';
 p.printOperand(getSelector());
 p << " : " << getSelector().getType() << " [";
-auto cases = getAttrOfType(getCasesAttr()).getValue();
+auto cases = 
(*this)->getAttrOfType(getCasesAttr()).getValue();
 auto count = getNumConditions();
 for (decltype(count) i = 0; i != count; ++i) {
   if (i)
@@ -839,7 +839,7 @@ def fir_SelectCaseOp : 
fir_SwitchTerminatorOp<"select_case"> {
   getSelector().getType().isa() ||
   getSelector().getType().isa()))
   return emitOpError("must be an integer, character, or logical");
-auto cases = getAttrOfType(getCasesAttr()).getValue();
+auto cases = 
(*this)->getAttrOfType(getCasesAttr()).getValue();
 auto count = getNumDest();
 if (count == 0)
   return emitOpError("must have at least one successor");
@@ -925,7 +925,7 @@ def fir_SelectTypeOp : 
fir_SwitchTerminatorOp<"select_type"> {
 p << getOperationName() << ' ';
 p.printOperand(getSelector());
 p << " : " << getSelector().getType() << " [";
-auto cases = getAttrOfType(getCasesAttr()).getValue();
+auto cases = 
(*this)->getAttrOfType(getCasesAttr()).getValue();
 auto count = getNumConditions();
 for (decltype(count) i = 0; i != count; ++i) {
   if (i)
@@ -941,7 +941,7 @@ def fir_SelectTypeOp : 
fir_SwitchTerminatorOp<"select_type"> {
   let verifier = [{
 if (!(getSelector().getType().isa()))
   return emitOpError("must be a boxed type");
-auto cases = getAttrOfType(getCasesAttr()).getValue();
+auto cases = 
(*this)->getAttrOfType(getCasesAttr()).getValue();
 auto count = getNumDest();
 if (count == 0)
   return emitOpError("must have at least one successor");
@@ -1056,7 +1056,7 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
 if (getNumOperands() == 2) {
   p << ", ";
   p.printOperands(dims());
-} else if (auto map = getAttr(layoutName())) {
+} else if (auto map = (*this)->getAttr(layoutName())) {
   p << " [" << map << ']';
 }
 p.printOptionalAttrDic

[llvm-branch-commits] [mlir] 6f271e9 - [mlir] Remove methods from mlir::OpState that just forward to mlir::Operation.

2020-12-14 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-14T21:26:14+01:00
New Revision: 6f271e921ba48f4c4fa54bbd2c7a4c548ca5e59e

URL: 
https://github.com/llvm/llvm-project/commit/6f271e921ba48f4c4fa54bbd2c7a4c548ca5e59e
DIFF: 
https://github.com/llvm/llvm-project/commit/6f271e921ba48f4c4fa54bbd2c7a4c548ca5e59e.diff

LOG: [mlir] Remove methods from mlir::OpState that just forward to 
mlir::Operation.

All call sites have been converted in previous changes.

Reviewed By: mehdi_amini

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

Added: 


Modified: 
mlir/include/mlir/IR/OpDefinition.h

Removed: 




diff  --git a/mlir/include/mlir/IR/OpDefinition.h 
b/mlir/include/mlir/IR/OpDefinition.h
index b200f7c2dc6c..2edc48dd099e 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -108,27 +108,6 @@ class OpState {
   /// Return the operation that this refers to.
   Operation *getOperation() { return state; }
 
-  /// Return the dialect that this refers to.
-  Dialect *getDialect() { return getOperation()->getDialect(); }
-
-  /// Return the parent Region of this operation.
-  Region *getParentRegion() { return getOperation()->getParentRegion(); }
-
-  /// Returns the closest surrounding operation that contains this operation
-  /// or nullptr if this is a top-level operation.
-  Operation *getParentOp() { return getOperation()->getParentOp(); }
-
-  /// Return the closest surrounding parent operation that is of type 'OpTy'.
-  template  OpTy getParentOfType() {
-return getOperation()->getParentOfType();
-  }
-
-  /// Returns the closest surrounding parent operation with trait `Trait`.
-  template  class Trait>
-  Operation *getParentWithTrait() {
-return getOperation()->getParentWithTrait();
-  }
-
   /// Return the context this operation belongs to.
   MLIRContext *getContext() { return getOperation()->getContext(); }
 
@@ -155,36 +134,6 @@ class OpState {
   using dialect_attr_iterator = Operation::dialect_attr_iterator;
   using dialect_attr_range = Operation::dialect_attr_range;
 
-  /// Return a range corresponding to the dialect attributes for this 
operation.
-  dialect_attr_range getDialectAttrs() { return state->getDialectAttrs(); }
-  dialect_attr_iterator dialect_attr_begin() {
-return state->dialect_attr_begin();
-  }
-  dialect_attr_iterator dialect_attr_end() { return state->dialect_attr_end(); 
}
-
-  /// Return an attribute with the specified name.
-  Attribute getAttr(StringRef name) { return state->getAttr(name); }
-
-  /// If the operation has an attribute of the specified type, return it.
-  template  AttrClass getAttrOfType(StringRef name) {
-return getAttr(name).dyn_cast_or_null();
-  }
-
-  /// If the an attribute exists with the specified name, change it to the new
-  /// value.  Otherwise, add a new attribute with the specified name/value.
-  void setAttr(Identifier name, Attribute value) {
-state->setAttr(name, value);
-  }
-  void setAttr(StringRef name, Attribute value) {
-setAttr(Identifier::get(name, getContext()), value);
-  }
-
-  /// Set the attributes held by this operation.
-  void setAttrs(ArrayRef attributes) {
-state->setAttrs(attributes);
-  }
-  void setAttrs(MutableDictionaryAttr newAttrs) { state->setAttrs(newAttrs); }
-
   /// Set the dialect attributes for this operation, and preserve all 
dependent.
   template  void setDialectAttrs(DialectAttrs &&attrs) {
 state->setDialectAttrs(std::move(attrs));



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 0cf7e4b - Revert "[mlir] Remove methods from mlir::OpState that just forward to mlir::Operation."

2020-12-14 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-14T22:47:17+01:00
New Revision: 0cf7e4b252fe1458fddb8e3dbfcae43450e9c04c

URL: 
https://github.com/llvm/llvm-project/commit/0cf7e4b252fe1458fddb8e3dbfcae43450e9c04c
DIFF: 
https://github.com/llvm/llvm-project/commit/0cf7e4b252fe1458fddb8e3dbfcae43450e9c04c.diff

LOG: Revert "[mlir] Remove methods from mlir::OpState that just forward to 
mlir::Operation."

This reverts commit 6f271e921ba48f4c4fa54bbd2c7a4c548ca5e59e.

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

Added: 


Modified: 
mlir/include/mlir/IR/OpDefinition.h

Removed: 




diff  --git a/mlir/include/mlir/IR/OpDefinition.h 
b/mlir/include/mlir/IR/OpDefinition.h
index 2edc48dd099e..9e4da63c3618 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -108,6 +108,28 @@ class OpState {
   /// Return the operation that this refers to.
   Operation *getOperation() { return state; }
 
+  /// Return the dialect that this refers to.
+  Dialect *getDialect() { return getOperation()->getDialect(); }
+
+  /// Return the parent Region of this operation.
+  Region *getParentRegion() { return getOperation()->getParentRegion(); }
+
+  /// Returns the closest surrounding operation that contains this operation
+  /// or nullptr if this is a top-level operation.
+  Operation *getParentOp() { return getOperation()->getParentOp(); }
+
+  /// Return the closest surrounding parent operation that is of type 'OpTy'.
+  template 
+  OpTy getParentOfType() {
+return getOperation()->getParentOfType();
+  }
+
+  /// Returns the closest surrounding parent operation with trait `Trait`.
+  template  class Trait>
+  Operation *getParentWithTrait() {
+return getOperation()->getParentWithTrait();
+  }
+
   /// Return the context this operation belongs to.
   MLIRContext *getContext() { return getOperation()->getContext(); }
 
@@ -134,6 +156,37 @@ class OpState {
   using dialect_attr_iterator = Operation::dialect_attr_iterator;
   using dialect_attr_range = Operation::dialect_attr_range;
 
+  /// Return a range corresponding to the dialect attributes for this 
operation.
+  dialect_attr_range getDialectAttrs() { return state->getDialectAttrs(); }
+  dialect_attr_iterator dialect_attr_begin() {
+return state->dialect_attr_begin();
+  }
+  dialect_attr_iterator dialect_attr_end() { return state->dialect_attr_end(); 
}
+
+  /// Return an attribute with the specified name.
+  Attribute getAttr(StringRef name) { return state->getAttr(name); }
+
+  /// If the operation has an attribute of the specified type, return it.
+  template 
+  AttrClass getAttrOfType(StringRef name) {
+return getAttr(name).dyn_cast_or_null();
+  }
+
+  /// If the an attribute exists with the specified name, change it to the new
+  /// value.  Otherwise, add a new attribute with the specified name/value.
+  void setAttr(Identifier name, Attribute value) {
+state->setAttr(name, value);
+  }
+  void setAttr(StringRef name, Attribute value) {
+setAttr(Identifier::get(name, getContext()), value);
+  }
+
+  /// Set the attributes held by this operation.
+  void setAttrs(ArrayRef attributes) {
+state->setAttrs(attributes);
+  }
+  void setAttrs(MutableDictionaryAttr newAttrs) { state->setAttrs(newAttrs); }
+
   /// Set the dialect attributes for this operation, and preserve all 
dependent.
   template  void setDialectAttrs(DialectAttrs &&attrs) {
 state->setDialectAttrs(std::move(attrs));



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] a79b26d - [mlir] Fix for gpu-async-region pass.

2020-12-16 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-16T19:08:10+01:00
New Revision: a79b26db0e96b6f6dd7888053ea300cfc2feb5a8

URL: 
https://github.com/llvm/llvm-project/commit/a79b26db0e96b6f6dd7888053ea300cfc2feb5a8
DIFF: 
https://github.com/llvm/llvm-project/commit/a79b26db0e96b6f6dd7888053ea300cfc2feb5a8.diff

LOG: [mlir] Fix for gpu-async-region pass.

- the !gpu.async.token is the second result of 'gpu.alloc async', not the first.
- async.execute construction takes operand types not yet wrapped in 
!async.value.
- fix typo

Reviewed By: herhut

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

Added: 


Modified: 
mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
mlir/test/Dialect/GPU/async-region.mlir

Removed: 




diff  --git a/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp 
b/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
index eaa777c38060..c8378ae8977a 100644
--- a/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
@@ -85,18 +85,19 @@ struct GpuAsyncRegionPass::ThreadTokenCallback {
 asyncOp.addAsyncDependency(currentToken);
 
 // Clone the op to return a token in addition to the other results.
-SmallVector resultTypes = {tokenType};
+SmallVector resultTypes;
 resultTypes.reserve(1 + op->getNumResults());
 copy(op->getResultTypes(), std::back_inserter(resultTypes));
+resultTypes.push_back(tokenType);
 auto *newOp = Operation::create(op->getLoc(), op->getName(), resultTypes,
 op->getOperands(), 
op->getMutableAttrDict(),
 op->getSuccessors());
 
 // Replace the op with the async clone.
 auto results = newOp->getResults();
-currentToken = results.front();
+currentToken = results.back();
 builder.insert(newOp);
-op->replaceAllUsesWith(results.drop_front());
+op->replaceAllUsesWith(results.drop_back());
 op->erase();
 
 return success();
@@ -165,7 +166,14 @@ struct GpuAsyncRegionPass::DeferWaitCallback {
 // Construct new result type list with `count` additional types.
 SmallVector resultTypes;
 resultTypes.reserve(numResults);
-copy(executeOp.getResultTypes(), std::back_inserter(resultTypes));
+transform(executeOp.getResultTypes(), std::back_inserter(resultTypes),
+  [](Type type) {
+// Extract value type from !async.value.
+if (auto valueType = type.dyn_cast())
+  return valueType.getValueType();
+assert(type.isa() && "expected token type");
+return type;
+  });
 OpBuilder builder(executeOp);
 auto tokenType = builder.getType();
 resultTypes.resize(numResults, tokenType);
@@ -266,7 +274,7 @@ void GpuAsyncRegionPass::runOnFunction() {
   .wasInterrupted())
 return signalPassFailure();
 
-  // Collect gpu.wait ops that we can move out of gpu.execute regions.
+  // Collect gpu.wait ops that we can move out of async.execute regions.
   getFunction().getRegion().walk(DeferWaitCallback());
 }
 

diff  --git a/mlir/test/Dialect/GPU/async-region.mlir 
b/mlir/test/Dialect/GPU/async-region.mlir
index 2fc58cf02a09..216ccceda1f0 100644
--- a/mlir/test/Dialect/GPU/async-region.mlir
+++ b/mlir/test/Dialect/GPU/async-region.mlir
@@ -18,7 +18,11 @@ module attributes {gpu.container_module} {
 // CHECK: %[[t2:.*]] = gpu.launch_func async [%[[t1]]]
 gpu.launch_func @kernels::@kernel
 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz)
-// CHECK: gpu.wait [%[[t2]]]
+// CHECK: %[[m:.*]], %[[t3:.*]] = gpu.alloc async [%[[t2]]] ()
+%0 = gpu.alloc() : memref<7xf32>
+// CHECK: %[[t4:.*]] = gpu.dealloc async [%[[t3]]] %[[m]]
+gpu.dealloc %0 : memref<7xf32>
+// CHECK: gpu.wait [%[[t4]]]
 // CHECK: call @foo
 call @foo() : () -> ()
 return
@@ -98,4 +102,27 @@ module attributes {gpu.container_module} {
 async.await %a1 : !async.token
 return
   }
+
+ // CHECK-LABEL:func @async_execute_with_result(%{{.*}}: index)
+  func @async_execute_with_result(%sz : index) -> index {
+// CHECK: %[[a0:.*]], %[[f0:.*]]:2 = async.execute
+// CHECK-SAME: -> (!async.value, !async.value)
+%a0, %f0 = async.execute -> !async.value {
+  // CHECK: %[[t:.*]] = gpu.launch_func async
+  gpu.launch_func @kernels::@kernel
+  blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz)
+  // CHECK-NOT: gpu.wait
+  // CHECK: async.yield {{.*}}, %[[t]] : index, !gpu.async.token
+  async.yield %sz : index
+}
+
+// CHECK: async.await %[[a0]] : !async.token
+// CHECK: %[[t:.*]] = async.await %[[f0]]#1 : 
!async.value
+// CHECK: gpu.wait [%[[t]]]
+async.await %a0 : !async.token
+// CHECK: %[[x:.*]] = async.await %[[f0]]#0 : !async.value
+%x = async.await %f0 : !async.value
+// CHE

[llvm-branch-commits] [mlir] 58f2b76 - Fix NDEBUG build after https://reviews.llvm.org/D93005.

2020-12-17 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-17T20:38:21+01:00
New Revision: 58f2b765ebec45643f0b0d6737fb3dc339f75cde

URL: 
https://github.com/llvm/llvm-project/commit/58f2b765ebec45643f0b0d6737fb3dc339f75cde
DIFF: 
https://github.com/llvm/llvm-project/commit/58f2b765ebec45643f0b0d6737fb3dc339f75cde.diff

LOG: Fix NDEBUG build after https://reviews.llvm.org/D93005.

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

Added: 


Modified: 
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Removed: 




diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp 
b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index d9094f8763d9..8c650506e2d7 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -327,6 +327,7 @@ static Value getPHISourceValue(Block *current, Block *pred,
   assert(std::adjacent_find(successors.begin(), successors.end()) ==
  successors.end() &&
  "successors with arguments in LLVM branches must be 
diff erent blocks");
+  (void)successors;
 
   // For instructions that branch based on a condition value, we need to take
   // the operands for the branch that was taken.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 0955d8d - [mlir] Add gpu.memcpy op.

2020-12-22 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-22T17:39:55+01:00
New Revision: 0955d8df06355610bf539c53afd26bb62c500f44

URL: 
https://github.com/llvm/llvm-project/commit/0955d8df06355610bf539c53afd26bb62c500f44
DIFF: 
https://github.com/llvm/llvm-project/commit/0955d8df06355610bf539c53afd26bb62c500f44.diff

LOG: [mlir] Add gpu.memcpy op.

Reviewed By: herhut

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

Added: 


Modified: 
mlir/include/mlir/Dialect/GPU/GPUOps.td
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
mlir/test/Dialect/GPU/invalid.mlir
mlir/test/Dialect/GPU/ops.mlir

Removed: 




diff  --git a/mlir/include/mlir/Dialect/GPU/GPUOps.td 
b/mlir/include/mlir/Dialect/GPU/GPUOps.td
index 953a2d5c282c9..457477f7f3c1a 100644
--- a/mlir/include/mlir/Dialect/GPU/GPUOps.td
+++ b/mlir/include/mlir/Dialect/GPU/GPUOps.td
@@ -879,4 +879,39 @@ def GPU_DeallocOp : GPU_Op<"dealloc", [
   }];
 }
 
+def GPU_MemcpyOp : GPU_Op<"memcpy", [
+GPU_AsyncOpInterface, MemoryEffects<[MemRead, MemWrite]>
+  ]> {
+
+  let summary = "GPU memcpy operation";
+
+  let description = [{
+The `gpu.memcpy` operation copies the content of one memref to another.
+
+The op does not execute before all async dependencies have finished
+executing.
+
+If the `async` keyword is present, the op is executed asynchronously (i.e.
+it does not block until the execution has finished on the device). In
+that case, it returns a !gpu.async.token.
+
+Example:
+
+```mlir
+%token = gpu.memcpy async [%dep] %dst, %src : memref, 
memref
+```
+  }];
+
+  let arguments = (ins Variadic:$asyncDependencies,
+   Arg:$dst,
+   Arg:$src);
+  let results = (outs Optional:$asyncToken);
+
+  let assemblyFormat = [{
+custom(type($asyncToken), $asyncDependencies)
+$dst`,` $src `:` type($dst)`,` type($src) attr-dict
+  }];
+  let verifier = [{ return ::verify(*this); }];
+}
+
 #endif // GPU_OPS

diff  --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp 
b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index e8a90acf8830f..d3fa2ccb6dcd2 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -22,6 +22,7 @@
 #include "mlir/IR/FunctionImplementation.h"
 #include "mlir/IR/OpImplementation.h"
 #include "mlir/IR/PatternMatch.h"
+#include "mlir/IR/TypeUtilities.h"
 #include "llvm/ADT/TypeSwitch.h"
 
 using namespace mlir;
@@ -842,6 +843,23 @@ static void print(OpAsmPrinter &p, GPUModuleOp op) {
 /*printBlockTerminators=*/false);
 }
 
+//===--===//
+// GPUMemcpyOp
+//===--===//
+
+static LogicalResult verify(MemcpyOp op) {
+  auto srcType = op.src().getType();
+  auto dstType = op.dst().getType();
+
+  if (getElementTypeOrSelf(srcType) != getElementTypeOrSelf(dstType))
+return op.emitOpError("arguments have incompatible element type");
+
+  if (failed(verifyCompatibleShape(srcType, dstType)))
+return op.emitOpError("arguments have incompatible shape");
+
+  return success();
+}
+
 static ParseResult parseAsyncDependencies(
 OpAsmParser &parser, Type &asyncTokenType,
 SmallVectorImpl &asyncDependencies) {

diff  --git a/mlir/test/Dialect/GPU/invalid.mlir 
b/mlir/test/Dialect/GPU/invalid.mlir
index 3dc5be405aac1..1f6058cde3974 100644
--- a/mlir/test/Dialect/GPU/invalid.mlir
+++ b/mlir/test/Dialect/GPU/invalid.mlir
@@ -444,3 +444,17 @@ func @async_wait_without_result() {
   // expected-error @+1 {{custom op 'gpu.wait' needs to be named when marked 
'async'}}
   gpu.wait async
 }
+
+// -
+
+func @memcpy_incompatible_type(%dst : memref, %src : memref) {
+  // expected-error @+1 {{'gpu.memcpy' op arguments have incompatible element 
type}}
+  gpu.memcpy %dst, %src  : memref, memref
+}
+
+// -
+
+func @memcpy_incompatible_shape(%dst : memref<7xf32>, %src : memref<9xf32>) {
+  // expected-error @+1 {{'gpu.memcpy' op arguments have incompatible shape}}
+  gpu.memcpy %dst, %src  : memref<7xf32>, memref<9xf32>
+}

diff  --git a/mlir/test/Dialect/GPU/ops.mlir b/mlir/test/Dialect/GPU/ops.mlir
index aed4368c22a71..5cea772ce5991 100644
--- a/mlir/test/Dialect/GPU/ops.mlir
+++ b/mlir/test/Dialect/GPU/ops.mlir
@@ -183,4 +183,15 @@ module attributes {gpu.container_module} {
 gpu.wait // Valid, but a no-op.
 return
   }
+
+  func @memcpy(%dst : memref<3x7xf32>, %src : memref<3x7xf32, 1>) {
+// CHECK-LABEL: func @memcpy
+// CHECK: gpu.memcpy {{.*}}, {{.*}} : memref<3x7xf32>, memref<3x7xf32, 1>
+gpu.memcpy %dst, %src : memref<3x7xf32>, memref<3x7xf32, 1>
+// CHECK: %[[t0:.*]] = gpu.wait async
+%0 = gpu.wait async
+// CHECK: {{.*}} = gpu.memcpy async [%[[t0]]] {{.*}}, {{.*}} : 
memref<3x7xf32>, memref<3x7xf32, 1>
+%1 = gpu.memcpy async [%0] %dst, %src : memref<3x7xf32>, memref<3x7xf32,

[llvm-branch-commits] [mlir] df6cbd3 - [mlir] Lower gpu.memcpy to GPU runtime calls.

2020-12-22 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-22T22:49:19+01:00
New Revision: df6cbd37f57fd330e413c394a4653ea55393fcef

URL: 
https://github.com/llvm/llvm-project/commit/df6cbd37f57fd330e413c394a4653ea55393fcef
DIFF: 
https://github.com/llvm/llvm-project/commit/df6cbd37f57fd330e413c394a4653ea55393fcef.diff

LOG: [mlir] Lower gpu.memcpy to GPU runtime calls.

Reviewed By: herhut

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

Added: 
mlir/test/Conversion/GPUCommon/lower-memcpy-to-gpu-runtime-calls.mlir

Modified: 
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp
mlir/tools/mlir-rocm-runner/rocm-runtime-wrappers.cpp

Removed: 




diff  --git a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp 
b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
index 3b4b39e57d55..41a079c44eea 100644
--- a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
+++ b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
@@ -151,6 +151,12 @@ class ConvertOpToGpuRuntimeCallPattern : public 
ConvertOpToLLVMPattern {
   "mgpuMemFree",
   llvmVoidType,
   {llvmPointerType /* void *ptr */, llvmPointerType /* void *stream */}};
+  FunctionCallBuilder memcpyCallBuilder = {
+  "mgpuMemcpy",
+  llvmVoidType,
+  {llvmPointerType /* void *dst */, llvmPointerType /* void *src */,
+   llvmIntPtrType /* intptr_t sizeBytes */,
+   llvmPointerType /* void *stream */}};
 };
 
 /// A rewrite pattern to convert gpu.host_register operations into a GPU 
runtime
@@ -268,6 +274,20 @@ class EraseGpuModuleOpPattern : public 
OpRewritePattern {
 return success();
   }
 };
+
+/// A rewrite pattern to convert gpu.memcpy operations into a GPU runtime
+/// call. Currently it supports CUDA and ROCm (HIP).
+class ConvertMemcpyOpToGpuRuntimeCallPattern
+: public ConvertOpToGpuRuntimeCallPattern {
+public:
+  ConvertMemcpyOpToGpuRuntimeCallPattern(LLVMTypeConverter &typeConverter)
+  : ConvertOpToGpuRuntimeCallPattern(typeConverter) {}
+
+private:
+  LogicalResult
+  matchAndRewrite(gpu::MemcpyOp memcpyOp, ArrayRef operands,
+  ConversionPatternRewriter &rewriter) const override;
+};
 } // namespace
 
 void GpuToLLVMConversionPass::runOnOperation() {
@@ -643,6 +663,50 @@ LogicalResult 
ConvertLaunchFuncOpToGpuRuntimeCallPattern::matchAndRewrite(
   return success();
 }
 
+LogicalResult ConvertMemcpyOpToGpuRuntimeCallPattern::matchAndRewrite(
+gpu::MemcpyOp memcpyOp, ArrayRef operands,
+ConversionPatternRewriter &rewriter) const {
+  auto memRefType = memcpyOp.src().getType().cast();
+
+  if (failed(areAllLLVMTypes(memcpyOp, operands, rewriter)) ||
+  !isSupportedMemRefType(memRefType) ||
+  failed(isAsyncWithOneDependency(rewriter, memcpyOp)))
+return failure();
+
+  auto loc = memcpyOp.getLoc();
+  auto adaptor = gpu::MemcpyOpAdaptor(operands, memcpyOp->getAttrDictionary());
+
+  MemRefDescriptor srcDesc(adaptor.src());
+
+  Value numElements =
+  memRefType.hasStaticShape()
+  ? createIndexConstant(rewriter, loc, memRefType.getNumElements())
+  // For identity layouts (verified above), the number of elements is
+  // stride[0] * size[0].
+  : rewriter.create(loc, srcDesc.stride(rewriter, loc, 0),
+ srcDesc.size(rewriter, loc, 0));
+
+  Type elementPtrType = getElementPtrType(memRefType);
+  Value nullPtr = rewriter.create(loc, elementPtrType);
+  Value gepPtr = rewriter.create(
+  loc, elementPtrType, ArrayRef{nullPtr, numElements});
+  auto sizeBytes =
+  rewriter.create(loc, getIndexType(), gepPtr);
+
+  auto src = rewriter.create(
+  loc, llvmPointerType, srcDesc.alignedPtr(rewriter, loc));
+  auto dst = rewriter.create(
+  loc, llvmPointerType,
+  MemRefDescriptor(adaptor.dst()).alignedPtr(rewriter, loc));
+
+  auto stream = adaptor.asyncDependencies().front();
+  memcpyCallBuilder.create(loc, rewriter, {dst, src, sizeBytes, stream});
+
+  rewriter.replaceOp(memcpyOp, {stream});
+
+  return success();
+}
+
 std::unique_ptr>
 mlir::createGpuToLLVMConversionPass(StringRef gpuBinaryAnnotation) {
   return std::make_unique(gpuBinaryAnnotation);
@@ -658,6 +722,7 @@ void mlir::populateGpuToLLVMConversionPatterns(
   patterns.insert(converter);
   patterns.insert(

diff  --git 
a/mlir/test/Conversion/GPUCommon/lower-memcpy-to-gpu-runtime-calls.mlir 
b/mlir/test/Conversion/GPUCommon/lower-memcpy-to-gpu-runtime-calls.mlir
new file mode 100644
index ..790c92f92ec9
--- /dev/null
+++ b/mlir/test/Conversion/GPUCommon/lower-memcpy-to-gpu-runtime-calls.mlir
@@ -0,0 +1,19 @@
+// RUN: mlir-opt -allow-unregistered-dialect %s --gpu-to-llvm | FileCheck %s
+
+module attributes {gpu.container_module} {
+
+  // CHECK: func @foo
+  func @foo(%dst : memref<7xf32, 1>, %sr

[llvm-branch-commits] [mlir] 8451d48 - [mlir] NFC: Remove ConvertToLLVMPattern::getDataPtr(). All call sites use getStridedElementPtr() now.

2020-12-23 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-23T11:35:01+01:00
New Revision: 8451d4872ed70d307e21bc437d51ecf9be0cdd08

URL: 
https://github.com/llvm/llvm-project/commit/8451d4872ed70d307e21bc437d51ecf9be0cdd08
DIFF: 
https://github.com/llvm/llvm-project/commit/8451d4872ed70d307e21bc437d51ecf9be0cdd08.diff

LOG: [mlir] NFC: Remove ConvertToLLVMPattern::getDataPtr(). All call sites use 
getStridedElementPtr() now.

Reviewed By: ftynse

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

Added: 


Modified: 
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp

Removed: 




diff  --git 
a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h 
b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index 63ff16a84ab8..63547db56e6d 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -512,11 +512,6 @@ class ConvertToLLVMPattern : public ConversionPattern {
  ValueRange indices,
  ConversionPatternRewriter &rewriter) const;
 
-  // Forwards to getStridedElementPtr. TODO: remove.
-  Value getDataPtr(Location loc, MemRefType type, Value memRefDesc,
-   ValueRange indices,
-   ConversionPatternRewriter &rewriter) const;
-
   /// Returns if the givem memref type is supported.
   bool isSupportedMemRefType(MemRefType type) const;
 

diff  --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp 
b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
index e37e7e2dc0c1..97e763fc08c4 100644
--- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
@@ -1085,12 +1085,6 @@ Value ConvertToLLVMPattern::getStridedElementPtr(
: base;
 }
 
-Value ConvertToLLVMPattern::getDataPtr(
-Location loc, MemRefType type, Value memRefDesc, ValueRange indices,
-ConversionPatternRewriter &rewriter) const {
-  return getStridedElementPtr(loc, type, memRefDesc, indices, rewriter);
-}
-
 // Check if the MemRefType `type` is supported by the lowering. We currently
 // only support memrefs with identity maps.
 bool ConvertToLLVMPattern::isSupportedMemRefType(MemRefType type) const {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 19a0d0a - [mlir] Rename ConvertToLLVMPattern::isSupportedMemRefType() to isConvertibleAndHasIdentityMaps().

2020-12-23 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-23T12:23:29+01:00
New Revision: 19a0d0a40ce991836d930ecf8614ad21a1c3c32c

URL: 
https://github.com/llvm/llvm-project/commit/19a0d0a40ce991836d930ecf8614ad21a1c3c32c
DIFF: 
https://github.com/llvm/llvm-project/commit/19a0d0a40ce991836d930ecf8614ad21a1c3c32c.diff

LOG: [mlir] Rename ConvertToLLVMPattern::isSupportedMemRefType() to 
isConvertibleAndHasIdentityMaps().

Reviewed By: ftynse, herhut

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

Added: 


Modified: 
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp

Removed: 




diff  --git 
a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h 
b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index 63547db56e6d..d5c1e923fab9 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -512,8 +512,9 @@ class ConvertToLLVMPattern : public ConversionPattern {
  ValueRange indices,
  ConversionPatternRewriter &rewriter) const;
 
-  /// Returns if the givem memref type is supported.
-  bool isSupportedMemRefType(MemRefType type) const;
+  /// Returns if the given memref has identity maps and the element type is
+  /// convertible to LLVM.
+  bool isConvertibleAndHasIdentityMaps(MemRefType type) const;
 
   /// Returns the type of a pointer to an element of the memref.
   Type getElementPtrType(MemRefType type) const;

diff  --git a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp 
b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
index bbb2bf1e04ff..d35aa0346f74 100644
--- a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
+++ b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
@@ -369,7 +369,7 @@ LogicalResult 
ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite(
   MemRefType memRefType = allocOp.getType();
 
   if (failed(areAllLLVMTypes(allocOp, operands, rewriter)) ||
-  !isSupportedMemRefType(memRefType) ||
+  !isConvertibleAndHasIdentityMaps(memRefType) ||
   failed(isAsyncWithOneDependency(rewriter, allocOp)))
 return failure();
 
@@ -670,7 +670,7 @@ LogicalResult 
ConvertMemcpyOpToGpuRuntimeCallPattern::matchAndRewrite(
   auto memRefType = memcpyOp.src().getType().cast();
 
   if (failed(areAllLLVMTypes(memcpyOp, operands, rewriter)) ||
-  !isSupportedMemRefType(memRefType) ||
+  !isConvertibleAndHasIdentityMaps(memRefType) ||
   failed(isAsyncWithOneDependency(rewriter, memcpyOp)))
 return failure();
 

diff  --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp 
b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
index 97e763fc08c4..f4d1df81565b 100644
--- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
@@ -1087,7 +1087,8 @@ Value ConvertToLLVMPattern::getStridedElementPtr(
 
 // Check if the MemRefType `type` is supported by the lowering. We currently
 // only support memrefs with identity maps.
-bool ConvertToLLVMPattern::isSupportedMemRefType(MemRefType type) const {
+bool ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps(
+MemRefType type) const {
   if (!typeConverter->convertType(type.getElementType()))
 return false;
   return type.getAffineMaps().empty() ||
@@ -1105,7 +1106,7 @@ void ConvertToLLVMPattern::getMemRefDescriptorSizes(
 Location loc, MemRefType memRefType, ArrayRef dynamicSizes,
 ConversionPatternRewriter &rewriter, SmallVectorImpl &sizes,
 SmallVectorImpl &strides, Value &sizeBytes) const {
-  assert(isSupportedMemRefType(memRefType) &&
+  assert(isConvertibleAndHasIdentityMaps(memRefType) &&
  "layout maps must have been normalized away");
 
   sizes.reserve(memRefType.getRank());
@@ -1977,7 +1978,7 @@ struct AllocLikeOpLowering : public ConvertToLLVMPattern {
 
   LogicalResult match(Operation *op) const override {
 MemRefType memRefType = getMemRefResultType(op);
-return success(isSupportedMemRefType(memRefType));
+return success(isConvertibleAndHasIdentityMaps(memRefType));
   }
 
   // An `alloc` is converted into a definition of a memref descriptor value and
@@ -2411,7 +2412,7 @@ struct GlobalMemrefOpLowering : public 
ConvertOpToLLVMPattern {
   matchAndRewrite(GlobalMemrefOp global, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override {
 MemRefType type = global.type().cast();
-if (!isSupportedMemRefType(type))
+if (!isConvertibleAndHasIdentityMaps(type))
   return failure();
 
 LLVM::LLVMType arrayTy =
@@ -3031,12 +3032,12 @@ struct RankOpLowering : public 
ConvertOpToLLVMPattern

[llvm-branch-commits] [mlir] 5535696 - [mlir] Add gpu.allocate, gpu.deallocate ops with LLVM lowering to runtime function calls.

2020-11-27 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-11-27T09:40:59+01:00
New Revision: 5535696c386ba89b66c1b5a72a2aa98783571cc9

URL: 
https://github.com/llvm/llvm-project/commit/5535696c386ba89b66c1b5a72a2aa98783571cc9
DIFF: 
https://github.com/llvm/llvm-project/commit/5535696c386ba89b66c1b5a72a2aa98783571cc9.diff

LOG: [mlir] Add gpu.allocate, gpu.deallocate ops with LLVM lowering to runtime 
function calls.

The ops are very similar to the std variants, but support async GPU execution.

gpu.alloc does not currently support an alignment attribute, and the new ops do 
not have
canonicalizers/folders like their std siblings do.

Reviewed By: herhut

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

Added: 
mlir/test/Conversion/GPUCommon/lower-alloc-to-gpu-runtime-calls.mlir

Modified: 
mlir/include/mlir/Dialect/GPU/GPUDialect.h
mlir/include/mlir/Dialect/GPU/GPUOps.td
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/test/Dialect/GPU/ops.mlir
mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp
mlir/tools/mlir-rocm-runner/rocm-runtime-wrappers.cpp

Removed: 




diff  --git a/mlir/include/mlir/Dialect/GPU/GPUDialect.h 
b/mlir/include/mlir/Dialect/GPU/GPUDialect.h
index 9828af7a31b0..99f388b4db51 100644
--- a/mlir/include/mlir/Dialect/GPU/GPUDialect.h
+++ b/mlir/include/mlir/Dialect/GPU/GPUDialect.h
@@ -19,6 +19,7 @@
 #include "mlir/IR/FunctionSupport.h"
 #include "mlir/IR/OpDefinition.h"
 #include "mlir/IR/OpImplementation.h"
+#include "mlir/IR/StandardTypes.h"
 #include "mlir/IR/SymbolTable.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"
 

diff  --git a/mlir/include/mlir/Dialect/GPU/GPUOps.td 
b/mlir/include/mlir/Dialect/GPU/GPUOps.td
index 593b735f01c9..33c00ca9b22c 100644
--- a/mlir/include/mlir/Dialect/GPU/GPUOps.td
+++ b/mlir/include/mlir/Dialect/GPU/GPUOps.td
@@ -804,4 +804,79 @@ def GPU_WaitOp : GPU_Op<"wait", [GPU_AsyncOpInterface]> {
   }];
 }
 
+def GPU_AllocOp : GPU_Op<"alloc", [
+GPU_AsyncOpInterface,
+AttrSizedOperandSegments,
+MemoryEffects<[MemAlloc]>
+  ]> {
+
+  let summary = "GPU memory allocation operation.";
+  let description = [{
+The `gpu.alloc` operation allocates a region of memory on the GPU. It is
+similar to the `std.alloc` op, but supports asynchronous GPU execution.
+
+The op does not execute before all async dependencies have finished
+executing.
+
+If the `async` keyword is present, the op is executed asynchronously (i.e.
+it does not block until the execution has finished on the device). In
+that case, it also returns a !gpu.async.token.
+
+Example:
+
+```mlir
+%memref, %token = gpu.alloc async [%dep] (%width) : memref<64x?xf32, 1>
+```
+  }];
+
+  let arguments = (ins Variadic:$asyncDependencies,
+   Variadic:$dynamicSizes, 
Variadic:$symbolOperands);
+  let results = (outs Res]>:$memref,
+ Optional:$asyncToken);
+
+  let extraClassDeclaration = [{
+MemRefType getType() { return memref().getType().cast(); }
+  }];
+
+  let assemblyFormat = [{
+custom(type($asyncToken), $asyncDependencies) ` `
+`(` $dynamicSizes `)` (`` `[` $symbolOperands^ `]`)? attr-dict `:` 
type($memref)
+  }];
+}
+
+def GPU_DeallocOp : GPU_Op<"dealloc", [
+GPU_AsyncOpInterface, MemoryEffects<[MemFree]>
+  ]> {
+
+  let summary = "GPU memory deallocation operation";
+
+  let description = [{
+The `gpu.dealloc` operation frees the region of memory referenced by a
+memref which was originally created by the `gpu.alloc` operation. It is
+similar to the `std.dealloc` op, but supports asynchronous GPU execution.
+
+The op does not execute before all async dependencies have finished
+executing.
+
+If the `async` keyword is present, the op is executed asynchronously (i.e.
+it does not block until the execution has finished on the device). In
+that case, it returns a !gpu.async.token.
+
+Example:
+
+```mlir
+%token = gpu.dealloc async [%dep] %memref : memref<8x64xf32, 1>
+```
+  }];
+
+  let arguments = (ins Variadic:$asyncDependencies,
+   Arg:$memref);
+  let results = (outs Optional:$asyncToken);
+
+  let assemblyFormat = [{
+custom(type($asyncToken), $asyncDependencies)
+$memref attr-dict `:` type($memref)
+  }];
+}
+
 #endif // GPU_OPS

diff  --git a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp 
b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
index a046bb068d12..d625db95e976 100644
--- a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
+++ b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
@@ -142,6 +142,15 @@ class ConvertOpToGpuRuntimeCallPattern : public 
ConvertOpToLLVMPattern {
   {llvmIntPtrType /* intptr_t rank */,
llvmPointerType /* void *memrefDesc */,
llvmIntPtrType /* intptr_t elementSizeBytes */}};
+  

[llvm-branch-commits] [mlir] acb69f3 - [mlir] Change ConvertOpToLLVMPattern::matchAndRewrite argument to concrete operand type.

2020-11-28 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-11-28T13:09:25+01:00
New Revision: acb69f3b7c83f411c08b77d75f2e812faf3cb83f

URL: 
https://github.com/llvm/llvm-project/commit/acb69f3b7c83f411c08b77d75f2e812faf3cb83f
DIFF: 
https://github.com/llvm/llvm-project/commit/acb69f3b7c83f411c08b77d75f2e812faf3cb83f.diff

LOG: [mlir] Change ConvertOpToLLVMPattern::matchAndRewrite argument to concrete 
operand type.

Reviewed By: herhut, ftynse

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

Added: 


Modified: 
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/test/lib/Transforms/TestConvertCallOp.cpp

Removed: 




diff  --git 
a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h 
b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index 919a93ac84a2..70db4c1510bf 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -564,14 +564,47 @@ class ConvertToLLVMPattern : public ConversionPattern {
 
 /// Utility class for operation conversions targeting the LLVM dialect that
 /// match exactly one source operation.
-template 
+template 
 class ConvertOpToLLVMPattern : public ConvertToLLVMPattern {
 public:
   ConvertOpToLLVMPattern(LLVMTypeConverter &typeConverter,
  PatternBenefit benefit = 1)
-  : ConvertToLLVMPattern(OpTy::getOperationName(),
+  : ConvertToLLVMPattern(SourceOp::getOperationName(),
  &typeConverter.getContext(), typeConverter,
  benefit) {}
+
+  /// Wrappers around the RewritePattern methods that pass the derived op type.
+  void rewrite(Operation *op, ArrayRef operands,
+   ConversionPatternRewriter &rewriter) const final {
+rewrite(cast(op), operands, rewriter);
+  }
+  LogicalResult match(Operation *op) const final {
+return match(cast(op));
+  }
+  LogicalResult
+  matchAndRewrite(Operation *op, ArrayRef operands,
+  ConversionPatternRewriter &rewriter) const final {
+return matchAndRewrite(cast(op), operands, rewriter);
+  }
+
+  /// Rewrite and Match methods that operate on the SourceOp type. These must 
be
+  /// overridden by the derived pattern class.
+  virtual void rewrite(SourceOp op, ArrayRef operands,
+   ConversionPatternRewriter &rewriter) const {
+llvm_unreachable("must override rewrite or matchAndRewrite");
+  }
+  virtual LogicalResult match(SourceOp op) const {
+llvm_unreachable("must override match or matchAndRewrite");
+  }
+  virtual LogicalResult
+  matchAndRewrite(SourceOp op, ArrayRef operands,
+  ConversionPatternRewriter &rewriter) const {
+if (succeeded(match(op))) {
+  rewrite(op, operands, rewriter);
+  return success();
+}
+return failure();
+  }
 };
 
 namespace LLVM {
@@ -604,7 +637,7 @@ class OneToOneConvertToLLVMPattern : public 
ConvertOpToLLVMPattern {
   /// Converts the type of the result to an LLVM type, pass operands as is,
   /// preserve attributes.
   LogicalResult
-  matchAndRewrite(Operation *op, ArrayRef operands,
+  matchAndRewrite(SourceOp op, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override {
 return LLVM::detail::oneToOneRewrite(op, TargetOp::getOperationName(),
  operands, this->typeConverter,
@@ -621,7 +654,7 @@ class VectorConvertToLLVMPattern : public 
ConvertOpToLLVMPattern {
   using Super = VectorConvertToLLVMPattern;
 
   LogicalResult
-  matchAndRewrite(Operation *op, ArrayRef operands,
+  matchAndRewrite(SourceOp op, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override {
 static_assert(
 std::is_base_of, SourceOp>::value,

diff  --git a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp 
b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
index d625db95e976..cb7644cb7202 100644
--- a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
+++ b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
@@ -163,7 +163,7 @@ class ConvertHostRegisterOpToGpuRuntimeCallPattern
 
 private:
   LogicalResult
-  matchAndRewrite(Operation *op, ArrayRef operands,
+  matchAndRewrite(gpu::HostRegisterOp hostRegisterOp, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override;
 };
 
@@ -205,7 +205,7 @@ class ConvertWaitOpToGpuRuntimeCallPattern
 
 private:
   LogicalResult
-  matchAndRewrite(Operation *op, ArrayRef operands,
+  matchAndRewrite(gpu::WaitOp waitOp, ArrayRef operands,
   ConversionPatt

[llvm-branch-commits] [mlir] e9e45b3 - [mlir] Fix bad rebase landed in acb69f3b7c83.

2020-11-28 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-11-28T13:57:01+01:00
New Revision: e9e45b3887ca343e90fe91fe77b98d47e66ca312

URL: 
https://github.com/llvm/llvm-project/commit/e9e45b3887ca343e90fe91fe77b98d47e66ca312
DIFF: 
https://github.com/llvm/llvm-project/commit/e9e45b3887ca343e90fe91fe77b98d47e66ca312.diff

LOG: [mlir] Fix bad rebase landed in acb69f3b7c83.

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

Added: 


Modified: 
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp

Removed: 




diff  --git a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp 
b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
index cb7644cb7202..a8e282901f83 100644
--- a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
+++ b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
@@ -177,7 +177,7 @@ class ConvertAllocOpToGpuRuntimeCallPattern
 
 private:
   LogicalResult
-  matchAndRewrite(Operation *op, ArrayRef operands,
+  matchAndRewrite(gpu::AllocOp allocOp, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override;
 };
 
@@ -191,7 +191,7 @@ class ConvertDeallocOpToGpuRuntimeCallPattern
 
 private:
   LogicalResult
-  matchAndRewrite(Operation *op, ArrayRef operands,
+  matchAndRewrite(gpu::DeallocOp deallocOp, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override;
 };
 
@@ -343,18 +343,16 @@ LogicalResult 
ConvertHostRegisterOpToGpuRuntimeCallPattern::matchAndRewrite(
 }
 
 LogicalResult ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite(
-Operation *op, ArrayRef operands,
+gpu::AllocOp allocOp, ArrayRef operands,
 ConversionPatternRewriter &rewriter) const {
-  auto allocOp = cast(op);
   MemRefType memRefType = allocOp.getType();
 
-  if (failed(areAllLLVMTypes(op, operands, rewriter)) ||
+  if (failed(areAllLLVMTypes(allocOp, operands, rewriter)) ||
   !isSupportedMemRefType(memRefType) ||
-  failed(
-  isAsyncWithOneDependency(rewriter, cast(op
+  failed(isAsyncWithOneDependency(rewriter, allocOp)))
 return failure();
 
-  auto loc = op->getLoc();
+  auto loc = allocOp.getLoc();
 
   // Get shape of the memref as values: static sizes are constant
   // values and dynamic sizes are passed to 'alloc' as operands.
@@ -367,7 +365,8 @@ LogicalResult 
ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite(
   // Allocate the underlying buffer and store a pointer to it in the MemRef
   // descriptor.
   Type elementPtrType = this->getElementPtrType(memRefType);
-  auto adaptor = gpu::AllocOpAdaptor(operands, op->getAttrDictionary());
+  auto adaptor = gpu::AllocOpAdaptor(
+  operands, allocOp.getOperation()->getAttrDictionary());
   auto stream = adaptor.asyncDependencies().front();
   Value allocatedPtr =
   allocCallBuilder.create(loc, rewriter, {sizeBytes, stream}).getResult(0);
@@ -381,29 +380,29 @@ LogicalResult 
ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite(
   auto memRefDescriptor = this->createMemRefDescriptor(
   loc, memRefType, allocatedPtr, alignedPtr, shape, strides, rewriter);
 
-  rewriter.replaceOp(op, {memRefDescriptor, stream});
+  rewriter.replaceOp(allocOp, {memRefDescriptor, stream});
 
   return success();
 }
 
 LogicalResult ConvertDeallocOpToGpuRuntimeCallPattern::matchAndRewrite(
-Operation *op, ArrayRef operands,
+gpu::DeallocOp deallocOp, ArrayRef operands,
 ConversionPatternRewriter &rewriter) const {
-  if (failed(areAllLLVMTypes(op, operands, rewriter)) ||
-  failed(
-  isAsyncWithOneDependency(rewriter, cast(op
+  if (failed(areAllLLVMTypes(deallocOp, operands, rewriter)) ||
+  failed(isAsyncWithOneDependency(rewriter, deallocOp)))
 return failure();
 
-  Location loc = op->getLoc();
+  Location loc = deallocOp.getLoc();
 
-  auto adaptor = gpu::DeallocOpAdaptor(operands, op->getAttrDictionary());
+  auto adaptor = gpu::DeallocOpAdaptor(
+  operands, deallocOp.getOperation()->getAttrDictionary());
   Value pointer =
   MemRefDescriptor(adaptor.memref()).allocatedPtr(rewriter, loc);
   auto casted = rewriter.create(loc, llvmPointerType, 
pointer);
   Value stream = adaptor.asyncDependencies().front();
   deallocCallBuilder.create(loc, rewriter, {casted, stream});
 
-  rewriter.replaceOp(op, {stream});
+  rewriter.replaceOp(deallocOp, {stream});
   return success();
 }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] ffaba24 - Add `using ConvertToLLVMPattern::match/matchAndRewrite` to avoid 'hiding overload' warning.

2020-11-30 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-11-30T11:40:34+01:00
New Revision: ffaba24c75edc274ec651915a0f2f500b8f6b341

URL: 
https://github.com/llvm/llvm-project/commit/ffaba24c75edc274ec651915a0f2f500b8f6b341
DIFF: 
https://github.com/llvm/llvm-project/commit/ffaba24c75edc274ec651915a0f2f500b8f6b341.diff

LOG: Add `using ConvertToLLVMPattern::match/matchAndRewrite` to avoid 'hiding 
overload' warning.

Reviewed By: ftynse

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

Added: 


Modified: 
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h

Removed: 




diff  --git 
a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h 
b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index 70db4c1510bf..edfd8c96eaa7 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -605,6 +605,10 @@ class ConvertOpToLLVMPattern : public ConvertToLLVMPattern 
{
 }
 return failure();
   }
+
+private:
+  using ConvertToLLVMPattern::match;
+  using ConvertToLLVMPattern::matchAndRewrite;
 };
 
 namespace LLVM {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] c4a0405 - Add `Operation* OpState::operator->()` to provide more convenient access to members of Operation.

2020-12-02 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-02T15:46:20+01:00
New Revision: c4a04059026b98e8c23981f1195a61494a661cdb

URL: 
https://github.com/llvm/llvm-project/commit/c4a04059026b98e8c23981f1195a61494a661cdb
DIFF: 
https://github.com/llvm/llvm-project/commit/c4a04059026b98e8c23981f1195a61494a661cdb.diff

LOG: Add `Operation* OpState::operator->()` to provide more convenient access 
to members of Operation.

Given that OpState already implicit converts to Operator*, this seems 
reasonable.

The alternative would be to add more functions to OpState which forward to 
Operation.

Reviewed By: rriddle, ftynse

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

Added: 


Modified: 
mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td
mlir/include/mlir/Dialect/Vector/VectorTransforms.h
mlir/include/mlir/IR/OpDefinition.h
mlir/include/mlir/Interfaces/VectorInterfaces.td
mlir/lib/Analysis/AffineAnalysis.cpp
mlir/lib/Analysis/BufferAliasAnalysis.cpp
mlir/lib/Analysis/Utils.cpp
mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp
mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp
mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
mlir/lib/Dialect/Affine/Transforms/AffineLoopInvariantCodeMotion.cpp
mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
mlir/lib/Dialect/Affine/Utils/Utils.cpp
mlir/lib/Dialect/Async/Transforms/AsyncRefCountingOptimization.cpp
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp
mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp
mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp
mlir/lib/Dialect/Linalg/Transforms/FusionOnTensors.cpp
mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
mlir/lib/Dialect/PDL/IR/PDL.cpp
mlir/lib/Dialect/SCF/SCF.cpp
mlir/lib/Dialect/SCF/Transforms/ParallelLoopFusion.cpp
mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
mlir/lib/Dialect/SPIRV/SPIRVCanonicalization.cpp
mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
mlir/lib/Dialect/SPIRV/Transforms/RewriteInsertsPass.cpp
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp
mlir/lib/Dialect/Vector/VectorOps.cpp
mlir/lib/Dialect/Vector/VectorTransforms.cpp
mlir/lib/IR/BuiltinDialect.cpp
mlir/lib/Parser/Parser.cpp
mlir/lib/Transforms/Inliner.cpp
mlir/lib/Transforms/LoopFusion.cpp
mlir/lib/Transforms/SCCP.cpp
mlir/lib/Transforms/Utils/InliningUtils.cpp
mlir/lib/Transforms/Utils/LoopFusionUtils.cpp
mlir/lib/Transforms/Utils/LoopUtils.cpp
mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
mlir/test/lib/Transforms/TestLinalgFusionTransforms.cpp
mlir/test/lib/Transforms/TestLoopFusion.cpp
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp

Removed: 




diff  --git a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp 
b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
index 6daccaef7cd3..46d8fe40e5d4 100644
--- a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
+++ b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
@@ -39,13 +39,13 @@ static Value insertAllocAndDealloc(MemRefType type, 
Location loc,
   auto alloc = rewriter.create(loc, type);
 
   // Make sure to allocate at the beginning of the block.
-  auto *parentBlock = alloc.getOperation()->getBlock();
-  alloc.getOperation()->moveBefore(&parentBlock->front());
+  auto *parentBlock = alloc->getBlock();
+  alloc->moveBefore(&parentBlock->front());
 
   // Make sure to deallocate this alloc at the end of the block. This is fine
   // as toy functions have no control flow.
   auto dealloc = rewriter.create(loc, alloc);
-  dealloc.getOperation()->moveBefore(&parentBlock->back());
+  dealloc->moveBefore(&parentBlock->back());
   return alloc;
 }
 

diff  --git a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp 
b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
index 14f68e6176b5..2089b6579ccb 100644
--- a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
+++ b/mlir/examples/toy/Ch6/mlir/Low

[llvm-branch-commits] [mlir] d9adde5 - [mlir][gpu] Move gpu.wait ops from async.execute regions to its dependencies.

2020-12-02 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-03T08:52:28+01:00
New Revision: d9adde5ae2164ed076d5683fd716deec49400d8b

URL: 
https://github.com/llvm/llvm-project/commit/d9adde5ae2164ed076d5683fd716deec49400d8b
DIFF: 
https://github.com/llvm/llvm-project/commit/d9adde5ae2164ed076d5683fd716deec49400d8b.diff

LOG: [mlir][gpu] Move gpu.wait ops from async.execute regions to its 
dependencies.

This can prevent unnecessary host synchronization.

Reviewed By: herhut

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

Added: 


Modified: 
mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
mlir/test/Dialect/GPU/async-region.mlir

Removed: 




diff  --git a/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp 
b/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
index 917c27714b4a..f2c7010be291 100644
--- a/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "PassDetail.h"
+#include "mlir/Dialect/Async/IR/Async.h"
 #include "mlir/Dialect/GPU/GPUDialect.h"
 #include "mlir/Dialect/GPU/Passes.h"
 #include "mlir/Dialect/GPU/Utils.h"
@@ -22,24 +23,35 @@
 #include "mlir/IR/SymbolTable.h"
 #include "mlir/Support/LLVM.h"
 #include "mlir/Transforms/RegionUtils.h"
+#include "llvm/ADT/TypeSwitch.h"
 
 using namespace mlir;
 namespace {
 class GpuAsyncRegionPass : public GpuAsyncRegionPassBase {
-  struct Callback;
+  struct ThreadTokenCallback;
+  struct DeferWaitCallback;
   void runOnFunction() override;
 };
 } // namespace
 
+static bool isTerminator(Operation *op) { return !op->isKnownNonTerminator(); }
+static bool hasSideEffects(Operation *op) {
+  return !MemoryEffectOpInterface::hasNoEffect(op);
+}
+
 // Region walk callback which makes GPU ops implementing the AsyncOpInterface
 // execute asynchronously.
-struct GpuAsyncRegionPass::Callback {
+struct GpuAsyncRegionPass::ThreadTokenCallback {
+  ThreadTokenCallback(MLIRContext &context) : builder(&context) {}
+
   // If `op` implements the AsyncOpInterface, insert a `gpu.wait async` to
   // create a current token (unless it already exists), and 'thread' that token
   // through the `op` so that it executes asynchronously.
   //
   // If `op` is a terminator or an op with side-effects, insert a `gpu.wait` to
-  // host-synchronize execution.
+  // host-synchronize execution. A `!gpu.async.token` will therefore only be
+  // used inside of its block and GPU execution will always synchronize with
+  // the host at block boundaries.
   WalkResult operator()(Operation *op) {
 if (isa(op))
   return op->emitOpError("replace with gpu.launch_func first");
@@ -50,14 +62,13 @@ struct GpuAsyncRegionPass::Callback {
   return rewriteAsyncOp(asyncOp); // Replace GPU op with async version.
 if (!currentToken)
   return success();
-if (!op->hasTrait() &&
-MemoryEffectOpInterface::hasNoEffect(op))
-  return success();
 // Insert host synchronization before terminator or op with side effects.
-currentToken = createWaitOp(op->getLoc(), Type(), {currentToken});
+if (isTerminator(op) || hasSideEffects(op))
+  currentToken = createWaitOp(op->getLoc(), Type(), {currentToken});
 return success();
   }
 
+private:
   // Replaces asyncOp with a clone that returns a token.
   LogicalResult rewriteAsyncOp(gpu::AsyncOpInterface asyncOp) {
 auto *op = asyncOp.getOperation();
@@ -104,13 +115,159 @@ struct GpuAsyncRegionPass::Callback {
   Value currentToken = {};
 };
 
+// Callback for `async.execute` ops which tries to push the contained
+// synchronous `gpu.wait` op to the dependencies of the `async.execute`.
+struct GpuAsyncRegionPass::DeferWaitCallback {
+  // If the `executeOp`s token is used only in `async.execute` or `async.await`
+  // ops, add the region's last `gpu.wait` op to the worklist if it is
+  // synchronous and is the last op with side effects.
+  void operator()(async::ExecuteOp executeOp) {
+if (!areAllUsersExecuteOrAwait(executeOp.token()))
+  return;
+// async.execute's region is currently restricted to one block.
+for (auto &op : llvm::reverse(executeOp.getBody()->without_terminator())) {
+  if (auto waitOp = dyn_cast(op)) {
+if (!waitOp.asyncToken())
+  worklist.push_back(waitOp);
+return;
+  }
+  if (hasSideEffects(&op))
+return;
+}
+  }
+
+  // The destructor performs the actual rewrite work.
+  ~DeferWaitCallback() {
+for (size_t i = 0; i < worklist.size(); ++i) {
+  auto waitOp = worklist[i];
+  auto executeOp = waitOp.getParentOfType();
+  auto numDependencies = waitOp.asyncDependencies().size();
+
+  // Erase `gpu.wait` and return async dependencies from region instead.
+  auto &yieldOp = executeOp.getBody()->getOperations().back();
+ 

[llvm-branch-commits] [mlir] 48f7ca1 - Fix forward for rGd9adde5ae216: adding missing dependency.

2020-12-03 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-03T10:16:57+01:00
New Revision: 48f7ca187944c14f7b134336fc86e365de765d22

URL: 
https://github.com/llvm/llvm-project/commit/48f7ca187944c14f7b134336fc86e365de765d22
DIFF: 
https://github.com/llvm/llvm-project/commit/48f7ca187944c14f7b134336fc86e365de765d22.diff

LOG: Fix forward for rGd9adde5ae216: adding missing dependency.

Reviewed By: herhut

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

Added: 


Modified: 
mlir/lib/Dialect/GPU/CMakeLists.txt

Removed: 




diff  --git a/mlir/lib/Dialect/GPU/CMakeLists.txt 
b/mlir/lib/Dialect/GPU/CMakeLists.txt
index 0bfd0ce30e5e..39d387964441 100644
--- a/mlir/lib/Dialect/GPU/CMakeLists.txt
+++ b/mlir/lib/Dialect/GPU/CMakeLists.txt
@@ -17,6 +17,7 @@ add_mlir_dialect_library(MLIRGPU
   MLIRParallelLoopMapperEnumsGen
 
   LINK_LIBS PUBLIC
+  MLIRAsync
   MLIREDSC
   MLIRIR
   MLIRLLVMIR



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] dcec2ca - Remove typeConverter from ConvertToLLVMPattern and use the existing one in ConversionPattern.

2020-12-04 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-04T14:27:16+01:00
New Revision: dcec2ca5bd3d82ebbe57d47fc2bdd742d35e8947

URL: 
https://github.com/llvm/llvm-project/commit/dcec2ca5bd3d82ebbe57d47fc2bdd742d35e8947
DIFF: 
https://github.com/llvm/llvm-project/commit/dcec2ca5bd3d82ebbe57d47fc2bdd742d35e8947.diff

LOG: Remove typeConverter from ConvertToLLVMPattern and use the existing one in 
ConversionPattern.

ftynse

Reviewed By: ftynse

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

Added: 


Modified: 
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h
mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
mlir/lib/Conversion/VectorToROCDL/VectorToROCDL.cpp

Removed: 




diff  --git 
a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h 
b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index 7b8bcdff4deb..bf41f29749de 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -71,7 +71,7 @@ class LLVMTypeConverter : public TypeConverter {
   /// Convert a function type.  The arguments and results are converted one by
   /// one and results are packed into a wrapped LLVM IR structure type. 
`result`
   /// is populated with argument mapping.
-  LLVM::LLVMType convertFunctionSignature(FunctionType type, bool isVariadic,
+  LLVM::LLVMType convertFunctionSignature(FunctionType funcTy, bool isVariadic,
   SignatureConversion &result);
 
   /// Convert a non-empty list of types to be returned from a function into a
@@ -485,6 +485,8 @@ class ConvertToLLVMPattern : public ConversionPattern {
   /// Returns the LLVM dialect.
   LLVM::LLVMDialect &getDialect() const;
 
+  LLVMTypeConverter *getTypeConverter() const;
+
   /// Gets the MLIR type wrapping the LLVM integer type whose bit width is
   /// defined by the used type converter.
   LLVM::LLVMType getIndexType() const;
@@ -556,10 +558,6 @@ class ConvertToLLVMPattern : public ConversionPattern {
  Value allocatedPtr, Value alignedPtr,
  ArrayRef sizes, ArrayRef strides,
  ConversionPatternRewriter &rewriter) const;
-
-protected:
-  /// Reference to the type converter, with potential extensions.
-  LLVMTypeConverter &typeConverter;
 };
 
 /// Utility class for operation conversions targeting the LLVM dialect that
@@ -644,7 +642,7 @@ class OneToOneConvertToLLVMPattern : public 
ConvertOpToLLVMPattern {
   matchAndRewrite(SourceOp op, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override {
 return LLVM::detail::oneToOneRewrite(op, TargetOp::getOperationName(),
- operands, this->typeConverter,
+ operands, *this->getTypeConverter(),
  rewriter);
   }
 };
@@ -666,9 +664,9 @@ class VectorConvertToLLVMPattern : public 
ConvertOpToLLVMPattern {
 static_assert(std::is_base_of,
   SourceOp>::value,
   "expected same operands and result type");
-return LLVM::detail::vectorOneToOneRewrite(op, 
TargetOp::getOperationName(),
-   operands, this->typeConverter,
-   rewriter);
+return LLVM::detail::vectorOneToOneRewrite(
+op, TargetOp::getOperationName(), operands, *this->getTypeConverter(),
+rewriter);
   }
 };
 

diff  --git a/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp 
b/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
index 3950562539f6..fe06e12c8f21 100644
--- a/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
+++ b/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp
@@ -86,7 +86,7 @@ struct MaskRndScaleOpPS512Conversion : public 
ConvertToLLVMPattern {
   return failure();
 return matchAndRewriteOneToOne(
-*this, this->typeConverter, op, operands, rewriter);
+*this, *getTypeConverter(), op, operands, rewriter);
   }
 };
 
@@ -103,7 +103,7 @@ struct MaskRndScaleOpPD512Conversion : public 
ConvertToLLVMPattern {
   return failure();
 return matchAndRewriteOneToOne(
-*this, this->typeConverter, op, operands, rewriter);
+*this, *getTypeConverter(), op, operands, rewriter);
   }
 };
 
@@ -120,7 +120,7 @@ struc

[llvm-branch-commits] [mlir] 02c9050 - [mlir] Tighten access of RewritePattern methods.

2020-12-08 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-08T16:44:51+01:00
New Revision: 02c9050155dff70497b3423ae95ed7d2ab7675a8

URL: 
https://github.com/llvm/llvm-project/commit/02c9050155dff70497b3423ae95ed7d2ab7675a8
DIFF: 
https://github.com/llvm/llvm-project/commit/02c9050155dff70497b3423ae95ed7d2ab7675a8.diff

LOG: [mlir] Tighten access of RewritePattern methods.

In RewritePattern, only expose `matchAndRewrite` as a public function. `match` 
can be protected (but needs to be protected because we want to call it from an 
override of `matchAndRewrite`). `rewrite` can be private.

For classes deriving from RewritePattern, all 3 functions can be private.

Side note: I didn't understand the need for the `using 
RewritePattern::matchAndRewrite` in derived classes, and started poking around. 
They are gone now, and I think the result is (only very slightly) cleaner.

Reviewed By: ftynse

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

Added: 


Modified: 
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/include/mlir/IR/PatternMatch.h
mlir/include/mlir/Transforms/DialectConversion.h

Removed: 




diff  --git 
a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h 
b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index bf41f29749de..5b605c165be6 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -571,11 +571,9 @@ class ConvertOpToLLVMPattern : public ConvertToLLVMPattern 
{
  &typeConverter.getContext(), typeConverter,
  benefit) {}
 
-  /// Wrappers around the RewritePattern methods that pass the derived op type.
-  void rewrite(Operation *op, ArrayRef operands,
-   ConversionPatternRewriter &rewriter) const final {
-rewrite(cast(op), operands, rewriter);
-  }
+private:
+  /// Wrappers around the ConversionPattern methods that pass the derived op
+  /// type.
   LogicalResult match(Operation *op) const final {
 return match(cast(op));
   }
@@ -584,6 +582,10 @@ class ConvertOpToLLVMPattern : public ConvertToLLVMPattern 
{
   ConversionPatternRewriter &rewriter) const final {
 return matchAndRewrite(cast(op), operands, rewriter);
   }
+  void rewrite(Operation *op, ArrayRef operands,
+   ConversionPatternRewriter &rewriter) const final {
+rewrite(cast(op), operands, rewriter);
+  }
 
   /// Rewrite and Match methods that operate on the SourceOp type. These must 
be
   /// overridden by the derived pattern class.
@@ -603,10 +605,6 @@ class ConvertOpToLLVMPattern : public ConvertToLLVMPattern 
{
 }
 return failure();
   }
-
-private:
-  using ConvertToLLVMPattern::match;
-  using ConvertToLLVMPattern::matchAndRewrite;
 };
 
 namespace LLVM {
@@ -636,6 +634,7 @@ class OneToOneConvertToLLVMPattern : public 
ConvertOpToLLVMPattern {
   using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;
   using Super = OneToOneConvertToLLVMPattern;
 
+private:
   /// Converts the type of the result to an LLVM type, pass operands as is,
   /// preserve attributes.
   LogicalResult
@@ -655,6 +654,7 @@ class VectorConvertToLLVMPattern : public 
ConvertOpToLLVMPattern {
   using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;
   using Super = VectorConvertToLLVMPattern;
 
+private:
   LogicalResult
   matchAndRewrite(SourceOp op, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override {

diff  --git a/mlir/include/mlir/IR/PatternMatch.h 
b/mlir/include/mlir/IR/PatternMatch.h
index 0bbb2216ee7b..1739cfa4a80c 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -156,17 +156,6 @@ class RewritePattern : public Pattern {
 public:
   virtual ~RewritePattern() {}
 
-  /// Rewrite the IR rooted at the specified operation with the result of
-  /// this pattern, generating any new operations with the specified
-  /// builder.  If an unexpected error is encountered (an internal
-  /// compiler error), it is emitted through the normal MLIR diagnostic
-  /// hooks and the IR is left in a valid state.
-  virtual void rewrite(Operation *op, PatternRewriter &rewriter) const;
-
-  /// Attempt to match against code rooted at the specified operation,
-  /// which is the same operation code as getRootKind().
-  virtual LogicalResult match(Operation *op) const;
-
   /// Attempt to match against code rooted at the specified operation,
   /// which is the same operation code as getRootKind(). If successful, this
   /// function will automatically perform the rewrite.
@@ -183,6 +172,18 @@ class RewritePattern : public Pattern {
   /// Inherit the base constructors from `Pattern`.
   using Pattern::Pattern;
 
+  /// Attempt to match against code rooted at the specified operation,
+  /// which is the same operat

[llvm-branch-commits] [mlir] 2a98409 - [mlir] Revert "Tighten access of RewritePattern methods."

2020-12-08 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-08T17:40:44+01:00
New Revision: 2a9840900ccc0add8fc6aed0533ceec198b3514d

URL: 
https://github.com/llvm/llvm-project/commit/2a9840900ccc0add8fc6aed0533ceec198b3514d
DIFF: 
https://github.com/llvm/llvm-project/commit/2a9840900ccc0add8fc6aed0533ceec198b3514d.diff

LOG: [mlir] Revert "Tighten access of RewritePattern methods."

This reverts commit 02c9050155dff70497b3423ae95ed7d2ab7675a8.
Painted myself into a corner with -Wvirtual_overload, private access, and final.

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

Added: 


Modified: 
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/include/mlir/IR/PatternMatch.h
mlir/include/mlir/Transforms/DialectConversion.h

Removed: 




diff  --git 
a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h 
b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index 5b605c165be6..bf41f29749de 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -571,9 +571,11 @@ class ConvertOpToLLVMPattern : public ConvertToLLVMPattern 
{
  &typeConverter.getContext(), typeConverter,
  benefit) {}
 
-private:
-  /// Wrappers around the ConversionPattern methods that pass the derived op
-  /// type.
+  /// Wrappers around the RewritePattern methods that pass the derived op type.
+  void rewrite(Operation *op, ArrayRef operands,
+   ConversionPatternRewriter &rewriter) const final {
+rewrite(cast(op), operands, rewriter);
+  }
   LogicalResult match(Operation *op) const final {
 return match(cast(op));
   }
@@ -582,10 +584,6 @@ class ConvertOpToLLVMPattern : public ConvertToLLVMPattern 
{
   ConversionPatternRewriter &rewriter) const final {
 return matchAndRewrite(cast(op), operands, rewriter);
   }
-  void rewrite(Operation *op, ArrayRef operands,
-   ConversionPatternRewriter &rewriter) const final {
-rewrite(cast(op), operands, rewriter);
-  }
 
   /// Rewrite and Match methods that operate on the SourceOp type. These must 
be
   /// overridden by the derived pattern class.
@@ -605,6 +603,10 @@ class ConvertOpToLLVMPattern : public ConvertToLLVMPattern 
{
 }
 return failure();
   }
+
+private:
+  using ConvertToLLVMPattern::match;
+  using ConvertToLLVMPattern::matchAndRewrite;
 };
 
 namespace LLVM {
@@ -634,7 +636,6 @@ class OneToOneConvertToLLVMPattern : public 
ConvertOpToLLVMPattern {
   using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;
   using Super = OneToOneConvertToLLVMPattern;
 
-private:
   /// Converts the type of the result to an LLVM type, pass operands as is,
   /// preserve attributes.
   LogicalResult
@@ -654,7 +655,6 @@ class VectorConvertToLLVMPattern : public 
ConvertOpToLLVMPattern {
   using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;
   using Super = VectorConvertToLLVMPattern;
 
-private:
   LogicalResult
   matchAndRewrite(SourceOp op, ArrayRef operands,
   ConversionPatternRewriter &rewriter) const override {

diff  --git a/mlir/include/mlir/IR/PatternMatch.h 
b/mlir/include/mlir/IR/PatternMatch.h
index 1739cfa4a80c..d97b328cdc01 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -156,6 +156,17 @@ class RewritePattern : public Pattern {
 public:
   virtual ~RewritePattern() {}
 
+  /// Rewrite the IR rooted at the specified operation with the result of
+  /// this pattern, generating any new operations with the specified
+  /// builder.  If an unexpected error is encountered (an internal
+  /// compiler error), it is emitted through the normal MLIR diagnostic
+  /// hooks and the IR is left in a valid state.
+  virtual void rewrite(Operation *op, PatternRewriter &rewriter) const;
+
+  /// Attempt to match against code rooted at the specified operation,
+  /// which is the same operation code as getRootKind().
+  virtual LogicalResult match(Operation *op) const;
+
   /// Attempt to match against code rooted at the specified operation,
   /// which is the same operation code as getRootKind(). If successful, this
   /// function will automatically perform the rewrite.
@@ -172,18 +183,6 @@ class RewritePattern : public Pattern {
   /// Inherit the base constructors from `Pattern`.
   using Pattern::Pattern;
 
-  /// Attempt to match against code rooted at the specified operation,
-  /// which is the same operation code as getRootKind().
-  virtual LogicalResult match(Operation *op) const;
-
-private:
-  /// Rewrite the IR rooted at the specified operation with the result of
-  /// this pattern, generating any new operations with the specified
-  /// builder.  If an unexpected error is encountered (an internal
-  /// compiler error), it is emitted through the normal MLIR diagnost

[llvm-branch-commits] [flang] 0bf4a82 - [mlir] Use mlir::OpState::operator->() to get to methods of mlir::Operation. This is a preparation step to remove the corresponding methods from OpState.

2020-12-09 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-09T12:11:32+01:00
New Revision: 0bf4a82a5a2b11a07a7f7eac5e49b565cb041b13

URL: 
https://github.com/llvm/llvm-project/commit/0bf4a82a5a2b11a07a7f7eac5e49b565cb041b13
DIFF: 
https://github.com/llvm/llvm-project/commit/0bf4a82a5a2b11a07a7f7eac5e49b565cb041b13.diff

LOG: [mlir] Use mlir::OpState::operator->() to get to methods of 
mlir::Operation. This is a preparation step to remove the corresponding methods 
from OpState.

Reviewed By: silvas, rriddle

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

Added: 


Modified: 
flang/include/flang/Optimizer/Dialect/FIROps.td
mlir/examples/toy/Ch2/mlir/Dialect.cpp
mlir/examples/toy/Ch3/mlir/Dialect.cpp
mlir/examples/toy/Ch4/mlir/Dialect.cpp
mlir/examples/toy/Ch5/mlir/Dialect.cpp
mlir/examples/toy/Ch6/mlir/Dialect.cpp
mlir/examples/toy/Ch7/mlir/Dialect.cpp
mlir/include/mlir/Dialect/GPU/GPUOps.td
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
mlir/include/mlir/Dialect/StandardOps/IR/Ops.h
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/include/mlir/Dialect/Vector/VectorOps.td
mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/lib/Conversion/GPUToVulkan/ConvertLaunchFuncToVulkanCalls.cpp
mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp
mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp
mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
mlir/lib/Dialect/Affine/Utils/Utils.cpp
mlir/lib/Dialect/Async/IR/Async.cpp
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp
mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp
mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
mlir/lib/Dialect/PDL/IR/PDL.cpp
mlir/lib/Dialect/SCF/SCF.cpp
mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
mlir/lib/Dialect/SCF/Transforms/Utils.cpp
mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
mlir/lib/Dialect/SPIRV/Transforms/DecorateSPIRVCompositeTypeLayoutPass.cpp
mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/lib/Dialect/Shape/Transforms/ShapeToShapeLowering.cpp
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/lib/Dialect/Vector/VectorTransferOpTransforms.cpp
mlir/lib/Dialect/Vector/VectorTransforms.cpp
mlir/lib/Target/LLVMIR/ConvertToROCDLIR.cpp
mlir/lib/Transforms/Inliner.cpp
mlir/lib/Transforms/LoopCoalescing.cpp
mlir/lib/Transforms/Utils/InliningUtils.cpp
mlir/lib/Transforms/Utils/LoopFusionUtils.cpp
mlir/lib/Transforms/Utils/LoopUtils.cpp
mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp
mlir/test/lib/Dialect/Test/TestDialect.cpp
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/lib/Dialect/Test/TestPatterns.cpp
mlir/test/lib/IR/TestFunc.cpp
mlir/test/lib/Transforms/TestAffineLoopParametricTiling.cpp
mlir/test/lib/Transforms/TestLinalgFusionTransforms.cpp
mlir/test/lib/Transforms/TestLoopMapping.cpp
mlir/test/lib/Transforms/TestLoopParametricTiling.cpp
mlir/test/mlir-tblgen/op-attribute.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Removed: 




diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.td 
b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 74471cf6f222..9f477aa81b0c 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -270,7 +270,7 @@ class fir_AllocatableOp 
traits = []> :
 bool hasLenParams() { return bool{getAttr(lenpName())}; }
 
 unsigned numLenParams() {
-  if (auto val = getAttrOfType(lenpName()))
+  if (auto val = (*this)->getAttrOfType(lenpName()))
 return val.getInt();
   return 0;
 }
@@ -291,7 +291,7 @@ class fir_AllocatableOp 
traits = []> :
 
 /// Get the input type of the allocation
 mlir::Type getInType() {
-  return getAttrOfType(inType()).getValue();
+  return (*this)->getAttrOfType(inType()).getValue();
 }
   }];
 
@@ -567,7 +567,7 @@ class fir_SwitchTerminatorOp 
traits = []> :
 
 // The number of destination conditions that may be tested
 unsigned getNu

[llvm-branch-commits] [flang] 1ffc1aa - [mlir] Use mlir::OpState::operator->() to get to methods of mlir::Operation.

2020-12-13 Thread Christian Sigg via llvm-branch-commits

Author: Christian Sigg
Date: 2020-12-13T09:58:16+01:00
New Revision: 1ffc1aaa09674824ce66600ee0b77d6a2c042e68

URL: 
https://github.com/llvm/llvm-project/commit/1ffc1aaa09674824ce66600ee0b77d6a2c042e68
DIFF: 
https://github.com/llvm/llvm-project/commit/1ffc1aaa09674824ce66600ee0b77d6a2c042e68.diff

LOG: [mlir] Use mlir::OpState::operator->() to get to methods of 
mlir::Operation.

This is a preparation step to remove those methods from OpState.

Reviewed By: mehdi_amini

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

Added: 


Modified: 
flang/include/flang/Optimizer/Dialect/FIROps.td
mlir/include/mlir/Dialect/Affine/IR/AffineOps.h
mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/include/mlir/IR/FunctionSupport.h
mlir/include/mlir/IR/Operation.h
mlir/include/mlir/IR/SymbolInterfaces.td
mlir/lib/Analysis/Utils.cpp
mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp
mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp
mlir/lib/Conversion/GPUToVulkan/ConvertGPULaunchFuncToVulkanLaunchFunc.cpp
mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp
mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
mlir/lib/Dialect/Affine/Utils/Utils.cpp
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp
mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/lib/Dialect/Linalg/Transforms/Interchange.cpp
mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp
mlir/lib/Dialect/Vector/VectorOps.cpp
mlir/lib/Dialect/Vector/VectorTransforms.cpp
mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp
mlir/test/lib/Dialect/Test/TestDialect.cpp
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/lib/Dialect/Test/TestPatterns.cpp
mlir/test/lib/Transforms/TestCallGraph.cpp
mlir/test/mlir-tblgen/op-attribute.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/tools/mlir-tblgen/OpFormatGen.cpp
mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp

Removed: 




diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.td 
b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 9f477aa81b0c..4ffca0395804 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -2700,7 +2700,7 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, 
Symbol]> {
 p.printAttributeWithoutType(getAttr(symbolAttrName()));
 if (auto val = getValueOrNull())
   p << '(' << val << ')';
-if (getAttr(constantAttrName()))
+if ((*this)->getAttr(constantAttrName()))
   p << " constant";
 p << " : ";
 p.printType(getType());

diff  --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h 
b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h
index c4bed26bfc29..b097f18e8cea 100644
--- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h
+++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h
@@ -107,7 +107,7 @@ class AffineDmaStartOp
   /// Returns the affine map used to access the src memref.
   AffineMap getSrcMap() { return getSrcMapAttr().getValue(); }
   AffineMapAttr getSrcMapAttr() {
-return getAttr(getSrcMapAttrName()).cast();
+return (*this)->getAttr(getSrcMapAttrName()).cast();
   }
 
   /// Returns the source memref affine map indices for this DMA operation.
@@ -146,7 +146,7 @@ class AffineDmaStartOp
   /// Returns the affine map used to access the dst memref.
   AffineMap getDstMap() { return getDstMapAttr().getValue(); }
   AffineMapAttr getDstMapAttr() {
-return getAttr(getDstMapAttrName()).cast();
+return (*this)->getAttr(getDstMapAttrName()).cast();
   }
 
   /// Returns the destination memref indices for this DMA operation.
@@ -175,7 +175,7 @@ class AffineDmaStartOp
   /// Returns the affine map used to access the tag memref.
   AffineMap getTagMap() { return getTagMapAttr().getValue(); }
   AffineMapAttr getTagMapAttr() {
-return getAttr(getTagMapAttrName()).cast();
+return (*this)->getAttr(getTagMapAttrName()).cast();
   }
 
   /// Returns the tag memref indices for this DMA operation.
@@ -289,7 +289,7 @@ class AffineDmaWaitOp
   /// Returns the affine map used to access the tag memref.
   AffineMap getTagMap() { return getTagMapAttr().getValue(); }
   AffineMapAttr getTagMapAttr() {
-return getAttr(getTagMapAttrName()).cast();
+return (*this)->getAttr(getTagMapAttrName()).cast();
   }
 
   // Returns the tag memref index f