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

     1  //===- SDBMExprDetail.h - MLIR SDBM Expression 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 SDBMExpr, in particular underlying
    19  // storage types.
    20  //
    21  //===----------------------------------------------------------------------===//
    22  
    23  #ifndef MLIR_IR_SDBMEXPRDETAIL_H
    24  #define MLIR_IR_SDBMEXPRDETAIL_H
    25  
    26  #include "mlir/Dialect/SDBM/SDBMExpr.h"
    27  #include "mlir/Support/StorageUniquer.h"
    28  
    29  namespace mlir {
    30  
    31  class SDBMDialect;
    32  
    33  namespace detail {
    34  
    35  // Base storage class for SDBMExpr.
    36  struct SDBMExprStorage : public StorageUniquer::BaseStorage {
    37    SDBMExprKind getKind() {
    38      return static_cast<SDBMExprKind>(BaseStorage::getKind());
    39    }
    40  
    41    SDBMDialect *dialect;
    42  };
    43  
    44  // Storage class for SDBM sum and stripe expressions.
    45  struct SDBMBinaryExprStorage : public SDBMExprStorage {
    46    using KeyTy = std::pair<SDBMVaryingExpr, SDBMConstantExpr>;
    47  
    48    bool operator==(const KeyTy &key) const {
    49      return std::get<0>(key) == lhs && std::get<1>(key) == rhs;
    50    }
    51  
    52    static SDBMBinaryExprStorage *
    53    construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
    54      auto *result = allocator.allocate<SDBMBinaryExprStorage>();
    55      result->lhs = std::get<0>(key);
    56      result->rhs = std::get<1>(key);
    57      result->dialect = result->lhs.getDialect();
    58      return result;
    59    }
    60  
    61    SDBMVaryingExpr lhs;
    62    SDBMConstantExpr rhs;
    63  };
    64  
    65  // Storage class for SDBM difference expressions.
    66  struct SDBMDiffExprStorage : public SDBMExprStorage {
    67    using KeyTy = std::pair<SDBMPositiveExpr, SDBMPositiveExpr>;
    68  
    69    bool operator==(const KeyTy &key) const {
    70      return std::get<0>(key) == lhs && std::get<1>(key) == rhs;
    71    }
    72  
    73    static SDBMDiffExprStorage *
    74    construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
    75      auto *result = allocator.allocate<SDBMDiffExprStorage>();
    76      result->lhs = std::get<0>(key);
    77      result->rhs = std::get<1>(key);
    78      result->dialect = result->lhs.getDialect();
    79      return result;
    80    }
    81  
    82    SDBMPositiveExpr lhs;
    83    SDBMPositiveExpr rhs;
    84  };
    85  
    86  // Storage class for SDBM constant expressions.
    87  struct SDBMConstantExprStorage : public SDBMExprStorage {
    88    using KeyTy = int64_t;
    89  
    90    bool operator==(const KeyTy &key) const { return constant == key; }
    91  
    92    static SDBMConstantExprStorage *
    93    construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
    94      auto *result = allocator.allocate<SDBMConstantExprStorage>();
    95      result->constant = key;
    96      return result;
    97    }
    98  
    99    int64_t constant;
   100  };
   101  
   102  // Storage class for SDBM dimension and symbol expressions.
   103  struct SDBMPositiveExprStorage : public SDBMExprStorage {
   104    using KeyTy = unsigned;
   105  
   106    bool operator==(const KeyTy &key) const { return position == key; }
   107  
   108    static SDBMPositiveExprStorage *
   109    construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
   110      auto *result = allocator.allocate<SDBMPositiveExprStorage>();
   111      result->position = key;
   112      return result;
   113    }
   114  
   115    unsigned position;
   116  };
   117  
   118  // Storage class for SDBM negation expressions.
   119  struct SDBMNegExprStorage : public SDBMExprStorage {
   120    using KeyTy = SDBMPositiveExpr;
   121  
   122    bool operator==(const KeyTy &key) const { return key == dim; }
   123  
   124    static SDBMNegExprStorage *
   125    construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
   126      auto *result = allocator.allocate<SDBMNegExprStorage>();
   127      result->dim = key;
   128      result->dialect = key.getDialect();
   129      return result;
   130    }
   131  
   132    SDBMPositiveExpr dim;
   133  };
   134  
   135  } // end namespace detail
   136  } // end namespace mlir
   137  
   138  #endif // MLIR_IR_SDBMEXPRDETAIL_H