MLIR Team | f85a626 | 2018-06-27 11:03:08 -0700 | [diff] [blame] | 1 | //===- AffineExpr.cpp - MLIR Affine Expr Classes --------------------------===// |
| 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 | #include "mlir/IR/AffineExpr.h" |
Uday Bondhugula | 3934d4d | 2018-07-09 09:00:25 -0700 | [diff] [blame^] | 19 | #include "mlir/Support/STLExtras.h" |
MLIR Team | f85a626 | 2018-06-27 11:03:08 -0700 | [diff] [blame] | 20 | |
| 21 | using namespace mlir; |
Uday Bondhugula | 3934d4d | 2018-07-09 09:00:25 -0700 | [diff] [blame^] | 22 | |
| 23 | bool AffineExpr::isSymbolic() const { |
| 24 | switch (getKind()) { |
| 25 | case Kind::Constant: |
| 26 | return true; |
| 27 | case Kind::DimId: |
| 28 | return false; |
| 29 | case Kind::SymbolId: |
| 30 | return true; |
| 31 | |
| 32 | case Kind::Add: |
| 33 | case Kind::Sub: |
| 34 | case Kind::Mul: |
| 35 | case Kind::FloorDiv: |
| 36 | case Kind::CeilDiv: |
| 37 | case Kind::Mod: |
| 38 | return cast<AffineBinaryOpExpr>(this)->isSymbolic(); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | bool AffineExpr::isPureAffine() const { |
| 43 | switch (getKind()) { |
| 44 | case Kind::SymbolId: |
| 45 | return cast<AffineSymbolExpr>(this)->isPureAffine(); |
| 46 | case Kind::DimId: |
| 47 | return cast<AffineDimExpr>(this)->isPureAffine(); |
| 48 | case Kind::Constant: |
| 49 | return cast<AffineConstantExpr>(this)->isPureAffine(); |
| 50 | case Kind::Add: |
| 51 | return cast<AffineAddExpr>(this)->isPureAffine(); |
| 52 | case Kind::Sub: |
| 53 | return cast<AffineSubExpr>(this)->isPureAffine(); |
| 54 | case Kind::Mul: |
| 55 | return cast<AffineMulExpr>(this)->isPureAffine(); |
| 56 | case Kind::FloorDiv: |
| 57 | return cast<AffineFloorDivExpr>(this)->isPureAffine(); |
| 58 | case Kind::CeilDiv: |
| 59 | return cast<AffineCeilDivExpr>(this)->isPureAffine(); |
| 60 | case Kind::Mod: |
| 61 | return cast<AffineModExpr>(this)->isPureAffine(); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | bool AffineMulExpr::isPureAffine() const { |
| 66 | return lhsOperand->isPureAffine() && rhsOperand->isPureAffine() && |
| 67 | (isa<AffineConstantExpr>(lhsOperand) || |
| 68 | isa<AffineConstantExpr>(rhsOperand)); |
| 69 | } |
| 70 | |
| 71 | bool AffineFloorDivExpr::isPureAffine() const { |
| 72 | return lhsOperand->isPureAffine() && isa<AffineConstantExpr>(rhsOperand); |
| 73 | } |
| 74 | |
| 75 | bool AffineCeilDivExpr::isPureAffine() const { |
| 76 | return lhsOperand->isPureAffine() && isa<AffineConstantExpr>(rhsOperand); |
| 77 | } |
| 78 | |
| 79 | bool AffineModExpr::isPureAffine() const { |
| 80 | return lhsOperand->isPureAffine() && isa<AffineConstantExpr>(rhsOperand); |
| 81 | } |