1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef MLIR_HLO_DIALECT_LHLO_TRANSFORMS_MAP_LMHLO_TO_SCALAR_OP_H 17 #define MLIR_HLO_DIALECT_LHLO_TRANSFORMS_MAP_LMHLO_TO_SCALAR_OP_H 18 19 #include "mlir-hlo/Dialect/lhlo/transforms/map_lhlo_to_hlo_op.h" 20 #include "mlir-hlo/Dialect/mhlo/transforms/map_mhlo_to_scalar_op.h" 21 22 namespace mlir { 23 namespace lmhlo { 24 25 struct LhloOpToStdScalarOp { 26 // Implementation for LHLO ops except lmhlo::CompareOp. 27 template <typename LhloOpTy, typename MhloOpTy = lmhlo::LhloToHloOp<LhloOpTy>, 28 typename = std::enable_if_t< 29 !std::is_same<LhloOpTy, lmhlo::CompareOp>::value && 30 !std::is_same<MhloOpTy, std::false_type>::value>> 31 static Value map(LhloOpTy op, ArrayRef<Type> resultTypes, ValueRange args, 32 OpBuilder* b, int /*i*/ = 0) { 33 return mlir::mhlo::impl::mapMhloOpToStdScalarOp<MhloOpTy>( 34 op.getLoc(), resultTypes, llvm::to_vector<4>(op->getOperandTypes()), 35 args, b); 36 } 37 38 // Implementation for lmhlo::CompareOp. 39 template <typename LhloOpTy, typename = std::enable_if_t<std::is_same< 40 LhloOpTy, lmhlo::CompareOp>::value>> mapLhloOpToStdScalarOp41 static Value map(lmhlo::CompareOp op, ArrayRef<Type> resultTypes, 42 ValueRange args, OpBuilder* b) { 43 auto comparisonDirection = op.getComparisonDirection(); 44 return mlir::mhlo::impl::mapCompareOpToStdScalarOp( 45 op.getLoc(), comparisonDirection, resultTypes, 46 llvm::to_vector<4>(op->getOperandTypes()), args, b); 47 } 48 49 // Implementation for LHLO ops except lmhlo::CompareOp. 50 template <typename LhloOpTy, typename MhloOpTy = lmhlo::LhloToHloOp<LhloOpTy>, 51 typename = std::enable_if_t< 52 !std::is_same<LhloOpTy, lmhlo::CompareOp>::value && 53 !std::is_same<MhloOpTy, std::false_type>::value>> 54 static Value map(Location loc, ArrayRef<Type> resultTypes, 55 ArrayRef<Type> argTypes, ValueRange args, OpBuilder* b, 56 unsigned /*i*/ = 0) { 57 return mlir::mhlo::impl::mapMhloOpToStdScalarOp<MhloOpTy>( 58 loc, resultTypes, argTypes, args, b); 59 } 60 }; 61 62 } // namespace lmhlo 63 } // namespace mlir 64 65 #endif // MLIR_HLO_DIALECT_LHLO_TRANSFORMS_MAP_LMHLO_TO_SCALAR_OP_H 66