From dafefe4ca18dc26148adfdecd13c2dde28ed3127 Mon Sep 17 00:00:00 2001 From: "dreamonlysh@gmail.com" Date: Tue, 10 Mar 2020 20:21:14 +0800 Subject: [PATCH 1/6] Implement feature to run single phase via shared library file --- src/maple_driver/include/driver_runner.h | 19 +++++--- src/maple_driver/include/mpl_options.h | 10 ++++ src/maple_driver/include/usages.h | 1 + src/maple_driver/src/driver_runner.cpp | 29 ++++++++++- src/maple_driver/src/maple_comb_compiler.cpp | 3 +- src/maple_driver/src/mpl_options.cpp | 16 ++++++ src/maple_ipa/include/interleaved_manager.h | 2 + src/maple_ipa/include/module_phase.h | 2 +- src/maple_ipa/src/interleaved_manager.cpp | 51 ++++++++++++++++++++ src/maple_me/include/me_phase.h | 2 +- src/maple_me/src/me_alias_class.cpp | 7 +++ src/maple_phase/include/phase.h | 5 ++ src/phases/hello_func_phase.cpp | 35 ++++++++++++++ src/phases/hello_module_phase.cpp | 29 +++++++++++ 14 files changed, 197 insertions(+), 14 deletions(-) create mode 100644 src/phases/hello_func_phase.cpp create mode 100644 src/phases/hello_module_phase.cpp diff --git a/src/maple_driver/include/driver_runner.h b/src/maple_driver/include/driver_runner.h index 8151ebd046..66efb21dbe 100644 --- a/src/maple_driver/include/driver_runner.h +++ b/src/maple_driver/include/driver_runner.h @@ -18,6 +18,7 @@ #include #include #include "me_option.h" +#include "mpl_options.h" #include "interleaved_manager.h" #include "error_code.h" namespace maple { @@ -28,8 +29,7 @@ class DriverRunner final { public: DriverRunner(MIRModule *theModule, const std::vector &exeNames, Options *mpl2mplOptions, std::string mpl2mplInput, MeOption *meOptions, const std::string &meInput, std::string actualInput, - MemPool *optMp, bool timePhases = false, - bool genVtableImpl = false, bool genMeMpl = false) + MemPool *optMp, const MplOptions &mapleOptions) : theModule(theModule), exeNames(exeNames), mpl2mplOptions(mpl2mplOptions), @@ -38,14 +38,15 @@ class DriverRunner final { meInput(meInput), actualInput(actualInput), optMp(optMp), - timePhases(timePhases), - genVtableImpl(genVtableImpl), - genMeMpl(genMeMpl) {} + timePhases(mapleOptions.HasSetTimePhases()), + genVtableImpl(mapleOptions.HasSetGenVtableImpl()), + genMeMpl(mapleOptions.HasSetGenMeMpl()), + isLoadPhase(mapleOptions.GetIsLoadPhase()), + loadPhaseFile(mapleOptions.GetLoadPhaseFile()) {} DriverRunner(MIRModule *theModule, const std::vector &exeNames, std::string actualInput, MemPool *optMp, - bool timePhases = false, bool genVtableImpl = false, bool genMeMpl = false) - : DriverRunner(theModule, exeNames, nullptr, "", nullptr, "", actualInput, optMp, timePhases, genVtableImpl, - genMeMpl) {} + const MplOptions &mapleOptions) + : DriverRunner(theModule, exeNames, nullptr, "", nullptr, "", actualInput, optMp, mapleOptions) {} ~DriverRunner() = default; @@ -73,6 +74,8 @@ class DriverRunner final { bool genVtableImpl = false; bool genMeMpl = false; std::string printOutExe; + bool isLoadPhase; + std::string loadPhaseFile; }; } // namespace maple diff --git a/src/maple_driver/include/mpl_options.h b/src/maple_driver/include/mpl_options.h index 74458154cc..22a179954f 100644 --- a/src/maple_driver/include/mpl_options.h +++ b/src/maple_driver/include/mpl_options.h @@ -200,6 +200,14 @@ class MplOptions { return verify; } + bool GetIsLoadPhase() const { + return isLoadPhase; + } + + std::string GetLoadPhaseFile() const { + return loadPhaseFile; + } + private: bool Init(const std::string &inputFile); ErrorCode HandleGeneralOptions(); @@ -222,6 +230,7 @@ class MplOptions { std::string outputFolder = ""; std::string outputName = "maple"; std::string exeFolder = ""; + std::string loadPhaseFile = ""; InputFileType inputFileType = InputFileType::kNone; OptimizationLevel optimizationLevel = OptimizationLevel::kO0; RunMode runMode = RunMode::kUnkownRun; @@ -237,6 +246,7 @@ class MplOptions { bool genMeMpl = false; bool genVtableImpl = false; bool verify = false; + bool isLoadPhase = false; }; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_MPL_OPTIONS_H diff --git a/src/maple_driver/include/usages.h b/src/maple_driver/include/usages.h index df4d4da613..df7e4522d6 100644 --- a/src/maple_driver/include/usages.h +++ b/src/maple_driver/include/usages.h @@ -21,6 +21,7 @@ enum OptionIndex : uint64 { kHelp, kVersion, kInFile, + kLoad, kInMplt, kOptimization0, kMeOpt, diff --git a/src/maple_driver/src/driver_runner.cpp b/src/maple_driver/src/driver_runner.cpp index b2be28e6e0..066c44ecaa 100644 --- a/src/maple_driver/src/driver_runner.cpp +++ b/src/maple_driver/src/driver_runner.cpp @@ -14,6 +14,7 @@ */ #include "driver_runner.h" #include +#include #include #include #include "mpl_timer.h" @@ -138,9 +139,33 @@ void DriverRunner::ProcessMpl2mplAndMePhases(const std::string &outputFile, cons InterleavedManager mgr(optMp, theModule, meInput, timePhases); std::vector phases; + + if (isLoadPhase) { + void *handle = dlopen(loadPhaseFile.c_str(), RTLD_LAZY); + if (handle == nullptr) { + LogInfo::MapleLogger() << "Failed to open phase file. \n" << dlerror() << "\n"; + return; + } + typedef Phase* (*ExportPhaseFunc)(); + ExportPhaseFunc func = reinterpret_cast(dlsym(handle, "_ZN5maple11ExportPhaseEv")); + if (func == nullptr) { + LogInfo::MapleLogger() << dlerror(); + dlclose(handle); + return; + } + + Phase *phase = static_cast(func()); + CHECK_NULL_FATAL(phase); + mgr.AttachPhase(*phase, dynamic_cast(phase) != nullptr, timePhases, genMeMpl); + mgr.Run(); + delete phase; + phase = nullptr; + dlclose(handle); + } else { #include "phases.def" - InitPhases(mgr, phases); - mgr.Run(); + InitPhases(mgr, phases); + mgr.Run(); + } // emit after module phase if (printOutExe == kMpl2mpl || printOutExe == kMplMe) { diff --git a/src/maple_driver/src/maple_comb_compiler.cpp b/src/maple_driver/src/maple_comb_compiler.cpp index 8e8db44416..fc71dc7dc1 100644 --- a/src/maple_driver/src/maple_comb_compiler.cpp +++ b/src/maple_driver/src/maple_comb_compiler.cpp @@ -469,8 +469,7 @@ ErrorCode MapleCombCompiler::Compile(const MplOptions &options, MIRModulePtr &th LogInfo::MapleLogger() << "Starting mpl2mpl&mplme\n"; PrintCommand(options); DriverRunner runner(theModule, options.GetRunningExes(), mpl2mplOptions.get(), fileName, meOptions.get(), - fileName, fileName, optMp, - options.HasSetTimePhases(), options.HasSetGenVtableImpl(), options.HasSetGenMeMpl()); + fileName, fileName, optMp, options); ErrorCode nErr = runner.Run(); memPoolCtrler.DeleteMemPool(optMp); diff --git a/src/maple_driver/src/mpl_options.cpp b/src/maple_driver/src/mpl_options.cpp index 9af0224307..4c038c6e9f 100644 --- a/src/maple_driver/src/mpl_options.cpp +++ b/src/maple_driver/src/mpl_options.cpp @@ -78,6 +78,18 @@ const mapleOption::Descriptor usages[] = { " --infile file1,file2,file3 \tInput files.\n", "all", { { nullptr, nullptr, nullptr, nullptr } } }, + { kLoad, + 0, + nullptr, + "load", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --load=phase.so \tCustom phase .so file.\n", + "all", + { { nullptr, nullptr, nullptr, nullptr } } }, { kInMplt, 0, nullptr, @@ -1280,6 +1292,10 @@ ErrorCode MplOptions::HandleGeneralOptions() { case kAllDebug: debugFlag = true; break; + case kLoad: + isLoadPhase = true; + loadPhaseFile = opt.Args(); + break; default: // I do not care break; diff --git a/src/maple_ipa/include/interleaved_manager.h b/src/maple_ipa/include/interleaved_manager.h index 3e477f5546..709a6c5b14 100644 --- a/src/maple_ipa/include/interleaved_manager.h +++ b/src/maple_ipa/include/interleaved_manager.h @@ -52,6 +52,7 @@ class InterleavedManager { void AddPhases(const std::vector &phases, bool isModulePhase, bool timePhases = false, bool genMpl = false); + void AttachPhase(Phase &phase, bool isModulePhase, bool timePhases = false, bool genMpl = false); void Run(); const PhaseManager *GetSupportPhaseManager(const std::string &phase); @@ -64,6 +65,7 @@ class InterleavedManager { bool timePasses = false; void InitSupportPhaseManagers(); + PhaseManager *GetLastPhaseManager(bool isModulePhaseManager) const; }; } // namespace maple #endif // MAPLE_IPA_INCLUDE_INTERLEAVED_MANAGER_H diff --git a/src/maple_ipa/include/module_phase.h b/src/maple_ipa/include/module_phase.h index c80949ea61..80a31d8a37 100644 --- a/src/maple_ipa/include/module_phase.h +++ b/src/maple_ipa/include/module_phase.h @@ -32,7 +32,7 @@ class ModulePhase; // circular dependency exists, no other choice using ModuleResultMgr = AnalysisResultManager; class ModulePhase : public Phase { public: - explicit ModulePhase(ModulePhaseID id) : Phase(), phaseID(id) {} + explicit ModulePhase(ModulePhaseID id = kMoPhaseDoNothing) : Phase(), phaseID(id) {} virtual ~ModulePhase() = default; diff --git a/src/maple_ipa/src/interleaved_manager.cpp b/src/maple_ipa/src/interleaved_manager.cpp index e41d87f5ba..9fc788c4a7 100644 --- a/src/maple_ipa/src/interleaved_manager.cpp +++ b/src/maple_ipa/src/interleaved_manager.cpp @@ -54,6 +54,57 @@ void InterleavedManager::AddPhases(const std::vector &phases, bool } } +PhaseManager *InterleavedManager::GetLastPhaseManager(bool isModulePhaseManager) const { + PhaseManager *pm = nullptr; + + for (auto it = phaseManagers.rbegin(); it != phaseManagers.rend(); ++it) { + if (isModulePhaseManager) { + pm = dynamic_cast(*it); + } else { + pm = dynamic_cast(*it); + } + + if (pm != nullptr) { + break; + } + } + + return pm; +} + +void InterleavedManager::AttachPhase(Phase &phase, bool isModulePhase, bool timePhases, bool genMpl) { + PhaseManager *pm = GetLastPhaseManager(isModulePhase); + if (pm != nullptr) { + pm->RegisterPhase(0, phase); + pm->AddPhase(phase.PhaseName()); + return; + } + + ModuleResultMgr *mrm = phaseManagers.empty() ? nullptr : phaseManagers.back()->GetModResultMgr(); + + if (isModulePhase) { + pm = GetMemPool()->New(GetMemPool(), mirModule, mrm); + auto *mpm = static_cast(pm); + mpm->RegisterModulePhases(); + mpm->SetTimePhases(timePhases); + } else { + if (mrm == nullptr) { + auto *mpm = GetMemPool()->New(GetMemPool(), mirModule, mrm); + mpm->RegisterModulePhases(); + mpm->SetTimePhases(timePhases); + phaseManagers.push_back(mpm); + } + mrm = phaseManagers.back()->GetModResultMgr(); + pm = GetMemPool()->New(GetMemPool(), mirModule, mrm); + auto *fpm = static_cast(pm); + fpm->RegisterFuncPhases(); + fpm->SetTimePhases(timePhases); + fpm->SetGenMeMpl(genMpl); + } + + pm->RegisterPhase(0, phase); + pm->AddPhase(phase.PhaseName()); + phaseManagers.push_back(pm); void InterleavedManager::Run() { for (auto *pm : phaseManagers) { diff --git a/src/maple_me/include/me_phase.h b/src/maple_me/include/me_phase.h index 12ecd694ee..5017c0d0c1 100644 --- a/src/maple_me/include/me_phase.h +++ b/src/maple_me/include/me_phase.h @@ -35,7 +35,7 @@ class MeFunction; // circular dependency exists, no other choice using MeFuncResultMgr = AnalysisResultManager; class MeFuncPhase : public Phase { public: - explicit MeFuncPhase(MePhaseID id) : Phase(), phaseID(id) {} + explicit MeFuncPhase(MePhaseID id = kMePhaseDonothing) : Phase(), phaseID(id) {} virtual ~MeFuncPhase() = default; diff --git a/src/maple_me/src/me_alias_class.cpp b/src/maple_me/src/me_alias_class.cpp index 5b76df6927..759943d552 100644 --- a/src/maple_me/src/me_alias_class.cpp +++ b/src/maple_me/src/me_alias_class.cpp @@ -83,6 +83,13 @@ AnalysisResult *MeDoAliasClass::Run(MeFunction *func, MeFuncResultMgr *funcResMg timer.Start(); (void)funcResMgr->GetAnalysisResult(MeFuncPhase_SSATAB, func); MemPool *aliasClassMp = NewMemPool(); + if (moduleResMgr == nullptr) { + moduleResMgr = new ModuleResultMgr(&func->GetAlloc()); + ModulePhase *phase = + new (func->GetMemPool()->Malloc(sizeof(DoKlassHierarchy(MoPhase_CHA)))) DoKlassHierarchy(MoPhase_CHA); + moduleResMgr->AddAnalysisPhase(MoPhase_CHA, phase); + } + CHECK_NULL_FATAL(moduleResMgr); auto *kh = static_cast(moduleResMgr->GetAnalysisResult( MoPhase_CHA, &func->GetMIRModule())); auto *aliasClass = aliasClassMp->New( diff --git a/src/maple_phase/include/phase.h b/src/maple_phase/include/phase.h index d556d94fa2..3732f2bbb4 100644 --- a/src/maple_phase/include/phase.h +++ b/src/maple_phase/include/phase.h @@ -182,5 +182,10 @@ class AnalysisResultManager { MapleMap analysisResults; MapleMap analysisPhases; }; + +#define EXPORT_PHASE(phaseType) \ + Phase *ExportPhase() { \ + return new phaseType(); \ + } } // namespace maple #endif // MAPLE_PHASE_INCLUDE_PHASE_H diff --git a/src/phases/hello_func_phase.cpp b/src/phases/hello_func_phase.cpp new file mode 100644 index 0000000000..385eb3583f --- /dev/null +++ b/src/phases/hello_func_phase.cpp @@ -0,0 +1,35 @@ +#include "me_phase.h" +#include "bb.h" +#include "me_option.h" +#include "dominance.h" +#include "me_function.h" +#include "dse.h" +#include "me_cfg.h" +#include "ssa_mir_nodes.h" +#include "ver_symbol.h" +#include "me_dse.h" + +namespace maple { + +class HelloFuncPhase : public MeFuncPhase { + public: + AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) override { + CHECK_NULL_FATAL(func); + std::cout << "HelloFuncPhase run..." << std::endl; + (void)funcResMgr->GetAnalysisResult(MeFuncPhase_ALIASCLASS, func); + auto *postDom = static_cast(funcResMgr->GetAnalysisResult(MeFuncPhase_DOMINANCE, func)); + CHECK_NULL_FATAL(postDom); + MeDSE dse(func, postDom, true); + dse.RunDSE(); + func->Verify(); + return nullptr; + } + + std::string PhaseName() const override { + return "hellofuncphase"; + } +}; + +EXPORT_PHASE(HelloFuncPhase) + +} diff --git a/src/phases/hello_module_phase.cpp b/src/phases/hello_module_phase.cpp new file mode 100644 index 0000000000..69b9690541 --- /dev/null +++ b/src/phases/hello_module_phase.cpp @@ -0,0 +1,29 @@ +#include +#include +#include "option.h" +#include "mir_function.h" +#include "module_phase.h" +#include "class_hierarchy.h" + +namespace maple { + +class HelloModulePhase : public ModulePhase { + public: + AnalysisResult *Run(MIRModule *module, ModuleResultMgr *moduleResMgr) override { + std::cout << "HelloModulePhase run..." << std::endl; + MemPool *memPool = memPoolCtrler.NewMemPool("classhierarchy mempool"); + KlassHierarchy *kh = memPool->New(module, memPool); + kh->BuildHierarchy(); + kh->CountVirtualMethods(); + kh->Dump(); + return kh; + } + + std::string PhaseName() const override { + return "hellomodulephase"; + } +}; + +EXPORT_PHASE(HelloModulePhase) + +} -- Gitee From 3d0739523bcc13ba4174fd70354bed318379bdd5 Mon Sep 17 00:00:00 2001 From: SkyWet Date: Wed, 11 Mar 2020 11:04:05 +0800 Subject: [PATCH 2/6] update hello_func_phase.cpp --- src/phases/hello_func_phase.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/phases/hello_func_phase.cpp b/src/phases/hello_func_phase.cpp index 385eb3583f..8e0e36c3ea 100644 --- a/src/phases/hello_func_phase.cpp +++ b/src/phases/hello_func_phase.cpp @@ -31,5 +31,4 @@ class HelloFuncPhase : public MeFuncPhase { }; EXPORT_PHASE(HelloFuncPhase) - } -- Gitee From 42078ad34058843da3a4b731353e70a448e16953 Mon Sep 17 00:00:00 2001 From: SkyWet Date: Wed, 11 Mar 2020 11:37:43 +0800 Subject: [PATCH 3/6] add phases BUILD.gn --- src/BUILD.gn | 2 + src/phases/BUILD.gn | 42 +++++++++++++++++++++ src/phases/{ => src}/hello_func_phase.cpp | 14 +++++++ src/phases/{ => src}/hello_module_phase.cpp | 15 +++++++- 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/phases/BUILD.gn rename src/phases/{ => src}/hello_func_phase.cpp (61%) rename src/phases/{ => src}/hello_module_phase.cpp (55%) diff --git a/src/BUILD.gn b/src/BUILD.gn index 7eabe88f02..869f0d984b 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -43,5 +43,7 @@ group("mapleall") { deps = [ "${MAPLEALL_ROOT}/maple_driver:maple", "${MAPLEALL_ROOT}/maple_ir:irbuild", + "${MAPLEALL_ROOT}/phases:libhello_func_phase", + "${MAPLEALL_ROOT}/phases:libhello_module_phase", ] } diff --git a/src/phases/BUILD.gn b/src/phases/BUILD.gn new file mode 100644 index 0000000000..27374b1ccd --- /dev/null +++ b/src/phases/BUILD.gn @@ -0,0 +1,42 @@ +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# 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 v1 for more details. +# +configs = [ "${MAPLEALL_ROOT}:mapleallcompilecfg" ] + +include_dirs = [ + "${MAPLEALL_ROOT}/mpl2mpl/include", + "${MAPLEALL_ROOT}/maplewpo/include", + "${MAPLEALL_ROOT}/maple_ipa/include", + "${MAPLEALL_ROOT}/maple_phase/include", + "${MAPLEALL_ROOT}/maple_util/include", + "${MAPLEALL_ROOT}/maple_ir/include", + "${MAPLEALL_ROOT}/maple_me/include", + "${MAPLEALL_ROOT}/mempool/include", + "${MAPLEALL_ROOT}/huawei_secure_c/include", +] + +shared_library("libhello_func_phase") { + sources = [ + "src/hello_func_phase.cpp", + ] +} + +shared_library("libhello_module_phase") { + sources = [ + "src/hello_module_phase.cpp", + ] +} + +libs = [] +libs += [ "-ldl" ] diff --git a/src/phases/hello_func_phase.cpp b/src/phases/src/hello_func_phase.cpp similarity index 61% rename from src/phases/hello_func_phase.cpp rename to src/phases/src/hello_func_phase.cpp index 8e0e36c3ea..0291f4c166 100644 --- a/src/phases/hello_func_phase.cpp +++ b/src/phases/src/hello_func_phase.cpp @@ -1,3 +1,17 @@ +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# 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 v1 for more details. +# #include "me_phase.h" #include "bb.h" #include "me_option.h" diff --git a/src/phases/hello_module_phase.cpp b/src/phases/src/hello_module_phase.cpp similarity index 55% rename from src/phases/hello_module_phase.cpp rename to src/phases/src/hello_module_phase.cpp index 69b9690541..067d7bef05 100644 --- a/src/phases/hello_module_phase.cpp +++ b/src/phases/src/hello_module_phase.cpp @@ -1,3 +1,17 @@ +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# 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 v1 for more details. +# #include #include #include "option.h" @@ -25,5 +39,4 @@ class HelloModulePhase : public ModulePhase { }; EXPORT_PHASE(HelloModulePhase) - } -- Gitee From 3c57327ef67a6131cbad2c3a9b7d6a36364f820e Mon Sep 17 00:00:00 2001 From: "dreamonlysh@gmail.com" Date: Fri, 10 Apr 2020 17:06:04 +0800 Subject: [PATCH 4/6] Update phase code --- src/phases/src/hello_func_phase.cpp | 28 +++++++++++++-------------- src/phases/src/hello_module_phase.cpp | 28 +++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/phases/src/hello_func_phase.cpp b/src/phases/src/hello_func_phase.cpp index 0291f4c166..3e76befa2e 100644 --- a/src/phases/src/hello_func_phase.cpp +++ b/src/phases/src/hello_func_phase.cpp @@ -1,17 +1,17 @@ -# -# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. -# -# OpenArkCompiler is licensed under the Mulan PSL v1. -# You can use this software according to the terms and conditions of the Mulan PSL v1. -# You may obtain a copy of Mulan PSL v1 at: -# -# http://license.coscl.org.cn/MulanPSL -# -# 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 v1 for more details. -# +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * 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 v1 for more details. + */ #include "me_phase.h" #include "bb.h" #include "me_option.h" diff --git a/src/phases/src/hello_module_phase.cpp b/src/phases/src/hello_module_phase.cpp index 067d7bef05..37bc6b85c0 100644 --- a/src/phases/src/hello_module_phase.cpp +++ b/src/phases/src/hello_module_phase.cpp @@ -1,17 +1,17 @@ -# -# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. -# -# OpenArkCompiler is licensed under the Mulan PSL v1. -# You can use this software according to the terms and conditions of the Mulan PSL v1. -# You may obtain a copy of Mulan PSL v1 at: -# -# http://license.coscl.org.cn/MulanPSL -# -# 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 v1 for more details. -# +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * 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 v1 for more details. + */ #include #include #include "option.h" -- Gitee From 177678ad9269e55b6c2ba5dea5750d0ccb3474d3 Mon Sep 17 00:00:00 2001 From: "dreamonlysh@gmail.com" Date: Fri, 10 Apr 2020 17:22:04 +0800 Subject: [PATCH 5/6] Fix bug --- src/maple_driver/src/mplcg_compiler.cpp | 2 +- src/maple_ipa/src/interleaved_manager.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/maple_driver/src/mplcg_compiler.cpp b/src/maple_driver/src/mplcg_compiler.cpp index a5faf4a4c1..9c57c1e213 100644 --- a/src/maple_driver/src/mplcg_compiler.cpp +++ b/src/maple_driver/src/mplcg_compiler.cpp @@ -364,7 +364,7 @@ ErrorCode MplcgCompiler::Compile(const MplOptions &options, MIRModulePtr &theMod } LogInfo::MapleLogger() << "Starting mplcg\n"; - DriverRunner runner(theModule, options.GetRunningExes(), fileName, optMp, options.HasSetTimePhases()); + DriverRunner runner(theModule, options.GetRunningExes(), fileName, optMp, options); PrintCommand(options); runner.SetCGInfo(cgOption.get(), fileName); runner.ProcessCGPhase(output, baseName); diff --git a/src/maple_ipa/src/interleaved_manager.cpp b/src/maple_ipa/src/interleaved_manager.cpp index 9fc788c4a7..fdd4829a38 100644 --- a/src/maple_ipa/src/interleaved_manager.cpp +++ b/src/maple_ipa/src/interleaved_manager.cpp @@ -105,6 +105,7 @@ void InterleavedManager::AttachPhase(Phase &phase, bool isModulePhase, bool time pm->RegisterPhase(0, phase); pm->AddPhase(phase.PhaseName()); phaseManagers.push_back(pm); +} void InterleavedManager::Run() { for (auto *pm : phaseManagers) { -- Gitee From 77711ce26d7e53f844b07d8e6e82aee6ba426f68 Mon Sep 17 00:00:00 2001 From: "dreamonlysh@gmail.com" Date: Sat, 18 Apr 2020 15:11:45 +0800 Subject: [PATCH 6/6] Fix build script issue --- BUILD.gn | 7 +++++++ Makefile | 4 ++++ src/BUILD.gn | 43 ++++++++++++++++++++++++++++++--------- src/maple_driver/BUILD.gn | 10 ++++----- src/phases/BUILD.gn | 10 +++------ 5 files changed, 51 insertions(+), 23 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 7c04edc968..fccf9e9388 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -24,6 +24,13 @@ group("irbuild") { ] } +group("mapleso") { + deps = [ + "${MAPLE_ROOT}/src:maple", + "${MAPLE_ROOT}/src:mapleso", + ] +} + group("mplfe") { deps = [ "${MAPLE_ROOT}/src:mplfe", diff --git a/Makefile b/Makefile index fab8b569bf..b188f0b038 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,10 @@ maple: maplegendef irbuild: $(call build_gn, ${GN_OPTIONS}, irbuild) +.PHONY: mapleso +mapleso: + $(call build_gn, ${GN_OPTIONS}, mapleso) + .PHONY: mplfe mplfe: $(call build_gn, ${GN_OPTIONS}, mplfe) diff --git a/src/BUILD.gn b/src/BUILD.gn index 6a2fff8ca6..6b2b47e4ca 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -39,28 +39,51 @@ config("mapleallcompilecfg") { } } -group("maple") { - deps = [ - "${MAPLEALL_ROOT}/maple_driver:maple", +config("maplesocfg") { + cflags_cc = [] + cflags_cc += [ + "-std=c++14", + "-Werror", ] + + if (GN_BUILD_TYPE == "DEBUG") { + cflags_c += [ "-DDEBUG" ] + cflags_cc += [ "-DDEBUG" ] + } + + if (HOST_ARCH == 64) { + ldflags = [] + ldflags += [ + "-fPIC", + "-std=c++14", + "-rdynamic", + "-lpthread", + "-Wl,-z,relro", + "-Wl,-z,now", + "-Wl,-z,noexecstack", + ] + } +} + +group("maple") { + deps = [ "${MAPLEALL_ROOT}/maple_driver:maple" ] } group("irbuild") { + deps = [ "${MAPLEALL_ROOT}/maple_ir:irbuild" ] +} + +group("mapleso") { deps = [ - "${MAPLEALL_ROOT}/maple_ir:irbuild", "${MAPLEALL_ROOT}/phases:libhello_func_phase", "${MAPLEALL_ROOT}/phases:libhello_module_phase", ] } group("mplfe") { - deps = [ - "${MAPLEALL_ROOT}/mplfe:mplfe", - ] + deps = [ "${MAPLEALL_ROOT}/mplfe:mplfe" ] } group("maplegen") { - deps = [ - "${MAPLEALL_ROOT}/maple_be:maplegen", - ] + deps = [ "${MAPLEALL_ROOT}/maple_be:maplegen" ] } diff --git a/src/maple_driver/BUILD.gn b/src/maple_driver/BUILD.gn index ae3c82ea15..753afbd67e 100644 --- a/src/maple_driver/BUILD.gn +++ b/src/maple_driver/BUILD.gn @@ -72,7 +72,9 @@ executable("maple") { "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", ] libs = [] + libs += [ + "dl", "${OPENSOURCE_DEPS}/libmplphase.a", "${OPENSOURCE_DEPS}/libmempool.a", "${OPENSOURCE_DEPS}/libmplutil.a", @@ -80,9 +82,7 @@ executable("maple") { } static_library("liboption_parser_extra") { - sources = [ - "src/option_parser.cpp", - ] + sources = [ "src/option_parser.cpp" ] cflags_cc += [ "-DOPTION_PARSER_EXTRAOPT", @@ -99,9 +99,7 @@ static_library("liboption_parser_extra") { } static_library("liboption_parser") { - sources = [ - "src/option_parser.cpp", - ] + sources = [ "src/option_parser.cpp" ] include_dirs = [ "${MAPLEALL_ROOT}/maple_util/include", diff --git a/src/phases/BUILD.gn b/src/phases/BUILD.gn index 27374b1ccd..449d53cd9a 100644 --- a/src/phases/BUILD.gn +++ b/src/phases/BUILD.gn @@ -12,7 +12,7 @@ # FIT FOR A PARTICULAR PURPOSE. # See the Mulan PSL v1 for more details. # -configs = [ "${MAPLEALL_ROOT}:mapleallcompilecfg" ] +configs = [ "${MAPLEALL_ROOT}:maplesocfg" ] include_dirs = [ "${MAPLEALL_ROOT}/mpl2mpl/include", @@ -27,15 +27,11 @@ include_dirs = [ ] shared_library("libhello_func_phase") { - sources = [ - "src/hello_func_phase.cpp", - ] + sources = [ "src/hello_func_phase.cpp" ] } shared_library("libhello_module_phase") { - sources = [ - "src/hello_module_phase.cpp", - ] + sources = [ "src/hello_module_phase.cpp" ] } libs = [] -- Gitee