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

     1  //===- AffineExprDetail.h - MLIR Affine Expr storage details ----*- 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  // This holds implementation details of AffineExpr. Ideally it would not be
    19  // exposed and would be kept local to AffineExpr.cpp however, MLIRContext.cpp
    20  // needs to know the sizes for placement-new style Allocation.
    21  //
    22  //===----------------------------------------------------------------------===//
    23  #ifndef MLIR_IR_AFFINEEXPRDETAIL_H_
    24  #define MLIR_IR_AFFINEEXPRDETAIL_H_
    25  
    26  #include "mlir/IR/AffineExpr.h"
    27  #include "mlir/IR/MLIRContext.h"
    28  #include "mlir/Support/StorageUniquer.h"
    29  
    30  namespace mlir {
    31  
    32  class MLIRContext;
    33  
    34  namespace detail {
    35  
    36  /// Base storage class appearing in an affine expression.
    37  struct AffineExprStorage : public StorageUniquer::BaseStorage {
    38    MLIRContext *context;
    39  };
    40  
    41  /// A binary operation appearing in an affine expression.
    42  struct AffineBinaryOpExprStorage : public AffineExprStorage {
    43    using KeyTy = std::pair<AffineExpr, AffineExpr>;
    44  
    45    bool operator==(const KeyTy &key) const {
    46      return key.first == lhs && key.second == rhs;
    47    }
    48  
    49    static AffineBinaryOpExprStorage *
    50    construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
    51      auto *result = allocator.allocate<AffineBinaryOpExprStorage>();
    52      result->lhs = key.first;
    53      result->rhs = key.second;
    54      result->context = result->lhs.getContext();
    55      return result;
    56    }
    57  
    58    AffineExpr lhs;
    59    AffineExpr rhs;
    60  };
    61  
    62  /// A dimensional or symbolic identifier appearing in an affine expression.
    63  struct AffineDimExprStorage : public AffineExprStorage {
    64    using KeyTy = unsigned;
    65  
    66    bool operator==(const KeyTy &key) const { return position == key; }
    67  
    68    static AffineDimExprStorage *
    69    construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
    70      auto *result = allocator.allocate<AffineDimExprStorage>();
    71      result->position = key;
    72      return result;
    73    }
    74  
    75    /// Position of this identifier in the argument list.
    76    unsigned position;
    77  };
    78  
    79  /// An integer constant appearing in affine expression.
    80  struct AffineConstantExprStorage : public AffineExprStorage {
    81    using KeyTy = int64_t;
    82  
    83    bool operator==(const KeyTy &key) const { return constant == key; }
    84  
    85    static AffineConstantExprStorage *
    86    construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
    87      auto *result = allocator.allocate<AffineConstantExprStorage>();
    88      result->constant = key;
    89      return result;
    90    }
    91  
    92    // The constant.
    93    int64_t constant;
    94  };
    95  
    96  } // end namespace detail
    97  } // end namespace mlir
    98  #endif // MLIR_IR_AFFINEEXPRDETAIL_H_