My Project
Utils.h
Go to the documentation of this file.
1 //===- Utils.h - General transformation utilities ---------------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 header file defines prototypes for various transformation utilities for
10 // memref's and non-loop IR structures. These are not passes by themselves but
11 // are used either by passes, optimization sequences, or in turn by other
12 // transformation utilities.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef MLIR_TRANSFORMS_UTILS_H
17 #define MLIR_TRANSFORMS_UTILS_H
18 
20 #include "mlir/IR/AffineMap.h"
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 
24 namespace mlir {
25 
26 class AffineApplyOp;
27 class AffineForOp;
28 class Location;
29 class OpBuilder;
30 
52 //
53 // Ex: to replace load %A[%i, %j] with load %Abuf[%t mod 2, %ii - %i, %j]:
54 // The SSA value corresponding to '%t mod 2' should be in 'extraIndices', and
55 // index remap will perform (%i, %j) -> (%ii - %i, %j), i.e., indexRemap = (d0,
56 // d1, d2) -> (d0 - d1, d2), and %ii will be the extra operand. Without any
57 // extra operands, note that 'indexRemap' would just be applied to existing
58 // indices (%i, %j).
59 // TODO(bondhugula): allow extraIndices to be added at any position.
60 LogicalResult replaceAllMemRefUsesWith(Value oldMemRef, Value newMemRef,
61  ArrayRef<Value> extraIndices = {},
62  AffineMap indexRemap = AffineMap(),
63  ArrayRef<Value> extraOperands = {},
64  ArrayRef<Value> symbolOperands = {},
65  Operation *domInstFilter = nullptr,
66  Operation *postDomInstFilter = nullptr);
67 
70 LogicalResult replaceAllMemRefUsesWith(Value oldMemRef, Value newMemRef,
71  Operation *op,
72  ArrayRef<Value> extraIndices = {},
73  AffineMap indexRemap = AffineMap(),
74  ArrayRef<Value> extraOperands = {},
75  ArrayRef<Value> symbolOperands = {});
76 
80 LogicalResult normalizeMemRef(AllocOp op);
81 
89 Operation *createComposedAffineApplyOp(OpBuilder &builder, Location loc,
90  ArrayRef<Value> operands,
91  ArrayRef<Operation *> affineApplyOps,
92  SmallVectorImpl<Value> *results);
93 
113 
123 void createAffineComputationSlice(Operation *opInst,
124  SmallVectorImpl<AffineApplyOp> *sliceOps);
125 
126 } // end namespace mlir
127 
128 #endif // MLIR_TRANSFORMS_UTILS_H
Definition: InferTypeOpInterface.cpp:20
Definition: Attributes.h:129
LogicalResult replaceAllMemRefUsesWith(Value oldMemRef, Value newMemRef, ArrayRef< Value > extraIndices={}, AffineMap indexRemap=AffineMap(), ArrayRef< Value > extraOperands={}, ArrayRef< Value > symbolOperands={}, Operation *domInstFilter=nullptr, Operation *postDomInstFilter=nullptr)
Definition: Utils.cpp:218
Operation * createComposedAffineApplyOp(OpBuilder &builder, Location loc, ArrayRef< Value > operands, ArrayRef< Operation *> affineApplyOps, SmallVectorImpl< Value > *results)
void createAffineComputationSlice(Operation *opInst, SmallVectorImpl< AffineApplyOp > *sliceOps)
Definition: Utils.cpp:322
LogicalResult normalizeMemRef(AllocOp op)
Definition: Utils.cpp:390