blob: 26447a0a19cdcfb881fd80945fcd6a81c2c05e7c [file] [log] [blame]
MLIR Teamf85a6262018-06-27 11:03:08 -07001//===- 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 Bondhugula3934d4d2018-07-09 09:00:25 -070019#include "mlir/Support/STLExtras.h"
MLIR Teamf85a6262018-06-27 11:03:08 -070020
21using namespace mlir;
Uday Bondhugula3934d4d2018-07-09 09:00:25 -070022
23bool 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
42bool 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
65bool AffineMulExpr::isPureAffine() const {
66 return lhsOperand->isPureAffine() && rhsOperand->isPureAffine() &&
67 (isa<AffineConstantExpr>(lhsOperand) ||
68 isa<AffineConstantExpr>(rhsOperand));
69}
70
71bool AffineFloorDivExpr::isPureAffine() const {
72 return lhsOperand->isPureAffine() && isa<AffineConstantExpr>(rhsOperand);
73}
74
75bool AffineCeilDivExpr::isPureAffine() const {
76 return lhsOperand->isPureAffine() && isa<AffineConstantExpr>(rhsOperand);
77}
78
79bool AffineModExpr::isPureAffine() const {
80 return lhsOperand->isPureAffine() && isa<AffineConstantExpr>(rhsOperand);
81}