diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 2ccdddadbd6bade4c4e26e19de02d49eccf3b952..bf225a67b8f2693d4c96ec724b5adf0f046e977f 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 14ce6013ef67b85b5638a02a0948b3090757d6ef..1092b627b9e4119c14a74c1a4591562ac8fd8448 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 01b920f6caf1e6e9bd5341e918405fce3c0b6b78..e459563de06c47cc7794c8f7c2bb9a042d8a6627 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/maple_ipa/src/callgraph.cpp b/src/maple_ipa/src/callgraph.cpp index d9943a1949d524de8df94e6c2b58493585873030..3429523c5787c4ab29756d0db3a301173917eecc 100644 --- a/src/maple_ipa/src/callgraph.cpp +++ b/src/maple_ipa/src/callgraph.cpp @@ -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. @@ -105,7 +105,7 @@ void CGNode::DumpDetail() const { CallInfo *ci = callSite.first; CGNode *node = cgIt; MIRFunction *mf = node->GetMIRFunction(); - if (mf) { + if (mf != nullptr) { LogInfo::MapleLogger() << "\tcallee in module : " << mf->GetName() << " "; } else { LogInfo::MapleLogger() << "\tcallee external: " << ci->GetCalleeName(); @@ -131,12 +131,12 @@ void CGNode::Dump(std::ofstream &fout) const { for (auto &cgIt : *callSite.second) { CallInfo *ci = callSite.first; CGNode *node = cgIt; - if (!node) { + if (node == nullptr) { continue; } MIRFunction *func = node->GetMIRFunction(); fout << "\"" << mirFunc->GetName() << "\" -> "; - if (func) { + if (func != nullptr) { if (node->GetSCCNode() != nullptr && node->GetSCCNode()->GetCGNodes().size() > 1) { fout << "\"" << func->GetName() << "\"[label=" << node->GetSCCNode()->id << " color=red];\n"; } else { @@ -530,7 +530,7 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin ASSERT(klass != nullptr, "Klass not found"); MapleVector *cands = klass->GetCandidates(calleeFunc->GetBaseFuncNameWithTypeStrIdx()); // continue to search its implinterfaces - if (!cands) { + if (cands == nullptr) { for (Klass *implinterface : klass->GetImplInterfaces()) { cands = implinterface->GetCandidates(calleeFunc->GetBaseFuncNameWithTypeStrIdx()); if (cands && !cands->empty()) { @@ -538,7 +538,7 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin } } } - if (!cands || cands->empty()) { + if (cands == nullptr || cands->empty()) { continue; // Fix CI } MIRFunction *actualMirfunc = cands->at(0); @@ -600,7 +600,7 @@ static void ResetInferredType(std::vector &inferredSymbols) { } static void ResetInferredType(std::vector &inferredSymbols, MIRSymbol *s) { - if (!s) { + if (s == nullptr) { return; } if (s->GetInferredTyIdx() == kInitTyIdx || s->GetInferredTyIdx() == kNoneTyIdx) { @@ -614,7 +614,6 @@ static void ResetInferredType(std::vector &inferredSymbols, MIRSymbo break; } } - // ASSERT(i &inferredSymbols, MIRSymbol *s, TyIdx idx) { @@ -875,7 +874,7 @@ 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()) { - if (!func->GetBody()) { + if (func->GetBody() == nullptr) { continue; } StmtNode *stmtNext = nullptr; @@ -991,7 +990,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { for (MIRFunction *const &method : iklass->GetMethods()) { if (calleefunc->GetBaseFuncNameWithTypeStrIdx() == method->GetBaseFuncNameWithTypeStrIdx() && !method->GetFuncAttrs().GetAttr(FUNCATTR_abstract)) { - if (!tmpInterface || klassh->IsSuperKlassForInterface(tmpInterface, iklass)) { + if (tmpInterface == nullptr || klassh->IsSuperKlassForInterface(tmpInterface, iklass)) { tmpInterface = iklass; tmpMethod = method; } @@ -1000,7 +999,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } } // Add this check for the thirdparty APP compile - if (!tmpMethod) { + if (tmpMethod == nullptr) { Klass *parentKlass = klassh->GetKlassFromName(calleefunc->GetBaseClassName()); CHECK_FATAL(parentKlass != nullptr, "null ptr check"); bool flag = false; @@ -1029,7 +1028,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { << currKlass->GetKlassName() << std::endl; } } - if (!tmpMethod) { // SearchWithoutRettype, search only in current class now. + if (tmpMethod == nullptr) { // SearchWithoutRettype, search only in current class now. MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(calleefunc->GetReturnTyIdx()); Klass *targetKlass = nullptr; bool isCalleeScalar = false; @@ -1041,7 +1040,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } else { targetKlass = klassh->GetKlassFromTyIdx(retType->GetTypeIndex()); } - if (!targetKlass && !isCalleeScalar) { + if (targetKlass == nullptr && !isCalleeScalar) { CHECK_FATAL(targetKlass != nullptr, "null ptr check"); } Klass *curRetKlass = nullptr; @@ -1059,7 +1058,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } else { tmpKlass = klassh->GetKlassFromTyIdx(tmpType->GetTypeIndex()); } - if (!tmpKlass && !isCurrVtabScalar) { + if (tmpKlass == nullptr && !isCurrVtabScalar) { CHECK_FATAL(tmpKlass != nullptr, "null ptr check"); } if (isCalleeScalar || isCurrVtabScalar) { @@ -1074,7 +1073,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { continue; } if (targetKlass->IsClass() && klassh->IsSuperKlass(tmpKlass, targetKlass) && - (!curRetKlass || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } @@ -1085,12 +1084,12 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { if (!targetKlass->IsClass()) { CHECK_FATAL(tmpKlass != nullptr, "Klass null ptr check"); if (tmpKlass->IsClass() && klassh->IsInterfaceImplemented(targetKlass, tmpKlass) && - (!curRetKlass || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } if (!tmpKlass->IsClass() && klassh->IsSuperKlassForInterface(tmpKlass, targetKlass) && - (!curRetKlass || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { + (curRetKlass == nullptr || klassh->IsSuperKlass(curRetKlass, tmpKlass))) { curRetKlass = tmpKlass; tmpMethod = method; } @@ -1098,12 +1097,12 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { } } } - if (!tmpMethod && (currKlass->IsClass() || currKlass->IsInterface())) { + if (tmpMethod == nullptr && (currKlass->IsClass() || currKlass->IsInterface())) { LogInfo::MapleLogger() << "warning: func " << calleefunc->GetName() << " is not found in DeVirtual!" << std::endl; stmt->SetOpCode(OP_callassigned); break; - } else if (!tmpMethod) { + } else if (tmpMethod == nullptr) { LogInfo::MapleLogger() << "Error: func " << calleefunc->GetName() << " is not found!" << std::endl; ASSERT(tmpMethod, "Must not be null"); } @@ -1216,25 +1215,24 @@ void IPODevirtulize::DevirtualFinal() { } } -using CallSite = std::pair; void CallGraph::GenCallGraph() { - // Read existing call graph from mplt, std::map > + // Read existing call graph from mplt, std::map > // caller_PUIdx and all call site info are needed. Rebuild all other info of CGNode using CHA for (auto const &it : mirModule->GetMethod2TargetMap()) { CGNode *node = GetOrGenCGNode(it.first); CHECK_FATAL(node != nullptr, "node is null"); - std::vector callees = it.second; + std::vector callees = it.second; for (auto itInner = callees.begin(); itInner != callees.end(); ++itInner) { - CallInfo *info = (*itInner).first; + CallInfo *info = *itInner; CGNode *calleeNode = GetOrGenCGNode(info->GetFunc()->GetPuidx(), info->GetCallType() == kCallTypeVirtualCall, info->GetCallType() == kCallTypeInterfaceCall); CHECK_FATAL(calleeNode != nullptr, "calleeNode is null"); if (info->GetCallType() == kCallTypeVirtualCall) { - node->AddCallsite((*itInner).first, &calleeNode->GetVcallCandidates()); + node->AddCallsite(*itInner, &calleeNode->GetVcallCandidates()); } else if (info->GetCallType() == kCallTypeInterfaceCall) { - node->AddCallsite((*itInner).first, &calleeNode->GetIcallCandidates()); + node->AddCallsite(*itInner, &calleeNode->GetIcallCandidates()); } else if (info->GetCallType() == kCallTypeCall) { - node->AddCallsite((*itInner).first, calleeNode); + node->AddCallsite(*itInner, calleeNode); } else if (info->GetCallType() == kCallTypeSuperCall) { const MIRFunction *calleefunc = info->GetFunc(); Klass *klass = klassh->GetKlassFromFunc(calleefunc); @@ -1275,7 +1273,7 @@ void CallGraph::GenCallGraph() { for (auto it = GlobalTables::GetFunctionTable().GetFuncTable().begin(); it != GlobalTables::GetFunctionTable().GetFuncTable().end(); it++) { MIRFunction *mirFunc = *it; - if (!mirFunc || !mirFunc->GetBody()) { + if (mirFunc == nullptr || mirFunc->GetBody() == nullptr) { continue; } mirModule->SetCurFunction(mirFunc); @@ -1504,7 +1502,7 @@ void SCCNode::Setup() { for (auto &callSite : node->GetCallee()) { for (auto &cgIt : *callSite.second) { CGNode *calleeNode = cgIt; - if (!calleeNode) { + if (calleeNode == nullptr) { continue; } if (calleeNode->GetSCCNode() == this) { @@ -1537,7 +1535,7 @@ void CallGraph::BuildSCCDFS(CGNode *caller, uint32 &visitIndex, std::vectorGetCallee()) { for (auto &cgIt : *callSite.second) { CGNode *calleeNode = cgIt; - if (!calleeNode) { + if (calleeNode == nullptr) { continue; } uint32 calleeId = calleeNode->GetID(); @@ -1648,9 +1646,9 @@ void CGNode::AddCandsForCallNode(const KlassHierarchy *kh) { } CHECK_FATAL(mirFunc != nullptr, ""); Klass *klass = kh->GetKlassFromFunc(mirFunc); - if (klass) { + if (klass != nullptr) { MapleVector *v = klass->GetCandidates(mirFunc->GetBaseFuncNameWithTypeStrIdx()); - if (v) { + if (v != nullptr) { vcallCands = *v; // Vector copy } } @@ -1670,7 +1668,7 @@ MIRFunction *CGNode::HasOneCandidate() const { } if (!vcallCands[i]->IsEmpty()) { count++; - if (!cand) { + if (cand == nullptr) { cand = vcallCands[i]; } } @@ -1681,18 +1679,19 @@ 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, ""); + CHECK_FATAL(cha != nullptr, "CHA can't be null"); CallGraph *cg = memPool->New(module, memPool, cha, module->GetFileName().c_str()); cg->debug_flag = TRACE_PHASE; cg->BuildCallGraph(); m->AddResult(GetPhaseID(), *module, *cg); - // do retype - MemPool *localMp = memPoolCtrler.NewMemPool(PhaseName()); - maple::MIRBuilder dexMirbuilder(module); - KlassHierarchy *retypeKh = static_cast(m->GetAnalysisResult(MoPhase_CHA, module)); - Retype retype(module, localMp, dexMirbuilder, retypeKh); - retype.DoRetype(); - memPoolCtrler.DeleteMemPool(localMp); + if (!module->IsInIPA()) { + // do retype + MemPool *localMp = memPoolCtrler.NewMemPool(PhaseName()); + maple::MIRBuilder dexMirbuilder(module); + Retype retype(module, localMp, dexMirbuilder, cha); + retype.DoRetype(); + memPoolCtrler.DeleteMemPool(localMp); + } return cg; } diff --git a/src/maple_ir/include/bin_mpl_import.h b/src/maple_ir/include/bin_mpl_import.h index d75acb20c43264cbf8d8086d71a9235a3a632400..c7cebc57744c84d2ff1106801ba6d99e630a8fbb 100644 --- a/src/maple_ir/include/bin_mpl_import.h +++ b/src/maple_ir/include/bin_mpl_import.h @@ -22,7 +22,6 @@ namespace maple { class BinaryMplImport { public: - using CallSite = std::pair; explicit BinaryMplImport(MIRModule &md) : mod(md), mirBuilder(&md) {} BinaryMplImport &operator=(const BinaryMplImport&) = delete; BinaryMplImport(const BinaryMplImport&) = delete; diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 310c878f5fec0d71d1d95b931705465161699e3d..beb879f7bc16ff1addf9a17b533e5fa6181a40f9 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -427,33 +427,33 @@ class MIRModule { return classList; } - const std::map> &GetMethod2TargetMap() const { + const std::map> &GetMethod2TargetMap() const { return method2TargetMap; } - std::vector &GetMemFromMethod2TargetMap(PUIdx methodPuIdx) { + std::vector &GetMemFromMethod2TargetMap(PUIdx methodPuIdx) { return method2TargetMap[methodPuIdx]; } - void SetMethod2TargetMap(const std::map> &map) { + void SetMethod2TargetMap(const std::map> &map) { method2TargetMap = map; } - void AddMemToMethod2TargetMap(PUIdx idx, const std::vector &callSite) { + void AddMemToMethod2TargetMap(PUIdx idx, const std::vector &callSite) { method2TargetMap[idx] = callSite; } - bool HasTargetHash(PUIdx idx, uint64 key) const { + bool HasTargetHash(PUIdx idx, uint32 key) const { auto it = method2TargetHash.find(idx); if (it == method2TargetHash.end()) { return false; } return it->second.find(key) != it->second.end(); } - void InsertTargetHash(PUIdx idx, uint64 key) { + void InsertTargetHash(PUIdx idx, uint32 key) { method2TargetHash[idx].insert(key); } - void AddValueToMethod2TargetHash(PUIdx idx, const std::unordered_set &value) { + void AddValueToMethod2TargetHash(PUIdx idx, const std::unordered_set &value) { method2TargetHash[idx] = value; } @@ -513,8 +513,8 @@ class MIRModule { MapleVector importPaths; MapleSet classList; - std::map> method2TargetMap; - std::map> method2TargetHash; + std::map> method2TargetMap; + std::map> method2TargetHash; std::map eaSummary; MIRFunction *entryFunc = nullptr;