Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 1 | //===- 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" |
Uday Bondhugula | 83a41c9 | 2018-08-30 17:35:15 -0700 | [diff] [blame^] | 23 | |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 24 | #include "mlir/IR/AffineExpr.h" |
Uday Bondhugula | 83a41c9 | 2018-08-30 17:35:15 -0700 | [diff] [blame^] | 25 | #include "mlir/IR/AffineExprVisitor.h" |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 26 | #include "mlir/IR/AffineMap.h" |
| 27 | #include "mlir/IR/IntegerSet.h" |
| 28 | #include "mlir/IR/MLIRContext.h" |
| 29 | #include "mlir/IR/StandardOps.h" |
Uday Bondhugula | 83a41c9 | 2018-08-30 17:35:15 -0700 | [diff] [blame^] | 30 | #include "llvm/ADT/ArrayRef.h" |
| 31 | #include "llvm/Support/raw_ostream.h" |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 32 | |
| 33 | namespace mlir { |
| 34 | |
Uday Bondhugula | 83a41c9 | 2018-08-30 17:35:15 -0700 | [diff] [blame^] | 35 | MutableAffineMap::MutableAffineMap(AffineMap *map, MLIRContext *context) |
| 36 | : numDims(map->getNumDims()), numSymbols(map->getNumSymbols()), |
| 37 | context(context) { |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 38 | for (auto *result : map->getResults()) |
| 39 | results.push_back(result); |
| 40 | for (auto *rangeSize : map->getRangeSizes()) |
| 41 | results.push_back(rangeSize); |
| 42 | } |
| 43 | |
Uday Bondhugula | 83a41c9 | 2018-08-30 17:35:15 -0700 | [diff] [blame^] | 44 | bool MutableAffineMap::isMultipleOf(unsigned idx, int64_t factor) const { |
| 45 | if (results[idx]->isMultipleOf(factor)) |
| 46 | return true; |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 47 | |
Uday Bondhugula | 83a41c9 | 2018-08-30 17:35:15 -0700 | [diff] [blame^] | 48 | // TODO(bondhugula): use FlatAffineConstraints to complete this (for a more |
| 49 | // powerful analysis). |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 50 | assert(0 && "isMultipleOf implementation incomplete"); |
Uday Bondhugula | b553adb | 2018-08-25 17:17:56 -0700 | [diff] [blame] | 51 | return false; |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Uday Bondhugula | 83a41c9 | 2018-08-30 17:35:15 -0700 | [diff] [blame^] | 54 | MutableIntegerSet::MutableIntegerSet(IntegerSet *set, MLIRContext *context) |
| 55 | : numDims(set->getNumDims()), numSymbols(set->getNumSymbols()), |
| 56 | context(context) { |
| 57 | // TODO(bondhugula) |
| 58 | } |
| 59 | |
| 60 | // Universal set. |
| 61 | MutableIntegerSet::MutableIntegerSet(unsigned numDims, unsigned numSymbols, |
| 62 | MLIRContext *context) |
| 63 | : numDims(numDims), numSymbols(numSymbols), context(context) {} |
| 64 | |
| 65 | AffineValueMap::AffineValueMap(const AffineApplyOp &op, MLIRContext *context) |
| 66 | : map(op.getAffineMap(), context) { |
| 67 | // TODO: pull operands and results in. |
| 68 | } |
| 69 | |
| 70 | inline bool AffineValueMap::isMultipleOf(unsigned idx, int64_t factor) const { |
| 71 | return map.isMultipleOf(idx, factor); |
| 72 | } |
| 73 | |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 74 | AffineValueMap::~AffineValueMap() {} |
| 75 | |
Uday Bondhugula | 83a41c9 | 2018-08-30 17:35:15 -0700 | [diff] [blame^] | 76 | void FlatAffineConstraints::addEquality(ArrayRef<int64_t> eq) { |
| 77 | assert(eq.size() == getNumCols()); |
| 78 | unsigned offset = equalities.size(); |
| 79 | equalities.resize(equalities.size() + eq.size()); |
| 80 | for (unsigned i = 0, e = eq.size(); i < e; i++) { |
| 81 | equalities[offset + i] = eq[i]; |
| 82 | } |
| 83 | } |
| 84 | |
Uday Bondhugula | 257339b | 2018-08-21 10:32:24 -0700 | [diff] [blame] | 85 | } // end namespace mlir |