My Project
IntegerSet.h
Go to the documentation of this file.
1 //===- IntegerSet.h - MLIR Integer Set Class --------------------*- 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 // Integer sets are sets of points from the integer lattice constrained by
10 // affine equality/inequality constraints. This class is meant to represent
11 // integer sets in the IR - for 'affine.if' operations and as attributes of
12 // other operations. It is typically expected to contain only a handful of
13 // affine constraints, and is immutable like an affine map. Integer sets are not
14 // unique'd - although affine expressions that make up its equalities and
15 // inequalities are themselves unique.
16 
17 // This class is not meant for affine analysis and operations like set
18 // operations, emptiness checks, or other math operations for analysis and
19 // transformation. For the latter, use FlatAffineConstraints.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 #ifndef MLIR_IR_INTEGER_SET_H
24 #define MLIR_IR_INTEGER_SET_H
25 
26 #include "mlir/IR/AffineExpr.h"
27 #include "llvm/ADT/ArrayRef.h"
28 
29 namespace mlir {
30 
31 namespace detail {
32 struct IntegerSetStorage;
33 }
34 
35 class MLIRContext;
36 
42 class IntegerSet {
43 public:
45 
46  IntegerSet() : set(nullptr) {}
47  explicit IntegerSet(ImplType *set) : set(set) {}
48  IntegerSet(const IntegerSet &other) : set(other.set) {}
49  IntegerSet &operator=(const IntegerSet &other) = default;
50 
51  static IntegerSet get(unsigned dimCount, unsigned symbolCount,
52  ArrayRef<AffineExpr> constraints,
53  ArrayRef<bool> eqFlags);
54 
55  // Returns the canonical empty IntegerSet (i.e. a set with no integer points).
56  static IntegerSet getEmptySet(unsigned numDims, unsigned numSymbols,
57  MLIRContext *context) {
58  auto one = getAffineConstantExpr(1, context);
59  /* 1 == 0 */
60  return get(numDims, numSymbols, one, true);
61  }
62 
64  bool isEmptyIntegerSet() const;
65 
71  IntegerSet replaceDimsAndSymbols(ArrayRef<AffineExpr> dimReplacements,
72  ArrayRef<AffineExpr> symReplacements,
73  unsigned numResultDims,
74  unsigned numResultSyms);
75 
76  explicit operator bool() { return set; }
77  bool operator==(IntegerSet other) const { return set == other.set; }
78 
79  unsigned getNumDims() const;
80  unsigned getNumSymbols() const;
81  unsigned getNumInputs() const;
82  unsigned getNumConstraints() const;
83  unsigned getNumEqualities() const;
84  unsigned getNumInequalities() const;
85 
86  ArrayRef<AffineExpr> getConstraints() const;
87 
88  AffineExpr getConstraint(unsigned idx) const;
89 
92  ArrayRef<bool> getEqFlags() const;
93 
96  bool isEq(unsigned idx) const;
97 
98  MLIRContext *getContext() const;
99 
102  void walkExprs(function_ref<void(AffineExpr)> callback) const;
103 
104  void print(raw_ostream &os) const;
105  void dump() const;
106 
107  friend ::llvm::hash_code hash_value(IntegerSet arg);
108 
109 private:
110  ImplType *set;
112  constexpr static unsigned kUniquingThreshold = 4;
113 };
114 
115 // Make AffineExpr hashable.
116 inline ::llvm::hash_code hash_value(IntegerSet arg) {
117  return ::llvm::hash_value(arg.set);
118 }
119 
120 } // end namespace mlir
121 namespace llvm {
122 
123 // IntegerSet hash just like pointers
124 template <> struct DenseMapInfo<mlir::IntegerSet> {
127  return mlir::IntegerSet(static_cast<mlir::IntegerSet::ImplType *>(pointer));
128  }
131  return mlir::IntegerSet(static_cast<mlir::IntegerSet::ImplType *>(pointer));
132  }
133  static unsigned getHashValue(mlir::IntegerSet val) {
134  return mlir::hash_value(val);
135  }
136  static bool isEqual(mlir::IntegerSet LHS, mlir::IntegerSet RHS) {
137  return LHS == RHS;
138  }
139 };
140 
141 } // namespace llvm
142 #endif // MLIR_IR_INTEGER_SET_H
Definition: InferTypeOpInterface.cpp:20
static unsigned getHashValue(mlir::IntegerSet val)
Definition: IntegerSet.h:133
Definition: PassRegistry.cpp:413
AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context)
Definition: AffineExpr.cpp:277
Definition: LLVM.h:45
Definition: LLVM.h:49
bool operator==(IntegerSet other) const
Definition: IntegerSet.h:77
IntegerSet(ImplType *set)
Definition: IntegerSet.h:47
static bool isEqual(mlir::IntegerSet LHS, mlir::IntegerSet RHS)
Definition: IntegerSet.h:136
Definition: LLVM.h:37
Definition: IntegerSetDetail.h:22
static mlir::IntegerSet getEmptyKey()
Definition: IntegerSet.h:125
Definition: AffineExpr.h:66
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
Definition: AffineExpr.h:201
static mlir::IntegerSet getTombstoneKey()
Definition: IntegerSet.h:129
Definition: MLIRContext.h:34
void print(OpAsmPrinter &p, AffineIfOp op)
Definition: AffineOps.cpp:1671
IntegerSet()
Definition: IntegerSet.h:46
IntegerSet(const IntegerSet &other)
Definition: IntegerSet.h:48
static IntegerSet getEmptySet(unsigned numDims, unsigned numSymbols, MLIRContext *context)
Definition: IntegerSet.h:56
Definition: Attributes.h:135
inline ::llvm::hash_code hash_value(IntegerSet arg)
Definition: IntegerSet.h:116
Definition: IntegerSet.h:42