github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/mlir/lib/IR/IntegerSet.cpp (about)

     1  //===- IntegerSet.cpp - MLIR Integer Set class ----------------------------===//
     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/IntegerSet.h"
    19  #include "IntegerSetDetail.h"
    20  #include "mlir/IR/AffineExpr.h"
    21  
    22  using namespace mlir;
    23  using namespace mlir::detail;
    24  
    25  unsigned IntegerSet::getNumDims() const { return set->dimCount; }
    26  unsigned IntegerSet::getNumSymbols() const { return set->symbolCount; }
    27  unsigned IntegerSet::getNumOperands() const {
    28    return set->dimCount + set->symbolCount;
    29  }
    30  
    31  unsigned IntegerSet::getNumConstraints() const {
    32    return set->constraints.size();
    33  }
    34  
    35  unsigned IntegerSet::getNumEqualities() const {
    36    unsigned numEqualities = 0;
    37    for (unsigned i = 0, e = getNumConstraints(); i < e; i++)
    38      if (isEq(i))
    39        ++numEqualities;
    40    return numEqualities;
    41  }
    42  
    43  unsigned IntegerSet::getNumInequalities() const {
    44    return getNumConstraints() - getNumEqualities();
    45  }
    46  
    47  bool IntegerSet::isEmptyIntegerSet() const {
    48    // This will only work if uniqui'ing is on.
    49    static_assert(kUniquingThreshold >= 1,
    50                  "uniquing threshold should be at least one");
    51    return *this == getEmptySet(set->dimCount, set->symbolCount, getContext());
    52  }
    53  
    54  ArrayRef<AffineExpr> IntegerSet::getConstraints() const {
    55    return set->constraints;
    56  }
    57  
    58  AffineExpr IntegerSet::getConstraint(unsigned idx) const {
    59    return getConstraints()[idx];
    60  }
    61  
    62  /// Returns the equality bits, which specify whether each of the constraints
    63  /// is an equality or inequality.
    64  ArrayRef<bool> IntegerSet::getEqFlags() const { return set->eqFlags; }
    65  
    66  /// Returns true if the idx^th constraint is an equality, false if it is an
    67  /// inequality.
    68  bool IntegerSet::isEq(unsigned idx) const { return getEqFlags()[idx]; }
    69  
    70  MLIRContext *IntegerSet::getContext() const {
    71    return getConstraint(0).getContext();
    72  }