From e0a87e543e16b0f5c2abecf667107801b94ffca0 Mon Sep 17 00:00:00 2001 From: penguin_wwy <940375606@qq.com> Date: Fri, 10 May 2024 17:07:37 +0800 Subject: [PATCH] [NFC] Standardize the std::is_same competime expression (#3321) --- lib/Conversion/TorchToStablehlo/Basic.cpp | 42 +++++++++++----------- lib/Conversion/TorchToTosa/TorchToTosa.cpp | 15 ++++---- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/Conversion/TorchToStablehlo/Basic.cpp b/lib/Conversion/TorchToStablehlo/Basic.cpp index 94037c107..f5844e442 100644 --- a/lib/Conversion/TorchToStablehlo/Basic.cpp +++ b/lib/Conversion/TorchToStablehlo/Basic.cpp @@ -449,11 +449,13 @@ public: "only floating-point or integer datatype legalization supported"); } - if (std::is_same()) { + if constexpr (std::is_same()) { rhs = lhs; - } else if (!rhsType) { - rhs = hlo::scalarToStablehloTensor(rewriter, op, adaptor.getOther(), - outElemTy); + } else { + if (!rhsType) { + rhs = hlo::scalarToStablehloTensor(rewriter, op, adaptor.getOther(), + outElemTy); + } } DenseI64ArrayAttr bcastDimensions; lhs = hlo::promoteType(rewriter, op.getLoc(), lhs, outType); @@ -462,8 +464,8 @@ public: Value result = rewriter.create(loc, outType, lhs, rhs, bcastDimensions); - if (!std::is_same() && - !std::is_same()) { + if constexpr (!std::is_same() && + !std::is_same()) { rewriter.replaceOp(op, result); return success(); } @@ -575,32 +577,32 @@ public: op->getContext(), chlo::ComparisonType::SIGNED); } - if (std::is_same() || - std::is_same()) { + if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::LT); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::GT); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::GE); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::EQ); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::NE); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::LT); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::LE); } else { diff --git a/lib/Conversion/TorchToTosa/TorchToTosa.cpp b/lib/Conversion/TorchToTosa/TorchToTosa.cpp index db8a435ab..c7c52d087 100644 --- a/lib/Conversion/TorchToTosa/TorchToTosa.cpp +++ b/lib/Conversion/TorchToTosa/TorchToTosa.cpp @@ -371,8 +371,8 @@ public: } auto rhsTensor = rhsTy ? rhs : rhsAsTensor; // There is no Lesser operator in TOSA. - auto swapLhsRhs = (std::is_same() || - std::is_same()); + constexpr auto swapLhsRhs = (std::is_same() || + std::is_same()); // Promote lhs and rhs dtypes for bitwise operators. TensorType resultTy = OpConversionPattern::getTypeConverter() @@ -388,12 +388,15 @@ public: (swapLhsRhs ? lhs : rhsTensor)); // There is no NE operator in TOSA. - if (std::is_same() || - std::is_same()) + if constexpr (std::is_same() || + std::is_same()) { rewriter.replaceOpWithNewOp(op, resultTy, resultOp.getResult()); - else + } + + else { rewriter.replaceOp(op, resultOp.getResult()); + } return success(); } @@ -425,7 +428,7 @@ public: op, "Only floating-point or integer datatype legalization supported"); Value rhsTensor; - if (std::is_same()) { + if constexpr (std::is_same()) { rhsTensor = lhs; } else { Value rhsAsTensor;