diff --git a/BUILD.gn b/BUILD.gn index 7c04edc9686fa58d3dcb41dca29234365d10c144..fccf9e9388f0bd05d506ff608b3585a83a82e43b 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 fab8b569bf1b8a4f7fe42cd70baaef28a6bcb26a..b188f0b03846ec0a77e17b984a891c07961d4d96 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 329c86e775bc6ee8ee1676bccb9c4876de677d69..6b2b47e4ca2c7ee98d4c07b490f0399c7823ca8c 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -39,26 +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 ae3c82ea151192cacac0edf32bb4f008b17af372..753afbd67e5b495078efebf163f8a934ce2b2739 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/maple_driver/include/driver_runner.h b/src/maple_driver/include/driver_runner.h index f7647879a9842bd818bfe912a7a17ae200656b9b..3ab6a3288e2a2912824655833fbcdf304f6d17a6 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" #include "cg.h" @@ -34,8 +35,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), @@ -44,14 +44,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; @@ -93,6 +94,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 74458154cc4c9fde4a5d8b57e10a1a74f542949a..22a179954fe730ab9be6cc6b127374ba4e12ab3c 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 fe2574f80ed13c0c64e24654c68a9ccf10ac2b82..f4dcd08ae96cc4f9ec77ec0afefbf846067ca209 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, kOptimization2, diff --git a/src/maple_driver/src/driver_runner.cpp b/src/maple_driver/src/driver_runner.cpp index 402a49c961f2f55ed74eb959fb5e59e4abb24172..ad737ee30dde50652daf5aab9b1a5bd6d2bd371c 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" @@ -153,9 +154,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 a3657bf2f56d25de2d6e253fa064f7dd71dc25b4..b7a1c46e7042e5c8b73d194d60c59958b992f98c 100644 --- a/src/maple_driver/src/maple_comb_compiler.cpp +++ b/src/maple_driver/src/maple_comb_compiler.cpp @@ -468,8 +468,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 89d1043a9414d11f3f4d4d21274c9a6063c6fefb..0fa981acf6991aaa9b3c2627df6828da57477f3f 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, @@ -1857,6 +1869,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_driver/src/mplcg_compiler.cpp b/src/maple_driver/src/mplcg_compiler.cpp index a5faf4a4c15fe34f6f19effd32fb621a1590ddab..9c57c1e213302139335efacda3d7348536993c36 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/include/interleaved_manager.h b/src/maple_ipa/include/interleaved_manager.h index 3e477f55462e7a696c164c0a4abc8265243c0b1d..709a6c5b14c9bf9e6334f673b28a9136318c0c4d 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 c80949ea61001f3573ea1db9328d7425df6efa4e..80a31d8a37d20048e55ea8f9172bb70a8aeaae97 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 e41d87f5ba9720e52c1fd52a0e9ddd5f18815455..fdd4829a380cf56ef24214e27dab319e5fb22ec3 100644 --- a/src/maple_ipa/src/interleaved_manager.cpp +++ b/src/maple_ipa/src/interleaved_manager.cpp @@ -54,6 +54,58 @@ 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 12ecd694ee44156909af2ad3e60f3fd05e1b0c70..5017c0d0c19a1e6598df1498c05fb60f966bb240 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 4441f0fee4c337a02915b4dfe05c27a0660a3135..68398d97d583f6e942ef7ed676d324b2c6087c93 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 d556d94fa201c2135cc9a722a573b1b6b0339970..3732f2bbb49abefec677bd244cd4197a2f2b8df3 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/BUILD.gn b/src/phases/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..449d53cd9ae4510b1521af2f1fd4acb9a1c292ba --- /dev/null +++ b/src/phases/BUILD.gn @@ -0,0 +1,38 @@ +# +# 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}:maplesocfg" ] + +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/src/hello_func_phase.cpp b/src/phases/src/hello_func_phase.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3e76befa2eae74416bab3ec94ce6736a697101ad --- /dev/null +++ b/src/phases/src/hello_func_phase.cpp @@ -0,0 +1,48 @@ +/* + * 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" +#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/src/hello_module_phase.cpp b/src/phases/src/hello_module_phase.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37bc6b85c0cb101d1c758276970947ca1ee0c6f1 --- /dev/null +++ b/src/phases/src/hello_module_phase.cpp @@ -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. + */ +#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) +}