diff --git a/src/mapleall/deplibs/libmempool.a b/src/mapleall/deplibs/libmempool.a deleted file mode 100644 index f44f9add3dd5703e0356ed153c73bb265751dda7..0000000000000000000000000000000000000000 Binary files a/src/mapleall/deplibs/libmempool.a and /dev/null differ diff --git a/src/mapleall/deplibs/libmplphase.a b/src/mapleall/deplibs/libmplphase.a deleted file mode 100644 index ee4d005f1d6293fb2bd02c21acb39b5c659a2507..0000000000000000000000000000000000000000 Binary files a/src/mapleall/deplibs/libmplphase.a and /dev/null differ diff --git a/src/mapleall/deplibs/libmplutil.a b/src/mapleall/deplibs/libmplutil.a deleted file mode 100644 index 0b6eaba3f94a9a52025b669e707c9d108d09dac4..0000000000000000000000000000000000000000 Binary files a/src/mapleall/deplibs/libmplutil.a and /dev/null differ diff --git a/src/mapleall/maple_be/BUILD.gn b/src/mapleall/maple_be/BUILD.gn index e02af538d8f8e5f2143ca590188b068c1b6f1c91..42fb9d831e470d7a4d25669647b550c6936d04f2 100644 --- a/src/mapleall/maple_be/BUILD.gn +++ b/src/mapleall/maple_be/BUILD.gn @@ -163,10 +163,8 @@ executable("maplegen") { ] deps = [ "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", - ] - libs = [ - "${OPENSOURCE_DEPS}/libmempool.a", - "${OPENSOURCE_DEPS}/libmplutil.a", + "${MAPLEALL_ROOT}/mempool:libmempool", + "${MAPLEALL_ROOT}/maple_util:libmplutil", ] include_dirs = [ diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index b303e72173bf030301502e241f3a94ce938f6946..35f6705ea701d6fc2ea32ffdd6821e9884bdb261 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -67,12 +67,9 @@ executable("maple") { "${MAPLEALL_ROOT}/maple_me:libmplme", "${MAPLEALL_ROOT}/maple_me:libmplmewpo", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", - ] - libs = [] - libs += [ - "${OPENSOURCE_DEPS}/libmplphase.a", - "${OPENSOURCE_DEPS}/libmempool.a", - "${OPENSOURCE_DEPS}/libmplutil.a", + "${MAPLEALL_ROOT}/maple_phase:libmplphase", + "${MAPLEALL_ROOT}/mempool:libmempool", + "${MAPLEALL_ROOT}/maple_util:libmplutil", ] } diff --git a/src/mapleall/maple_ir/BUILD.gn b/src/mapleall/maple_ir/BUILD.gn index 609581dda61accbb4d8f84b78cd8d6ed988170db..471cf5d9e112745fad6befc073052639b4d87483 100644 --- a/src/mapleall/maple_ir/BUILD.gn +++ b/src/mapleall/maple_ir/BUILD.gn @@ -57,11 +57,10 @@ static_library("libmplir") { sources = src_libmplir include_dirs = include_directories output_dir = "${root_out_dir}/ar" - libs = [] - libs += [ "${OPENSOURCE_DEPS}/libmplutil.a" ] deps = [ "${MAPLEALL_ROOT}/maple_driver:libdriver_option", "${MAPLEALL_ROOT}/maple_driver:liboption_parser", + "${MAPLEALL_ROOT}/maple_util:libmplutil", ] } @@ -73,11 +72,8 @@ executable("irbuild") { "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_driver:liboption_parser", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", - ] - libs = [] - libs += [ - "${OPENSOURCE_DEPS}/libmplphase.a", - "${OPENSOURCE_DEPS}/libmempool.a", - "${OPENSOURCE_DEPS}/libmplutil.a", + "${MAPLEALL_ROOT}/maple_phase:libmplphase", + "${MAPLEALL_ROOT}/mempool:libmempool", + "${MAPLEALL_ROOT}/maple_util:libmplutil", ] } diff --git a/src/mapleall/maple_phase/BUILD.gn b/src/mapleall/maple_phase/BUILD.gn index 653603ba25016a542ca761beb13236ba94ff695e..23e58422cae0bc08ade6ce91c78580e07d989804 100644 --- a/src/mapleall/maple_phase/BUILD.gn +++ b/src/mapleall/maple_phase/BUILD.gn @@ -6,7 +6,7 @@ include_libmplphase = [ "${MAPLEALL_ROOT}/maple_phase/include", "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mpl2mpl/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", "${MAPLEALL_ROOT}/maple_driver/include", ] @@ -21,4 +21,4 @@ static_library("libmplphase") { sources = src_libmplphase include_dirs = include_libmplphase output_dir = "${root_out_dir}/lib/${HOST_ARCH}" -} \ No newline at end of file +} diff --git a/src/mapleall/maple_phase/include/phase_driver.h b/src/mapleall/maple_phase/include/phase_driver.h new file mode 100644 index 0000000000000000000000000000000000000000..c9efcf4686e67be62a0954c5fb89c6eb2e1f4193 --- /dev/null +++ b/src/mapleall/maple_phase/include/phase_driver.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#ifndef MAPLE_PHASE_INCLUDE_PHASEDRIVER_H +#define MAPLE_PHASE_INCLUDE_PHASEDRIVER_H +#include "mir_module.h" +#include "mir_function.h" +#include "mpl_scheduler.h" + +namespace maple { +class PhaseDriverImpl : public MplTaskParam { + public: + PhaseDriverImpl() = default; + virtual ~PhaseDriverImpl() = default; + + virtual void GlobalInit() {} + + virtual void LocalInit() {} + + virtual void ProcessRun(uint32, void*, void*) {} + + virtual void ProcessFinish(uint32, void*, void*) {} +}; + +class PhaseDriver : public MplScheduler { + public: + class Task : public MplTask { + public: + Task(void *currTarget, void *currParamEx = nullptr) : target(currTarget), paramException(currParamEx) {} + + ~Task() = default; + + protected: + int RunImpl(MplTaskParam *param) override { + CHECK_NULL_FATAL(param); + static_cast(param)->ProcessRun(taskId, target, paramException); + return 0; + } + + int FinishImpl(MplTaskParam *param) override { + CHECK_NULL_FATAL(param); + static_cast(param)->ProcessFinish(taskId, target, paramException); + return 0; + } + void *target; + void *paramException; + }; + + explicit PhaseDriver(const std::string &phaseName); + virtual ~PhaseDriver() = default; + + virtual void RunAll(MIRModule *module, int thread, bool bSeq = false); + virtual void RunSerial(); + virtual void RunParallel(int thread, bool bSeq = false); + virtual PhaseDriverImpl *NewPhase() = 0; + virtual void RegisterTasks() = 0; + + protected: + virtual void CallbackThreadMainStart(); + virtual void CallbackThreadMainEnd(); + virtual MplTaskParam *CallbackGetTaskRunParam() const { + return phaseImplLocal; + } + + virtual MplTaskParam *CallbackGetTaskFinishParam() const { + return phaseImplLocal; + } + + MIRModule *module; + PhaseDriverImpl *phaseImpl; + thread_local static PhaseDriverImpl *phaseImplLocal; + std::string phaseName; +}; +} // namespace maple +#endif // MAPLE_PHASE_INCLUDE_PHASEDRIVER_H diff --git a/src/mapleall/maple_util/BUILD.gn b/src/mapleall/maple_util/BUILD.gn index 1a2830979cb7d60a79671cd39c5ab5f85e29a9d6..e84c7e7c01adb8337eaeed88306333b47029cb23 100755 --- a/src/mapleall/maple_util/BUILD.gn +++ b/src/mapleall/maple_util/BUILD.gn @@ -18,7 +18,7 @@ include_libmplutil = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", "${MAPLEALL_ROOT}/maple_driver/include", - "${MAPLE_ROOT}/third-party/bounds_checking_function/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] configs = [ "${MAPLEALL_ROOT}:mapleallcompilecfg" ] diff --git a/src/mapleall/maple_util/include/thread_env.h b/src/mapleall/maple_util/include/thread_env.h new file mode 100644 index 0000000000000000000000000000000000000000..7540ac137d6077ec707c5718ce3982fecbf7622c --- /dev/null +++ b/src/mapleall/maple_util/include/thread_env.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#ifndef MAPLE_UTIL_INCLUDE_THREAD_STATUS_H +#define MAPLE_UTIL_INCLUDE_THREAD_STATUS_H +#include +#include +#include + +namespace maple { +class ThreadEnv { + public: + static bool IsMeParallel() { + return threadEnv.isMeParallel; + } + + static void SetMeParallel(bool status) { + threadEnv.isMeParallel = status; + } + + static size_t GetThreadIndex(const std::thread::id &tid) { + static std::mutex mtx; + std::lock_guard guard(mtx); + auto it = threadEnv.threadIndexMap.find(tid); + if (it != threadEnv.threadIndexMap.end()) { + return it->second; + } + return 0; // the index of main thread is 0 + } + + static void InitThreadIndex(const std::thread::id &tid) { + static std::mutex mtx; + std::lock_guard guard(mtx); + size_t currThreadCnt = threadEnv.threadIndexMap.size(); + threadEnv.threadIndexMap[tid] = (currThreadCnt + 1); + } + + private: + static ThreadEnv threadEnv; + bool isMeParallel = false; // whether me is under multithreading (optimize separate functions in parallel) + // thread index begins from 1. 0 is reserved for main thread, which is not in the map + std::unordered_map threadIndexMap; +}; + +class ParallelGuard { + public: + explicit ParallelGuard(std::mutex &mtxInput, bool cond = true) : mtx(mtxInput), condition(cond) { + if (condition) { + mtx.lock(); + } + } + + ParallelGuard(const ParallelGuard&) = delete; + ParallelGuard &operator=(const ParallelGuard&) = delete; + + ~ParallelGuard() { + if (condition) { + mtx.unlock(); + } + } + + private: + std::mutex &mtx; + const bool condition; +}; +} // namespace maple +#endif // MAPLE_UTIL_INCLUDE_THREAD_STATUS_H diff --git a/src/mapleall/mempool/BUILD.gn b/src/mapleall/mempool/BUILD.gn index 68e5116076162df3e7c14d0a5081b546848d9e85..386f797efe551d4594b478872302f54cfbacd2c8 100644 --- a/src/mapleall/mempool/BUILD.gn +++ b/src/mapleall/mempool/BUILD.gn @@ -7,7 +7,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] configs = [ "${MAPLEALL_ROOT}:mapleallcompilecfg" ] @@ -28,7 +28,7 @@ executable("MemPool") { deps = [ ":libmempool", - "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", + "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_driver:liboption_parser", "${MAPLEALL_ROOT}/maple_util:libmplutil", ] diff --git a/src/mplfe/BUILD.gn b/src/mplfe/BUILD.gn index 2bc68f21159a96d9b91978fe7dbdfd186af0728a..9ff431a1b17a1d7f0775de814638398c8aa1c6dc 100644 --- a/src/mplfe/BUILD.gn +++ b/src/mplfe/BUILD.gn @@ -95,10 +95,8 @@ executable("mplfe") { "${MAPLEALL_ROOT}/maple_driver:libdriver_option", "${MAPLEALL_ROOT}/maple_ir:libmplir", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", - ] - libs = [ - "${OPENSOURCE_DEPS}/libmempool.a", - "${OPENSOURCE_DEPS}/libmplutil.a", + "${MAPLEALL_ROOT}/mempool:libmempool", + "${MAPLEALL_ROOT}/maple_util:libmplutil", ] ldflags = [ "-lz" ] }