Skip to content

Commit 0432d91

Browse files
introduce UnrollScopeInterface and apply it to funcOp and gpu.launch Op.
1 parent 814b34f commit 0432d91

File tree

12 files changed

+150
-6
lines changed

12 files changed

+150
-6
lines changed

mlir/include/mlir/Dialect/Func/IR/FuncOps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "mlir/Interfaces/FunctionInterfaces.h"
2121
#include "mlir/Interfaces/InferTypeOpInterface.h"
2222
#include "mlir/Interfaces/SideEffectInterfaces.h"
23+
#include "mlir/Interfaces/UnrollScopeInterface.h"
2324

2425
namespace mlir {
2526
class PatternRewriter;

mlir/include/mlir/Dialect/Func/IR/FuncOps.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include "mlir/Interfaces/ControlFlowInterfaces.td"
1717
include "mlir/Interfaces/FunctionInterfaces.td"
1818
include "mlir/Interfaces/InferTypeOpInterface.td"
1919
include "mlir/Interfaces/SideEffectInterfaces.td"
20+
include "mlir/Interfaces/UnrollScopeInterface.td"
2021

2122
def Func_Dialect : Dialect {
2223
let name = "func";
@@ -225,8 +226,8 @@ def ConstantOp : Func_Op<"constant",
225226
//===----------------------------------------------------------------------===//
226227

227228
def FuncOp : Func_Op<"func", [
228-
AffineScope, AutomaticAllocationScope,
229-
FunctionOpInterface, IsolatedFromAbove, OpAsmOpInterface
229+
AffineScope, AutomaticAllocationScope, FunctionOpInterface,
230+
IsolatedFromAbove, OpAsmOpInterface, UnrollScopeInterface
230231
]> {
231232
let summary = "An operation with a name containing a single `SSACFG` region";
232233
let description = [{

mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "mlir/Interfaces/InferIntRangeInterface.h"
3030
#include "mlir/Interfaces/InferTypeOpInterface.h"
3131
#include "mlir/Interfaces/SideEffectInterfaces.h"
32+
#include "mlir/Interfaces/UnrollScopeInterface.h"
3233
#include "llvm/ADT/STLExtras.h"
3334

3435
namespace mlir {

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ include "mlir/Interfaces/FunctionInterfaces.td"
3030
include "mlir/Interfaces/InferIntRangeInterface.td"
3131
include "mlir/Interfaces/InferTypeOpInterface.td"
3232
include "mlir/Interfaces/SideEffectInterfaces.td"
33+
include "mlir/Interfaces/UnrollScopeInterface.td"
3334

3435
//===----------------------------------------------------------------------===//
3536
// GPU Dialect operations.
@@ -796,7 +797,7 @@ def GPU_LaunchFuncOp :GPU_Op<"launch_func", [
796797
def GPU_LaunchOp : GPU_Op<"launch", [
797798
AutomaticAllocationScope, AttrSizedOperandSegments, GPU_AsyncOpInterface,
798799
DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>,
799-
RecursiveMemoryEffects]>,
800+
RecursiveMemoryEffects, UnrollScopeInterface]>,
800801
Arguments<(ins Variadic<GPU_AsyncToken>:$asyncDependencies,
801802
Index:$gridSizeX, Index:$gridSizeY, Index:$gridSizeZ,
802803
Index:$blockSizeX, Index:$blockSizeY, Index:$blockSizeZ,

mlir/include/mlir/Interfaces/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_mlir_interface(TilingInterface)
1717
add_mlir_interface(ValueBoundsOpInterface)
1818
add_mlir_interface(VectorInterfaces)
1919
add_mlir_interface(ViewLikeInterface)
20+
add_mlir_interface(UnrollScopeInterface)
2021

2122
set(LLVM_TARGET_DEFINITIONS MemorySlotInterfaces.td)
2223
mlir_tablegen(MemorySlotOpInterfaces.h.inc -gen-op-interface-decls)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===- UnrollScopeInterface.h - unroll region interface -------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file implements the operation interface for unroll region
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_INTERFACES_UNROLLSCOPEINTERFACE_H_
14+
#define MLIR_INTERFACES_UNROLLSCOPEINTERFACE_H_
15+
16+
#include "mlir/IR/OpDefinition.h"
17+
18+
/// Include the generated interface declarations.
19+
#include "mlir/Interfaces/UnrollScopeInterface.h.inc"
20+
21+
#endif // MLIR_INTERFACES_UNROLLSCOPEINTERFACE_H_
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===- UnrollScopeInterface.td - unroll scope interface ----*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Defines the interface for unroll region.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_INTERFACES_UNROLLSCOPEINTERFACE
14+
#define MLIR_INTERFACES_UNROLLSCOPEINTERFACE
15+
16+
include "mlir/IR/OpBase.td"
17+
18+
def UnrollScopeInterface : OpInterface<"UnrollScopeInterface"> {
19+
let description = [{
20+
This interface controls the scope of the loop unroll.It ensures
21+
that SSA values generated outside the loop when unrolling are
22+
in the nearest `UnrollScopeInterface` region.
23+
}];
24+
let cppNamespace = "::mlir";
25+
let methods = [
26+
InterfaceMethod<[{
27+
return the `UnrollScopeInterface` region.
28+
}],
29+
"::mlir::Region&", "getUnrollBody", (ins),
30+
/*methodBody=*/[{}], /*defaultImplementation=*/[{
31+
return $_op->getRegion(0);
32+
}]>,
33+
];
34+
}
35+
36+
#endif // MLIR_INTERFACES_UNROLLSCOPEINTERFACE

mlir/lib/Dialect/Affine/Utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ add_mlir_dialect_library(MLIRAffineUtils
1616
MLIRMemRefDialect
1717
MLIRTransformUtils
1818
MLIRViewLikeInterface
19+
MLIRUnrollScopeInterface
1920
)

mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "mlir/Dialect/SCF/IR/SCF.h"
2222
#include "mlir/IR/IRMapping.h"
2323
#include "mlir/IR/IntegerSet.h"
24+
#include "mlir/Interfaces/UnrollScopeInterface.h"
2425
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2526
#include "llvm/ADT/MapVector.h"
2627
#include "llvm/ADT/SmallPtrSet.h"
@@ -129,10 +130,10 @@ LogicalResult mlir::affine::promoteIfSingleIteration(AffineForOp forOp) {
129130
auto *parentBlock = forOp->getBlock();
130131
if (!iv.use_empty()) {
131132
if (forOp.hasConstantLowerBound()) {
132-
auto func = forOp->getParentOfType<FunctionOpInterface>();
133+
auto unrollScope = forOp->getParentOfType<UnrollScopeInterface>();
133134
OpBuilder builder(forOp->getContext());
134-
if (func)
135-
builder.setInsertionPointToStart(&func.getFunctionBody().front());
135+
if (unrollScope)
136+
builder.setInsertionPointToStart(&unrollScope.getUnrollBody().front());
136137
else
137138
builder.setInsertionPoint(forOp);
138139
auto constOp = builder.create<arith::ConstantIndexOp>(

mlir/lib/Interfaces/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(LLVM_OPTIONAL_SOURCES
2121
ValueBoundsOpInterface.cpp
2222
VectorInterfaces.cpp
2323
ViewLikeInterface.cpp
24+
UnrollScopeInterface.cpp
2425
)
2526

2627
function(add_mlir_interface_library name)
@@ -46,6 +47,7 @@ add_mlir_interface_library(CopyOpInterface)
4647
add_mlir_interface_library(DataLayoutInterfaces)
4748
add_mlir_interface_library(DerivedAttributeOpInterface)
4849
add_mlir_interface_library(DestinationStyleOpInterface)
50+
add_mlir_interface_library(UnrollScopeInterface)
4951

5052
add_mlir_library(MLIRFunctionInterfaces
5153
FunctionInterfaces.cpp

0 commit comments

Comments
 (0)