diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index 7094d12549592389316625779aee7019539b36d1..f2b151efabab8dc18f36da84b874676ace6478f2 100755 Binary files a/src/mapleall/bin/dex2mpl and b/src/mapleall/bin/dex2mpl differ diff --git a/src/mapleall/bin/dex2mpl_android b/src/mapleall/bin/dex2mpl_android index c9fd5296ca6bd7de5043bb41a5592f6915a95410..554fbcdbd929f094880512605450cac414dba35d 100755 Binary files a/src/mapleall/bin/dex2mpl_android and b/src/mapleall/bin/dex2mpl_android differ diff --git a/src/mapleall/bin/jbc2mpl b/src/mapleall/bin/jbc2mpl index 68ce9ad20f0a2e7184f37cb3641da8ea42cf3962..69d6ff51931924a2ae33192fd5497dc381cfe54d 100755 Binary files a/src/mapleall/bin/jbc2mpl and b/src/mapleall/bin/jbc2mpl differ diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h index a11bb9493f1a51df6b1c38e2d162a95004309204..57e30762fed1c27fd46d2b4d361465bcb9298c9b 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -575,8 +575,8 @@ class AArch64CGFunc : public CGFunc { } void CreateCallStructParamPassByStack(int32 symSize, MIRSymbol *sym, RegOperand *addrOpnd, int32 baseOffset); - AArch64RegOperand *SelectParmListDreadAccessField(MIRSymbol &sym, FieldID fieldID, PLocInfo &ploc, int32 offset, - uint32 parmNum); + AArch64RegOperand *SelectParmListDreadAccessField(const MIRSymbol &sym, FieldID fieldID, const PLocInfo &ploc, + int32 offset, uint32 parmNum); void CreateCallStructParamPassByReg(AArch64reg reg, MemOperand &memOpnd, AArch64ListOperand &srcOpnds, fpParamState state); void CreateCallStructParamMemcpy(const MIRSymbol *sym, RegOperand *addropnd, diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index fc41723c064ae63c98af46e54300e7dfe9b7115e..d10467c8a542633d0c60e641133058c8b84dade0 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -5218,7 +5218,8 @@ void AArch64CGFunc::SelectParmListIreadSmallAggregate(const IreadNode &iread, MI &GetOrCreateMemOpnd(AArch64MemOperand::kAddrModeBOi, memSize, addrOpnd1, nullptr, offOpnd0, nullptr); CreateCallStructParamPassByReg(ploc.reg0, *mopnd, srcOpnds, state); if (ploc.reg1) { - AArch64OfstOperand *offOpnd1 = &GetOrCreateOfstOpnd(((ploc.fpSize ? ploc.fpSize : kSizeOfPtr) + offset), k32BitSize); + AArch64OfstOperand *offOpnd1 = &GetOrCreateOfstOpnd(((ploc.fpSize ? ploc.fpSize : kSizeOfPtr) + offset), + k32BitSize); mopnd = &GetOrCreateMemOpnd(AArch64MemOperand::kAddrModeBOi, memSize, addrOpnd1, nullptr, offOpnd1, nullptr); CreateCallStructParamPassByReg(ploc.reg1, *mopnd, srcOpnds, state); } @@ -5308,15 +5309,14 @@ void AArch64CGFunc::CreateCallStructParamPassByStack(int32 symSize, MIRSymbol *s } } -AArch64RegOperand *AArch64CGFunc::SelectParmListDreadAccessField(MIRSymbol &sym, FieldID fieldID, PLocInfo &ploc, int32 offset, - uint32 parmNum) { - fpParamState state = kStateUnknown; - uint32 memSize; - PrimType primType; - AArch64RegOperand *parmOpnd; - uint32 dataSizeBits; - AArch64reg reg; - switch (parmNum) { +AArch64RegOperand *AArch64CGFunc::SelectParmListDreadAccessField(const MIRSymbol &sym, FieldID fieldID, + const PLocInfo &ploc, int32 offset, uint32 parmNum) { + uint32 memSize; + PrimType primType; + AArch64RegOperand *parmOpnd; + uint32 dataSizeBits; + AArch64reg reg; + switch (parmNum) { case 0: reg = ploc.reg0; break; @@ -5331,33 +5331,30 @@ AArch64RegOperand *AArch64CGFunc::SelectParmListDreadAccessField(MIRSymbol &sym, break; default: CHECK_FATAL(false, "Exceeded maximum allowed fp parameter registers for struct passing"); - } - if (ploc.fpSize == 0) { - state = kNotFp; - memSize = k64BitSize; - primType = PTY_i64; - dataSizeBits = GetPrimTypeSize(PTY_i64) * kBitsPerByte; - parmOpnd = &GetOrCreatePhysicalRegisterOperand(reg, k64BitSize, kRegTyInt); - } else if (ploc.fpSize == k4ByteSize) { - state = kFp32Bit; - memSize = k32BitSize; - primType = PTY_f32; - dataSizeBits = GetPrimTypeSize(PTY_f32) * kBitsPerByte; - parmOpnd = &GetOrCreatePhysicalRegisterOperand(reg, k32BitSize, kRegTyFloat); - } else if (ploc.fpSize == k8ByteSize) { - state = kFp64Bit; - memSize = k64BitSize; - primType = PTY_f64; - dataSizeBits = GetPrimTypeSize(PTY_i64) * kBitsPerByte; - parmOpnd = &GetOrCreatePhysicalRegisterOperand(reg, k64BitSize, kRegTyFloat); - } else { - CHECK_FATAL(false, "Unknown call parameter state"); - } + } + if (ploc.fpSize == 0) { + memSize = k64BitSize; + primType = PTY_i64; + dataSizeBits = GetPrimTypeSize(PTY_i64) * kBitsPerByte; + parmOpnd = &GetOrCreatePhysicalRegisterOperand(reg, k64BitSize, kRegTyInt); + } else if (ploc.fpSize == k4ByteSize) { + memSize = k32BitSize; + primType = PTY_f32; + dataSizeBits = GetPrimTypeSize(PTY_f32) * kBitsPerByte; + parmOpnd = &GetOrCreatePhysicalRegisterOperand(reg, k32BitSize, kRegTyFloat); + } else if (ploc.fpSize == k8ByteSize) { + memSize = k64BitSize; + primType = PTY_f64; + dataSizeBits = GetPrimTypeSize(PTY_i64) * kBitsPerByte; + parmOpnd = &GetOrCreatePhysicalRegisterOperand(reg, k64BitSize, kRegTyFloat); + } else { + CHECK_FATAL(false, "Unknown call parameter state"); + } MemOperand *memOpnd; if (sym.GetStorageClass() == kScFormal && fieldID > 0) { MemOperand &baseOpnd = GetOrCreateMemOpnd(sym, 0, memSize); - RegOperand &base = CreateVirtualRegisterOperand(NewVReg(kRegTyInt, 8)); - GetCurBB()->AppendInsn(cg->BuildInstruction(PickLdInsn(64, PTY_i64), base, baseOpnd)); + RegOperand &base = CreateVirtualRegisterOperand(NewVReg(kRegTyInt, k8ByteSize)); + GetCurBB()->AppendInsn(cg->BuildInstruction(PickLdInsn(k64BitSize, PTY_i64), base, baseOpnd)); memOpnd = &CreateMemOpnd(base, offset, memSize); } else if (ploc.fpSize) { memOpnd = &GetOrCreateMemOpnd(sym, (ploc.fpSize * parmNum + offset), memSize); @@ -5470,7 +5467,7 @@ AArch64RegOperand *AArch64CGFunc::CreateCallStructParamCopyToStack(uint32 numMem Insn &ldInsn = cg->BuildInstruction(PickLdInsn(k64BitSize, PTY_i64), vreg, base); GetCurBB()->AppendInsn(ldInsn); ldMopnd = &GetOrCreateMemOpnd(AArch64MemOperand::kAddrModeBOi, k64BitSize, &vreg, nullptr, - &GetOrCreateOfstOpnd((static_cast(j) * kSizeOfPtr + fromOffset), k32BitSize), nullptr); + &GetOrCreateOfstOpnd((static_cast(j) * kSizeOfPtr + fromOffset), k32BitSize), nullptr); } else { ldMopnd = &GetOrCreateMemOpnd(*sym, (j * static_cast(kSizeOfPtr) + fromOffset), k64BitSize); } diff --git a/src/mapleall/maple_be/src/cg/cg.cpp b/src/mapleall/maple_be/src/cg/cg.cpp index 42ba9342bbd0d061cfa79783505b65c733971f5f..726adf8315f7cee364d88dd7f75bf73ba3627e98 100644 --- a/src/mapleall/maple_be/src/cg/cg.cpp +++ b/src/mapleall/maple_be/src/cg/cg.cpp @@ -257,7 +257,6 @@ std::vector CG::GetReferenceOffsets64(const BECommon &beCommon, MIRStruct return result; } - const std::string CG::ExtractFuncName(const std::string &str) { /* 3: length of "_7C" */ size_t offset = 3; diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index c35129401e1851999c166c361c2d192364d996dc..114b4adf509f5d63168b310be00158e20c10c0a6 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -2662,7 +2662,6 @@ void Emitter::EmitHexUnsigned(uint64 num) { outStream.flags(flag); } - #define XSTR(s) str(s) #define str(s) #s @@ -2682,7 +2681,6 @@ void Emitter::EmitDIHeaderFileInfo() { Emit("// dummy header file 3\n"); } - void Emitter::EmitHugeSoRoutines(bool lastRoutine) { if (!lastRoutine && (javaInsnCount < (static_cast(hugeSoSeqence) * static_cast(kHugeSoInsnCountThreshold)))) { diff --git a/src/mapleall/maple_be/src/cg/schedule.cpp b/src/mapleall/maple_be/src/cg/schedule.cpp index e09d9d794ca534d14a8847e4d6054205c028bc9d..eff7d50ce251b7d5aa83b6267918b3d153029279 100644 --- a/src/mapleall/maple_be/src/cg/schedule.cpp +++ b/src/mapleall/maple_be/src/cg/schedule.cpp @@ -507,6 +507,7 @@ void Schedule::InitIDAndLoc() { } } } + AnalysisResult* CgDoPreScheduling::Run(CGFunc *cgFunc, CgFuncResultMgr *cgFuncResMgr) { ASSERT(cgFunc != nullptr, "expect a cgfunc in CgDoPreScheduling"); CHECK_NULL_FATAL(cgFuncResMgr); diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index 1c69cb1dd484d454283975e045e62195434fe32f..5c06347ddce2ae7e74351358c7db40fd40b7626f 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -35,7 +35,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", "${MAPLE_ROOT}/third_party/bounds_checking_function/include", - "${MAPLE_ROOT}/third_party/dwarf/include", + "${MAPLE_ROOT}/third_party/dwarf_h/include", ] executable("maple") { diff --git a/src/mapleall/maple_driver/include/driver_runner.h b/src/mapleall/maple_driver/include/driver_runner.h index 9e0b134222c2ddea9cca568cc414e056fb32f709..854de244256f744ee22dbb9918d2964ef549631c 100644 --- a/src/mapleall/maple_driver/include/driver_runner.h +++ b/src/mapleall/maple_driver/include/driver_runner.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -116,7 +116,6 @@ class DriverRunner final { std::string baseName; std::string outputFile; InputFileType inputFileType; - bool hasDebugFlag = false; }; } // namespace maple diff --git a/src/mapleall/maple_driver/src/driver_runner.cpp b/src/mapleall/maple_driver/src/driver_runner.cpp index 544ea4931341e8de112850cd933b403ec1ad06dd..faec5eef0e316293800df7a9e46484e48b012504 100644 --- a/src/mapleall/maple_driver/src/driver_runner.cpp +++ b/src/mapleall/maple_driver/src/driver_runner.cpp @@ -197,12 +197,6 @@ ErrorCode DriverRunner::ParseInput() const { void DriverRunner::ProcessMpl2mplAndMePhases(const std::string &outputFile, const std::string &vtableImplFile) const { CHECK_MODULE(); theMIRModule = theModule; - - if (hasDebugFlag) { - std::cout << "set up debug info " << std::endl; - theMIRModule->GetDbgInfo()->BuildDebugInfo(); - } - if (mpl2mplOptions != nullptr || meOptions != nullptr) { LogInfo::MapleLogger() << "Processing maplecomb" << '\n'; diff --git a/src/mapleall/maple_ipa/BUILD.gn b/src/mapleall/maple_ipa/BUILD.gn index 7353694d863ef2774736e747d5cf27be6ac2d009..74c85c121484b5198dbc89a897d3076bf06fc32a 100755 --- a/src/mapleall/maple_ipa/BUILD.gn +++ b/src/mapleall/maple_ipa/BUILD.gn @@ -30,6 +30,7 @@ src_libmplipa = [ "src/clone.cpp", "src/retype.cpp", "src/call_graph.cpp", + "src/inline.cpp", "src/method_replace.cpp", "src/ipa_escape_analysis.cpp", "src/do_ipa_escape_analysis.cpp", diff --git a/src/mapleall/maple_ipa/include/module_phases.def b/src/mapleall/maple_ipa/include/module_phases.def index bee904f03fbdaca753c0895a24c12cf31d28cf0a..312ac58dbf572521f1be8aafcf56b0f2a8c12e50 100644 --- a/src/mapleall/maple_ipa/include/module_phases.def +++ b/src/mapleall/maple_ipa/include/module_phases.def @@ -12,6 +12,7 @@ * FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v1 for more details. */ +MODAPHASE(MoPhase_METHODREPLACE, DoMethodReplace) MODAPHASE(MoPhase_CLONE, DoClone) MODAPHASE(MoPhase_CHA, DoKlassHierarchy) MODAPHASE(MoPhase_VERIFICATION, DoVerification) @@ -19,6 +20,8 @@ MODAPHASE(MoPhase_VERIFYMARK, DoVerifyMark) MODAPHASE(MoPhase_CLINIT, DoClassInit) MODAPHASE(MoPhase_CALLGRAPH_ANALYSIS, DoCallGraph) MODAPHASE(MoPhase_PREME, DoPreme) +MODAPHASE(MoPhase_IPO_DEVIRTULIZE, DoIPODevirtulize) +MODAPHASE(MoPhase_UPDATEMPLT_ANALYSIS, DoUpdateMplt) #if MIR_JAVA MODTPHASE(MoPhase_GENNATIVESTUBFUNC, DoGenerateNativeStubFunc) MODAPHASE(MoPhase_VTABLEANALYSIS, DoVtableAnalysis) @@ -32,4 +35,6 @@ MODTPHASE(MoPhase_MUIDREPLACEMENT, DoMUIDReplacement) MODTPHASE(MoPhase_CHECKCASTGENERATION, DoCheckCastGeneration) MODTPHASE(MoPhase_CodeReLayout, DoCodeReLayout) #endif +MODTPHASE(MoPhase_INLINE, DoInline) +MODTPHASE(MoPhase_OPENPROFILE, DoOpenProfile) MODTPHASE(MoPhase_CONSTANTFOLD, DoConstantFold) diff --git a/src/mapleall/maple_ipa/include/retype.h b/src/mapleall/maple_ipa/include/retype.h index 67ecb087d14ad2d06c9cb62b808bdd2f1f249c81..7e76a9df24fbfef293e3ea8afe40ed347065fb54 100644 --- a/src/mapleall/maple_ipa/include/retype.h +++ b/src/mapleall/maple_ipa/include/retype.h @@ -16,7 +16,7 @@ #define MAPLE_IPA_INCLUDE_RETYPE_H #include "module_phase.h" #include "mir_nodes.h" -#include "class_hierarchy.h" +#include "inline.h" namespace maple { class Retype { diff --git a/src/mapleall/maple_ipa/src/module_phase_manager.cpp b/src/mapleall/maple_ipa/src/module_phase_manager.cpp index d940f775a59abf79bfadb37977df3dc239cc36ed..23a5cd6fffbda6e508d9c61ec671093ab3a3e7dc 100644 --- a/src/mapleall/maple_ipa/src/module_phase_manager.cpp +++ b/src/mapleall/maple_ipa/src/module_phase_manager.cpp @@ -38,6 +38,7 @@ #include "constantfold.h" #include "barrierinsertion.h" #include "preme.h" +#include "openProfile.h" #endif // ~MIR_JAVA namespace { diff --git a/src/mapleall/maple_ir/BUILD.gn b/src/mapleall/maple_ir/BUILD.gn index adb50c2a4377574afeb406e424ae9bd544858989..3b4dea929cc34350673e7dd99661c932cae71190 100755 --- a/src/mapleall/maple_ir/BUILD.gn +++ b/src/mapleall/maple_ir/BUILD.gn @@ -22,7 +22,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/maple_phase/include", - "${MAPLE_ROOT}/third_party/dwarf/include", + "${MAPLE_ROOT}/third_party/dwarf_h/include", ] src_libmplir = [ @@ -51,9 +51,9 @@ src_libmplir = [ "src/bin_func_export.cpp", "src/bin_mpl_import.cpp", "src/bin_mpl_export.cpp", - "${MAPLEALL_ROOT}/maple_ipa/src/ea_connection_graph.cpp", "src/debug_info.cpp", "src/debug_info_util.cpp", + "${MAPLEALL_ROOT}/maple_ipa/src/ea_connection_graph.cpp", ] src_irbuild = [ "src/driver.cpp" ] diff --git a/src/mapleall/maple_ir/include/bin_mpl_import.h b/src/mapleall/maple_ir/include/bin_mpl_import.h index fdced8f4f975b81fad62d7a710e854707ad2fe66..1970d73ba25621337d34d33e300050b3c7d37c70 100644 --- a/src/mapleall/maple_ir/include/bin_mpl_import.h +++ b/src/mapleall/maple_ir/include/bin_mpl_import.h @@ -93,7 +93,6 @@ class BinaryMplImport { void InsertInHashTable(MIRType &ptype); void SetupEHRootType(); void UpdateMethodSymbols(); - void UpdateDebugInfo(); void ImportConstBase(MIRConstKind &kind, MIRTypePtr &type, uint32 &fieldID); MIRConst *ImportConst(MIRFunction *func); GStrIdx ImportStr(); diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index a794a8ea2a7ebeff260bfd3bcefadeb582604bb0..4ea0aef5d052b824ae2df8efe36027b66870ee5e 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -24,10 +24,7 @@ #include "lexer.h" #include "Dwarf.h" -using namespace maple; - namespace maple { - // for more color code: http://ascii-table.com/ansi-escape-sequences.php #define RESET "\x1B[0m" #define BOLD "\x1B[1m" @@ -152,7 +149,7 @@ class DBGExprLoc { virtual ~DBGExprLoc() {} bool IsSimp() const { - return (exprVec.size() == 0 && simpLoc->GetVal() != (int)kDbgDefaultVal); + return (exprVec.size() == 0 && simpLoc->GetVal() != static_cast(kDbgDefaultVal)); } int GetFboffset() const { @@ -326,7 +323,7 @@ class DBGDie { DBGDieAttr *AddAttr(DwAt attr, DwForm form, uint64 val); DBGDieAttr *AddSimpLocAttr(DwAt at, DwForm form, uint64 val); DBGDieAttr *AddGlobalLocAttr(DwAt at, DwForm form, uint64 val); - DBGDieAttr *AddFrmBaseAttr(DwAt at, DwForm form, uint64 val); + DBGDieAttr *AddFrmBaseAttr(DwAt at, DwForm form); DBGExprLoc *GetExprLoc(); bool SetAttr(DwAt attr, uint64 val); bool SetAttr(DwAt attr, int64 val); @@ -654,7 +651,7 @@ class DebugInfo { DBGDieAttr *CreateAttr(DwAt attr, DwForm form, uint64 val); - DBGDie *CreateVarDie(MIRSymbol *sym, uint32 lnum); + DBGDie *CreateVarDie(MIRSymbol *sym); DBGDie *CreateFormalParaDie(MIRFunction *func, MIRType *type, MIRSymbol *sym); DBGDie *CreateFieldDie(maple::FieldPair pair, uint32 lnum); DBGDie *CreateBitfieldDie(MIRBitFieldType *type, GStrIdx idx); @@ -667,7 +664,7 @@ class DebugInfo { DBGDie *GetOrCreateTypeAttrDie(MIRSymbol *sym); DBGDie *GetOrCreateConstTypeDie(TypeAttrs attr, DBGDie *typedie); DBGDie *GetOrCreateVolatileTypeDie(TypeAttrs attr, DBGDie *typedie); - DBGDie *GetOrCreateFuncDeclDie(MIRFunction *func, uint32 lnum); + DBGDie *GetOrCreateFuncDeclDie(MIRFunction *func); DBGDie *GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum); DBGDie *GetOrCreatePrimTypeDie(PrimType pty); DBGDie *GetOrCreateTypeDie(MIRType *type); @@ -707,7 +704,5 @@ class DebugInfo { MapleMap> funcLstrIdxLabIdxMap; MapleSet strps; }; - } // namespace maple - #endif // MAPLE_IR_INCLUDE_DBG_INFO_H diff --git a/src/mapleall/maple_ir/include/mir_module.h b/src/mapleall/maple_ir/include/mir_module.h index bf037b5877c4533a7786a2390f61dcb5eeff9325..2e106e8929c0320cc344e6bcc46cc2f3ef578c98 100644 --- a/src/mapleall/maple_ir/include/mir_module.h +++ b/src/mapleall/maple_ir/include/mir_module.h @@ -554,7 +554,7 @@ class MIRModule { void SetWithDbgInfo(bool v) { withDbgInfo = v; } - bool IsWithDbgInfo() { + bool IsWithDbgInfo() const { return withDbgInfo; } @@ -585,7 +585,7 @@ class MIRModule { TyIdx throwableTyIdx{0}; // a special type that is the base of java exception type. only used for java bool withProfileInfo = false; - DebugInfo *dbgInfo; + DebugInfo *dbgInfo = nullptr; bool withDbgInfo = false; // for cg in mplt diff --git a/src/mapleall/maple_ir/src/bin_mpl_import.cpp b/src/mapleall/maple_ir/src/bin_mpl_import.cpp index 73077f9b06eff9cba6591c55f28f82e3abd0ece1..00dd9679d485d8d249cc9f3056adfd8d43d7d8cd 100644 --- a/src/mapleall/maple_ir/src/bin_mpl_import.cpp +++ b/src/mapleall/maple_ir/src/bin_mpl_import.cpp @@ -741,7 +741,8 @@ MIRType &BinaryMplImport::InsertInTypeTables(MIRType &type) { (!IsIncomplete(*prevType) && !IsIncomplete(type)) || (!IsIncomplete(*prevType) && IsIncomplete(type)))) { resultTypePtr = prevType->CopyMIRTypeNode(); - if (resultTypePtr->GetKind() == kTypeStruct || resultTypePtr->GetKind() == kTypeUnion || resultTypePtr->GetKind() == kTypeStructIncomplete) { + if (resultTypePtr->GetKind() == kTypeStruct || resultTypePtr->GetKind() == kTypeUnion || + resultTypePtr->GetKind() == kTypeStructIncomplete) { tmpStruct.push_back(static_cast(resultTypePtr)); } else if (resultTypePtr->GetKind() == kTypeClass || resultTypePtr->GetKind() == kTypeClassIncomplete) { tmpClass.push_back(static_cast(resultTypePtr)); @@ -1344,9 +1345,6 @@ void BinaryMplImport::Jump2NextField() { ReadNum(); // skip end tag for this field } -void BinaryMplImport::UpdateDebugInfo() { -} - bool BinaryMplImport::Import(const std::string &fname, bool readSymbols, bool readSe) { Reset(); ReadFileAt(fname, 0); diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 13a139ec3411daa369ccf8c8ab7b65316a1a77da..9893f16558ea39db092b70ffe061933da7932202 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -12,12 +12,11 @@ * FIT FOR A PARTICULAR PURPOSE. * See the MulanPSL - 2.0 for more details. */ - +#include "debug_info.h" #include "mir_builder.h" #include "printing.h" #include "maple_string.h" #include "namemangler.h" -#include "debug_info.h" #include "global_tables.h" #include "mir_type.h" #include @@ -25,7 +24,6 @@ #include "mpl_logging.h" namespace maple { - extern const char *GetDwTagName(unsigned n); extern const char *GetDwFormName(unsigned n); extern const char *GetDwAtName(unsigned n); @@ -34,6 +32,14 @@ extern const char *GetDwAteName(unsigned n); extern const char *GetDwCfaName(unsigned n); extern DwAte GetAteFromPTY(PrimType pty); +constexpr uint32 kIndx2 = 2; +constexpr uint32 k2BitSize = 2; +constexpr uint32 k3BitSize = 3; +constexpr uint32 k4BitSize = 4; +constexpr uint32 k8BitSize = 8; +constexpr uint32 k9BitSize = 9; +constexpr uint32 kStructDBGSize = 8888; + // DBGDie methods DBGDie::DBGDie(MIRModule *m, DwTag tag) : module(m), @@ -90,7 +96,7 @@ DBGDieAttr *DBGDie::AddGlobalLocAttr(DwAt at, DwForm form, uint64 val) { return attr; } -DBGDieAttr *DBGDie::AddFrmBaseAttr(DwAt at, DwForm form, uint64 val) { +DBGDieAttr *DBGDie::AddFrmBaseAttr(DwAt at, DwForm form) { DBGExprLoc *p = module->GetMemPool()->New(module, DW_OP_call_frame_cfa); DBGDieAttr *attr = module->GetDbgInfo()->CreateAttr(at, form, reinterpret_cast(p)); AddAttr(attr); @@ -329,7 +335,7 @@ void DebugInfo::BuildDebugInfo() { } // function decl if (stridxDieIdMap.find(func->GetNameStrIdx().GetIdx()) == stridxDieIdMap.end()) { - DBGDie *fdie = GetOrCreateFuncDeclDie(func, 0); + DBGDie *fdie = GetOrCreateFuncDeclDie(func); if (!func->GetClassTyIdx().GetIdx() && func->GetBody()) { compUnit->AddSubVec(fdie); } @@ -429,7 +435,7 @@ DBGDie *DebugInfo::GetOrCreateLabelDie(LabelIdx labid) { return die; } -DBGDie *DebugInfo::CreateVarDie(MIRSymbol *sym, uint32 lnum) { +DBGDie *DebugInfo::CreateVarDie(MIRSymbol *sym) { // filter vtab if (sym->GetName().find(VTAB_PREFIX_STR) == 0) { return nullptr; @@ -444,7 +450,6 @@ DBGDie *DebugInfo::CreateVarDie(MIRSymbol *sym, uint32 lnum) { } bool isLocal = sym->IsLocal(); - if (isLocal) { MIRFunction *func = module->CurFunction(); if ((funcLstrIdxDieIdMap[func]).size() && @@ -491,7 +496,7 @@ DBGDie *DebugInfo::CreateVarDie(MIRSymbol *sym, uint32 lnum) { return die; } -DBGDie *DebugInfo::GetOrCreateFuncDeclDie(MIRFunction *func, uint32 lnum) { +DBGDie *DebugInfo::GetOrCreateFuncDeclDie(MIRFunction *func) { uint32 funcnameidx = func->GetNameStrIdx().GetIdx(); if (stridxDieIdMap.find(funcnameidx) != stridxDieIdMap.end()) { uint32 id = stridxDieIdMap[funcnameidx]; @@ -551,7 +556,7 @@ DBGDie *DebugInfo::GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum) { return idDieMap[id]; } - DBGDie *funcdecldie = GetOrCreateFuncDeclDie(func, lnum); + DBGDie *funcdecldie = GetOrCreateFuncDeclDie(func); DBGDie *die = module->GetMemPool()->New(module, DW_TAG_subprogram); // update funcDefStrIdxDieIdMap and leave stridxDieIdMap for the func decl funcDefStrIdxDieIdMap[funcnameidx] = die->GetId(); @@ -560,7 +565,7 @@ DBGDie *DebugInfo::GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum) { die->AddAttr(DW_AT_decl_line, DW_FORM_data4, lnum); die->AddAttr(DW_AT_low_pc, DW_FORM_addr, kDbgDefaultVal); die->AddAttr(DW_AT_high_pc, DW_FORM_data8, kDbgDefaultVal); - die->AddFrmBaseAttr(DW_AT_frame_base, DW_FORM_exprloc, kDbgDefaultVal); + die->AddFrmBaseAttr(DW_AT_frame_base, DW_FORM_exprloc); if (!func->IsStatic() && !LIsCompilerGenerated(func)) { die->AddAttr(DW_AT_object_pointer, DW_FORM_ref4, kDbgDefaultVal); } @@ -579,7 +584,7 @@ DBGDie *DebugInfo::GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum) { // local variables, start from 1 for (uint32 i = 1; i < func->GetSymTab()->GetSymbolTableSize(); i++) { MIRSymbol *var = func->GetSymTab()->GetSymbolFromStIdx(i); - DBGDie *vdie = CreateVarDie(var, 0); + DBGDie *vdie = CreateVarDie(var); die->AddSubVec(vdie); } } @@ -610,7 +615,7 @@ DBGDie *DebugInfo::GetOrCreatePrimTypeDie(PrimType pty) { DBGDie *DebugInfo::CreatePointedFuncTypeDie(MIRFuncType *ftype) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_subroutine_type); - die->AddAttr(DW_AT_prototyped, DW_FORM_data4, (int)(ftype->GetParamTypeList().size()>0)); + die->AddAttr(DW_AT_prototyped, DW_FORM_data4, static_cast(ftype->GetParamTypeList().size() > 0)); MIRType *rtype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ftype->GetRetTyIdx()); (void)GetOrCreateTypeDie(rtype); die->AddAttr(DW_AT_type, DW_FORM_ref4, ftype->GetRetTyIdx().GetIdx()); @@ -702,7 +707,7 @@ DBGDie *DebugInfo::GetOrCreatePointTypeDie(const MIRPtrType *ptrtype) { if (type && (type->GetPrimType() == PTY_void || type->GetKind() == kTypeFunction)) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_pointer_type); - die->AddAttr(DW_AT_byte_size, DW_FORM_data4, 8); + die->AddAttr(DW_AT_byte_size, DW_FORM_data4, k8BitSize); if (type->GetKind() == kTypeFunction) { DBGDie *pdie = GetOrCreateTypeDie(type); die->AddAttr(DW_AT_type, DW_FORM_ref4, type->GetTypeIndex().GetIdx()); @@ -727,7 +732,7 @@ DBGDie *DebugInfo::GetOrCreatePointTypeDie(const MIRPtrType *ptrtype) { } // update incomplete type from stridxDieIdMap to tyIdxDieIdMap - MIRStructType *stype = dynamic_cast(type); + MIRStructType *stype = static_cast(type); if (stype && stype->IsIncomplete()) { uint32 sid = stype->GetNameStrIdx().GetIdx(); if (stridxDieIdMap.find(sid) != stridxDieIdMap.end()) { @@ -739,7 +744,7 @@ DBGDie *DebugInfo::GetOrCreatePointTypeDie(const MIRPtrType *ptrtype) { } DBGDie *die = module->GetMemPool()->New(module, DW_TAG_pointer_type); - die->AddAttr(DW_AT_byte_size, DW_FORM_data4, 8); + die->AddAttr(DW_AT_byte_size, DW_FORM_data4, k8BitSize); // fill with type idx instead of typedie->id to avoid nullptr typedie of // forward reference of class types die->AddAttr(DW_AT_type, DW_FORM_ref4, type->GetTypeIndex().GetIdx()); @@ -761,7 +766,7 @@ DBGDie *DebugInfo::GetOrCreateArrayTypeDie(const MIRArrayType *arraytype) { (void)GetOrCreateTypeDie(type); DBGDie *die = module->GetMemPool()->New(module, DW_TAG_array_type); - die->AddAttr(DW_AT_byte_size, DW_FORM_data4, 8); + die->AddAttr(DW_AT_byte_size, DW_FORM_data4, k8BitSize); // fill with type idx instead of typedie->id to avoid nullptr typedie of // forward reference of class types die->AddAttr(DW_AT_type, DW_FORM_ref4, type->GetTypeIndex().GetIdx()); @@ -813,8 +818,8 @@ DBGDie *DebugInfo::CreateBitfieldDie(MIRBitFieldType *type, GStrIdx sidx) { die->AddAttr(DW_AT_byte_size, DW_FORM_data4, GetPrimTypeSize(type->GetPrimType())); die->AddAttr(DW_AT_bit_size, DW_FORM_data4, type->GetFieldSize()); - die->AddAttr(DW_AT_bit_offset, DW_FORM_data4, GetPrimTypeSize(type->GetPrimType())*8-type->GetFieldSize()); - + die->AddAttr(DW_AT_bit_offset, DW_FORM_data4, + GetPrimTypeSize(type->GetPrimType()) * k8BitSize - type->GetFieldSize()); die->AddAttr(DW_AT_data_member_location, DW_FORM_data4, 0); return die; @@ -883,7 +888,7 @@ DBGDie *DebugInfo::CreateStructTypeDie(GStrIdx strIdx, const MIRStructType *stru compUnit->AddSubVec(die); - die->AddAttr(DW_AT_decl_line, DW_FORM_data4, 8888); + die->AddAttr(DW_AT_decl_line, DW_FORM_data4, kStructDBGSize); die->AddAttr(DW_AT_name, DW_FORM_strp, strIdx.GetIdx()); die->AddAttr(DW_AT_byte_size, DW_FORM_data4, kDbgDefaultVal); die->AddAttr(DW_AT_decl_file, DW_FORM_data4, mplSrcIdx.GetIdx()); @@ -894,7 +899,7 @@ DBGDie *DebugInfo::CreateStructTypeDie(GStrIdx strIdx, const MIRStructType *stru for (int64 i = 0; i < structtype->GetFieldsSize(); i++) { MIRType *ety = structtype->GetElemType(i); FieldPair fp = structtype->GetFieldsElemt(i); - if (MIRBitFieldType *bfty = dynamic_cast(ety)) { + if (MIRBitFieldType *bfty = static_cast(ety)) { DBGDie *bfdie = CreateBitfieldDie(bfty, fp.first); die->AddSubVec(bfdie); } else { @@ -916,7 +921,7 @@ DBGDie *DebugInfo::CreateStructTypeDie(GStrIdx strIdx, const MIRStructType *stru ASSERT(symbol && symbol->GetSKind() == kStFunc, "member function symbol not exist"); MIRFunction *func = symbol->GetValue().mirFunc; ASSERT(func, "member function not exist"); - DBGDie *fdie = GetOrCreateFuncDeclDie(func, 0); + DBGDie *fdie = GetOrCreateFuncDeclDie(func); die->AddSubVec(fdie); } @@ -1076,8 +1081,8 @@ void DebugInfo::FillTypeAttrWithDieId() { if (dieid) { at->SetId(dieid); } else { - LogInfo::MapleLogger() << "dieid not found, typeKind = " << type->GetKind() << " primType = " << type->GetPrimType() - << " nameStrIdx = " << type->GetNameStrIdx().GetIdx() << std::endl; + LogInfo::MapleLogger() << "dieid not found, typeKind = " << type->GetKind() << " primType = " + << type->GetPrimType() << " nameStrIdx = " << type->GetNameStrIdx().GetIdx() << std::endl; } } else { LogInfo::MapleLogger() << "type not found, tid = " << tid << std::endl; @@ -1126,7 +1131,7 @@ uint32 DBGDieAttr::SizeOf(DBGDieAttr *attr) { // case DW_FORM_codeLinestrp: // case DW_FORM_strp_sup: // case DW_FORM_ref_sup: - return 4; // DWARF32, 8 if DWARF64 + return k4BitSize; // DWARF32, 8 if DWARF64 case DW_FORM_string: { GStrIdx stridx(attr->value.id); @@ -1135,25 +1140,25 @@ uint32 DBGDieAttr::SizeOf(DBGDieAttr *attr) { } case DW_FORM_exprloc: { DBGExprLoc *ptr = attr->value.ptr; - CHECK_FATAL(ptr != (DBGExprLoc *)0xdeadbeef, "wrong ptr"); + CHECK_FATAL(ptr != (DBGExprLoc*)(0xdeadbeef), "wrong ptr"); switch (ptr->GetOp()) { case DW_OP_call_frame_cfa: - return 2; // size 1 byte + DW_OP_call_frame_cfa 1 byte + return k2BitSize; // size 1 byte + DW_OP_call_frame_cfa 1 byte case DW_OP_fbreg: { // DW_OP_fbreg 1 byte uint32 size = 1 + namemangler::GetSleb128Size(ptr->GetFboffset()); return size + namemangler::GetUleb128Size(size); } case DW_OP_addr: { - return namemangler::GetUleb128Size(9) + 9; + return namemangler::GetUleb128Size(k9BitSize) + k9BitSize; } default: - return 4; + return k4BitSize; } } default: CHECK_FATAL(maple::GetDwFormName(form) != nullptr, - "GetDwFormName return null in DebugInfo::FillTypeAttrWithDieId"); + "GetDwFormName return null in DebugInfo::FillTypeAttrWithDieId"); LogInfo::MapleLogger() << "unhandled SizeOf: " << maple::GetDwFormName(form) << std::endl; return 0; } @@ -1202,9 +1207,10 @@ void DebugInfo::ComputeSizeAndOffset(DBGDie *die, uint32 &cuOffset) { } } -/////////////////////////////// -// Dumps -/////////////////////////////// +/* /////////////// + * Dumps + * /////////////// + */ void DebugInfo::Dump(int indent) { LogInfo::MapleLogger() << "\n" << std::endl; LogInfo::MapleLogger() << "maple_debug_information {" @@ -1295,11 +1301,12 @@ void DBGAbbrevEntry::Dump(int indent) { } else { LogInfo::MapleLogger() << " [no children] {" << std::endl; } - for (uint32 i = 0; i < attrPairs.size(); i += 2) { + for (uint32 i = 0; i < attrPairs.size(); i += k2BitSize) { PrintIndentation(indent + 1); CHECK_FATAL(GetDwAtName(attrPairs[i]) && GetDwFormName(attrPairs[i + 1]), "NULLPTR CHECK"); - LogInfo::MapleLogger() << " " << GetDwAtName(attrPairs[i]) << " " << GetDwFormName(attrPairs[i + 1]) << " " << std::endl; + LogInfo::MapleLogger() << " " << GetDwAtName(attrPairs[i]) << " " << GetDwFormName(attrPairs[i + 1]) + << " " << std::endl; } PrintIndentation(indent); LogInfo::MapleLogger() << "}" << std::endl; @@ -1325,10 +1332,10 @@ void DBGCompileMsgInfo::ClearLine(uint32 n) { DBGCompileMsgInfo::DBGCompileMsgInfo() : startLine(0), errPos(0) { lineNum[0] = 0; lineNum[1] = 0; - lineNum[2] = 0; + lineNum[kIndx2] = 0; ClearLine(0); ClearLine(1); - ClearLine(2); + ClearLine(kIndx2); errLNum = 0; errCNum = 0; } @@ -1344,7 +1351,7 @@ void DBGCompileMsgInfo::UpdateMsg(uint32 lnum, const char *line) { if (size > MAXLINELEN - 1) { size = MAXLINELEN - 1; } - startLine = (startLine + 2) % 3; + startLine = (startLine + k2BitSize) % k3BitSize; ClearLine(startLine); errno_t eNum = memcpy_s(codeLine[startLine], MAXLINELEN, line, size); if (eNum) { @@ -1358,7 +1365,7 @@ void DBGCompileMsgInfo::EmitMsg() { char str[MAXLINELEN + 1]; errPos = errCNum; - errPos = (errPos < 2) ? 2 : errPos; + errPos = (errPos < k2BitSize) ? k2BitSize : errPos; errPos = (errPos > MAXLINELEN) ? MAXLINELEN : errPos; for (uint32 i = 0; i < errPos - 1; i++) { str[i] = ' '; @@ -1371,14 +1378,13 @@ void DBGCompileMsgInfo::EmitMsg() { fprintf(stderr, BOLD YEL " Compilation Error Diagnosis " RESET); fprintf(stderr, "==================\n"); fprintf(stderr, "===================================================================\n"); - fprintf(stderr, "line %4d %s\n", lineNum[(startLine + 2) % 3], - reinterpret_cast(codeLine[(startLine + 2) % 3])); - fprintf(stderr, "line %4d %s\n", lineNum[(startLine + 1) % 3], - reinterpret_cast(codeLine[(startLine + 1) % 3])); - fprintf(stderr, "line %4d %s\n", lineNum[(startLine + 0) % 3], - reinterpret_cast(codeLine[(startLine + 0) % 3])); + fprintf(stderr, "line %4d %s\n", lineNum[(startLine + k2BitSize) % k3BitSize], + reinterpret_cast(codeLine[(startLine + k2BitSize) % k3BitSize])); + fprintf(stderr, "line %4d %s\n", lineNum[(startLine + 1) % k3BitSize], + reinterpret_cast(codeLine[(startLine + 1) % k3BitSize])); + fprintf(stderr, "line %4d %s\n", lineNum[(startLine + 0) % k3BitSize], + reinterpret_cast(codeLine[(startLine + 0) % k3BitSize])); fprintf(stderr, BOLD RED " %s\n" RESET, str); fprintf(stderr, "===================================================================\n"); } - } // namespace maple diff --git a/src/mapleall/maple_ir/src/debug_info_util.cpp b/src/mapleall/maple_ir/src/debug_info_util.cpp index 1ff75cfa6a7607a07d72f21982074d105fe9c07f..c9c3516029162184c4f816a9f084d97a696c9694 100644 --- a/src/mapleall/maple_ir/src/debug_info_util.cpp +++ b/src/mapleall/maple_ir/src/debug_info_util.cpp @@ -25,7 +25,6 @@ #include "mpl_logging.h" namespace maple { - #define TOSTR(s) #s // utility functions to get the string from tag value etc. // GetDwTagName(unsigned n) @@ -37,7 +36,7 @@ const char *GetDwTagName(unsigned n) { case DW_TAG_hi_user: return "DW_TAG_hi_user"; case DW_TAG_user_base: return "DW_TAG_user_base"; } - return 0; + return nullptr; } // GetDwFormName(unsigned n) @@ -47,7 +46,7 @@ const char *GetDwFormName(unsigned n) { #include "Dwarf.def" case DW_FORM_lo_user: return "DW_FORM_lo_user"; } - return 0; + return nullptr; } // GetDwAtName(unsigned n) @@ -57,7 +56,7 @@ const char *GetDwAtName(unsigned n) { #include "Dwarf.def" case DW_AT_lo_user: return "DW_AT_lo_user"; } - return 0; + return nullptr; } // GetDwOpName(unsigned n) @@ -72,7 +71,7 @@ const char *GetDwOpName(unsigned n) { case DW_OP_LLVM_tag_offset: return "DW_OP_LLVM_tag_offset"; case DW_OP_LLVM_entry_value: return "DW_OP_LLVM_entry_value"; } - return 0; + return nullptr; } #define DW_ATE_void 0x20 @@ -85,7 +84,7 @@ const char *GetDwAteName(unsigned n) { case DW_ATE_hi_user: return "DW_ATE_hi_user"; case DW_ATE_void: return "DW_ATE_void"; } - return 0; + return nullptr; } // GetDwCfaName(unsigned n) @@ -98,7 +97,7 @@ const char *GetDwCfaName(unsigned n) { case DW_CFA_lo_user: return "DW_CFA_lo_user"; case DW_CFA_hi_user: return "DW_CFA_hi_user"; } - return 0; + return nullptr; } DwAte GetAteFromPTY(PrimType pty) { @@ -136,5 +135,4 @@ DwAte GetAteFromPTY(PrimType pty) { return DW_ATE_void; } } - } // namespace maple diff --git a/src/mapleall/maple_ir/src/lexer.cpp b/src/mapleall/maple_ir/src/lexer.cpp index 6a877c708f77c60f514b7096df4aaf87b075bba2..e21cc8c01ae5f9cbb5d7a80e13fce30fda69a3a8 100644 --- a/src/mapleall/maple_ir/src/lexer.cpp +++ b/src/mapleall/maple_ir/src/lexer.cpp @@ -17,10 +17,10 @@ #include #include #include "mpl_logging.h" +#include "debug_info.h" #include "mir_module.h" #include "securec.h" #include "utils.h" -#include "debug_info.h" namespace maple { int32 HexCharToDigit(char c) { @@ -86,7 +86,6 @@ void MIRLexer::PrepareForFile(const std::string &filename) { } else { lineNum = 1; } - module.GetDbgInfo()->UpdateMsg(lineNum, line.c_str()); kind = TK_invalid; } @@ -543,7 +542,6 @@ TokenKind MIRLexer::LexToken() { return TK_eof; } ++lineNum; // a new line read. - module.GetDbgInfo()->UpdateMsg(lineNum, line.c_str()); // skip spaces c = GetCurrentCharWithUpperCheck(); while (c == ' ' || c == '\t') { diff --git a/src/mapleall/maple_ir/src/mir_function.cpp b/src/mapleall/maple_ir/src/mir_function.cpp index 42195d17dfbb4ec4ec505708e757555d1a26e3a0..ab212d7fa5a88e3228ba3cd432d4e79589f21ce1 100644 --- a/src/mapleall/maple_ir/src/mir_function.cpp +++ b/src/mapleall/maple_ir/src/mir_function.cpp @@ -297,7 +297,7 @@ void MIRFunction::Dump(bool withoutBody) { // class and interface decls. these has nothing in formals // they do have paramtypelist_. this can not skip ones without args // but for them at least the func decls are valid - if ((module->IsJavaModule() && GetParamSize() != formalDefVec.size()) || + if ((module->IsJavaModule() && GetParamSize() != formalDefVec.size()) || GetAttr(FUNCATTR_optimized)) { return; } diff --git a/src/mapleall/maple_ir/src/mir_module.cpp b/src/mapleall/maple_ir/src/mir_module.cpp index c4efb90699ad3d28502c10a350a621ff41e78518..f65136bceea6b4290b5bba5af71863aa90e6ce1a 100644 --- a/src/mapleall/maple_ir/src/mir_module.cpp +++ b/src/mapleall/maple_ir/src/mir_module.cpp @@ -639,9 +639,6 @@ void MIRModule::OutputAsciiMpl(const char *phaseName, const char *suffix, std::streambuf *backup = LogInfo::MapleLogger().rdbuf(); LogInfo::MapleLogger().rdbuf(mplFile.rdbuf()); // change LogInfo::MapleLogger()'s buffer to that of file Dump(emitStructureType, dumpFuncSet); - if (withDbgInfo) { - dbgInfo->Dump(0); - } LogInfo::MapleLogger().rdbuf(backup); // restore LogInfo::MapleLogger()'s buffer mplFile.close(); } else { @@ -649,6 +646,13 @@ void MIRModule::OutputAsciiMpl(const char *phaseName, const char *suffix, binaryMplt.GetBinExport().not2mplt = true; binaryMplt.Export(outfileName); } + std::ofstream mplFile; + mplFile.open(outfileName, std::ios::trunc); + std::streambuf *backup = LogInfo::MapleLogger().rdbuf(); + LogInfo::MapleLogger().rdbuf(mplFile.rdbuf()); // change cout's buffer to that of file + Dump(emitStructureType); + LogInfo::MapleLogger().rdbuf(backup); // restore cout's buffer + mplFile.close(); } uint32 MIRModule::GetFileinfo(GStrIdx strIdx) const { diff --git a/src/mapleall/maple_ir/src/mpl_dbg.cpp b/src/mapleall/maple_ir/src/mpl_dbg.cpp deleted file mode 100644 index 10b5a4435a45a2f8633dcfd261ff872cdbaf3d8c..0000000000000000000000000000000000000000 --- a/src/mapleall/maple_ir/src/mpl_dbg.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. - * - * OpenArkCompiler is licensed under the Mulan Permissive Software License v2. - * You can use this software according to the terms and conditions of the MulanPSL - 2.0. - * You may obtain a copy of MulanPSL - 2.0 at: - * - * https://opensource.org/licenses/MulanPSL-2.0 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. - * See the MulanPSL - 2.0 for more details. - */ - -#include "mir_parser.h" -#include "debug_info.h" -#include "bin_mplt.h" -#include "opcode_info.h" -#include -#include "mir_function.h" -#include "mir_type.h" -#include -#include - -using namespace maple; - -std::unordered_set dumpFuncSet = {}; - -int main(int argc, char **argv) { - if (argc < 2) { - MIR_PRINTF("usage: mpldbg foo.mpl\n"); - exit(1); - } - std::vector themodule(argc, nullptr); - bool useBinary = false; - MIRSrcLang srcLang = kSrcLangUnknown; - // process the options which must come first - maple::int32 i = 1; - while (argv[i][0] == '-' ) { - if (argv[i][1] == 'b' && argv[i][2] == '\0') { - useBinary = true; - } else if (strncmp(argv[i], "-dumpfunc=", 10) == 0 && strlen(argv[i]) > 10) { - std::string funcName(&argv[i][10]); - dumpFuncSet.insert(funcName); - } else if (strcmp(argv[i], "-srclang=java") == 0 ) { - srcLang = kSrcLangJava; - } else if (strcmp(argv[i], "-srclang=c") == 0 ) { - srcLang = kSrcLangC; - } else if (strcmp(argv[i], "-srclang=c++") == 0 ) { - srcLang = kSrcLangCPlusPlus; - } else { - ERR(kLncErr, "mpldbg: unrecognized command line option"); - return 1; - } - i++; - } - // process the input files - while (i < argc) { - themodule[i] = new maple::MIRModule(argv[i]); - themodule[i]->SetSrcLang(srcLang); - std::string::size_type lastdot = themodule[i]->GetFileName().find_last_of("."); - bool ismplt = themodule[i]->GetFileName().compare(lastdot, 5, ".mplt") == 0; - bool istmpl = themodule[i]->GetFileName().compare(lastdot, 5, ".tmpl") == 0; - bool ismpl = themodule[i]->GetFileName().compare(lastdot, 5, ".mpl\0") == 0; - bool isbpl = themodule[i]->GetFileName().compare(lastdot, 5, ".bpl\0") == 0; - if (!ismplt && !istmpl && !ismpl && !isbpl) { - ERR(kLncErr, "mpldbg: input must be .mplt or .mpl or .bpl or .tmpl file"); - return 1; - } - // input the file - if (ismpl || istmpl) { - maple::MIRParser theparser(*themodule[i]); - if (!theparser.ParseMIR()) { - theparser.EmitError(themodule[i]->GetFileName().c_str()); - return 1; - } - } else { - BinaryMplImport binMplt(*themodule[i]); - binMplt.SetImported(false); - std::string modid = themodule[i]->GetFileName(); - if (!binMplt.Import(modid, true)) { - ERR(kLncErr, "mpldbg: cannot open .mplt or .bpl file: %s", modid.c_str()); - return 1; - } - } - - themodule[i]->GetDbgInfo()->BuildDebugInfo(); - themodule[i]->SetWithDbgInfo(true); - - // output the file - themodule[i]->OutputAsciiMpl(".dbg", (ismpl || isbpl) ? ".mpl" : ".tmpl"); - i++; - } - return 0; -} diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index 7e4044fc82a4a79a7552c73cf50c737e55c5240f..1090783ba5196c14817d6a45b34c9508f4d7bb24 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -162,8 +162,6 @@ void MIRParser::Error(const std::string &str) { message += ": "; message += lexer.GetTokenString(); message += "\n"; - - mod.GetDbgInfo()->SetErrPos(lexer.GetLineNum(), lexer.GetCurIdx()); } const std::string &MIRParser::GetError() { @@ -2882,7 +2880,6 @@ void MIRParser::EmitError(const std::string &fileName) { if (!strlen(GetError().c_str())) { return; } - mod.GetDbgInfo()->EmitMsg(); ERR(kLncErr, "%s \n%s", fileName.c_str(), GetError().c_str()); } diff --git a/src/mapleall/maple_me/src/sync_select.cpp b/src/mapleall/maple_me/src/sync_select.cpp index c5a47c578f46d2b6a22eca16eff58222459c58db..14ef035529d0e01ce2272e4f3c4035056d2d55d2 100644 --- a/src/mapleall/maple_me/src/sync_select.cpp +++ b/src/mapleall/maple_me/src/sync_select.cpp @@ -29,6 +29,7 @@ class SyncSelect { public: explicit SyncSelect(MeFunction &func) : func(func) { + AddFunc(SyncKind::kDefault, "Landroid_2Fos_2FParcel_3B_7Crecycle_7C_28_29V"); } ~SyncSelect() = default; @@ -41,8 +42,8 @@ class SyncSelect { } private: - void AddFunc(uint8 kind, const std::string &funcName) { - syncMap[funcName] = static_cast(kind); + void AddFunc(SyncKind kind, const std::string &funcName) { + syncMap[funcName] = kind; } void SetAllSyncKind(SyncKind kind) { diff --git a/src/mapleall/mpl2mpl/include/constantfold.h b/src/mapleall/mpl2mpl/include/constantfold.h index 4b45e1b58a601643acfe9477adf67979cfd01a93..0bf8d497a0775c36977b71a6a67618e434f91cd8 100644 --- a/src/mapleall/mpl2mpl/include/constantfold.h +++ b/src/mapleall/mpl2mpl/include/constantfold.h @@ -133,6 +133,9 @@ class DoConstantFold : public ModulePhase { AnalysisResult *Run(MIRModule *mod, ModuleResultMgr *mrm) override { OPT_TEMPLATE(ConstantFold); + if (MeOption::meVerify) { + VerifyGlobalTypeTable(); + } return nullptr; } }; diff --git a/src/mapleall/mpl2mpl/include/muid_replacement.h b/src/mapleall/mpl2mpl/include/muid_replacement.h index 62d3233cd68399ce3c53e8b065c3d50fff46f9f1..d3334d646280af420ac40f6d1630e25093b062ab 100644 --- a/src/mapleall/mpl2mpl/include/muid_replacement.h +++ b/src/mapleall/mpl2mpl/include/muid_replacement.h @@ -121,11 +121,20 @@ class MUIDReplacement : public FuncOptimizeImpl { void ReplaceFieldTypeTable(const std::string &name); BaseNode *ReplaceDreadExpr(MIRFunction *currentFunc, StmtNode *stmt, BaseNode *expr); BaseNode *ReplaceDread(MIRFunction ¤tFunc, const StmtNode *stmt, BaseNode *opnd); + void CollectFieldCallSite(); + void CollectDreadStmt(MIRFunction *currentFunc, BlockNode *block, StmtNode *stmt); + BaseNode *CollectDreadExpr(MIRFunction *currentFunc, BlockNode &block, StmtNode *stmt, BaseNode *expr); void CollectDread(MIRFunction ¤tFunc, StmtNode &stmt, BaseNode &opnd); void DumpMUIDFile(bool isFunc); void ReplaceStmts(); void GenerateGlobalRootList(); void CollectImplicitUndefClassInfo(StmtNode &stmt); + void CollectFuncAndData(); + void InsertFunctionProfile(MIRFunction ¤tFunc, int64 index); + void GenericSourceMuid(); + void GenCompilerMfileStatus(); + bool FindFuncNameInSimplfy(const std::string &name); + bool CheckFunctionIsUsed(const MIRFunction &mirFunc) const; void ReplaceMethodMetaFuncAddr(MIRSymbol &funcSymbol, int64 index); void ReplaceFieldMetaStaticAddr(const MIRSymbol &mirSymbol, uint32 index); void CollectFuncAndDataFromKlasses(); @@ -169,11 +178,13 @@ class MUIDReplacement : public FuncOptimizeImpl { #define __MRT_MAGIC_PASTE2(x, y) x##y #define CLASS_PREFIX(classname) TO_STR(__MRT_MAGIC_PASTE(CLASSINFO_PREFIX, classname)), const std::unordered_set preloadedClassInfo = { +#include "white_list.def" }; #undef CLASS_PREFIX #undef __MRT_MAGIC_PASTE2 #undef __MRT_MAGIC_PASTE const std::unordered_set reflectionList = { +#include "reflection_list.def" }; bool isLibcore = false; MIRSymbol *funcDefTabSym = nullptr; diff --git a/src/mapleall/mpl2mpl/include/openProfile.h b/src/mapleall/mpl2mpl/include/openProfile.h new file mode 100644 index 0000000000000000000000000000000000000000..563c44710a16fc64010a80f525b284c00eae2078 --- /dev/null +++ b/src/mapleall/mpl2mpl/include/openProfile.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#ifndef MAPLE_MPL2MPL_INCLUDE_OPENPROFILE_H +#define MAPLE_MPL2MPL_INCLUDE_OPENPROFILE_H +#include "mir_module.h" + +namespace maple { +class DoOpenProfile : public ModulePhase { + public: + DoOpenProfile(ModulePhaseID id) : ModulePhase(id) {} + + AnalysisResult *Run(MIRModule *module, ModuleResultMgr*) override { + uint32 dexNameIdx = module->GetFileinfo(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("INFO_filename")); + const std::string &dexName = GlobalTables::GetStrTable().GetStringFromStrIdx(GStrIdx(dexNameIdx)); + bool deCompressSucc = module->GetProfile().DeCompress(Options::profile, dexName); + if (!deCompressSucc) { + LogInfo::MapleLogger() << "WARN: DeCompress() failed in DoOpenProfile::Run()\n"; + } + return nullptr; + } + + std::string PhaseName() const override { + return "openprofile"; + } +}; +} // namespace maple +#endif // MAPLE_MPL2MPL_INCLUDE_OPENPROFILE_H diff --git a/src/mapleall/mpl2mpl/src/muid_replacement.cpp b/src/mapleall/mpl2mpl/src/muid_replacement.cpp index 48453ad65a60669cb9f96512721b6fe919c352a7..215cc77fae9a259fd2a080091df7020ca28e5052 100644 --- a/src/mapleall/mpl2mpl/src/muid_replacement.cpp +++ b/src/mapleall/mpl2mpl/src/muid_replacement.cpp @@ -14,9 +14,10 @@ */ #include "muid_replacement.h" #include -#include "vtable_analysis.h" #include "reflection_analysis.h" #include "me_profile_gen.h" +#include "module_phase.h" +#include "phase_impl.h" namespace { // Version for the mpl linker @@ -38,8 +39,6 @@ constexpr maple::uint64 kFromDefIndexMask = 0x2000000000000000; constexpr maple::uint64 KReservedBits = 2u; constexpr maple::uint32 kFromUndefIndexMask32Mod = 0x80000000; constexpr maple::uint32 kFromDefIndexMask32Mod = 0x40000000; - - } // namespace // MUIDReplacement @@ -72,6 +71,14 @@ ConstvalNode* MUIDReplacement::GetConstvalNode(int64 index) { #endif } +bool MUIDReplacement::CheckFunctionIsUsed(const MIRFunction &mirFunc) const { + if (Options::decoupleStatic && mirFunc.GetAttr(FUNCATTR_static)) { + return false; + } else { + return true; + } +} + void MUIDReplacement::DumpMUIDFile(bool isFunc) { std::ofstream outFile; const std::string &mplName = GetMIRModule().GetFileName(); @@ -230,6 +237,9 @@ void MUIDReplacement::CollectFuncAndDataFromKlasses() { MIRSymbol *funcSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(vMethodPair->first.Idx()); MIRFunction *mirFunc = funcSymbol->GetFunction(); if (mirFunc != nullptr && mirFunc->GetBody() == nullptr && !mirFunc->IsAbstract()) { + if (!CheckFunctionIsUsed(*mirFunc)) { + continue; + } AddUndefFunc(mirFunc); } } @@ -246,7 +256,11 @@ void MUIDReplacement::CollectFuncAndDataFromGlobalTab() { CHECK_FATAL(mirSymbol != nullptr, "Invalid global data symbol at index %u", i); if (mirSymbol->GetStorageClass() == kScGlobal) { if (mirSymbol->IsReflectionClassInfo()) { - mirSymbol->SetStorageClass(kScFstatic); + if (!mirSymbol->IsForcedGlobalClassinfo() && + preloadedClassInfo.find(mirSymbol->GetName()) == preloadedClassInfo.end()) { + // With maple linker, global data can be declared as local + mirSymbol->SetStorageClass(kScFstatic); + } if (mirSymbol->GetKonst() != nullptr) { // Use this to exclude forward-declared classinfo symbol AddDefData(mirSymbol); @@ -309,7 +323,140 @@ void MUIDReplacement::CollectFuncAndDataFromFuncList() { MIRFunction *undefMIRFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puidx); if (undefMIRFunc->GetBody() == nullptr && (undefMIRFunc->IsJava() || !undefMIRFunc->GetBaseClassName().empty())) { - AddUndefFunc(undefMIRFunc); + if (CheckFunctionIsUsed(*undefMIRFunc)) { + AddUndefFunc(undefMIRFunc); + } + } + } + // Some stmt requires classinfo but is lowered in CG. Handle them here. + CollectImplicitUndefClassInfo(*stmt); + stmt = stmt->GetNext(); + } + } +} + +void MUIDReplacement::CollectFuncAndData() { + // Iterate klasses + for (Klass *klass : klassHierarchy->GetTopoSortedKlasses()) { + MIRStructType *sType = klass->GetMIRStructType(); + // DefTable and UndefTable are placed where a class is defined + if (sType == nullptr || !sType->IsLocal()) { + continue; + } + // Collect FuncDefSet + for (MethodPair &methodPair : sType->GetMethods()) { + MIRSymbol *funcSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(methodPair.first.Idx()); + MIRFunction *mirFunc = funcSymbol->GetFunction(); + CHECK_FATAL(mirFunc != nullptr, "Invalid function symbol for Class %s", sType->GetName().c_str()); + if (mirFunc != nullptr && mirFunc->GetBody()) { + AddDefFunc(mirFunc); + } + } + // Cases where an external method can be referred: + // 1. vtable entry (what we are dealing with here) + // 2. direct call (collected later when iterating function bodies) + if (!klass->IsInterface()) { + for (MethodPair *vMethodPair : sType->GetVTableMethods()) { + CHECK_FATAL(vMethodPair != nullptr, "Invalid vtable_methods entry for Class %s", sType->GetName().c_str()); + + MIRSymbol *funcSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(vMethodPair->first.Idx()); + MIRFunction *mirFunc = funcSymbol->GetFunction(); + if (mirFunc != nullptr && !mirFunc->GetBody() && !mirFunc->IsAbstract()) { + if (CheckFunctionIsUsed(*mirFunc)) { + AddUndefFunc(mirFunc); + } + } + } + } + } + // Iterate global symbols + for (size_t i = 1; i < GlobalTables::GetGsymTable().GetSymbolTableSize(); ++i) { + // entry 0 is reserved as nullptr + MIRSymbol *mirSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(i); + CHECK_FATAL(mirSymbol != nullptr, "Invalid global data symbol at index %u", i); + if (mirSymbol->GetStorageClass() == kScGlobal) { + if (mirSymbol->IsReflectionClassInfo()) { + if (!mirSymbol->IsForcedGlobalClassinfo() && + preloadedClassInfo.find(mirSymbol->GetName()) == preloadedClassInfo.end()) { + // With maple linker, global data can be declared as local + mirSymbol->SetStorageClass(kScFstatic); + } + if (mirSymbol->GetKonst() != nullptr) { + // Use this to exclude forward-declared classinfo symbol + AddDefData(mirSymbol); + } + } else if (mirSymbol->IsStatic()) { + mirSymbol->SetStorageClass(kScFstatic); + AddDefData(mirSymbol); + } + } else if (mirSymbol->GetStorageClass() == kScExtern && + (mirSymbol->IsReflectionClassInfo() || mirSymbol->IsStatic())) { + AddUndefData(mirSymbol); + } + } + // Iterate function bodies + for (MIRFunction *mirFunc : GetMIRModule().GetFunctionList()) { + if (mirFunc->GetBody() == nullptr) { + continue; + } + StmtNode *stmt = mirFunc->GetBody()->GetFirst(); + while (stmt != nullptr) { + PUIdx puidx = 0; + switch (stmt->GetOpCode()) { + case OP_call: + case OP_callassigned: { + puidx = static_cast(stmt)->GetPUIdx(); + break; + } + case OP_dassign: { + // epre in ME may have splitted a direct call into addroffunc and an indirect call + BaseNode *rhs = static_cast(stmt)->GetRHS(); + if (rhs != nullptr && rhs->GetOpCode() == OP_addroffunc) { + puidx = static_cast(rhs)->GetPUIdx(); + } + break; + } + case OP_regassign: { + BaseNode *rhs = static_cast(stmt)->Opnd(0); + if (rhs != nullptr && rhs->GetOpCode() == OP_addroffunc) { + puidx = static_cast(rhs)->GetPUIdx(); + } + break; + } + case OP_catch: { + auto &catchNode = static_cast(*stmt); + if (catchNode.GetExceptionTyIdxVec().size() != 1) { + break; + } + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(catchNode.GetExceptionTyIdxVecElement(0)); + ASSERT(type->GetKind() == kTypePointer, "Must be pointer"); + auto *pType = static_cast(type); + Klass *catchClass = nullptr; + if (pType->GetPointedTyIdx() == PTY_void) { + catchClass = klassHierarchy->GetKlassFromName(namemangler::kJavaLangExceptionStr); + } else { + catchClass = klassHierarchy->GetKlassFromTyIdx(pType->GetPointedTyIdx()); + } + if (catchClass != nullptr) { + std::string classInfoName = CLASSINFO_PREFIX_STR + catchClass->GetKlassName(); + MIRSymbol *classSym = GetSymbolFromName(classInfoName); + if (classSym == nullptr) { + classSym = builder->CreateGlobalDecl(classInfoName, *GlobalTables::GetTypeTable().GetPtr()); + classSym->SetStorageClass(kScExtern); + AddUndefData(classSym); + } + } + break; + } + default: + break; + } + if (puidx != 0) { + MIRFunction *undefMIRFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puidx); + if (!undefMIRFunc->GetBody() && (undefMIRFunc->IsJava() || !undefMIRFunc->GetBaseClassName().empty())) { + if (CheckFunctionIsUsed(*undefMIRFunc)) { + AddUndefFunc(undefMIRFunc); + } } } // Some stmt requires classinfo but is lowered in CG. Handle them here. @@ -375,6 +522,27 @@ void MUIDReplacement::CollectImplicitUndefClassInfo(StmtNode &stmt) { } } +void MUIDReplacement::InsertFunctionProfile(MIRFunction ¤tFunc, int64 index) { + // Insert profile code __profile_func_tab[idx] = __profile_func_tab[idx] + 1 + SetCurrentFunction(currentFunc); + AddrofNode *baseExpr = nullptr; + MIRArrayType *arrayType = nullptr; + baseExpr = builder->CreateExprAddrof(0, *funcProfileTabSym, GetMIRModule().GetMemPool()); + arrayType = static_cast(funcProfileTabSym->GetType()); + ConstvalNode *offsetExpr = GetConstvalNode(index); + ConstvalNode *incExpr = GetConstvalNode(1); + ArrayNode *arrayExpr = builder->CreateExprArray(*arrayType, baseExpr, offsetExpr); + arrayExpr->SetBoundsCheck(false); + MIRType *elemType = arrayType->GetElemType(); + BaseNode *ireadPtrExpr = + builder->CreateExprIread(*GlobalTables::GetTypeTable().GetVoidPtr(), + *GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 0, arrayExpr); + BaseNode *addExpr = + builder->CreateExprBinary(OP_add, *GlobalTables::GetTypeTable().GetUInt32(), ireadPtrExpr, incExpr); + MIRType *destPtrType = GlobalTables::GetTypeTable().GetOrCreatePointerType(TyIdx(PTY_u32)); + StmtNode *funcProfileIAssign = builder->CreateStmtIassign(*destPtrType, 0, arrayExpr, addExpr); + currentFunc.GetBody()->InsertFirst(funcProfileIAssign); +} void MUIDReplacement::GenerateFuncDefTable() { // Use funcDefMap to make sure funcDefTab is sorted by an increasing order of MUID @@ -443,6 +611,22 @@ void MUIDReplacement::GenerateFuncDefTable() { *GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcProfInfTabEntryType, arraySize); MIRAggConst *funcProfInfTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), funcProfInfArrayType); + if (Options::profileFunc) { + // create a table each field is 4 byte record the call times + MIRAggConst *funcCallTimesConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), muidIdxArrayType); + for (size_t start = 0; start < arraySize; ++start) { + MIRIntConst *indexConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *GlobalTables::GetTypeTable().GetUInt32(), + 0 /* fieldID */); + funcCallTimesConst->PushBack(indexConst); + } + if (arraySize) { + std::string funcProfileName = namemangler::kFunctionProfileTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); + funcProfileTabSym = builder->CreateGlobalDecl(funcProfileName, muidIdxArrayType); + funcProfileTabSym->SetKonst(funcCallTimesConst); + funcProfileTabSym->SetStorageClass(kScFstatic); + } + } // Create funcDefSet to store functions sorted by address std::vector> funcDefArray; idx = 0; @@ -473,7 +657,13 @@ void MUIDReplacement::GenerateFuncDefTable() { 0 /* fieldID */); muidIdxTabConst->SetConstVecItem(idx, *tempConst); } - if (Options::genIRProfile) { + if (Options::profileFunc) { + InsertFunctionProfile(*mirFunc, idx); + } + if (Options::lazyBinding && !isLibcore) { + ReplaceMethodMetaFuncAddr(*mirFunc->GetFuncSymbol(), idx); + } + if (Options::genIRProfile || Options::profileFunc) { auto funcProfInf = mirFunc->GetProfInf(); MIRAggConst *funcProfInfEntryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *funcProfInfTabEntryType); @@ -497,7 +687,7 @@ void MUIDReplacement::GenerateFuncDefTable() { << ", Offset in muid order: " << iter->second.second << "\n"; } } - if (Options::genIRProfile) { + if (Options::genIRProfile || Options::profileFunc) { MeProfGen::DumpSummary(); } // Create funcDefTab, funcInfoTab and funcMuidTab sorted by address, funcMuidIdxTab sorted by muid @@ -530,6 +720,15 @@ void MUIDReplacement::GenerateFuncDefTable() { funcDefTabSym = builder->CreateGlobalDecl(funcDefTabName, arrayType); funcDefTabSym->SetKonst(funcDefTabConst); funcDefTabSym->SetStorageClass(kScFstatic); + // We add the original def tab for lazy binding, and emit them by CG. + if (Options::lazyBinding) { + std::string funcDefOrigTabName = namemangler::kMuidFuncDefOrigTabPrefixStr + + GetMIRModule().GetFileNameAsPostfix(); + funcDefOrigTabSym = builder->CreateGlobalDecl(funcDefOrigTabName, + arrayType); + funcDefOrigTabSym->SetKonst(funcDefTabConst); + funcDefOrigTabSym->SetStorageClass(kScFstatic); + } } if (!funcInfTabConst->GetConstVec().empty()) { std::string funcInfTabName = namemangler::kMuidFuncInfTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); @@ -589,6 +788,25 @@ void MUIDReplacement::GenerateDataDefTable() { for (auto &keyVal : dataDefMap) { // Fill in the real index keyVal.second.second = idx++; + // Add the def index of cinf for lazy binding. + if (Options::lazyBinding && !isLibcore) { + MIRSymbol *mirSymbol = keyVal.second.first; + if (mirSymbol->IsReflectionClassInfo()) { + MIRConst *mirConst = mirSymbol->GetKonst(); + auto *aggConst = safe_cast(mirConst); + // CLASS::kShadow holds a field of uint32 size, for def index. + // Should we extend it later? + CHECK_NULL_FATAL(aggConst); + MIRConst *elemConst = aggConst->GetConstVecItem(static_cast(ClassProperty::kShadow)); + auto *intConst = safe_cast(elemConst); + // We use 0 as flag of not lazy. + intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( + idx, intConst->GetType(), intConst->GetFieldId()); + aggConst->SetConstVecItem(static_cast(ClassProperty::kShadow), *intConst); + } else { + ReplaceFieldMetaStaticAddr(*mirSymbol, idx - 1); + } + } } FieldVector parentFields; FieldVector fields; @@ -640,6 +858,14 @@ void MUIDReplacement::GenerateDataDefTable() { dataDefTabSym = builder->CreateGlobalDecl(dataDefTabName, arrayType); dataDefTabSym->SetKonst(dataDefTabConst); dataDefTabSym->SetStorageClass(kScFstatic); + // We add the original def tab for lazy binding, and emit them by CG. + if (Options::lazyBinding) { + std::string dataDefOrigTabName = namemangler::kMuidDataDefOrigTabPrefixStr + + GetMIRModule().GetFileNameAsPostfix(); + dataDefOrigTabSym = builder->CreateGlobalDecl(dataDefOrigTabName, arrayType); + dataDefOrigTabSym->SetKonst(dataDefTabConst); + dataDefOrigTabSym->SetStorageClass(kScFstatic); + } } if (!dataDefMuidTabConst->GetConstVec().empty()) { std::string dataDefMuidTabName = namemangler::kMuidDataDefMuidTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); @@ -882,19 +1108,19 @@ void MUIDReplacement::GenerateRangeTable() { } // Please refer to mrt/compiler-rt/include/mpl_linker.h for the layout std::vector workList = { - funcDefTabSym, - funcDefOrigTabSym, - funcInfTabSym, - funcUndefTabSym, - dataDefTabSym, - dataDefOrigTabSym, - dataUndefTabSym, - funcDefMuidTabSym, - funcUndefMuidTabSym, - dataDefMuidTabSym, - dataUndefMuidTabSym, - funcMuidIdxTabSym, - funcProfileTabSym + funcDefTabSym, + funcDefOrigTabSym, + funcInfTabSym, + funcUndefTabSym, + dataDefTabSym, + dataDefOrigTabSym, + dataUndefTabSym, + funcDefMuidTabSym, + funcUndefMuidTabSym, + dataDefMuidTabSym, + dataUndefMuidTabSym, + funcMuidIdxTabSym, + funcProfileTabSym }; InitRangeTabUseSym(workList, rangeTabEntryType, *rangeTabConst); for (int i = RangeIdx::kOldMaxNum + 1; i < RangeIdx::kNewMaxNum; ++i) { @@ -1324,6 +1550,56 @@ void MUIDReplacement::ReplaceDassign(MIRFunction ¤tFunc, const DassignNode currentFunc.GetBody()->ReplaceStmt1WithStmt2(&dassignNode, iassignNode); } +void MUIDReplacement::CollectFieldCallSite() { + for (MIRFunction *mirFunc : GetMIRModule().GetFunctionList()) { + if (mirFunc->GetBody() == nullptr) { + continue; + } + SetCurrentFunction(*mirFunc); + StmtNode *stmt = mirFunc->GetBody()->GetFirst(); + StmtNode *next = nullptr; + while (stmt != nullptr) { + next = stmt->GetNext(); + CollectDreadStmt(mirFunc, mirFunc->GetBody(), stmt); + stmt = next; + } + } +} + +void MUIDReplacement::CollectDreadStmt(MIRFunction *currentFunc, BlockNode *block, StmtNode *stmt) { + if (currentFunc == nullptr || stmt == nullptr) { + return; + } + switch (stmt->GetOpCode()) { + case OP_if: { + auto *iNode = static_cast(stmt); + ASSERT(block != nullptr, "null ptr check!"); + iNode->SetOpnd(CollectDreadExpr(currentFunc, *block, stmt, iNode->Opnd(0)), 0); + CollectDreadStmt(currentFunc, nullptr, iNode->GetThenPart()); + CollectDreadStmt(currentFunc, nullptr, iNode->GetElsePart()); + break; + } + case OP_while: { + auto *wNode = static_cast(stmt); + ASSERT(block != nullptr, "null ptr check!"); + wNode->SetOpnd(CollectDreadExpr(currentFunc, *block, stmt, wNode->Opnd(0)), 0); + CollectDreadStmt(currentFunc, nullptr, wNode->GetBody()); + break; + } + case OP_block: { + auto *bNode = static_cast(stmt); + for (auto &stmtNode : bNode->GetStmtNodes()) { + CollectDreadStmt(currentFunc, bNode, &stmtNode); + } + break; + } + default: + ASSERT(block != nullptr, "null ptr check!"); + for (size_t i = 0; i < stmt->NumOpnds(); ++i) { + stmt->SetOpnd(CollectDreadExpr(currentFunc, *block, stmt, stmt->Opnd(i)), i); + } + } +} void MUIDReplacement::ReplaceDreadStmt(MIRFunction *currentFunc, StmtNode *stmt) { if (currentFunc == nullptr || stmt == nullptr) { @@ -1359,6 +1635,36 @@ void MUIDReplacement::ReplaceDreadStmt(MIRFunction *currentFunc, StmtNode *stmt) } } +BaseNode *MUIDReplacement::CollectDreadExpr(MIRFunction *currentFunc, BlockNode &block, StmtNode *stmt, + BaseNode *expr) { + if (currentFunc == nullptr || stmt == nullptr || expr == nullptr) { + return nullptr; + } + if (expr->GetOpCode() == OP_intrinsicop) { + auto *intrinsicsNode = static_cast(expr); + if (intrinsicsNode->GetIntrinsic() == INTRN_MPL_READ_OVTABLE_ENTRY || + intrinsicsNode->GetIntrinsic() == INTRN_MPL_READ_OVTABLE_ENTRY2) { + std::string valueSymName = namemangler::kOffsetTabStr + GetMIRModule().GetFileNameAsPostfix(); + MIRSymbol *offsetTableSym = GetSymbolFromName(valueSymName); + ASSERT(offsetTableSym != nullptr, "null ptr check"); + auto *arrayType = static_cast(offsetTableSym->GetType()); + MIRType *elemType = arrayType->GetElemType(); + IreadNode *iread = builder->CreateExprIread(*GlobalTables::GetTypeTable().GetUInt32(), + *GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 1, + intrinsicsNode->GetNopndAt(0)); + if (intrinsicsNode->GetIntrinsic() == INTRN_MPL_READ_OVTABLE_ENTRY || + intrinsicsNode->GetIntrinsic() == INTRN_MPL_READ_OVTABLE_ENTRY2) { + return iread; + } else { + ASSERT(false, "Wrong lazy binding option"); + } + } + } + for (size_t i = 0; i < expr->NumOpnds(); ++i) { + expr->SetOpnd(CollectDreadExpr(currentFunc, block, stmt, expr->Opnd(i)), i); + } + return expr; +} // Turn dread into iread BaseNode *MUIDReplacement::ReplaceDreadExpr(MIRFunction *currentFunc, StmtNode *stmt, BaseNode *expr) { @@ -1530,6 +1836,35 @@ void MUIDReplacement::GenerateCompilerVersionNum() { versionNum->SetKonst(newConst); } +void MUIDReplacement::GenericSourceMuid() { + if (Options::sourceMuid != "") { + MIRArrayType &arrayType = + *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt8(), 0); + MIRAggConst *newConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); + for (const char &c : Options::sourceMuid) { + MIRConst *charConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( + c, *GlobalTables::GetTypeTable().GetUInt8(), 0 /* fieldID */); + newConst->GetConstVec().push_back(charConst); + } + + MIRType &type = *GlobalTables::GetTypeTable().GetInt64(); + MIRConst *slotConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); + newConst->GetConstVec().push_back(slotConst); + newConst->GetConstVec().push_back(slotConst); + std::string symName = namemangler::kSourceMuid + GetMIRModule().GetFileNameAsPostfix(); + MIRSymbol *sourceMuid = builder->CreateGlobalDecl(symName, arrayType); + sourceMuid->SetKonst(newConst); + } +} + +void MUIDReplacement::GenCompilerMfileStatus() { + MIRType &type = *GlobalTables::GetTypeTable().GetInt32(); + MIRConst *intConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(Options::gcOnly ? 1 : 0, type, 0 /* fieldID */); + std::string symName = namemangler::kCompilerMfileStatus + GetMIRModule().GetFileNameAsPostfix(); + MIRSymbol *mfileStatus = builder->CreateGlobalDecl(symName.c_str(), type); + mfileStatus->SetKonst(intConst); +} void MUIDReplacement::GenerateSourceInfo() { for (Klass *klass : klassHierarchy->GetTopoSortedKlasses()) { @@ -1586,9 +1921,13 @@ void MUIDReplacement::ReleasePragmaMemPool() { void MUIDReplacement::GenerateTables() { GenerateGlobalRootList(); - CollectFuncAndDataFromKlasses(); - CollectFuncAndDataFromGlobalTab(); - CollectFuncAndDataFromFuncList(); + if (Options::partialAot) { + GenerateSourceInfo(); + } + if (Options::buildApp) { + CollectFieldCallSite(); + } + CollectFuncAndData(); ReleasePragmaMemPool(); CollectSuperClassArraySymbolData(); CollectArrayClass(); @@ -1610,11 +1949,51 @@ void MUIDReplacement::GenerateTables() { // Replace undef entries in vtab/itab/reflectionMetaData for (Klass *klass : klassHierarchy->GetTopoSortedKlasses()) { ReplaceFieldTypeTable(namemangler::kFieldsInfoPrefixStr + klass->GetKlassName()); - ReplaceFuncTable(VTAB_PREFIX_STR + klass->GetKlassName()); - ReplaceFuncTable(ITAB_PREFIX_STR + klass->GetKlassName()); - ReplaceFuncTable(ITAB_CONFLICT_PREFIX_STR + klass->GetKlassName()); + if (Options::buildApp && !Options::genVtabAndItabForDecouple && klass->GetNeedDecoupling()) { + ClearVtabItab(VTAB_PREFIX_STR + klass->GetKlassName()); + ClearVtabItab(ITAB_PREFIX_STR + klass->GetKlassName()); + ClearVtabItab(ITAB_CONFLICT_PREFIX_STR + klass->GetKlassName()); + } else { + ReplaceFuncTable(VTAB_PREFIX_STR + klass->GetKlassName()); + ReplaceFuncTable(ITAB_PREFIX_STR + klass->GetKlassName()); + ReplaceFuncTable(ITAB_CONFLICT_PREFIX_STR + klass->GetKlassName()); + } } ReplaceDataTable(namemangler::kGcRootList); + if (Options::buildApp) { + // ReplaceVtableOffsetTable + ReplaceDataTable(namemangler::kVtabOffsetTabStr + GetMIRModule().GetFileNameAsPostfix()); + // ReplaceFieldOffsetTable + ReplaceDataTable(namemangler::kFieldOffsetTabStr + GetMIRModule().GetFileNameAsPostfix()); + } + if (Options::decoupleStatic) { + MIRSymbol *tabSym = GetSymbolFromName(namemangler::kDecoupleStaticKeyStr + GetMIRModule().GetFileNameAsPostfix()); + if (tabSym == nullptr) { + return; + } + ReplaceDecoupleKeyTable(static_cast(tabSym->GetKonst())); + } + // Set the flag for decouple + { + MIRType &type = *GlobalTables::GetTypeTable().GetVoidPtr(); + uint64 value = 0; + if (Options::buildApp) { + value = Options::buildApp; + if (Options::lazyBinding) { + value = kDecoupleAndLazy; + } + } + if (Options::decoupleStatic) { + value |= 0x4; + } + MIRConst *newConst = + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(value), type, 0 /* fieldID */); + std::string decoupleOption = namemangler::kDecoupleOption + GetMIRModule().GetFileNameAsPostfix(); + MIRSymbol *decoupleSt = builder->CreateGlobalDecl(decoupleOption, type); + decoupleSt->SetKonst(newConst); + } + GenericSourceMuid(); + GenCompilerMfileStatus(); GenerateCompilerVersionNum(); } } // namespace maple diff --git a/tools/setup_tools.sh b/tools/setup_tools.sh index d4923743fcc0b78fc7464b924faed740fbb895be..3d2a9eef7b3ba06d540da86baa6925c086cf8fa8 100755 --- a/tools/setup_tools.sh +++ b/tools/setup_tools.sh @@ -158,11 +158,11 @@ if [ ! -f $TOOLS/open64_prebuilt/x86/riscv64/bin/clangfe ]; then echo Downloaded open64_prebuilt. fi -if [ ! -f $MAPLE_ROOT/third_party/dwarf/include/Dwarf.h ]; then +if [ ! -f $MAPLE_ROOT/third_party/dwarf_h/include/Dwarf.h ]; then cd $TOOLS - rm -rf dwarf $MAPLE_ROOT/third_party/dwarf - git clone https://gitee.com/hu-_-wen/dwarf_h.git dwarf - mv dwarf $MAPLE_ROOT/third_party/ + rm -rf dwarf $MAPLE_ROOT/third_party/dwarf* + git clone https://gitee.com/hu-_-wen/dwarf_h.git + mv dwarf_h $MAPLE_ROOT/third_party/ echo Downloaded dwarf header files. fi @@ -180,4 +180,4 @@ else ln -s -f /usr/bin/llvm-ranlib ${TOOL_BIN_PATH}/llvm-ranlib ln -s -f ${MAPLE_ROOT}/tools/qemu/package/usr/bin/qemu-aarch64 ${TOOL_BIN_PATH}/qemu-aarch64 fi -ln -s -f ${MAPLE_ROOT}/tools/open64_prebuilt/x86/aarch64/bin/clangfe ${TOOL_BIN_PATH}/clangfe \ No newline at end of file +ln -s -f ${MAPLE_ROOT}/tools/open64_prebuilt/x86/aarch64/bin/clangfe ${TOOL_BIN_PATH}/clangfe