From 1215aca765ff269bb9f2b9994dbd07be141c2b33 Mon Sep 17 00:00:00 2001 From: linma Date: Sat, 10 Jul 2021 21:20:37 -0700 Subject: [PATCH 1/2] add lfoloopvec phase to mapleme and run with -O3 only implement widen instruction for a perfect loop like for (i = 0; i < 256; i++) { a[i] = b[i] + c[i] } --- src/mapleall/maple_driver/defs/phases.def | 2 +- src/mapleall/maple_ir/include/global_tables.h | 10 ++++++++++ src/mapleall/maple_me/BUILD.gn | 1 + src/mapleall/maple_me/include/lfo_pre_emit.h | 10 +++++++++- src/mapleall/maple_me/include/me_phases.def | 1 + src/mapleall/maple_me/src/lfo_pre_emit.cpp | 12 ++---------- src/mapleall/maple_me/src/me_function.cpp | 4 ++++ src/mapleall/maple_me/src/me_phase_manager.cpp | 1 + 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/mapleall/maple_driver/defs/phases.def b/src/mapleall/maple_driver/defs/phases.def index 32ce5fadb4..8f9ea2346b 100644 --- a/src/mapleall/maple_driver/defs/phases.def +++ b/src/mapleall/maple_driver/defs/phases.def @@ -36,7 +36,7 @@ ADD_PHASE("irmapbuild", CLANG && MeOption::optLevel >= 3) ADD_PHASE("ivcanon", CLANG && MeOption::optLevel >= 3) ADD_PHASE("hprop", CLANG && MeOption::optLevel >= 3) ADD_PHASE("hdse", CLANG && MeOption::optLevel >= 3) -ADD_PHASE("lfopreemit", CLANG && MeOption::optLevel >= 3) +ADD_PHASE("lfoloopvec", CLANG && MeOption::optLevel >= 3) ADD_PHASE("mecfgbuild", MeOption::optLevel >= 2 || JAVALANG) ADD_PHASE("cfgOpt", CLANG && MeOption::optLevel >= 2) ADD_PHASE("bypatheh", JAVALANG && MeOption::optLevel >= 2) diff --git a/src/mapleall/maple_ir/include/global_tables.h b/src/mapleall/maple_ir/include/global_tables.h index ad419cd59c..a41d388b74 100644 --- a/src/mapleall/maple_ir/include/global_tables.h +++ b/src/mapleall/maple_ir/include/global_tables.h @@ -315,6 +315,16 @@ class TypeTable { ASSERT(PTY_unknown < typeTable.size(), "array index out of range"); return typeTable.at(PTY_unknown); } + // vector type + MIRType *GetV4Int32() const { + ASSERT(PTY_v4i32 < typeTable.size(), "array index out of range"); + return typeTable.at(PTY_v4i32); + } + + MIRType *GetV2Int32() const { + ASSERT(PTY_v2i32 < typeTable.size(), "array index out of range"); + return typeTable.at(PTY_v2i32); + } // Get or Create derived types. MIRType *GetOrCreatePointerType(const TyIdx &pointedTyIdx, PrimType primType = PTY_ptr, diff --git a/src/mapleall/maple_me/BUILD.gn b/src/mapleall/maple_me/BUILD.gn index 16ab6c8ddf..f9111feb6b 100755 --- a/src/mapleall/maple_me/BUILD.gn +++ b/src/mapleall/maple_me/BUILD.gn @@ -96,6 +96,7 @@ src_libmplme = [ "src/lfo_inject_iv.cpp", "src/lfo_pre_emit.cpp", "src/lfo_iv_canon.cpp", + "src/lfo_loop_vec.cpp", "src/me_value_range_prop.cpp", "src/cfg_opt.cpp", ] diff --git a/src/mapleall/maple_me/include/lfo_pre_emit.h b/src/mapleall/maple_me/include/lfo_pre_emit.h index 0ab6ff76d0..6eaccf3392 100644 --- a/src/mapleall/maple_me/include/lfo_pre_emit.h +++ b/src/mapleall/maple_me/include/lfo_pre_emit.h @@ -15,6 +15,7 @@ #ifndef MAPLE_ME_INCLUDE_LFO_PRE_EMIT_H #define MAPLE_ME_INCLUDE_LFO_PRE_EMIT_H +#include "mir_nodes.h" #include "me_irmap.h" #include "me_phase.h" @@ -28,8 +29,9 @@ class LfoPreEmitter : public AnalysisResult { MapleAllocator *codeMPAlloc; MemPool *lfoMP; MapleAllocator lfoMPAlloc; - MapleMap lfoStmtParts; // map lfoinfo for StmtNode, key is stmtID + MapleMap lfoStmtParts; // map lfoinfo for StmtNode, key is stmtID MapleMap lfoExprParts; // map lfoinfor for exprNode, key is mirnode + MapleVector lfoDoloops; // store doloop node MeCFG *cfg; public: @@ -43,6 +45,7 @@ class LfoPreEmitter : public AnalysisResult { lfoMPAlloc(lfoMP), lfoStmtParts(lfoMPAlloc.Adapter()), lfoExprParts(lfoMPAlloc.Adapter()), + lfoDoloops(lfoMPAlloc.Adapter()), cfg(f->meFunc->GetCfg()) {} private: @@ -93,6 +96,11 @@ class LfoPreEmitter : public AnalysisResult { LfoPart *lfopart = lfoStmtParts[stmtID]; return lfopart->mestmt; } + MIRFunction *GetMirFunction() { return mirFunc; } + MemPool *GetCodeMP() { return codeMP; } + MapleMap *GetLfoStmtMap() { return &lfoStmtParts; } + MapleMap *GetLfoExprMap() { return &lfoExprParts; } + MapleVector *GetLfoDoLoops() { return &lfoDoloops; } }; /* emit ir to specified file */ diff --git a/src/mapleall/maple_me/include/me_phases.def b/src/mapleall/maple_me/include/me_phases.def index 69132caa31..0b2fc274cb 100644 --- a/src/mapleall/maple_me/include/me_phases.def +++ b/src/mapleall/maple_me/include/me_phases.def @@ -55,6 +55,7 @@ FUNCAPHASE(MeFuncPhase_MECFG, MeDoMeCfg) FUNCTPHASE(MeFuncPhase_LFOINJECTIV, DoLfoInjectIV) FUNCAPHASE(MeFuncPhase_LFOPREEMIT, DoLfoPreEmission) FUNCTPHASE(MeFuncPhase_LFOIVCANON, DoLfoIVCanon) +FUNCTPHASE(MeFuncPhase_LFOLOOPVEC, DoLfoLoopVectorization) FUNCAPHASE(MeFuncPhase_MECFGOPT, DoCfgOpt) #if MIR_JAVA FUNCTPHASE(MeFuncPhase_SYNCSELECT, MeDoSyncSelect) diff --git a/src/mapleall/maple_me/src/lfo_pre_emit.cpp b/src/mapleall/maple_me/src/lfo_pre_emit.cpp index 2ab7b4953d..dc02140ef3 100644 --- a/src/mapleall/maple_me/src/lfo_pre_emit.cpp +++ b/src/mapleall/maple_me/src/lfo_pre_emit.cpp @@ -16,7 +16,6 @@ #include "me_irmap.h" #include "lfo_function.h" #include "lfo_pre_emit.h" -#include "mir_lower.h" #include "constantfold.h" namespace maple { @@ -626,6 +625,7 @@ uint32 LfoPreEmitter::Raise2LfoWhile(uint32 curj, BlockNode *curblk) { BlockNode *Dobody = nullptr; if (whileInfo->canConvertDoloop) { // emit doloop DoloopNode *doloopnode = EmitLfoDoloop(curbb, curblk, whileInfo); + lfoDoloops.push_back(doloopnode); ++curj; Dobody = static_cast(doloopnode->GetDoBody()); } else { // emit while loop @@ -781,8 +781,7 @@ AnalysisResult *DoLfoPreEmission::Run(MeFunction *func, MeFuncResultMgr *m, Modu i = emitter->EmitLfoBB(i, curblk); } // invalid cfg information only in lfo phase - // m->InvalidAnalysisResult(MeFuncPhase_MECFG, func); - m->InvalidAllResults(); + m->InvalidAnalysisResult(MeFuncPhase_MECFG, func); func->SetMeSSATab(nullptr); func->SetIRMap(nullptr); func->SetLfo(false); @@ -795,13 +794,6 @@ AnalysisResult *DoLfoPreEmission::Run(MeFunction *func, MeFuncResultMgr *m, Modu mirfunction->Dump(false); } -#if 1 // use this only if directly feeding to mainopt - MIRLower mirlowerer(func->GetMIRModule(), mirfunction); - mirlowerer.SetLowerME(); - mirlowerer.SetLowerExpandArray(); - mirlowerer.LowerFunc(*mirfunction); -#endif - return emitter; } } // namespace maple diff --git a/src/mapleall/maple_me/src/me_function.cpp b/src/mapleall/maple_me/src/me_function.cpp index 7b88f4b65a..1d936f7b5f 100644 --- a/src/mapleall/maple_me/src/me_function.cpp +++ b/src/mapleall/maple_me/src/me_function.cpp @@ -69,6 +69,10 @@ void MeFunction::DumpFunction() const { } void MeFunction::DumpFunctionNoSSA() const { + if (theCFG == nullptr) { + mirFunc->Dump(false); + return; + } auto eIt = theCFG->valid_end(); for (auto bIt = theCFG->valid_begin(); bIt != eIt; ++bIt) { auto *bb = *bIt; diff --git a/src/mapleall/maple_me/src/me_phase_manager.cpp b/src/mapleall/maple_me/src/me_phase_manager.cpp index 4fb95a025a..b868173f7b 100644 --- a/src/mapleall/maple_me/src/me_phase_manager.cpp +++ b/src/mapleall/maple_me/src/me_phase_manager.cpp @@ -64,6 +64,7 @@ #include "me_rc_lowering.h" #include "gen_check_cast.h" #include "me_fsaa.h" +#include "lfo_loop_vec.h" #if MIR_JAVA #include "sync_select.h" #endif // MIR_JAVA -- Gitee From c02d1dff93b366b17a2dbd37ffd89e4b93e2b49e Mon Sep 17 00:00:00 2001 From: linma Date: Sun, 11 Jul 2021 21:15:30 -0700 Subject: [PATCH 2/2] Revert "add lfoloopvec phase to mapleme and run with -O3" This reverts commit 1215aca765ff269bb9f2b9994dbd07be141c2b33. --- src/mapleall/maple_driver/defs/phases.def | 2 +- src/mapleall/maple_ir/include/global_tables.h | 10 ---------- src/mapleall/maple_me/BUILD.gn | 1 - src/mapleall/maple_me/include/lfo_pre_emit.h | 10 +--------- src/mapleall/maple_me/include/me_phases.def | 1 - src/mapleall/maple_me/src/lfo_pre_emit.cpp | 12 ++++++++++-- src/mapleall/maple_me/src/me_function.cpp | 4 ---- src/mapleall/maple_me/src/me_phase_manager.cpp | 1 - 8 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/mapleall/maple_driver/defs/phases.def b/src/mapleall/maple_driver/defs/phases.def index 8f9ea2346b..32ce5fadb4 100644 --- a/src/mapleall/maple_driver/defs/phases.def +++ b/src/mapleall/maple_driver/defs/phases.def @@ -36,7 +36,7 @@ ADD_PHASE("irmapbuild", CLANG && MeOption::optLevel >= 3) ADD_PHASE("ivcanon", CLANG && MeOption::optLevel >= 3) ADD_PHASE("hprop", CLANG && MeOption::optLevel >= 3) ADD_PHASE("hdse", CLANG && MeOption::optLevel >= 3) -ADD_PHASE("lfoloopvec", CLANG && MeOption::optLevel >= 3) +ADD_PHASE("lfopreemit", CLANG && MeOption::optLevel >= 3) ADD_PHASE("mecfgbuild", MeOption::optLevel >= 2 || JAVALANG) ADD_PHASE("cfgOpt", CLANG && MeOption::optLevel >= 2) ADD_PHASE("bypatheh", JAVALANG && MeOption::optLevel >= 2) diff --git a/src/mapleall/maple_ir/include/global_tables.h b/src/mapleall/maple_ir/include/global_tables.h index a41d388b74..ad419cd59c 100644 --- a/src/mapleall/maple_ir/include/global_tables.h +++ b/src/mapleall/maple_ir/include/global_tables.h @@ -315,16 +315,6 @@ class TypeTable { ASSERT(PTY_unknown < typeTable.size(), "array index out of range"); return typeTable.at(PTY_unknown); } - // vector type - MIRType *GetV4Int32() const { - ASSERT(PTY_v4i32 < typeTable.size(), "array index out of range"); - return typeTable.at(PTY_v4i32); - } - - MIRType *GetV2Int32() const { - ASSERT(PTY_v2i32 < typeTable.size(), "array index out of range"); - return typeTable.at(PTY_v2i32); - } // Get or Create derived types. MIRType *GetOrCreatePointerType(const TyIdx &pointedTyIdx, PrimType primType = PTY_ptr, diff --git a/src/mapleall/maple_me/BUILD.gn b/src/mapleall/maple_me/BUILD.gn index f9111feb6b..16ab6c8ddf 100755 --- a/src/mapleall/maple_me/BUILD.gn +++ b/src/mapleall/maple_me/BUILD.gn @@ -96,7 +96,6 @@ src_libmplme = [ "src/lfo_inject_iv.cpp", "src/lfo_pre_emit.cpp", "src/lfo_iv_canon.cpp", - "src/lfo_loop_vec.cpp", "src/me_value_range_prop.cpp", "src/cfg_opt.cpp", ] diff --git a/src/mapleall/maple_me/include/lfo_pre_emit.h b/src/mapleall/maple_me/include/lfo_pre_emit.h index 6eaccf3392..0ab6ff76d0 100644 --- a/src/mapleall/maple_me/include/lfo_pre_emit.h +++ b/src/mapleall/maple_me/include/lfo_pre_emit.h @@ -15,7 +15,6 @@ #ifndef MAPLE_ME_INCLUDE_LFO_PRE_EMIT_H #define MAPLE_ME_INCLUDE_LFO_PRE_EMIT_H -#include "mir_nodes.h" #include "me_irmap.h" #include "me_phase.h" @@ -29,9 +28,8 @@ class LfoPreEmitter : public AnalysisResult { MapleAllocator *codeMPAlloc; MemPool *lfoMP; MapleAllocator lfoMPAlloc; - MapleMap lfoStmtParts; // map lfoinfo for StmtNode, key is stmtID + MapleMap lfoStmtParts; // map lfoinfo for StmtNode, key is stmtID MapleMap lfoExprParts; // map lfoinfor for exprNode, key is mirnode - MapleVector lfoDoloops; // store doloop node MeCFG *cfg; public: @@ -45,7 +43,6 @@ class LfoPreEmitter : public AnalysisResult { lfoMPAlloc(lfoMP), lfoStmtParts(lfoMPAlloc.Adapter()), lfoExprParts(lfoMPAlloc.Adapter()), - lfoDoloops(lfoMPAlloc.Adapter()), cfg(f->meFunc->GetCfg()) {} private: @@ -96,11 +93,6 @@ class LfoPreEmitter : public AnalysisResult { LfoPart *lfopart = lfoStmtParts[stmtID]; return lfopart->mestmt; } - MIRFunction *GetMirFunction() { return mirFunc; } - MemPool *GetCodeMP() { return codeMP; } - MapleMap *GetLfoStmtMap() { return &lfoStmtParts; } - MapleMap *GetLfoExprMap() { return &lfoExprParts; } - MapleVector *GetLfoDoLoops() { return &lfoDoloops; } }; /* emit ir to specified file */ diff --git a/src/mapleall/maple_me/include/me_phases.def b/src/mapleall/maple_me/include/me_phases.def index 0b2fc274cb..69132caa31 100644 --- a/src/mapleall/maple_me/include/me_phases.def +++ b/src/mapleall/maple_me/include/me_phases.def @@ -55,7 +55,6 @@ FUNCAPHASE(MeFuncPhase_MECFG, MeDoMeCfg) FUNCTPHASE(MeFuncPhase_LFOINJECTIV, DoLfoInjectIV) FUNCAPHASE(MeFuncPhase_LFOPREEMIT, DoLfoPreEmission) FUNCTPHASE(MeFuncPhase_LFOIVCANON, DoLfoIVCanon) -FUNCTPHASE(MeFuncPhase_LFOLOOPVEC, DoLfoLoopVectorization) FUNCAPHASE(MeFuncPhase_MECFGOPT, DoCfgOpt) #if MIR_JAVA FUNCTPHASE(MeFuncPhase_SYNCSELECT, MeDoSyncSelect) diff --git a/src/mapleall/maple_me/src/lfo_pre_emit.cpp b/src/mapleall/maple_me/src/lfo_pre_emit.cpp index dc02140ef3..2ab7b4953d 100644 --- a/src/mapleall/maple_me/src/lfo_pre_emit.cpp +++ b/src/mapleall/maple_me/src/lfo_pre_emit.cpp @@ -16,6 +16,7 @@ #include "me_irmap.h" #include "lfo_function.h" #include "lfo_pre_emit.h" +#include "mir_lower.h" #include "constantfold.h" namespace maple { @@ -625,7 +626,6 @@ uint32 LfoPreEmitter::Raise2LfoWhile(uint32 curj, BlockNode *curblk) { BlockNode *Dobody = nullptr; if (whileInfo->canConvertDoloop) { // emit doloop DoloopNode *doloopnode = EmitLfoDoloop(curbb, curblk, whileInfo); - lfoDoloops.push_back(doloopnode); ++curj; Dobody = static_cast(doloopnode->GetDoBody()); } else { // emit while loop @@ -781,7 +781,8 @@ AnalysisResult *DoLfoPreEmission::Run(MeFunction *func, MeFuncResultMgr *m, Modu i = emitter->EmitLfoBB(i, curblk); } // invalid cfg information only in lfo phase - m->InvalidAnalysisResult(MeFuncPhase_MECFG, func); + // m->InvalidAnalysisResult(MeFuncPhase_MECFG, func); + m->InvalidAllResults(); func->SetMeSSATab(nullptr); func->SetIRMap(nullptr); func->SetLfo(false); @@ -794,6 +795,13 @@ AnalysisResult *DoLfoPreEmission::Run(MeFunction *func, MeFuncResultMgr *m, Modu mirfunction->Dump(false); } +#if 1 // use this only if directly feeding to mainopt + MIRLower mirlowerer(func->GetMIRModule(), mirfunction); + mirlowerer.SetLowerME(); + mirlowerer.SetLowerExpandArray(); + mirlowerer.LowerFunc(*mirfunction); +#endif + return emitter; } } // namespace maple diff --git a/src/mapleall/maple_me/src/me_function.cpp b/src/mapleall/maple_me/src/me_function.cpp index 1d936f7b5f..7b88f4b65a 100644 --- a/src/mapleall/maple_me/src/me_function.cpp +++ b/src/mapleall/maple_me/src/me_function.cpp @@ -69,10 +69,6 @@ void MeFunction::DumpFunction() const { } void MeFunction::DumpFunctionNoSSA() const { - if (theCFG == nullptr) { - mirFunc->Dump(false); - return; - } auto eIt = theCFG->valid_end(); for (auto bIt = theCFG->valid_begin(); bIt != eIt; ++bIt) { auto *bb = *bIt; diff --git a/src/mapleall/maple_me/src/me_phase_manager.cpp b/src/mapleall/maple_me/src/me_phase_manager.cpp index b868173f7b..4fb95a025a 100644 --- a/src/mapleall/maple_me/src/me_phase_manager.cpp +++ b/src/mapleall/maple_me/src/me_phase_manager.cpp @@ -64,7 +64,6 @@ #include "me_rc_lowering.h" #include "gen_check_cast.h" #include "me_fsaa.h" -#include "lfo_loop_vec.h" #if MIR_JAVA #include "sync_select.h" #endif // MIR_JAVA -- Gitee