diff --git a/src/mapleall/maple_be/include/cg/cg_phase.h b/src/mapleall/maple_be/include/cg/cg_phase.h index 907e6627ddec7febaf5c48805254e4182ef1669b..4a8fe92d1b988fd330646547a00a668029d29cab 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 d902b02d273ebd05f7e15a37c1ee81fc9b485409..cd205bac4fca5771ab56df9d8115f981f3ebadcc 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 6be456c4fc424255351f674cf74db572bc7155ff..5191562f2ea13b9c20ea2acad83a1937ae39d3bb 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();