CIRCT  20.0.0git
DependenceAnalysis.h
Go to the documentation of this file.
1 //===- DependenceAnalysis.h - memory dependence analyses ------------------===//
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 header file defines prototypes for methods that perform analysis
10 // involving memory access dependences.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef CIRCT_ANALYSIS_DEPENDENCE_ANALYSIS_H
15 #define CIRCT_ANALYSIS_DEPENDENCE_ANALYSIS_H
16 
17 #include "circt/Support/LLVM.h"
18 #include "mlir/Dialect/Affine/Analysis/AffineAnalysis.h"
19 #include <utility>
20 
21 namespace mlir {
22 namespace affine {
23 struct DependenceComponent;
24 } // namespace affine
25 namespace func {
26 class FuncOp;
27 } // namespace func
28 } // namespace mlir
29 
30 namespace circt {
31 namespace analysis {
32 
33 /// MemoryDependence captures a dependence from one memory operation to another.
34 /// It represents the destination of the dependence edge, the type of the
35 /// dependence, and the components associated with each enclosing loop.
38  Operation *source,
39  mlir::affine::DependenceResult::ResultEnum dependenceType,
40  ArrayRef<mlir::affine::DependenceComponent> dependenceComponents)
43  dependenceComponents.end()) {}
44 
45  // The source Operation where this dependence originates.
46  Operation *source;
47 
48  // The dependence type denotes whether or not there is a dependence.
49  mlir::affine::DependenceResult::ResultEnum dependenceType;
50 
51  // The dependence components include lower and upper bounds for each loop.
52  SmallVector<mlir::affine::DependenceComponent> dependenceComponents;
53 };
54 
55 /// MemoryDependenceResult captures a set of memory dependences. The map key is
56 /// the operation to which the dependences exist, and the map value is zero or
57 /// more MemoryDependences for that operation.
59  DenseMap<Operation *, SmallVector<MemoryDependence>>;
60 
61 /// MemoryDependenceAnalysis traverses any AffineForOps in the FuncOp body and
62 /// checks for affine memory access dependences. Non-affine memory dependences
63 /// are currently not supported. Results are captured in a
64 /// MemoryDependenceResult, and an API is exposed to query dependences of a
65 /// given Operation.
66 /// TODO(mikeurbach): consider upstreaming this to MLIR's AffineAnalysis.
68  // Construct the analysis from a FuncOp.
69  MemoryDependenceAnalysis(Operation *funcOp);
70 
71  // Returns the dependences, if any, that the given Operation depends on.
72  ArrayRef<MemoryDependence> getDependences(Operation *);
73 
74  // Replaces the dependences, if any, from the oldOp to the newOp.
75  void replaceOp(Operation *oldOp, Operation *newOp);
76 
77 private:
78  // Store dependence results.
80 };
81 
82 } // namespace analysis
83 } // namespace circt
84 
85 #endif // CIRCT_ANALYSIS_DEPENDENCE_ANALYSIS_H
DenseMap< Operation *, SmallVector< MemoryDependence > > MemoryDependenceResult
MemoryDependenceResult captures a set of memory dependences.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
MemoryDependenceAnalysis traverses any AffineForOps in the FuncOp body and checks for affine memory a...
MemoryDependenceAnalysis(Operation *funcOp)
MemoryDependenceAnalysis traverses any AffineForOps in the FuncOp body and checks for memory access d...
void replaceOp(Operation *oldOp, Operation *newOp)
Replaces the dependences, if any, from the oldOp to the newOp.
ArrayRef< MemoryDependence > getDependences(Operation *)
Returns the dependences, if any, that the given Operation depends on.
MemoryDependence captures a dependence from one memory operation to another.
SmallVector< mlir::affine::DependenceComponent > dependenceComponents
mlir::affine::DependenceResult::ResultEnum dependenceType
MemoryDependence(Operation *source, mlir::affine::DependenceResult::ResultEnum dependenceType, ArrayRef< mlir::affine::DependenceComponent > dependenceComponents)