1//===- LoopLikeInterface.td - LoopLike 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 loop-like operations.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_INTERFACES_LOOPLIKEINTERFACE
14#define MLIR_INTERFACES_LOOPLIKEINTERFACE
15
16include "mlir/IR/OpBase.td"
17
18def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
19  let description = [{
20    Encodes properties of a loop. Operations that implement this interface will
21    be considered by loop-invariant code motion.
22  }];
23  let cppNamespace = "::mlir";
24
25  let methods = [
26    InterfaceMethod<[{
27        Returns true if the given value is defined outside of the loop.
28        A sensible implementation could be to check whether the value's defining
29        operation lies outside of the loops body region. If the loop uses
30        explicit capture of dependencies, an implementation could check whether
31        the value corresponds to a captured dependency.
32      }],
33      "bool", "isDefinedOutsideOfLoop", (ins "::mlir::Value ":$value), [{}], [{
34        return value.getParentRegion()->isProperAncestor(&$_op.getLoopBody());
35      }]
36    >,
37    InterfaceMethod<[{
38        Returns the region that makes up the body of the loop and should be
39        inspected for loop-invariant operations.
40      }],
41      "::mlir::Region &", "getLoopBody"
42    >,
43    InterfaceMethod<[{
44        Moves the given loop-invariant operation out of the loop.
45      }],
46      "void", "moveOutOfLoop",
47      (ins "::mlir::Operation *":$op), [{}], [{
48        op->moveBefore($_op);
49      }]
50    >,
51    InterfaceMethod<[{
52        If there is a single induction variable return it, otherwise return
53        llvm::None.
54      }],
55      /*retTy=*/"::llvm::Optional<::mlir::Value>",
56      /*methodName=*/"getSingleInductionVar",
57      /*args=*/(ins),
58      /*methodBody=*/"",
59      /*defaultImplementation=*/[{
60        return llvm::None;
61      }]
62    >,
63    InterfaceMethod<[{
64        Return the single lower bound value or attribute if it exists, otherwise
65        return llvm::None.
66      }],
67      /*retTy=*/"::llvm::Optional<::mlir::OpFoldResult>",
68      /*methodName=*/"getSingleLowerBound",
69      /*args=*/(ins),
70      /*methodBody=*/"",
71      /*defaultImplementation=*/[{
72        return llvm::None;
73      }]
74    >,
75    InterfaceMethod<[{
76        Return the single step value or attribute if it exists, otherwise
77        return llvm::None.
78      }],
79      /*retTy=*/"::llvm::Optional<::mlir::OpFoldResult>",
80      /*methodName=*/"getSingleStep",
81      /*args=*/(ins),
82      /*methodBody=*/"",
83      /*defaultImplementation=*/[{
84        return llvm::None;
85      }]
86    >,
87    InterfaceMethod<[{
88        Return the single upper bound value or attribute if it exists, otherwise
89        return llvm::None.
90      }],
91      /*retTy=*/"::llvm::Optional<::mlir::OpFoldResult>",
92      /*methodName=*/"getSingleUpperBound",
93      /*args=*/(ins),
94      /*methodBody=*/"",
95      /*defaultImplementation=*/[{
96        return llvm::None;
97      }]
98    >,
99  ];
100}
101
102#endif // MLIR_INTERFACES_LOOPLIKEINTERFACE
103