diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index d08a5c3a85e60b33fabd818055592c4bf8b18050..12a8e81f50c4d39613a5670c29626d78ffb2f584 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 329f6efcae996c7881406a1f8d5c56225b71f29a..7eba3e6242f3b3999272a8ba70914509f77339f3 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 5a5f202d2746a6a6fc2cc537309d7ad9ca5985f4..e251505f93b91576cf43067baf8e1488f24a4812 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/maple_be/include/cg/cg_option.h b/src/maple_be/include/cg/cg_option.h index 750b303dc414bc6effb38b2c4762ae3021ae5adf..34ad082785001a9075906c4143459054f0db5d96 100644 --- a/src/maple_be/include/cg/cg_option.h +++ b/src/maple_be/include/cg/cg_option.h @@ -77,6 +77,13 @@ class CGOptions : public MapleDriverOptionBase { kLevel1 = 1, kLevel2 = 2, }; + + enum ABIType : uint8 { + kABIHard, + kABISoft, + kABISoftFP, + kABIUndef + }; /* * The default CG option values are: * Don't BE_QUITE; verbose, diff --git a/src/maple_be/src/cg/cg_phasemanager.cpp b/src/maple_be/src/cg/cg_phasemanager.cpp index f3e6b93cacd390c0711513da77d151a7d125b806..6e7dbd90ac04047a981461c3e7686b8a8d94d94b 100644 --- a/src/maple_be/src/cg/cg_phasemanager.cpp +++ b/src/maple_be/src/cg/cg_phasemanager.cpp @@ -15,7 +15,6 @@ #include "cg_phasemanager.h" #include #include - #include "cg_option.h" #include "live.h" #include "loop.h" diff --git a/src/maple_be/src/cg/emit.cpp b/src/maple_be/src/cg/emit.cpp index c8607cf92459b9b45002ed9ee942b099162ebf32..d9a395ab1e24b44d830d92177fd43c0d6210453a 100644 --- a/src/maple_be/src/cg/emit.cpp +++ b/src/maple_be/src/cg/emit.cpp @@ -2253,11 +2253,12 @@ void Emitter::EmitHexUnsigned(uint64 num) { #define str(s) #s void Emitter::EmitDIHeader() { + Emit("\t.section ." + std::string(NameMangler::kMuidJavatextPrefixStr) + ",\"ax\"\n"); Emit(".L" XSTR(TEXT_BEGIN) ":\n"); } void Emitter::EmitDIFooter() { - Emit("\t.text\n"); + Emit("\t.section ." + std::string(NameMangler::kMuidJavatextPrefixStr) + ",\"ax\"\n"); Emit(".L" XSTR(TEXT_END) ":\n"); } diff --git a/src/maple_driver/include/driver_option_common.h b/src/maple_driver/include/driver_option_common.h index 6646ff56ee347021180534d345f819247cbbfc1b..03abfb7e932d9d2fe7c8fbe26294554482ac910f 100644 --- a/src/maple_driver/include/driver_option_common.h +++ b/src/maple_driver/include/driver_option_common.h @@ -48,7 +48,7 @@ class MapleDriverOptionBase { usageVec.push_back(usage[i]); } } - std::vector &GetUsageVec() { + const std::vector &GetUsageVec() const { return usageVec; } MapleDriverOptionBase() = default; diff --git a/src/maple_driver/include/option_parser.h b/src/maple_driver/include/option_parser.h index c2bbc6028c69d2c27ee77d2932a7c31267d418c6..bacd68f6f0810c40b28d77eda80b0579e5945bf1 100644 --- a/src/maple_driver/include/option_parser.h +++ b/src/maple_driver/include/option_parser.h @@ -28,7 +28,7 @@ class OptionParser { ~OptionParser() = default; - void RegisteUsages(maple::MapleDriverOptionBase &base); + void RegisteUsages(const maple::MapleDriverOptionBase &base); void RegisteUsages(const Descriptor usage[]); maple::ErrorCode Parse(int argc, char **argv, const std::string exeName = "all"); diff --git a/src/maple_driver/src/option_parser.cpp b/src/maple_driver/src/option_parser.cpp index 2887dd70b47ebe0ee837d118e3870e07ac1c2f11..56361754438b9fbe5f5388e726fb9e0d42144e9e 100644 --- a/src/maple_driver/src/option_parser.cpp +++ b/src/maple_driver/src/option_parser.cpp @@ -78,7 +78,7 @@ void OptionParser::CreateNoOption(const Descriptor &usage) { InsertExtraUsage(tempUsage); } -void OptionParser::RegisteUsages(MapleDriverOptionBase &base) { +void OptionParser::RegisteUsages(const MapleDriverOptionBase &base) { for (auto &usage : base.GetUsageVec()) { if (usage.help == nullptr) { continue; diff --git a/src/maple_ipa/include/callgraph.h b/src/maple_ipa/include/callgraph.h index f779e480370fef5ea155b2c865b4a073e6303134..faaa784591d977ad98c3beba32b0a7f24457590c 100644 --- a/src/maple_ipa/include/callgraph.h +++ b/src/maple_ipa/include/callgraph.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -20,7 +20,7 @@ #include "mir_builder.h" namespace maple { class SCCNode; -typedef enum { +enum CallType { kCallTypeInvalid, kCallTypeCall, kCallTypeVirtualCall, @@ -33,7 +33,7 @@ typedef enum { kCallTypeCustomCall, kCallTypePolymorphicCall, kCallTypeFakeThreadStartRun -} CallType; +}; struct NodeComparator { bool operator()(const MIRFunction *lhs, const MIRFunction *rhs) const { @@ -135,7 +135,7 @@ class CGNode { return mirFunc; } - void AddCallsite(CallInfo*, CGNode*); + void AddCallsite(CallInfo&, CGNode*); void AddCallsite(CallInfo*, MapleSet>*); void RemoveCallsite(const CallInfo*, CGNode*); @@ -159,7 +159,7 @@ class CGNode { return mirFunc ? mirFunc->GetName() : GlobalTables::GetStrTable().GetStringFromStrIdx(GStrIdx(0)); } - void AddCandsForCallNode(const KlassHierarchy *kh); + void AddCandsForCallNode(const KlassHierarchy &kh); void AddVCallCandidate(MIRFunction *func) { vcallCands.push_back(func); } @@ -190,7 +190,7 @@ class CGNode { return callerSet.size(); } - bool IsCalleeOf(CGNode *func); + bool IsCalleeOf(CGNode *func) const; void IncrStmtCount() { ++stmtCount; } @@ -307,7 +307,7 @@ class SCCNode { MapleVector cgNodes; MapleSet> callerScc; MapleSet> calleeScc; - explicit SCCNode(uint32 index, MapleAllocator *alloc) + SCCNode(uint32 index, MapleAllocator *alloc) : id(index), cgNodes(alloc->Adapter()), callerScc(alloc->Adapter()), @@ -319,9 +319,9 @@ class SCCNode { cgNodes.push_back(cgn); } - void Dump(); - void DumpCycle(); - void Verify(); + void Dump() const; + void DumpCycle() const; + void Verify() const; void Setup(); const MapleVector &GetCGNodes() const { return cgNodes; @@ -371,15 +371,15 @@ class CallGraph : public AnalysisResult { return nodesMap; } - void HandleBody(MIRFunction*, BlockNode*, CGNode*, uint32); - void AddCallGraphNode(MIRFunction*); - void DumpToFile(bool dumpall = true); + void HandleBody(MIRFunction&, BlockNode&, CGNode&, uint32); + void AddCallGraphNode(MIRFunction&); + void DumpToFile(bool dumpAll = true); void Dump() const; CGNode *GetCGNode(MIRFunction *func) const; CGNode *GetCGNode(PUIdx puIdx) const; SCCNode *GetSCCNode(MIRFunction *func) const; bool IsRootNode(MIRFunction *func) const; - void UpdateCallGraphNode(CGNode *node); + void UpdateCallGraphNode(CGNode &node); void RecomputeSCC(); MIRFunction *CurFunction() const { return mirModule->CurFunction(); @@ -390,7 +390,7 @@ class CallGraph : public AnalysisResult { } /* iterator */ - typedef MapleMap::iterator iterator; + using iterator = MapleMap::iterator; iterator Begin() { return nodesMap.begin(); } @@ -407,12 +407,12 @@ class CallGraph : public AnalysisResult { return (*it).second; } - void DelNode(CGNode *node); + void DelNode(CGNode &node); bool debug_flag; bool debug_scc; void BuildSCC(); - void VerifySCC(); - void BuildSCCDFS(CGNode *caller, unsigned int &visitIndex, std::vector &sccNodes, + void VerifySCC() const; + void BuildSCCDFS(CGNode &caller, unsigned int &visitIndex, std::vector &sccNodes, std::vector &cgNodes, std::vector &visitedOrder, std::vector &lowestOrder, std::vector &inStack, std::vector &visitStack); @@ -439,13 +439,14 @@ class CallGraph : public AnalysisResult { } void FindRootNodes(); - void SCCTopologicalSort(std::vector &sccNodes); - void SetCompilationFunclist(); + void SCCTopologicalSort(const std::vector &sccNodes); + void SetCompilationFunclist() const; void IncrNodesCount(CGNode *cgnode, BaseNode *bn); }; + class DoCallGraph : public ModulePhase { public: - DoCallGraph(ModulePhaseID id) : ModulePhase(id) {} + explicit DoCallGraph(ModulePhaseID id) : ModulePhase(id) {} AnalysisResult *Run(MIRModule *module, ModuleResultMgr *m) override; std::string PhaseName() const override { @@ -454,6 +455,7 @@ class DoCallGraph : public ModulePhase { virtual ~DoCallGraph(){}; }; + class IPODevirtulize { public: IPODevirtulize(MIRModule *m, MemPool *memPool, KlassHierarchy *kh) @@ -470,9 +472,10 @@ class IPODevirtulize { MIRBuilder *mirBuilder; KlassHierarchy *klassh; bool debugFlag; - void SearchDefInMemberMethods(const Klass *klass); - void SearchDefInClinit(const Klass *klass); + void SearchDefInMemberMethods(const Klass &klass); + void SearchDefInClinit(const Klass &klass); }; + class DoIPODevirtulize : public ModulePhase { public: explicit DoIPODevirtulize(ModulePhaseID id) : ModulePhase(id) {} @@ -484,6 +487,5 @@ class DoIPODevirtulize : public ModulePhase { virtual ~DoIPODevirtulize(){}; }; - } // namespace maple #endif // MAPLE_IPA_INCLUDE_CALLGRAPH_H diff --git a/src/maple_ipa/include/clone.h b/src/maple_ipa/include/clone.h index 055706702eb6c412c1f5ab6eb002480767808fc9..9bba62e4d09ce0f86552d775eac0f2f5d9dd66e4 100644 --- a/src/maple_ipa/include/clone.h +++ b/src/maple_ipa/include/clone.h @@ -22,6 +22,7 @@ #include "class_hierarchy.h" #include "me_ir.h" #include "module_phase.h" + static constexpr char kFullNameStr[] = "INFO_fullname"; static constexpr char kClassNameStr[] = "INFO_classname"; static constexpr char kFuncNameStr[] = "INFO_funcname"; @@ -29,12 +30,12 @@ static constexpr char kVoidRetSuffix[] = "CLONEDignoreret"; namespace maple { class ReplaceRetIgnored { public: - ReplaceRetIgnored(MemPool *memPool); + explicit ReplaceRetIgnored(MemPool *memPool); virtual ~ReplaceRetIgnored() = default; - bool ShouldReplaceWithVoidFunc(const CallMeStmt *stmt, const MIRFunction *calleeFunc) const; - std::string GenerateNewBaseName(const MIRFunction *originalFunc); - std::string GenerateNewFullName(const MIRFunction *originalFunc); + bool ShouldReplaceWithVoidFunc(const CallMeStmt &stmt, const MIRFunction &calleeFunc) const; + std::string GenerateNewBaseName(const MIRFunction &originalFunc) const; + std::string GenerateNewFullName(const MIRFunction &originalFunc) const; const MapleSet *GetTobeClonedFuncNames() const { return &toBeClonedFuncNames; } @@ -51,8 +52,9 @@ class ReplaceRetIgnored { MemPool *memPool; maple::MapleAllocator allocator; MapleSet toBeClonedFuncNames; - bool RealShouldReplaceWithVoidFunc(Opcode op, size_t nRetSize, const MIRFunction *calleeFunc) const; + bool RealShouldReplaceWithVoidFunc(Opcode op, size_t nRetSize, const MIRFunction &calleeFunc) const; }; + class Clone : public AnalysisResult { public: Clone(MIRModule *mod, MemPool *memPool, MIRBuilder &builder, KlassHierarchy *kh) @@ -61,21 +63,21 @@ class Clone : public AnalysisResult { ~Clone() = default; - static MIRSymbol *CloneLocalSymbol(const MIRSymbol *oldSym, MIRFunction *newFunc); - static void CloneSymbols(MIRFunction *newFunc, const MIRFunction *oldFunc); - static void CloneLabels(MIRFunction *newFunc, const MIRFunction *oldFunc); - MIRFunction *CloneFunction(MIRFunction *originalFunction, const std::string &newBaseFuncName, - MIRType *returnType = nullptr); - MIRFunction *CloneFunctionNoReturn(MIRFunction *originalFunction); + static MIRSymbol *CloneLocalSymbol(const MIRSymbol &oldSym, const MIRFunction &newFunc); + static void CloneSymbols(MIRFunction &newFunc, const MIRFunction &oldFunc); + static void CloneLabels(MIRFunction &newFunc, const MIRFunction &oldFunc); + MIRFunction *CloneFunction(MIRFunction &originalFunction, const std::string &newBaseFuncName, + MIRType *returnType = nullptr) const; + MIRFunction *CloneFunctionNoReturn(MIRFunction &originalFunction); void DoClone(); - void CopyFuncInfo(const MIRFunction *originalFunction, MIRFunction *newFunc) const; + void CopyFuncInfo(const MIRFunction &originalFunction, MIRFunction *newFunc) const; void UpdateFuncInfo(MIRFunction *newFunc); - void CloneArgument(MIRFunction *originalFunction, ArgVector &argument) const; + void CloneArgument(MIRFunction &riginalFunction, ArgVector &argument) const; ReplaceRetIgnored *GetReplaceRetIgnored() { return replaceRetIgnored; } - void UpdateReturnVoidIfPossible(CallMeStmt *callMeStmt, const MIRFunction *targetFunc); + void UpdateReturnVoidIfPossible(CallMeStmt *callMeStmt, const MIRFunction &targetFunc); private: MIRModule *mirModule; @@ -84,6 +86,7 @@ class Clone : public AnalysisResult { KlassHierarchy *kh; ReplaceRetIgnored *replaceRetIgnored; }; + class DoClone : public ModulePhase { public: explicit DoClone(ModulePhaseID id) : ModulePhase(id) {} diff --git a/src/maple_ipa/src/callgraph.cpp b/src/maple_ipa/src/callgraph.cpp index 35d9de72b69a6473855d7294a891e3a83466ec7f..370cbe5380c57f477bb70b02cf87a1e83ff5008d 100644 --- a/src/maple_ipa/src/callgraph.cpp +++ b/src/maple_ipa/src/callgraph.cpp @@ -114,15 +114,16 @@ void CGNode::DumpDetail() const { } // dump caller for (auto const &callernode : callerSet) { - CHECK_FATAL(callernode && callernode->mirFunc, ""); + CHECK_NULL_FATAL(callernode); + CHECK_NULL_FATAL(callernode->mirFunc); LogInfo::MapleLogger() << "\tcaller : " << callernode->mirFunc->GetName() << std::endl; } } void CGNode::Dump(std::ofstream &fout) const { - /* if dumpall == 1, dump whole call graph - * else dump callgraph with function defined in same module */ - CHECK_FATAL(mirFunc != nullptr, ""); + // if dumpall == 1, dump whole call graph + // else dump callgraph with function defined in same module + CHECK_NULL_FATAL(mirFunc); if (callees.empty()) { fout << "\"" << mirFunc->GetName() << "\";\n"; return; @@ -154,13 +155,13 @@ void CGNode::AddCallsite(CallInfo *ci, MapleSet> *ca callees.insert(std::pair>*>(ci, callee)); } -void CGNode::AddCallsite(CallInfo *ci, CGNode *node) { - CHECK_FATAL(ci->GetCallType() != kCallTypeInterfaceCall, "must be true"); - CHECK_FATAL(ci->GetCallType() != kCallTypeVirtualCall, "must be true"); +void CGNode::AddCallsite(CallInfo &ci, CGNode *node) { + CHECK_FATAL(ci.GetCallType() != kCallTypeInterfaceCall, "must be true"); + CHECK_FATAL(ci.GetCallType() != kCallTypeVirtualCall, "must be true"); auto *cgVector = alloc->GetMemPool()->New>>(alloc->Adapter()); cgVector->insert(node); - (void)callees.emplace(ci, cgVector); - if (node) { + (void)callees.emplace(&ci, cgVector); + if (node != nullptr) { node->AddNumRefs(); } } @@ -178,24 +179,23 @@ void CGNode::RemoveCallsite(const CallInfo *ci, CGNode *node) { } } -bool CGNode::IsCalleeOf(CGNode *func) { +bool CGNode::IsCalleeOf(CGNode *func) const { return callerSet.find(func) != callerSet.end(); } -void CallGraph::DelNode(CGNode *node) { - ASSERT_NOT_NULL(node); - if (!node->GetMIRFunction()) { +void CallGraph::DelNode(CGNode &node) { + if (node.GetMIRFunction() == nullptr) { return; } - for (auto &callSite : node->GetCallee()) { + for (auto &callSite : node.GetCallee()) { for (auto &cgIt : *callSite.second) { - cgIt->DelCaller(node); + cgIt->DelCaller(&node); if (!cgIt->HasCaller()) { - DelNode(cgIt); + DelNode(*cgIt); } } } - MIRFunction *func = node->GetMIRFunction(); + MIRFunction *func = node.GetMIRFunction(); // Delete the method of class info if (func->GetClassTyIdx() != 0u) { MIRType *classType = GlobalTables::GetTypeTable().GetTypeTable().at(func->GetClassTyIdx()); @@ -311,11 +311,11 @@ CGNode *CallGraph::GetCGNode(PUIdx puIdx) const { SCCNode *CallGraph::GetSCCNode(MIRFunction *func) const { CGNode *cgnode = GetCGNode(func); - return cgnode ? cgnode->GetSCCNode() : nullptr; + return cgnode != nullptr ? cgnode->GetSCCNode() : nullptr; } bool CallGraph::IsRootNode(MIRFunction *func) const { - if (GetCGNode(func)) { + if (GetCGNode(func) != nullptr) { return (!GetCGNode(func)->HasCaller()); } else { return false; @@ -419,27 +419,27 @@ CGNode *CallGraph::GetOrGenCGNode(PUIdx puIdx, bool isVcall, bool isIcall) { return node; } -void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uint32 loopDepth) { +void CallGraph::HandleBody(MIRFunction &func, BlockNode &body, CGNode &node, uint32 loopDepth) { StmtNode *stmtNext = nullptr; - for (StmtNode *stmt = body->GetFirst(); stmt != nullptr; stmt = stmtNext) { + for (StmtNode *stmt = body.GetFirst(); stmt != nullptr; stmt = stmtNext) { stmtNext = static_cast(stmt)->GetNext(); Opcode op = stmt->GetOpCode(); if (op == OP_comment) { continue; } else if (op == OP_doloop) { DoloopNode *n = static_cast(stmt); - HandleBody(func, n->GetDoBody(), node, loopDepth + 1); + HandleBody(func, *n->GetDoBody(), node, loopDepth + 1); } else if (op == OP_dowhile || op == OP_while) { WhileStmtNode *n = static_cast(stmt); - HandleBody(func, n->GetBody(), node, loopDepth + 1); + HandleBody(func, *n->GetBody(), node, loopDepth + 1); } else if (op == OP_if) { IfStmtNode *n = static_cast(stmt); - HandleBody(func, n->GetThenPart(), node, loopDepth); + HandleBody(func, *n->GetThenPart(), node, loopDepth); if (n->GetElsePart()) { - HandleBody(func, n->GetElsePart(), node, loopDepth); + HandleBody(func, *n->GetElsePart(), node, loopDepth); } } else { - node->IncrStmtCount(); + node.IncrStmtCount(); CallType ct = GetCallType(op); switch (ct) { case kCallTypeVirtualCall: { @@ -458,7 +458,7 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin RetypeNode *retypeNode = static_cast(dassignNode->GetRHS()); CHECK_FATAL(retypeNode->Opnd(0)->GetOpCode() == OP_dread, "Must be dread."); AddrofNode *dreadT = static_cast(retypeNode->Opnd(0)); - MIRType *type = func->GetLocalOrGlobalSymbol(dreadT->GetStIdx())->GetType(); + MIRType *type = func.GetLocalOrGlobalSymbol(dreadT->GetStIdx())->GetType(); CHECK_FATAL(type->IsMIRPtrType(), "Must be ptr type."); MIRPtrType *ptrType = static_cast(type); MIRType *targetType = ptrType->GetPointedType(); @@ -486,10 +486,10 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin CGNode *calleeNode = GetOrGenCGNode(calleePUIdx, true); CHECK_FATAL(calleeNode != nullptr, "calleenode is null"); CHECK_FATAL(calleeNode->IsVcallCandidatesValid(), "vcall candidate must be valid"); - node->AddCallsite(callInfo, &calleeNode->GetVcallCandidates()); + node.AddCallsite(callInfo, &calleeNode->GetVcallCandidates()); for (auto &cgIt : calleeNode->GetVcallCandidates()) { CGNode *calleeNodeT = cgIt; - calleeNodeT->AddCaller(node); + calleeNodeT->AddCaller(&node); } break; } @@ -501,10 +501,10 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin CGNode *calleeNode = GetOrGenCGNode(calleeFunc->GetPuidx(), false, true); CHECK_FATAL(calleeNode != nullptr, "calleenode is null"); CHECK_FATAL(calleeNode->IsIcallCandidatesValid(), "icall candidate must be valid"); - node->AddCallsite(callInfo, &calleeNode->GetIcallCandidates()); + node.AddCallsite(callInfo, &calleeNode->GetIcallCandidates()); for (auto &cgIt : calleeNode->GetIcallCandidates()) { CGNode *calleeNodeT = cgIt; - calleeNodeT->AddCaller(node); + calleeNodeT->AddCaller(&node); } break; } @@ -516,8 +516,8 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin CallInfo *callInfo = GenCallInfo(kCallTypeCall, calleeFunc, stmt, loopDepth, stmt->GetStmtID()); CGNode *calleeNode = GetOrGenCGNode(calleeFunc->GetPuidx()); ASSERT(calleeNode != nullptr, "calleenode is null"); - calleeNode->AddCaller(node); - node->AddCallsite(callInfo, calleeNode); + calleeNode->AddCaller(&node); + node.AddCallsite(*callInfo, calleeNode); } break; } @@ -546,9 +546,9 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin CallInfo *callInfo = GenCallInfo(kCallTypeCall, actualMirfunc, stmt, loopDepth, stmt->GetStmtID()); CGNode *calleeNode = GetOrGenCGNode(actualMirfunc->GetPuidx()); ASSERT(calleeNode != nullptr, "calleenode is null"); - calleeNode->AddCaller(node); + calleeNode->AddCaller(&node); (static_cast(stmt))->SetPUIdx(actualMirfunc->GetPuidx()); - node->AddCallsite(callInfo, calleeNode); + node.AddCallsite(*callInfo, calleeNode); break; } case kCallTypeIntrinsicCall: @@ -568,12 +568,12 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin } } -void CallGraph::UpdateCallGraphNode(CGNode *node) { - ASSERT_NOT_NULL(node); - node->Reset(); - MIRFunction *func = node->GetMIRFunction(); +void CallGraph::UpdateCallGraphNode(CGNode &node) { + node.Reset(); + MIRFunction *func = node.GetMIRFunction(); + CHECK_NULL_FATAL(func); BlockNode *body = func->GetBody(); - HandleBody(func, body, node, 0); + HandleBody(*func, *body, node, 0); } void CallGraph::RecomputeSCC() { @@ -582,14 +582,14 @@ void CallGraph::RecomputeSCC() { BuildSCC(); } -void CallGraph::AddCallGraphNode(MIRFunction *func) { - CGNode *node = GetOrGenCGNode(func->GetPuidx()); +void CallGraph::AddCallGraphNode(MIRFunction &func) { + CGNode *node = GetOrGenCGNode(func.GetPuidx()); CHECK_FATAL(node != nullptr, "node is null in CallGraph::GenCallGraph"); - BlockNode *body = func->GetBody(); - HandleBody(func, body, node, 0); + BlockNode *body = func.GetBody(); + HandleBody(func, *body, *node, 0); /* set root if current function is static main */ - if (func->GetName() == mirModule->GetEntryFuncName()) { - mirModule->SetEntryFunction(func); + if (func.GetName() == mirModule->GetEntryFuncName()) { + mirModule->SetEntryFunction(&func); entry_node = node; } } @@ -631,17 +631,17 @@ static void SetInferredType(std::vector &inferredSymbols, MIRSymbol } } -void IPODevirtulize::SearchDefInClinit(const Klass *klass) { - MIRClassType *classtype = static_cast(klass->GetMIRStructType()); +void IPODevirtulize::SearchDefInClinit(const Klass &klass) { + MIRClassType *classType = static_cast(klass.GetMIRStructType()); std::vector staticFinalPrivateSymbols; - for (uint32 i = 0; i < classtype->GetStaticFields().size(); i++) { - FieldAttrs attribute = classtype->GetStaticFields()[i].second.second; + for (uint32 i = 0; i < classType->GetStaticFields().size(); i++) { + FieldAttrs attribute = classType->GetStaticFields()[i].second.second; if (attribute.GetAttr(FLDATTR_final)) { staticFinalPrivateSymbols.push_back( - GlobalTables::GetGsymTable().GetSymbolFromStrIdx(classtype->GetStaticFields()[i].first)); + GlobalTables::GetGsymTable().GetSymbolFromStrIdx(classType->GetStaticFields()[i].first)); } } - std::string typeName = klass->GetKlassName(); + std::string typeName = klass.GetKlassName(); typeName.append(NameMangler::kClinitSuffix); GStrIdx clinitFuncGstridx = GlobalTables::GetStrTable().GetStrIdxFromName(NameMangler::GetInternalNameLiteral(typeName)); @@ -649,7 +649,7 @@ void IPODevirtulize::SearchDefInClinit(const Klass *klass) { return; } MIRFunction *func = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(clinitFuncGstridx)->GetFunction(); - if (!func->GetBody()) { + if (func->GetBody() == nullptr) { return; } StmtNode *stmtNext = nullptr; @@ -696,19 +696,20 @@ void IPODevirtulize::SearchDefInClinit(const Klass *klass) { } case OP_call: case OP_callassigned: { - CallNode *cnode = static_cast(stmt); - MIRFunction *calleefunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(cnode->GetPUIdx()); - if (calleefunc->GetName().find(NameMangler::kClinitSubStr, 0) != std::string::npos) { + CallNode *callNode = static_cast(stmt); + MIRFunction *calleeFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(callNode->GetPUIdx()); + if (calleeFunc->GetName().find(NameMangler::kClinitSubStr, 0) != std::string::npos) { // ignore all side effect of initizlizor continue; } - for (unsigned int i = 0; i < cnode->GetReturnVec().size(); i++) { - StIdx stidx = cnode->GetReturnVec()[i].first; - MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stidx); + for (unsigned int i = 0; i < callNode->GetReturnVec().size(); i++) { + StIdx stIdx = callNode->GetReturnVec()[i].first; + MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stIdx); ResetInferredType(gcmallocSymbols, tmpSymbol); } - for (size_t i = 0; i < cnode->GetNopndSize(); i++) { - BaseNode *node = cnode->GetNopndAt(i); + for (size_t i = 0; i < callNode->GetNopndSize(); i++) { + BaseNode *node = callNode->GetNopndAt(i); + CHECK_NULL_FATAL(node); if (node->GetOpCode() != OP_dread) { continue; } @@ -719,8 +720,8 @@ void IPODevirtulize::SearchDefInClinit(const Klass *klass) { break; } case OP_intrinsiccallwithtype: { - IntrinsiccallNode *callnode = static_cast(stmt); - if (callnode->GetIntrinsic() != INTRN_JAVA_CLINIT_CHECK) { + IntrinsiccallNode *callNode = static_cast(stmt); + if (callNode->GetIntrinsic() != INTRN_JAVA_CLINIT_CHECK) { ResetInferredType(gcmallocSymbols); } break; @@ -732,22 +733,22 @@ void IPODevirtulize::SearchDefInClinit(const Klass *klass) { } } -void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { +void IPODevirtulize::SearchDefInMemberMethods(const Klass &klass) { SearchDefInClinit(klass); - MIRClassType *classtype = static_cast(klass->GetMIRStructType()); + MIRClassType *classType = static_cast(klass.GetMIRStructType()); std::vector finalPrivateFieldID; - for (uint32 i = 0; i < classtype->GetFieldsSize(); i++) { - FieldAttrs attribute = classtype->GetFields()[i].second.second; + for (uint32 i = 0; i < classType->GetFieldsSize(); i++) { + FieldAttrs attribute = classType->GetFields()[i].second.second; if (attribute.GetAttr(FLDATTR_final)) { FieldID id = mirBuilder->GetStructFieldIDFromFieldNameParentFirst( - classtype, GlobalTables::GetStrTable().GetStringFromStrIdx(classtype->GetFields()[i].first)); + classType, GlobalTables::GetStrTable().GetStringFromStrIdx(classType->GetFields()[i].first)); finalPrivateFieldID.push_back(id); } } std::vector initMethods; - std::string typeName = klass->GetKlassName(); + std::string typeName = klass.GetKlassName(); typeName.append(NameMangler::kCinitStr); - for (MIRFunction *const &method : klass->GetMethods()) { + for (MIRFunction *const &method : klass.GetMethods()) { if (!strncmp(method->GetName().c_str(), typeName.c_str(), typeName.length())) { initMethods.push_back(method); } @@ -759,7 +760,7 @@ void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { StmtNode *stmtNext = nullptr; for (unsigned int i = 0; i < initMethods.size(); i++) { MIRFunction *func = initMethods[i]; - if (!func->GetBody()) { + if (func->GetBody() == nullptr) { continue; } std::vector gcmallocSymbols; @@ -776,10 +777,10 @@ void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { GCMallocNode *gcmallocNode = static_cast(dassignNode->GetRHS()); SetInferredType(gcmallocSymbols, leftSymbol, gcmallocNode->GetTyIdx()); } else if (dassignNode->GetRHS()->GetOpCode() == OP_retype) { - RetypeNode *retystmt = static_cast(dassignNode->GetRHS()); - BaseNode *fromnode = retystmt->Opnd(0); - if (fromnode->GetOpCode() == OP_dread) { - DreadNode *dreadNode = static_cast(fromnode); + RetypeNode *retyStmt = static_cast(dassignNode->GetRHS()); + BaseNode *fromNode = retyStmt->Opnd(0); + if (fromNode->GetOpCode() == OP_dread) { + DreadNode *dreadNode = static_cast(fromNode); MIRSymbol *fromSymbol = func->GetLocalOrGlobalSymbol(dreadNode->GetStIdx()); SetInferredType(gcmallocSymbols, leftSymbol, fromSymbol->GetInferredTyIdx()); } else { @@ -792,19 +793,19 @@ void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { } case OP_call: case OP_callassigned: { - CallNode *cnode = static_cast(stmt); - MIRFunction *calleefunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(cnode->GetPUIdx()); - if (calleefunc->GetName().find(NameMangler::kClinitSubStr, 0) != std::string::npos) { + CallNode *callNode = static_cast(stmt); + MIRFunction *calleeFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(callNode->GetPUIdx()); + if (calleeFunc->GetName().find(NameMangler::kClinitSubStr, 0) != std::string::npos) { // ignore all side effect of initizlizor continue; } - for (size_t j = 0; j < cnode->GetReturnVec().size(); j++) { - StIdx stidx = cnode->GetReturnVec()[j].first; - MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stidx); + for (size_t j = 0; j < callNode->GetReturnVec().size(); j++) { + StIdx stIdx = callNode->GetReturnVec()[j].first; + MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stIdx); ResetInferredType(gcmallocSymbols, tmpSymbol); } - for (size_t j = 0; j < cnode->GetNopndSize(); j++) { - BaseNode *node = cnode->GetNopndAt(j); + for (size_t j = 0; j < callNode->GetNopndSize(); j++) { + BaseNode *node = callNode->GetNopndAt(j); if (node->GetOpCode() != OP_dread) { continue; } @@ -826,7 +827,7 @@ void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(iassignNode->GetTyIdx()); ASSERT(type->GetKind() == kTypePointer, "Must be pointer type"); MIRPtrType *pointedType = static_cast(type); - if (pointedType->GetPointedTyIdx() == classtype->GetTypeIndex()) { + if (pointedType->GetPointedTyIdx() == classType->GetTypeIndex()) { // set field of current class FieldID fieldID = iassignNode->GetFieldID(); unsigned j = 0; @@ -841,15 +842,15 @@ void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { CHECK_FATAL(dreadNode != nullptr, "Impossible"); MIRSymbol *rightSymbol = func->GetLocalOrGlobalSymbol(dreadNode->GetStIdx()); if (rightSymbol->GetInferredTyIdx() != kInitTyIdx && rightSymbol->GetInferredTyIdx() != kNoneTyIdx && - (classtype->GetElemInferredTyIdx(fieldID) == kInitTyIdx || - (classtype->GetElemInferredTyIdx(fieldID) == rightSymbol->GetInferredTyIdx()))) { - classtype->SetElemInferredTyIdx(fieldID, rightSymbol->GetInferredTyIdx()); + (classType->GetElemInferredTyIdx(fieldID) == kInitTyIdx || + (classType->GetElemInferredTyIdx(fieldID) == rightSymbol->GetInferredTyIdx()))) { + classType->SetElemInferredTyIdx(fieldID, rightSymbol->GetInferredTyIdx()); } else { - classtype->SetElemInferredTyIdx(fieldID, kInitTyIdx); + classType->SetElemInferredTyIdx(fieldID, kInitTyIdx); finalPrivateFieldID.erase(finalPrivateFieldID.begin() + j); } } else { - classtype->SetElemInferredTyIdx(fieldID, kInitTyIdx); + classType->SetElemInferredTyIdx(fieldID, kInitTyIdx); finalPrivateFieldID.erase(finalPrivateFieldID.begin() + j); } } @@ -864,9 +865,9 @@ void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { } } -void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { - MIRClassType *classtype = static_cast(klass->GetMIRStructType()); - for (auto &func : klass->GetMethods()) { +void DoDevirtual(const Klass &klass, const KlassHierarchy &klassh) { + MIRClassType *classType = static_cast(klass.GetMIRStructType()); + for (auto &func : klass.GetMethods()) { if (func->GetBody() == nullptr) { continue; } @@ -895,12 +896,12 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ireadNode->GetTyIdx()); ASSERT(type->GetKind() == kTypePointer, "Must be pointer type"); MIRPtrType *pointedType = static_cast(type); - if (pointedType->GetPointedTyIdx() == classtype->GetTypeIndex()) { + if (pointedType->GetPointedTyIdx() == classType->GetTypeIndex()) { FieldID fieldID = ireadNode->GetFieldID(); FieldID tmpID = fieldID; - TyIdx tmpTyIdx = classtype->GetElemInferredTyIdx(tmpID); + TyIdx tmpTyIdx = classType->GetElemInferredTyIdx(tmpID); if (tmpTyIdx != kInitTyIdx && tmpTyIdx != kNoneTyIdx) { - SetInferredType(inferredSymbols, leftSymbol, classtype->GetElemInferredTyIdx(fieldID)); + SetInferredType(inferredSymbols, leftSymbol, classType->GetElemInferredTyIdx(fieldID)); } } } else { @@ -913,13 +914,13 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { case OP_virtualcall: case OP_virtualcallassigned: { CallNode *calleeNode = static_cast(stmt); - MIRFunction *calleefunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(calleeNode->GetPUIdx()); + MIRFunction *calleeFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(calleeNode->GetPUIdx()); if (calleeNode->GetNopndAt(0)->GetOpCode() == OP_dread) { DreadNode *dreadNode = static_cast(calleeNode->GetNopndAt(0)); MIRSymbol *rightSymbol = func->GetLocalOrGlobalSymbol(dreadNode->GetStIdx()); if (rightSymbol->GetInferredTyIdx() != kInitTyIdx && rightSymbol->GetInferredTyIdx() != kNoneTyIdx) { // Devirtual - Klass *currKlass = klassh->GetKlassFromTyIdx(rightSymbol->GetInferredTyIdx()); + Klass *currKlass = klassh.GetKlassFromTyIdx(rightSymbol->GetInferredTyIdx()); if (op == OP_interfacecall || op == OP_interfacecallassigned || op == OP_virtualcall || op == OP_virtualcallassigned) { std::vector klassVector; @@ -928,7 +929,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { for (unsigned int index = 0; index < klassVector.size(); index++) { Klass *tmpKlass = klassVector[index]; for (MIRFunction *const &method : tmpKlass->GetMethods()) { - if (calleefunc->GetBaseFuncNameWithTypeStrIdx() == method->GetBaseFuncNameWithTypeStrIdx()) { + if (calleeFunc->GetBaseFuncNameWithTypeStrIdx() == method->GetBaseFuncNameWithTypeStrIdx()) { calleeNode->SetPUIdx(method->GetPuidx()); if (op == OP_virtualcall || op == OP_interfacecall) { calleeNode->SetOpCode(OP_call); @@ -940,10 +941,10 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { if (false) { LogInfo::MapleLogger() << "Devirtualize In function:" + func->GetName() << '\n'; LogInfo::MapleLogger() << calleeNode->GetOpCode() << '\n'; - LogInfo::MapleLogger() << " From:" << calleefunc->GetName() << '\n'; - LogInfo::MapleLogger() << " To :" - << GlobalTables::GetFunctionTable().GetFunctionFromPuidx(calleeNode->GetPUIdx())->GetName() - << '\n'; + LogInfo::MapleLogger() << " From:" << calleeFunc->GetName() << '\n'; + LogInfo::MapleLogger() << " To :" << + GlobalTables::GetFunctionTable().GetFunctionFromPuidx(calleeNode->GetPUIdx())->GetName() << + '\n'; } break; } @@ -959,6 +960,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { if (hasDevirtualed) { for (size_t i = 0; i < calleeNode->GetNopndSize(); i++) { BaseNode *node = calleeNode->GetNopndAt(i); + CHECK_NULL_FATAL(node); if (node->GetOpCode() != OP_dread) { continue; } @@ -967,10 +969,10 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { ResetInferredType(inferredSymbols, tmpSymbol); } if (op == OP_interfacecallassigned || op == OP_virtualcallassigned) { - CallNode *cnode = static_cast(stmt); - for (unsigned int i = 0; i < cnode->GetReturnVec().size(); i++) { - StIdx stidx = cnode->GetReturnVec()[i].first; - MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stidx); + CallNode *callNode = static_cast(stmt); + for (unsigned int i = 0; i < callNode->GetReturnVec().size(); i++) { + StIdx stIdx = callNode->GetReturnVec()[i].first; + MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stIdx); ResetInferredType(inferredSymbols, tmpSymbol); } } @@ -979,12 +981,12 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { // Search default function in interfaces Klass *tmpInterface = nullptr; MIRFunction *tmpMethod = nullptr; - for (Klass *iklass : currKlass->GetImplInterfaces()) { - for (MIRFunction *const &method : iklass->GetMethods()) { - if (calleefunc->GetBaseFuncNameWithTypeStrIdx() == method->GetBaseFuncNameWithTypeStrIdx() && + for (Klass *iKlass : currKlass->GetImplInterfaces()) { + for (MIRFunction *const &method : iKlass->GetMethods()) { + if (calleeFunc->GetBaseFuncNameWithTypeStrIdx() == method->GetBaseFuncNameWithTypeStrIdx() && !method->GetFuncAttrs().GetAttr(FUNCATTR_abstract)) { - if (tmpInterface == nullptr || klassh->IsSuperKlassForInterface(tmpInterface, iklass)) { - tmpInterface = iklass; + if (tmpInterface == nullptr || klassh.IsSuperKlassForInterface(tmpInterface, iKlass)) { + tmpInterface = iKlass; tmpMethod = method; } break; @@ -993,7 +995,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } // Add this check for the thirdparty APP compile if (tmpMethod == nullptr) { - Klass *parentKlass = klassh->GetKlassFromName(calleefunc->GetBaseClassName()); + Klass *parentKlass = klassh.GetKlassFromName(calleeFunc->GetBaseClassName()); CHECK_FATAL(parentKlass != nullptr, "null ptr check"); bool flag = false; if (parentKlass->GetKlassName() == currKlass->GetKlassName()) { @@ -1015,23 +1017,23 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } } if (!flag) { - LogInfo::MapleLogger() << "warning: func " << calleefunc->GetName() << " is not found in DeVirtual!" - << std::endl; - LogInfo::MapleLogger() << "warning: " << calleefunc->GetBaseClassName() << " is not the parent of " - << currKlass->GetKlassName() << std::endl; + LogInfo::MapleLogger() << "warning: func " << calleeFunc->GetName() << + " is not found in DeVirtual!" << std::endl; + LogInfo::MapleLogger() << "warning: " << calleeFunc->GetBaseClassName() << + " is not the parent of " << currKlass->GetKlassName() << std::endl; } } if (tmpMethod == nullptr) { // SearchWithoutRettype, search only in current class now. - MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(calleefunc->GetReturnTyIdx()); + MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(calleeFunc->GetReturnTyIdx()); Klass *targetKlass = nullptr; bool isCalleeScalar = false; if (retType->GetKind() == kTypePointer && retType->GetPrimType() == PTY_ref) { MIRType *ptrType = (static_cast(retType))->GetPointedType(); - targetKlass = klassh->GetKlassFromTyIdx(ptrType->GetTypeIndex()); + targetKlass = klassh.GetKlassFromTyIdx(ptrType->GetTypeIndex()); } else if (retType->GetKind() == kTypeScalar) { isCalleeScalar = true; } else { - targetKlass = klassh->GetKlassFromTyIdx(retType->GetTypeIndex()); + targetKlass = klassh.GetKlassFromTyIdx(retType->GetTypeIndex()); } if (targetKlass == nullptr && !isCalleeScalar) { CHECK_FATAL(targetKlass != nullptr, "null ptr check"); @@ -1040,49 +1042,49 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { bool isCurrVtabScalar = false; bool isFindMethod = false; for (MIRFunction *const &method : currKlass->GetMethods()) { - if (calleefunc->GetBaseFuncSigStrIdx() == method->GetBaseFuncSigStrIdx()) { + if (calleeFunc->GetBaseFuncSigStrIdx() == method->GetBaseFuncSigStrIdx()) { Klass *tmpKlass = nullptr; MIRType *tmpType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(method->GetReturnTyIdx()); if (tmpType->GetKind() == kTypePointer && tmpType->GetPrimType() == PTY_ref) { MIRType *ptrType = (static_cast(tmpType))->GetPointedType(); - tmpKlass = klassh->GetKlassFromTyIdx(ptrType->GetTypeIndex()); + tmpKlass = klassh.GetKlassFromTyIdx(ptrType->GetTypeIndex()); } else if (tmpType->GetKind() == kTypeScalar) { isCurrVtabScalar = true; } else { - tmpKlass = klassh->GetKlassFromTyIdx(tmpType->GetTypeIndex()); + tmpKlass = klassh.GetKlassFromTyIdx(tmpType->GetTypeIndex()); } if (tmpKlass == nullptr && !isCurrVtabScalar) { CHECK_FATAL(false, "null ptr check"); } if (isCalleeScalar || isCurrVtabScalar) { if (isFindMethod) { - LogInfo::MapleLogger() << "warning: this " << currKlass->GetKlassName() - << " has mult methods with the same function name but with different return type!" - << std::endl; + LogInfo::MapleLogger() << "warning: this " << currKlass->GetKlassName() << + " has mult methods with the same function name but with different return type!" << + std::endl; break; } tmpMethod = method; isFindMethod = true; continue; } - if (targetKlass->IsClass() && klassh->IsSuperKlass(tmpKlass, targetKlass) && - (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + if (targetKlass->IsClass() && klassh.IsSuperKlass(tmpKlass, targetKlass) && + (curRetKlass == nullptr || klassh.IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } - if (targetKlass->IsClass() && klassh->IsInterfaceImplemented(tmpKlass, targetKlass)) { + if (targetKlass->IsClass() && klassh.IsInterfaceImplemented(tmpKlass, targetKlass)) { tmpMethod = method; break; } if (!targetKlass->IsClass()) { CHECK_FATAL(tmpKlass != nullptr, "Klass null ptr check"); - if (tmpKlass->IsClass() && klassh->IsInterfaceImplemented(targetKlass, tmpKlass) && - (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + if (tmpKlass->IsClass() && klassh.IsInterfaceImplemented(targetKlass, tmpKlass) && + (curRetKlass == nullptr || klassh.IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } - if (!tmpKlass->IsClass() && klassh->IsSuperKlassForInterface(tmpKlass, targetKlass) && - (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + if (!tmpKlass->IsClass() && klassh.IsSuperKlassForInterface(tmpKlass, targetKlass) && + (curRetKlass == nullptr || klassh.IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } @@ -1091,12 +1093,12 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } } if (tmpMethod == nullptr && (currKlass->IsClass() || currKlass->IsInterface())) { - LogInfo::MapleLogger() << "warning: func " << calleefunc->GetName() - << " is not found in DeVirtual!" << std::endl; + LogInfo::MapleLogger() << "warning: func " << calleeFunc->GetName() << + " is not found in DeVirtual!" << std::endl; stmt->SetOpCode(OP_callassigned); break; } else if (tmpMethod == nullptr) { - LogInfo::MapleLogger() << "Error: func " << calleefunc->GetName() << " is not found!" << std::endl; + LogInfo::MapleLogger() << "Error: func " << calleeFunc->GetName() << " is not found!" << std::endl; ASSERT(tmpMethod, "Must not be null"); } calleeNode->SetPUIdx(tmpMethod->GetPuidx()); @@ -1109,10 +1111,9 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { if (false) { LogInfo::MapleLogger() << "Devirtualize In function:" + func->GetName() << '\n'; LogInfo::MapleLogger() << calleeNode->GetOpCode() << '\n'; - LogInfo::MapleLogger() << " From:" << calleefunc->GetName() << '\n'; - LogInfo::MapleLogger() << " To :" - << GlobalTables::GetFunctionTable().GetFunctionFromPuidx(calleeNode->GetPUIdx())->GetName() - << '\n'; + LogInfo::MapleLogger() << " From:" << calleeFunc->GetName() << '\n'; + LogInfo::MapleLogger() << " To :" << + GlobalTables::GetFunctionTable().GetFunctionFromPuidx(calleeNode->GetPUIdx())->GetName() << '\n'; } for (size_t i = 0; i < calleeNode->GetNopndSize(); i++) { BaseNode *node = calleeNode->GetNopndAt(i); @@ -1124,9 +1125,9 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { ResetInferredType(inferredSymbols, tmpSymbol); } if (op == OP_interfacecallassigned || op == OP_virtualcallassigned) { - CallNode *cnode = static_cast(stmt); - for (unsigned int i = 0; i < cnode->GetReturnVec().size(); i++) { - StIdx stidx = cnode->GetReturnVec()[i].first; + CallNode *callNode = static_cast(stmt); + for (unsigned int i = 0; i < callNode->GetReturnVec().size(); i++) { + StIdx stidx = callNode->GetReturnVec()[i].first; MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stidx); ResetInferredType(inferredSymbols, tmpSymbol); } @@ -1139,14 +1140,14 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { [[clang::fallthrough]]; case OP_call: case OP_callassigned: { - CallNode *cnode = static_cast(stmt); - for (size_t i = 0; i < cnode->GetReturnVec().size(); i++) { - StIdx stidx = cnode->GetReturnVec()[i].first; - MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stidx); + CallNode *callNode = static_cast(stmt); + for (size_t i = 0; i < callNode->GetReturnVec().size(); i++) { + StIdx stIdx = callNode->GetReturnVec()[i].first; + MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(stIdx); ResetInferredType(inferredSymbols, tmpSymbol); } - for (size_t i = 0; i < cnode->GetNopndSize(); i++) { - BaseNode *node = cnode->GetNopndAt(i); + for (size_t i = 0; i < callNode->GetNopndSize(); i++) { + BaseNode *node = callNode->GetNopndAt(i); if (node->GetOpCode() != OP_dread) { continue; } @@ -1170,41 +1171,37 @@ void IPODevirtulize::DevirtualFinal() { for (; it != klassh->GetKlasses().end(); ++it) { Klass *klass = it->second; if (klass->IsClass()) { - MIRClassType *classtype = static_cast(klass->GetMIRStructType()); + MIRClassType *classType = static_cast(klass->GetMIRStructType()); // Initialize inferred type of member fileds as kInitTyidx - for (unsigned int i = 0; i < classtype->GetFieldsSize(); i++) { // Don't include parent's field - classtype->SetElemInferredTyIdx(i, kInitTyIdx); + for (unsigned int i = 0; i < classType->GetFieldsSize(); i++) { // Don't include parent's field + classType->SetElemInferredTyIdx(i, kInitTyIdx); } - SearchDefInMemberMethods(klass); - for (unsigned int i = 0; i < classtype->GetFieldInferredTyIdx().size(); i++) { - if (classtype->GetElemInferredTyIdx(i) != kInitTyIdx && classtype->GetElemInferredTyIdx(i) != kNoneTyIdx) { - if (debugFlag) { - FieldID tmpID = i; - FieldPair pair = classtype->TraverseToFieldRef(tmpID); - LogInfo::MapleLogger() << "Inferred Final Private None-Static Variable:" + klass->GetKlassName() + ":" + - GlobalTables::GetStrTable().GetStringFromStrIdx(pair.first) - << '\n'; - } + SearchDefInMemberMethods(*klass); + for (unsigned int i = 0; i < classType->GetFieldInferredTyIdx().size(); i++) { + if (classType->GetElemInferredTyIdx(i) != kInitTyIdx && classType->GetElemInferredTyIdx(i) != kNoneTyIdx && + debugFlag) { + FieldID tmpID = i; + FieldPair pair = classType->TraverseToFieldRef(tmpID); + LogInfo::MapleLogger() << "Inferred Final Private None-Static Variable:" + klass->GetKlassName() + ":" + + GlobalTables::GetStrTable().GetStringFromStrIdx(pair.first) << '\n'; } } - for (uint32 i = 0; i < classtype->GetStaticFields().size(); i++) { - FieldAttrs attribute = classtype->GetStaticFields()[i].second.second; - if (!GlobalTables::GetGsymTable().GetSymbolFromStrIdx(classtype->GetStaticFields()[i].first)) { + for (uint32 i = 0; i < classType->GetStaticFields().size(); i++) { + FieldAttrs attribute = classType->GetStaticFields()[i].second.second; + if (GlobalTables::GetGsymTable().GetSymbolFromStrIdx(classType->GetStaticFields()[i].first) == nullptr) { continue; } - if (GlobalTables::GetGsymTable().GetSymbolFromStrIdx(classtype->GetStaticFields()[i].first)->GetInferredTyIdx() - != kInitTyIdx && - GlobalTables::GetGsymTable().GetSymbolFromStrIdx(classtype->GetStaticFields()[i].first)->GetInferredTyIdx() - != kNoneTyIdx) { + TyIdx tyIdx = GlobalTables::GetGsymTable().GetSymbolFromStrIdx( + classType->GetStaticFields()[i].first)->GetInferredTyIdx(); + if (tyIdx != kInitTyIdx && tyIdx != kNoneTyIdx) { CHECK_FATAL(attribute.GetAttr(FLDATTR_final), "Must be final private"); if (debugFlag) { LogInfo::MapleLogger() << "Final Private Static Variable:" + - GlobalTables::GetStrTable().GetStringFromStrIdx(classtype->GetStaticFields()[i].first) - << '\n'; + GlobalTables::GetStrTable().GetStringFromStrIdx(classType->GetStaticFields()[i].first) << '\n'; } } } - DoDevirtual(klass, GetKlassh()); + DoDevirtual(*klass, *GetKlassh()); } } } @@ -1226,7 +1223,7 @@ void CallGraph::GenCallGraph() { } else if (info->GetCallType() == kCallTypeInterfaceCall) { node->AddCallsite(*itInner, &calleeNode->GetIcallCandidates()); } else if (info->GetCallType() == kCallTypeCall) { - node->AddCallsite(*itInner, calleeNode); + node->AddCallsite(**itInner, calleeNode); } else if (info->GetCallType() == kCallTypeSuperCall) { const MIRFunction *calleefunc = info->GetFunc(); Klass *klass = klassh->GetKlassFromFunc(calleefunc); @@ -1238,7 +1235,7 @@ void CallGraph::GenCallGraph() { if (cands == nullptr) { for (Klass *implinterface : klass->GetImplInterfaces()) { cands = implinterface->GetCandidates(calleefunc->GetBaseFuncNameWithTypeStrIdx()); - if (cands && !cands->empty()) { + if (cands != nullptr && !cands->empty()) { break; } } @@ -1249,7 +1246,7 @@ void CallGraph::GenCallGraph() { MIRFunction *actualMirfunc = cands->at(0); CGNode *tempNode = GetOrGenCGNode(actualMirfunc->GetPuidx()); ASSERT(tempNode != nullptr, "calleenode is null in CallGraph::HandleBody"); - node->AddCallsite(info, tempNode); + node->AddCallsite(*info, tempNode); } for (auto &callSite : node->GetCallee()) { if (callSite.first == info) { @@ -1274,7 +1271,7 @@ void CallGraph::GenCallGraph() { continue; } mirModule->SetCurFunction(mirFunc); - AddCallGraphNode(mirFunc); + AddCallGraphNode(*mirFunc); } // Add all root nodes FindRootNodes(); @@ -1300,14 +1297,14 @@ void CallGraph::Dump() const { } } -void CallGraph::DumpToFile(bool dumpall) { +void CallGraph::DumpToFile(bool dumpAll) { if (Options::noDot) { return; } std::ofstream cgfile; char *outName = nullptr; MapleString outfile(fileName, GetMempool()); - if (dumpall) { + if (dumpAll) { outName = (outfile.append("-callgraph.dot")).c_str(); } else { outName = (outfile.append("-callgraphlight.dot")).c_str(); @@ -1317,7 +1314,7 @@ void CallGraph::DumpToFile(bool dumpall) { for (auto const &it : nodesMap) { CGNode *node = it.second; // dump user defined function - if (dumpall) { + if (dumpAll) { node->Dump(cgfile); } else { if ((node->GetMIRFunction() != nullptr) && (!node->GetMIRFunction()->IsEmpty())) { @@ -1335,7 +1332,9 @@ void CallGraph::BuildCallGraph() { if (debug_flag) { DumpToFile(true); } - SetCompilationFunclist(); + if (mirModule->firstInline) { + SetCompilationFunclist(); + } } // Sort CGNode within an SCC. Try best to arrange callee appears before @@ -1359,7 +1358,7 @@ static bool CGNodeCompare(CGNode *left, CGNode *right) { // Set compilation order as the bottom-up order of callgraph. So callee // is always compiled before caller. This benifits thoses optimizations // need interprocedure information like escape analysis. -void CallGraph::SetCompilationFunclist() { +void CallGraph::SetCompilationFunclist() const { mirModule->GetCompilationList().clear(); mirModule->GetFunctionList().clear(); const MapleVector &sccTopVec = GetSCCTopVec(); @@ -1369,7 +1368,7 @@ void CallGraph::SetCompilationFunclist() { for (auto const kIt : sccNode->cgNodes) { CGNode *node = kIt; MIRFunction *func = node->GetMIRFunction(); - if ((func && func->GetBody() && !IsInIPA()) || (func && !func->IsNative())) { + if ((func != nullptr && func->GetBody() && !IsInIPA()) || (func != nullptr && !func->IsNative())) { mirModule->GetCompilationList().push_back(func); mirModule->GetFunctionList().push_back(func); } @@ -1422,7 +1421,7 @@ bool SCCNode::HasSelfRecursion() const { return false; } -void SCCNode::Dump() { +void SCCNode::Dump() const { printf("SCC %d contains\n", id); for (auto const kIt : cgNodes) { CGNode *node = kIt; @@ -1434,7 +1433,7 @@ void SCCNode::Dump() { } } -void SCCNode::DumpCycle() { +void SCCNode::DumpCycle() const { CGNode *currNode = cgNodes[0]; std::vector searched; searched.push_back(currNode); @@ -1483,7 +1482,7 @@ void SCCNode::DumpCycle() { } } -void SCCNode::Verify() { +void SCCNode::Verify() const { if (cgNodes.size() <= 0) { CHECK_FATAL(false, ""); } @@ -1518,18 +1517,18 @@ void SCCNode::Setup() { } } -void CallGraph::BuildSCCDFS(CGNode *caller, uint32 &visitIndex, std::vector &sccNodes, +void CallGraph::BuildSCCDFS(CGNode &caller, uint32 &visitIndex, std::vector &sccNodes, std::vector &cgNodes, std::vector &visitedOrder, std::vector &lowestOrder, std::vector &inStack, std::vector &visitStack) { - uint32 id = caller->GetID(); - cgNodes.at(id) = caller; + uint32 id = caller.GetID(); + cgNodes.at(id) = &caller; visitedOrder.at(id) = visitIndex; lowestOrder.at(id) = visitIndex; visitIndex++; visitStack.push_back(id); inStack.at(id) = true; - for (auto &callSite : caller->GetCallee()) { + for (auto &callSite : caller.GetCallee()) { for (auto &cgIt : *callSite.second) { CGNode *calleeNode = cgIt; if (calleeNode == nullptr) { @@ -1538,7 +1537,7 @@ void CallGraph::BuildSCCDFS(CGNode *caller, uint32 &visitIndex, std::vectorGetID(); if (!visitedOrder.at(calleeId)) { // callee has not been processed yet - BuildSCCDFS(calleeNode, visitIndex, sccNodes, cgNodes, visitedOrder, lowestOrder, inStack, visitStack); + BuildSCCDFS(*calleeNode, visitIndex, sccNodes, cgNodes, visitedOrder, lowestOrder, inStack, visitStack); if (lowestOrder.at(calleeId) < lowestOrder.at(id)) { lowestOrder.at(id) = lowestOrder.at(calleeId); } @@ -1563,7 +1562,7 @@ void CallGraph::BuildSCCDFS(CGNode *caller, uint32 &visitIndex, std::vectorGetSCCNode() == nullptr) { @@ -1584,18 +1583,17 @@ void CallGraph::BuildSCC() { std::vector visitStack; // Starting from roots is a good strategy for DSF for (CGNode *const &root : rootNodes) { - BuildSCCDFS(root, visitIndex, sccNodes, cgNodes, visitedOrder, lowestOrder, inStack, visitStack); + BuildSCCDFS(*root, visitIndex, sccNodes, cgNodes, visitedOrder, lowestOrder, inStack, visitStack); } // However, not all SCC can be reached from roots. // E.g. foo()->foo(), foo is not considered as a root. for (auto const &it : nodesMap) { CGNode *node = it.second; - if (!node->GetSCCNode()) { - BuildSCCDFS(node, visitIndex, sccNodes, cgNodes, visitedOrder, lowestOrder, inStack, visitStack); + if (node->GetSCCNode() == nullptr) { + BuildSCCDFS(*node, visitIndex, sccNodes, cgNodes, visitedOrder, lowestOrder, inStack, visitStack); } } for (SCCNode *const &scc : sccNodes) { - // LogInfo::MapleLogger() << "SCC:" << scc->cgNodes.size() << '\n'; scc->Verify(); scc->Setup(); // fix caller and callee info. if (debug_scc && scc->HasRecursion()) { @@ -1605,7 +1603,7 @@ void CallGraph::BuildSCC() { SCCTopologicalSort(sccNodes); } -void CallGraph::SCCTopologicalSort(std::vector &sccNodes) { +void CallGraph::SCCTopologicalSort(const std::vector &sccNodes) { std::set> inQueue; // Local variable, no need to use MapleSet for (SCCNode *const &node : sccNodes) { if (!node->HasCaller()) { @@ -1636,14 +1634,13 @@ void CallGraph::SCCTopologicalSort(std::vector &sccNodes) { } } -void CGNode::AddCandsForCallNode(const KlassHierarchy *kh) { +void CGNode::AddCandsForCallNode(const KlassHierarchy &kh) { /* already set vcall candidates information */ - ASSERT_NOT_NULL(kh); if (HasSetVCallCandidates()) { return; } - CHECK_FATAL(mirFunc != nullptr, ""); - Klass *klass = kh->GetKlassFromFunc(mirFunc); + CHECK_NULL_FATAL(mirFunc); + Klass *klass = kh.GetKlassFromFunc(mirFunc); if (klass != nullptr) { MapleVector *v = klass->GetCandidates(mirFunc->GetBaseFuncNameWithTypeStrIdx()); if (v != nullptr) { @@ -1656,16 +1653,16 @@ MIRFunction *CGNode::HasOneCandidate() const { int count = 0; MIRFunction *cand = nullptr; if (!mirFunc->IsEmpty()) { - count++; + ++count; cand = mirFunc; } /* scan candidates */ - for (uint32 i = 0; i < vcallCands.size(); i++) { + for (uint32 i = 0; i < vcallCands.size(); ++i) { if (vcallCands[i] == nullptr) { - CHECK_FATAL(false, ""); + CHECK_FATAL(false, "must not be nullptr"); } if (!vcallCands[i]->IsEmpty()) { - count++; + ++count; if (cand == nullptr) { cand = vcallCands[i]; } @@ -1676,17 +1673,17 @@ MIRFunction *CGNode::HasOneCandidate() const { AnalysisResult *DoCallGraph::Run(MIRModule *module, ModuleResultMgr *m) { MemPool *memPool = memPoolCtrler.NewMemPool("callgraph mempool"); - KlassHierarchy *cha = static_cast(m->GetAnalysisResult(MoPhase_CHA, module)); - CHECK_FATAL(cha != nullptr, "CHA can't be null"); - CallGraph *cg = memPool->New(module, memPool, cha, module->GetFileName().c_str()); + KlassHierarchy *klassh = static_cast(m->GetAnalysisResult(MoPhase_CHA, module)); + CHECK_FATAL(klassh != nullptr, "CHA can't be null"); + CallGraph *cg = memPool->New(module, memPool, klassh, module->GetFileName().c_str()); cg->debug_flag = TRACE_PHASE; cg->BuildCallGraph(); m->AddResult(GetPhaseID(), *module, *cg); - if (!module->IsInIPA()) { + if (!module->IsInIPA() && module->firstInline) { // do retype MemPool *localMp = memPoolCtrler.NewMemPool(PhaseName()); maple::MIRBuilder dexMirbuilder(module); - Retype retype(module, localMp, dexMirbuilder, cha); + Retype retype(module, localMp, dexMirbuilder, klassh); retype.DoRetype(); memPoolCtrler.DeleteMemPool(localMp); } @@ -1695,13 +1692,12 @@ AnalysisResult *DoCallGraph::Run(MIRModule *module, ModuleResultMgr *m) { AnalysisResult *DoIPODevirtulize::Run(MIRModule *module, ModuleResultMgr *m) { MemPool *memPool = memPoolCtrler.NewMemPool("ipodevirulize mempool"); - KlassHierarchy *cha = static_cast(m->GetAnalysisResult(MoPhase_CHA, module)); - CHECK_FATAL(cha != nullptr, ""); - IPODevirtulize *dev = memPool->New(module, memPool, cha); + KlassHierarchy *klassh = static_cast(m->GetAnalysisResult(MoPhase_CHA, module)); + CHECK_NULL_FATAL(klassh); + IPODevirtulize *dev = memPool->New(module, memPool, klassh); // Devirtualize vcall of final variable dev->DevirtualFinal(); memPoolCtrler.DeleteMemPool(memPool); return nullptr; } - } // namespace maple diff --git a/src/maple_ipa/src/clone.cpp b/src/maple_ipa/src/clone.cpp index 94b16d6770cbae6130521e1ea79f4018d75cf5b2..17c1f4f3797bd266612c299f7f7ce49697dd454e 100644 --- a/src/maple_ipa/src/clone.cpp +++ b/src/maple_ipa/src/clone.cpp @@ -28,24 +28,24 @@ ReplaceRetIgnored::ReplaceRetIgnored(MemPool *memPool) } bool ReplaceRetIgnored::RealShouldReplaceWithVoidFunc(Opcode op, size_t nRetSize, - const MIRFunction *calleeFunc) const { - MIRType *returnType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(calleeFunc->GetReturnTyIdx()); + const MIRFunction &calleeFunc) const { + MIRType *returnType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(calleeFunc.GetReturnTyIdx()); return nRetSize == 0 && (op == OP_virtualcallassigned || op == OP_callassigned || op == OP_superclasscallassigned) && - !calleeFunc->IsNative() && (returnType->GetKind() == kTypePointer) && (returnType->GetPrimType() == PTY_ref); + !calleeFunc.IsNative() && (returnType->GetKind() == kTypePointer) && (returnType->GetPrimType() == PTY_ref); } -bool ReplaceRetIgnored::ShouldReplaceWithVoidFunc(const CallMeStmt *stmt, const MIRFunction *calleeFunc) const { - return RealShouldReplaceWithVoidFunc(stmt->GetOp(), stmt->MustDefListSize(), calleeFunc); +bool ReplaceRetIgnored::ShouldReplaceWithVoidFunc(const CallMeStmt &stmt, const MIRFunction &calleeFunc) const { + return RealShouldReplaceWithVoidFunc(stmt.GetOp(), stmt.MustDefListSize(), calleeFunc); } -std::string ReplaceRetIgnored::GenerateNewBaseName(const MIRFunction *originalFunc) { - return std::string(originalFunc->GetBaseFuncName()).append(kVoidRetSuffix); +std::string ReplaceRetIgnored::GenerateNewBaseName(const MIRFunction &originalFunc) const { + return std::string(originalFunc.GetBaseFuncName()).append(kVoidRetSuffix); } -std::string ReplaceRetIgnored::GenerateNewFullName(const MIRFunction *originalFunc) { - const std::string &oldSignature = originalFunc->GetSignature(); +std::string ReplaceRetIgnored::GenerateNewFullName(const MIRFunction &originalFunc) const { + const std::string &oldSignature = originalFunc.GetSignature(); auto retPos = oldSignature.find("_29"); - return std::string(originalFunc->GetBaseClassName()) + return std::string(originalFunc.GetBaseClassName()) .append(NameMangler::kNameSplitterStr) .append(GenerateNewBaseName(originalFunc)) .append(NameMangler::kNameSplitterStr) @@ -53,102 +53,102 @@ std::string ReplaceRetIgnored::GenerateNewFullName(const MIRFunction *originalFu .append("V"); } -MIRSymbol *Clone::CloneLocalSymbol(const MIRSymbol *oldSym, MIRFunction *newFunc) { - MemPool *newMP = newFunc->GetDataMemPool(); - MIRSymbol *newSym = newMP->New(*oldSym); - if (oldSym->GetSKind() == kStConst) { - newSym->SetKonst(oldSym->GetKonst()->Clone(*newMP)); - } else if (oldSym->GetSKind() == kStPreg) { - newSym->SetPreg(newMP->New(*oldSym->GetPreg())); - } else if (oldSym->GetSKind() == kStFunc) { - CHECK_FATAL(false, "%s has unexpected local func symbol", oldSym->GetName().c_str()); +MIRSymbol *Clone::CloneLocalSymbol(const MIRSymbol &oldSym, const MIRFunction &newFunc) { + MemPool *newMP = newFunc.GetDataMemPool(); + MIRSymbol *newSym = newMP->New(oldSym); + if (oldSym.GetSKind() == kStConst) { + newSym->SetKonst(oldSym.GetKonst()->Clone(*newMP)); + } else if (oldSym.GetSKind() == kStPreg) { + newSym->SetPreg(newMP->New(*oldSym.GetPreg())); + } else if (oldSym.GetSKind() == kStFunc) { + CHECK_FATAL(false, "%s has unexpected local func symbol", oldSym.GetName().c_str()); } return newSym; } -void Clone::CloneSymbols(MIRFunction *newFunc, const MIRFunction *oldFunc) { - size_t symTabSize = oldFunc->GetSymbolTabSize(); - for (size_t i = oldFunc->GetFormalCount() + 1; i < symTabSize; ++i) { - MIRSymbol *sym = oldFunc->GetSymbolTabItem(i); +void Clone::CloneSymbols(MIRFunction &newFunc, const MIRFunction &oldFunc) { + size_t symTabSize = oldFunc.GetSymbolTabSize(); + for (size_t i = oldFunc.GetFormalCount() + 1; i < symTabSize; ++i) { + MIRSymbol *sym = oldFunc.GetSymbolTabItem(i); if (sym == nullptr) { continue; } - MIRSymbol *newSym = CloneLocalSymbol(sym, newFunc); - if (!newFunc->GetSymTab()->AddStOutside(newSym)) { - CHECK_FATAL(false, "%s already existed in func %s", sym->GetName().c_str(), newFunc->GetName().c_str()); + MIRSymbol *newSym = CloneLocalSymbol(*sym, newFunc); + if (!newFunc.GetSymTab()->AddStOutside(newSym)) { + CHECK_FATAL(false, "%s already existed in func %s", sym->GetName().c_str(), newFunc.GetName().c_str()); } } } -void Clone::CloneLabels(MIRFunction *newFunc, const MIRFunction *oldFunc) { - size_t labelTabSize = oldFunc->GetLabelTab()->GetLabelTableSize(); +void Clone::CloneLabels(MIRFunction &newFunc, const MIRFunction &oldFunc) { + size_t labelTabSize = oldFunc.GetLabelTab()->GetLabelTableSize(); for (size_t i = 1; i < labelTabSize; ++i) { - const std::string &labelName = oldFunc->GetLabelTabItem(i); + const std::string &labelName = oldFunc.GetLabelTabItem(i); GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(labelName); - newFunc->GetLabelTab()->AddLabel(strIdx); + newFunc.GetLabelTab()->AddLabel(strIdx); } } // Clone a function -MIRFunction *Clone::CloneFunction(MIRFunction *originalFunction, const std::string &newBaseFuncName, - MIRType *returnType) { - MapleAllocator cgAlloc(originalFunction->GetCodeMempool()); +MIRFunction *Clone::CloneFunction(MIRFunction &originalFunction, const std::string &newBaseFuncName, + MIRType *returnType) const { + MapleAllocator cgAlloc(originalFunction.GetCodeMempool()); ArgVector argument(cgAlloc.Adapter()); CloneArgument(originalFunction, argument); MIRType *retType = returnType; if (retType == nullptr) { - retType = originalFunction->GetReturnType(); + retType = originalFunction.GetReturnType(); } - std::string fullName = originalFunction->GetBaseClassName(); - const std::string &signature = originalFunction->GetSignature(); + std::string fullName = originalFunction.GetBaseClassName(); + const std::string &signature = originalFunction.GetSignature(); fullName = fullName.append(NameMangler::kNameSplitterStr) .append(newBaseFuncName) .append(NameMangler::kNameSplitterStr) .append(signature); MIRFunction *newFunc = - dexBuilder.CreateFunction(fullName, *retType, argument, false, originalFunction->GetBody() != nullptr); + dexBuilder.CreateFunction(fullName, *retType, argument, false, originalFunction.GetBody() != nullptr); CHECK_FATAL(newFunc != nullptr, "create cloned function failed"); dexBuilder.GetMirModule().AddFunction(newFunc); - Klass *klass = kh->GetKlassFromName(originalFunction->GetBaseClassName()); + Klass *klass = kh->GetKlassFromName(originalFunction.GetBaseClassName()); CHECK_FATAL(klass != nullptr, "getklass failed"); klass->AddMethod(newFunc); - newFunc->SetClassTyIdx(originalFunction->GetClassTyIdx()); + newFunc->SetClassTyIdx(originalFunction.GetClassTyIdx()); MIRClassType *classType = klass->GetMIRClassType(); classType->GetMethods().push_back( MethodPair(newFunc->GetStIdx(), TyidxFuncAttrPair(newFunc->GetFuncSymbol()->GetTyIdx(), - originalFunction->GetFuncAttrs()))); - newFunc->SetFlag(originalFunction->GetFlag()); - newFunc->SetSrcPosition(originalFunction->GetSrcPosition()); - newFunc->SetFuncAttrs(originalFunction->GetFuncAttrs()); + originalFunction.GetFuncAttrs()))); + newFunc->SetFlag(originalFunction.GetFlag()); + newFunc->SetSrcPosition(originalFunction.GetSrcPosition()); + newFunc->SetFuncAttrs(originalFunction.GetFuncAttrs()); newFunc->SetBaseClassFuncNames(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(fullName)); - if (originalFunction->GetBody()) { + if (originalFunction.GetBody() != nullptr) { CopyFuncInfo(originalFunction, newFunc); MIRFunction *originalCurrFunction = dexBuilder.GetCurrentFunctionNotNull(); dexBuilder.SetCurrentFunction(*newFunc); newFunc->SetBody( - originalFunction->GetBody()->CloneTree(originalFunction->GetModule()->GetCurFuncCodeMPAllocator())); - CloneSymbols(newFunc, originalFunction); - CloneLabels(newFunc, originalFunction); + originalFunction.GetBody()->CloneTree(originalFunction.GetModule()->GetCurFuncCodeMPAllocator())); + CloneSymbols(*newFunc, originalFunction); + CloneLabels(*newFunc, originalFunction); dexBuilder.SetCurrentFunction(*originalCurrFunction); } return newFunc; } -void Clone::CloneArgument(MIRFunction *originalFunction, ArgVector &argument) const { - for (size_t i = 0; i < originalFunction->GetFormalCount(); ++i) { - argument.push_back(ArgPair(originalFunction->GetFormal(i)->GetName(), originalFunction->GetNthParamType(i))); +void Clone::CloneArgument(MIRFunction &originalFunction, ArgVector &argument) const { + for (size_t i = 0; i < originalFunction.GetFormalCount(); ++i) { + argument.push_back(ArgPair(originalFunction.GetFormal(i)->GetName(), originalFunction.GetNthParamType(i))); } } -void Clone::CopyFuncInfo(const MIRFunction *originalFunction, MIRFunction *newFunc) const { +void Clone::CopyFuncInfo(const MIRFunction &originalFunction, MIRFunction *newFunc) const { auto funcNameIdx = newFunc->GetBaseFuncNameStrIdx(); auto fullNameIdx = newFunc->GetNameStrIdx(); auto classNameIdx = newFunc->GetBaseClassNameStrIdx(); auto metaFullNameIdx = dexBuilder.GetOrCreateStringIndex(kFullNameStr); auto metaClassNameIdx = dexBuilder.GetOrCreateStringIndex(kClassNameStr); auto metaFuncNameIdx = dexBuilder.GetOrCreateStringIndex(kFuncNameStr); - const MIRInfoVector &fnInfo = originalFunction->GetInfoVector(); - const MapleVector &infoIsString = originalFunction->InfoIsString(); + const MIRInfoVector &fnInfo = originalFunction.GetInfoVector(); + const MapleVector &infoIsString = originalFunction.InfoIsString(); size_t size = fnInfo.size(); for (size_t i = 0; i < size; ++i) { if (fnInfo[i].first == metaFullNameIdx) { @@ -180,8 +180,8 @@ void Clone::UpdateFuncInfo(MIRFunction *newFunc) { // @param original_function The original function to be cloned // @param dexBuilder A helper object // @return Pointer to the newly cloned function -MIRFunction *Clone::CloneFunctionNoReturn(MIRFunction *originalFunction) { - const std::string oldSignature = originalFunction->GetSignature(); +MIRFunction *Clone::CloneFunctionNoReturn(MIRFunction &originalFunction) { + const std::string oldSignature = originalFunction.GetSignature(); const std::string kNewMethodBaseName = replaceRetIgnored->GenerateNewBaseName(originalFunction); MIRFunction *originalCurrFunction = dexBuilder.GetMirModule().CurFunction(); MIRFunction *newFunction = @@ -190,7 +190,7 @@ MIRFunction *Clone::CloneFunctionNoReturn(MIRFunction *originalFunction) { // new stmt should be located in the newFunction->codemp, dexBuilder.CreateStmtReturn will use CurFunction().codemp // to assign space for the new stmt. So we set it correctly here. dexBuilder.GetMirModule().SetCurFunction(newFunction); - if (originalFunction->GetBody()) { + if (originalFunction.GetBody() != nullptr) { auto *body = newFunction->GetBody(); for (auto &stmt : body->GetStmtNodes()) { if (stmt.GetOpCode() == OP_return) { @@ -211,17 +211,17 @@ MIRFunction *Clone::CloneFunctionNoReturn(MIRFunction *originalFunction) { return newFunction; } -void Clone::UpdateReturnVoidIfPossible(CallMeStmt *callMeStmt, const MIRFunction *targetFunc) { - if (callMeStmt) { - if (replaceRetIgnored->ShouldReplaceWithVoidFunc(callMeStmt, targetFunc)) { - if (replaceRetIgnored->IsInCloneList(targetFunc->GetName())) { - std::string funcNameReturnVoid = replaceRetIgnored->GenerateNewFullName(targetFunc); - GStrIdx gStrIdx = GlobalTables::GetStrTable().GetStrIdxFromName(funcNameReturnVoid); - MIRFunction *funcReturnVoid = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(gStrIdx)->GetFunction(); - CHECK_FATAL(nullptr != funcReturnVoid, "target function not found at ssadevirtual"); - callMeStmt->SetPUIdx(funcReturnVoid->GetPuidx()); - } - } +void Clone::UpdateReturnVoidIfPossible(CallMeStmt *callMeStmt, const MIRFunction &targetFunc) { + if (callMeStmt == nullptr) { + return; + } + if (replaceRetIgnored->ShouldReplaceWithVoidFunc(*callMeStmt, targetFunc) && + replaceRetIgnored->IsInCloneList(targetFunc.GetName())) { + std::string funcNameReturnVoid = replaceRetIgnored->GenerateNewFullName(targetFunc); + GStrIdx gStrIdx = GlobalTables::GetStrTable().GetStrIdxFromName(funcNameReturnVoid); + MIRFunction *funcReturnVoid = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(gStrIdx)->GetFunction(); + CHECK_FATAL(funcReturnVoid != nullptr, "target function not found at ssadevirtual"); + callMeStmt->SetPUIdx(funcReturnVoid->GetPuidx()); } } @@ -230,11 +230,11 @@ void Clone::DoClone() { for (const MapleString &funcName : *(replaceRetIgnored->GetTobeClonedFuncNames())) { GStrIdx gStrIdx = GlobalTables::GetStrTable().GetStrIdxFromName(std::string(funcName.c_str())); MIRSymbol *symbol = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(gStrIdx); - if (nullptr != symbol) { + if (symbol != nullptr) { GStrIdx gStrIdxOfFunc = GlobalTables::GetStrTable().GetStrIdxFromName(std::string(funcName.c_str())); MIRFunction *oriFunc = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(gStrIdxOfFunc)->GetFunction(); mirModule->SetCurFunction(oriFunc); - clonedNewFuncMap.insert(CloneFunctionNoReturn(oriFunc)->GetName()); + clonedNewFuncMap.insert(CloneFunctionNoReturn(*oriFunc)->GetName()); } } } @@ -248,5 +248,4 @@ AnalysisResult *DoClone::Run(MIRModule *module, ModuleResultMgr *mrm) { mrm->AddResult(GetPhaseID(), *module, *clone); return clone; } - } // namespace maple diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index feeb781a66908a038e31351ceb2c59ed10abf6ab..78ee584e87f06950fe0832a0405125be5cac46e2 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -759,7 +759,7 @@ class MIRFunction { retRefSym.insert(sym); } - MemPool *GetDataMemPool() { + MemPool *GetDataMemPool() const { return module->GetMemPool(); } diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 15912a86204707ea5c59a792d4f70f943f879629..31e080d4b82be0db9ff378e093a456edf463d218 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -114,6 +114,7 @@ class MIRTypeNameTable { class MIRModule { public: + bool firstInline = true; using CallSite = std::pair; explicit MIRModule(const std::string &fn = ""); diff --git a/src/maple_ir/include/mir_nodes.h b/src/maple_ir/include/mir_nodes.h index 958b34fc3439a3e3e48249ddd2ac3972fb5dbfdb..e58fbd8aa191548515f0e41f36a3cea0da5ef3e5 100644 --- a/src/maple_ir/include/mir_nodes.h +++ b/src/maple_ir/include/mir_nodes.h @@ -532,13 +532,13 @@ class BinaryOpnds { virtual void Dump(int32 indent) const; - BaseNode *GetBOpnd(int32 i) const { - CHECK_FATAL(i >= 0 && i < kOperandNumBinary, "Invalid operand idx in BinaryOpnds"); + BaseNode *GetBOpnd(size_t i) const { + CHECK_FATAL(i < kOperandNumBinary, "Invalid operand idx in BinaryOpnds"); return bOpnd[i]; } - void SetBOpnd(BaseNode *node, int32 i) { - CHECK_FATAL(i >= 0 && i < kOperandNumBinary, "Invalid operand idx in BinaryOpnds"); + void SetBOpnd(BaseNode *node, size_t i) { + CHECK_FATAL(i < kOperandNumBinary, "Invalid operand idx in BinaryOpnds"); bOpnd[i] = node; } diff --git a/src/maple_ir/include/types_def.h b/src/maple_ir/include/types_def.h index 3d9be38a1b3bd6d4a69e80385e5ba8cb8bd179c1..32311090f0e597ae4787d9459cefe70e7f1061b7 100644 --- a/src/maple_ir/include/types_def.h +++ b/src/maple_ir/include/types_def.h @@ -121,8 +121,8 @@ using U16StrIdx = utils::Index; // user string table index ( const TyIdx kInitTyIdx = TyIdx(0); const TyIdx kNoneTyIdx = TyIdx(UINT32_MAX); -constexpr int kOperandNumUnary = 1; -constexpr int kOperandNumBinary = 2; -constexpr int kOperandNumTernary = 3; +constexpr uint8 kOperandNumUnary = 1; +constexpr uint8 kOperandNumBinary = 2; +constexpr uint8 kOperandNumTernary = 3; } // namespace maple #endif // MAPLE_IR_INCLUDE_TYPES_DEF_H diff --git a/src/maple_ir/src/global_tables.cpp b/src/maple_ir/src/global_tables.cpp index f521c25c1ca433b0f656e2c905d8abf1e57a06af..4a0af15f2930a45d17ee56a3e44a1bc67dc432e5 100644 --- a/src/maple_ir/src/global_tables.cpp +++ b/src/maple_ir/src/global_tables.cpp @@ -47,7 +47,7 @@ void TypeTable::SetTypeWithTyIdx(const TyIdx &tyIdx, MIRType &type) { MIRType *oldType = typeTable.at(tyIdx); typeTable.at(tyIdx) = &type; if (oldType != nullptr && oldType != &type) { - typeHashTable.erase(oldType); + (void)typeHashTable.erase(oldType); delete oldType; } } diff --git a/src/maple_me/include/hdse.h b/src/maple_me/include/hdse.h index 293cd9ecb66333468bdf1b48633dcf1c6f7946b0..7e5eeee5ee6811531f34e866f421677e439b6d2b 100644 --- a/src/maple_me/include/hdse.h +++ b/src/maple_me/include/hdse.h @@ -72,10 +72,10 @@ class HDSE { bool NeedNotNullCheck(MeExpr &meExpr, const BB &bb); bool IsExprNeeded(const MeExpr &meExpr) const { - return exprLive.at(meExpr.GetExprID()); + return exprLive.at(static_cast(static_cast(meExpr.GetExprID()))); } void SetExprNeeded(const MeExpr &meExpr) { - exprLive.at(meExpr.GetExprID()) = true; + exprLive.at(static_cast(static_cast(meExpr.GetExprID()))) = true; } void PropagateLive() { diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index 9282ba943c364098d6399924ccb1e33e7a8fecc3..fc2682d17472fbb69ac233076e8713049e888f42 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -104,10 +104,10 @@ class MeExpr { return next; } - void InitBase(Opcode op, PrimType primType, uint32 numOpnds) { - this->op = op; - this->primType = primType; - this->numOpnds = static_cast(numOpnds); + void InitBase(Opcode opcode, PrimType primaryType, size_t opndsNum) { + this->op = opcode; + this->primType = primaryType; + this->numOpnds = static_cast(opndsNum); } virtual void Dump(const IRMap*, int32 indent = 0) const { @@ -952,7 +952,7 @@ class IvarMeExpr : public MeExpr { public: explicit IvarMeExpr(int32 exprid) : MeExpr(exprid, kMeOpIvar) { - SetNumOpnds(kOperandNumUnary); + SetNumOpnds(static_cast(kOperandNumUnary)); } IvarMeExpr(int32 exprid, const IvarMeExpr &ivarme) @@ -1175,7 +1175,7 @@ class MeStmt { return nullptr; } - virtual void SetOpnd(uint32, MeExpr*) {} + virtual void SetOpnd(size_t, MeExpr*) {} bool IsAssertBce() const { return op == OP_assertlt || op == OP_assertge; @@ -1562,7 +1562,7 @@ class DassignMeStmt : public MeStmt { return rhs; } - void SetOpnd(uint32, MeExpr *val) { + void SetOpnd(size_t, MeExpr *val) { rhs = val; } @@ -1691,7 +1691,7 @@ class RegassignMeStmt : public MeStmt { return rhs; } - void SetOpnd(uint32, MeExpr *val) { + void SetOpnd(size_t, MeExpr *val) { rhs = val; } @@ -1757,7 +1757,7 @@ class MaydassignMeStmt : public MeStmt { return rhs; } - void SetOpnd(uint32, MeExpr *val) { + void SetOpnd(size_t, MeExpr *val) { rhs = val; } @@ -1888,7 +1888,7 @@ class IassignMeStmt : public MeStmt { return idx == 0 ? lhsVar->GetBase() : rhs; } - void SetOpnd(uint32 idx, MeExpr *val) { + void SetOpnd(size_t idx, MeExpr *val) { if (idx == 0) { lhsVar->SetBase(val); } else { @@ -1984,7 +1984,7 @@ class NaryMeStmt : public MeStmt { return opnds.at(idx); } - void SetOpnd(uint32 idx, MeExpr *val) { + void SetOpnd(size_t idx, MeExpr *val) { opnds[idx] = val; } @@ -2441,7 +2441,7 @@ class UnaryMeStmt : public MeStmt { return opnd; } - void SetOpnd(uint32, MeExpr *val) { + void SetOpnd(size_t, MeExpr *val) { opnd = val; } @@ -2654,7 +2654,7 @@ class ThrowMeStmt : public WithMuMeStmt { return opnd; } - void SetOpnd(uint32, MeExpr *val) { + void SetOpnd(size_t, MeExpr *val) { opnd = val; } @@ -2727,7 +2727,7 @@ class AssertMeStmt : public MeStmt { return opnds[0]; } - void SetOpnd(uint32 i, MeExpr *opnd) override { + void SetOpnd(size_t i, MeExpr *opnd) override { CHECK_FATAL(i < kOperandNumBinary, "AssertMeStmt has two opnds"); opnds[i] = opnd; } diff --git a/src/maple_me/include/me_ssa_epre.h b/src/maple_me/include/me_ssa_epre.h index 5419c4c63dd96295167b03ba9f871ce06bb88984..a02b11c2908422ab4b6533ae7e8207013ccbe0aa 100644 --- a/src/maple_me/include/me_ssa_epre.h +++ b/src/maple_me/include/me_ssa_epre.h @@ -72,10 +72,10 @@ class MeSSAEPre : public SSAEPre { void EnterCandsForSSAUpdate(OStIdx ostIdx, const BB &bb) override { if (candsForSSAUpdate.find(ostIdx) == candsForSSAUpdate.end()) { MapleSet *bbSet = ssaPreMemPool->New>(std::less(), ssaPreAllocator.Adapter()); - bbSet->insert(bb.GetBBId()); + (void)bbSet->insert(bb.GetBBId()); candsForSSAUpdate[ostIdx] = bbSet; } else { - candsForSSAUpdate[ostIdx]->insert(bb.GetBBId()); + (void)candsForSSAUpdate[ostIdx]->insert(bb.GetBBId()); } } }; diff --git a/src/maple_me/include/me_store_pre.h b/src/maple_me/include/me_store_pre.h index 94aa0f4807c8e35dac5b0e1164d1b36c72b7555f..4809f38c289078f5eb6a3e5288cc0a62de9f6fb7 100644 --- a/src/maple_me/include/me_store_pre.h +++ b/src/maple_me/include/me_store_pre.h @@ -35,8 +35,8 @@ class MeStorePre : public MeSSUPre { RegMeExpr *EnsureRHSInCurTemp(BB &bb); void CodeMotion(); // step 0 methods - void CreateRealOcc(OStIdx ostIdx, MeStmt &meStmt); - void CreateUseOcc(OStIdx ostIdx, BB &bb) const; + void CreateRealOcc(const OStIdx &ostIdx, MeStmt &meStmt); + void CreateUseOcc(const OStIdx &ostIdx, BB &bb) const; void CreateSpreUseOccsThruAliasing(const OriginalSt &muOst, BB &bb) const; void FindAndCreateSpreUseOccs(const MeExpr &meExpr, BB &bb) const; void CreateSpreUseOccsForAll(BB &bb) const; diff --git a/src/maple_me/include/ssa_tab.h b/src/maple_me/include/ssa_tab.h index da2e7e094635f1b0e8101fd02bdf6715e7e348cd..0f43c223da30884aa6fea3a62b51d54f2e9b1c24 100644 --- a/src/maple_me/include/ssa_tab.h +++ b/src/maple_me/include/ssa_tab.h @@ -97,6 +97,10 @@ class SSATab : public AnalysisResult { return originalStTable; } + const OriginalStTable &GetOriginalStTable() const { + return originalStTable; + } + size_t GetOriginalStTableSize() const { return originalStTable.Size(); } diff --git a/src/maple_me/src/me_bypath_eh.cpp b/src/maple_me/src/me_bypath_eh.cpp index b29df12427382b040e5cec5fa8cae4a9e892acd2..cb77b6d296b6f6e2b3de1f2fe1de0643a4ecd447 100644 --- a/src/maple_me/src/me_bypath_eh.cpp +++ b/src/maple_me/src/me_bypath_eh.cpp @@ -25,7 +25,7 @@ bool MeDoBypathEH::DoBypathException(BB *tryBB, BB *catchBB, const Klass *catchC std::vector tryBBV; std::set tryBBS; tryBBV.push_back(tryBB); - tryBBS.insert(tryBB); + (void)tryBBS.insert(tryBB); uint32 idx = 0; bool transformed = false; while (idx < tryBBV.size()) { @@ -211,7 +211,7 @@ void MeDoBypathEH::BypathException(MeFunction &func, const KlassHierarchy &kh) c if (visited.find(bb) != visited.end()) { continue; } - visited.emplace(bb); + (void)visited.emplace(bb); for (StmtNode *stmt = &bb->GetFirst(); stmt != nullptr && stmt != bb->GetLast().GetNext(); stmt = stmt->GetNext()) { if (stmt->GetOpCode() != OP_try) { continue; diff --git a/src/maple_me/src/me_delegate_rc.cpp b/src/maple_me/src/me_delegate_rc.cpp index d7d03109ad9447b9f7a842503f2ce86bef815074..52463980fa19f651edbd891b39b3f06af29a56a4 100644 --- a/src/maple_me/src/me_delegate_rc.cpp +++ b/src/maple_me/src/me_delegate_rc.cpp @@ -648,7 +648,7 @@ void DelegateRC::RenameDelegatedRefVarUses(MeStmt &meStmt, MeExpr &meExpr) { auto &varMeExpr = static_cast(meExpr); auto it = refVar2RegMap.find(&varMeExpr); if (it != refVar2RegMap.end()) { - irMap.ReplaceMeExprStmt(meStmt, varMeExpr, *it->second); + (void)irMap.ReplaceMeExprStmt(meStmt, varMeExpr, *it->second); } } } @@ -714,7 +714,7 @@ std::set DelegateRC::RenameAndGetLiveLocalRefVar() { CHECK_FATAL(lhs != nullptr, "null ptr check"); const OriginalSt *ost = ssaTab.GetOriginalStFromID(lhs->GetOStIdx()); if (ost->IsLocal() && !ost->IsFormal() && !ost->IsIgnoreRC() && lhs->GetPrimType() == PTY_ref) { - liveLocalrefvars.insert(lhs->GetOStIdx()); + (void)liveLocalrefvars.insert(lhs->GetOStIdx()); } } else if (kOpcodeInfo.IsCallAssigned(stmt.GetOp())) { MapleVector *mustdefList = stmt.GetMustDefList(); @@ -727,7 +727,7 @@ std::set DelegateRC::RenameAndGetLiveLocalRefVar() { auto *varLhs = static_cast(theLhs); const OriginalSt *ost = ssaTab.GetOriginalStFromID(varLhs->GetOStIdx()); if (ost->IsLocal() && !ost->IsFormal() && !ost->IsIgnoreRC()) { - liveLocalrefvars.insert(varLhs->GetOStIdx()); + (void)liveLocalrefvars.insert(varLhs->GetOStIdx()); } } } diff --git a/src/maple_me/src/me_loop_analysis.cpp b/src/maple_me/src/me_loop_analysis.cpp index f29d4889867e235a33548034017401aff18b2f49..6278e2a0b77c03faa4cf735f39e5b78663077ada 100644 --- a/src/maple_me/src/me_loop_analysis.cpp +++ b/src/maple_me/src/me_loop_analysis.cpp @@ -97,13 +97,13 @@ void IdentifyLoops::ProcessBB(BB *bb) { if (curr == bb || loop->loopBBs.count(curr->GetBBId()) == 1) { continue; } - loop->loopBBs.insert(curr->GetBBId()); + (void)loop->loopBBs.insert(curr->GetBBId()); SetLoopParent4BB(*curr, *loop); for (BB *curPred : curr->GetPred()) { bodyList.push_back(curPred); } } - loop->loopBBs.insert(bb->GetBBId()); + (void)loop->loopBBs.insert(bb->GetBBId()); SetLoopParent4BB(*bb, *loop); } } diff --git a/src/maple_me/src/me_loop_canon.cpp b/src/maple_me/src/me_loop_canon.cpp index 0a5f2a1492d6216fb19a78c7313e7f7c98a0c091..ffb01c747454b57f6fefcbdc0a6d5a68cad38328 100644 --- a/src/maple_me/src/me_loop_canon.cpp +++ b/src/maple_me/src/me_loop_canon.cpp @@ -79,7 +79,7 @@ bool MeDoLoopCanon::NeedConvert(BB &bb, BB &pred, MapleAllocator &localAlloc, Ma if (curr == &bb || inLoop.count(curr->GetBBId()) == 1) { continue; } - inLoop.insert(curr->GetBBId()); + (void)inLoop.insert(curr->GetBBId()); for (BB *tmpPred : curr->GetPred()) { ASSERT_NOT_NULL(tmpPred); bodyList.push_back(tmpPred); @@ -92,7 +92,7 @@ bool MeDoLoopCanon::NeedConvert(BB &bb, BB &pred, MapleAllocator &localAlloc, Ma // other case // fallthru is in loop body, latchBB need swap succs if (inLoop.count(bb.GetSucc().at(0)->GetBBId()) == 1) { - swapSuccs.insert(make_pair(std::make_pair(&bb, &pred), true)); + (void)swapSuccs.insert(make_pair(std::make_pair(&bb, &pred), true)); } return true; } diff --git a/src/maple_me/src/me_rename2preg.cpp b/src/maple_me/src/me_rename2preg.cpp index 2bd0dd2d450b92c88b7d0c76ef33f4bcbd8c220c..dcdb5972267054f38b006df6487fd913c951a5e9 100644 --- a/src/maple_me/src/me_rename2preg.cpp +++ b/src/maple_me/src/me_rename2preg.cpp @@ -80,7 +80,7 @@ class PregCache final { } RegMeExpr *regExpr = creator(irMap); - cache.insert(std::make_pair(varExpr.GetExprID(), regExpr)); + (void)cache.insert(std::make_pair(varExpr.GetExprID(), regExpr)); return utils::ToRef(regExpr); } @@ -88,7 +88,7 @@ class PregCache final { MIRType &ty = utils::ToRef(GlobalTables::GetTypeTable().GetTypeFromTyIdx(symbolIdx)); RegMeExpr *regExpr = ty.GetPrimType() == PTY_ref ? irMap.CreateRegRefMeExpr(ty) : irMap.CreateRegMeExpr(varExpr.GetPrimType()); - cache.insert(std::make_pair(varExpr.GetExprID(), regExpr)); + (void)cache.insert(std::make_pair(varExpr.GetExprID(), regExpr)); return utils::ToRef(regExpr); } @@ -153,8 +153,9 @@ class FormalRenaming final { // in this case, the paramter is not used by any statement, promote it MIRType &irTy = utils::ToRef(irFunc.GetNthParamType(i)); MIRPregTable &irPregTbl = utils::ToRef(irFunc.GetPregTab()); - PregIdx16 regIdx = (irTy.GetPrimType() == PTY_ref) ? irPregTbl.CreateRefPreg(irTy) - : irPregTbl.CreatePreg(irTy.GetPrimType()); + PregIdx16 regIdx = (irTy.GetPrimType() == PTY_ref) ? + static_cast(irPregTbl.CreateRefPreg(irTy)) : + static_cast(irPregTbl.CreatePreg(irTy.GetPrimType())); irFunc.SetFormal(i, irBuilder.CreatePregFormalSymbol(irTy.GetTypeIndex(), regIdx, irFunc)); } else { RegMeExpr *regExpr = renamedReg[i]; @@ -346,7 +347,7 @@ class SSARename2Preg { return irMap.CreateRegMeExprVersion(curRegExpr); }); regPhiNode.GetOpnds().push_back(®Expr); - regExpr.GetPhiUseSet().insert(®PhiNode); + (void)regExpr.GetPhiUseSet().insert(®PhiNode); } } diff --git a/src/maple_me/src/me_ssa_epre.cpp b/src/maple_me/src/me_ssa_epre.cpp index 4f1471b870046c039d5f262a01dde288ef6df0db..7c55a029a5e464afc73371222966784c33efb19b 100644 --- a/src/maple_me/src/me_ssa_epre.cpp +++ b/src/maple_me/src/me_ssa_epre.cpp @@ -26,7 +26,7 @@ void MeSSAEPre::GetIterDomFrontier(const BB &bb, MapleSet &dfSet, std::v } visitedMap[bb.GetBBId()] = true; for (BBId frontierBBId : dom->GetDomFrontier(bb.GetBBId())) { - dfSet.insert(dom->GetDtDfnItem(frontierBBId)); + (void)dfSet.insert(dom->GetDtDfnItem(frontierBBId)); BB *frontierBB = GetBB(frontierBBId); GetIterDomFrontier(*frontierBB, dfSet, visitedMap); } diff --git a/src/maple_me/src/me_ssa_lpre.cpp b/src/maple_me/src/me_ssa_lpre.cpp index 71eae551432b9261cebcadf69ab1c837093ae7a4..42352995df0cbf2fd6b2d6d4c96daf8457676571 100644 --- a/src/maple_me/src/me_ssa_lpre.cpp +++ b/src/maple_me/src/me_ssa_lpre.cpp @@ -139,7 +139,7 @@ void MeSSALPre::GetIterDomFrontier(const BB &bb, MapleSet &dfSet, std::v visitedMap[bb.GetBBId()] = true; CHECK_FATAL(bb.GetBBId() < dom->GetDomFrontierSize(), "index out of range in MeSSALPre::GetIterDomFrontier"); for (BBId frontierBBId : dom->GetDomFrontier(bb.GetBBId())) { - dfSet.insert(dom->GetDtDfnItem(frontierBBId)); + (void)dfSet.insert(dom->GetDtDfnItem(frontierBBId)); BB *frontierBB = GetBB(frontierBBId); GetIterDomFrontier(*frontierBB, dfSet, visitedMap); } @@ -184,7 +184,7 @@ void MeSSALPre::BuildEntryLHSOcc4Formals() const { VarMeExpr *zeroVersion = irMap->GetOrCreateZeroVersionVarMeExpr(*ost); MeRealOcc *occ = ssaPreMemPool->New(nullptr, 0, zeroVersion); auto occIt = workCand->GetRealOccs().begin(); - workCand->GetRealOccs().insert(occIt, occ); // insert at beginning + (void)workCand->GetRealOccs().insert(occIt, occ); // insert at beginning occ->SetIsLHS(true); occ->SetIsFormalAtEntry(true); occ->SetBB(*func->GetFirstBB()); @@ -199,7 +199,7 @@ void MeSSALPre::BuildWorkListLHSOcc(MeStmt &meStmt, int32 seqStmt) { CHECK_NULL_FATAL(lhs); const OriginalSt *ost = ssaTab->GetSymbolOriginalStFromID(lhs->GetOStIdx()); if (ost->IsFormal()) { - assignedFormals.insert(ost->GetIndex()); + (void)assignedFormals.insert(ost->GetIndex()); } CHECK_NULL_FATAL(meStmt.GetRHS()); if (ost->IsVolatile()) { @@ -220,7 +220,7 @@ void MeSSALPre::BuildWorkListLHSOcc(MeStmt &meStmt, int32 seqStmt) { auto *theLHS = static_cast(mustDefList->front().GetLHS()); const OriginalSt *ost = ssaTab->GetOriginalStFromID(theLHS->GetOStIdx()); if (ost->IsFormal()) { - assignedFormals.insert(ost->GetIndex()); + (void)assignedFormals.insert(ost->GetIndex()); } if (theLHS->GetPrimType() == PTY_ref && !MeOption::rcLowering) { return; @@ -249,7 +249,7 @@ void MeSSALPre::CreateMembarOccAtCatch(BB &bb) { auto *varMeExpr = static_cast(workCand->GetTheMeExpr()); const OriginalSt *ost = ssaTab->GetOriginalStFromID(varMeExpr->GetOStIdx()); if (ost->IsFormal()) { - assignedFormals.insert(ost->GetIndex()); + (void)assignedFormals.insert(ost->GetIndex()); } } } @@ -343,7 +343,7 @@ void MeSSALPre::BuildWorkList() { void MeSSALPre::FindLoopHeadBBs(const IdentifyLoops &identLoops) { for (LoopDesc *mapleLoop : identLoops.GetMeLoops()) { if (mapleLoop->head != nullptr) { - loopHeadBBs.insert(mapleLoop->head->GetBBId()); + (void)loopHeadBBs.insert(mapleLoop->head->GetBBId()); } } } diff --git a/src/maple_me/src/me_ssu_pre.cpp b/src/maple_me/src/me_ssu_pre.cpp index 0224f7272aadbccfa2d06dd1ffb38e2b333e5637..3df638506d963cf28bfd635dbd878360cf9fed5c 100644 --- a/src/maple_me/src/me_ssu_pre.cpp +++ b/src/maple_me/src/me_ssu_pre.cpp @@ -52,7 +52,7 @@ void MeSSUPre::Finalize() { BB *insertBB = &lambdaResOcc->GetBB(); if (insertBB->GetAttributes(kBBAttrIsCatch)) { if (preKind == kDecrefPre) { - catchBlocks2Insert.insert(insertBB->GetBBId()); + (void)catchBlocks2Insert.insert(insertBB->GetBBId()); } // else { kStorePre: omit insertion at entry of catch blocks } break; } @@ -368,7 +368,7 @@ void MeSSUPre::GetIterPdomFrontier(const BB &bb, MapleSet &pdfSet, std:: CHECK_FATAL(!visitedMap.empty(), "visitedMap in MeSSUPre::GetIterPdomFrontier is empty"); visitedMap[bb.GetBBId()] = true; for (BBId frontierBBId : dom->GetPdomFrontierItem(bb.GetBBId())) { - pdfSet.insert(dom->GetPdtDfnItem(frontierBBId)); + (void)pdfSet.insert(dom->GetPdtDfnItem(frontierBBId)); } CHECK_NULL_FATAL(func); for (BBId frontierBBId : dom->GetPdomFrontierItem(bb.GetBBId())) { @@ -398,7 +398,7 @@ void MeSSUPre::CreateSortedOccs() { const BBId &bbId = dom->GetPdtPreOrderItem(dfn); BB *bb = func->GetAllBBs().at(bbId); for (BB *succ : bb->GetSucc()) { - lambdaResDfns.insert(dom->GetPdtDfnItem(succ->GetBBId())); + (void)lambdaResDfns.insert(dom->GetPdtDfnItem(succ->GetBBId())); } } allOccs.clear(); diff --git a/src/maple_me/src/me_stmt_fre.cpp b/src/maple_me/src/me_stmt_fre.cpp index d8af9ff561b2358173ae3c0bde538ecf39e48157..7a2deef9f19f1d3136ce024ccbdc1b799c753de5 100644 --- a/src/maple_me/src/me_stmt_fre.cpp +++ b/src/maple_me/src/me_stmt_fre.cpp @@ -112,7 +112,7 @@ void MeStmtPre::Rename1StmtFre() { if (isAllDom) { realOcc->SetClassID(topOccur->GetClassID()); realOcc->SetDef(topOccur); - rename2Set.insert(realOcc->GetPosition()); + (void)rename2Set.insert(realOcc->GetPosition()); occStack.push(realOcc); } else { // assign new class diff --git a/src/maple_me/src/me_stmt_pre.cpp b/src/maple_me/src/me_stmt_pre.cpp index e1a1840c3de192f45cd80e14d25eb0b7057a8b60..c9cdb698ef9970c0720dc60d333456b8b4fd7d88 100644 --- a/src/maple_me/src/me_stmt_pre.cpp +++ b/src/maple_me/src/me_stmt_pre.cpp @@ -32,7 +32,7 @@ void MeStmtPre::GetIterDomFrontier(const BB &bb, MapleSet &dfSet, std::v } visitedMap[bb.GetBBId()] = true; for (BBId frontierBBId : dom->GetDomFrontier(bb.GetBBId())) { - dfSet.insert(dom->GetDtDfnItem(frontierBBId)); + (void)dfSet.insert(dom->GetDtDfnItem(frontierBBId)); BB *frontierBB = GetBB(frontierBBId); GetIterDomFrontier(*frontierBB, dfSet, visitedMap); } @@ -84,10 +84,10 @@ void MeStmtPre::CodeMotion() { if (candsForSSAUpdate.find(ostIdx) == candsForSSAUpdate.end()) { MapleSet *bbSet = ssaPreMemPool->New>(std::less(), ssaPreAllocator.Adapter()); - bbSet->insert(occ->GetBB()->GetBBId()); + (void)bbSet->insert(occ->GetBB()->GetBBId()); candsForSSAUpdate[ostIdx] = bbSet; } else { - candsForSSAUpdate[ostIdx]->insert(occ->GetBB()->GetBBId()); + (void)candsForSSAUpdate[ostIdx]->insert(occ->GetBB()->GetBBId()); } // create a new LHS for the dassign in insertedOcc->GetMeStmt() VarMeExpr *newVarVersion = irMap->CreateVarMeExprVersion(*dass->GetVarLHS()); @@ -102,10 +102,10 @@ void MeStmtPre::CodeMotion() { if (candsForSSAUpdate.find(ostIdx) == candsForSSAUpdate.end()) { MapleSet *bbSet = ssaPreMemPool->New>(std::less(), ssaPreAllocator.Adapter()); - bbSet->insert(occ->GetBB()->GetBBId()); + (void)bbSet->insert(occ->GetBB()->GetBBId()); candsForSSAUpdate[ostIdx] = bbSet; } else { - candsForSSAUpdate[ostIdx]->insert(occ->GetBB()->GetBBId()); + (void)candsForSSAUpdate[ostIdx]->insert(occ->GetBB()->GetBBId()); } VarMeExpr *newVarVersion = irMap->CreateVarMeExprVersion(*var); call->GetMustDefList()->front().UpdateLHS(*newVarVersion); @@ -387,7 +387,7 @@ void MeStmtPre::Rename2() { while (!rename2Set.empty()) { MapleSet::iterator it = rename2Set.begin(); MeRealOcc *realOcc = workCand->GetRealOcc(*it); - rename2Set.erase(it); + (void)rename2Set.erase(it); MeOccur *defOcc = realOcc->GetDef(); CHECK_FATAL(defOcc != nullptr, "should be def by phiocc"); CHECK_FATAL(defOcc->GetOccType() == kOccPhiocc, "should be def by phiocc"); @@ -450,7 +450,7 @@ void MeStmtPre::Rename2() { workCand->GetRealOccs().push_back(occY); occY->SetDef(defX); occY->SetClassID(defX->GetClassID()); - rename2Set.insert(occY->GetPosition()); + (void)rename2Set.insert(occY->GetPosition()); if (GetSSAPreDebug()) { mirModule->GetOut() << "--- rename2 adds to rename2Set manufactured "; occY->Dump(*irMap); @@ -554,7 +554,7 @@ void MeStmtPre::CreateSortedOccs() { BB *bb = GetBB(bbId); CHECK_FATAL(bb != nullptr, "GetBB error"); for (BB *pred : bb->GetPred()) { - phiOpndDfns.insert(dom->GetDtDfnItem(pred->GetBBId())); + (void)phiOpndDfns.insert(dom->GetDtDfnItem(pred->GetBBId())); } } std::unordered_map> bb2PhiOpndMap; @@ -713,7 +713,7 @@ void MeStmtPre::ConstructUseOccurMapExpr(uint32 bbDfn, const MeExpr &meExpr) { return; } MapleSet *bbDfnSet = mapIt->second; - bbDfnSet->insert(bbDfn); + (void)bbDfnSet->insert(bbDfn); return; } for (uint8 i = 0; i < meExpr.GetNumOpnds(); ++i) { @@ -746,7 +746,7 @@ void MeStmtPre::ConstructUseOccurMap() { BB *bb = func->GetAllBBs().at(preOrderDt[i]); for (auto &stmt : bb->GetMeStmts()) { for (size_t j = 0; j < stmt.NumMeStmtOpnds(); ++j) { - ConstructUseOccurMapExpr(i, *stmt.GetOpnd(j)); + ConstructUseOccurMapExpr(static_cast(i), *stmt.GetOpnd(j)); } } } @@ -1054,7 +1054,7 @@ void MeStmtPre::RemoveUnnecessaryDassign(DassignMeStmt &dssMeStmt) { } else { bbSet = candsForSSAUpdate[ostIdx]; } - bbSet->insert(bb->GetBBId()); + (void)bbSet->insert(bb->GetBBId()); } AnalysisResult *MeDoStmtPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr*) { diff --git a/src/maple_me/src/me_store_pre.cpp b/src/maple_me/src/me_store_pre.cpp index fc0dbc693d19ddffed9e4da4def5f4f0412fe50d..ff89e7fbb8853707cb7a88f4e4c63e849dc6a9ab 100644 --- a/src/maple_me/src/me_store_pre.cpp +++ b/src/maple_me/src/me_store_pre.cpp @@ -115,10 +115,10 @@ RegMeExpr *MeStorePre::EnsureRHSInCurTemp(BB &bb) { RegMeExpr *regPhiOpnd = EnsureRHSInCurTemp(*pred); CHECK_NULL_FATAL(regPhiOpnd); regPhi->GetOpnds().push_back(regPhiOpnd); - regPhiOpnd->GetPhiUseSet().insert(regPhi); + (void)regPhiOpnd->GetPhiUseSet().insert(regPhi); } // insert the regPhi - bb.GetMeRegPhiList().insert(std::make_pair(lhsReg->GetOstIdx(), regPhi)); + (void)bb.GetMeRegPhiList().insert(std::make_pair(lhsReg->GetOstIdx(), regPhi)); return lhsReg; } // continue at immediate dominator @@ -193,7 +193,7 @@ void MeStorePre::CodeMotion() { // ================ Step 0: collect occurrences ================ // create a new real occurrence for the store of meStmt of symbol oidx -void MeStorePre::CreateRealOcc(OStIdx ostIdx, MeStmt &meStmt) { +void MeStorePre::CreateRealOcc(const OStIdx &ostIdx, MeStmt &meStmt) { SpreWorkCand *wkCand = nullptr; auto mapIt = workCandMap.find(ostIdx); if (mapIt != workCandMap.end()) { @@ -225,7 +225,7 @@ void MeStorePre::CreateRealOcc(OStIdx ostIdx, MeStmt &meStmt) { } // create a new use occurrence for symbol oidx in given bb -void MeStorePre::CreateUseOcc(OStIdx ostIdx, BB &bb) const { +void MeStorePre::CreateUseOcc(const OStIdx &ostIdx, BB &bb) const { SpreWorkCand *wkCand = nullptr; auto mapIt = workCandMap.find(ostIdx); if (mapIt == workCandMap.end()) { diff --git a/src/maple_me/src/preg_renamer.cpp b/src/maple_me/src/preg_renamer.cpp index 930cb4d862116fcb2212301e892f5f053ea098e6..4d33506d37df4e1388c30858454245b3d4360d9c 100644 --- a/src/maple_me/src/preg_renamer.cpp +++ b/src/maple_me/src/preg_renamer.cpp @@ -27,7 +27,7 @@ void PregRenamer::EnqueDefUses(std::list &qu, RegMeExpr *node, std:: RegMeExpr *neibNode = it; // node's connected register node if (neibNode != node && curVisited.find(neibNode) == curVisited.end()) { qu.push_back(neibNode); - curVisited.insert(neibNode); + (void)curVisited.insert(neibNode); } } } @@ -38,13 +38,13 @@ void PregRenamer::EnqueDefUses(std::list &qu, RegMeExpr *node, std:: RegMeExpr *lhsReg = meRegPhi->GetLHS(); if (lhsReg != node && curVisited.find(lhsReg) == curVisited.end()) { qu.push_back(lhsReg); - curVisited.insert(lhsReg); + (void)curVisited.insert(lhsReg); } for (auto opdIt : meRegPhi->GetOpnds()) { RegMeExpr *opndReg = opdIt; if (opndReg != node && curVisited.find(opndReg) == curVisited.end()) { qu.push_back(opndReg); - curVisited.insert(opndReg); + (void)curVisited.insert(opndReg); } } } @@ -77,7 +77,7 @@ void PregRenamer::RunSelf() const { qu.pop_back(); // put all its neighbors into the queue EnqueDefUses(qu, curNode, curVisited); - curVisited.insert(curNode); + (void)curVisited.insert(curNode); candidates.push_back(curNode); if (curNode->GetDefBy() == kDefByNo) { // if any use are from zero version, we stop renaming all the candidates related to it issue #1420 diff --git a/src/maple_me/src/prop.cpp b/src/maple_me/src/prop.cpp index 1bc2f269fe5f3723fffa12a6b3e22df56e3d2a54..7091c5ea7f5c6f56a87dd2352173e79e46f6e16c 100644 --- a/src/maple_me/src/prop.cpp +++ b/src/maple_me/src/prop.cpp @@ -68,7 +68,7 @@ MeExpr *Prop::SimplifyCvtMeExpr(const OpMeExpr &opMeExpr) const { // 1. converting type3 to type2 is safe; // 2. converting type1 to type2 is safe; // Otherwise, deleting the cvt of cvtOpnd0 may result in information loss. - if (IsCvtSafe(cvtOpnd0->GetOpnd(0)->GetPrimType(), cvtOpnd0->GetPrimType()) || + if (IsCvtSafe(cvtOpnd0->GetOpnd(0)->GetPrimType(), cvtOpnd0->GetPrimType()) && IsCvtSafe(opMeExpr.GetPrimType(), cvtOpnd0->GetPrimType())) { return irMap.CreateMeExprTypeCvt(opMeExpr.GetPrimType(), cvtOpnd0->GetOpndType(), utils::ToRef(cvtOpnd0->GetOpnd(0))); @@ -138,7 +138,7 @@ MeExpr *Prop::SimplifyCompareMeExpr(OpMeExpr &opMeExpr) const { } if (constOpnd->IsZero()) { // addrof will not be zero, so this comparison can be replaced with a constant - auto *resConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst((opcode == OP_ne), + auto *resConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(opcode == OP_ne), utils::ToRef(GlobalTables::GetTypeTable().GetUInt1())); return irMap.CreateConstMeExpr(opMeExpr.GetPrimType(), *resConst); } diff --git a/src/maple_me/src/ssa_devirtual.cpp b/src/maple_me/src/ssa_devirtual.cpp index d8bd4fb20f540e8f63a14fd5b3441fe39375995d..8809cf573ccfd7fe6f0ec7612a3b944f1fefd788 100644 --- a/src/maple_me/src/ssa_devirtual.cpp +++ b/src/maple_me/src/ssa_devirtual.cpp @@ -117,7 +117,7 @@ void SSADevirtual::ReplaceCall(CallMeStmt &callStmt, const MIRFunction &targetFu ++optedInterfaceCalls; } if (clone != nullptr && OP_callassigned == callStmt.GetOp()) { - clone->UpdateReturnVoidIfPossible(&callStmt, &targetFunc); + clone->UpdateReturnVoidIfPossible(&callStmt, targetFunc); } if (SSADevirtual::debug) { LogInfo::MapleLogger() << "\t -> \t" << kOpcodeInfo.GetTableItemAt(callStmt.GetOp()).name << " " << @@ -489,7 +489,7 @@ void SSADevirtual::TraversalMeStmt(MeStmt &meStmt) { (void)DevirtualizeCall(*callMeStmt); if (clone != nullptr && OP_callassigned == callMeStmt->GetOp()) { MIRFunction &targetFunc = callMeStmt->GetTargetFunction(); - clone->UpdateReturnVoidIfPossible(callMeStmt, &targetFunc); + clone->UpdateReturnVoidIfPossible(callMeStmt, targetFunc); } break; } diff --git a/src/maple_me/src/ssa_epre.cpp b/src/maple_me/src/ssa_epre.cpp index 9efe03818f3166c2d5ce87f12bd8ff4ed58814c1..ff565dc5dfcb7c99ecf1bda025572403c98af78f 100644 --- a/src/maple_me/src/ssa_epre.cpp +++ b/src/maple_me/src/ssa_epre.cpp @@ -95,7 +95,7 @@ void SSAEPre::GenerateSaveRealOcc(MeRealOcc &realOcc) { (realOcc.GetMeStmt()->GetOpnd(0) == realOcc.GetMeExpr())) { isRHSOfDassign = true; // setting flag so delegaterc will skip - static_cast(realOcc.GetMeStmt())->GetVarLHS()->SetNoDelegateRC(1); + static_cast(realOcc.GetMeStmt())->GetVarLHS()->SetNoDelegateRC(true); } if (!workCand->NeedLocalRefVar() || isRHSOfDassign || GetPlacementRCOn()) { if (regOrVar->GetMeOp() == kMeOpReg) { diff --git a/src/maple_me/src/ssa_pre.cpp b/src/maple_me/src/ssa_pre.cpp index 555d65671e28a620fed27354614eebc06be446a7..9346fa647efefd54fa85d0d75a91312084afef5e 100644 --- a/src/maple_me/src/ssa_pre.cpp +++ b/src/maple_me/src/ssa_pre.cpp @@ -187,9 +187,9 @@ void SSAPre::UpdateInsertedPhiOccOpnd() { regOpnd = irMap->CreateRegMeExprVersion(static_cast(*curTemp)); } phiReg->GetOpnds().push_back(regOpnd); - regOpnd->GetPhiUseSet().insert(phiReg); // record all the uses phi node for preg renaming + (void)regOpnd->GetPhiUseSet().insert(phiReg); // record all the uses phi node for preg renaming } - phiOcc->GetBB()->GetMeRegPhiList().insert(std::make_pair(phiReg->GetOpnd(0)->GetOstIdx(), phiReg)); + (void)phiOcc->GetBB()->GetMeRegPhiList().insert(std::make_pair(phiReg->GetOpnd(0)->GetOstIdx(), phiReg)); if (workCand->NeedLocalRefVar() && phiOcc->GetVarPhi() != nullptr) { MeVarPhiNode *phiVar = phiOcc->GetVarPhi(); for (MePhiOpndOcc *phiOpnd : phiOcc->GetPhiOpnds()) { @@ -212,7 +212,7 @@ void SSAPre::UpdateInsertedPhiOccOpnd() { } phiVar->GetOpnds().push_back(localRefVarOpnd); } - phiOcc->GetBB()->GetMevarPhiList().insert(std::make_pair(phiVar->GetOpnd(0)->GetOStIdx(), phiVar)); + (void)phiOcc->GetBB()->GetMevarPhiList().insert(std::make_pair(phiVar->GetOpnd(0)->GetOStIdx(), phiVar)); } } else { MeVarPhiNode *phiVar = phiOcc->GetVarPhi(); @@ -224,7 +224,7 @@ void SSAPre::UpdateInsertedPhiOccOpnd() { } phiVar->GetOpnds().push_back(varOpnd); } - phiOcc->GetBB()->GetMevarPhiList().insert(std::make_pair(phiVar->GetOpnd(0)->GetOStIdx(), phiVar)); + (void)phiOcc->GetBB()->GetMevarPhiList().insert(std::make_pair(phiVar->GetOpnd(0)->GetOStIdx(), phiVar)); } } } @@ -752,7 +752,7 @@ void SSAPre::Rename1() { if (isAllDom) { realOcc->SetClassID(topOccur->GetClassID()); realOcc->SetDef(topOccur); - rename2Set.insert(realOcc->GetPosition()); + (void)rename2Set.insert(realOcc->GetPosition()); occStack.push(realOcc); if (IsLoopHeadBB(topOccur->GetBB()->GetBBId())) { static_cast(topOccur)->SetSpeculativeDownSafe(true); @@ -889,7 +889,7 @@ void SSAPre::Rename2() { while (!rename2Set.empty()) { MapleSet::iterator it = rename2Set.begin(); MeRealOcc *realOcc = workCand->GetRealOcc(*it); - rename2Set.erase(it); + (void)rename2Set.erase(it); MeOccur *defOcc = realOcc->GetDef(); if (defOcc == nullptr || defOcc->GetOccType() != kOccPhiocc) { CHECK_FATAL(false, "should be def by phiOcc"); @@ -941,7 +941,7 @@ void SSAPre::Rename2() { workCand->GetRealOccs().push_back(occY); occY->SetDef(defX); occY->SetClassID(defX->GetClassID()); - rename2Set.insert(occY->GetPosition()); + (void)rename2Set.insert(occY->GetPosition()); if (GetSSAPreDebug()) { mirModule->GetOut() << "--- rename2 adds to rename2Set manufactured "; occY->Dump(*irMap); @@ -979,7 +979,7 @@ void SSAPre::SetVarPhis(const MeExpr &meExpr) { if (phiMeNode != nullptr) { BBId defBBId = phiMeNode->GetDefBB()->GetBBId(); if (varPhiDfns.find(dom->GetDtDfnItem(defBBId)) == varPhiDfns.end() && ScreenPhiBB(defBBId)) { - varPhiDfns.insert(dom->GetDtDfnItem(defBBId)); + (void)varPhiDfns.insert(dom->GetDtDfnItem(defBBId)); for (auto opndIt = phiMeNode->GetOpnds().begin(); opndIt != phiMeNode->GetOpnds().end(); ++opndIt) { VarMeExpr *opnd = *opndIt; SetVarPhis(*opnd); @@ -992,7 +992,7 @@ void SSAPre::SetVarPhis(const MeExpr &meExpr) { BBId defBbId = phiMeNode->GetDefBB()->GetBBId(); CHECK(defBbId < dom->GetDtDfnSize(), "defBbId.idx out of range in SSAPre::SetVarPhis"); if (varPhiDfns.find(dom->GetDtDfnItem(defBbId)) == varPhiDfns.end() && ScreenPhiBB(defBbId)) { - varPhiDfns.insert(dom->GetDtDfnItem(defBbId)); + (void)varPhiDfns.insert(dom->GetDtDfnItem(defBbId)); for (auto opndIt = phiMeNode->GetOpnds().begin(); opndIt != phiMeNode->GetOpnds().end(); ++opndIt) { RegMeExpr *opnd = *opndIt; @@ -1017,7 +1017,7 @@ void SSAPre::CreateSortedOccs() { BB *bb = GetBB(bbId); ASSERT(bb != nullptr, "GetBB return null in SSAPre::CreateSortedOccs"); for (BB *pred : bb->GetPred()) { - phiOpndDfns.insert(dom->GetDtDfnItem(pred->GetBBId())); + (void)phiOpndDfns.insert(dom->GetDtDfnItem(pred->GetBBId())); } } // under lpre, form lhs occ for formals at function entry @@ -1621,7 +1621,7 @@ void SSAPre::DumpWorkList() const { GStrIdx SSAPre::NewTempStrIdx() { std::string preStr("ssapre_tempvar"); - preStr.append(std::to_string(strIdxCount++)); + (void)preStr.append(std::to_string(strIdxCount++)); return GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(preStr); } diff --git a/src/maple_phase/include/phase.h b/src/maple_phase/include/phase.h index d556d94fa201c2135cc9a722a573b1b6b0339970..b977ad382003bef6118ff4f2894a2599c24908bb 100644 --- a/src/maple_phase/include/phase.h +++ b/src/maple_phase/include/phase.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/mpl2mpl/src/coderelayout.cpp b/src/mpl2mpl/src/coderelayout.cpp index 17f27c17573df029a6eb198c83894f56605b76e6..f85246f0f6548897ec9ec3d27c262c8ca411a9f4 100644 --- a/src/mpl2mpl/src/coderelayout.cpp +++ b/src/mpl2mpl/src/coderelayout.cpp @@ -211,8 +211,8 @@ void CodeReLayout::Finish() { MIRSymbol *CodeReLayout::GenStrSym(const std::string &str) { std::string newStr = str + '\0'; - MIRArrayType &strTabType = - *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt8(), newStr.length()); + MIRArrayType &strTabType = *GlobalTables::GetTypeTable().GetOrCreateArrayType( + *GlobalTables::GetTypeTable().GetUInt8(), static_cast(newStr.length())); std::string strTabName = NameMangler::kStaticFieldNamePrefixStr + str; MIRSymbol *staticSym = builder->CreateGlobalDecl(strTabName, strTabType); MIRAggConst *strTabAggConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), strTabType); @@ -232,7 +232,7 @@ MIRSymbol *CodeReLayout::GetorCreateStaticFieldSym(const std::string &fieldName) return it->second; } else { MIRSymbol *sym = GenStrSym(fieldName); - str2SymMap.insert(std::make_pair(fieldName, sym)); + (void)str2SymMap.insert(std::make_pair(fieldName, sym)); return sym; } } diff --git a/src/mpl2mpl/src/constantfold.cpp b/src/mpl2mpl/src/constantfold.cpp index aaceb5240893d054df7cae5df63c65a094176a9a..e80a8959c3fa36609bf9fc1efbf314b422453803 100644 --- a/src/mpl2mpl/src/constantfold.cpp +++ b/src/mpl2mpl/src/constantfold.cpp @@ -361,9 +361,9 @@ ConstvalNode *ConstantFold::FoldIntConstBinary(Opcode opcode, PrimType resultTyp } case OP_sub: { if (useResult64) { - result64 = intValueOfConst0 - intValueOfConst1; + result64 = static_cast(intValueOfConst0 - intValueOfConst1); } else { - result32 = static_cast(intValueOfConst0) - static_cast(intValueOfConst1); + result32 = static_cast(static_cast(intValueOfConst0) - static_cast(intValueOfConst1)); } break; } @@ -371,7 +371,7 @@ ConstvalNode *ConstantFold::FoldIntConstBinary(Opcode opcode, PrimType resultTyp if (useResult64) { result64 = intValueOfConst0 * intValueOfConst1; } else { - result32 = static_cast(intValueOfConst0) * static_cast(intValueOfConst1); + result32 = static_cast(static_cast(intValueOfConst0) * static_cast(intValueOfConst1)); } break; } @@ -384,9 +384,9 @@ ConstvalNode *ConstantFold::FoldIntConstBinary(Opcode opcode, PrimType resultTyp } } else { if (useResult64) { - result64 = intValueOfConst0 / intValueOfConst1; + result64 = static_cast(intValueOfConst0 / intValueOfConst1); } else { - result32 = static_cast(intValueOfConst0) / static_cast(intValueOfConst1); + result32 = static_cast(static_cast(intValueOfConst0) / static_cast(intValueOfConst1)); } } break; @@ -400,7 +400,7 @@ ConstvalNode *ConstantFold::FoldIntConstBinary(Opcode opcode, PrimType resultTyp } } else { if (useResult64) { - result64 = intValueOfConst0 % intValueOfConst1; + result64 = static_cast(intValueOfConst0 % intValueOfConst1); } else { result32 = static_cast(intValueOfConst0) % static_cast(intValueOfConst1); } @@ -435,17 +435,18 @@ ConstvalNode *ConstantFold::FoldIntConstBinary(Opcode opcode, PrimType resultTyp if (IsUnsignedInteger(const0.GetPrimType())) { if (useResult64) { result64 = (static_cast(intValueOfConst0) >= static_cast(intValueOfConst1)) ? - intValueOfConst0 : intValueOfConst1; + static_cast(intValueOfConst0) : static_cast(intValueOfConst1); } else { result32 = (static_cast(intValueOfConst0) >= static_cast(intValueOfConst1)) ? - intValueOfConst0 : intValueOfConst1; + static_cast(intValueOfConst0) : static_cast(intValueOfConst1); } } else { if (useResult64) { - result64 = (intValueOfConst0 >= intValueOfConst1) ? intValueOfConst0 : intValueOfConst1; + result64 = (intValueOfConst0 >= intValueOfConst1) ? + static_cast(intValueOfConst0) : static_cast(intValueOfConst1); } else { result32 = (static_cast(intValueOfConst0) >= static_cast(intValueOfConst1)) ? - intValueOfConst0 : intValueOfConst1; + static_cast(intValueOfConst0) : static_cast(intValueOfConst1); } } break; @@ -454,17 +455,18 @@ ConstvalNode *ConstantFold::FoldIntConstBinary(Opcode opcode, PrimType resultTyp if (IsUnsignedInteger(const0.GetPrimType())) { if (useResult64) { result64 = (static_cast(intValueOfConst0) <= static_cast(intValueOfConst1)) ? - intValueOfConst0 : intValueOfConst1; + static_cast(intValueOfConst0) : static_cast(intValueOfConst1); } else { result32 = (static_cast(intValueOfConst0) <= static_cast(intValueOfConst1)) ? - intValueOfConst0 : intValueOfConst1; + static_cast(intValueOfConst0) : static_cast(intValueOfConst1); } } else { if (useResult64) { - result64 = (intValueOfConst0 <= intValueOfConst1) ? intValueOfConst0 : intValueOfConst1; + result64 = (intValueOfConst0 <= intValueOfConst1) ? + static_cast(intValueOfConst0) : static_cast(intValueOfConst1); } else { result32 = (static_cast(intValueOfConst0) <= static_cast(intValueOfConst1)) ? - intValueOfConst0 : intValueOfConst1; + static_cast(intValueOfConst0) : static_cast(intValueOfConst1); } } break; @@ -496,18 +498,18 @@ ConstvalNode *ConstantFold::FoldIntConstBinary(Opcode opcode, PrimType resultTyp case OP_cand: case OP_land: { if (useResult64) { - result64 = static_cast(intValueOfConst0) && static_cast(intValueOfConst1); + result64 = static_cast(intValueOfConst0 && intValueOfConst1); } else { - result32 = static_cast(intValueOfConst0) && static_cast(intValueOfConst1); + result32 = static_cast(intValueOfConst0 && intValueOfConst1); } break; } case OP_cior: case OP_lior: { if (useResult64) { - result64 = static_cast(intValueOfConst0) || static_cast(intValueOfConst1); + result64 = static_cast(intValueOfConst0 || intValueOfConst1); } else { - result32 = static_cast(intValueOfConst0) || static_cast(intValueOfConst1); + result32 = static_cast(intValueOfConst0 || intValueOfConst1); } break; } @@ -1065,7 +1067,7 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst &cst, PrimType fromType } else if (toType == PTY_f32 && IsPrimitiveInteger(fromType)) { const auto &constValue = static_cast(cst); int64 fromValue = constValue.GetValue(); - float floatValue = round(static_cast(fromValue)); + float floatValue = static_cast(round(fromValue)); if (static_cast(floatValue) == fromValue) { return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue); }