1//===- InferIntRangeInterfaceImpls.cpp - Integer range impls for affine --===//
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#include "mlir/Dialect/Affine/IR/AffineOps.h"
10#include "mlir/Interfaces/InferIntRangeInterface.h"
11#include "mlir/Interfaces/Utils/InferIntRangeCommon.h"
12
13using namespace mlir;
14using namespace mlir::affine;
15using namespace mlir::intrange;
16
17//===----------------------------------------------------------------------===//
18// AffineApplyOp
19//===----------------------------------------------------------------------===//
20
21void AffineApplyOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
22 SetIntRangeFn setResultRange) {
23 AffineMap map = getAffineMap();
24
25 // Split operand ranges into dimensions and symbols.
26 unsigned numDims = map.getNumDims();
27 ArrayRef<ConstantIntRanges> dimRanges = argRanges.take_front(N: numDims);
28 ArrayRef<ConstantIntRanges> symbolRanges = argRanges.drop_front(N: numDims);
29
30 // Affine maps should have exactly one result for affine.apply.
31 assert(map.getNumResults() == 1 && "affine.apply must have single result");
32
33 // Infer the range for the affine expression.
34 ConstantIntRanges resultRange =
35 inferAffineExpr(expr: map.getResult(idx: 0), dimRanges, symbolRanges);
36
37 setResultRange(getResult(), resultRange);
38}
39