-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathOptimizeRelinearizationAnalysis.h
More file actions
56 lines (48 loc) · 2.32 KB
/
OptimizeRelinearizationAnalysis.h
File metadata and controls
56 lines (48 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef LIB_ANALYSIS_OPTIMIZE_RELINEARIZATIONANALYSIS_H
#define LIB_ANALYSIS_OPTIMIZE_RELINEARIZATIONANALYSIS_H
#include "llvm/include/llvm/ADT/DenseMap.h" // from @llvm-project
#include "mlir/include/mlir/Analysis/DataFlowFramework.h" // from @llvm-project
#include "mlir/include/mlir/IR/Operation.h" // from @llvm-project
#include "mlir/include/mlir/IR/Value.h" // from @llvm-project
#include "mlir/include/mlir/Support/LLVM.h" // from @llvm-project
namespace mlir {
namespace heir {
class OptimizeRelinearizationAnalysis {
public:
OptimizeRelinearizationAnalysis(Operation* op, DataFlowSolver* solver,
bool useLocBasedVariableNames,
bool allowMixedDegreeOperands)
: opToRunOn(op),
solver(solver),
useLocBasedVariableNames(useLocBasedVariableNames),
allowMixedDegreeOperands(allowMixedDegreeOperands) {}
~OptimizeRelinearizationAnalysis() = default;
LogicalResult solve();
// Return true if a relin op should be inserted after the given
// operation, according to the solution to the optimization problem.
bool shouldInsertRelin(Operation* op) const { return solution.lookup(op); }
// Return the key basis degree at the given SSA value, as determined by the
// solution to the optimization problem. When the input value is the result
// of an op, and the model solution suggests a relinearization should be
// inserted after that op, this function returns the pre-relinearization
// degree.
//
// We don't need an "after relin" version because after relin the key basis
// is (1, s), which is degree 1.
int keyBasisDegreeBeforeRelin(Value value) const {
return solutionKeyBasisDegreeBeforeRelin.lookup(value);
}
/// Maps a loop operation to its output degrees (one int per loop result).
/// Populated by the inner solver and read by the outer solver.
llvm::DenseMap<Operation*, SmallVector<int>> loopBoundaryDegrees;
private:
Operation* opToRunOn;
DataFlowSolver* solver;
bool useLocBasedVariableNames;
bool allowMixedDegreeOperands;
llvm::DenseMap<Operation*, bool> solution;
llvm::DenseMap<Value, int> solutionKeyBasisDegreeBeforeRelin;
};
} // namespace heir
} // namespace mlir
#endif // LIB_ANALYSIS_OPTIMIZE_RELINEARIZATIONANALYSIS_H