From 66b19cd218d46f9f3e0b6ae293fab5613bbc0644 Mon Sep 17 00:00:00 2001 From: Roman Rusyaev Date: Mon, 18 Jul 2022 14:16:52 +0300 Subject: [PATCH 1/3] Add pre- and post-increment and decrement operators in IntVal class --- src/mapleall/maple_util/include/mpl_int_val.h | 24 ++++++++++ src/mapleall/test/BUILD.gn | 5 +- src/mapleall/test/int_val_test.cpp | 46 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/mapleall/test/int_val_test.cpp diff --git a/src/mapleall/maple_util/include/mpl_int_val.h b/src/mapleall/maple_util/include/mpl_int_val.h index 965048d349..2a6b022177 100644 --- a/src/mapleall/maple_util/include/mpl_int_val.h +++ b/src/mapleall/maple_util/include/mpl_int_val.h @@ -155,6 +155,30 @@ class IntVal { return IntVal(value - val.value, width, sign); } + IntVal &operator++() { + ++value; + TruncInPlace(); + return *this; + } + + IntVal operator++(int) { + IntVal tmp(*this); + ++*this; + return tmp; + } + + IntVal &operator--() { + --value; + TruncInPlace(); + return *this; + } + + IntVal operator--(int) { + IntVal tmp(*this); + --*this; + return tmp; + } + IntVal operator*(const IntVal &val) const { ASSERT(width == val.width && sign == val.sign, "bit-width and sign must be the same"); return IntVal(value * val.value, width, sign); diff --git a/src/mapleall/test/BUILD.gn b/src/mapleall/test/BUILD.gn index 2b0dc3b75c..85042d7cae 100644 --- a/src/mapleall/test/BUILD.gn +++ b/src/mapleall/test/BUILD.gn @@ -21,8 +21,11 @@ cflags_cc -= [ include_directories = [ "${MAPLE_ROOT}/tools/gtest_lib/include", "${MAPLEALL_ROOT}/maple_util/include", + "${MAPLEALL_ROOT}/maple_ir/include/", + "${MAPLEALL_ROOT}/mempool/include/", + "${THIRD_PARTY_ROOT}/bounds_checking_function/include", ] -src_mapleallUT = [ "cl_ut_test.cpp" ] +src_mapleallUT = [ "cl_ut_test.cpp", "int_val_test.cpp" ] executable("mapleallUT") { sources = src_mapleallUT diff --git a/src/mapleall/test/int_val_test.cpp b/src/mapleall/test/int_val_test.cpp new file mode 100644 index 0000000000..b6f169c0a6 --- /dev/null +++ b/src/mapleall/test/int_val_test.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) [2022] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#include "mpl_int_val.h" + +#include "gtest/gtest.h" + +TEST(IntVals, IncDec) { + maple::IntVal uValInc(254, 8, false); + maple::IntVal sValInc(126, 8, true); + + maple::IntVal uValDec(1, 8, false); + maple::IntVal sValDec((maple::uint64)-127, 8, true); + + ++uValInc; + ASSERT_EQ(uValInc.GetExtValue(), 255); + ASSERT_EQ((uValInc++).GetExtValue(), 255); + ASSERT_EQ(uValInc.GetExtValue(), 0); + + ++sValInc; + ASSERT_EQ(sValInc.GetExtValue(), 127); + ASSERT_EQ((sValInc++).GetExtValue(), 127); + ASSERT_EQ(sValInc.GetExtValue(), -128); + + --uValDec; + ASSERT_EQ(uValDec.GetExtValue(), 0); + ASSERT_EQ((uValDec--).GetExtValue(), 0); + ASSERT_EQ(uValDec.GetExtValue(), 255); + + --sValDec; + ASSERT_EQ(sValDec.GetExtValue(), -128); + ASSERT_EQ((sValDec--).GetExtValue(), -128); + ASSERT_EQ(sValDec.GetExtValue(), 127); +} -- Gitee From 22b801a2ea237c303ff0f850f1725b380f7a2a01 Mon Sep 17 00:00:00 2001 From: Roman Rusyaev Date: Mon, 18 Jul 2022 14:17:11 +0300 Subject: [PATCH 2/3] Add missed header file --- src/mapleall/mpl2mpl/include/inline_summary.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mapleall/mpl2mpl/include/inline_summary.h b/src/mapleall/mpl2mpl/include/inline_summary.h index eaaf90b1fa..a75a59be88 100644 --- a/src/mapleall/mpl2mpl/include/inline_summary.h +++ b/src/mapleall/mpl2mpl/include/inline_summary.h @@ -20,6 +20,8 @@ #include "me_loop_analysis.h" #include "me_predict.h" +#include + namespace maple { enum ExprKind : uint32 { kExprKindParam = 0x01, // expr is a unmodified parameter -- Gitee From 2463239886289ba7aea1f999b7f180583392136d Mon Sep 17 00:00:00 2001 From: Roman Rusyaev Date: Mon, 18 Jul 2022 14:17:39 +0300 Subject: [PATCH 3/3] Fix command line options unit tests --- src/mapleall/test/cl_ut_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mapleall/test/cl_ut_test.cpp b/src/mapleall/test/cl_ut_test.cpp index 888e0ba28a..48b31f2007 100644 --- a/src/mapleall/test/cl_ut_test.cpp +++ b/src/mapleall/test/cl_ut_test.cpp @@ -56,7 +56,7 @@ std::vector maplecl::Option::GetRawValues() { } template <> -maplecl::RetCode maplecl::Option::Parse(ssize_t &argsIndex, +maplecl::RetCode maplecl::Option::Parse(size_t &argsIndex, const std::deque &args, KeyArg &keyArg) { utCLTypeChecker = true; RetCode err = maplecl::RetCode::noError; @@ -65,7 +65,7 @@ maplecl::RetCode maplecl::Option::Parse(ssize_t &argsIndex, return maplecl::RetCode::parsingErr; } - ssize_t localArgsIndex = argsIndex + 1; + size_t localArgsIndex = argsIndex + 1; /* Second command line argument does not exist */ if (localArgsIndex >= args.size() || args[localArgsIndex].empty()) { return RetCode::valueEmpty; -- Gitee