Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][linalg] ValueBoundsOpInterface: Add LinalgOps
Also add a few more complex test cases. Differential Revision: https://reviews.llvm.org/D145806
- Loading branch information
1 parent
10dbf23
commit edc8b60
Showing
7 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
mlir/include/mlir/Dialect/Linalg/IR/ValueBoundsOpInterfaceImpl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===- ValueBoundsOpInterfaceImpl.h - Impl. of ValueBoundsOpInterface -----===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_LINALG_IR_VALUEBOUNDSOPINTERFACEIMPL_H | ||
#define MLIR_DIALECT_LINALG_IR_VALUEBOUNDSOPINTERFACEIMPL_H | ||
|
||
namespace mlir { | ||
class DialectRegistry; | ||
|
||
namespace linalg { | ||
void registerValueBoundsOpInterfaceExternalModels(DialectRegistry ®istry); | ||
} // namespace linalg | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_LINALG_IR_VALUEBOUNDSOPINTERFACEIMPL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===- ValueBoundsOpInterfaceImpl.cpp - Impl. of ValueBoundsOpInterface ---===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/Dialect/Linalg/IR/ValueBoundsOpInterfaceImpl.h" | ||
|
||
#include "mlir/Dialect/Linalg/IR/Linalg.h" | ||
#include "mlir/Interfaces/ValueBoundsOpInterface.h" | ||
|
||
using namespace mlir; | ||
|
||
namespace mlir { | ||
namespace linalg { | ||
namespace { | ||
|
||
/// Helper structure that iterates over all LinalgOps in `OpTys` and registers | ||
/// the `ValueBoundsOpInterface` with each of them. | ||
template <typename... Ops> struct LinalgValueBoundsOpInterfaceHelper { | ||
static void registerOpInterface(MLIRContext *ctx) { | ||
(Ops::template attachInterface<DstValueBoundsOpInterfaceExternalModel<Ops>>( | ||
*ctx), | ||
...); | ||
} | ||
}; | ||
|
||
} // namespace | ||
} // namespace linalg | ||
} // namespace mlir | ||
|
||
void mlir::linalg::registerValueBoundsOpInterfaceExternalModels( | ||
DialectRegistry ®istry) { | ||
registry.addExtension(+[](MLIRContext *ctx, linalg::LinalgDialect *dialect) { | ||
// Register all Linalg structured ops. | ||
LinalgValueBoundsOpInterfaceHelper< | ||
#define GET_OP_LIST | ||
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc" | ||
>::registerOpInterface(ctx); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
mlir/test/Dialect/Linalg/value-bounds-op-interface-impl.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// RUN: mlir-opt %s -test-affine-reify-value-bounds -verify-diagnostics \ | ||
// RUN: -split-input-file | FileCheck %s | ||
|
||
// CHECK-LABEL: func @linalg_fill( | ||
// CHECK-SAME: %[[t:.*]]: tensor<?xf32> | ||
// CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
// CHECK: %[[dim:.*]] = tensor.dim %[[t]], %[[c0]] | ||
// CHECK: return %[[dim]] | ||
func.func @linalg_fill(%t: tensor<?xf32>, %f: f32) -> index { | ||
%0 = linalg.fill ins(%f : f32) outs(%t : tensor<?xf32>) -> tensor<?xf32> | ||
%1 = "test.reify_bound"(%0) {dim = 0} : (tensor<?xf32>) -> (index) | ||
return %1 : index | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters