My Project
AffineAnalysis.h
Go to the documentation of this file.
1 //===- AffineAnalysis.h - analyses for affine structures --------*- 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 methods that perform analysis
10 // involving affine structures (AffineExprStorage, AffineMap, IntegerSet, etc.)
11 // and other IR structures that in turn use these.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef MLIR_ANALYSIS_AFFINE_ANALYSIS_H
16 #define MLIR_ANALYSIS_AFFINE_ANALYSIS_H
17 
18 #include "mlir/IR/Value.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SmallVector.h"
21 
22 namespace mlir {
23 
24 class AffineApplyOp;
25 class AffineForOp;
26 class AffineValueMap;
27 class FlatAffineConstraints;
28 class Operation;
29 
33 void getReachableAffineApplyOps(ArrayRef<Value> operands,
34  SmallVectorImpl<Operation *> &affineApplyOps);
35 
41 // TODO(bondhugula): handle non-unit strides.
42 LogicalResult getIndexSet(MutableArrayRef<AffineForOp> forOps,
43  FlatAffineConstraints *domain);
44 
46 struct MemRefAccess {
50 
52  // TODO(b/119949820): add accessors to standard op's load, store, DMA op's to
53  // return MemRefAccess, i.e., loadOp->getAccess(), dmaOp->getRead/WriteAccess.
54  explicit MemRefAccess(Operation *opInst);
55 
56  // Returns the rank of the memref associated with this access.
57  unsigned getRank() const;
58  // Returns true if this access is of a store op.
59  bool isStore() const;
60 
63  void getAccessMap(AffineValueMap *accessMap) const;
64 
71  bool operator==(const MemRefAccess &rhs) const;
72  bool operator!=(const MemRefAccess &rhs) const { return !(*this == rhs); }
73 };
74 
75 // DependenceComponent contains state about the direction of a dependence as an
76 // interval [lb, ub] for an AffineForOp.
77 // Distance vectors components are represented by the interval [lb, ub] with
78 // lb == ub.
79 // Direction vectors components are represented by the interval [lb, ub] with
80 // lb < ub. Note that ub/lb == None means unbounded.
82  // The AffineForOp Operation associated with this dependence component.
84  // The lower bound of the dependence distance.
86  // The upper bound of the dependence distance (inclusive).
89 };
90 
98 // TODO(andydavis) Wrap 'dependenceConstraints' and 'dependenceComponents' into
99 // a single struct.
100 // TODO(andydavis) Make 'dependenceConstraints' optional arg.
102  enum ResultEnum {
103  HasDependence, // A dependence exists between 'srcAccess' and 'dstAccess'.
104  NoDependence, // No dependence exists between 'srcAccess' and 'dstAccess'.
105  Failure, // Dependence check failed due to unsupported cases.
106  } value;
107  DependenceResult(ResultEnum v) : value(v) {}
108 };
109 
111  const MemRefAccess &srcAccess, const MemRefAccess &dstAccess,
112  unsigned loopDepth, FlatAffineConstraints *dependenceConstraints,
113  SmallVector<DependenceComponent, 2> *dependenceComponents,
114  bool allowRAR = false);
115 
118 inline bool hasDependence(DependenceResult result) {
119  return result.value == DependenceResult::HasDependence;
120 }
121 
126  AffineForOp forOp, unsigned maxLoopDepth,
127  std::vector<SmallVector<DependenceComponent, 2>> *depCompsVec);
128 
129 } // end namespace mlir
130 
131 #endif // MLIR_ANALYSIS_AFFINE_ANALYSIS_H
Definition: InferTypeOpInterface.cpp:20
void getDependenceComponents(AffineForOp forOp, unsigned maxLoopDepth, std::vector< SmallVector< DependenceComponent, 2 >> *depCompsVec)
Definition: AffineAnalysis.cpp:856
Definition: PassRegistry.cpp:413
Definition: Operation.h:27
bool operator==(const MemRefAccess &rhs) const
Definition: Utils.cpp:880
Optional< int64_t > lb
Definition: AffineAnalysis.h:85
void getAccessMap(AffineValueMap *accessMap) const
Definition: AffineAnalysis.cpp:662
Definition: LLVM.h:40
Definition: AffineAnalysis.h:101
Definition: AffineStructures.h:229
bool operator!=(const MemRefAccess &rhs) const
Definition: AffineAnalysis.h:72
bool hasDependence(DependenceResult result)
Definition: AffineAnalysis.h:118
DependenceResult checkMemrefAccessDependence(const MemRefAccess &srcAccess, const MemRefAccess &dstAccess, unsigned loopDepth, FlatAffineConstraints *dependenceConstraints, SmallVector< DependenceComponent, 2 > *dependenceComponents, bool allowRAR=false)
Definition: AffineAnalysis.cpp:763
LogicalResult getIndexSet(MutableArrayRef< AffineForOp > forOps, FlatAffineConstraints *domain)
Definition: AffineAnalysis.cpp:91
enum mlir::DependenceResult::ResultEnum value
unsigned getRank() const
Definition: Utils.cpp:856
Definition: AffineAnalysis.h:105
SmallVector< Value, 4 > indices
Definition: AffineAnalysis.h:49
DependenceComponent()
Definition: AffineAnalysis.h:88
MemRefAccess(Operation *opInst)
Constructs a MemRefAccess from a load or store operation.
Definition: Utils.cpp:834
Definition: Value.h:38
Definition: LLVM.h:35
bool isStore() const
Definition: Utils.cpp:860
DependenceResult(ResultEnum v)
Definition: AffineAnalysis.h:107
Definition: AffineAnalysis.h:81
Definition: AffineAnalysis.h:103
Definition: AffineAnalysis.h:104
Optional< int64_t > ub
Definition: AffineAnalysis.h:87
Value memref
Definition: AffineAnalysis.h:47
Encapsulates a memref load or store access information.
Definition: AffineAnalysis.h:46
Definition: StandardTypes.h:63
Definition: AffineStructures.h:112
ResultEnum
Definition: AffineAnalysis.h:102
void getReachableAffineApplyOps(ArrayRef< Value > operands, SmallVectorImpl< Operation *> &affineApplyOps)
Definition: AffineAnalysis.cpp:41
Operation * op
Definition: AffineAnalysis.h:83
Operation * opInst
Definition: AffineAnalysis.h:48