From d3fbdae502a9e3c4941a7c4107053efc214e37bb Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 25 Nov 2021 13:42:27 +0300 Subject: [PATCH 01/21] [mapleall][driver] Add "target" and "isystem" as default options for clang-ast generator These options are needed to correct compile for aarch64. These options were tested with SPECCPU2017 benchmark. --- .../defs/default/O0_options_clang.def | 3 +- .../include/driver_option_common.h | 1 + .../maple_driver/src/clang_compiler.cpp | 52 ++++++++++++++++--- .../maple_driver/src/driver_option_common.cpp | 9 ++++ 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_clang.def b/src/mapleall/maple_driver/defs/default/O0_options_clang.def index a8edd35c27..fb70797f01 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_clang.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_clang.def @@ -1,2 +1 @@ -{"-emit-ast", "", false}, -{"-o", "", false}, \ No newline at end of file +{"-emit-ast", "", false}, \ No newline at end of file diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index 5f6f08ee4d..3607a328df 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -71,6 +71,7 @@ enum DriverOptionIndex { kLdLibPath, kClangMacro, kClangInclude, + kClangISystem, kMapleOut, kCommonOptionEnd, }; diff --git a/src/mapleall/maple_driver/src/clang_compiler.cpp b/src/mapleall/maple_driver/src/clang_compiler.cpp index 002994d595..c6c8f061a3 100644 --- a/src/mapleall/maple_driver/src/clang_compiler.cpp +++ b/src/mapleall/maple_driver/src/clang_compiler.cpp @@ -29,16 +29,56 @@ const std::string &ClangCompiler::GetBinName() const { return kBinNameClang; } +static inline uint32_t FillSpecialDefaulOpt(std::unique_ptr &opt, + const Action &action) { + uint32_t additionalLen = 1; // for -o option + + /* TODO: Add check for the target architecture and OS environment. + * Currently it supports only aarch64 and linux-gnu- + */ + if (kOperatingSystem == "linux-gnu-" && kMachine == "aarch64-") { + additionalLen += 3; + opt = std::make_unique(additionalLen); + + opt[0].SetKey("-isystem"); + opt[0].SetValue(FileUtils::SafeGetenv(kMapleRoot) + "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/include"); + + opt[1].SetKey("-isystem"); + opt[1].SetValue(FileUtils::SafeGetenv(kMapleRoot) + "/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/include"); + + opt[2].SetKey("-target"); + opt[2].SetValue("aarch64"); + } else { + CHECK_FATAL(false, "Only linux-gnu OS and aarch64 target are supported \n"); + } + + /* Set last option as -o option */ + opt[additionalLen-1].SetKey("-o"); + opt[additionalLen-1].SetValue(action.GetFullOutputName() + ".ast"); + + return additionalLen; +} + DefaultOption ClangCompiler::GetDefaultOptions(const MplOptions &options, const Action &action) const { - uint32_t len = sizeof(kClangDefaultOptions) / sizeof(MplOption); - DefaultOption defaultOptions = { std::make_unique(len), len }; + DefaultOption defaultOptions; + uint32_t fullLen = 0; + uint32_t defaultLen = 0; + uint32_t additionalLen = 0; + std::unique_ptr additionalOptions; + + additionalLen = FillSpecialDefaulOpt(additionalOptions, action); + defaultLen = sizeof(kClangDefaultOptions) / sizeof(MplOption); + fullLen = defaultLen + additionalLen; - for (uint32_t i = 0; i < len; ++i) { + defaultOptions = { std::make_unique(fullLen), fullLen }; + + for (uint32_t i = 0; i < defaultLen; ++i) { defaultOptions.mplOptions[i] = kClangDefaultOptions[i]; } - - CHECK_FATAL((len > 1), "Option is hardcoded in O0_options_clang.def file \n"); - defaultOptions.mplOptions[1].SetValue(action.GetFullOutputName() + ".ast"); + for (uint32_t defInd = defaultLen, additionalInd = 0; + additionalInd < additionalLen; ++additionalInd) { + defaultOptions.mplOptions[defInd++] = additionalOptions[additionalInd]; + } for (uint32_t i = 0; i < defaultOptions.length; ++i) { defaultOptions.mplOptions[i].SetValue( diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index 59ba0e46aa..f07f4531fe 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -492,6 +492,15 @@ const mapleOption::Descriptor kUsages[] = { " -I \tAdd directory to include search path\n", "all", {"clang"} }, + { kClangISystem, + 0, + "I", + "", + kBuildTypeAll, + kArgCheckPolicyRequired, + " -isystem \tAdd directory to SYSTEN include search path\n", + "all", + {"clang"} }, { kMaplePhaseOnly, kEnable, "", -- Gitee From c3afff196d941271d13d70674c5d77923be2b8f6 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 25 Nov 2021 13:48:30 +0300 Subject: [PATCH 02/21] [mapleall][driver] Add "-U" option "-U " option is used to undefine macro . --- src/mapleall/maple_driver/include/driver_option_common.h | 1 + src/mapleall/maple_driver/src/driver_option_common.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/mapleall/maple_driver/include/driver_option_common.h b/src/mapleall/maple_driver/include/driver_option_common.h index 3607a328df..238312b263 100644 --- a/src/mapleall/maple_driver/include/driver_option_common.h +++ b/src/mapleall/maple_driver/include/driver_option_common.h @@ -70,6 +70,7 @@ enum DriverOptionIndex { kLdLib, kLdLibPath, kClangMacro, + kClangUMacro, kClangInclude, kClangISystem, kMapleOut, diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index f07f4531fe..e1998fedd0 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -483,6 +483,15 @@ const mapleOption::Descriptor kUsages[] = { " -D = \tDefine to (or 1 if omitted)\n", "all", {"clang"} }, + { kClangMacro, + 0, + "U", + "", + kBuildTypeAll, + kArgCheckPolicyRequired, + " -U \tUndefine macro \n", + "all", + {"clang"} }, { kClangInclude, 0, "I", -- Gitee From 65d3e39e965c6a46e0c938f3ac35b775fe7e9622 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 25 Nov 2021 14:26:53 +0300 Subject: [PATCH 03/21] [mapleall][driver] Add enable-variable-array as default option for mplfe --- src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def index 311847daa5..111969a37f 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_cpp2mpl.def @@ -1,2 +1 @@ -{} - +{"-enable-variable-array", "", false}, -- Gitee From d5ab39a81e087f8aed71a5d3909fecf25f1f8dbc Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 25 Nov 2021 15:50:39 +0300 Subject: [PATCH 04/21] [mapleall][driver] Do not replace default options Default options must be extended with extra options(not replaced). This commit implements it. To implement it options map was replaced with options vector. --- src/mapleall/maple_driver/include/compiler.h | 18 ++----- src/mapleall/maple_driver/src/compiler.cpp | 52 +++++++++++++------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index 089ba8ea0d..e27316d8fb 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -98,28 +98,20 @@ class Compiler { std::vector MakeOption(const MplOptions &options, const Action &action) const; void AppendDefaultOptions(std::vector &finalOptions, - const std::map &defaultOptions, + const std::vector &defaultOptions, bool isDebug) const; void AppendExtraOptions(std::vector &finalOptions, - std::map defaultOptions, const MplOptions &options, bool isDebug) const; void AppendInputsAsOptions(std::vector &finalOptions, const MplOptions &mplOptions, const Action &action) const; - std::map MakeDefaultOptions(const MplOptions &options, - const Action &action) const; + void ReplaceOrInsertOption(std::vector &finalOptions, + const std::string &key, const std::string &value) const; + std::vector MakeDefaultOptions(const MplOptions &options, + const Action &action) const; int Exe(const MplOptions &mplOptions, const std::vector &options) const; const std::string &GetName() const { return name; } - - void ReplaceOption(std::vector &finalOptions, - const std::string &key, const std::string &value) const { - for (auto &opt : finalOptions) { - if (opt.GetKey() == key) { - opt.SetValue(value); - } - } - } }; class Jbc2MplCompiler : public Compiler { diff --git a/src/mapleall/maple_driver/src/compiler.cpp b/src/mapleall/maple_driver/src/compiler.cpp index ea872fbe49..8fb9f24cb4 100644 --- a/src/mapleall/maple_driver/src/compiler.cpp +++ b/src/mapleall/maple_driver/src/compiler.cpp @@ -64,34 +64,33 @@ ErrorCode Compiler::Compile(MplOptions &options, const Action &action, std::vector Compiler::MakeOption(const MplOptions &options, const Action &action) const { std::vector finalOptions; - std::map defaultOptions = MakeDefaultOptions(options, action); + std::vector defaultOptions = MakeDefaultOptions(options, action); AppendInputsAsOptions(finalOptions, options, action); AppendDefaultOptions(finalOptions, defaultOptions, options.HasSetDebugFlag()); - AppendExtraOptions(finalOptions, defaultOptions, options, options.HasSetDebugFlag()); + AppendExtraOptions(finalOptions, options, options.HasSetDebugFlag()); return finalOptions; } void Compiler::AppendDefaultOptions(std::vector &finalOptions, - const std::map &defaultOptions, + const std::vector &defaultOptions, bool isDebug) const { for (const auto &defaultIt : defaultOptions) { - (void)finalOptions.push_back(defaultIt.second); + (void)finalOptions.push_back(defaultIt); } if (isDebug) { LogInfo::MapleLogger() << Compiler::GetName() << " Default Options: "; for (const auto &defaultIt : defaultOptions) { - LogInfo::MapleLogger() << defaultIt.first << " " - << defaultIt.second.GetValue(); + LogInfo::MapleLogger() << defaultIt.GetKey() << " " + << defaultIt.GetValue(); } LogInfo::MapleLogger() << '\n'; } } void Compiler::AppendExtraOptions(std::vector &finalOptions, - std::map defaultOptions, const MplOptions &options, bool isDebug) const { const std::string &binName = GetTool(); auto exeOption = options.GetExeOptions().find(binName); @@ -107,13 +106,18 @@ void Compiler::AppendExtraOptions(std::vector &finalOptions, prefix = "--"; } - const std::string key = prefix + opt.OptionKey(); + const std::string baseKey = opt.OptionKey(); + const std::string key = prefix + baseKey; const std::string value = opt.Args(); - /* Update option if needed */ - auto it = defaultOptions.find(key); - if (it != defaultOptions.end()) { - ReplaceOption(finalOptions, key, value); + /* Default behaviour: extra options do not replace default options, + * because it can be some additional option with the same key. + * For example: we can have some default -isystem SYSTEM pathes option. + * And if some additional -isystem SYSTEM pathes is added, it's not correct + * to replace them (SYSTEM pathes msut be extended (not replaced)). + * If you need to replace some special option, check and replace it here */ + if (baseKey == "o") { + ReplaceOrInsertOption(finalOptions, key, value); } else { finalOptions.push_back(MplOption(key, value)); } @@ -129,6 +133,21 @@ void Compiler::AppendExtraOptions(std::vector &finalOptions, } } +void Compiler::ReplaceOrInsertOption(std::vector &finalOptions, + const std::string &key, const std::string &value) const { + bool wasFound = false; + for (auto &opt : finalOptions) { + if (opt.GetKey() == key) { + opt.SetValue(value); + wasFound = true; + } + } + + if (!wasFound) { + finalOptions.push_back(MplOption(key, value)); + } +} + void Compiler::AppendInputsAsOptions(std::vector &finalOptions, const MplOptions &mplOptions, const Action &action) const { std::vector splittedInputFileNames; @@ -140,14 +159,13 @@ void Compiler::AppendInputsAsOptions(std::vector &finalOptions, } } -std::map Compiler::MakeDefaultOptions(const MplOptions &options, - const Action &action) const { +std::vector Compiler::MakeDefaultOptions(const MplOptions &options, + const Action &action) const { DefaultOption rawDefaultOptions = GetDefaultOptions(options, action); - std::map defaultOptions; + std::vector defaultOptions; if (rawDefaultOptions.mplOptions != nullptr) { for (uint32_t i = 0; i < rawDefaultOptions.length; ++i) { - (void)defaultOptions.insert(std::make_pair(rawDefaultOptions.mplOptions[i].GetKey(), - rawDefaultOptions.mplOptions[i])); + (void)defaultOptions.push_back(rawDefaultOptions.mplOptions[i]); } } return defaultOptions; -- Gitee From 8c743f819f9bc6961eaadde3d74075c74862bf32 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Mon, 29 Nov 2021 13:18:26 +0300 Subject: [PATCH 05/21] [CI] Add new degradation tests for maple driver * DRIVER0003-macro tests macro options: -D and -U; * DRIVER0004-syslibs tests system library linking with -l option; * DRIVER0005-path tests path options -L and -I; --- .../driver_test/DRIVER0003-macro/expected.txt | 4 ++ .../driver_test/DRIVER0003-macro/helper.c | 31 ++++++++++++++ .../driver_test/DRIVER0003-macro/main.c | 38 ++++++++++++++++++ .../driver_test/DRIVER0003-macro/test.cfg | 2 + .../DRIVER0004-syslibs/expected.txt | 1 + .../driver_test/DRIVER0004-syslibs/main.c | 29 +++++++++++++ .../driver_test/DRIVER0004-syslibs/test.cfg | 2 + .../driver_test/DRIVER0005-path/expected.txt | 1 + .../DRIVER0005-path/includes/mylib.h | 4 ++ .../DRIVER0005-path/libs/libmylib.a | Bin 0 -> 1040 bytes .../c_test/driver_test/DRIVER0005-path/main.c | 26 ++++++++++++ .../driver_test/DRIVER0005-path/test.cfg | 2 + 12 files changed, 140 insertions(+) create mode 100644 testsuite/c_test/driver_test/DRIVER0003-macro/expected.txt create mode 100644 testsuite/c_test/driver_test/DRIVER0003-macro/helper.c create mode 100644 testsuite/c_test/driver_test/DRIVER0003-macro/main.c create mode 100644 testsuite/c_test/driver_test/DRIVER0003-macro/test.cfg create mode 100644 testsuite/c_test/driver_test/DRIVER0004-syslibs/expected.txt create mode 100644 testsuite/c_test/driver_test/DRIVER0004-syslibs/main.c create mode 100644 testsuite/c_test/driver_test/DRIVER0004-syslibs/test.cfg create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/expected.txt create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/main.c create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/test.cfg diff --git a/testsuite/c_test/driver_test/DRIVER0003-macro/expected.txt b/testsuite/c_test/driver_test/DRIVER0003-macro/expected.txt new file mode 100644 index 0000000000..f57d321a22 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0003-macro/expected.txt @@ -0,0 +1,4 @@ +TEST1 +HELPER TEST1 +RES: 40 +HELPER TEST2 10 diff --git a/testsuite/c_test/driver_test/DRIVER0003-macro/helper.c b/testsuite/c_test/driver_test/DRIVER0003-macro/helper.c new file mode 100644 index 0000000000..9ad6a5b4e3 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0003-macro/helper.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * 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 MulanPSL - 2.0 for more details. + */ + +#include +#include + +int helper(int in) +{ +#ifdef TEST1 + printf("HELPER TEST1\n"); +#endif + +#ifdef TEST2 + printf("HELPER TEST2\n"); +#endif + + return in * 2; +} + diff --git a/testsuite/c_test/driver_test/DRIVER0003-macro/main.c b/testsuite/c_test/driver_test/DRIVER0003-macro/main.c new file mode 100644 index 0000000000..c967a6db28 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0003-macro/main.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * 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 MulanPSL - 2.0 for more details. + */ + +#include +#include + +int helper(int in); + +int main(void) +{ +#ifdef TEST1 + printf("TEST1\n"); +#endif + +#ifdef TEST2 + printf("TEST2\n"); +#endif + + int res = helper(NUM); + printf("RES: %d\n", res); + +#ifdef TEST3 + printf("HELPER TEST2 %d\n", EXTRANUM); +#endif + return 0; +} diff --git a/testsuite/c_test/driver_test/DRIVER0003-macro/test.cfg b/testsuite/c_test/driver_test/DRIVER0003-macro/test.cfg new file mode 100644 index 0000000000..ad25f535d3 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0003-macro/test.cfg @@ -0,0 +1,2 @@ +compile(APP="main.c helper.c",OPTION="--no-maple-phase --static -DTEST1 -DNUM=20 -DTEST2 -UTEST2 -D TEST3 -D EXTRANUM=10") +run(a) diff --git a/testsuite/c_test/driver_test/DRIVER0004-syslibs/expected.txt b/testsuite/c_test/driver_test/DRIVER0004-syslibs/expected.txt new file mode 100644 index 0000000000..9ecdb58fc1 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0004-syslibs/expected.txt @@ -0,0 +1 @@ +sqrt(1024.0) = 32.0 diff --git a/testsuite/c_test/driver_test/DRIVER0004-syslibs/main.c b/testsuite/c_test/driver_test/DRIVER0004-syslibs/main.c new file mode 100644 index 0000000000..cb346561e8 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0004-syslibs/main.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * 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 MulanPSL - 2.0 for more details. + */ + +#include +#include + +#define PI 3.14 + +int main() +{ + double param, result; + param = 1024.0; + result = sqrt(param); + + printf ("sqrt(%.1f) = %.1f\n", param, result ); + return 0; +} diff --git a/testsuite/c_test/driver_test/DRIVER0004-syslibs/test.cfg b/testsuite/c_test/driver_test/DRIVER0004-syslibs/test.cfg new file mode 100644 index 0000000000..d576379fe0 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0004-syslibs/test.cfg @@ -0,0 +1,2 @@ +compile(APP=main.c,OPTION="--no-maple-phase --static -lm") +run(a) diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt b/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt new file mode 100644 index 0000000000..7501d9e823 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt @@ -0,0 +1 @@ +mylib H_NUM: 5, val: 40 diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h b/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h new file mode 100644 index 0000000000..c6b66c5277 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h @@ -0,0 +1,4 @@ +#define H_NUM 5 + +int mylib_doubleval(int in); + diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a b/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a new file mode 100644 index 0000000000000000000000000000000000000000..01afb78ecc9440c0c4aa14892647ed136d153e3d GIT binary patch literal 1040 zcmbtSO-jQ+6n-^YYj@g>pkNAuAet#sr3;aWRwxKc1y_YOZ3k1DG+{C=DFxkmmU;s1 zM#Mw7u1D|yMQ55BjWMqJAoN=ScQGLh-n7#SA!k>_+t1EW&sk~lX6dmg%Qap#z{PaNBAS(qS-J?eE^ z6r)C!`>07;Jxl`sv|PF_mUFq>{;q3K6KO~+$i|xOTCnLubc3LIeVZC}hLi+oN{?cn zg4Q&s0b1Sj +#include "mylib.h" + +int main() +{ + int in = 20; + int res = mylib_doubleval(in); + + printf ("mylib H_NUM: %d, val: %d\n", H_NUM, res); + return 0; +} diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg b/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg new file mode 100644 index 0000000000..afad22c368 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg @@ -0,0 +1,2 @@ +compile(APP=main.c,OPTION="--no-maple-phase --static -lmylib -L./libs -I./includes") +run(a) -- Gitee From 8971286f9478f5929714d1179ad9a76acc75a345 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Mon, 29 Nov 2021 14:44:26 +0300 Subject: [PATCH 06/21] [maple_driver] Raw ld phase implementation --- .../defs/default/O0_options_ld.def | 32 ++++++++++++++++++- src/mapleall/maple_driver/src/ld_compiler.cpp | 16 +++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_ld.def b/src/mapleall/maple_driver/defs/default/O0_options_ld.def index 9e26dfeeb6..914751db83 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_ld.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_ld.def @@ -1 +1,31 @@ -{} \ No newline at end of file +{"-plugin", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/liblto_plugin.so", true}, +{"-plugin-opt", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/lto-wrapper", true}, +{"-plugin-opt", "-fresolution=/tmp/ccU2hAX4.res", false}, +{"-plugin-opt", "-pass-through=-lgcc", false}, +{"-plugin-opt", "-pass-through=-lgcc_eh", false}, +{"-plugin-opt", "-pass-through=-lc", false}, +{"--sysroot", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc", true}, +{"--build-id", "", false}, +{"-Bstatic", "", false}, +{"-X", "", false}, +{"-EL", "", false}, +{"-maarch64linux", "", false}, +{"--fix-cortex-a53-835769", "", false}, +{"--fix-cortex-a53-843419", "", false}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crt1.o", "", true}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crti.o", "", true}, +{"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtbeginT.o", "", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/lib64", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/lib", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib", true}, +{"--start-group", "", false}, +{"-lgcc", "", false}, +{"-lgcc_eh", "", false}, +{"-lc", "", false}, +{"--end-group", "", false}, +{"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtend.o", "", true}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crtn.o", "", true}, \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/ld_compiler.cpp b/src/mapleall/maple_driver/src/ld_compiler.cpp index 2b54bf739f..8a48250321 100644 --- a/src/mapleall/maple_driver/src/ld_compiler.cpp +++ b/src/mapleall/maple_driver/src/ld_compiler.cpp @@ -27,7 +27,7 @@ std::string LdCompiler::GetBinPath(const MplOptions&) const { // TODO: Required to use ld instead of gcc; ld will be implemented later const std::string &LdCompiler::GetBinName() const { - return kBinNameGcc; + return kBinNameLd; } /* the tool name must be the same as exeName field in Descriptor structure */ @@ -44,10 +44,16 @@ DefaultOption LdCompiler::GetDefaultOptions(const MplOptions &options, const Act } for (uint32_t i = 0; i < defaultOptions.length; ++i) { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); + if (defaultOptions.mplOptions[i].GetValue() == "" && defaultOptions.mplOptions[i].GetNeedRootPath()) { + defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + + defaultOptions.mplOptions[i].GetKey()); + } + else { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } } return defaultOptions; } -- Gitee From ee230a1f9d81cda0d1dbb7aad55de3ba9e9bdcb6 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Mon, 24 Jan 2022 12:54:30 +0300 Subject: [PATCH 07/21] Ld phase improvements --- ...ptions_ld.def => aarch64_linux_gnu_ld.def} | 10 ---------- .../maple_driver/defs/default_options.def | 2 +- src/mapleall/maple_driver/src/ld_compiler.cpp | 20 ++++++++++--------- 3 files changed, 12 insertions(+), 20 deletions(-) rename src/mapleall/maple_driver/defs/default/{O0_options_ld.def => aarch64_linux_gnu_ld.def} (67%) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_ld.def b/src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def similarity index 67% rename from src/mapleall/maple_driver/defs/default/O0_options_ld.def rename to src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def index 914751db83..87c4942869 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_ld.def +++ b/src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def @@ -1,17 +1,7 @@ -{"-plugin", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/liblto_plugin.so", true}, -{"-plugin-opt", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/lto-wrapper", true}, -{"-plugin-opt", "-fresolution=/tmp/ccU2hAX4.res", false}, -{"-plugin-opt", "-pass-through=-lgcc", false}, -{"-plugin-opt", "-pass-through=-lgcc_eh", false}, -{"-plugin-opt", "-pass-through=-lc", false}, {"--sysroot", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc", true}, -{"--build-id", "", false}, {"-Bstatic", "", false}, -{"-X", "", false}, {"-EL", "", false}, {"-maarch64linux", "", false}, -{"--fix-cortex-a53-835769", "", false}, -{"--fix-cortex-a53-843419", "", false}, {"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crt1.o", "", true}, {"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crti.o", "", true}, {"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtbeginT.o", "", true}, diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index b923ab1fe2..5a73cd8f9a 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -122,7 +122,7 @@ static MplOption kAsDefaultOptions[] = { }; // O0 ld options static MplOption kLdDefaultOptions[] = { -#include "default/O0_options_ld.def" +#include "default/aarch64_linux_gnu_ld.def" }; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_DEFAULT_OPTIONS_H diff --git a/src/mapleall/maple_driver/src/ld_compiler.cpp b/src/mapleall/maple_driver/src/ld_compiler.cpp index 8a48250321..f0e0407b4a 100644 --- a/src/mapleall/maple_driver/src/ld_compiler.cpp +++ b/src/mapleall/maple_driver/src/ld_compiler.cpp @@ -44,15 +44,17 @@ DefaultOption LdCompiler::GetDefaultOptions(const MplOptions &options, const Act } for (uint32_t i = 0; i < defaultOptions.length; ++i) { - if (defaultOptions.mplOptions[i].GetValue() == "" && defaultOptions.mplOptions[i].GetNeedRootPath()) { - defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + - defaultOptions.mplOptions[i].GetKey()); - } - else { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); + if (defaultOptions.mplOptions[i].GetNeedRootPath()) { + if (defaultOptions.mplOptions[i].GetValue().empty()) { + defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + + defaultOptions.mplOptions[i].GetKey()); + } + else { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } } } return defaultOptions; -- Gitee From 2e686a314e35af38e959142db8677e41b2fe33e7 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 25 Nov 2021 13:42:27 +0300 Subject: [PATCH 08/21] [mapleall][driver] Add "target" and "isystem" as default options for clang-ast generator These options are needed to correct compile for aarch64. These options were tested with SPECCPU2017 benchmark. --- src/mapleall/maple_driver/src/clang_compiler.cpp | 5 +++++ src/mapleall/maple_driver/src/driver_option_common.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/mapleall/maple_driver/src/clang_compiler.cpp b/src/mapleall/maple_driver/src/clang_compiler.cpp index e5924a388c..634a45d822 100644 --- a/src/mapleall/maple_driver/src/clang_compiler.cpp +++ b/src/mapleall/maple_driver/src/clang_compiler.cpp @@ -29,8 +29,13 @@ const std::string &ClangCompiler::GetBinName() const { return kBinNameClang; } +<<<<<<< HEAD static uint32_t FillSpecialDefaulOpt(std::unique_ptr &opt, const Action &action) { +======= +static inline uint32_t FillSpecialDefaulOpt(std::unique_ptr &opt, + const Action &action) { +>>>>>>> [mapleall][driver] Add "target" and "isystem" as default options for clang-ast generator uint32_t additionalLen = 1; // for -o option /* TODO: Add check for the target architecture and OS environment. diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index 7652807453..d05c37185e 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -532,6 +532,15 @@ const mapleOption::Descriptor kUsages[] = { " -isystem \tAdd directory to SYSTEM include search path\n", "driver", {"clang"} }, + { kClangISystem, + 0, + "I", + "", + kBuildTypeAll, + kArgCheckPolicyRequired, + " -isystem \tAdd directory to SYSTEN include search path\n", + "all", + {"clang"} }, { kMaplePhaseOnly, kEnable, "", -- Gitee From fd933796534412b5c84216b27901db3e30151d3a Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Mon, 29 Nov 2021 13:18:26 +0300 Subject: [PATCH 09/21] [CI] Add new degradation tests for maple driver * DRIVER0003-macro tests macro options: -D and -U; * DRIVER0004-syslibs tests system library linking with -l option; * DRIVER0005-path tests path options -L and -I; --- .../driver_test/DRIVER0005-path/expected.txt | 1 + .../DRIVER0005-path/includes/mylib.h | 4 +++ .../DRIVER0005-path/libs/libmylib.a | Bin 0 -> 1040 bytes .../c_test/driver_test/DRIVER0005-path/main.c | 26 ++++++++++++++++++ .../driver_test/DRIVER0005-path/test.cfg | 2 ++ 5 files changed, 33 insertions(+) create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/expected.txt create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/main.c create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/test.cfg diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt b/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt new file mode 100644 index 0000000000..7501d9e823 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt @@ -0,0 +1 @@ +mylib H_NUM: 5, val: 40 diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h b/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h new file mode 100644 index 0000000000..c6b66c5277 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h @@ -0,0 +1,4 @@ +#define H_NUM 5 + +int mylib_doubleval(int in); + diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a b/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a new file mode 100644 index 0000000000000000000000000000000000000000..01afb78ecc9440c0c4aa14892647ed136d153e3d GIT binary patch literal 1040 zcmbtSO-jQ+6n-^YYj@g>pkNAuAet#sr3;aWRwxKc1y_YOZ3k1DG+{C=DFxkmmU;s1 zM#Mw7u1D|yMQ55BjWMqJAoN=ScQGLh-n7#SA!k>_+t1EW&sk~lX6dmg%Qap#z{PaNBAS(qS-J?eE^ z6r)C!`>07;Jxl`sv|PF_mUFq>{;q3K6KO~+$i|xOTCnLubc3LIeVZC}hLi+oN{?cn zg4Q&s0b1Sj +#include "mylib.h" + +int main() +{ + int in = 20; + int res = mylib_doubleval(in); + + printf ("mylib H_NUM: %d, val: %d\n", H_NUM, res); + return 0; +} diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg b/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg new file mode 100644 index 0000000000..afad22c368 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg @@ -0,0 +1,2 @@ +compile(APP=main.c,OPTION="--no-maple-phase --static -lmylib -L./libs -I./includes") +run(a) -- Gitee From 57062a84da373519093c8132e290750e56293f8f Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Mon, 29 Nov 2021 14:44:26 +0300 Subject: [PATCH 10/21] [maple_driver] Raw ld phase implementation --- .../defs/default/O0_options_ld.def | 32 ++++++++++++++++++- src/mapleall/maple_driver/src/ld_compiler.cpp | 16 +++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_ld.def b/src/mapleall/maple_driver/defs/default/O0_options_ld.def index 9e26dfeeb6..914751db83 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_ld.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_ld.def @@ -1 +1,31 @@ -{} \ No newline at end of file +{"-plugin", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/liblto_plugin.so", true}, +{"-plugin-opt", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/lto-wrapper", true}, +{"-plugin-opt", "-fresolution=/tmp/ccU2hAX4.res", false}, +{"-plugin-opt", "-pass-through=-lgcc", false}, +{"-plugin-opt", "-pass-through=-lgcc_eh", false}, +{"-plugin-opt", "-pass-through=-lc", false}, +{"--sysroot", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc", true}, +{"--build-id", "", false}, +{"-Bstatic", "", false}, +{"-X", "", false}, +{"-EL", "", false}, +{"-maarch64linux", "", false}, +{"--fix-cortex-a53-835769", "", false}, +{"--fix-cortex-a53-843419", "", false}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crt1.o", "", true}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crti.o", "", true}, +{"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtbeginT.o", "", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/lib64", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/lib", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib", true}, +{"--start-group", "", false}, +{"-lgcc", "", false}, +{"-lgcc_eh", "", false}, +{"-lc", "", false}, +{"--end-group", "", false}, +{"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtend.o", "", true}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crtn.o", "", true}, \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/ld_compiler.cpp b/src/mapleall/maple_driver/src/ld_compiler.cpp index 2b54bf739f..8a48250321 100644 --- a/src/mapleall/maple_driver/src/ld_compiler.cpp +++ b/src/mapleall/maple_driver/src/ld_compiler.cpp @@ -27,7 +27,7 @@ std::string LdCompiler::GetBinPath(const MplOptions&) const { // TODO: Required to use ld instead of gcc; ld will be implemented later const std::string &LdCompiler::GetBinName() const { - return kBinNameGcc; + return kBinNameLd; } /* the tool name must be the same as exeName field in Descriptor structure */ @@ -44,10 +44,16 @@ DefaultOption LdCompiler::GetDefaultOptions(const MplOptions &options, const Act } for (uint32_t i = 0; i < defaultOptions.length; ++i) { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); + if (defaultOptions.mplOptions[i].GetValue() == "" && defaultOptions.mplOptions[i].GetNeedRootPath()) { + defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + + defaultOptions.mplOptions[i].GetKey()); + } + else { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } } return defaultOptions; } -- Gitee From eefa5609ebc66fb9d9fb9a7ab03d3d50f2e288c6 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Mon, 24 Jan 2022 12:54:30 +0300 Subject: [PATCH 11/21] Ld phase improvements --- ...ptions_ld.def => aarch64_linux_gnu_ld.def} | 10 ---------- .../maple_driver/defs/default_options.def | 2 +- src/mapleall/maple_driver/src/ld_compiler.cpp | 20 ++++++++++--------- 3 files changed, 12 insertions(+), 20 deletions(-) rename src/mapleall/maple_driver/defs/default/{O0_options_ld.def => aarch64_linux_gnu_ld.def} (67%) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_ld.def b/src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def similarity index 67% rename from src/mapleall/maple_driver/defs/default/O0_options_ld.def rename to src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def index 914751db83..87c4942869 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_ld.def +++ b/src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def @@ -1,17 +1,7 @@ -{"-plugin", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/liblto_plugin.so", true}, -{"-plugin-opt", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/lto-wrapper", true}, -{"-plugin-opt", "-fresolution=/tmp/ccU2hAX4.res", false}, -{"-plugin-opt", "-pass-through=-lgcc", false}, -{"-plugin-opt", "-pass-through=-lgcc_eh", false}, -{"-plugin-opt", "-pass-through=-lc", false}, {"--sysroot", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc", true}, -{"--build-id", "", false}, {"-Bstatic", "", false}, -{"-X", "", false}, {"-EL", "", false}, {"-maarch64linux", "", false}, -{"--fix-cortex-a53-835769", "", false}, -{"--fix-cortex-a53-843419", "", false}, {"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crt1.o", "", true}, {"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crti.o", "", true}, {"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtbeginT.o", "", true}, diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index b923ab1fe2..5a73cd8f9a 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -122,7 +122,7 @@ static MplOption kAsDefaultOptions[] = { }; // O0 ld options static MplOption kLdDefaultOptions[] = { -#include "default/O0_options_ld.def" +#include "default/aarch64_linux_gnu_ld.def" }; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_DEFAULT_OPTIONS_H diff --git a/src/mapleall/maple_driver/src/ld_compiler.cpp b/src/mapleall/maple_driver/src/ld_compiler.cpp index 8a48250321..f0e0407b4a 100644 --- a/src/mapleall/maple_driver/src/ld_compiler.cpp +++ b/src/mapleall/maple_driver/src/ld_compiler.cpp @@ -44,15 +44,17 @@ DefaultOption LdCompiler::GetDefaultOptions(const MplOptions &options, const Act } for (uint32_t i = 0; i < defaultOptions.length; ++i) { - if (defaultOptions.mplOptions[i].GetValue() == "" && defaultOptions.mplOptions[i].GetNeedRootPath()) { - defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + - defaultOptions.mplOptions[i].GetKey()); - } - else { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); + if (defaultOptions.mplOptions[i].GetNeedRootPath()) { + if (defaultOptions.mplOptions[i].GetValue().empty()) { + defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + + defaultOptions.mplOptions[i].GetKey()); + } + else { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } } } return defaultOptions; -- Gitee From 23dd47d6179993446d194899c557fd51216a9dda Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Thu, 27 Jan 2022 12:39:56 +0300 Subject: [PATCH 12/21] [mapleall][driver] Duplicate lines and unnecessary files lines removal --- .../maple_driver/src/driver_option_common.cpp | 27 ------------------ .../driver_test/DRIVER0005-path/expected.txt | 1 - .../DRIVER0005-path/includes/mylib.h | 4 --- .../DRIVER0005-path/libs/libmylib.a | Bin 1040 -> 0 bytes .../c_test/driver_test/DRIVER0005-path/main.c | 26 ----------------- .../driver_test/DRIVER0005-path/test.cfg | 2 -- 6 files changed, 60 deletions(-) delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/expected.txt delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/main.c delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/test.cfg diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index 93edb0c670..7652807453 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -514,15 +514,6 @@ const mapleOption::Descriptor kUsages[] = { " -U \tUndefine macro \n", "driver", {"clang"} }, - { kClangMacro, - 0, - "U", - "", - kBuildTypeAll, - kArgCheckPolicyRequired, - " -U \tUndefine macro \n", - "all", - {"clang"} }, { kClangInclude, 0, "I", @@ -541,24 +532,6 @@ const mapleOption::Descriptor kUsages[] = { " -isystem \tAdd directory to SYSTEM include search path\n", "driver", {"clang"} }, - { kClangISystem, - 0, - "I", - "", - kBuildTypeAll, - kArgCheckPolicyRequired, - " -isystem \tAdd directory to SYSTEN include search path\n", - "all", - {"clang"} }, - { kClangISystem, - 0, - "I", - "", - kBuildTypeAll, - kArgCheckPolicyRequired, - " -isystem \tAdd directory to SYSTEN include search path\n", - "all", - {"clang"} }, { kMaplePhaseOnly, kEnable, "", diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt b/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt deleted file mode 100644 index 7501d9e823..0000000000 --- a/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt +++ /dev/null @@ -1 +0,0 @@ -mylib H_NUM: 5, val: 40 diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h b/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h deleted file mode 100644 index c6b66c5277..0000000000 --- a/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h +++ /dev/null @@ -1,4 +0,0 @@ -#define H_NUM 5 - -int mylib_doubleval(int in); - diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a b/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a deleted file mode 100644 index 01afb78ecc9440c0c4aa14892647ed136d153e3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1040 zcmbtSO-jQ+6n-^YYj@g>pkNAuAet#sr3;aWRwxKc1y_YOZ3k1DG+{C=DFxkmmU;s1 zM#Mw7u1D|yMQ55BjWMqJAoN=ScQGLh-n7#SA!k>_+t1EW&sk~lX6dmg%Qap#z{PaNBAS(qS-J?eE^ z6r)C!`>07;Jxl`sv|PF_mUFq>{;q3K6KO~+$i|xOTCnLubc3LIeVZC}hLi+oN{?cn zg4Q&s0b1Sj -#include "mylib.h" - -int main() -{ - int in = 20; - int res = mylib_doubleval(in); - - printf ("mylib H_NUM: %d, val: %d\n", H_NUM, res); - return 0; -} diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg b/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg deleted file mode 100644 index afad22c368..0000000000 --- a/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg +++ /dev/null @@ -1,2 +0,0 @@ -compile(APP=main.c,OPTION="--no-maple-phase --static -lmylib -L./libs -I./includes") -run(a) -- Gitee From fc1a5648a7d8dc80a9c385140d6a04f030266c4e Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Tue, 25 Jan 2022 17:43:31 +0300 Subject: [PATCH 13/21] [mapleall][driver] Fix remark from CodeDex static analyzer CID 98928871: (AssertUsedAtRuntime) Variable 'len' is the return value of function 'readlink'. The return value of system or dorpa library function cannot be verified within ASSERT. --- src/mapleall/maple_driver/src/file_utils.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_driver/src/file_utils.cpp b/src/mapleall/maple_driver/src/file_utils.cpp index 2eab48fc85..a2d9ea466b 100644 --- a/src/mapleall/maple_driver/src/file_utils.cpp +++ b/src/mapleall/maple_driver/src/file_utils.cpp @@ -93,7 +93,10 @@ std::string FileUtils::GetExecutable() { const char *symLinkToCurrentExe = "/proc/self/exe"; int len = static_cast(readlink(symLinkToCurrentExe, exePath, sizeof(exePath))); - ASSERT(len >= 0, "Something wrong: %d, Not Linux System??\n", len); + if (len < 0) { + LogInfo::MapleLogger(kLlErr) << "Currently toolchain supports only Linux System\n"; + return ""; + } /* Add Null terminate for the string: readlink does not * append a terminating null byte to buf */ -- Gitee From 40a239f3620cca0b76630445bcaee4b20c456f6c Mon Sep 17 00:00:00 2001 From: linma Date: Mon, 24 Jan 2022 22:23:53 -0800 Subject: [PATCH 14/21] delete more empty fallthru BBs in optimiseCFG bblayout phase --- src/mapleall/maple_me/include/me_bb_layout.h | 1 + src/mapleall/maple_me/src/me_bb_layout.cpp | 54 +++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/mapleall/maple_me/include/me_bb_layout.h b/src/mapleall/maple_me/include/me_bb_layout.h index 99d100a206..a5d51856ba 100644 --- a/src/mapleall/maple_me/include/me_bb_layout.h +++ b/src/mapleall/maple_me/include/me_bb_layout.h @@ -236,6 +236,7 @@ class BBLayout { void LayoutWithoutProf(); void RunLayout(); void DumpBBPhyOrder() const; + void VerifyBB(); private: void FixEndTryBB(BB &bb); diff --git a/src/mapleall/maple_me/src/me_bb_layout.cpp b/src/mapleall/maple_me/src/me_bb_layout.cpp index 4052b07a1e..7c54247dab 100644 --- a/src/mapleall/maple_me/src/me_bb_layout.cpp +++ b/src/mapleall/maple_me/src/me_bb_layout.cpp @@ -947,16 +947,27 @@ BB *BBLayout::CreateGotoBBAfterCondBB(BB &bb, BB &fallthru) { void BBLayout::OptimizeEmptyFallThruBB(BB &bb) { if (needDealWithTryBB) { return; } auto *fallthru = bb.GetSucc().front(); - if (fallthru && fallthru->GetBBLabel() == 0 && - (BBEmptyAndFallthru(*fallthru) || BBContainsOnlyGoto(*fallthru))) { - if (fallthru->GetSucc().front() == bb.GetSucc().back()) { - bb.ReplaceSucc(fallthru, bb.GetSucc().back()); + while (fallthru && (fallthru->GetPred().size() == 1) && + (BBEmptyAndFallthru(*fallthru) || BBContainsOnlyGoto(*fallthru))) { + BB *newFallthru = fallthru->GetSucc().front(); + if (newFallthru == bb.GetSucc().back()) { + bb.ReplaceSucc(fallthru, newFallthru); ASSERT(fallthru->GetPred().empty(), "fallthru should not has other pred"); ChangeToFallthruFromCondGoto(bb); bb.GetSucc().resize(1); // resize succ to 1 - laidOut[fallthru->GetBBId()] = true; - RemoveUnreachable(*fallthru); + } else if (newFallthru->GetPred().size() == 1) { + if (newFallthru->GetBBLabel() != 0) { + // reset newFallthru label + newFallthru->SetBBLabel(0); + } + // replace empty fallthru with fallthru's succ + bb.ReplaceSucc(fallthru, newFallthru); + } else { + break; } + laidOut[fallthru->GetBBId()] = true; + RemoveUnreachable(*fallthru); + fallthru = newFallthru; } } @@ -993,6 +1004,19 @@ void BBLayout::OptimiseCFG() { } } (void)cfg->UnreachCodeAnalysis(false); + + // do 2nd fallthru optimize if succs of bb were optimized by first iteration + for (auto bIt = cfg->valid_begin(); bIt != cfg->valid_end(); ++bIt) { + if (bIt == cfg->common_entry() || bIt == cfg->common_exit()) { + continue; + } + auto *bb = *bIt; + if (bb->GetKind() == kBBCondGoto) { + OptimizeEmptyFallThruBB(*bb); + } + } + (void)cfg->UnreachCodeAnalysis(false); + } void BBLayout::SetAttrTryForTheCanBeMovedBB(BB &bb, BB &canBeMovedBB) const { @@ -1306,6 +1330,21 @@ void BBLayout::RunLayout() { } } +// check condBB if they have same succs +void BBLayout::VerifyBB() { + for (auto bIt = cfg->valid_begin(); bIt != cfg->valid_end(); ++bIt) { + auto *bb = *bIt; + if (bb->GetKind() == kBBCondGoto) { + auto *fallthru = bb->GetSucc(0); + auto *targetBB = bb->GetSucc(1); + if (fallthru == targetBB || + (BBEmptyAndFallthru(*fallthru) && (fallthru->GetSucc(0) == targetBB))) { + LogInfo::MapleLogger() << "WARN: cond BB " << bb->GetBBId() << " has same target"; + } + } + } +} + void MEBBLayout::GetAnalysisDependence(maple::AnalysisDep &aDep) const { aDep.AddRequired(); aDep.AddRequired(); @@ -1322,7 +1361,10 @@ bool MEBBLayout::PhaseRun(maple::MeFunction &f) { } bbLayout->RunLayout(); f.SetLaidOutBBs(bbLayout->GetBBs()); + if (DEBUGFUNC_NEWPM(f)) { + // verify CFG : check condBB's succs should be different + bbLayout->VerifyBB(); bbLayout->DumpBBPhyOrder(); cfg->DumpToFile("afterBBLayout", false); } -- Gitee From 1d5fb29402816ff038a8e9fa3d9320286407c835 Mon Sep 17 00:00:00 2001 From: binaryfz Date: Thu, 27 Jan 2022 14:50:52 +0800 Subject: [PATCH 15/21] [mapleall]Internal commit msg: [mapleall] PCLint warning fix 2. --- .../include/cg/aarch64/aarch64_cgfunc.h | 2 +- .../include/cg/aarch64/aarch64_operand.h | 4 +- .../include/cg/aarch64/aarch64_prop.h | 2 +- .../include/cg/aarch64/aarch64_ra_opt.h | 2 +- .../include/cg/aarch64/aarch64_strldr.h | 2 +- src/mapleall/maple_be/include/cg/ebo.h | 2 +- src/mapleall/maple_be/include/cg/loop.h | 2 +- src/mapleall/maple_be/include/cg/peep.h | 2 +- src/mapleall/maple_be/include/cg/pressure.h | 2 +- .../src/cg/aarch64/aarch64_cgfunc.cpp | 2 +- .../src/cg/aarch64/aarch64_offset_adjust.cpp | 6 +-- .../src/cg/aarch64/aarch64_operand.cpp | 2 +- .../maple_be/src/cg/aarch64/aarch64_opnd.def | 14 ++--- .../maple_be/src/cg/aarch64/aarch64_peep.cpp | 4 +- .../src/cg/aarch64/aarch64_proepilog.cpp | 32 +++++------ .../maple_be/src/cg/aarch64/aarch64_prop.cpp | 12 ++--- .../src/cg/aarch64/aarch64_ra_opt.cpp | 4 +- .../src/cg/aarch64/aarch64_reg_alloc.cpp | 2 +- .../maple_be/src/cg/aarch64/aarch64_ssa.cpp | 6 +-- .../src/cg/aarch64/aarch64_strldr.cpp | 4 +- src/mapleall/maple_be/src/cg/cg_dominance.cpp | 8 +-- src/mapleall/maple_be/src/cg/cg_ssa.cpp | 4 +- src/mapleall/maple_be/src/cg/ebo.cpp | 6 +-- src/mapleall/maple_be/src/cg/emit.cpp | 14 ++--- src/mapleall/maple_be/src/cg/loop.cpp | 2 +- src/mapleall/maple_be/src/cg/peep.cpp | 14 ++--- src/mapleall/maple_be/src/cg/schedule.cpp | 32 +++++------ src/mapleall/maple_me/include/me_bb_layout.h | 1 - src/mapleall/maple_me/src/me_bb_layout.cpp | 54 +++---------------- 29 files changed, 101 insertions(+), 142 deletions(-) diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h index 66084f5de5..f06bf9c097 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -519,7 +519,7 @@ class AArch64CGFunc : public CGFunc { return cleanEANode; } - AArch64MemOperand &CreateStkTopOpnd(int32 offset, int32 size); + AArch64MemOperand &CreateStkTopOpnd(uint32 offset, uint32 size); /* if offset < 0, allocation; otherwise, deallocation */ AArch64MemOperand &CreateCallFrameOperand(int32 offset, int32 size); diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_operand.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_operand.h index 0d361b58a4..d4e514bb15 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_operand.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_operand.h @@ -820,8 +820,8 @@ class AArch64MemOperand : public MemOperand { return IsExtendedRegisterMode() && !SignedExtend(); } - int32 ShiftAmount() const { - int32 scale = extend & 0xF; + uint32 ShiftAmount() const { + uint32 scale = extend & 0xF; /* 8 is 1 << 3, 4 is 1 << 2, 2 is 1 << 1, 1 is 1 << 0; */ return (scale == 8) ? 3 : ((scale == 4) ? 2 : ((scale == 2) ? 1 : 0)); } diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_prop.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_prop.h index d067d3c3f8..d3746e1086 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_prop.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_prop.h @@ -64,7 +64,7 @@ class A64StrLdrProp { void DoMemReplace(const RegOperand &replacedReg, AArch64MemOperand &newMem, Insn &useInsn); uint32 GetMemOpndIdx(AArch64MemOperand *newMemOpnd, const Insn &insn); - bool CheckSameReplace(const RegOperand &replacedReg, AArch64MemOperand *memOpnd); + bool CheckSameReplace(const RegOperand &replacedReg, const AArch64MemOperand *memOpnd); CGFunc *cgFunc; CGSSAInfo *ssaInfo; diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_ra_opt.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_ra_opt.h index 4fc3df7462..395b492b51 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_ra_opt.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_ra_opt.h @@ -130,7 +130,7 @@ class VregRename { void RenameFindLoopVregs(const CGFuncLoops *loop); void RenameFindVregsToRename(const CGFuncLoops *loop); - bool IsProfitableToRename(VregRenameInfo *info) const; + bool IsProfitableToRename(const VregRenameInfo *info) const; void RenameProfitableVreg(RegOperand *ropnd, const CGFuncLoops *loop); void RenameGetFuncVregInfo(); void UpdateVregInfo(regno_t reg, BB *bb, bool isInner, bool isDef); diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_strldr.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_strldr.h index 2c688b3c1d..ad61524967 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_strldr.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_strldr.h @@ -50,7 +50,7 @@ class AArch64StoreLoadOpt : public StoreLoadOpt { AArch64MemOperand *HandleArithImmDef(AArch64RegOperand &replace, Operand *oldOffset, int64 defVal); AArch64MemOperand *SelectReplaceMem(Insn &defInsn, Insn &curInsn, RegOperand &base, Operand *offset); AArch64MemOperand *SelectReplaceExt(const Insn &defInsn, RegOperand &base, bool isSigned); - bool CanDoMemProp(Insn *insn); + bool CanDoMemProp(const Insn *insn); bool CanDoIndexOpt(const AArch64MemOperand &MemOpnd); void MemPropInit(); void SelectPropMode(const AArch64MemOperand &currMemOpnd); diff --git a/src/mapleall/maple_be/include/cg/ebo.h b/src/mapleall/maple_be/include/cg/ebo.h index 0a710e4fff..17a2e5dd70 100644 --- a/src/mapleall/maple_be/include/cg/ebo.h +++ b/src/mapleall/maple_be/include/cg/ebo.h @@ -215,7 +215,7 @@ class Ebo { virtual bool IsSameRedefine(BB &bb, Insn &insn, OpndInfo &opndInfo) const = 0; virtual bool ResIsNotDefAndUse(Insn &insn) const = 0; virtual bool LiveOutOfBB(const Operand &opnd, const BB &bb) const = 0; - OpndInfo *BuildMemOpndInfo(BB &bb, Insn &insn, Operand &opnd, int32 opndIndex); + OpndInfo *BuildMemOpndInfo(BB &bb, Insn &insn, Operand &opnd, uint32 opndIndex); OpndInfo *BuildOperandInfo(BB &bb, Insn &insn, Operand &opnd, uint32 opndIndex, MapleVector &origInfos); bool ForwardPropagateOpnd(Insn &insn, Operand *&opnd, uint32 opndIndex, OpndInfo *&opndInfo, MapleVector &origInfos); diff --git a/src/mapleall/maple_be/include/cg/loop.h b/src/mapleall/maple_be/include/cg/loop.h index 581b31406a..8a67c29a29 100644 --- a/src/mapleall/maple_be/include/cg/loop.h +++ b/src/mapleall/maple_be/include/cg/loop.h @@ -138,7 +138,7 @@ class LoopFinder : public AnalysisResult { void MergeLoops(); void SortLoops(); void UpdateOuterForInnerLoop(BB *bb, LoopHierarchy *outer); - void UpdateOuterLoop(LoopHierarchy *outer); + void UpdateOuterLoop(const LoopHierarchy *loop); void CreateInnerLoop(LoopHierarchy &inner, LoopHierarchy &outer); void DetectInnerLoop(); void UpdateCGFunc(); diff --git a/src/mapleall/maple_be/include/cg/peep.h b/src/mapleall/maple_be/include/cg/peep.h index d88154c52d..fb2557b366 100644 --- a/src/mapleall/maple_be/include/cg/peep.h +++ b/src/mapleall/maple_be/include/cg/peep.h @@ -67,7 +67,7 @@ class CGPeepPattern { virtual bool CheckCondition(Insn &insn) = 0; virtual std::string GetPatternName() = 0; Insn *GetDefInsn(const RegOperand &useReg); - void DumpAfterPattern(std::vector &prevInsns, Insn *replacedInsn, Insn *newInsn); + void DumpAfterPattern(std::vector &prevInsns, const Insn *replacedInsn, const Insn *newInsn); int64 GetLogValueAtBase2(int64 val) const; /* The CC reg is unique and cannot cross-version props. */ bool IsCCRegCrossVersion(Insn &startInsn, Insn &endInsn, RegOperand &ccReg); diff --git a/src/mapleall/maple_be/include/cg/pressure.h b/src/mapleall/maple_be/include/cg/pressure.h index fbee594e33..72051385f9 100644 --- a/src/mapleall/maple_be/include/cg/pressure.h +++ b/src/mapleall/maple_be/include/cg/pressure.h @@ -25,7 +25,7 @@ struct RegList { }; #define FOR_ALL_REGCLASS(i) \ - for (int32 i = 0; i < RegPressure::GetMaxRegClassNum(); ++i) + for (uint32 i = 0; i < static_cast(RegPressure::GetMaxRegClassNum()); ++i) class RegPressure { public: diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index c4ddb998c4..555ba36b75 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -5707,7 +5707,7 @@ AArch64CGFunc::MovkLslOperandArray AArch64CGFunc::movkLslOperands = { /* kShiftAmount12 = 12, less than 16, use 4 bit to store, bitLen is 4 */ LogicalShiftLeftOperand AArch64CGFunc::addSubLslOperand(kShiftAmount12, 4); -AArch64MemOperand &AArch64CGFunc::CreateStkTopOpnd(int32 offset, int32 size) { +AArch64MemOperand &AArch64CGFunc::CreateStkTopOpnd(uint32 offset, uint32 size) { return *memPool->New(RFP, offset, size); } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_offset_adjust.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_offset_adjust.cpp index eb8903c1c0..6ff8a897b6 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_offset_adjust.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_offset_adjust.cpp @@ -142,7 +142,7 @@ void AArch64FPLROffsetAdjustment::AdjustmentStackPointer(Insn &insn, AArch64CGFu if (memOpnd.GetAddrMode() == AArch64MemOperand::kAddrModeBOi) { OfstOperand *ofstOpnd = memOpnd.GetOffsetOperand(); OfstOperand *newOfstOpnd = &aarchCGFunc.GetOrCreateOfstOpnd( - ofstOpnd->GetValue() + static_cast(offset), ofstOpnd->GetSize()); + static_cast(ofstOpnd->GetValue() + offset), ofstOpnd->GetSize()); AArch64MemOperand &newOfstMemOpnd = aarchCGFunc.GetOrCreateMemOpnd( AArch64MemOperand::kAddrModeBOi, memOpnd.GetSize(), memOpnd.GetBaseRegister(), memOpnd.GetIndexRegister(), newOfstOpnd, memOpnd.GetSymbol()); @@ -157,7 +157,7 @@ void AArch64FPLROffsetAdjustment::AdjustmentStackPointer(Insn &insn, AArch64CGFu } else if (memOpnd.GetAddrMode() == AArch64MemOperand::kAddrModeBOrX) { CHECK_FATAL(false, "Unexpect adjust insn"); } else { - (void)insn.Dump(); + insn.Dump(); CHECK_FATAL(false, "Unexpect adjust insn"); } } @@ -198,7 +198,7 @@ void AArch64FPLROffsetAdjustment::AdjustmentStackPointer(Insn &insn, AArch64CGFu break; } default: - (void)insn.Dump(); + insn.Dump(); CHECK_FATAL(false, "Unexpect offset adjustment insn"); } } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp index a12271ce82..a50a95ca19 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp @@ -87,7 +87,7 @@ void AArch64RegOperand::EmitVectorOpnd(Emitter &emitter) const { break; } emitter.Emit(AArch64CG::vectorRegNames[regNO]); - uint32 lanePos = GetVecLanePosition(); + int32 lanePos = GetVecLanePosition(); if (lanePos == -1) { emitter.Emit("." + std::to_string(GetVecLaneSize()) + width); } else { diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_opnd.def b/src/mapleall/maple_be/src/cg/aarch64/aarch64_opnd.def index 653d07afe6..5e5be5b353 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_opnd.def +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_opnd.def @@ -40,8 +40,9 @@ AArch64OpndProp mopdIntImm6Src = {Operand::kOpdImmediate, {kRegTyUndef, kAllRegN AArch64OpndProp mopdIntImm8Src = {Operand::kOpdImmediate, {kRegTyUndef, kAllRegNum, kRegPropUse}, 8}; bool Imm12BitValid(int64 value) { - bool result = maplebe::IsBitSizeImmediate(value, kMaxImmVal12Bits, 0); - result = result || maplebe::IsBitSizeImmediate(value, kMaxImmVal12Bits, kMaxImmVal12Bits); // for target linux-aarch64-gnu + bool result = maplebe::IsBitSizeImmediate(static_cast(value), kMaxImmVal12Bits, 0); + // for target linux-aarch64-gnu + result = result || maplebe::IsBitSizeImmediate(static_cast(value), kMaxImmVal12Bits, kMaxImmVal12Bits); return result; } @@ -53,8 +54,9 @@ bool Imm12BitMaskValid(int64 value) { } bool Imm13BitValid(int64 value) { - bool result = maplebe::IsBitSizeImmediate(value, kMaxImmVal13Bits, 0); - result = result || maplebe::IsBitSizeImmediate(value, kMaxImmVal13Bits, kMaxImmVal13Bits); // for target linux-aarch64-gnu + bool result = maplebe::IsBitSizeImmediate(static_cast(value), kMaxImmVal13Bits, 0); + // for target linux-aarch64-gnu + result = result || maplebe::IsBitSizeImmediate(static_cast(value), kMaxImmVal13Bits, kMaxImmVal13Bits); return result; } @@ -66,13 +68,13 @@ bool Imm13BitMaskValid(int64 value) { } bool Imm16BitValid(int64 value) { - bool result = maplebe::IsBitSizeImmediate(value, kMaxImmVal16Bits, 0); + bool result = maplebe::IsBitSizeImmediate(static_cast(value), kMaxImmVal16Bits, 0); /* * for target linux-aarch64-gnu * aarch64 assembly takes up to 24-bits immediate, generating * either cmp or cmp with shift 12 encoding */ - result = result || maplebe::IsBitSizeImmediate(value, kMaxImmVal12Bits, kMaxImmVal12Bits); + result = result || maplebe::IsBitSizeImmediate(static_cast(value), kMaxImmVal12Bits, kMaxImmVal12Bits); return result; } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_peep.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_peep.cpp index 6dd9c4f39d..e23edebf1e 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_peep.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_peep.cpp @@ -2064,7 +2064,7 @@ void EnhanceStrLdrAArch64::Run(BB &bb, Insn &insn) { static_cast(prevInsn->GetOperand(kInsnSecondOpnd))); auto &ofstOpnd = static_cast(prevInsn->GetOperand(kInsnThirdOpnd)); AArch64OfstOperand &offOpnd = static_cast(cgFunc).GetOrCreateOfstOpnd( - ofstOpnd.GetValue(), k32BitSize); + static_cast(ofstOpnd.GetValue()), k32BitSize); auto *origOffOpnd = concreteMemOpnd.GetOffsetImmediate(); concreteMemOpnd.SetOffsetImmediate(offOpnd); if (!static_cast(cgFunc).IsOperandImmValid(insn.GetMachineOpcode(), &memOpnd, kInsnSecondOpnd)) { @@ -2323,7 +2323,7 @@ void CombineContiLoadAndStoreAArch64::Run(BB &bb, Insn &insn) { } int64 offsetVal = offsetOpnd->GetOffsetValue(); int64 prevOffsetVal = prevOffsetOpnd->GetOffsetValue(); - int64 diffVal = std::abs(offsetVal - prevOffsetVal); + auto diffVal = std::abs(offsetVal - prevOffsetVal); /* do combination str/ldr -> stp/ldp */ if ((insn.IsStore() || destOpnd.GetRegisterNumber() != prevDestOpnd.GetRegisterNumber()) || (destOpnd.GetRegisterNumber() == RZR && prevDestOpnd.GetRegisterNumber() == RZR)) { diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_proepilog.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_proepilog.cpp index 26bf53d113..60766b63cb 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_proepilog.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_proepilog.cpp @@ -213,13 +213,13 @@ bool AArch64GenProEpilog::TailCallOpt() { } else { exitBB = cgFunc.GetExitBBsVec().front(); } - size_t i = 1; - int optCount = 0; + uint32 i = 1; + uint32 optCount = 0; do { std::set callInsns; TailCallBBOpt(*exitBB, callInsns, *exitBB); if (callInsns.size() != 0) { - optCount += static_cast(callInsns.size()); + optCount += callInsns.size(); exitBB2CallSitesMap[exitBB] = callInsns; } if (i < exitBBSize) { @@ -339,7 +339,7 @@ void AArch64GenProEpilog::GenStackGuard(BB &bb) { } } - int32 stkSize = static_cast(cgFunc.GetMemlayout())->RealStackFrameSize(); + auto stkSize = static_cast(cgFunc.GetMemlayout())->RealStackFrameSize(); if (useFP) { stkSize -= static_cast(cgFunc.GetMemlayout())->SizeOfArgsToStackPass(); } @@ -401,7 +401,7 @@ BB &AArch64GenProEpilog::GenStackGuardCheckInsn(BB &bb) { AArch64RegOperand &checkOp = aarchCGFunc.GetOrCreatePhysicalRegisterOperand(R10, kSizeOfPtr * kBitsPerByte, kRegTyInt); - int32 stkSize = static_cast(cgFunc.GetMemlayout())->RealStackFrameSize(); + auto stkSize = static_cast(cgFunc.GetMemlayout())->RealStackFrameSize(); if (useFP) { stkSize -= static_cast(cgFunc.GetMemlayout())->SizeOfArgsToStackPass(); } @@ -1210,16 +1210,16 @@ void AArch64GenProEpilog::GeneratePushRegs() { CHECK_FATAL(*it == RLR, "The second callee saved reg is expected to be RLR"); ++it; - int32 offset = static_cast(cgFunc.GetMemlayout())->RealStackFrameSize() - - (aarchCGFunc.SizeOfCalleeSaved() - (kDivide2 * kIntregBytelen) /* for FP/LR */) - - cgFunc.GetMemlayout()->SizeOfArgsToStackPass(); + auto offset = static_cast(static_cast(cgFunc.GetMemlayout())->RealStackFrameSize() - + (aarchCGFunc.SizeOfCalleeSaved() - (kDivide2 * kIntregBytelen) /* for FP/LR */) - + cgFunc.GetMemlayout()->SizeOfArgsToStackPass()); if (cgFunc.GetMirModule().IsCModule() && cgFunc.GetFunction().GetAttr(FUNCATTR_varargs)) { /* GR/VR save areas are above the callee save area */ AArch64MemLayout *ml = static_cast(cgFunc.GetMemlayout()); - uint64 saveareasize = RoundUp(ml->GetSizeOfGRSaveArea(), kSizeOfPtr * k2BitSize) + - RoundUp(ml->GetSizeOfVRSaveArea(), kSizeOfPtr * k2BitSize); - offset -= static_cast(saveareasize); + auto saveareasize = static_cast(RoundUp(ml->GetSizeOfGRSaveArea(), kSizeOfPtr * k2BitSize) + + RoundUp(ml->GetSizeOfVRSaveArea(), kSizeOfPtr * k2BitSize)); + offset -= saveareasize; } for (; it != regsToSave.end(); ++it) { @@ -1262,11 +1262,11 @@ void AArch64GenProEpilog::GeneratePushUnnamedVarargRegs() { if (cgFunc.GetMirModule().IsCModule() && cgFunc.GetFunction().GetAttr(FUNCATTR_varargs)) { AArch64MemLayout *memlayout = static_cast(cgFunc.GetMemlayout()); uint32 dataSizeBits = kSizeOfPtr * kBitsPerByte; - int32 offset = memlayout->GetGRSaveAreaBaseLoc(); + uint32 offset = memlayout->GetGRSaveAreaBaseLoc(); if (memlayout->GetSizeOfGRSaveArea() % kAarch64StackPtrAlignment) { offset += kSizeOfPtr; /* End of area should be aligned. Hole between VR and GR area */ } - int32 start_regno = k8BitSize - (memlayout->GetSizeOfGRSaveArea() / kSizeOfPtr); + uint32 start_regno = k8BitSize - (memlayout->GetSizeOfGRSaveArea() / kSizeOfPtr); ASSERT(start_regno <= k8BitSize, "Incorrect starting GR regno for GR Save Area"); for (uint32 i = start_regno + static_cast(R0); i < static_cast(R8); i++) { Operand &stackloc = aarchCGFunc.CreateStkTopOpnd(offset, dataSizeBits); @@ -1657,9 +1657,9 @@ void AArch64GenProEpilog::GeneratePopRegs() { if (cgFunc.GetMirModule().IsCModule() && cgFunc.GetFunction().GetAttr(FUNCATTR_varargs)) { /* GR/VR save areas are above the callee save area */ AArch64MemLayout *ml = static_cast(cgFunc.GetMemlayout()); - uint64 saveareasize = RoundUp(ml->GetSizeOfGRSaveArea(), kSizeOfPtr * k2BitSize) + - RoundUp(ml->GetSizeOfVRSaveArea(), kSizeOfPtr * k2BitSize); - offset -= static_cast(saveareasize); + auto saveareasize = static_cast(RoundUp(ml->GetSizeOfGRSaveArea(), kSizeOfPtr * k2BitSize) + + RoundUp(ml->GetSizeOfVRSaveArea(), kSizeOfPtr * k2BitSize)); + offset -= saveareasize; } /* diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_prop.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_prop.cpp index f9b29a9f0f..dca1fd6194 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_prop.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_prop.cpp @@ -469,7 +469,7 @@ bool A64StrLdrProp::ReplaceMemOpnd(const AArch64MemOperand &currMemOpnd, Insn *d return false; } -bool A64StrLdrProp::CheckSameReplace(const RegOperand &replacedReg, AArch64MemOperand *memOpnd) { +bool A64StrLdrProp::CheckSameReplace(const RegOperand &replacedReg, const AArch64MemOperand *memOpnd) { if (memOpnd != nullptr && memPropMode != kUndef) { if (memPropMode == kPropBase) { return replacedReg.GetRegisterNumber() == memOpnd->GetBaseRegister()->GetRegisterNumber(); @@ -483,7 +483,7 @@ bool A64StrLdrProp::CheckSameReplace(const RegOperand &replacedReg, AArch64MemOp } uint32 A64StrLdrProp::GetMemOpndIdx(AArch64MemOperand *newMemOpnd, const Insn &insn) { - int32 opndIdx = kInsnMaxOpnd; + uint32 opndIdx = kInsnMaxOpnd; if (insn.IsLoadPair() || insn.IsStorePair()) { ASSERT(newMemOpnd->GetOffsetImmediate() != nullptr, "unexpect insn"); opndIdx = kInsnThirdOpnd; @@ -540,7 +540,7 @@ MemPropMode A64StrLdrProp::SelectStrLdrPropMode(const AArch64MemOperand &currMem } case AArch64MemOperand::kAddrModeBOrX: { innerMemPropMode = kPropOffset; - uint32 amount = currMemOpnd.ShiftAmount(); + auto amount = currMemOpnd.ShiftAmount(); if (currMemOpnd.GetExtendAsString() == "LSL") { if (amount != 0) { innerMemPropMode = kPropShift; @@ -658,11 +658,11 @@ AArch64MemOperand *A64StrLdrProp::SelectReplaceMem(Insn &defInsn, const AArch64 break; } case MOP_xsxtw64: { - newMemOpnd = SelectReplaceExt(defInsn, *base, currMemOpnd.ShiftAmount(),true); + newMemOpnd = SelectReplaceExt(defInsn, *base, static_cast(currMemOpnd.ShiftAmount()),true); break; } case MOP_xuxtw64: { - newMemOpnd = SelectReplaceExt(defInsn, *base, currMemOpnd.ShiftAmount(), false); + newMemOpnd = SelectReplaceExt(defInsn, *base, static_cast(currMemOpnd.ShiftAmount()), false); break; } default: @@ -725,7 +725,7 @@ bool A64StrLdrProp::CheckNewMemOffset(Insn &insn, AArch64MemOperand *newMemOpnd, !a64CgFunc->IsOperandImmValid(insn.GetMachineOpcode(), newMemOpnd, opndIdx)) { return false; } - uint32 newAmount = newMemOpnd->ShiftAmount(); + auto newAmount = static_cast(newMemOpnd->ShiftAmount()); if (!AArch64StoreLoadOpt::CheckNewAmount(insn, newAmount)) { return false; } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_ra_opt.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_ra_opt.cpp index ad917c6bcd..64d269b646 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_ra_opt.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_ra_opt.cpp @@ -64,7 +64,7 @@ bool RaX0Opt::PropagateRenameReg(Insn *nInsn, const X0OptInfo &optVal) { } } else { if (regCandidate == optVal.GetReplaceReg()) { - nInsn->SetOperand(i, *optVal.GetRenameOpnd()); + nInsn->SetOperand(static_cast(i), *optVal.GetRenameOpnd()); } } } @@ -318,7 +318,7 @@ void VregRename::PrintAllRenameInfo() const { } } -bool VregRename::IsProfitableToRename(VregRenameInfo *info) const { +bool VregRename::IsProfitableToRename(const VregRenameInfo *info) const{ if ((info->numInnerDefs == 0) && (info->numUses != info->numInnerUses)) { return true; } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_reg_alloc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_reg_alloc.cpp index 912c179676..2a45335221 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_reg_alloc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_reg_alloc.cpp @@ -441,7 +441,7 @@ void AArch64RegAllocator::AllocHandleDest(Insn &insn, Operand &opnd, uint32 idx) } if (opnd.IsRegister()) { - insn.SetOperand(static_cast(idx), *AllocDestOpnd(opnd, insn)); + insn.SetOperand(idx, *AllocDestOpnd(opnd, insn)); SaveCalleeSavedReg(static_cast(opnd)); } } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_ssa.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_ssa.cpp index 6b459ebf93..803a172caa 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_ssa.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_ssa.cpp @@ -24,8 +24,8 @@ void AArch64CGSSAInfo::RenameInsn(Insn &insn) { return; } for (int i = opndNum - 1; i >= 0; --i) { - Operand &opnd = insn.GetOperand(i); - auto *opndProp = static_cast(md->operand[i]); + Operand &opnd = insn.GetOperand(static_cast(i)); + auto *opndProp = static_cast(md->operand[static_cast(i)]); A64SSAOperandRenameVisitor renameVisitor(*this, insn, *opndProp, i); opnd.Accept(renameVisitor); } @@ -85,7 +85,7 @@ void AArch64CGSSAInfo::ReplaceInsn(Insn &oriInsn, Insn &newInsn) { auto UpdateInsnSSAInfo = [&ssaUpdator](Insn &curInsn, bool isDelete) { const AArch64MD *md = &AArch64CG::kMd[static_cast(curInsn).GetMachineOpcode()]; for (uint32 i = 0; i < curInsn.GetOperandSize(); ++i) { - Operand &opnd = curInsn.GetOperand(static_cast(i)); + Operand &opnd = curInsn.GetOperand(i); auto *opndProp = static_cast(md->operand[i]); if (isDelete) { ssaUpdator.MarkDecrease(); diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_strldr.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_strldr.cpp index f7ea33bda3..0d8b843e07 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_strldr.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_strldr.cpp @@ -447,7 +447,7 @@ bool AArch64StoreLoadOpt::CheckNewMemOffset(Insn &insn, AArch64MemOperand *newMe !a64CgFunc.IsOperandImmValid(insn.GetMachineOpcode(), newMemOpnd, opndIdx)) { return false; } - uint32 newAmount = newMemOpnd->ShiftAmount(); + auto newAmount = newMemOpnd->ShiftAmount(); if (!CheckNewAmount(insn, newAmount)) { return false; } @@ -737,7 +737,7 @@ bool AArch64StoreLoadOpt::ReplaceMemOpnd(Insn &insn, regno_t regNo, RegOperand & return true; } -bool AArch64StoreLoadOpt::CanDoMemProp(Insn *insn) { +bool AArch64StoreLoadOpt::CanDoMemProp(const Insn *insn) { if (!cgFunc.GetMirModule().IsCModule()) { return false; } diff --git a/src/mapleall/maple_be/src/cg/cg_dominance.cpp b/src/mapleall/maple_be/src/cg/cg_dominance.cpp index 53c9f4f920..f90d95282b 100644 --- a/src/mapleall/maple_be/src/cg/cg_dominance.cpp +++ b/src/mapleall/maple_be/src/cg/cg_dominance.cpp @@ -42,13 +42,13 @@ void DomAnalysis::GenPostOrderID() { PostOrderWalk(commonEntryBB, postOrderID, visitedMap); // initialize reversePostOrder int32 maxPostOrderID = postOrderID - 1; - reversePostOrder.resize(maxPostOrderID + 1); + reversePostOrder.resize(static_cast(maxPostOrderID + 1)); for (size_t i = 0; i < postOrderIDVec.size(); ++i) { int32 postOrderNo = postOrderIDVec[i]; if (postOrderNo == -1) { continue; } - reversePostOrder[maxPostOrderID - postOrderNo] = bbVec[i]; + reversePostOrder[static_cast(maxPostOrderID - postOrderNo)] = bbVec[i]; } } @@ -280,13 +280,13 @@ void PostDomAnalysis::PdomGenPostOrderID() { PdomPostOrderWalk(commonExitBB, postOrderID, visitedMap); // initialize pdomReversePostOrder int32 maxPostOrderID = postOrderID - 1; - pdomReversePostOrder.resize(maxPostOrderID + 1); + pdomReversePostOrder.resize(static_cast(maxPostOrderID + 1)); for (size_t i = 0; i < pdomPostOrderIDVec.size(); ++i) { int32 postOrderNo = pdomPostOrderIDVec[i]; if (postOrderNo == -1) { continue; } - pdomReversePostOrder[maxPostOrderID - postOrderNo] = bbVec[i]; + pdomReversePostOrder[static_cast(maxPostOrderID - postOrderNo)] = bbVec[i]; } } diff --git a/src/mapleall/maple_be/src/cg/cg_ssa.cpp b/src/mapleall/maple_be/src/cg/cg_ssa.cpp index 7109e1ebe4..466570811d 100644 --- a/src/mapleall/maple_be/src/cg/cg_ssa.cpp +++ b/src/mapleall/maple_be/src/cg/cg_ssa.cpp @@ -28,7 +28,7 @@ void CGSSAInfo::ConstructSSA() { void CGSSAInfo::MarkInsnsInSSA(Insn &insn) { CHECK_FATAL(insn.GetId() == 0, "insn is not clean !!"); /* change to assert*/ insnCount++; - insn.SetId(insnCount); + insn.SetId(static_cast(insnCount)); } void CGSSAInfo::InsertPhiInsn() { @@ -112,7 +112,7 @@ void CGSSAInfo::RenameBB(BB &bb) { /* stack pop up */ for (auto &it : vRegStk) { if (it.first < oriStackSize.size() && oriStackSize[it.first] >= 0) { - while (static_cast(it.second.size()) > oriStackSize[it.first]) { + while (static_cast(it.second.size()) > oriStackSize[static_cast(it.first)]) { ASSERT(!it.second.empty(), "empty stack"); it.second.pop(); } diff --git a/src/mapleall/maple_be/src/cg/ebo.cpp b/src/mapleall/maple_be/src/cg/ebo.cpp index 38926f7228..4b1b8a7ac4 100644 --- a/src/mapleall/maple_be/src/cg/ebo.cpp +++ b/src/mapleall/maple_be/src/cg/ebo.cpp @@ -221,7 +221,7 @@ void Ebo::SetOpndInfo(const Operand &opnd, OpndInfo *opndInfo, int32 hashVal) { return; } - CHECK_FATAL(hashVal < static_cast(exprInfoTable.size()), "SetOpndInfo hashval outof range!"); + CHECK_FATAL(static_cast(hashVal) < exprInfoTable.size(), "SetOpndInfo hashval outof range!"); opndInfo->hashVal = hashVal; opndInfo->hashNext = exprInfoTable.at(hashVal); exprInfoTable.at(hashVal) = opndInfo; @@ -469,7 +469,7 @@ void Ebo::RemoveUses(uint32 opndNum, const MapleVector &origInfo) { } } -OpndInfo *Ebo::BuildMemOpndInfo(BB &bb, Insn &insn, Operand &opnd, int32 opndIndex) { +OpndInfo *Ebo::BuildMemOpndInfo(BB &bb, Insn &insn, Operand &opnd, uint32 opndIndex) { auto *memOpnd = static_cast(&opnd); Operand *base = memOpnd->GetBaseRegister(); Operand *offset = memOpnd->GetOffset(); @@ -602,7 +602,7 @@ bool Ebo::ForwardPropagateOpnd(Insn &insn, Operand *&opnd, uint32 opndIndex, return false; } /* Copies to and from the same register are not needed. */ - if (!beforeRegAlloc && insn.IsEffectiveCopy() && (insn.CopyOperands() == opndIndex) && + if (!beforeRegAlloc && insn.IsEffectiveCopy() && (static_cast(insn.CopyOperands()) == opndIndex) && RegistersIdentical(*opnd, *(insn.GetResult(0)))) { if (EBO_DUMP) { LogInfo::MapleLogger() << "===replace operand " << opndIndex << " of insn: \n"; diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index accaefe35a..17aae3bff2 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -220,7 +220,7 @@ void Emitter::EmitFileInfo(const std::string &fileName) { SetFileMapValue(1, irFile); /* save ir file in 1 */ if (cg->GetCGOptions().WithSrc()) { /* insert a list of src files */ - int i = 2; + uint32 i = 2; for (auto it : cg->GetMIRModule()->GetSrcFileInfo()) { if (cg->GetCGOptions().WithAsm()) { Emit("\t// "); @@ -468,7 +468,7 @@ void Emitter::EmitCombineBfldValue(StructEmitInfo &structEmitInfo) { uint8 charBitWidth = GetPrimTypeSize(PTY_i8) * kBitsPerByte; auto emitBfldValue = [&](bool flag) { while (structEmitInfo.GetCombineBitFieldWidth() > charBitWidth) { - uint8 shift = flag ? (structEmitInfo.GetCombineBitFieldWidth() - charBitWidth) : 0; + uint8 shift = flag ? (structEmitInfo.GetCombineBitFieldWidth() - charBitWidth) : 0U; uint64 tmp = (structEmitInfo.GetCombineBitFieldValue() >> shift) & 0x00000000000000ffUL; EmitAsmLabel(kAsmByte); Emit(std::to_string(tmp)); @@ -485,7 +485,7 @@ void Emitter::EmitCombineBfldValue(StructEmitInfo &structEmitInfo) { * If the total number of bits in the bit field is not a multiple of 8, * the bits must be aligned to 8 bits to prevent errors in the emit. */ - uint64 width = RoundUp(structEmitInfo.GetCombineBitFieldWidth(), charBitWidth); + auto width = static_cast(RoundUp(structEmitInfo.GetCombineBitFieldWidth(), charBitWidth)); if(structEmitInfo.GetCombineBitFieldWidth() < width) { structEmitInfo.SetCombineBitFieldValue(structEmitInfo.GetCombineBitFieldValue() << (width - structEmitInfo.GetCombineBitFieldWidth())); @@ -3043,7 +3043,7 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa } } } else { - EmitHexUnsigned(attr->GetI()); + EmitHexUnsigned(static_cast(attr->GetI())); } break; case DW_FORM_sec_offset: @@ -3148,7 +3148,7 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa Emit("\n\t.byte "); EmitHexUnsigned(elp->GetOp()); Emit("\n\t.8byte "); - Emit(GlobalTables::GetStrTable().GetStringFromStrIdx(elp->GetGvarStridx()).c_str()); + Emit(GlobalTables::GetStrTable().GetStringFromStrIdx(static_cast(elp->GetGvarStridx())).c_str()); break; case DW_OP_fbreg: EmitHexUnsigned(1 + namemangler::GetSleb128Size(elp->GetFboffset())); @@ -3380,7 +3380,7 @@ void Emitter::FillInClassByteSize(DBGDie *die, DBGDieAttr *byteSizeAttr) { ASSERT(byteSizeAttr->GetDwForm() == DW_FORM_data1 || byteSizeAttr->GetDwForm() == DW_FORM_data2 || byteSizeAttr->GetDwForm() == DW_FORM_data4 || byteSizeAttr->GetDwForm() == DW_FORM_data8, "Unknown FORM value for DW_AT_byte_size"); - if (byteSizeAttr->GetI() == static_cast(kDbgDefaultVal)) { + if (static_cast(byteSizeAttr->GetI()) == kDbgDefaultVal) { /* get class size */ DBGDieAttr *nameAttr = LFindDieAttr(die, DW_AT_name); CHECK_FATAL(nameAttr != nullptr, "name_attr is nullptr in Emitter::FillInClassByteSize"); @@ -3433,7 +3433,7 @@ void Emitter::SetupDBGInfo(DebugInfo *mirdi) { CHECK_FATAL(sty != nullptr, "pointer cast failed"); CHECK_FATAL(sty->GetTypeIndex().GetIdx() < Globals::GetInstance()->GetBECommon()->GetSizeOfStructFieldCountTable(), ""); - int embeddedIDs = 0; + uint32 embeddedIDs = 0; MIRStructType *prevSubstruct = nullptr; for (size_t i = 0; i < sty->GetFields().size(); i++) { TyIdx fieldtyidx = sty->GetFieldsElemt(i).second.first; diff --git a/src/mapleall/maple_be/src/cg/loop.cpp b/src/mapleall/maple_be/src/cg/loop.cpp index d682e4364d..a4198b40e5 100644 --- a/src/mapleall/maple_be/src/cg/loop.cpp +++ b/src/mapleall/maple_be/src/cg/loop.cpp @@ -487,7 +487,7 @@ void LoopFinder::UpdateOuterForInnerLoop(BB *bb, LoopHierarchy *outer) { } } -void LoopFinder::UpdateOuterLoop(LoopHierarchy *loop) { +void LoopFinder::UpdateOuterLoop(const LoopHierarchy *loop) { for (auto inner : loop->GetInnerLoops()) { UpdateOuterLoop(inner); } diff --git a/src/mapleall/maple_be/src/cg/peep.cpp b/src/mapleall/maple_be/src/cg/peep.cpp index 38fb56809c..fecbb4f61f 100644 --- a/src/mapleall/maple_be/src/cg/peep.cpp +++ b/src/mapleall/maple_be/src/cg/peep.cpp @@ -64,7 +64,7 @@ bool CGPeepPattern::IsCCRegCrossVersion(Insn &startInsn, Insn &endInsn, RegOpera } int64 CGPeepPattern::GetLogValueAtBase2(int64 val) const { - return (__builtin_popcountll(val) == 1) ? (__builtin_ffsll(val) - 1) : -1; + return (__builtin_popcountll(static_cast(val)) == 1) ? (__builtin_ffsll(val) - 1) : -1; } Insn *CGPeepPattern::GetDefInsn(const RegOperand &useReg) { @@ -80,7 +80,7 @@ Insn *CGPeepPattern::GetDefInsn(const RegOperand &useReg) { return defInfo == nullptr ? nullptr : defInfo->GetInsn(); } -void CGPeepPattern::DumpAfterPattern(std::vector &prevInsns, Insn *replacedInsn, Insn *newInsn) { +void CGPeepPattern::DumpAfterPattern(std::vector &prevInsns, const Insn *replacedInsn, const Insn *newInsn) { auto *aarCGSSAInfo = static_cast(ssaInfo); LogInfo::MapleLogger() << ">>>>>>> In " << GetPatternName() << " : <<<<<<<\n"; if (!prevInsns.empty()) { @@ -122,7 +122,7 @@ void CGPeepPattern::DumpAfterPattern(std::vector &prevInsns, Insn *replac } int PeepPattern::logValueAtBase2(int64 val) const { - return (__builtin_popcountll(val) == 1) ? (__builtin_ffsll(val) - 1) : (-1); + return (__builtin_popcountll(static_cast(val)) == 1) ? (__builtin_ffsll(val) - 1) : (-1); } /* Check if a regOpnd is live after insn. True if live, otherwise false. */ @@ -162,7 +162,7 @@ bool PeepPattern::IfOperandIsLiveAfterInsn(const RegOperand ®Opnd, Insn &insn } #if TARGAARCH64 || TARGRISCV64 const AArch64MD *md = &AArch64CG::kMd[static_cast(nextInsn)->GetMachineOpcode()]; - auto *regProp = static_cast(md->operand[i]); + auto *regProp = static_cast(md->operand[static_cast(i)]); #endif #if TARGARM32 const Arm32MD *md = &Arm32CG::kMd[static_cast(nextInsn)->GetMachineOpcode()]; @@ -278,7 +278,7 @@ ReturnType PeepPattern::IsOpndLiveinBB(const RegOperand ®Opnd, const BB &bb) for (int32 i = lastOpndId; i >= 0; --i) { Operand &opnd = insn->GetOperand(i); #if TARGAARCH64 || TARGRISCV64 - auto *regProp = static_cast(md->operand[i]); + auto *regProp = static_cast(md->operand[static_cast(i)]); #endif #if TARGARM32 auto *regProp = static_cast(md->operand[i]); @@ -295,14 +295,14 @@ ReturnType PeepPattern::IsOpndLiveinBB(const RegOperand ®Opnd, const BB &bb) } else if (opnd.IsList()) { auto &listOpnd = static_cast(opnd); if (insn->GetMachineOpcode() == MOP_asm) { - if (i == kAsmOutputListOpnd || i == kAsmClobberListOpnd) { + if (static_cast(i) == kAsmOutputListOpnd || static_cast(i) == kAsmClobberListOpnd) { for (auto op : listOpnd.GetOperands()) { if (op->GetRegisterNumber() == regOpnd.GetRegisterNumber()) { return kResDefFirst; } } continue; - } else if (i != kAsmInputListOpnd) { + } else if (static_cast(i) != kAsmInputListOpnd) { continue; } /* fall thru for kAsmInputListOpnd */ diff --git a/src/mapleall/maple_be/src/cg/schedule.cpp b/src/mapleall/maple_be/src/cg/schedule.cpp index dd0c597328..a82db54fa7 100644 --- a/src/mapleall/maple_be/src/cg/schedule.cpp +++ b/src/mapleall/maple_be/src/cg/schedule.cpp @@ -27,13 +27,13 @@ namespace maplebe { /* pressure standard value; pressure under this value will not lead to spill operation */ -static int g_pressureStandard = 27; +static constexpr int g_pressureStandard = 27; /* optimistic scheduling option */ -static bool g_optimisticScheduling = false; +static constexpr bool g_optimisticScheduling = false; /* brute maximum count limit option */ -static bool g_bruteMaximumLimit = true; +static constexpr bool g_bruteMaximumLimit = true; /* brute maximum count */ -static int g_schedulingMaximumCount = 20000; +static constexpr int g_schedulingMaximumCount = 20000; /* ---- RegPressureSchedule function ---- */ void RegPressureSchedule::InitBBInfo(BB &b, MemPool &memPool, const MapleVector &nodes) { @@ -65,10 +65,10 @@ void RegPressureSchedule::BuildPhyRegInfo(const std::vector ®NumVec) { /* Initialize pre-scheduling split point in BB */ void RegPressureSchedule::initPartialSplitters(const MapleVector &nodes) { bool addFirstAndLastNodeIndex = false; - int SecondLastNodeIndexFromBack = 2; - int LastNodeIndexFromBack = 1; - int FirstNodeIndex = 0; - size_t minimumBBSize = 2; + constexpr uint32 SecondLastNodeIndexFromBack = 2; + constexpr uint32 LastNodeIndexFromBack = 1; + constexpr uint32 FirstNodeIndex = 0; + constexpr uint32 minimumBBSize = 2; /* Add split point for the last instruction in return BB */ if (bb->GetKind() == BB::kBBReturn && nodes.size() > minimumBBSize) { splitterIndexes.emplace_back(nodes.size() - SecondLastNodeIndexFromBack); @@ -445,7 +445,7 @@ void RegPressureSchedule::BruteUpdateReadyList(const DepNode &node, std::vector< * Restore the ready list status when finishing one brute scheduling series generation */ void RegPressureSchedule::RestoreReadyList(DepNode &node, std::vector &changedToReady) { - int i = 0; + uint32 i = 0; /* restore state information of the successors and delete them from readyList */ for (auto *succ : node.GetSuccs()) { DepNode &succNode = succ->GetTo(); @@ -715,7 +715,7 @@ int RegPressureSchedule::CalculateRegisterPressure(MapleVector &nodes) #endif } /* Restore the Schedule State */ - int i = 0; + uint32 i = 0; for (auto node : nodes){ node->SetState(restoreStateSeries.at(i)); ++i; @@ -727,11 +727,11 @@ int RegPressureSchedule::CalculateRegisterPressure(MapleVector &nodes) * Split the series into multiple parts and conduct pre-scheduling in every part */ void RegPressureSchedule::PartialScheduling(MapleVector &nodes) { - for (size_t i = 0; i < splitterIndexes.size() - 1; i = i + 1) { - int lastTwoNodeIndex = 2; - int begin = splitterIndexes.at(i); - int end = splitterIndexes.at(i + 1); - for (int j = begin; j < end; j = j + 1) { + for (size_t i = 0; i < splitterIndexes.size() - 1; ++i) { + constexpr uint32 lastTwoNodeIndex = 2; + auto begin = static_cast(splitterIndexes.at(i)); + auto end = static_cast(splitterIndexes.at(i + 1)); + for (uint32 j = begin; j < end; ++j) { partialList.emplace_back(nodes.at(j)); } if (i == splitterIndexes.size() - lastTwoNodeIndex) { @@ -810,7 +810,7 @@ void RegPressureSchedule::BruteForceScheduling() { * Calculate the pred size based on the dependency information */ void RegPressureSchedule::CalculatePredSize(DepNode &node) { - int emptyPredsSize = 0; + constexpr uint32 emptyPredsSize = 0; node.SetValidPredsSize(emptyPredsSize); for (auto pred : node.GetPreds()) { DepNode &from = pred->GetFrom(); diff --git a/src/mapleall/maple_me/include/me_bb_layout.h b/src/mapleall/maple_me/include/me_bb_layout.h index a5d51856ba..99d100a206 100644 --- a/src/mapleall/maple_me/include/me_bb_layout.h +++ b/src/mapleall/maple_me/include/me_bb_layout.h @@ -236,7 +236,6 @@ class BBLayout { void LayoutWithoutProf(); void RunLayout(); void DumpBBPhyOrder() const; - void VerifyBB(); private: void FixEndTryBB(BB &bb); diff --git a/src/mapleall/maple_me/src/me_bb_layout.cpp b/src/mapleall/maple_me/src/me_bb_layout.cpp index 7c54247dab..4052b07a1e 100644 --- a/src/mapleall/maple_me/src/me_bb_layout.cpp +++ b/src/mapleall/maple_me/src/me_bb_layout.cpp @@ -947,27 +947,16 @@ BB *BBLayout::CreateGotoBBAfterCondBB(BB &bb, BB &fallthru) { void BBLayout::OptimizeEmptyFallThruBB(BB &bb) { if (needDealWithTryBB) { return; } auto *fallthru = bb.GetSucc().front(); - while (fallthru && (fallthru->GetPred().size() == 1) && - (BBEmptyAndFallthru(*fallthru) || BBContainsOnlyGoto(*fallthru))) { - BB *newFallthru = fallthru->GetSucc().front(); - if (newFallthru == bb.GetSucc().back()) { - bb.ReplaceSucc(fallthru, newFallthru); + if (fallthru && fallthru->GetBBLabel() == 0 && + (BBEmptyAndFallthru(*fallthru) || BBContainsOnlyGoto(*fallthru))) { + if (fallthru->GetSucc().front() == bb.GetSucc().back()) { + bb.ReplaceSucc(fallthru, bb.GetSucc().back()); ASSERT(fallthru->GetPred().empty(), "fallthru should not has other pred"); ChangeToFallthruFromCondGoto(bb); bb.GetSucc().resize(1); // resize succ to 1 - } else if (newFallthru->GetPred().size() == 1) { - if (newFallthru->GetBBLabel() != 0) { - // reset newFallthru label - newFallthru->SetBBLabel(0); - } - // replace empty fallthru with fallthru's succ - bb.ReplaceSucc(fallthru, newFallthru); - } else { - break; + laidOut[fallthru->GetBBId()] = true; + RemoveUnreachable(*fallthru); } - laidOut[fallthru->GetBBId()] = true; - RemoveUnreachable(*fallthru); - fallthru = newFallthru; } } @@ -1004,19 +993,6 @@ void BBLayout::OptimiseCFG() { } } (void)cfg->UnreachCodeAnalysis(false); - - // do 2nd fallthru optimize if succs of bb were optimized by first iteration - for (auto bIt = cfg->valid_begin(); bIt != cfg->valid_end(); ++bIt) { - if (bIt == cfg->common_entry() || bIt == cfg->common_exit()) { - continue; - } - auto *bb = *bIt; - if (bb->GetKind() == kBBCondGoto) { - OptimizeEmptyFallThruBB(*bb); - } - } - (void)cfg->UnreachCodeAnalysis(false); - } void BBLayout::SetAttrTryForTheCanBeMovedBB(BB &bb, BB &canBeMovedBB) const { @@ -1330,21 +1306,6 @@ void BBLayout::RunLayout() { } } -// check condBB if they have same succs -void BBLayout::VerifyBB() { - for (auto bIt = cfg->valid_begin(); bIt != cfg->valid_end(); ++bIt) { - auto *bb = *bIt; - if (bb->GetKind() == kBBCondGoto) { - auto *fallthru = bb->GetSucc(0); - auto *targetBB = bb->GetSucc(1); - if (fallthru == targetBB || - (BBEmptyAndFallthru(*fallthru) && (fallthru->GetSucc(0) == targetBB))) { - LogInfo::MapleLogger() << "WARN: cond BB " << bb->GetBBId() << " has same target"; - } - } - } -} - void MEBBLayout::GetAnalysisDependence(maple::AnalysisDep &aDep) const { aDep.AddRequired(); aDep.AddRequired(); @@ -1361,10 +1322,7 @@ bool MEBBLayout::PhaseRun(maple::MeFunction &f) { } bbLayout->RunLayout(); f.SetLaidOutBBs(bbLayout->GetBBs()); - if (DEBUGFUNC_NEWPM(f)) { - // verify CFG : check condBB's succs should be different - bbLayout->VerifyBB(); bbLayout->DumpBBPhyOrder(); cfg->DumpToFile("afterBBLayout", false); } -- Gitee From b060fdae537be292b8c1a4ca82f434e5f122b73e Mon Sep 17 00:00:00 2001 From: binaryfz Date: Thu, 27 Jan 2022 15:01:22 +0800 Subject: [PATCH 16/21] [mapleall]Internal commit msg: !1041 delete more empty fallthru BBs in optimiseCFG bblayout phase --- src/mapleall/maple_me/include/me_bb_layout.h | 1 + src/mapleall/maple_me/src/me_bb_layout.cpp | 54 +++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/mapleall/maple_me/include/me_bb_layout.h b/src/mapleall/maple_me/include/me_bb_layout.h index 99d100a206..a5d51856ba 100644 --- a/src/mapleall/maple_me/include/me_bb_layout.h +++ b/src/mapleall/maple_me/include/me_bb_layout.h @@ -236,6 +236,7 @@ class BBLayout { void LayoutWithoutProf(); void RunLayout(); void DumpBBPhyOrder() const; + void VerifyBB(); private: void FixEndTryBB(BB &bb); diff --git a/src/mapleall/maple_me/src/me_bb_layout.cpp b/src/mapleall/maple_me/src/me_bb_layout.cpp index 4052b07a1e..7c54247dab 100644 --- a/src/mapleall/maple_me/src/me_bb_layout.cpp +++ b/src/mapleall/maple_me/src/me_bb_layout.cpp @@ -947,16 +947,27 @@ BB *BBLayout::CreateGotoBBAfterCondBB(BB &bb, BB &fallthru) { void BBLayout::OptimizeEmptyFallThruBB(BB &bb) { if (needDealWithTryBB) { return; } auto *fallthru = bb.GetSucc().front(); - if (fallthru && fallthru->GetBBLabel() == 0 && - (BBEmptyAndFallthru(*fallthru) || BBContainsOnlyGoto(*fallthru))) { - if (fallthru->GetSucc().front() == bb.GetSucc().back()) { - bb.ReplaceSucc(fallthru, bb.GetSucc().back()); + while (fallthru && (fallthru->GetPred().size() == 1) && + (BBEmptyAndFallthru(*fallthru) || BBContainsOnlyGoto(*fallthru))) { + BB *newFallthru = fallthru->GetSucc().front(); + if (newFallthru == bb.GetSucc().back()) { + bb.ReplaceSucc(fallthru, newFallthru); ASSERT(fallthru->GetPred().empty(), "fallthru should not has other pred"); ChangeToFallthruFromCondGoto(bb); bb.GetSucc().resize(1); // resize succ to 1 - laidOut[fallthru->GetBBId()] = true; - RemoveUnreachable(*fallthru); + } else if (newFallthru->GetPred().size() == 1) { + if (newFallthru->GetBBLabel() != 0) { + // reset newFallthru label + newFallthru->SetBBLabel(0); + } + // replace empty fallthru with fallthru's succ + bb.ReplaceSucc(fallthru, newFallthru); + } else { + break; } + laidOut[fallthru->GetBBId()] = true; + RemoveUnreachable(*fallthru); + fallthru = newFallthru; } } @@ -993,6 +1004,19 @@ void BBLayout::OptimiseCFG() { } } (void)cfg->UnreachCodeAnalysis(false); + + // do 2nd fallthru optimize if succs of bb were optimized by first iteration + for (auto bIt = cfg->valid_begin(); bIt != cfg->valid_end(); ++bIt) { + if (bIt == cfg->common_entry() || bIt == cfg->common_exit()) { + continue; + } + auto *bb = *bIt; + if (bb->GetKind() == kBBCondGoto) { + OptimizeEmptyFallThruBB(*bb); + } + } + (void)cfg->UnreachCodeAnalysis(false); + } void BBLayout::SetAttrTryForTheCanBeMovedBB(BB &bb, BB &canBeMovedBB) const { @@ -1306,6 +1330,21 @@ void BBLayout::RunLayout() { } } +// check condBB if they have same succs +void BBLayout::VerifyBB() { + for (auto bIt = cfg->valid_begin(); bIt != cfg->valid_end(); ++bIt) { + auto *bb = *bIt; + if (bb->GetKind() == kBBCondGoto) { + auto *fallthru = bb->GetSucc(0); + auto *targetBB = bb->GetSucc(1); + if (fallthru == targetBB || + (BBEmptyAndFallthru(*fallthru) && (fallthru->GetSucc(0) == targetBB))) { + LogInfo::MapleLogger() << "WARN: cond BB " << bb->GetBBId() << " has same target"; + } + } + } +} + void MEBBLayout::GetAnalysisDependence(maple::AnalysisDep &aDep) const { aDep.AddRequired(); aDep.AddRequired(); @@ -1322,7 +1361,10 @@ bool MEBBLayout::PhaseRun(maple::MeFunction &f) { } bbLayout->RunLayout(); f.SetLaidOutBBs(bbLayout->GetBBs()); + if (DEBUGFUNC_NEWPM(f)) { + // verify CFG : check condBB's succs should be different + bbLayout->VerifyBB(); bbLayout->DumpBBPhyOrder(); cfg->DumpToFile("afterBBLayout", false); } -- Gitee From 648a6c02369a2709f8165cfd0452c8a0951a6119 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 25 Nov 2021 13:42:27 +0300 Subject: [PATCH 17/21] [mapleall][driver] Add "target" and "isystem" as default options for clang-ast generator These options are needed to correct compile for aarch64. These options were tested with SPECCPU2017 benchmark. --- src/mapleall/maple_driver/src/clang_compiler.cpp | 5 +++++ src/mapleall/maple_driver/src/driver_option_common.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/mapleall/maple_driver/src/clang_compiler.cpp b/src/mapleall/maple_driver/src/clang_compiler.cpp index e5924a388c..634a45d822 100644 --- a/src/mapleall/maple_driver/src/clang_compiler.cpp +++ b/src/mapleall/maple_driver/src/clang_compiler.cpp @@ -29,8 +29,13 @@ const std::string &ClangCompiler::GetBinName() const { return kBinNameClang; } +<<<<<<< HEAD static uint32_t FillSpecialDefaulOpt(std::unique_ptr &opt, const Action &action) { +======= +static inline uint32_t FillSpecialDefaulOpt(std::unique_ptr &opt, + const Action &action) { +>>>>>>> [mapleall][driver] Add "target" and "isystem" as default options for clang-ast generator uint32_t additionalLen = 1; // for -o option /* TODO: Add check for the target architecture and OS environment. diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index 7652807453..d05c37185e 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -532,6 +532,15 @@ const mapleOption::Descriptor kUsages[] = { " -isystem \tAdd directory to SYSTEM include search path\n", "driver", {"clang"} }, + { kClangISystem, + 0, + "I", + "", + kBuildTypeAll, + kArgCheckPolicyRequired, + " -isystem \tAdd directory to SYSTEN include search path\n", + "all", + {"clang"} }, { kMaplePhaseOnly, kEnable, "", -- Gitee From c56ddcef88d1543774f05e70bc3d39ff1f36ede7 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Mon, 29 Nov 2021 13:18:26 +0300 Subject: [PATCH 18/21] [CI] Add new degradation tests for maple driver * DRIVER0003-macro tests macro options: -D and -U; * DRIVER0004-syslibs tests system library linking with -l option; * DRIVER0005-path tests path options -L and -I; --- .../driver_test/DRIVER0005-path/expected.txt | 1 + .../DRIVER0005-path/includes/mylib.h | 4 +++ .../DRIVER0005-path/libs/libmylib.a | Bin 0 -> 1040 bytes .../c_test/driver_test/DRIVER0005-path/main.c | 26 ++++++++++++++++++ .../driver_test/DRIVER0005-path/test.cfg | 2 ++ 5 files changed, 33 insertions(+) create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/expected.txt create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/main.c create mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/test.cfg diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt b/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt new file mode 100644 index 0000000000..7501d9e823 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt @@ -0,0 +1 @@ +mylib H_NUM: 5, val: 40 diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h b/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h new file mode 100644 index 0000000000..c6b66c5277 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h @@ -0,0 +1,4 @@ +#define H_NUM 5 + +int mylib_doubleval(int in); + diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a b/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a new file mode 100644 index 0000000000000000000000000000000000000000..01afb78ecc9440c0c4aa14892647ed136d153e3d GIT binary patch literal 1040 zcmbtSO-jQ+6n-^YYj@g>pkNAuAet#sr3;aWRwxKc1y_YOZ3k1DG+{C=DFxkmmU;s1 zM#Mw7u1D|yMQ55BjWMqJAoN=ScQGLh-n7#SA!k>_+t1EW&sk~lX6dmg%Qap#z{PaNBAS(qS-J?eE^ z6r)C!`>07;Jxl`sv|PF_mUFq>{;q3K6KO~+$i|xOTCnLubc3LIeVZC}hLi+oN{?cn zg4Q&s0b1Sj +#include "mylib.h" + +int main() +{ + int in = 20; + int res = mylib_doubleval(in); + + printf ("mylib H_NUM: %d, val: %d\n", H_NUM, res); + return 0; +} diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg b/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg new file mode 100644 index 0000000000..afad22c368 --- /dev/null +++ b/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg @@ -0,0 +1,2 @@ +compile(APP=main.c,OPTION="--no-maple-phase --static -lmylib -L./libs -I./includes") +run(a) -- Gitee From 63c13fee65574157172ef20bc6cacb3be32eb50d Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Mon, 29 Nov 2021 14:44:26 +0300 Subject: [PATCH 19/21] [maple_driver] Raw ld phase implementation --- .../defs/default/O0_options_ld.def | 32 ++++++++++++++++++- src/mapleall/maple_driver/src/ld_compiler.cpp | 16 +++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_ld.def b/src/mapleall/maple_driver/defs/default/O0_options_ld.def index 9e26dfeeb6..914751db83 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_ld.def +++ b/src/mapleall/maple_driver/defs/default/O0_options_ld.def @@ -1 +1,31 @@ -{} \ No newline at end of file +{"-plugin", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/liblto_plugin.so", true}, +{"-plugin-opt", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/lto-wrapper", true}, +{"-plugin-opt", "-fresolution=/tmp/ccU2hAX4.res", false}, +{"-plugin-opt", "-pass-through=-lgcc", false}, +{"-plugin-opt", "-pass-through=-lgcc_eh", false}, +{"-plugin-opt", "-pass-through=-lc", false}, +{"--sysroot", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc", true}, +{"--build-id", "", false}, +{"-Bstatic", "", false}, +{"-X", "", false}, +{"-EL", "", false}, +{"-maarch64linux", "", false}, +{"--fix-cortex-a53-835769", "", false}, +{"--fix-cortex-a53-843419", "", false}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crt1.o", "", true}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crti.o", "", true}, +{"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtbeginT.o", "", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib/gcc", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/lib64", true}, +{"-L", "/tools/gcc-linaro-7.5.0/lib", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/lib", true}, +{"-L", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib", true}, +{"--start-group", "", false}, +{"-lgcc", "", false}, +{"-lgcc_eh", "", false}, +{"-lc", "", false}, +{"--end-group", "", false}, +{"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtend.o", "", true}, +{"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crtn.o", "", true}, \ No newline at end of file diff --git a/src/mapleall/maple_driver/src/ld_compiler.cpp b/src/mapleall/maple_driver/src/ld_compiler.cpp index 2b54bf739f..8a48250321 100644 --- a/src/mapleall/maple_driver/src/ld_compiler.cpp +++ b/src/mapleall/maple_driver/src/ld_compiler.cpp @@ -27,7 +27,7 @@ std::string LdCompiler::GetBinPath(const MplOptions&) const { // TODO: Required to use ld instead of gcc; ld will be implemented later const std::string &LdCompiler::GetBinName() const { - return kBinNameGcc; + return kBinNameLd; } /* the tool name must be the same as exeName field in Descriptor structure */ @@ -44,10 +44,16 @@ DefaultOption LdCompiler::GetDefaultOptions(const MplOptions &options, const Act } for (uint32_t i = 0; i < defaultOptions.length; ++i) { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); + if (defaultOptions.mplOptions[i].GetValue() == "" && defaultOptions.mplOptions[i].GetNeedRootPath()) { + defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + + defaultOptions.mplOptions[i].GetKey()); + } + else { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } } return defaultOptions; } -- Gitee From cf367868e348e717c66478f9f946bba0d91c5eca Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Mon, 24 Jan 2022 12:54:30 +0300 Subject: [PATCH 20/21] Ld phase improvements --- ...ptions_ld.def => aarch64_linux_gnu_ld.def} | 10 ---------- .../maple_driver/defs/default_options.def | 2 +- src/mapleall/maple_driver/src/ld_compiler.cpp | 20 ++++++++++--------- 3 files changed, 12 insertions(+), 20 deletions(-) rename src/mapleall/maple_driver/defs/default/{O0_options_ld.def => aarch64_linux_gnu_ld.def} (67%) diff --git a/src/mapleall/maple_driver/defs/default/O0_options_ld.def b/src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def similarity index 67% rename from src/mapleall/maple_driver/defs/default/O0_options_ld.def rename to src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def index 914751db83..87c4942869 100644 --- a/src/mapleall/maple_driver/defs/default/O0_options_ld.def +++ b/src/mapleall/maple_driver/defs/default/aarch64_linux_gnu_ld.def @@ -1,17 +1,7 @@ -{"-plugin", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/liblto_plugin.so", true}, -{"-plugin-opt", "/tools/gcc-linaro-7.5.0/libexec/gcc/aarch64-linux-gnu/7.5.0/lto-wrapper", true}, -{"-plugin-opt", "-fresolution=/tmp/ccU2hAX4.res", false}, -{"-plugin-opt", "-pass-through=-lgcc", false}, -{"-plugin-opt", "-pass-through=-lgcc_eh", false}, -{"-plugin-opt", "-pass-through=-lc", false}, {"--sysroot", "/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc", true}, -{"--build-id", "", false}, {"-Bstatic", "", false}, -{"-X", "", false}, {"-EL", "", false}, {"-maarch64linux", "", false}, -{"--fix-cortex-a53-835769", "", false}, -{"--fix-cortex-a53-843419", "", false}, {"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crt1.o", "", true}, {"/tools/gcc-linaro-7.5.0/aarch64-linux-gnu/libc/usr/lib/crti.o", "", true}, {"/tools/gcc-linaro-7.5.0/lib/gcc/aarch64-linux-gnu/7.5.0/crtbeginT.o", "", true}, diff --git a/src/mapleall/maple_driver/defs/default_options.def b/src/mapleall/maple_driver/defs/default_options.def index b923ab1fe2..5a73cd8f9a 100644 --- a/src/mapleall/maple_driver/defs/default_options.def +++ b/src/mapleall/maple_driver/defs/default_options.def @@ -122,7 +122,7 @@ static MplOption kAsDefaultOptions[] = { }; // O0 ld options static MplOption kLdDefaultOptions[] = { -#include "default/O0_options_ld.def" +#include "default/aarch64_linux_gnu_ld.def" }; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_DEFAULT_OPTIONS_H diff --git a/src/mapleall/maple_driver/src/ld_compiler.cpp b/src/mapleall/maple_driver/src/ld_compiler.cpp index 8a48250321..f0e0407b4a 100644 --- a/src/mapleall/maple_driver/src/ld_compiler.cpp +++ b/src/mapleall/maple_driver/src/ld_compiler.cpp @@ -44,15 +44,17 @@ DefaultOption LdCompiler::GetDefaultOptions(const MplOptions &options, const Act } for (uint32_t i = 0; i < defaultOptions.length; ++i) { - if (defaultOptions.mplOptions[i].GetValue() == "" && defaultOptions.mplOptions[i].GetNeedRootPath()) { - defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + - defaultOptions.mplOptions[i].GetKey()); - } - else { - defaultOptions.mplOptions[i].SetValue( - FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), - defaultOptions.mplOptions[i].GetValue(), - options.GetExeFolder())); + if (defaultOptions.mplOptions[i].GetNeedRootPath()) { + if (defaultOptions.mplOptions[i].GetValue().empty()) { + defaultOptions.mplOptions[i].SetKey(FileUtils::SafeGetenv(kMapleRoot) + + defaultOptions.mplOptions[i].GetKey()); + } + else { + defaultOptions.mplOptions[i].SetValue( + FileUtils::AppendMapleRootIfNeeded(defaultOptions.mplOptions[i].GetNeedRootPath(), + defaultOptions.mplOptions[i].GetValue(), + options.GetExeFolder())); + } } } return defaultOptions; -- Gitee From ededc6ce8b61ef1de3d2aa27c8481ceb31e65c27 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 25 Nov 2021 13:48:30 +0300 Subject: [PATCH 21/21] [mapleall][driver] Add "-U" option "-U " option is used to undefine macro . [mapleall][driver] Duplicate lines and unnecessary files lines removal --- .../maple_driver/src/clang_compiler.cpp | 5 ---- .../maple_driver/src/driver_option_common.cpp | 9 ------ .../driver_test/DRIVER0005-path/expected.txt | 1 - .../DRIVER0005-path/includes/mylib.h | 4 --- .../DRIVER0005-path/libs/libmylib.a | Bin 1040 -> 0 bytes .../c_test/driver_test/DRIVER0005-path/main.c | 26 ------------------ .../driver_test/DRIVER0005-path/test.cfg | 2 -- 7 files changed, 47 deletions(-) delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/expected.txt delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/main.c delete mode 100644 testsuite/c_test/driver_test/DRIVER0005-path/test.cfg diff --git a/src/mapleall/maple_driver/src/clang_compiler.cpp b/src/mapleall/maple_driver/src/clang_compiler.cpp index 634a45d822..e5924a388c 100644 --- a/src/mapleall/maple_driver/src/clang_compiler.cpp +++ b/src/mapleall/maple_driver/src/clang_compiler.cpp @@ -29,13 +29,8 @@ const std::string &ClangCompiler::GetBinName() const { return kBinNameClang; } -<<<<<<< HEAD static uint32_t FillSpecialDefaulOpt(std::unique_ptr &opt, const Action &action) { -======= -static inline uint32_t FillSpecialDefaulOpt(std::unique_ptr &opt, - const Action &action) { ->>>>>>> [mapleall][driver] Add "target" and "isystem" as default options for clang-ast generator uint32_t additionalLen = 1; // for -o option /* TODO: Add check for the target architecture and OS environment. diff --git a/src/mapleall/maple_driver/src/driver_option_common.cpp b/src/mapleall/maple_driver/src/driver_option_common.cpp index d05c37185e..7652807453 100644 --- a/src/mapleall/maple_driver/src/driver_option_common.cpp +++ b/src/mapleall/maple_driver/src/driver_option_common.cpp @@ -532,15 +532,6 @@ const mapleOption::Descriptor kUsages[] = { " -isystem \tAdd directory to SYSTEM include search path\n", "driver", {"clang"} }, - { kClangISystem, - 0, - "I", - "", - kBuildTypeAll, - kArgCheckPolicyRequired, - " -isystem \tAdd directory to SYSTEN include search path\n", - "all", - {"clang"} }, { kMaplePhaseOnly, kEnable, "", diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt b/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt deleted file mode 100644 index 7501d9e823..0000000000 --- a/testsuite/c_test/driver_test/DRIVER0005-path/expected.txt +++ /dev/null @@ -1 +0,0 @@ -mylib H_NUM: 5, val: 40 diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h b/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h deleted file mode 100644 index c6b66c5277..0000000000 --- a/testsuite/c_test/driver_test/DRIVER0005-path/includes/mylib.h +++ /dev/null @@ -1,4 +0,0 @@ -#define H_NUM 5 - -int mylib_doubleval(int in); - diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a b/testsuite/c_test/driver_test/DRIVER0005-path/libs/libmylib.a deleted file mode 100644 index 01afb78ecc9440c0c4aa14892647ed136d153e3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1040 zcmbtSO-jQ+6n-^YYj@g>pkNAuAet#sr3;aWRwxKc1y_YOZ3k1DG+{C=DFxkmmU;s1 zM#Mw7u1D|yMQ55BjWMqJAoN=ScQGLh-n7#SA!k>_+t1EW&sk~lX6dmg%Qap#z{PaNBAS(qS-J?eE^ z6r)C!`>07;Jxl`sv|PF_mUFq>{;q3K6KO~+$i|xOTCnLubc3LIeVZC}hLi+oN{?cn zg4Q&s0b1Sj -#include "mylib.h" - -int main() -{ - int in = 20; - int res = mylib_doubleval(in); - - printf ("mylib H_NUM: %d, val: %d\n", H_NUM, res); - return 0; -} diff --git a/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg b/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg deleted file mode 100644 index afad22c368..0000000000 --- a/testsuite/c_test/driver_test/DRIVER0005-path/test.cfg +++ /dev/null @@ -1,2 +0,0 @@ -compile(APP=main.c,OPTION="--no-maple-phase --static -lmylib -L./libs -I./includes") -run(a) -- Gitee