14 #ifndef MLIR_IR_AFFINEMAP_H 15 #define MLIR_IR_AFFINEMAP_H 19 #include "llvm/ADT/ArrayRef.h" 20 #include "llvm/ADT/DenseMapInfo.h" 29 struct AffineMapStorage;
53 static AffineMap get(
unsigned dimCount,
unsigned symbolCount,
58 static AffineMap get(
unsigned dimCount,
unsigned symbolCount,
63 static AffineMap get(
unsigned dimCount,
unsigned symbolCount,
70 static AffineMap getMultiDimIdentityMap(
unsigned numDims,
75 static AffineMap getMinorIdentityMap(
unsigned dims,
unsigned results,
97 explicit operator bool()
const {
return map !=
nullptr; }
104 bool isIdentity()
const;
108 bool isMinorIdentity()
const;
116 bool isMinorIdentityWithBroadcasting(
132 bool isPermutationOfMinorIdentityWithBroadcasting(
136 bool isEmpty()
const;
139 bool isSingleConstant()
const;
142 bool isConstant()
const;
146 int64_t getSingleConstantResult()
const;
153 void print(raw_ostream &os)
const;
156 unsigned getNumDims()
const;
157 unsigned getNumSymbols()
const;
158 unsigned getNumResults()
const;
159 unsigned getNumInputs()
const;
170 unsigned getPermutedPosition(
unsigned input)
const;
174 return llvm::any_of(getResults(), [&](
AffineExpr e) {
181 return llvm::any_of(getResults(), [&](
AffineExpr e) {
197 unsigned numResultDims,
198 unsigned numResultSyms)
const;
204 unsigned numResultDims,
unsigned numResultSyms)
const;
215 unsigned numResultDims,
unsigned numResultSyms)
const;
220 assert(offset <= getNumDims());
221 return AffineMap::get(getNumDims() + shift, getNumSymbols(),
222 llvm::to_vector<4>(llvm::map_range(
225 return e.
shiftDims(getNumDims(), shift, offset);
233 return AffineMap::get(getNumDims(), getNumSymbols() + shift,
234 llvm::to_vector<4>(llvm::map_range(
283 bool isProjectedPermutation(
bool allowZeroInResults =
false)
const;
292 AffineMap getSliceMap(
unsigned start,
unsigned length)
const;
297 AffineMap getMajorSubMap(
unsigned numResults)
const;
302 AffineMap getMinorSubMap(
unsigned numResults)
const;
308 return static_cast<const void *
>(map);
311 return AffineMap(reinterpret_cast<ImplType *>(const_cast<void *>(pointer)));
317 static AffineMap getImpl(
unsigned dimCount,
unsigned symbolCount,
343 bool isMultipleOf(
unsigned idx, int64_t factor)
const;
359 unsigned numDims = 0;
360 unsigned numSymbols = 0;
390 const llvm::SmallBitVector &unusedSymbols);
527 const llvm::SmallBitVector &projectedDimensions);
530 template <
typename T>
538 result.push_back(source[dimExpr.getPosition()]);
540 assert(constExpr.getValue() == 0 &&
541 "Unexpected constant in projected permutation map");
544 llvm_unreachable(
"Unexpected result in projected permutation map");
552 template <
typename AffineExprContainer>
554 int64_t &maxDim, int64_t &maxSym) {
555 for (
const auto &exprs : exprsList) {
556 for (
auto expr : exprs) {
559 maxDim =
std::max(maxDim, static_cast<int64_t>(d.getPosition()));
561 maxSym =
std::max(maxSym, static_cast<int64_t>(s.getPosition()));
580 return mlir::AffineMap(static_cast<mlir::AffineMap::ImplType *>(pointer));
584 return mlir::AffineMap(static_cast<mlir::AffineMap::ImplType *>(pointer));
596 #endif // MLIR_IR_AFFINEMAP_H Include the generated interface declarations.
AffineMap inversePermutation(AffineMap map)
Returns a map of codomain to domain dimensions such that the first codomain dimension for a particula...
static bool isEqual(mlir::AffineMap LHS, mlir::AffineMap RHS)
Explicitly register a set of "builtin" types.
static void getMaxDimAndSymbol(ArrayRef< AffineExprContainer > exprsList, int64_t &maxDim, int64_t &maxSym)
Calculates maxmimum dimension and symbol positions from the expressions in exprsLists and stores them...
bool isFunctionOfDim(unsigned position) const
Return true if the affine expression involves AffineDimExpr position.
AffineExpr shiftSymbols(unsigned numSymbols, unsigned shift, unsigned offset=0) const
Replace symbols[offset ...
AffineExpr shiftDims(unsigned numDims, unsigned shift, unsigned offset=0) const
Replace dims[offset ...
unsigned getNumResults() const
AffineMap shiftSymbols(unsigned shift, unsigned offset=0) const
Replace symbols[offset ...
void setNumDims(unsigned d)
bool operator!=(AffineMap other) const
static bool isPermutation(std::vector< PermutationTy > permutation)
AffineMap shiftDims(unsigned shift, unsigned offset=0) const
Replace dims[offset ...
bool isFunctionOfSymbol(unsigned position) const
Return true if any affine expression involves AffineSymbolExpr position.
An integer constant appearing in affine expression.
AffineMap compressSymbols(AffineMap map, const llvm::SmallBitVector &unusedSymbols)
Drop the symbols that are not listed in unusedSymbols.
unsigned getNumInputs() const
static mlir::AffineMap getEmptyKey()
This class represents an efficient way to signal success or failure.
AffineMap removeDuplicateExprs(AffineMap map)
Returns a map with the same dimension and symbol count as map, but whose results are the unique affin...
bool operator==(AffineMap other) const
A mutable affine map. Its affine expressions are however unique.
SmallVector< T > applyPermutationMap(AffineMap map, llvm::ArrayRef< T > source)
Apply a permutation from map to source and return the result.
bool isProjectedPermutation(bool allowZeroInResults=false) const
Returns true if the AffineMap represents a subset (i.e.
AffineMap concatAffineMaps(ArrayRef< AffineMap > maps)
Concatenates a list of maps into a single AffineMap, stepping over potentially empty maps...
inline ::llvm::hash_code hash_value(AffineMap arg)
unsigned getNumSymbols() const
Base type for affine expression.
static mlir::AffineMap getTombstoneKey()
unsigned getNumResults() const
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued...
ArrayRef< AffineExpr > getResults() const
bool isFunctionOfSymbol(unsigned position) const
Return true if the affine expression involves AffineSymbolExpr position.
AffineMap inverseAndBroadcastProjectedPermutation(AffineMap map)
Return the reverse map of a projected permutation where the projected dimensions are transformed into...
static void print(ArrayType type, DialectAsmPrinter &os)
static unsigned getHashValue(mlir::AffineMap val)
MLIRContext * getContext() const
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
const void * getAsOpaquePointer() const
Methods supporting C API.
void print(raw_ostream &os) const
AffineExpr getResult(unsigned idx) const
void setResult(unsigned idx, AffineExpr result)
void setNumSymbols(unsigned d)
unsigned getNumDims() const
AffineMap simplifyAffineMap(AffineMap map)
Simplifies an affine map by simplifying its underlying AffineExpr results.
std::ostream & operator<<(std::ostream &out, const llvm::Twine &twine)
ArrayRef< AffineExpr > getResults() const
AffineMap compressDims(AffineMap map, const llvm::SmallBitVector &unusedDims)
Drop the dims that are not listed in unusedDims.
AffineMap getProjectedMap(AffineMap map, const llvm::SmallBitVector &projectedDimensions)
Returns the map that results from projecting out the dimensions specified in projectedDimensions.
A dimensional identifier appearing in an affine expression.
bool isFunctionOfDim(unsigned position) const
Return true if any affine expression involves AffineDimExpr position.
MLIRContext is the top-level object for a collection of MLIR operations.
SmallVector< AffineMap > compressUnusedSymbols(ArrayRef< AffineMap > maps)
Drop the symbols that are not used by any of the individual maps in maps.
static AffineMap getFromOpaquePointer(const void *pointer)
SmallVector< AffineMap > compressUnusedDims(ArrayRef< AffineMap > maps)
Drop the dims that are not used by any of the individual maps in maps.
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
A symbolic identifier appearing in an affine expression.
static SmallVector< AffineMap, 4 > inferFromExprList(ArrayRef< AffineExprContainer > exprsList)