blob: 295c76a93c7de472f2a2c45d518939cb0bb076f3 [file] [log] [blame]
Uday Bondhugula257339b2018-08-21 10:32:24 -07001//===- AffineStructures.cpp - MLIR Affine Structures Class-------*- C++ -*-===//
2//
3// Copyright 2019 The MLIR Authors.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16// =============================================================================
17//
18// Structures for affine/polyhedral analysis of MLIR functions.
19//
20//===----------------------------------------------------------------------===//
21
22#include "mlir/Analysis/AffineStructures.h"
23#include "mlir/IR/AffineExpr.h"
24#include "mlir/IR/AffineMap.h"
25#include "mlir/IR/IntegerSet.h"
26#include "mlir/IR/MLIRContext.h"
27#include "mlir/IR/StandardOps.h"
28
29namespace mlir {
30
31MutableAffineMap::MutableAffineMap(AffineMap *map) {
32 for (auto *result : map->getResults())
33 results.push_back(result);
34 for (auto *rangeSize : map->getRangeSizes())
35 results.push_back(rangeSize);
36}
37
38MutableIntegerSet::MutableIntegerSet(IntegerSet *set)
39 : numDims(set->getNumDims()), numSymbols(set->getNumSymbols()) {
40 // TODO(bondhugula)
41}
42
43AffineValueMap::AffineValueMap(const AffineApplyOp &op)
44 : map(op.getAffineMap()) {
45 // TODO: pull operands and results in.
46}
47
48bool AffineValueMap::isMultipleOf(unsigned idx, int64_t factor) const {
49 /* Check if the (first result expr) % factor becomes 0. */
50 if (auto *expr = dyn_cast<AffineConstantExpr>(AffineBinaryOpExpr::get(
51 AffineExpr::Kind::Mod, map.getResult(idx),
52 AffineConstantExpr::get(factor, context), context)))
53 return expr->getValue() == 0;
54
55 // TODO(bondhugula): use FlatAffineConstraints to complete this.
56 assert(0 && "isMultipleOf implementation incomplete");
57}
58
59AffineValueMap::~AffineValueMap() {}
60
61} // end namespace mlir