[Mlir-commits] [mlir] 235eed2 - [MLIR][LLVM] Allow inlining noalias attributes.
Johannes de Fine Licht
llvmlistbot at llvm.org
Mon May 22 05:00:10 PDT 2023
Author: Johannes de Fine Licht
Date: 2023-05-22T11:55:06Z
New Revision: 235eed2646585e5a5328e0e63b18497f8f6d17a3
URL: https://github.com/llvm/llvm-project/commit/235eed2646585e5a5328e0e63b18497f8f6d17a3
DIFF: https://github.com/llvm/llvm-project/commit/235eed2646585e5a5328e0e63b18497f8f6d17a3.diff
LOG: [MLIR][LLVM] Allow inlining noalias attributes.
We can not yet generate new aliasing metadata based on these arguments
because their global nature does not allow parallel inlining, but since
this is not necessary for correctness, we allow inlining functions that
have arguments with the noalias attribute for now.
Reviewed By: gysit
Differential Revision: https://reviews.llvm.org/D151067
Added:
Modified:
mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
mlir/test/Dialect/LLVMIR/inlining.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
index 0c27d0fc2e2d7..f5a4e3a7ca698 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
@@ -245,16 +245,6 @@ static Value handleByValArgument(OpBuilder &builder, Operation *callable,
targetAlignment);
}
-/// Returns true if the given argument or result attribute is supported by the
-/// inliner, false otherwise.
-static bool isArgOrResAttrSupported(NamedAttribute attr) {
- if (attr.getName() == LLVM::LLVMDialect::getInAllocaAttrName())
- return false;
- if (attr.getName() == LLVM::LLVMDialect::getNoAliasAttrName())
- return false;
- return true;
-}
-
namespace {
struct LLVMInlinerInterface : public DialectInlinerInterface {
using DialectInlinerInterface::DialectInlinerInterface;
@@ -287,27 +277,13 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
<< "Cannot inline: callable is not an LLVM::LLVMFuncOp\n");
return false;
}
+ // TODO: Generate aliasing metadata from noalias argument/result attributes.
if (auto attrs = funcOp.getArgAttrs()) {
for (DictionaryAttr attrDict : attrs->getAsRange<DictionaryAttr>()) {
- for (NamedAttribute attr : attrDict) {
- if (!isArgOrResAttrSupported(attr)) {
- LLVM_DEBUG(llvm::dbgs() << "Cannot inline " << funcOp.getSymName()
- << ": unhandled argument attribute "
- << attr.getName() << "\n");
- return false;
- }
- }
- }
- }
- if (auto attrs = funcOp.getResAttrs()) {
- for (DictionaryAttr attrDict : attrs->getAsRange<DictionaryAttr>()) {
- for (NamedAttribute attr : attrDict) {
- if (!isArgOrResAttrSupported(attr)) {
- LLVM_DEBUG(llvm::dbgs() << "Cannot inline " << funcOp.getSymName()
- << ": unhandled return attribute "
- << attr.getName() << "\n");
- return false;
- }
+ if (attrDict.contains(LLVM::LLVMDialect::getInAllocaAttrName())) {
+ LLVM_DEBUG(llvm::dbgs() << "Cannot inline " << funcOp.getSymName()
+ << ": inalloca arguments not supported\n");
+ return false;
}
}
}
diff --git a/mlir/test/Dialect/LLVMIR/inlining.mlir b/mlir/test/Dialect/LLVMIR/inlining.mlir
index 14866d45c9acc..564c1908e0920 100644
--- a/mlir/test/Dialect/LLVMIR/inlining.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining.mlir
@@ -564,7 +564,7 @@ llvm.func @test_byval_global() {
// -----
-llvm.func @ignored_attrs(%ptr : !llvm.ptr { llvm.inreg, llvm.nocapture, llvm.nofree, llvm.preallocated = i32, llvm.returned, llvm.alignstack = 32 : i64, llvm.writeonly, llvm.noundef, llvm.nonnull }, %x : i32 { llvm.zeroext }) -> (!llvm.ptr { llvm.noundef, llvm.inreg, llvm.nonnull }) {
+llvm.func @ignored_attrs(%ptr : !llvm.ptr { llvm.inreg, llvm.noalias, llvm.nocapture, llvm.nofree, llvm.preallocated = i32, llvm.returned, llvm.alignstack = 32 : i64, llvm.writeonly, llvm.noundef, llvm.nonnull }, %x : i32 { llvm.zeroext }) -> (!llvm.ptr { llvm.noundef, llvm.inreg, llvm.nonnull }) {
llvm.return %ptr : !llvm.ptr
}
@@ -578,7 +578,7 @@ llvm.func @test_ignored_attrs(%ptr : !llvm.ptr, %x : i32) {
// -----
-llvm.func @disallowed_arg_attr(%ptr : !llvm.ptr { llvm.noalias }) {
+llvm.func @disallowed_arg_attr(%ptr : !llvm.ptr { llvm.inalloca = i64 }) {
llvm.return
}
@@ -588,16 +588,3 @@ llvm.func @test_disallow_arg_attr(%ptr : !llvm.ptr) {
llvm.call @disallowed_arg_attr(%ptr) : (!llvm.ptr) -> ()
llvm.return
}
-
-// -----
-
-llvm.func @disallowed_res_attr(%ptr : !llvm.ptr) -> (!llvm.ptr { llvm.noalias }) {
- llvm.return %ptr : !llvm.ptr
-}
-
-// CHECK-LABEL: @test_disallow_res_attr
-// CHECK-NEXT: llvm.call
-llvm.func @test_disallow_res_attr(%ptr : !llvm.ptr) {
- llvm.call @disallowed_res_attr(%ptr) : (!llvm.ptr) -> (!llvm.ptr)
- llvm.return
-}
More information about the Mlir-commits
mailing list