From efdcecf288328bc74aa9835cd42cfc92f4fca309 Mon Sep 17 00:00:00 2001 From: linma Date: Tue, 4 May 2021 18:31:35 -0700 Subject: [PATCH 1/3] check function IR status (hssa or not) according to phase name in me_emit --- src/mapleall/maple_be/include/cg/cg_phase.h | 4 +- src/mapleall/maple_me/include/me_phase.h | 2 +- src/mapleall/maple_me/src/me_emit.cpp | 58 ++++++++++++++------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/mapleall/maple_be/include/cg/cg_phase.h b/src/mapleall/maple_be/include/cg/cg_phase.h index 907e6627dd..10fc2f3b2f 100644 --- a/src/mapleall/maple_be/include/cg/cg_phase.h +++ b/src/mapleall/maple_be/include/cg/cg_phase.h @@ -57,7 +57,7 @@ class FuncPhase : public Phase { return prevPhaseName; } - void SetPreviousPhaseName(const std::string &phaseName) { + void SetPreviousPhaseName(const std::string phaseName) { prevPhaseName = phaseName; } @@ -100,4 +100,4 @@ class FuncPhase : public Phase { } \ }; -#endif /* MAPLEBE_INCLUDE_CG_CG_PHASE_H */ \ No newline at end of file +#endif /* MAPLEBE_INCLUDE_CG_CG_PHASE_H */ diff --git a/src/mapleall/maple_me/include/me_phase.h b/src/mapleall/maple_me/include/me_phase.h index d902b02d27..9756f14c43 100644 --- a/src/mapleall/maple_me/include/me_phase.h +++ b/src/mapleall/maple_me/include/me_phase.h @@ -48,7 +48,7 @@ class MeFuncPhase : public Phase { return prevPhaseName; } - void SetPreviousPhaseName(const std::string &phaseName) { + void SetPreviousPhaseName(const std::string phaseName) { prevPhaseName = phaseName; } diff --git a/src/mapleall/maple_me/src/me_emit.cpp b/src/mapleall/maple_me/src/me_emit.cpp index 6be456c4fc..f45eaa77c7 100644 --- a/src/mapleall/maple_me/src/me_emit.cpp +++ b/src/mapleall/maple_me/src/me_emit.cpp @@ -20,34 +20,54 @@ #include "me_cfg.h" #include "constantfold.h" +static const std::set kHssaPhases{ + "irmapbuild", "hprop", "hssa", "hdse", "ssadevirt", "ea", "epre", + "lpre", "stmtpre", "rename2preg", "ti", "analyzerc", + "spre", "rclowering", "delegaterc", "condbasedrc", "condbasednpc", "may2dassign", "pregrename", + "bdcopt", "syncselect", "cfgopt", "placementrc", "symrename", "checkcastopt", "bblayout", +}; + namespace maple { // emit IR to specified file -AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr*, ModuleResultMgr*) { +AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr*) { static std::mutex mtx; ParallelGuard guard(mtx, ThreadEnv::IsMeParallel()); if (func->NumBBs() > 0) { - CHECK_FATAL(func->GetIRMap() != nullptr, "Why not hssa?"); - // generate bblist after layout (bb physical position) - CHECK_FATAL(func->HasLaidOut(), "Check/Run bb layout phase."); - auto layoutBBs = func->GetLaidOutBBs(); - MIRFunction *mirFunction = func->GetMirFunc(); - mirFunction->ReleaseCodeMemory(); + std::string passName = GetPreviousPhaseName(); + bool emitHssaOrAfter = kHssaPhases.find(std::string(passName)) != kHssaPhases.end(); + if (emitHssaOrAfter) { + CHECK_FATAL(func->GetIRMap() != nullptr, "Why not hssa?"); + // generate bblist after layout (bb physical position) + CHECK_FATAL(func->HasLaidOut(), "Check/Run bb layout phase."); + auto layoutBBs = func->GetLaidOutBBs(); + MIRFunction *mirFunction = func->GetMirFunc(); + mirFunction->ReleaseCodeMemory(); - mirFunction->SetMemPool(new ThreadLocalMemPool(memPoolCtrler, "IR from IRMap::Emit()")); - mirFunction->SetBody(mirFunction->GetCodeMempool()->New()); - // initialize is_deleted field to true; will reset when emitting Maple IR - for (size_t k = 1; k < mirFunction->GetSymTab()->GetSymbolTableSize(); ++k) { - MIRSymbol *sym = mirFunction->GetSymTab()->GetSymbolFromStIdx(k); - if (sym->GetSKind() == kStVar) { - sym->SetIsDeleted(); + mirFunction->SetMemPool(new ThreadLocalMemPool(memPoolCtrler, "IR from IRMap::Emit()")); + mirFunction->SetBody(mirFunction->GetCodeMempool()->New()); + // initialize is_deleted field to true; will reset when emitting Maple IR + for (size_t k = 1; k < mirFunction->GetSymTab()->GetSymbolTableSize(); ++k) { + MIRSymbol *sym = mirFunction->GetSymTab()->GetSymbolFromStIdx(k); + if (sym->GetSKind() == kStVar) { + sym->SetIsDeleted(); + } + } + for (BB *bb : layoutBBs) { + ASSERT(bb != nullptr, "Check bblayout phase"); + bb->EmitBB(*func->GetMeSSATab(), *mirFunction->GetBody(), false); + } + } else { + if(!func->HasLaidOut()) { + (void)m->GetAnalysisResult(MeFuncPhase_BBLAYOUT, func); + CHECK_FATAL(func->HasLaidOut(), "Check bb layout phase."); } + func->EmitBeforeHSSA((*(func->GetMirFunc())), func->GetLaidOutBBs()); } - for (BB *bb : layoutBBs) { - ASSERT(bb != nullptr, "Check bblayout phase"); - bb->EmitBB(*func->GetMeSSATab(), *mirFunction->GetBody(), false); + if (!DEBUGFUNC(func)) { + // constantfolding does not update BB's stmtNodeList, which breaks MirCFG::DumpToFile() + ConstantFold cf(func->GetMIRModule()); + cf.Simplify(func->GetMirFunc()->GetBody()); } - ConstantFold cf(func->GetMIRModule()); - cf.Simplify(func->GetMirFunc()->GetBody()); if (DEBUGFUNC(func)) { LogInfo::MapleLogger() << "\n==============after meemit =============" << '\n'; func->GetMirFunc()->Dump(); -- Gitee From b2e16705654a75ee863debfdecf7a85340df2fb3 Mon Sep 17 00:00:00 2001 From: linma Date: Thu, 13 May 2021 11:30:42 -0700 Subject: [PATCH 2/3] revert !PR578 --- src/mapleall/maple_be/include/cg/cg_phase.h | 2 +- src/mapleall/maple_me/include/me_phase.h | 2 +- src/mapleall/maple_me/src/me_emit.cpp | 58 +++++++-------------- 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/mapleall/maple_be/include/cg/cg_phase.h b/src/mapleall/maple_be/include/cg/cg_phase.h index 10fc2f3b2f..4a8fe92d1b 100644 --- a/src/mapleall/maple_be/include/cg/cg_phase.h +++ b/src/mapleall/maple_be/include/cg/cg_phase.h @@ -57,7 +57,7 @@ class FuncPhase : public Phase { return prevPhaseName; } - void SetPreviousPhaseName(const std::string phaseName) { + void SetPreviousPhaseName(const std::string& phaseName) { prevPhaseName = phaseName; } diff --git a/src/mapleall/maple_me/include/me_phase.h b/src/mapleall/maple_me/include/me_phase.h index 9756f14c43..cd205bac4f 100644 --- a/src/mapleall/maple_me/include/me_phase.h +++ b/src/mapleall/maple_me/include/me_phase.h @@ -48,7 +48,7 @@ class MeFuncPhase : public Phase { return prevPhaseName; } - void SetPreviousPhaseName(const std::string phaseName) { + void SetPreviousPhaseName(const std::string& phaseName) { prevPhaseName = phaseName; } diff --git a/src/mapleall/maple_me/src/me_emit.cpp b/src/mapleall/maple_me/src/me_emit.cpp index f45eaa77c7..6be456c4fc 100644 --- a/src/mapleall/maple_me/src/me_emit.cpp +++ b/src/mapleall/maple_me/src/me_emit.cpp @@ -20,54 +20,34 @@ #include "me_cfg.h" #include "constantfold.h" -static const std::set kHssaPhases{ - "irmapbuild", "hprop", "hssa", "hdse", "ssadevirt", "ea", "epre", - "lpre", "stmtpre", "rename2preg", "ti", "analyzerc", - "spre", "rclowering", "delegaterc", "condbasedrc", "condbasednpc", "may2dassign", "pregrename", - "bdcopt", "syncselect", "cfgopt", "placementrc", "symrename", "checkcastopt", "bblayout", -}; - namespace maple { // emit IR to specified file -AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr*) { +AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr*, ModuleResultMgr*) { static std::mutex mtx; ParallelGuard guard(mtx, ThreadEnv::IsMeParallel()); if (func->NumBBs() > 0) { - std::string passName = GetPreviousPhaseName(); - bool emitHssaOrAfter = kHssaPhases.find(std::string(passName)) != kHssaPhases.end(); - if (emitHssaOrAfter) { - CHECK_FATAL(func->GetIRMap() != nullptr, "Why not hssa?"); - // generate bblist after layout (bb physical position) - CHECK_FATAL(func->HasLaidOut(), "Check/Run bb layout phase."); - auto layoutBBs = func->GetLaidOutBBs(); - MIRFunction *mirFunction = func->GetMirFunc(); - mirFunction->ReleaseCodeMemory(); + CHECK_FATAL(func->GetIRMap() != nullptr, "Why not hssa?"); + // generate bblist after layout (bb physical position) + CHECK_FATAL(func->HasLaidOut(), "Check/Run bb layout phase."); + auto layoutBBs = func->GetLaidOutBBs(); + MIRFunction *mirFunction = func->GetMirFunc(); + mirFunction->ReleaseCodeMemory(); - mirFunction->SetMemPool(new ThreadLocalMemPool(memPoolCtrler, "IR from IRMap::Emit()")); - mirFunction->SetBody(mirFunction->GetCodeMempool()->New()); - // initialize is_deleted field to true; will reset when emitting Maple IR - for (size_t k = 1; k < mirFunction->GetSymTab()->GetSymbolTableSize(); ++k) { - MIRSymbol *sym = mirFunction->GetSymTab()->GetSymbolFromStIdx(k); - if (sym->GetSKind() == kStVar) { - sym->SetIsDeleted(); - } - } - for (BB *bb : layoutBBs) { - ASSERT(bb != nullptr, "Check bblayout phase"); - bb->EmitBB(*func->GetMeSSATab(), *mirFunction->GetBody(), false); - } - } else { - if(!func->HasLaidOut()) { - (void)m->GetAnalysisResult(MeFuncPhase_BBLAYOUT, func); - CHECK_FATAL(func->HasLaidOut(), "Check bb layout phase."); + mirFunction->SetMemPool(new ThreadLocalMemPool(memPoolCtrler, "IR from IRMap::Emit()")); + mirFunction->SetBody(mirFunction->GetCodeMempool()->New()); + // initialize is_deleted field to true; will reset when emitting Maple IR + for (size_t k = 1; k < mirFunction->GetSymTab()->GetSymbolTableSize(); ++k) { + MIRSymbol *sym = mirFunction->GetSymTab()->GetSymbolFromStIdx(k); + if (sym->GetSKind() == kStVar) { + sym->SetIsDeleted(); } - func->EmitBeforeHSSA((*(func->GetMirFunc())), func->GetLaidOutBBs()); } - if (!DEBUGFUNC(func)) { - // constantfolding does not update BB's stmtNodeList, which breaks MirCFG::DumpToFile() - ConstantFold cf(func->GetMIRModule()); - cf.Simplify(func->GetMirFunc()->GetBody()); + for (BB *bb : layoutBBs) { + ASSERT(bb != nullptr, "Check bblayout phase"); + bb->EmitBB(*func->GetMeSSATab(), *mirFunction->GetBody(), false); } + ConstantFold cf(func->GetMIRModule()); + cf.Simplify(func->GetMirFunc()->GetBody()); if (DEBUGFUNC(func)) { LogInfo::MapleLogger() << "\n==============after meemit =============" << '\n'; func->GetMirFunc()->Dump(); -- Gitee From f1a9f7077938a7bb2badbcdf78eadd838d795d82 Mon Sep 17 00:00:00 2001 From: linma Date: Thu, 13 May 2021 11:37:15 -0700 Subject: [PATCH 3/3] Me_Emit: check IR status according to IRMap --- src/mapleall/maple_me/src/me_emit.cpp | 51 ++++++++++++++++----------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/mapleall/maple_me/src/me_emit.cpp b/src/mapleall/maple_me/src/me_emit.cpp index 6be456c4fc..5191562f2e 100644 --- a/src/mapleall/maple_me/src/me_emit.cpp +++ b/src/mapleall/maple_me/src/me_emit.cpp @@ -21,33 +21,44 @@ #include "constantfold.h" namespace maple { + // emit IR to specified file -AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr*, ModuleResultMgr*) { +AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr*) { static std::mutex mtx; ParallelGuard guard(mtx, ThreadEnv::IsMeParallel()); if (func->NumBBs() > 0) { - CHECK_FATAL(func->GetIRMap() != nullptr, "Why not hssa?"); - // generate bblist after layout (bb physical position) - CHECK_FATAL(func->HasLaidOut(), "Check/Run bb layout phase."); - auto layoutBBs = func->GetLaidOutBBs(); - MIRFunction *mirFunction = func->GetMirFunc(); - mirFunction->ReleaseCodeMemory(); - - mirFunction->SetMemPool(new ThreadLocalMemPool(memPoolCtrler, "IR from IRMap::Emit()")); - mirFunction->SetBody(mirFunction->GetCodeMempool()->New()); - // initialize is_deleted field to true; will reset when emitting Maple IR - for (size_t k = 1; k < mirFunction->GetSymTab()->GetSymbolTableSize(); ++k) { - MIRSymbol *sym = mirFunction->GetSymTab()->GetSymbolFromStIdx(k); - if (sym->GetSKind() == kStVar) { - sym->SetIsDeleted(); + if(!func->HasLaidOut()) { + (void)m->GetAnalysisResult(MeFuncPhase_BBLAYOUT, func); + CHECK_FATAL(func->HasLaidOut(), "Check bb layout phase."); + } + // each phase need to keep either irmap or mirfunction is valid + if (func->GetIRMap()) { + // emit after hssa + auto layoutBBs = func->GetLaidOutBBs(); + MIRFunction *mirFunction = func->GetMirFunc(); + mirFunction->ReleaseCodeMemory(); + mirFunction->SetMemPool(new ThreadLocalMemPool(memPoolCtrler, "IR from IRMap::Emit()")); + mirFunction->SetBody(mirFunction->GetCodeMempool()->New()); + // initialize is_deleted field to true; will reset when emitting Maple IR + for (size_t k = 1; k < mirFunction->GetSymTab()->GetSymbolTableSize(); ++k) { + MIRSymbol *sym = mirFunction->GetSymTab()->GetSymbolFromStIdx(k); + if (sym->GetSKind() == kStVar) { + sym->SetIsDeleted(); + } + } + for (BB *bb : layoutBBs) { + ASSERT(bb != nullptr, "Check bblayout phase"); + bb->EmitBB(*func->GetMeSSATab(), *mirFunction->GetBody(), false); } + } else { + // emit from mir function body + func->EmitBeforeHSSA((*(func->GetMirFunc())), func->GetLaidOutBBs()); } - for (BB *bb : layoutBBs) { - ASSERT(bb != nullptr, "Check bblayout phase"); - bb->EmitBB(*func->GetMeSSATab(), *mirFunction->GetBody(), false); + if (!DEBUGFUNC(func)) { + // constantfolding does not update BB's stmtNodeList, which breaks MirCFG::DumpToFile() + ConstantFold cf(func->GetMIRModule()); + cf.Simplify(func->GetMirFunc()->GetBody()); } - ConstantFold cf(func->GetMIRModule()); - cf.Simplify(func->GetMirFunc()->GetBody()); if (DEBUGFUNC(func)) { LogInfo::MapleLogger() << "\n==============after meemit =============" << '\n'; func->GetMirFunc()->Dump(); -- Gitee