From 4f618c0943b0471a600d22190a23d2883ca0703b Mon Sep 17 00:00:00 2001 From: Hyukjin Jeong Date: Thu, 21 Nov 2024 09:31:13 +0900 Subject: [PATCH] [luci] Revise ForwardTransposeOpPass.cpp (#14328) This uses a macro for readability. ONE-DCO-1.0-Signed-off-by: Hyukjin Jeong --- .../luci/pass/src/ForwardTransposeOpPass.cpp | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/compiler/luci/pass/src/ForwardTransposeOpPass.cpp b/compiler/luci/pass/src/ForwardTransposeOpPass.cpp index 10665bbb5cc..61b568793d8 100644 --- a/compiler/luci/pass/src/ForwardTransposeOpPass.cpp +++ b/compiler/luci/pass/src/ForwardTransposeOpPass.cpp @@ -26,6 +26,10 @@ using namespace luci; +#define RETURN_FALSE_UNLESS(COND) \ + if (not(COND)) \ + return false; + namespace { @@ -35,8 +39,7 @@ namespace bool check_perm(const CircleTranspose *t) { auto perm = dynamic_cast(t->perm()); - if (not perm) - return false; + RETURN_FALSE_UNLESS(perm); switch (perm->dtype()) { @@ -45,8 +48,7 @@ bool check_perm(const CircleTranspose *t) { auto data = perm->at(i); // TODO Support not normalized index - if (data < 0 or data >= static_cast(t->rank())) - return false; + RETURN_FALSE_UNLESS(data >= 0 and data < static_cast(t->rank())); } break; // TODO Support S64 data type @@ -91,23 +93,18 @@ std::vector get_perm_data(const CircleConst *node) bool check_same_perm(const CircleTranspose *lhs, const CircleTranspose *rhs) { auto lhs_perm = dynamic_cast(lhs->perm()); - if (not lhs_perm) - return false; + RETURN_FALSE_UNLESS(lhs_perm); auto rhs_perm = dynamic_cast(rhs->perm()); - if (not rhs_perm) - return false; + RETURN_FALSE_UNLESS(rhs_perm); std::vector lhs_perm_data = get_perm_data(lhs_perm); - if (lhs_perm_data.empty()) - return false; + RETURN_FALSE_UNLESS(not lhs_perm_data.empty()); std::vector rhs_perm_data = get_perm_data(rhs_perm); - if (rhs_perm_data.empty()) - return false; + RETURN_FALSE_UNLESS(not rhs_perm_data.empty()); - if (lhs_perm_data != rhs_perm_data) - return false; + RETURN_FALSE_UNLESS(lhs_perm_data == rhs_perm_data); return true; } @@ -227,10 +224,6 @@ bool has_single_element(const luci::CircleConst *node) return has_single_elem; } -#define RETURN_FALSE_UNLESS(COND) \ - if (not(COND)) \ - return false; - // Elementwise Binary Operator with const class EBOWithConstPattern final : public CircleNodeMutableVisitor {