diff --git a/src/mapleall/maple_ir/include/mir_nodes.h b/src/mapleall/maple_ir/include/mir_nodes.h index f39856f41254c3ed16c85bca82f52cbe780f39dc..620b31c36df845d942a22bc01b58bb07337b200d 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 952f614db02843ebe973cb00c5c8b8d9851dba92..dcb8340b41e86fbf94696bb3e353ea9b7dbfa585 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 e3ea91037c21a814a6ef7027955ef4d257d7b39e..330857d285ebcc9ce243986b7d20b9e6e7aa2899 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 f688380541685266b1ee7eea22e3be07fb5bf416..be4e09a086ddca1b4f38d940ef1cf32780e1f040 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 741da2eefac21990343d739429279cdfb375ba1d..27b28ec5e0b3702b2c91969448d6dc83cfdc3ef7 100644 --- a/src/mapleall/maple_me/include/me_ir.h +++ b/src/mapleall/maple_me/include/me_ir.h @@ -2337,6 +2337,45 @@ 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(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; + gotoLabels = static_cast(stt)->gotoLabels; + } + virtual ~AsmMeStmt() = default; + void Dump(const IRMap*) const; + MapleMap *GetMuList() { + return &muList; + } + 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 eac9898160eed134afa8ed143dd9f12819bd9679..cc1e5aadf9a005a582b2fcb082d3100abe46c5e3 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -741,13 +741,14 @@ void AliasClass::ApplyUnionForCopies(StmtNode &stmt) { } break; } + case OP_asm: case OP_icall: case OP_icallassigned: { for (uint32 i = 0; i < stmt.NumOpnds(); ++i) { 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; } @@ -2028,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/copy_prop.cpp b/src/mapleall/maple_me/src/copy_prop.cpp index 49192243fb2f3706e127a512fc3125977bf58257..45797cf92177f7cef7001d20c1293d21a8e61fdc 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 3a3c0227cea7389c9b4f374aae510eb5a0b298e7..f4f533db86e53f1a0a0cd018673f7f4637e6e6f7 100644 --- a/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp +++ b/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp @@ -591,6 +591,7 @@ void PEGBuilder::BuildPEGNodeInStmt(const StmtNode *stmt) { BuildPEGNodeInDirectCall(static_cast(stmt)); break; } + case OP_asm: case OP_virtualcall: case OP_virtualicall: case OP_superclasscall: @@ -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/dse.cpp b/src/mapleall/maple_me/src/dse.cpp index 17ed67c1bf87b7b4d683c2f15ce8107f92ee23e1..ca7afd8763b1d20610e685ac98cb5cce832ffeab 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 e09600b96ee312c41e2fc1c6cc86cd1e31ed8f51..9e32841e79a3ee4740a5021335f1a22eb0296205 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/ipa_side_effect.cpp b/src/mapleall/maple_me/src/ipa_side_effect.cpp index a76d0479bdc08719a08fa18395cef86156e73e6a..5f9a6c22281f80c8befcc1befca5723e8836fd55 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 c3aa3bc45dfa5e02b6218b9686352f2859f0baab..eaec7e5a9947b04a49423482a881cf72f21311ba 100644 --- a/src/mapleall/maple_me/src/irmap_build.cpp +++ b/src/mapleall/maple_me/src/irmap_build.cpp @@ -724,6 +724,28 @@ 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; + asmMeStmt->qualifiers = asmNode->qualifiers; + 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 +791,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 da22f1d8b0451a58a1f09c38da5dbc41f0c8c14f..3f559789dae6385476acf77a717c4a973b3877ac 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()))); + } } } @@ -491,6 +491,35 @@ 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; + asmNode->qualifiers = qualifiers; + 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 00322aac6ab6efa59d6354ef66930932be238a9d..08e60ef19c4b2c0db33f9d60347d8a83e611112a 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 a7899e2fb6e5979167f1f651ba62cbdc3fba57d6..192339a16cb5724d7a514dd1a3d0555579963513 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 ae602ae65e836ecce230a6a689d1f997776edd00..a98a5b1336ab0bbf0e31a1936e10a4551c270f9a 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_ir.cpp b/src/mapleall/maple_me/src/me_ir.cpp index c5084420e99f5a516e3cb1fbbad7f28b3fb51a37..acbb6f490b4e3d2dfe4eb20f68246a6d8649bcdb 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); diff --git a/src/mapleall/maple_me/src/me_phase_manager.cpp b/src/mapleall/maple_me/src/me_phase_manager.cpp index d8bd3e237dc9c2f85f3e88b1c9c10929a22491f2..433617bed79710bc71fe7450b60f26955bc0d5e3 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 79ceb99144b320653a4ef5768f50a0001102b134..337a0615210198cb2157a99713c0078aba81ef89 100644 --- a/src/mapleall/maple_me/src/me_rename2preg.cpp +++ b/src/mapleall/maple_me/src/me_rename2preg.cpp @@ -131,12 +131,9 @@ RegMeExpr *SSARename2Preg::RenameVar(const VarMeExpr *varmeexpr) { } void SSARename2Preg::Rename2PregCallReturn(MapleVector &mustdeflist) { - if (mustdeflist.empty()) { - return; - } - CHECK_FATAL(mustdeflist.size() == 1, "NYI"); - { - 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; @@ -277,6 +274,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_ssa_lpre.cpp b/src/mapleall/maple_me/src/me_ssa_lpre.cpp index a8e9ca542077c5d6674dc714f43d3936da3eb2b0..bca9e9b2eb2a5c187917922db49c5a93ad8686d8 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 1168f1ca91aa96dcf6243702a95b2b563055b29e..2e6f041109905e7804007404872d27c27c5b77fb 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 17ecd3f5c29493fedc4cc955e1fcc0f98bcef7b1..df66bf58d2fb3d6ffc8be73e08955b7e024c9293 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: @@ -1051,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 def01ff2611e535a60793c2cab1902c3ddab14ef..3f0e6ab2e71e6ed57a108bcc763ae8bc327eb02e 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/preg_renamer.cpp b/src/mapleall/maple_me/src/preg_renamer.cpp index d70b766ff11f7866b0d5b4a240bf904b31fc67c9..aa3d9b745a35c0cd8dc4e8f27e1ab6bcfc24672c 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 0a6f43ea58395a6060ae7ef589a5a0ed2b809ec6..7e540e570a466cee0b794c41c0c502d676caee92 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); } } @@ -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 af47708155da96a9ca9d11aedac737beee65dbea..cb4013014a8b3a5bc84dde769e285011508fba70 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 8c0cf2991ce5d566fc6e19bee0cb19860ef7b38e..09d592bc767b1b819e0e851064d2ada587ac758d 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) {