From 3ac395a11ec3eea94ad1e67c01aacf8ab4aca35e Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Sat, 7 Aug 2021 08:46:29 -0700 Subject: [PATCH 1/5] mplme supports OP_asm by modelling it like call statements copy propagation is disabled for operands of OP_asm. pregrename cannot be performed in functions containing inline asm. --- src/mapleall/maple_ir/include/mir_nodes.h | 4 +++ src/mapleall/maple_ir/include/opcodes.def | 2 +- src/mapleall/maple_ir/include/opcodes.h | 1 + src/mapleall/maple_me/include/irmap_build.h | 1 + src/mapleall/maple_me/include/me_ir.h | 34 +++++++++++++++++++ src/mapleall/maple_me/src/alias_class.cpp | 1 + src/mapleall/maple_me/src/copy_prop.cpp | 1 + .../src/demand_driven_alias_analysis.cpp | 3 +- src/mapleall/maple_me/src/ipa_side_effect.cpp | 3 +- src/mapleall/maple_me/src/irmap_build.cpp | 22 ++++++++++++ src/mapleall/maple_me/src/irmap_emit.cpp | 28 +++++++++++++++ src/mapleall/maple_me/src/lfo_dep_test.cpp | 1 + src/mapleall/maple_me/src/lfo_pre_emit.cpp | 25 +++++++++----- src/mapleall/maple_me/src/me_cfg.cpp | 1 + .../maple_me/src/me_phase_manager.cpp | 4 --- src/mapleall/maple_me/src/me_rename2preg.cpp | 2 +- src/mapleall/maple_me/src/me_stmt_pre.cpp | 1 + src/mapleall/maple_me/src/preg_renamer.cpp | 6 ++++ src/mapleall/maple_me/src/prop.cpp | 1 + src/mapleall/maple_me/src/ssa_devirtual.cpp | 1 + src/mapleall/maple_me/src/ssa_pre.cpp | 3 +- 21 files changed, 127 insertions(+), 18 deletions(-) diff --git a/src/mapleall/maple_ir/include/mir_nodes.h b/src/mapleall/maple_ir/include/mir_nodes.h index f39856f412..620b31c36d 100644 --- a/src/mapleall/maple_ir/include/mir_nodes.h +++ b/src/mapleall/maple_ir/include/mir_nodes.h @@ -3198,6 +3198,10 @@ class AsmNode : public NaryStmtNode { return (qualifiers & (1U << static_cast(x))) != 0; } + CallReturnVector *GetCallReturnVector() override { + return &asmOutputs; + } + void DumpOutputs(int32 indent, std::string &uStr) const; void DumpInputOperands(int32 indent, std::string &uStr) const; void Dump(int32 indent) const override; diff --git a/src/mapleall/maple_ir/include/opcodes.def b/src/mapleall/maple_ir/include/opcodes.def index 952f614db0..dcb8340b41 100644 --- a/src/mapleall/maple_ir/include/opcodes.def +++ b/src/mapleall/maple_ir/include/opcodes.def @@ -200,4 +200,4 @@ // leaf node OPCODE(addroffpc, AddroffPCNode, 0, 0) OPCODE(igoto, UnaryStmtNode, OPCODEISSTMT, 0) - OPCODE(asm, AsmNode, OPCODEISSTMT, 0) + OPCODE(asm, AsmNode, OPCODEISSTMT | OPCODEHASSSAUSE | OPCODEHASSSADEF | OPCODEISCALLASSIGNED, 0) diff --git a/src/mapleall/maple_ir/include/opcodes.h b/src/mapleall/maple_ir/include/opcodes.h index e3ea91037c..330857d285 100644 --- a/src/mapleall/maple_ir/include/opcodes.h +++ b/src/mapleall/maple_ir/include/opcodes.h @@ -99,6 +99,7 @@ constexpr bool IsStmtMustRequire(Opcode opcode) { case OP_xintrinsiccallassigned: case OP_intrinsiccallwithtype: case OP_intrinsiccallwithtypeassigned: + case OP_asm: case OP_syncenter: case OP_syncexit: case OP_membaracquire: diff --git a/src/mapleall/maple_me/include/irmap_build.h b/src/mapleall/maple_me/include/irmap_build.h index f688380541..be4e09a086 100644 --- a/src/mapleall/maple_me/include/irmap_build.h +++ b/src/mapleall/maple_me/include/irmap_build.h @@ -89,6 +89,7 @@ class IRMapBuild { MeStmt *BuildGosubMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart); MeStmt *BuildThrowMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart); MeStmt *BuildSyncMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart); + MeStmt *BuildAsmMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart); MeStmt *BuildMeStmt(StmtNode&); static void InitMeStmtFactory(); diff --git a/src/mapleall/maple_me/include/me_ir.h b/src/mapleall/maple_me/include/me_ir.h index 741da2eefa..57dbcce160 100644 --- a/src/mapleall/maple_me/include/me_ir.h +++ b/src/mapleall/maple_me/include/me_ir.h @@ -2337,6 +2337,40 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign PrimType retPType = kPtyInvalid; }; +class AsmMeStmt : public NaryMeStmt, public MuChiMePart, public AssignedPart { + public: + AsmMeStmt(MapleAllocator *alloc, const StmtNode *stt) + : NaryMeStmt(alloc, stt), + MuChiMePart(alloc), + AssignedPart(alloc), + asmString(static_cast(stt)->asmString), + inputConstraints(alloc->Adapter()), + outputConstraints(alloc->Adapter()), + clobberList(alloc->Adapter()), + gotoLabels(alloc->Adapter()), + qualifiers(static_cast(stt)->qualifiers) { + inputConstraints = static_cast(stt)->inputConstraints; + outputConstraints = static_cast(stt)->outputConstraints; + clobberList = static_cast(stt)->clobberList; + gotoLabels = static_cast(stt)->gotoLabels; + } + virtual ~AsmMeStmt() = default; + MapleMap *GetChiList() { + return &chiList; + } + MapleVector *GetMustDefList() { + return &mustDefList; + } + StmtNode &EmitStmt(SSATab &ssaTab); + public: + MapleString asmString; + MapleVector inputConstraints; // length is numOpnds + MapleVector outputConstraints; // length is returnValues.size() + MapleVector clobberList; + MapleVector gotoLabels; + uint32 qualifiers; +}; + class RetMeStmt : public NaryMeStmt { public: RetMeStmt(MapleAllocator *alloc, const StmtNode *stt) diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index eac9898160..750b1a7e8f 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -741,6 +741,7 @@ void AliasClass::ApplyUnionForCopies(StmtNode &stmt) { } break; } + case OP_asm: case OP_icall: case OP_icallassigned: { for (uint32 i = 0; i < stmt.NumOpnds(); ++i) { diff --git a/src/mapleall/maple_me/src/copy_prop.cpp b/src/mapleall/maple_me/src/copy_prop.cpp index 49192243fb..45797cf921 100644 --- a/src/mapleall/maple_me/src/copy_prop.cpp +++ b/src/mapleall/maple_me/src/copy_prop.cpp @@ -243,6 +243,7 @@ void CopyProp::TraversalMeStmt(MeStmt &meStmt) { PropUpdateDef(*assignStmt.GetLHS()); break; } + case OP_asm: break; default:{ for (size_t i = 0; i != meStmt.NumMeStmtOpnds(); ++i) { auto opnd = meStmt.GetOpnd(i); diff --git a/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp b/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp index 3a3c0227ce..27adb916d3 100644 --- a/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp +++ b/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp @@ -586,6 +586,7 @@ void PEGBuilder::BuildPEGNodeInStmt(const StmtNode *stmt) { } return; } + case OP_asm: case OP_call: case OP_callassigned: { BuildPEGNodeInDirectCall(static_cast(stmt)); @@ -1046,4 +1047,4 @@ bool DemandDrivenAliasAnalysis::MayAlias(OriginalSt *ostA, OriginalSt *ostB) { } return aliasAccordingDDAA; } -} // namespace maple \ No newline at end of file +} // namespace maple diff --git a/src/mapleall/maple_me/src/ipa_side_effect.cpp b/src/mapleall/maple_me/src/ipa_side_effect.cpp index a76d0479bd..5f9a6c2228 100644 --- a/src/mapleall/maple_me/src/ipa_side_effect.cpp +++ b/src/mapleall/maple_me/src/ipa_side_effect.cpp @@ -933,7 +933,8 @@ bool IpaSideEffect::UpdateSideEffectWithStmt(MeStmt &meStmt, case OP_customcallassigned: case OP_polymorphiccallassigned: case OP_icallassigned: - case OP_superclasscallassigned: { + case OP_superclasscallassigned: + case OP_asm: { hasPrivateDef = hasThrException = true; SetHasDef(); for (size_t i = 0; i < meStmt.NumMeStmtOpnds(); ++i) { diff --git a/src/mapleall/maple_me/src/irmap_build.cpp b/src/mapleall/maple_me/src/irmap_build.cpp index c3aa3bc45d..5b58c3cd6d 100644 --- a/src/mapleall/maple_me/src/irmap_build.cpp +++ b/src/mapleall/maple_me/src/irmap_build.cpp @@ -724,6 +724,27 @@ MeStmt *IRMapBuild::BuildSyncMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { return naryStmt; } +MeStmt *IRMapBuild::BuildAsmMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { + AsmNode *asmNode = &static_cast(stmt); + AsmMeStmt *asmMeStmt = irMap->NewInPool(asmNode); + for (size_t i = 0; i < asmNode->NumOpnds(); ++i) { + asmMeStmt->PushBackOpnd(BuildExpr(*asmNode->Opnd(i), true, true)); + } + BuildMuList(ssaPart.GetMayUseNodes(), *(asmMeStmt->GetMuList())); + BuildMustDefList(*asmMeStmt, ssaPart.GetMustDefNodes(), *(asmMeStmt->GetMustDefList())); + BuildChiList(*asmMeStmt, ssaPart.GetMayDefNodes(), *(asmMeStmt->GetChiList())); + asmMeStmt->asmString = asmNode->asmString; + asmMeStmt->inputConstraints = asmNode->inputConstraints; + asmMeStmt->outputConstraints = asmNode->outputConstraints; + asmMeStmt->clobberList = asmNode->clobberList; + asmMeStmt->gotoLabels = asmNode->gotoLabels; + if (propagater) { + propagater->PropUpdateChiListDef(*asmMeStmt->GetChiList()); + propagater->PropUpdateMustDefList(asmMeStmt); + } + return asmMeStmt; +} + MeStmt *IRMapBuild::BuildMeStmt(StmtNode &stmt) { AccessSSANodes *ssaPart = ssaTab.GetStmtsSSAPart().SSAPartOf(stmt); if (ssaPart == nullptr) { @@ -769,6 +790,7 @@ void IRMapBuild::InitMeStmtFactory() { RegisterFactoryFunction(OP_throw, &IRMapBuild::BuildThrowMeStmt); RegisterFactoryFunction(OP_syncenter, &IRMapBuild::BuildSyncMeStmt); RegisterFactoryFunction(OP_syncexit, &IRMapBuild::BuildSyncMeStmt); + RegisterFactoryFunction(OP_asm, &IRMapBuild::BuildAsmMeStmt); } // recursively invoke itself in a pre-order traversal of the dominator tree of diff --git a/src/mapleall/maple_me/src/irmap_emit.cpp b/src/mapleall/maple_me/src/irmap_emit.cpp index da22f1d8b0..57c09ff501 100644 --- a/src/mapleall/maple_me/src/irmap_emit.cpp +++ b/src/mapleall/maple_me/src/irmap_emit.cpp @@ -491,6 +491,34 @@ StmtNode &IntrinsiccallMeStmt::EmitStmt(SSATab &ssaTab) { return *callNode; } +StmtNode &AsmMeStmt::EmitStmt(SSATab &ssaTab) { + AsmNode *asmNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(&ssaTab.GetModule().GetCurFuncCodeMPAllocator()); + asmNode->GetNopnd().resize(NumMeStmtOpnds()); + for (size_t i = 0; i < NumMeStmtOpnds(); ++i) { + asmNode->SetOpnd(&GetOpnd(i)->EmitExpr(ssaTab), i); + } + asmNode->SetNumOpnds(asmNode->GetNopndSize()); + asmNode->SetSrcPos(GetSrcPosition()); + EmitCallReturnVector(*asmNode->GetCallReturnVector()); + for (size_t j = 0; j < asmNode->GetCallReturnVector()->size(); ++j) { + CallReturnPair retPair = (*asmNode->GetCallReturnVector())[j]; + if (!retPair.second.IsReg()) { + StIdx stIdx = retPair.first; + if (stIdx.Islocal()) { + MIRSymbolTable *symbolTab = ssaTab.GetModule().CurFunction()->GetSymTab(); + MIRSymbol *symbol = symbolTab->GetSymbolFromStIdx(stIdx.Idx()); + symbol->ResetIsDeleted(); + } + } + } + asmNode->asmString = asmString; + asmNode->inputConstraints = inputConstraints; + asmNode->outputConstraints = outputConstraints; + asmNode->clobberList = clobberList; + asmNode->gotoLabels = gotoLabels; + return *asmNode; +} + StmtNode &NaryMeStmt::EmitStmt(SSATab &ssaTab) { auto *naryStmt = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule(), Opcode(GetOp())); diff --git a/src/mapleall/maple_me/src/lfo_dep_test.cpp b/src/mapleall/maple_me/src/lfo_dep_test.cpp index 00322aac6a..08e60ef19c 100644 --- a/src/mapleall/maple_me/src/lfo_dep_test.cpp +++ b/src/mapleall/maple_me/src/lfo_dep_test.cpp @@ -68,6 +68,7 @@ void LfoDepInfo::CreateDoloopInfo(BlockNode *block, DoloopInfo *parent) { case OP_icallassigned: case OP_return: case OP_throw: + case OP_asm: if (parent) { parent->hasOtherCtrlFlow = true; } diff --git a/src/mapleall/maple_me/src/lfo_pre_emit.cpp b/src/mapleall/maple_me/src/lfo_pre_emit.cpp index a7899e2fb6..192339a16c 100644 --- a/src/mapleall/maple_me/src/lfo_pre_emit.cpp +++ b/src/mapleall/maple_me/src/lfo_pre_emit.cpp @@ -437,19 +437,26 @@ StmtNode* LfoPreEmitter::EmitLfoStmt(MeStmt *mestmt, BaseNode *parent) { callnode->SetSrcPos(mestmt->GetSrcPosition()); if (kOpcodeInfo.IsCallAssigned(mestmt->GetOp())) { mestmt->EmitCallReturnVector(callnode->GetReturnVec()); - for (uint32 j = 0; j < callnode->GetReturnVec().size(); j++) { - CallReturnPair retpair = callnode->GetReturnVec()[j]; - if (!retpair.second.IsReg()) { - StIdx stIdx = retpair.first; - if (stIdx.Islocal()) { - - } - } - } } lfoStmtParts[callnode->GetStmtID()] = lfopart; return callnode; } + case OP_asm: { + AsmMeStmt *asmMeStmt = static_cast(mestmt); + AsmNode *asmNode = codeMP->New(codeMPAlloc); + for (size_t i = 0; i < asmMeStmt->NumMeStmtOpnds(); ++i) { + asmNode->GetNopnd().push_back(EmitLfoExpr(asmMeStmt->GetOpnd(i), asmNode)); + } + asmNode->SetNumOpnds(asmNode->GetNopndSize()); + asmNode->SetSrcPos(mestmt->GetSrcPosition()); + mestmt->EmitCallReturnVector(*asmNode->GetCallReturnVector()); + asmNode->asmString = asmMeStmt->asmString; + asmNode->inputConstraints = asmMeStmt->inputConstraints; + asmNode->outputConstraints = asmMeStmt->outputConstraints; + asmNode->clobberList = asmMeStmt->clobberList; + asmNode->gotoLabels = asmMeStmt->gotoLabels; + return asmNode; + } case OP_jscatch: case OP_finally: case OP_endtry: diff --git a/src/mapleall/maple_me/src/me_cfg.cpp b/src/mapleall/maple_me/src/me_cfg.cpp index ae602ae65e..a98a5b1336 100644 --- a/src/mapleall/maple_me/src/me_cfg.cpp +++ b/src/mapleall/maple_me/src/me_cfg.cpp @@ -371,6 +371,7 @@ bool MeCFG::FindUse(const StmtNode &stmt, StIdx stIdx) const { case OP_intrinsiccallassigned: case OP_xintrinsiccallassigned: case OP_intrinsiccallwithtypeassigned: + case OP_asm: case OP_syncenter: case OP_syncexit: { for (size_t i = 0; i < stmt.NumOpnds(); ++i) { diff --git a/src/mapleall/maple_me/src/me_phase_manager.cpp b/src/mapleall/maple_me/src/me_phase_manager.cpp index d8bd3e237d..433617bed7 100644 --- a/src/mapleall/maple_me/src/me_phase_manager.cpp +++ b/src/mapleall/maple_me/src/me_phase_manager.cpp @@ -215,10 +215,6 @@ void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::s LogInfo::MapleLogger() << "Function < " << mirFunc->GetName() << " not optimized because it has setjmp\n"; return; } - if (mirFunc->HasAsm()) { - LogInfo::MapleLogger() << "Function < " << mirFunc->GetName() << " not optimized because it has inline asm\n"; - return; - } MPLTimer runPhasetimer; MPLTimer funcPrepareTimer; MPLTimer iteratorTimer; diff --git a/src/mapleall/maple_me/src/me_rename2preg.cpp b/src/mapleall/maple_me/src/me_rename2preg.cpp index 79ceb99144..98a4586e1f 100644 --- a/src/mapleall/maple_me/src/me_rename2preg.cpp +++ b/src/mapleall/maple_me/src/me_rename2preg.cpp @@ -134,7 +134,6 @@ void SSARename2Preg::Rename2PregCallReturn(MapleVector &mustdefli if (mustdeflist.empty()) { return; } - CHECK_FATAL(mustdeflist.size() == 1, "NYI"); { MustDefMeNode &mustdefmenode = mustdeflist.front(); MeExpr *melhs = mustdefmenode.GetLHS(); @@ -277,6 +276,7 @@ void SSARename2Preg::Rename2PregStmt(MeStmt *stmt) { Rename2PregLeafLHS(stmt, static_cast(stmt->GetVarLHS())); break; } + case OP_asm: case OP_callassigned: case OP_virtualcallassigned: case OP_virtualicallassigned: diff --git a/src/mapleall/maple_me/src/me_stmt_pre.cpp b/src/mapleall/maple_me/src/me_stmt_pre.cpp index 17ecd3f5c2..db63e57f7e 100644 --- a/src/mapleall/maple_me/src/me_stmt_pre.cpp +++ b/src/mapleall/maple_me/src/me_stmt_pre.cpp @@ -900,6 +900,7 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { case OP_assertlt: case OP_assertge: break; + case OP_asm: case OP_call: case OP_virtualcall: case OP_virtualicall: diff --git a/src/mapleall/maple_me/src/preg_renamer.cpp b/src/mapleall/maple_me/src/preg_renamer.cpp index d70b766ff1..aa3d9b745a 100644 --- a/src/mapleall/maple_me/src/preg_renamer.cpp +++ b/src/mapleall/maple_me/src/preg_renamer.cpp @@ -113,6 +113,12 @@ void PregRenamer::RunSelf() { } AnalysisResult *MeDoPregRename::Run(MeFunction *func, MeFuncResultMgr *frm, ModuleResultMgr *mrm) { + if (func->GetMirFunc()->HasAsm()) { + if (!MeOption::quiet) { + LogInfo::MapleLogger() << " == " << PhaseName() << " skipped due to inline asm\n"; + } + return nullptr; + } MeIRMap *irmap = static_cast(frm->GetAnalysisResult(MeFuncPhase_IRMAPBUILD, func)); std::string renamePhaseName = PhaseName(); MemPool *renamemp = memPoolCtrler.NewMemPool(renamePhaseName, true /* isLocalPool */); diff --git a/src/mapleall/maple_me/src/prop.cpp b/src/mapleall/maple_me/src/prop.cpp index 0a6f43ea58..39c4ef8c72 100644 --- a/src/mapleall/maple_me/src/prop.cpp +++ b/src/mapleall/maple_me/src/prop.cpp @@ -884,6 +884,7 @@ void Prop::TraversalMeStmt(MeStmt &meStmt) { PropUpdateDef(*asmestmt->GetLHS()); break; } + case OP_asm: break; default: for (size_t i = 0; i != meStmt.NumMeStmtOpnds(); ++i) { MeExpr &expr = PropMeExpr(utils::ToRef(meStmt.GetOpnd(i)), subProped, kOpcodeInfo.IsCall(op)); diff --git a/src/mapleall/maple_me/src/ssa_devirtual.cpp b/src/mapleall/maple_me/src/ssa_devirtual.cpp index af47708155..cb4013014a 100644 --- a/src/mapleall/maple_me/src/ssa_devirtual.cpp +++ b/src/mapleall/maple_me/src/ssa_devirtual.cpp @@ -503,6 +503,7 @@ void SSADevirtual::TraversalMeStmt(MeStmt &meStmt) { VisitMeExpr(unaryStmt->GetOpnd()); break; } + case OP_asm: case OP_call: case OP_virtualcall: case OP_virtualicall: diff --git a/src/mapleall/maple_me/src/ssa_pre.cpp b/src/mapleall/maple_me/src/ssa_pre.cpp index 8c0cf2991c..09d592bc76 100644 --- a/src/mapleall/maple_me/src/ssa_pre.cpp +++ b/src/mapleall/maple_me/src/ssa_pre.cpp @@ -1646,7 +1646,8 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE case OP_interfaceicallassigned: case OP_customcallassigned: case OP_polymorphiccallassigned: - case OP_icallassigned: { + case OP_icallassigned: + case OP_asm:{ auto *naryMeStmt = static_cast(meStmt); const MapleVector &opnds = naryMeStmt->GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { -- Gitee From 8fde836966a91bde3f84a5c5327ea4ec4d2594f3 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Mon, 9 Aug 2021 13:06:41 -0700 Subject: [PATCH 2/5] Fixed assumption in many places of only 1 element in mustDefList; dse and hdse should not delete asm's output operands --- src/mapleall/maple_me/src/dse.cpp | 2 +- src/mapleall/maple_me/src/hdse.cpp | 2 +- src/mapleall/maple_me/src/irmap_build.cpp | 1 + src/mapleall/maple_me/src/irmap_emit.cpp | 21 +++--- src/mapleall/maple_me/src/me_rename2preg.cpp | 8 +-- src/mapleall/maple_me/src/me_ssa_lpre.cpp | 68 +++++++++++--------- src/mapleall/maple_me/src/me_ssa_update.cpp | 24 +++---- src/mapleall/maple_me/src/me_stmt_pre.cpp | 5 +- src/mapleall/maple_me/src/me_store_pre.cpp | 13 ++-- src/mapleall/maple_me/src/prop.cpp | 8 +-- 10 files changed, 80 insertions(+), 72 deletions(-) diff --git a/src/mapleall/maple_me/src/dse.cpp b/src/mapleall/maple_me/src/dse.cpp index 17ed67c1bf..ca7afd8763 100644 --- a/src/mapleall/maple_me/src/dse.cpp +++ b/src/mapleall/maple_me/src/dse.cpp @@ -173,7 +173,7 @@ void DSE::DumpStmt(const StmtNode &stmt, const std::string &msg) const { } void DSE::CheckRemoveCallAssignedReturn(StmtNode &stmt) { - if (kOpcodeInfo.IsCallAssigned(stmt.GetOpCode())) { + if (kOpcodeInfo.IsCallAssigned(stmt.GetOpCode()) && stmt.GetOpCode() != OP_asm) { MapleVector &mustDefs = ssaTab.GetStmtMustDefNodes(stmt); for (auto &node : mustDefs) { if (IsSymbolLived(ToRef(node.GetResult()))) { diff --git a/src/mapleall/maple_me/src/hdse.cpp b/src/mapleall/maple_me/src/hdse.cpp index e09600b96e..9e32841e79 100644 --- a/src/mapleall/maple_me/src/hdse.cpp +++ b/src/mapleall/maple_me/src/hdse.cpp @@ -656,7 +656,7 @@ void HDSE::DseInit() { } } // mark mustDef nodes dead - if (kOpcodeInfo.IsCallAssigned(stmt.GetOp())) { + if (kOpcodeInfo.IsCallAssigned(stmt.GetOp()) && stmt.GetOp() != OP_asm) { MapleVector *mustDefList = stmt.GetMustDefList(); for (MustDefMeNode &mustDef : *mustDefList) { mustDef.SetIsLive(false); diff --git a/src/mapleall/maple_me/src/irmap_build.cpp b/src/mapleall/maple_me/src/irmap_build.cpp index 5b58c3cd6d..eaec7e5a99 100644 --- a/src/mapleall/maple_me/src/irmap_build.cpp +++ b/src/mapleall/maple_me/src/irmap_build.cpp @@ -738,6 +738,7 @@ MeStmt *IRMapBuild::BuildAsmMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { asmMeStmt->outputConstraints = asmNode->outputConstraints; asmMeStmt->clobberList = asmNode->clobberList; asmMeStmt->gotoLabels = asmNode->gotoLabels; + asmMeStmt->qualifiers = asmNode->qualifiers; if (propagater) { propagater->PropUpdateChiListDef(*asmMeStmt->GetChiList()); propagater->PropUpdateMustDefList(asmMeStmt); diff --git a/src/mapleall/maple_me/src/irmap_emit.cpp b/src/mapleall/maple_me/src/irmap_emit.cpp index 57c09ff501..3f559789da 100644 --- a/src/mapleall/maple_me/src/irmap_emit.cpp +++ b/src/mapleall/maple_me/src/irmap_emit.cpp @@ -328,16 +328,16 @@ StmtNode &MaydassignMeStmt::EmitStmt(SSATab &ssaTab) { void MeStmt::EmitCallReturnVector(CallReturnVector &nRets) { MapleVector *mustDefs = GetMustDefList(); - if (mustDefs == nullptr || mustDefs->empty()) { - return; - } - MeExpr *meExpr = mustDefs->front().GetLHS(); - if (meExpr->GetMeOp() == kMeOpVar) { - OriginalSt *ost = static_cast(meExpr)->GetOst(); - MIRSymbol *symbol = ost->GetMIRSymbol(); - nRets.push_back(CallReturnPair(symbol->GetStIdx(), RegFieldPair(0, 0))); - } else if (meExpr->GetMeOp() == kMeOpReg) { - nRets.push_back(CallReturnPair(StIdx(), RegFieldPair(0, static_cast(meExpr)->GetRegIdx()))); + CHECK_FATAL(mustDefs != nullptr, "EmitCallReturnVector: mustDefList cannot be null"); + for (MustDefMeNode mustdef : *mustDefs) { + MeExpr *meExpr = mustdef.GetLHS(); + if (meExpr->GetMeOp() == kMeOpVar) { + OriginalSt *ost = static_cast(meExpr)->GetOst(); + MIRSymbol *symbol = ost->GetMIRSymbol(); + nRets.push_back(CallReturnPair(symbol->GetStIdx(), RegFieldPair(0, 0))); + } else if (meExpr->GetMeOp() == kMeOpReg) { + nRets.push_back(CallReturnPair(StIdx(), RegFieldPair(0, static_cast(meExpr)->GetRegIdx()))); + } } } @@ -516,6 +516,7 @@ StmtNode &AsmMeStmt::EmitStmt(SSATab &ssaTab) { asmNode->outputConstraints = outputConstraints; asmNode->clobberList = clobberList; asmNode->gotoLabels = gotoLabels; + asmNode->qualifiers = qualifiers; return *asmNode; } diff --git a/src/mapleall/maple_me/src/me_rename2preg.cpp b/src/mapleall/maple_me/src/me_rename2preg.cpp index 98a4586e1f..337a061521 100644 --- a/src/mapleall/maple_me/src/me_rename2preg.cpp +++ b/src/mapleall/maple_me/src/me_rename2preg.cpp @@ -131,11 +131,9 @@ RegMeExpr *SSARename2Preg::RenameVar(const VarMeExpr *varmeexpr) { } void SSARename2Preg::Rename2PregCallReturn(MapleVector &mustdeflist) { - if (mustdeflist.empty()) { - return; - } - { - MustDefMeNode &mustdefmenode = mustdeflist.front(); + MapleVector::iterator it = mustdeflist.begin(); + for (; it != mustdeflist.end(); it++) { + MustDefMeNode &mustdefmenode = *it; MeExpr *melhs = mustdefmenode.GetLHS(); if (melhs->GetMeOp() != kMeOpVar) { return; diff --git a/src/mapleall/maple_me/src/me_ssa_lpre.cpp b/src/mapleall/maple_me/src/me_ssa_lpre.cpp index a8e9ca5420..bca9e9b2eb 100644 --- a/src/mapleall/maple_me/src/me_ssa_lpre.cpp +++ b/src/mapleall/maple_me/src/me_ssa_lpre.cpp @@ -94,18 +94,21 @@ void MeSSALPre::GenerateSaveRealOcc(MeRealOcc &realOcc) { MapleVector *mustDefList = realOcc.GetMeStmt()->GetMustDefList(); CHECK_NULL_FATAL(mustDefList); CHECK_FATAL(!mustDefList->empty(), "empty mustdef in callassigned stmt"); - MustDefMeNode *mustDefMeNode = &mustDefList->front(); - if (regOrVar->GetMeOp() == kMeOpReg) { - auto *theLHS = static_cast(mustDefMeNode->GetLHS()); - // change mustDef lhs to regOrVar - mustDefMeNode->UpdateLHS(*regOrVar); - EnterCandsForSSAUpdate(regOrVar->GetOstIdx(), *realOcc.GetMeStmt()->GetBB()); - // create new dassign for original lhs - MeStmt *newDassign = irMap->CreateAssignMeStmt(*theLHS, *regOrVar, *realOcc.GetMeStmt()->GetBB()); - theLHS->SetDefByStmt(*newDassign); - realOcc.GetMeStmt()->GetBB()->InsertMeStmtAfter(realOcc.GetMeStmt(), newDassign); - } else { - CHECK_FATAL(false, "GenerateSaveRealOcc: non-reg temp for callassigned LHS occurrence NYI"); + MapleVector::iterator it = mustDefList->begin(); + for (; it != mustDefList->end(); it++) { + MustDefMeNode *mustDefMeNode = &(*it); + if (regOrVar->GetMeOp() == kMeOpReg) { + auto *theLHS = static_cast(mustDefMeNode->GetLHS()); + // change mustDef lhs to regOrVar + mustDefMeNode->UpdateLHS(*regOrVar); + EnterCandsForSSAUpdate(regOrVar->GetOstIdx(), *realOcc.GetMeStmt()->GetBB()); + // create new dassign for original lhs + MeStmt *newDassign = irMap->CreateAssignMeStmt(*theLHS, *regOrVar, *realOcc.GetMeStmt()->GetBB()); + theLHS->SetDefByStmt(*newDassign); + realOcc.GetMeStmt()->GetBB()->InsertMeStmtAfter(realOcc.GetMeStmt(), newDassign); + } else { + CHECK_FATAL(false, "GenerateSaveRealOcc: non-reg temp for callassigned LHS occurrence NYI"); + } } } realOcc.SetSavedExpr(*regOrVar); @@ -258,27 +261,28 @@ void MeSSALPre::BuildWorkListLHSOcc(MeStmt &meStmt, int32 seqStmt) { (void)CreateRealOcc(meStmt, seqStmt, *lhs, false, true); } else if (kOpcodeInfo.IsCallAssigned(meStmt.GetOp())) { MapleVector *mustDefList = meStmt.GetMustDefList(); - if (mustDefList->empty()) { - return; - } - if (mustDefList->front().GetLHS()->GetMeOp() != kMeOpVar) { - return; - } - auto *theLHS = static_cast(mustDefList->front().GetLHS()); - const OriginalSt *ost = theLHS->GetOst(); - if (ost->IsFormal()) { - (void)assignedFormals.insert(ost->GetIndex()); - } - if (theLHS->GetPrimType() == PTY_ref && !MeOption::rcLowering) { - return; - } - if (ost->IsVolatile()) { - return; - } - if (theLHS->GetPrimType() == PTY_agg) { - return; + MapleVector::iterator it = mustDefList->begin(); + for (; it != mustDefList->end(); it++) { + if ((*it).GetLHS()->GetMeOp() != kMeOpVar) { + continue; + } + auto *theLHS = static_cast((*it).GetLHS()); + const OriginalSt *ost = theLHS->GetOst(); + if (ost->IsFormal()) { + (void)assignedFormals.insert(ost->GetIndex()); + } + if (theLHS->GetPrimType() == PTY_ref && !MeOption::rcLowering) { + continue; + } + if (ost->IsVolatile()) { + continue; + } + if (theLHS->GetPrimType() == PTY_agg) { + continue; + } + (void)CreateRealOcc(meStmt, seqStmt, *theLHS, false, true); } - (void)CreateRealOcc(meStmt, seqStmt, *theLHS, false, true); + return; } } diff --git a/src/mapleall/maple_me/src/me_ssa_update.cpp b/src/mapleall/maple_me/src/me_ssa_update.cpp index 1168f1ca91..2e6f041109 100644 --- a/src/mapleall/maple_me/src/me_ssa_update.cpp +++ b/src/mapleall/maple_me/src/me_ssa_update.cpp @@ -178,21 +178,23 @@ void MeSSAUpdate::RenameStmts(BB &bb) { ScalarMeExpr *lhs = nullptr; if (stmt.GetOp() == OP_dassign || stmt.GetOp() == OP_maydassign || stmt.GetOp() == OP_regassign) { lhs = stmt.GetLHS(); + CHECK_FATAL(lhs != nullptr, "stmt doesn't have lhs?"); + auto it = renameStacks.find(lhs->GetOstIdx()); + if (it != renameStacks.end()) { + it->second->push(lhs); + } } else if (kOpcodeInfo.IsCallAssigned(stmt.GetOp())) { MapleVector *mustDefList = stmt.GetMustDefList(); - if (mustDefList->empty()) { - continue; + MapleVector::iterator mustdefit = mustDefList->begin(); + for (; mustdefit != mustDefList->end(); mustdefit++) { + lhs = (*mustdefit).GetLHS(); + CHECK_FATAL(lhs != nullptr, "stmt doesn't have lhs?"); + auto it = renameStacks.find(lhs->GetOstIdx()); + if (it != renameStacks.end()) { + it->second->push(lhs); + } } - lhs = mustDefList->front().GetLHS(); - } else { - continue; - } - CHECK_FATAL(lhs != nullptr, "stmt doesn't have lhs?"); - auto it = renameStacks.find(lhs->GetOstIdx()); - if (it == renameStacks.end()) { - continue; } - it->second->push(lhs); } } diff --git a/src/mapleall/maple_me/src/me_stmt_pre.cpp b/src/mapleall/maple_me/src/me_stmt_pre.cpp index db63e57f7e..df66bf58d2 100644 --- a/src/mapleall/maple_me/src/me_stmt_pre.cpp +++ b/src/mapleall/maple_me/src/me_stmt_pre.cpp @@ -1052,8 +1052,9 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { if (kOpcodeInfo.IsCallAssigned(stmt.GetOp())) { // update version stacks MapleVector *mustDefList = stmt.GetMustDefList(); - if (!mustDefList->empty()) { - MeExpr *meLHS = mustDefList->front().GetLHS(); + MapleVector::iterator it = mustDefList->begin(); + for (; it != mustDefList->end(); it++) { + MeExpr *meLHS = (*it).GetLHS(); if (meLHS->GetMeOp() == kMeOpVar) { auto *lhsVar = static_cast(meLHS); MapleStack *pStack = versionStackVec.at(lhsVar->GetOstIdx()); diff --git a/src/mapleall/maple_me/src/me_store_pre.cpp b/src/mapleall/maple_me/src/me_store_pre.cpp index def01ff261..3f0e6ab2e7 100644 --- a/src/mapleall/maple_me/src/me_store_pre.cpp +++ b/src/mapleall/maple_me/src/me_store_pre.cpp @@ -74,8 +74,9 @@ RegMeExpr *MeStorePre::EnsureRHSInCurTemp(BB &bb) { } else if (kOpcodeInfo.IsCallAssigned(itStmt->GetOp())) { MapleVector *mustDefList = itStmt->GetMustDefList(); CHECK_NULL_FATAL(mustDefList); - if (!mustDefList->empty()) { - MeExpr *mdLHS = mustDefList->front().GetLHS(); + MapleVector::iterator it = mustDefList->begin(); + for (; it != mustDefList->end(); it++) { + MeExpr *mdLHS = (*it).GetLHS(); if (mdLHS->GetMeOp() != kMeOpVar) { continue; } @@ -88,7 +89,7 @@ RegMeExpr *MeStorePre::EnsureRHSInCurTemp(BB &bb) { } // change mustDefList RegMeExpr *lhsReg = irMap->CreateRegMeExprVersion(*curTemp); - mustDefList->front().UpdateLHS(*lhsReg); + (*it).UpdateLHS(*lhsReg); // create dassign AssignMeStmt *dass = irMap->CreateAssignMeStmt(*lhsVar, *lhsReg, bb); dass->SetSrcPos(itStmt->GetSrcPosition()); @@ -184,7 +185,7 @@ void MeStorePre::CodeMotion() { } realOcc->GetBB().RemoveMeStmt(dass); } else { - CHECK_FATAL(kOpcodeInfo.IsCallAssigned(realOcc->GetStmt()->GetOp()), "CodeMotion: callassign expected"); + CHECK_FATAL(kOpcodeInfo.IsCallAssigned(realOcc->GetStmt()->GetOp()) && realOcc->GetStmt()->GetOp() != OP_asm, "CodeMotion: callassign expected"); MapleVector *mustDefList = realOcc->GetStmt()->GetMustDefList(); CHECK_NULL_FATAL(mustDefList); mustDefList->clear(); @@ -223,7 +224,7 @@ void MeStorePre::CreateRealOcc(const OStIdx &ostIdx, MeStmt &meStmt) { if (meStmt.GetOp() == OP_dassign) { wkCand->SetTheVar(*static_cast(static_cast(&meStmt)->GetVarLHS())); } else { - ASSERT(kOpcodeInfo.IsCallAssigned(meStmt.GetOp()), "CreateRealOcc: callassign expected"); + ASSERT(kOpcodeInfo.IsCallAssigned(meStmt.GetOp()) && meStmt.GetOp() != OP_asm, "CreateRealOcc: callassign expected"); MapleVector *mustDefList = meStmt.GetMustDefList(); CHECK_FATAL(mustDefList != nullptr, "CreateRealOcc: mustDefList cannot be empty"); CHECK_FATAL(!mustDefList->empty(), "CreateRealOcc: mustDefList cannot be empty"); @@ -323,7 +324,7 @@ void MeStorePre::BuildWorkListBB(BB *bb) { if (dass->GetLHS()->GetPrimType() != PTY_ref && dass->GetLHS()->GetPrimType() != PTY_agg) { lhsOstIdx = dass->GetVarLHS()->GetOstIdx(); } - } else if (kOpcodeInfo.IsCallAssigned(stmt->GetOp())) { + } else if (kOpcodeInfo.IsCallAssigned(stmt->GetOp()) && stmt->GetOp() != OP_asm) { MapleVector *mustDefList = stmt->GetMustDefList(); CHECK_NULL_FATAL(mustDefList); if (!mustDefList->empty()) { diff --git a/src/mapleall/maple_me/src/prop.cpp b/src/mapleall/maple_me/src/prop.cpp index 39c4ef8c72..7e540e570a 100644 --- a/src/mapleall/maple_me/src/prop.cpp +++ b/src/mapleall/maple_me/src/prop.cpp @@ -69,10 +69,10 @@ void Prop::PropUpdateChiListDef(const MapleMap &chiList) { } void Prop::PropUpdateMustDefList(MeStmt *mestmt) { - MapleVector *mustdefList = mestmt->GetMustDefList(); - if (!mustdefList->empty()) { - MeExpr *melhs = mustdefList->front().GetLHS(); - PropUpdateDef(*static_cast(melhs)); + MapleVector *mustDefList = mestmt->GetMustDefList(); + for (auto &node : utils::ToRef(mustDefList)) { + MeExpr *melhs = node.GetLHS(); + PropUpdateDef(*melhs); } } -- Gitee From 9f8f24988a90346953c20797711ea8aed03fbae0 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Mon, 9 Aug 2021 16:36:03 -0700 Subject: [PATCH 3/5] Fixed bug in handling AsmMeStmt's asmString field --- src/mapleall/maple_me/include/me_ir.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_me/include/me_ir.h b/src/mapleall/maple_me/include/me_ir.h index 57dbcce160..d74f901b39 100644 --- a/src/mapleall/maple_me/include/me_ir.h +++ b/src/mapleall/maple_me/include/me_ir.h @@ -2343,12 +2343,13 @@ class AsmMeStmt : public NaryMeStmt, public MuChiMePart, public AssignedPart { : NaryMeStmt(alloc, stt), MuChiMePart(alloc), AssignedPart(alloc), - asmString(static_cast(stt)->asmString), + asmString(alloc->GetMemPool()), inputConstraints(alloc->Adapter()), outputConstraints(alloc->Adapter()), clobberList(alloc->Adapter()), gotoLabels(alloc->Adapter()), qualifiers(static_cast(stt)->qualifiers) { + asmString = static_cast(stt)->asmString; inputConstraints = static_cast(stt)->inputConstraints; outputConstraints = static_cast(stt)->outputConstraints; clobberList = static_cast(stt)->clobberList; -- Gitee From 0810de6a09de0903adf2c779ef92afde809c03c1 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Mon, 9 Aug 2021 20:14:19 -0700 Subject: [PATCH 4/5] Fixed bug of maydef/mayuse not inserted for asm statements --- src/mapleall/maple_me/include/me_ir.h | 4 ++++ src/mapleall/maple_me/src/alias_class.cpp | 1 + src/mapleall/maple_me/src/me_ir.cpp | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/src/mapleall/maple_me/include/me_ir.h b/src/mapleall/maple_me/include/me_ir.h index d74f901b39..27b28ec5e0 100644 --- a/src/mapleall/maple_me/include/me_ir.h +++ b/src/mapleall/maple_me/include/me_ir.h @@ -2356,6 +2356,10 @@ class AsmMeStmt : public NaryMeStmt, public MuChiMePart, public AssignedPart { gotoLabels = static_cast(stt)->gotoLabels; } virtual ~AsmMeStmt() = default; + void Dump(const IRMap*) const; + MapleMap *GetMuList() { + return &muList; + } MapleMap *GetChiList() { return &chiList; } diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index 750b1a7e8f..0a67761216 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -2029,6 +2029,7 @@ void AliasClass::GenericInsertMayDefUse(StmtNode &stmt, BBId bbID) { CallHasNoPrivateDefEffect(&stmt)); return; } + case OP_asm: case OP_virtualcallassigned: case OP_virtualicallassigned: case OP_superclasscallassigned: diff --git a/src/mapleall/maple_me/src/me_ir.cpp b/src/mapleall/maple_me/src/me_ir.cpp index c5084420e9..acbb6f490b 100644 --- a/src/mapleall/maple_me/src/me_ir.cpp +++ b/src/mapleall/maple_me/src/me_ir.cpp @@ -1302,6 +1302,7 @@ void NaryMeStmt::Dump(const IRMap *irMap) const { void AssignedPart::DumpAssignedPart(const IRMap *irMap) const { LogInfo::MapleLogger() << " assignedpart: {"; for (auto it = mustDefList.begin(); it != mustDefList.end(); ++it) { + LogInfo::MapleLogger() << " "; const MeExpr *lhsVar = (*it).GetLHS(); lhsVar->Dump(irMap); } @@ -1357,6 +1358,14 @@ void IntrinsiccallMeStmt::Dump(const IRMap *irMap) const { DumpAssignedPart(irMap); } +void AsmMeStmt::Dump(const IRMap *irMap) const { + LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << " " << '\"' << asmString << '\"' << std::endl; + DumpOpnds(irMap); + DumpMuList(irMap, muList); + DumpChiList(irMap, chiList); + DumpAssignedPart(irMap); +} + void RetMeStmt::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << '\n'; DumpOpnds(irMap); -- Gitee From 94306198a38754d96e693ae44387c6419e558ca4 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Mon, 9 Aug 2021 20:52:00 -0700 Subject: [PATCH 5/5] Fixed bug where SetPtrOpndsNextLevNADS() was not called for asm's first input operand --- src/mapleall/maple_me/src/alias_class.cpp | 2 +- src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index 0a67761216..cc1e5aadf9 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -748,7 +748,7 @@ void AliasClass::ApplyUnionForCopies(StmtNode &stmt) { CreateAliasElemsExpr(*stmt.Opnd(i)); } auto &call = static_cast(stmt); - SetPtrOpndsNextLevNADS(1, static_cast(call.NumOpnds()), call.GetNopnd(), false); + SetPtrOpndsNextLevNADS(stmt.GetOpCode() == OP_asm ? 0 : 1, static_cast(call.NumOpnds()), call.GetNopnd(), false); SetAggOpndPtrFieldsNextLevNADS(call.GetNopnd()); break; } diff --git a/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp b/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp index 27adb916d3..f4f533db86 100644 --- a/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp +++ b/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp @@ -586,12 +586,12 @@ void PEGBuilder::BuildPEGNodeInStmt(const StmtNode *stmt) { } return; } - case OP_asm: case OP_call: case OP_callassigned: { BuildPEGNodeInDirectCall(static_cast(stmt)); break; } + case OP_asm: case OP_virtualcall: case OP_virtualicall: case OP_superclasscall: -- Gitee