Lines Matching defs:map
127 /// Returns a single constant result affine map.
133 /// Returns an identity affine map (d0, ..., dn) -> (dp, ..., dn) on the most
174 /// Returns true if this affine map is a minor identity up to broadcasted
203 /// Return true if this affine map can be converted to a minor identity with
214 /// leading broadcat dimensions. The map returned would be (0, 0, d0, d1) with
223 // If there are more results than input dimensions we want the new map to
267 "Cannot create permutation map from empty permutation vector");
291 /// Creates an affine map each for each list of AffineExpr's in `exprsList`
343 MLIRContext *AffineMap::getContext() const { return map->context; }
382 assert(isSingleConstant() && "map must have a single constant result");
387 assert(isConstant() && "map must have only constant results");
395 assert(map && "uninitialized map storage");
396 return map->numDims;
399 assert(map && "uninitialized map storage");
400 return map->numSymbols;
404 assert(map && "uninitialized map storage");
405 return map->numDims + map->numSymbols;
408 assert(map && "uninitialized map storage");
409 return map->results();
431 /// Folds the results of the application of an affine map on the provided
499 /// the result. The returned map always has the same number of results.
525 /// Sparse replace method. Apply AffineExpr::replace(`map`) to each of the
528 AffineMap AffineMap::replace(const DenseMap<AffineExpr, AffineExpr> &map,
534 newResults.push_back(e.replace(map));
539 AffineMap::replace(const DenseMap<AffineExpr, AffineExpr> &map) const {
543 newResults.push_back(e.replace(map));
556 AffineMap AffineMap::compose(AffineMap map) const {
557 assert(getNumDims() == map.getNumResults() && "Number of results mismatch");
558 // Prepare `map` by concatenating the symbols and rewriting its exprs.
559 unsigned numDims = map.getNumDims();
561 unsigned numSymbols = numSymbolsThisMap + map.getNumSymbols();
572 map.replaceDimsAndSymbols(newDims, newSymbols, numDims, numSymbols);
577 return AffineMap::get(numDims, numSymbols, exprs, map.getContext());
581 assert(getNumSymbols() == 0 && "Expected symbol-less map");
717 AffineMap mlir::compressDims(AffineMap map,
719 return projectDims(map, unusedDims, /*compressDimsFlag=*/true);
722 AffineMap mlir::compressUnusedDims(AffineMap map) {
723 return compressDims(map, getUnusedDimsBitVector({map}));
731 AffineMap mlir::compressSymbols(AffineMap map,
733 return projectSymbols(map, unusedSymbols, /*compressSymbolsFlag=*/true);
736 AffineMap mlir::compressUnusedSymbols(AffineMap map) {
737 return compressSymbols(map, getUnusedSymbolsBitVector({map}));
745 AffineMap mlir::foldAttributesIntoMap(Builder &b, AffineMap map,
750 for (int64_t i = 0; i < map.getNumDims(); ++i) {
760 for (int64_t i = 0; i < map.getNumSymbols(); ++i) {
761 if (auto attr = operands[i + map.getNumDims()].dyn_cast<Attribute>()) {
766 remainingValues.push_back(cast<Value>(operands[i + map.getNumDims()]));
769 return map.replaceDimsAndSymbols(dimReplacements, symReplacements, numDims,
773 AffineMap mlir::simplifyAffineMap(AffineMap map) {
775 for (auto e : map.getResults()) {
777 simplifyAffineExpr(e, map.getNumDims(), map.getNumSymbols()));
779 return AffineMap::get(map.getNumDims(), map.getNumSymbols(), exprs,
780 map.getContext());
783 AffineMap mlir::removeDuplicateExprs(AffineMap map) {
784 auto results = map.getResults();
787 return AffineMap::get(map.getNumDims(), map.getNumSymbols(), uniqueExprs,
788 map.getContext());
791 AffineMap mlir::inversePermutation(AffineMap map) {
792 if (map.isEmpty())
793 return map;
794 assert(map.getNumSymbols() == 0 && "expected map without symbols");
795 SmallVector<AffineExpr, 4> exprs(map.getNumDims());
796 for (const auto &en : llvm::enumerate(map.getResults())) {
806 seenExprs.reserve(map.getNumDims());
810 if (seenExprs.size() != map.getNumInputs())
812 return AffineMap::get(map.getNumResults(), 0, seenExprs, map.getContext());
815 AffineMap mlir::inverseAndBroadcastProjectedPermutation(AffineMap map) {
816 assert(map.isProjectedPermutation(/*allowZeroInResults=*/true));
817 MLIRContext *context = map.getContext();
820 SmallVector<AffineExpr, 4> exprs(map.getNumInputs(), zero);
821 for (unsigned i : llvm::seq(unsigned(0), map.getNumResults())) {
822 // Skip zeros from input map. 'exprs' is already initialized to zero.
823 if (auto constExpr = dyn_cast<AffineConstantExpr>(map.getResult(i))) {
830 // Reverse each dimension existing in the original map result.
831 exprs[map.getDimPosition(i)] = getAffineDimExpr(i, context);
833 return AffineMap::get(map.getNumResults(), /*symbolCount=*/0, exprs, context);
856 /// map based on the template type.
858 /// are also dropped from the resulting map.
860 static AffineMap projectCommonImpl(AffineMap map,
868 int64_t numDimOrSym = (isDim) ? map.getNumDims() : map.getNumSymbols();
886 MLIRContext *context = map.getContext();
897 resultExprs.reserve(map.getNumResults());
898 for (auto e : map.getResults())
901 int64_t numDims = (compress && isDim) ? newNumDimOrSym : map.getNumDims();
902 int64_t numSyms = (compress && !isDim) ? newNumDimOrSym : map.getNumSymbols();
906 AffineMap mlir::projectDims(AffineMap map,
909 return projectCommonImpl<AffineDimExpr>(map, projectedDimensions,
913 AffineMap mlir::projectSymbols(AffineMap map,
916 return projectCommonImpl<AffineSymbolExpr>(map, projectedSymbols,
920 AffineMap mlir::getProjectedMap(AffineMap map,
924 map = projectDims(map, projectedDimensions, compressDimsFlag);
926 map = compressUnusedSymbols(map);
927 return map;
955 mlir::expandDimsToRank(AffineMap map, int64_t rank,
957 auto id = AffineMap::getMultiDimIdentityMap(rank, map.getContext());
959 return map.compose(proj);
966 MutableAffineMap::MutableAffineMap(AffineMap map)
967 : results(map.getResults()), numDims(map.getNumDims()),
968 numSymbols(map.getNumSymbols()), context(map.getContext()) {}
970 void MutableAffineMap::reset(AffineMap map) {
972 numDims = map.getNumDims();
973 numSymbols = map.getNumSymbols();
974 context = map.getContext();
975 llvm::append_range(results, map.getResults());
982 // Simplifies the result affine expressions of this map. The expressions
986 // TODO: functional-style map