diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index d0ed6542d6aa96a21982f5d93a16de0340e04a5c..750a4eb19b957d2eb4b59d6e966ec5d0f40e3e41 100755 Binary files a/src/mapleall/bin/dex2mpl and b/src/mapleall/bin/dex2mpl differ diff --git a/src/mapleall/bin/jbc2mpl b/src/mapleall/bin/jbc2mpl index 901cc4b03afab609cedf4457ce37ec7187295200..d5ec6ed4ca3076a7d4f69a848d9fbaa33bbf2702 100755 Binary files a/src/mapleall/bin/jbc2mpl and b/src/mapleall/bin/jbc2mpl differ diff --git a/src/mapleall/maple_be/BUILD.gn b/src/mapleall/maple_be/BUILD.gn index ff226e4b6a4f58d64534be93a1f3f00c4a1308ba..01d287f2a63c09401c30aceea06edde8e2b604bb 100644 --- a/src/mapleall/maple_be/BUILD.gn +++ b/src/mapleall/maple_be/BUILD.gn @@ -26,7 +26,8 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_phase/include", "${THIRD_PARTY_ROOT}/bounds_checking_function/include", - "${THIRD_PARTY_ROOT}/llvm_modified/include/llvm/BinaryFormat" + "${THIRD_PARTY_ROOT}/dwarf_h/include", + "${THIRD_PARTY_ROOT}/bounds_checking_function/include" ] deps_libcg = [] diff --git a/src/mapleall/maple_be/include/be/common_utils.h b/src/mapleall/maple_be/include/be/common_utils.h index 63c2db9053208aa4472c6bb89739c52885b3a7a8..2307a9f01631864a38c77aec4a759e94392288a0 100644 --- a/src/mapleall/maple_be/include/be/common_utils.h +++ b/src/mapleall/maple_be/include/be/common_utils.h @@ -53,6 +53,7 @@ constexpr uint32 k2ByteSize = 2; constexpr uint32 k3ByteSize = 3; constexpr uint32 k4ByteSize = 4; constexpr uint32 k8ByteSize = 8; +constexpr uint32 k9ByteSize = 9; constexpr uint32 k12ByteSize = 12; constexpr uint32 k14ByteSize = 14; constexpr uint32 k15ByteSize = 15; diff --git a/src/mapleall/maple_be/include/cg/cg.h b/src/mapleall/maple_be/include/cg/cg.h index 30b4e18fedfc30488b3de489b9920a6dd87cc318..d2e4c1f57c20e5a413c589193a82500ce48b7c48 100644 --- a/src/mapleall/maple_be/include/cg/cg.h +++ b/src/mapleall/maple_be/include/cg/cg.h @@ -347,19 +347,16 @@ class CG { std::vector GetReferenceOffsets64(const BECommon &beCommon, MIRStructType &structType); static bool IsInFuncWrapLabels(MIRFunction *func) { - if (funcWrapLabels.find(func) != funcWrapLabels.end()) { - return true; - } - return false; + return funcWrapLabels.find(func) != funcWrapLabels.end(); } - static void SetFuncWrapLabels(MIRFunction *func, std::pair labels) { + static void SetFuncWrapLabels(MIRFunction *func, const std::pair labels) { if (!IsInFuncWrapLabels(func)) { funcWrapLabels[func] = labels; } } - static std::map> &GetFuncWrapLabels() { + static std::map> &GetFuncWrapLabels() { return funcWrapLabels; } @@ -378,7 +375,7 @@ class CG { MIRSymbol *dbgTraceEnter; MIRSymbol *dbgTraceExit; MIRSymbol *dbgFuncProfile; - static std::map> funcWrapLabels; + static std::map> funcWrapLabels; }; /* class CG */ } /* namespace maplebe */ diff --git a/src/mapleall/maple_be/include/cg/cgfunc.h b/src/mapleall/maple_be/include/cg/cgfunc.h index fbb37c4a6692262a7abc8672027e7fb83c7bfb98..c1ed514124284df6891a53842e29cd923d984a57 100644 --- a/src/mapleall/maple_be/include/cg/cgfunc.h +++ b/src/mapleall/maple_be/include/cg/cgfunc.h @@ -406,7 +406,7 @@ class CGFunc { void AddDIESymbolLocation(const MIRSymbol *sym, SymbolAlloc *loc); - virtual void DBGFixCallFrameLocationOffsets(){}; + virtual void DBGFixCallFrameLocationOffsets() {}; /* Get And Set private members */ CG *GetCG() { @@ -839,7 +839,7 @@ class CGFunc { return (mirModule.GetSrcLang() != kSrcLangC); } - MapleVector &GetDbgCallFrameLocations() { + MapleVector &GetDbgCallFrameLocations() { return dbgCallFrameLocations; } @@ -871,7 +871,7 @@ class CGFunc { bool hasTakenLabel = false; uint32 frequency = 0; DebugInfo *debugInfo = nullptr; /* debugging info */ - MapleVector dbgCallFrameLocations; + MapleVector dbgCallFrameLocations; RegOperand *aggParamReg = nullptr; ReachingDefinition *reachingDef = nullptr; diff --git a/src/mapleall/maple_be/include/cg/emit.h b/src/mapleall/maple_be/include/cg/emit.h index aa046d85aec2054b9624a0777152cfd36cb9b450..198644e9d9c92eb67a74596c6430faa278dba66c 100644 --- a/src/mapleall/maple_be/include/cg/emit.h +++ b/src/mapleall/maple_be/include/cg/emit.h @@ -51,14 +51,14 @@ const char *GetDwAtName(unsigned n); #define DEBUG_ABBREV_0 debug_abbrev0 #define DEBUG_LINE_0 debug_line0 #define DEBUG_STR_LABEL ASF -#define DEBUG_MAPLE_THIS "_this" -#define DWARF_VERSION 4 -#define SIZEOFPTR 8 namespace maplebe { constexpr int32 kSizeOfDecoupleStaticStruct = 4; constexpr uint32 kHugeSoInsnCountThreshold = 0x1f00000; /* 124M (4bytes per Insn), leave 4M rooms for 128M */ constexpr char kHugeSoPostFix[] = "$$hugeso_"; +constexpr char kDebugMapleThis[] = "_this"; +constexpr uint32 kDwarfVersion = 4; +constexpr uint32 kSizeOfPTR = 8; class StructEmitInfo { public: /* default ctor */ @@ -236,7 +236,7 @@ class Emitter { void EmitLabelRef(LabelIdx labIdx); void EmitStmtLabel(LabelIdx labIdx); void EmitLabelPair(const LabelPair &pairLabel); - void EmitLabelForFunc(MIRFunction *func, LabelIdx labIdx); + void EmitLabelForFunc(const MIRFunction *func, LabelIdx labIdx); /* Emit signed/unsigned integer literals in decimal or hexadecimal */ void EmitDecSigned(int64 num); @@ -244,23 +244,23 @@ class Emitter { void EmitHexUnsigned(uint64 num); /* Dwarf debug info */ - void FillInClassByteSize(DBGDie *die, DBGDieAttr *byteSizeAttr, DBGAbbrevEntry *diae); - void SetupDBGInfo(DebugInfo *); - void ApplyInPrefixOrder(DBGDie *die, const std::function &func); - void AddLabelDieToLabelIdxMapping(DBGDie *, LabelIdx); - LabelIdx GetLabelIdxForLabelDie(DBGDie *); + void FillInClassByteSize(DBGDie *die, DBGDieAttr *byteSizeAttr); + void SetupDBGInfo(DebugInfo*); + void ApplyInPrefixOrder(DBGDie *die, const std::function &func); + void AddLabelDieToLabelIdxMapping(DBGDie*, LabelIdx); + LabelIdx GetLabelIdxForLabelDie(DBGDie*); void EmitDIHeader(); void EmitDIFooter(); void EmitDIHeaderFileInfo(); - void EmitDIDebugInfoSection(DebugInfo *); - void EmitDIDebugAbbrevSection(DebugInfo *); + void EmitDIDebugInfoSection(DebugInfo*); + void EmitDIDebugAbbrevSection(DebugInfo*); void EmitDIDebugARangesSection(); void EmitDIDebugRangesSection(); void EmitDIDebugLineSection(); void EmitDIDebugStrSection(); void EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTag tagName, DebugInfo *di); void EmitDIFormSpecification(unsigned int dwform); - void EmitDIFormSpecification(DBGDieAttr *attr) { + void EmitDIFormSpecification(const DBGDieAttr *attr) { EmitDIFormSpecification(attr->GetDwForm()); } @@ -280,7 +280,7 @@ class Emitter { return fileMap; } - void SetFileMapValue(uint32_t n, std::string &file) { + void SetFileMapValue(uint32_t n, const std::string &file) { fileMap[n] = file; } @@ -332,7 +332,7 @@ class Emitter { arraySize(0), isFlexibleArray(false), hugeSoTargets(cg.GetMIRModule()->GetMPAllocator().Adapter()), - labdie2labidxTable(std::less(), cg.GetMIRModule()->GetMPAllocator().Adapter()), + labdie2labidxTable(std::less(), cg.GetMIRModule()->GetMPAllocator().Adapter()), fileMap(std::less(), cg.GetMIRModule()->GetMPAllocator().Adapter()) { outStream.open(fileName, std::ios::trunc); MIRModule &mirModule = *cg.GetMIRModule(); @@ -365,7 +365,7 @@ class Emitter { MapleSet hugeSoTargets; uint32 hugeSoSeqence = 2; #endif - MapleMap labdie2labidxTable; + MapleMap labdie2labidxTable; MapleMap fileMap; }; } /* namespace maplebe */ 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 7e9a1e5f5a4b8f24079004bdbf2374b395ed6b9b..79750b7bbc3228796fd562b45f2983c7f2810929 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -107,7 +107,7 @@ MOperator PickLdStInsn(bool isLoad, uint32 bitSize, PrimType primType, AArch64is } /* __builtin_ffs(x) returns: 0 -> 0, 1 -> 1, 2 -> 2, 4 -> 3, 8 -> 4 */ - if (IsPrimitiveInteger(primType)) { + if (IsPrimitiveInteger(primType) || primType == PTY_agg) { MOperator(*table)[kIntByteSizeDimension]; if (isLoad) { table = (memOrd == AArch64isa::kMoAcquire) ? ldIsAcq : ldIs; @@ -116,6 +116,12 @@ MOperator PickLdStInsn(bool isLoad, uint32 bitSize, PrimType primType, AArch64is } int32 signedUnsigned = IsUnsignedInteger(primType) ? 0 : 1; + if (primType == PTY_agg) { + CHECK_FATAL(bitSize >= k8BitSize, " unexpect agg size"); + bitSize = RoundUp(bitSize, k8BitSize); + ASSERT((bitSize & (bitSize - 1)) == 0, "bitlen error"); + } + /* __builtin_ffs(x) returns: 8 -> 4, 16 -> 5, 32 -> 6, 64 -> 7 */ uint32 size = static_cast(__builtin_ffs(static_cast(bitSize))) - 4; ASSERT(size <= 3, "wrong bitSize"); @@ -734,7 +740,12 @@ RegOperand &AArch64CGFunc::SelectCopy(Operand &src, PrimType stype, PrimType dty bool AArch64CGFunc::IsImmediateOffsetOutOfRange(AArch64MemOperand &memOpnd, uint32 bitLen) { ASSERT(bitLen >= k8BitSize, "bitlen error"); ASSERT(bitLen <= k64BitSize, "bitlen error"); + + if (bitLen >= k8BitSize) { + bitLen = RoundUp(bitLen, k8BitSize); + } ASSERT((bitLen & (bitLen - 1)) == 0, "bitlen error"); + AArch64MemOperand::AArch64AddressingMode mode = memOpnd.GetAddrMode(); if ((mode == AArch64MemOperand::kAddrModeBOi) && memOpnd.IsIntactIndexed()) { int32 offsetValue = memOpnd.GetOffsetImmediate()->GetOffsetValue(); @@ -965,7 +976,7 @@ void AArch64CGFunc::SelectDassign(StIdx stIdx, FieldID fieldId, PrimType rhsPTyp } /* In bpl mode, a func symbol's type is represented as a MIRFuncType instead of a MIRPtrType (pointing to - MIRFuncType), so we allow `kTypeFunction` to appear here */ + * MIRFuncType), so we allow `kTypeFunction` to appear here */ ASSERT(((type->GetKind() == kTypeScalar) || (type->GetKind() == kTypePointer) || (type->GetKind() == kTypeFunction) || (type->GetKind() == kTypeStruct) || (type->GetKind() == kTypeArray)), "NYI dassign type"); PrimType ptyp = type->GetPrimType(); @@ -1642,7 +1653,6 @@ Operand *AArch64CGFunc::SelectDread(const BaseNode &parent, DreadNode &expr) { } MemOperand *memOpnd = nullptr; if (aggSize > k8ByteSize) { - CHECK_FATAL(false, "SelectDread: aggregate of wrong size check IR"); if (parent.op == OP_eval) { if (symbol->GetAttr(ATTR_volatile)) { /* Need to generate loads for the upper parts of the struct. */ @@ -1968,7 +1978,8 @@ Operand *AArch64CGFunc::SelectIread(const BaseNode &parent, IreadNode &expr) { destType = PTY_u64; break; default: - CHECK_FATAL(false, "SelectIRead: aggregate of wrong size check IR"); + destType = PTY_u64; // when eval agg . a way to round up + break; } } } @@ -6833,7 +6844,7 @@ void AArch64CGFunc::AppendCall(const MIRSymbol &funcSymbol) { void AArch64CGFunc::DBGFixCallFrameLocationOffsets() { for (DBGExprLoc *el : GetDbgCallFrameLocations()) { if (el->GetSimpLoc()->GetDwOp() == DW_OP_fbreg) { - SymbolAlloc *symloc = static_cast(el->GetSymLoc()); + SymbolAlloc *symloc = static_cast(el->GetSymLoc()); int64_t offset = GetBaseOffset(*symloc) - GetDbgCallFrameOffset(); el->SetFboffset(offset); } @@ -7714,7 +7725,7 @@ void AArch64CGFunc::InsertJumpPad(Insn *insn) { BB *targetBB; BB *fallthruBB = bb->GetNext(); - ASSERT(bb->NumSuccs() == 2, "if bb should have 2 successors"); + ASSERT(bb->NumSuccs() == k2ByteSize, "if bb should have 2 successors"); if (bb->GetSuccs().front() == fallthruBB) { targetBB = bb->GetSuccs().back(); } else { diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp index ff0624d2719712d4fd59c14d27dcb76a5eded7ed..f77bbea17b547e0d9f7e2c5e4d0000e829ced10f 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp @@ -179,15 +179,13 @@ void StImmOperand::Emit(Emitter &emitter, const OpndProp *opndProp) const { } if (CGOptions::IsPIC() && (symbol->GetStorageClass() == kScGlobal || symbol->GetStorageClass() == kScExtern)) { emitter.Emit(":got:" + GetName()); + } else if (symbol->GetStorageClass() == kScPstatic && symbol->GetSKind() != kStConst && symbol->IsLocal()) { + emitter.Emit(symbol->GetName() + std::to_string(emitter.GetCG()->GetMIRModule()->CurFunction()->GetPuidx())); } else { - if (symbol->GetStorageClass() == kScPstatic && symbol->GetSKind() != kStConst && symbol->IsLocal()) { - emitter.Emit(symbol->GetName() + std::to_string(emitter.GetCG()->GetMIRModule()->CurFunction()->GetPuidx())); - } else { - emitter.Emit(GetName()); - } - if (offset != 0) { - emitter.Emit("+" + std::to_string(offset)); - } + emitter.Emit(GetName()); + } + if (offset != 0) { + emitter.Emit("+" + std::to_string(offset)); } } @@ -255,7 +253,11 @@ void AArch64MemOperand::Emit(Emitter &emitter, const OpndProp *opndProp) const { emitter.Emit(",#:got_lo12:"); emitter.Emit(offset->GetSymbolName()); } else { - ASSERT(!IsPIMMOffsetOutOfRange(offset->GetOffsetValue(), size), "should not be PIMMOffsetOutOfRange"); + uint32 dsize = size; + if (size > k8BitSize) { + dsize = RoundUp(size, k8BitSize); + } + ASSERT(!IsPIMMOffsetOutOfRange(offset->GetOffsetValue(), dsize), "should not be PIMMOffsetOutOfRange"); if (!offset->IsZero()) { emitter.Emit(","); offset->Emit(emitter, nullptr); diff --git a/src/mapleall/maple_be/src/cg/cg.cpp b/src/mapleall/maple_be/src/cg/cg.cpp index aa5a1f2aa1251b52ed79d4d501b967e500701a9e..18e446783779f8200c631fc528f80adf895ed194 100644 --- a/src/mapleall/maple_be/src/cg/cg.cpp +++ b/src/mapleall/maple_be/src/cg/cg.cpp @@ -21,7 +21,7 @@ using namespace maple; #define JAVALANG (mirModule->IsJavaModule()) CGFunc *CG::currentCGFunction = nullptr; -std::map> CG::funcWrapLabels; +std::map> CG::funcWrapLabels; CG::~CG() { if (emitter != nullptr) { diff --git a/src/mapleall/maple_be/src/cg/cg_option.cpp b/src/mapleall/maple_be/src/cg/cg_option.cpp index b57151a5a31f9581b5d088e227e03731d502895c..029f91c39e285497bc6e768fa34a9047056b50c2 100644 --- a/src/mapleall/maple_be/src/cg/cg_option.cpp +++ b/src/mapleall/maple_be/src/cg/cg_option.cpp @@ -1440,7 +1440,21 @@ void CGOptions::SetDefaultOptions(const maple::MIRModule &mod) { void CGOptions::EnableO0() { optimizeLevel = kLevel0; + doEBO = false; + doCFGO = false; + doICO = false; + doPrePeephole = false; + doPeephole = false; + doStoreLoadOpt = false; + doGlobalOpt = false; + doPreLSRAOpt = false; + doLocalRefSpill = false; + doCalleeToSpill = false; + doSchedule = false; + doWriteRefFieldOpt = false; SetOption(kUseStackGuard); + ClearOption(kConstFold); + ClearOption(kProEpilogueOpt); } void CGOptions::EnableO1() { @@ -1454,7 +1468,6 @@ void CGOptions::EnableO1() { void CGOptions::EnableO2() { optimizeLevel = kLevel2; -#if TARGARM32 doEBO = true; doCFGO = true; doICO = true; @@ -1462,32 +1475,23 @@ void CGOptions::EnableO2() { doPeephole = true; doStoreLoadOpt = true; doGlobalOpt = true; + doPreSchedule = false; + doSchedule = true; + SetOption(kConstFold); + ClearOption(kUseStackGuard); +#if TARGARM32 doPreLSRAOpt = false; doLocalRefSpill = false; doCalleeToSpill = false; - doPreSchedule = false; - doSchedule = true; doWriteRefFieldOpt = false; - SetOption(kConstFold); ClearOption(kProEpilogueOpt); #else - doEBO = true; - doCFGO = true; - doICO = true; - doPrePeephole = true; - doPeephole = true; - doStoreLoadOpt = true; - doGlobalOpt = true; doPreLSRAOpt = true; doLocalRefSpill = true; doCalleeToSpill = true; - doPreSchedule = false; - doSchedule = true; doWriteRefFieldOpt = true; - SetOption(kConstFold); SetOption(kProEpilogueOpt); #endif - ClearOption(kUseStackGuard); } void CGOptions::SplitPhases(const std::string &str, std::unordered_set &set) { diff --git a/src/mapleall/maple_be/src/cg/cgfunc.cpp b/src/mapleall/maple_be/src/cg/cgfunc.cpp index c938e01b39596f87062f2213d9f03e47ac15036c..33225735844b50855e0ece790e2bddf80ffe8944 100644 --- a/src/mapleall/maple_be/src/cg/cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/cgfunc.cpp @@ -1213,12 +1213,11 @@ void CGFunc::HandleFunction() { } void CGFunc::AddDIESymbolLocation(const MIRSymbol *sym, SymbolAlloc *loc) { - ASSERT(debugInfo, ""); + ASSERT(debugInfo != nullptr, "debugInfo is null!"); DBGDie *sdie = debugInfo->GetLocalDie(&func, sym->GetNameStrIdx()); - if (!sdie) { + if (sdie == nullptr) { return; } - ASSERT(sdie, ""); DBGExprLoc *exprloc = sdie->GetExprLoc(); CHECK_FATAL(exprloc != nullptr, "exprloc is null in CGFunc::AddDIESymbolLocation"); @@ -1318,11 +1317,11 @@ void CGFunc::ClearLoopInfo() { } void CGFunc::PatchLongBranch() { - for (BB *bb = firstBB->GetNext(); bb; bb = bb->GetNext()) { + for (BB *bb = firstBB->GetNext(); bb != nullptr; bb = bb->GetNext()) { bb->SetInternalFlag1(bb->GetInternalFlag1() + bb->GetPrev()->GetInternalFlag1()); } - BB *next; - for (BB *bb = firstBB; bb; bb = next) { + BB *next = nullptr; + for (BB *bb = firstBB; bb != nullptr; bb = next) { next = bb->GetNext(); if (bb->GetKind() != BB::kBBIf && bb->GetKind() != BB::kBBGoto) { continue; @@ -1332,7 +1331,7 @@ void CGFunc::PatchLongBranch() { insn = insn->GetPrev(); } LabelIdx labidx = static_cast(insn->GetOperand(insn->GetJumpTargetIdx())).GetLabelIndex(); - BB *tbb = GetBBFromLab2BBMap(labidx); + BB *tbb = GetBBFromLab2BBMap(static_cast(labidx)); if ((tbb->GetInternalFlag1() - bb->GetInternalFlag1()) < MaxCondBranchDistance()) { continue; } @@ -1351,6 +1350,7 @@ AnalysisResult *CgDoHandleFunc::Run(CGFunc *cgFunc, CgFuncResultMgr *cgFuncResul } AnalysisResult *CgFixCFLocOsft::Run(CGFunc *cgFunc, CgFuncResultMgr *m) { + (void)m; if (cgFunc->GetCG()->GetCGOptions().WithDwarf()) { cgFunc->DBGFixCallFrameLocationOffsets(); } diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index 9e5973082e455dbb5e54046740f415e1a4438c72..8a8f513932543f65e478d091d536197bbddc5c4b 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -56,8 +56,7 @@ int32 GetPrimitiveTypeSize(const std::string &name) { return -1; } } - -DBGDieAttr *LFindAttribute(MapleVector &vec, DwAt key) { +DBGDieAttr *LFindAttribute(MapleVector &vec, DwAt key) { for (DBGDieAttr *at : vec) if (at->GetDwAt() == key) { return at; @@ -65,7 +64,7 @@ DBGDieAttr *LFindAttribute(MapleVector &vec, DwAt key) { return nullptr; } -DBGAbbrevEntry *LFindAbbrevEntry(MapleVector &abbvec, unsigned int key) { +DBGAbbrevEntry *LFindAbbrevEntry(MapleVector &abbvec, unsigned int key) { for (DBGAbbrevEntry *daie : abbvec) { if (!daie) { continue; @@ -79,14 +78,10 @@ DBGAbbrevEntry *LFindAbbrevEntry(MapleVector &abbvec, unsigned } bool LShouldEmit(unsigned int dwform) { - switch (dwform) { - case DW_FORM_flag_present: - return false; - } - return true; + return dwform != DW_FORM_flag_present; } -DBGDie *LFindChildDieWithName(DBGDie *die, DwTag tag, GStrIdx key) { +DBGDie *LFindChildDieWithName(DBGDie *die, DwTag tag, const GStrIdx key) { for (DBGDie *c : die->GetSubDieVec()) { if (c->GetTag() == tag) { for (DBGDieAttr *a : c->GetAttrVec()) { @@ -112,9 +107,8 @@ DBGDieAttr *LFindDieAttr(DBGDie *die, DwAt attrname) { return nullptr; } -static void LUpdateAttrValue(DBGDieAttr *attr, int64_t newval, DBGAbbrevEntry *diae) { +static void LUpdateAttrValue(DBGDieAttr *attr, int64_t newval) { attr->SetI(int32_t(newval)); - return; } } @@ -141,8 +135,8 @@ void Emitter::EmitLabelPair(const LabelPair &pairLabel) { outStream << "\n"; } -void Emitter::EmitLabelForFunc(MIRFunction *func, LabelIdx labidx) { - const char *idx = static_cast(strdup(std::to_string(func->GetPuidx()).c_str())); +void Emitter::EmitLabelForFunc(const MIRFunction *func, LabelIdx labidx) { + const std::string idx = static_cast(strdup(std::to_string(func->GetPuidx()).c_str())); outStream << ".L." << idx << "__" << labidx; } @@ -2747,11 +2741,7 @@ void Emitter::EmitDIHeader() { } void Emitter::EmitDIFooter() { - if (cg->GetMIRModule()->GetSrcLang() == kSrcLangC) { - (void)Emit("\t.section ." + std::string("c_text") + ",\"ax\"\n"); - } else { - (void)Emit("\t.section ." + std::string(namemangler::kMuidJavatextPrefixStr) + ",\"ax\"\n"); - } + (void)Emit("\t.section ." + std::string(namemangler::kMuidJavatextPrefixStr) + ",\"ax\"\n"); Emit(".L" XSTR(TEXT_END) ":\n"); } @@ -2772,7 +2762,7 @@ LabelIdx Emitter::GetLabelIdxForLabelDie(DBGDie *lbldie) { } -void Emitter::ApplyInPrefixOrder(DBGDie *die, const std::function &func) { +void Emitter::ApplyInPrefixOrder(DBGDie *die, const std::function &func) { func(die); ASSERT(die, ""); if (die->GetSubDieVec().size() > 0) { @@ -2815,14 +2805,14 @@ void Emitter::EmitDIFormSpecification(unsigned int dwform) { break; default: CHECK_FATAL(maple::GetDwFormName(dwform) != nullptr, - "GetDwFormName() return null in Emitter::EmitDIFormSpecification"); + "GetDwFormName() return null in Emitter::EmitDIFormSpecification"); LogInfo::MapleLogger() << "unhandled : " << maple::GetDwFormName(dwform) << std::endl; ASSERT(0, "NYI"); } } void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTag tagName, DebugInfo *di) { - MapleVector &attrvec = die->GetAttrVec(); + MapleVector &attrvec = die->GetAttrVec(); switch (attr->GetDwForm()) { case DW_FORM_string: { @@ -2841,7 +2831,7 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa EmitHexUnsigned(attr->GetI()); } else #endif - EmitHexUnsigned(uint8_t(attr->GetI())); + EmitHexUnsigned(uint8_t(attr->GetI())); break; case DW_FORM_data2: #if DEBUG @@ -2849,7 +2839,7 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa EmitHexUnsigned(attr->GetI()); } else #endif - EmitHexUnsigned(uint16_t(attr->GetI())); + EmitHexUnsigned(uint16_t(attr->GetI())); break; case DW_FORM_data4: #if DEBUG @@ -2857,7 +2847,7 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa EmitHexUnsigned(attr->GetI()); } else #endif - EmitHexUnsigned(uint32_t(attr->GetI())); + EmitHexUnsigned(uint32_t(attr->GetI())); break; case DW_FORM_data8: if (attrName == DW_AT_high_pc) { @@ -2876,8 +2866,8 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa MIRBuilder *mirbuilder = GetCG()->GetMIRModule()->GetMIRBuilder(); MIRFunction *mfunc = mirbuilder->GetFunctionFromName(str); - MapleMap >::iterator it = - CG::GetFuncWrapLabels().find(mfunc); + MapleMap >::iterator it = + CG::GetFuncWrapLabels().find(mfunc); if (it != CG::GetFuncWrapLabels().end()) { EmitLabelForFunc(mfunc, (*it).second.second); /* end label */ } else { @@ -2919,8 +2909,8 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa const std::string &str = GlobalTables::GetStrTable().GetStringFromStrIdx(name->GetId()); MIRBuilder *mirbuilder = GetCG()->GetMIRModule()->GetMIRBuilder(); MIRFunction *mfunc = mirbuilder->GetFunctionFromName(str); - MapleMap >::iterator - it = CG::GetFuncWrapLabels().find(mfunc); + MapleMap >::iterator + it = CG::GetFuncWrapLabels().find(mfunc); if (it != CG::GetFuncWrapLabels().end()) { EmitLabelForFunc(mfunc, (*it).second.first); /* it is a */ } else { @@ -2952,20 +2942,20 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa break; case DW_FORM_ref4: if (attrName == DW_AT_type) { - DBGDie *die = di->GetDie(attr->GetU()); - if (die->GetOffset()) { - EmitHexUnsigned(die->GetOffset()); + DBGDie *die0 = di->GetDie(attr->GetU()); + if (die0->GetOffset()) { + EmitHexUnsigned(die0->GetOffset()); } else { /* unknown type, missing mplt */ EmitHexUnsigned(di->GetDummyTypeDie()->GetOffset()); Emit(CMNT "Warning: dummy type used"); } } else if (attrName == DW_AT_specification || attrName == DW_AT_sibling) { - DBGDie *die = di->GetDie(attr->GetU()); - ASSERT(die->GetOffset(), ""); - EmitHexUnsigned(die->GetOffset()); + DBGDie *die0 = di->GetDie(attr->GetU()); + ASSERT(die0->GetOffset(), ""); + EmitHexUnsigned(die0->GetOffset()); } else if (attrName == DW_AT_object_pointer) { - GStrIdx thisIdx = GlobalTables::GetStrTable().GetStrIdxFromName(DEBUG_MAPLE_THIS); + GStrIdx thisIdx = GlobalTables::GetStrTable().GetStrIdxFromName(kDebugMapleThis); DBGDie *that = LFindChildDieWithName(die, DW_TAG_formal_parameter, thisIdx); /* need to find the this or self based on the source language what is the name for 'this' used in mapleir? @@ -2989,7 +2979,7 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa EmitHexUnsigned(elp->GetOp()); break; case DW_OP_addr: - EmitHexUnsigned(9); + EmitHexUnsigned(k9ByteSize); Emit("\n\t.byte "); EmitHexUnsigned(elp->GetOp()); Emit("\n\t.8byte "); @@ -3009,7 +2999,7 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa } break; default: CHECK_FATAL(maple::GetDwFormName(attr->GetDwForm()) != nullptr, - "GetDwFormName return null in Emitter::EmitDIAttrValue"); + "GetDwFormName return null in Emitter::EmitDIAttrValue"); LogInfo::MapleLogger() << "unhandled : " << maple::GetDwFormName(attr->GetDwForm()) << std::endl; ASSERT(0, "NYI"); } @@ -3026,11 +3016,11 @@ void Emitter::EmitDIDebugInfoSection(DebugInfo *mirdi) { EmitHexUnsigned(mirdi->GetDebugInfoLength()); Emit(CMNT "section length\n"); /* DWARF version. uhalf. */ - Emit("\t.2byte\t0x" XSTR(DWARF_VERSION) "\n"); /* 4 for version 4. */ + Emit("\t.2byte\t0x" XSTR(kDwarfVersion) "\n"); /* 4 for version 4. */ /* debug_abbrev_offset. 4byte for 32-bit, 8byte for 64-bit */ Emit("\t.4byte\t.L" XSTR(DEBUG_ABBREV_0) "\n"); /* address size. ubyte */ - Emit("\t.byte\t0x" XSTR(SIZEOFPTR) "\n"); + Emit("\t.byte\t0x" XSTR(kSizeOfPTR) "\n"); /* * 7.5.1.2 type unit header * currently empty... @@ -3038,7 +3028,7 @@ void Emitter::EmitDIDebugInfoSection(DebugInfo *mirdi) { * 7.5.2 Debugging Information Entry (DIE) */ Emitter *emitter = this; - MapleVector &abbrevVec = mirdi->GetAbbrevVec(); + MapleVector &abbrevVec = mirdi->GetAbbrevVec(); ApplyInPrefixOrder(mirdi->GetCompUnit(), [&abbrevVec, &emitter, &mirdi](DBGDie *die) { if (!die) { /* emit the null entry and return */ @@ -3054,7 +3044,7 @@ void Emitter::EmitDIDebugInfoSection(DebugInfo *mirdi) { if (verbose) { emitter->Emit(CMNT); CHECK_FATAL(maple::GetDwTagName(die->GetTag()) != nullptr, - "GetDwTagName(die->GetTag()) return null in Emitter::EmitDIDebugInfoSection"); + "GetDwTagName(die->GetTag()) return null in Emitter::EmitDIDebugInfoSection"); emitter->Emit(maple::GetDwTagName(die->GetTag())); emitter->Emit(" Offset= "); emitter->EmitHexUnsigned(die->GetOffset()); @@ -3075,16 +3065,16 @@ void Emitter::EmitDIDebugInfoSection(DebugInfo *mirdi) { std::string sfile, spath; if (diae->GetTag() == DW_TAG_compile_unit && sfile.empty()) { /* get full source path from fileMap[2] */ - if (emitter->GetFileMap().size() > 2) { /* have src file map */ - std::string srcPath = emitter->GetFileMap()[2]; + if (emitter->GetFileMap().size() > k2ByteSize) { /* have src file map */ + std::string srcPath = emitter->GetFileMap()[k2ByteSize]; size_t t = srcPath.rfind("/"); ASSERT(t != std::string::npos, ""); - sfile = srcPath.substr(t+1); + sfile = srcPath.substr(t + 1); spath = srcPath.substr(0, t); } } - for (int i = 0; i < diae->GetAttrPairs().size(); i += 2) { + for (int i = 0; i < diae->GetAttrPairs().size(); i += k2ByteSize) { DBGDieAttr *attr = LFindAttribute(die->GetAttrVec(), DwAt(apl[i])); if (!LShouldEmit(unsigned(apl[i + 1]))) { continue; @@ -3148,7 +3138,7 @@ void Emitter::EmitDIDebugAbbrevSection(DebugInfo *mirdi) { Emit("\t.uleb128 "); EmitHexUnsigned(diae->GetTag()); CHECK_FATAL(maple::GetDwTagName(diae->GetTag()) != nullptr, - "GetDwTagName return null in Emitter::EmitDIDebugAbbrevSection"); + "GetDwTagName return null in Emitter::EmitDIDebugAbbrevSection"); if (verbose) { Emit(CMNT); Emit(maple::GetDwTagName(diae->GetTag())); @@ -3164,12 +3154,12 @@ void Emitter::EmitDIDebugAbbrevSection(DebugInfo *mirdi) { } Emit("\n"); - for (int i = 0; i < diae->GetAttrPairs().size(); i += 2) { + for (int i = 0; i < diae->GetAttrPairs().size(); i += k2ByteSize) { /* odd entry -- DW_AT_*, even entry -- DW_FORM_* */ Emit("\t.uleb128 "); EmitHexUnsigned(apl[i]); CHECK_FATAL(maple::GetDwAtName(unsigned(apl[i])) != nullptr, - "GetDwAtName return null in Emitter::EmitDIDebugAbbrevSection"); + "GetDwAtName return null in Emitter::EmitDIDebugAbbrevSection"); if (verbose) { Emit(CMNT); Emit(maple::GetDwAtName(unsigned(apl[i]))); @@ -3178,7 +3168,7 @@ void Emitter::EmitDIDebugAbbrevSection(DebugInfo *mirdi) { Emit("\t.uleb128 "); EmitHexUnsigned(apl[i + 1]); CHECK_FATAL(maple::GetDwFormName(unsigned(apl[i + 1])) != nullptr, - "GetDwFormName return null in Emitter::EmitDIDebugAbbrevSection"); + "GetDwFormName return null in Emitter::EmitDIDebugAbbrevSection"); if (verbose) { Emit(CMNT); Emit(maple::GetDwFormName(unsigned(apl[i + 1]))); @@ -3216,37 +3206,39 @@ void Emitter::EmitDIDebugStrSection() { } } -void Emitter::FillInClassByteSize(DBGDie *die, DBGDieAttr *byteSizeAttr, DBGAbbrevEntry *diae) { +void Emitter::FillInClassByteSize(DBGDie *die, DBGDieAttr *byteSizeAttr) { ASSERT(byteSizeAttr->GetDwForm() == DW_FORM_data1 || byteSizeAttr->GetDwForm() == DW_FORM_data2 || - byteSizeAttr->GetDwForm() == DW_FORM_data4 || byteSizeAttr->GetDwForm() == DW_FORM_data8, - "Unknown FORM value for DW_AT_byte_size"); + byteSizeAttr->GetDwForm() == DW_FORM_data4 || byteSizeAttr->GetDwForm() == DW_FORM_data8, + "Unknown FORM value for DW_AT_byte_size"); if (byteSizeAttr->GetI() == static_cast(kDbgDefaultVal)) { /* get class size */ DBGDieAttr *nameAttr = LFindDieAttr(die, DW_AT_name); CHECK_FATAL(nameAttr != nullptr, "name_attr is nullptr in Emitter::FillInClassByteSize"); + /* hope this is a global string index as it is a type name */ TyIdx tyIdx = - GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(GStrIdx(nameAttr->GetId())); /* hope this is a global string index as it is a type name */ - CHECK_FATAL(tyIdx.GetIdx() < Globals::GetInstance()->GetBECommon()->GetSizeOfTypeSizeTable(), "index out of range in Emitter::FillInClassByteSize"); + GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(GStrIdx(nameAttr->GetId())); + CHECK_FATAL(tyIdx.GetIdx() < Globals::GetInstance()->GetBECommon()->GetSizeOfTypeSizeTable(), + "index out of range in Emitter::FillInClassByteSize"); int64_t byteSize = Globals::GetInstance()->GetBECommon()->GetTypeSize(tyIdx.GetIdx()); - LUpdateAttrValue(byteSizeAttr, byteSize, diae); + LUpdateAttrValue(byteSizeAttr, byteSize); } } void Emitter::SetupDBGInfo(DebugInfo *mirdi) { Emitter *emitter = this; - MapleVector &abbrevVec = mirdi->GetAbbrevVec(); + MapleVector &abbrevVec = mirdi->GetAbbrevVec(); ApplyInPrefixOrder(mirdi->GetCompUnit(), [&abbrevVec, &emitter](DBGDie *die) { if (!die) { return; } CHECK_FATAL(maple::GetDwTagName(die->GetTag()) != nullptr, - "maple::GetDwTagName(die->GetTag()) is nullptr in Emitter::SetupDBGInfo"); + "maple::GetDwTagName(die->GetTag()) is nullptr in Emitter::SetupDBGInfo"); if (die->GetAbbrevId() == 0) { LogInfo::MapleLogger() << maple::GetDwTagName(die->GetTag()) << std::endl; } CHECK_FATAL(die->GetAbbrevId() < abbrevVec.size(), "index out of range in Emitter::SetupDBGInfo"); - ASSERT(abbrevVec[die->GetAbbrevId()]->GetAbbrevId()== die->GetAbbrevId(), ""); + ASSERT(abbrevVec[die->GetAbbrevId()]->GetAbbrevId() == die->GetAbbrevId(), ""); DBGAbbrevEntry *diae = abbrevVec[die->GetAbbrevId()]; switch (diae->GetTag()) { case DW_TAG_subprogram: { @@ -3259,7 +3251,7 @@ void Emitter::SetupDBGInfo(DebugInfo *mirdi) { case DW_TAG_interface_type: { DBGDieAttr *byteSizeAttr = LFindDieAttr(die, DW_AT_byte_size); if (byteSizeAttr) { - emitter->FillInClassByteSize(die, byteSizeAttr, diae); + emitter->FillInClassByteSize(die, byteSizeAttr); } /* get the name */ DBGDieAttr *atName = LFindDieAttr(die, DW_AT_name); @@ -3269,14 +3261,16 @@ void Emitter::SetupDBGInfo(DebugInfo *mirdi) { MIRType *mty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ctyIdx); MIRStructType *sty = static_cast(mty); CHECK_FATAL(sty != nullptr, "pointer cast failed"); - CHECK_FATAL(sty->GetTypeIndex().GetIdx() < Globals::GetInstance()->GetBECommon()->GetSizeOfStructFieldCountTable(), ""); + CHECK_FATAL(sty->GetTypeIndex().GetIdx() < + Globals::GetInstance()->GetBECommon()->GetSizeOfStructFieldCountTable(), ""); int embeddedIDs = 0; MIRStructType *prevSubstruct = nullptr; for (int i = 0; i < sty->GetFields().size(); i++) { TyIdx fieldtyidx = sty->GetFieldsElemt(i).second.first; MIRType *fieldty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldtyidx); if (prevSubstruct) { - embeddedIDs += Globals::GetInstance()->GetBECommon()->GetStructFieldCount(prevSubstruct->GetTypeIndex().GetIdx()); + embeddedIDs += + Globals::GetInstance()->GetBECommon()->GetStructFieldCount(prevSubstruct->GetTypeIndex().GetIdx()); } prevSubstruct = fieldty->EmbeddedStructType(); FieldID fieldID = i + embeddedIDs + 1; @@ -3288,7 +3282,7 @@ void Emitter::SetupDBGInfo(DebugInfo *mirdi) { CHECK_FATAL(mloc != nullptr, "mloc is null in Emitter::SetupDBGInfo"); DBGAbbrevEntry *childDiae = abbrevVec[cdie->GetAbbrevId()]; CHECK_FATAL(childDiae != nullptr, "child_diae is null in Emitter::SetupDBGInfo"); - LUpdateAttrValue(mloc, offset, childDiae); + LUpdateAttrValue(mloc, offset); } } break; default: @@ -3332,4 +3326,4 @@ void LabelOperand::Emit(Emitter &emitter, const OpndProp *opndProp) const { void LabelOperand::Dump() const { LogInfo::MapleLogger() << "label:" << labelIndex; } -} /* namespace maplebe */ +} /* namespace maplebe */ diff --git a/src/mapleall/maple_be/src/cg/label_creation.cpp b/src/mapleall/maple_be/src/cg/label_creation.cpp index 85bc653b7f3764edb7e850fa529ce95c79c5aaaf..5a7466d8968a9ab1e6153068ee4f4f3eb5419e50 100644 --- a/src/mapleall/maple_be/src/cg/label_creation.cpp +++ b/src/mapleall/maple_be/src/cg/label_creation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved. + * 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. diff --git a/src/mapleall/maple_ir/BUILD.gn b/src/mapleall/maple_ir/BUILD.gn index e82727b14cda85c331b69dc432e059e825069a60..8043fcebce91956741a29d8c6a074383f25a2270 100755 --- a/src/mapleall/maple_ir/BUILD.gn +++ b/src/mapleall/maple_ir/BUILD.gn @@ -22,6 +22,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/maple_phase/include", + "${THIRD_PARTY_ROOT}/dwarf_h/include", "${THIRD_PARTY_ROOT}/llvm_modified/include/llvm/BinaryFormat", ] diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index 3550366fd0607369bd01c3ddf6cbb049a1104eaf..6db59af0031486381fe9f947bc14f584e3e384f5 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -1,5 +1,5 @@ /* - * Copyright (C) [2020-2021] Futurewei Technologies, Inc. All rights reverved. + * 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. @@ -224,7 +224,7 @@ class DBGDieAttr { void Dump(int indent); - DBGDieKind GetKind() { + DBGDieKind GetKind() const { return dieKind; } @@ -232,7 +232,7 @@ class DBGDieAttr { dieKind = kind; } - DwAt GetDwAt() { + DwAt GetDwAt() const { return dwAttr; } @@ -240,7 +240,7 @@ class DBGDieAttr { dwAttr = at; } - DwForm GetDwForm() { + DwForm GetDwForm() const { return dwForm; } @@ -248,7 +248,7 @@ class DBGDieAttr { dwForm = form; } - int32 GetI() { + int32 GetI() const { return value.i; } @@ -256,7 +256,7 @@ class DBGDieAttr { value.i = val; } - uint32 GetId() { + uint32 GetId() const { return value.id; } @@ -264,7 +264,7 @@ class DBGDieAttr { value.id = val; } - int64 GetJ() { + int64 GetJ() const { return value.j; } @@ -272,7 +272,7 @@ class DBGDieAttr { value.j = val; } - uint64 GetU() { + uint64 GetU() const { return value.u; } @@ -280,7 +280,7 @@ class DBGDieAttr { value.u = val; } - float GetF() { + float GetF() const { return value.f; } @@ -288,7 +288,7 @@ class DBGDieAttr { value.f = val; } - double GetD() { + double GetD() const { return value.d; } @@ -673,11 +673,11 @@ class DebugInfo { return abbrevVec; } - DBGDie * GetCompUnit() const { + DBGDie *GetCompUnit() const { return compUnit; } - void SetTyidxDieIdMap(TyIdx tyIdx, const DBGDie *die) { + void SetTyidxDieIdMap(const TyIdx tyIdx, const DBGDie *die) { tyIdxDieIdMap[tyIdx.GetIdx()] = die->GetId(); } diff --git a/src/mapleall/maple_ir/include/global_tables.h b/src/mapleall/maple_ir/include/global_tables.h index 3a49f5246fb0e6112d66a556edaaf95dc1c35e7b..ad419cd59cd4d59b911bf8ad9b72d39f81ca3bf2 100644 --- a/src/mapleall/maple_ir/include/global_tables.h +++ b/src/mapleall/maple_ir/include/global_tables.h @@ -73,7 +73,7 @@ class IntConstKey { class IntConstHash { public: std::size_t operator() (const IntConstKey &key) const { - return std::hash{}(key.val) ^ (std::hash{}((uint64)key.tyIdx) << 1); + return std::hash{}(key.val) ^ (std::hash{}(static_cast(key.tyIdx)) << 1); } }; diff --git a/src/mapleall/maple_ir/include/intrinsic_vector.def b/src/mapleall/maple_ir/include/intrinsic_vector.def index d814047649229c1fe0f9c7a96911d5690bcd4384..5614883370641d3e048e1985188230adb79288c9 100644 --- a/src/mapleall/maple_ir/include/intrinsic_vector.def +++ b/src/mapleall/maple_ir/include/intrinsic_vector.def @@ -571,3 +571,149 @@ DEF_MIR_INTRINSIC(vector_reverse_v2f32, "vector_reverse_v2f32", INTRNISVECTOR | INTRNISPURE | INTRNNOSIDEEFFECT, kArgTyV2F32, kArgTyV2F32) + +// vecTy vector_load(scalarTy *ptr) +// Load the elements pointed to by ptr into a vector. +DEF_MIR_INTRINSIC(vector_load_v2i64, + "vector_load_v2i64", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV2I64, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v4i32, + "vector_load_v4i32", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV4I32, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v8i16, + "vector_load_v8i16", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV8I16, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v16i8, + "vector_load_v16i8", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV16I8, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v2u64, + "vector_load_v2u64", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV2U64, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v4u32, + "vector_load_v4u32", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV4U32, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v8u16, + "vector_load_v8u16", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV8U16, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v16u8, + "vector_load_v16u8", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV16U8, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v2f64, + "vector_load_v2f64", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV2F64, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v4f32, + "vector_load_v4f32", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV4F32, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v1i64, + "vector_load_v1i64", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV1I64, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v2i32, + "vector_load_v2i32", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV2I32, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v4i16, + "vector_load_v4i16", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV4I16, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v8i8, + "vector_load_v8i8", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV8I8, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v1u64, + "vector_load_v1u64", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV1U64, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v2u32, + "vector_load_v2u32", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV2U32, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v4u16, + "vector_load_v4u16", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV4U16, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v8u8, + "vector_load_v8u8", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV8U8, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v1f64, + "vector_load_v1f64", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV1F64, kArgTyPtr) +DEF_MIR_INTRINSIC(vector_load_v2f32, + "vector_load_v2f32", + INTRNISVECTOR | INTRNLOADMEM | INTRNNOSIDEEFFECT, + kArgTyV2F32, kArgTyPtr) + +// void vector_store(scalarTy *ptr, vecTy src) +// Store the elements from src into the memory pointed to by ptr. +DEF_MIR_INTRINSIC(vector_store_v2i64, + "vector_store_v2i64", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV2I64) +DEF_MIR_INTRINSIC(vector_store_v4i32, + "vector_store_v4i32", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV4I32) +DEF_MIR_INTRINSIC(vector_store_v8i16, + "vector_store_v8i16", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV8I16) +DEF_MIR_INTRINSIC(vector_store_v16i8, + "vector_store_v16i8", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV16I8) +DEF_MIR_INTRINSIC(vector_store_v2u64, + "vector_store_v2u64", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV2U64) +DEF_MIR_INTRINSIC(vector_store_v4u32, + "vector_store_v4u32", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV4U32) +DEF_MIR_INTRINSIC(vector_store_v8u16, + "vector_store_v8u16", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV8U16) +DEF_MIR_INTRINSIC(vector_store_v16u8, + "vector_store_v16u8", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV16U8) +DEF_MIR_INTRINSIC(vector_store_v2f64, + "vector_store_v2f64", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV2F64) +DEF_MIR_INTRINSIC(vector_store_v4f32, + "vector_store_v4f32", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV4F32) +DEF_MIR_INTRINSIC(vector_store_v1i64, + "vector_store_v1i64", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV1I64) +DEF_MIR_INTRINSIC(vector_store_v2i32, + "vector_store_v2i32", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV2I32) +DEF_MIR_INTRINSIC(vector_store_v4i16, + "vector_store_v4i16", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV4I16) +DEF_MIR_INTRINSIC(vector_store_v8i8, + "vector_store_v8i8", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV8I8) +DEF_MIR_INTRINSIC(vector_store_v1u64, + "vector_store_v1u64", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV1U64) +DEF_MIR_INTRINSIC(vector_store_v2u32, + "vector_store_v2u32", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV2U32) +DEF_MIR_INTRINSIC(vector_store_v4u16, + "vector_store_v4u16", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV4U16) +DEF_MIR_INTRINSIC(vector_store_v8u8, + "vector_store_v8u8", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV8U8) +DEF_MIR_INTRINSIC(vector_store_v1f64, + "vector_store_v1f64", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV1F64) +DEF_MIR_INTRINSIC(vector_store_v2f32, + "vector_store_v2f32", + INTRNISVECTOR, kArgTyVoid, kArgTyPtr, kArgTyV2F32) diff --git a/src/mapleall/maple_ir/src/mir_builder.cpp b/src/mapleall/maple_ir/src/mir_builder.cpp index 96fcd947375a6f426a7714ff23b986c6c4ec452c..1c74c3449e927d1818c90bb75dfdfc4a78476eec 100644 --- a/src/mapleall/maple_ir/src/mir_builder.cpp +++ b/src/mapleall/maple_ir/src/mir_builder.cpp @@ -146,9 +146,6 @@ bool MIRBuilder::TraverseToNamedFieldWithTypeAndMatchStyle(MIRStructType &struct unsigned int style = matchStyle & kMatchAnyField; if (fieldType->IsStructType()) { auto *subStructType = static_cast(fieldType); - if (subStructType->GetKind() == kTypeUnion) { - continue; - } if (TraverseToNamedFieldWithTypeAndMatchStyle(*subStructType, nameIdx, typeIdx, fieldID, style)) { return true; } diff --git a/src/mapleall/maple_me/BUILD.gn b/src/mapleall/maple_me/BUILD.gn index 7d4f7e9924e50b2291d852c41012ac58f5951658..c0440d402e2b3a28418e35c7a87d7dcde70cb65d 100755 --- a/src/mapleall/maple_me/BUILD.gn +++ b/src/mapleall/maple_me/BUILD.gn @@ -96,7 +96,6 @@ src_libmplme = [ ] src_libmplmewpo = [ - "src/alias_analysis_table.cpp", "src/alias_class.cpp", "src/bb.cpp", "src/dominance.cpp", diff --git a/src/mapleall/maple_me/include/alias_analysis_table.h b/src/mapleall/maple_me/include/alias_analysis_table.h deleted file mode 100644 index 71f1ca37093970d12e3128fdd5aecffe70d313d8..0000000000000000000000000000000000000000 --- a/src/mapleall/maple_me/include/alias_analysis_table.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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. - * 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_ME_INCLUDE_ALIAS_ANALYSIS_TABLE_H -#define MAPLE_ME_INCLUDE_ALIAS_ANALYSIS_TABLE_H -#include "orig_symbol.h" -#include "ssa_tab.h" -#include "class_hierarchy.h" - -namespace maple { -class AliasAnalysisTable { - public: - AliasAnalysisTable(SSATab &ssaTable, const MapleAllocator &allocator, KlassHierarchy &kh) - : ssaTab(ssaTable), - alloc(allocator), - prevLevelNode(alloc.Adapter()), - nextLevelNodes(alloc.Adapter()), - memPool(ssaTab.GetMempool()), - klassHierarchy(kh) {} - - ~AliasAnalysisTable() = default; - - OriginalSt *GetPrevLevelNode(const OriginalSt &ost); - MapleVector *GetNextLevelNodes(const OriginalSt &ost); - OriginalSt *FindOrCreateAddrofSymbolOriginalSt(OriginalSt &ost); - OriginalSt *FindOrCreateExtraLevOriginalSt(OriginalSt &ost, TyIdx ptyidx, FieldID fld); - - SSATab &ssaTab; - MapleAllocator alloc; - MapleMap prevLevelNode; // index is the OStIdx - private: - OriginalSt *FindOrCreateExtraLevSymOrRegOriginalSt(OriginalSt &ost, TyIdx tyIdx, FieldID fld); - OriginalSt *FindExtraLevOriginalSt(const MapleVector &nextLevelOsts, FieldID fld); - - MapleMap*> nextLevelNodes; // index is the OStIdx - MemPool *memPool; - KlassHierarchy &klassHierarchy; -}; -} // namespace maple -#endif // MAPLE_ME_INCLUDE_ALIAS_ANALYSIS_TABLE_H diff --git a/src/mapleall/maple_me/include/alias_class.h b/src/mapleall/maple_me/include/alias_class.h index a2697e5cdea57d4ebd4faf277be2b02589e3e4eb..9c342f6c5d92ca90016d19265c9ab23e576ebc20 100644 --- a/src/mapleall/maple_me/include/alias_class.h +++ b/src/mapleall/maple_me/include/alias_class.h @@ -20,7 +20,6 @@ #include "ssa_tab.h" #include "union_find.h" #include "class_hierarchy.h" -#include "alias_analysis_table.h" namespace maple { class AliasElem { @@ -120,13 +119,6 @@ class AliasClass : public AnalysisResult { ~AliasClass() override = default; - AliasAnalysisTable *GetAliasAnalysisTable() { - if (aliasAnalysisTable == nullptr) { - aliasAnalysisTable = acMemPool.New(ssaTab, acAlloc, *klassHierarchy); - } - return aliasAnalysisTable; - } - const AliasElem *FindAliasElem(const OriginalSt &ost) const { return osym2Elem.at(ost.GetIndex()); } @@ -175,6 +167,8 @@ class AliasClass : public AnalysisResult { void InsertMayDefUseCall(StmtNode &stmt, BBId bbid, bool hasSideEffect, bool hasNoPrivateDefEffect); void GenericInsertMayDefUse(StmtNode &stmt, BBId bbID); + static bool MayAliasBasicAA(const OriginalSt *ostA, const OriginalSt *ostB); + protected: virtual bool InConstructorLikeFunc() const { return true; @@ -197,7 +191,6 @@ class AliasClass : public AnalysisResult { bool SetNextLevNADSForPtrIntegerCopy(AliasElem &lhsAe, const AliasElem *rhsAe, BaseNode &rhs); void CreateMirroringAliasElems(const OriginalSt *ost1, OriginalSt *ost2); AliasElem *FindOrCreateDummyNADSAe(); - bool IsPointedTo(OriginalSt &oSt); AliasElem &FindOrCreateAliasElemOfAddrofOSt(OriginalSt &oSt); AliasElem &FindOrCreateAliasElemOfAddrofZeroFieldIDOSt(OriginalSt &oSt); void CollectMayDefForMustDefs(const StmtNode &stmt, std::set &mayDefOsts); @@ -246,7 +239,6 @@ class AliasClass : public AnalysisResult { bool ignoreIPA; // whether to ignore information provided by IPA bool calleeHasSideEffect; KlassHierarchy *klassHierarchy; - AliasAnalysisTable *aliasAnalysisTable = nullptr; }; } // namespace maple #endif // MAPLE_ME_INCLUDE_ALIAS_CLASS_H diff --git a/src/mapleall/maple_me/include/orig_symbol.h b/src/mapleall/maple_me/include/orig_symbol.h index 0e7f100229c4d0c8c613acdb97667c191ea9c311..d0d3d3d69dc7df27f2142822e1cacdacf8ca8348 100644 --- a/src/mapleall/maple_me/include/orig_symbol.h +++ b/src/mapleall/maple_me/include/orig_symbol.h @@ -19,6 +19,7 @@ #include "mir_preg.h" #include "mir_function.h" #include "mpl_number.h" +#include "class_hierarchy.h" // This file defines the data structure OriginalSt that represents a program // symbol occurring in the code of the program being optimized. @@ -202,6 +203,35 @@ class OriginalSt { return GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); } + OriginalSt *GetPrevLevelOst() const { + return prevLevOst; + } + + void SetPrevLevelOst(OriginalSt *prevLevelOst) { + ASSERT(this->prevLevOst == nullptr || this->prevLevOst == prevLevelOst, "wrong prev-level-ost"); + this->prevLevOst = prevLevelOst; + } + + const MapleVector &GetNextLevelOsts() const { + return nextLevOsts; + } + + MapleVector &GetNextLevelOsts() { + return nextLevOsts; + } + + void AddNextLevelOst(OriginalSt *nextLevelOst, bool checkRedundant = false) { + ASSERT(nextLevelOst->GetPrevLevelOst() == this, "prev-level-ost of nextLevelOst should be this ost"); + if (checkRedundant) { + for (auto *ost : nextLevOsts) { + if (ost->fieldID == nextLevelOst->fieldID) { + return; + } + } + } + nextLevOsts.push_back(nextLevelOst); + } + private: enum OSTType { kUnkonwnOst, @@ -222,7 +252,8 @@ class OriginalSt { isFormal(isFormal), ignoreRC(ignoreRC), symOrPreg(sysOrPreg), - puIdx(pIdx) {} + puIdx(pIdx), + nextLevOsts(alloc.Adapter()) {} OSTType ostType; OStIdx index; // index number in originalStVector @@ -240,6 +271,8 @@ class OriginalSt { bool epreLocalRefVar = false; // is a localrefvar temp created by epre phase SymOrPreg symOrPreg; PUIdx puIdx; + OriginalSt *prevLevOst = nullptr; + MapleVector nextLevOsts; }; class SymbolFieldPair { @@ -337,6 +370,12 @@ class OriginalStTable { void Dump(); + OriginalSt *FindOrCreateAddrofSymbolOriginalSt(OriginalSt *ost); + OriginalSt *FindOrCreateExtraLevOriginalSt(OriginalSt *ost, TyIdx ptyidx, FieldID fld); + OriginalSt *FindOrCreateExtraLevSymOrRegOriginalSt(OriginalSt *ost, TyIdx tyIdx, FieldID fld, + const KlassHierarchy *klassHierarchy = nullptr); + OriginalSt *FindExtraLevOriginalSt(const MapleVector &nextLevelOsts, FieldID fld); + private: MapleAllocator alloc; MIRModule &mirModule; diff --git a/src/mapleall/maple_me/include/ssa_tab.h b/src/mapleall/maple_me/include/ssa_tab.h index 028e9f63b09395d751ea941b538ce0d0ca434d0a..e655f30c8f41bf7fcbead6a83cda7c4202403218 100644 --- a/src/mapleall/maple_me/include/ssa_tab.h +++ b/src/mapleall/maple_me/include/ssa_tab.h @@ -69,6 +69,14 @@ class SSATab : public AnalysisResult { return originalStTable.FindOrCreateSymbolOriginalSt(mirSt, puIdx, fld); } + OriginalSt *FindOrCreateExtraLevOriginalSt(OriginalSt *ost, TyIdx tyIdx, FieldID fld) { + return originalStTable.FindOrCreateExtraLevOriginalSt(ost, tyIdx, fld); + } + + OriginalSt *FindOrCreateAddrofSymbolOriginalSt(OriginalSt *ost) { + return originalStTable.FindOrCreateAddrofSymbolOriginalSt(ost); + } + const OriginalSt *GetOriginalStFromID(OStIdx id) const { return originalStTable.GetOriginalStFromID(id); } diff --git a/src/mapleall/maple_me/src/alias_analysis_table.cpp b/src/mapleall/maple_me/src/alias_analysis_table.cpp deleted file mode 100644 index 7bade2fed7bd87ef1e2d6dfa262aafeb28b9fd40..0000000000000000000000000000000000000000 --- a/src/mapleall/maple_me/src/alias_analysis_table.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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. - * 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. - */ -#include "alias_analysis_table.h" - -namespace maple { -OriginalSt *AliasAnalysisTable::GetPrevLevelNode(const OriginalSt &ost) { - auto it = prevLevelNode.find(ost.GetIndex()); - if (it != prevLevelNode.end()) { - return it->second; - } - return nullptr; -} - -MapleVector *AliasAnalysisTable::GetNextLevelNodes(const OriginalSt &ost) { - auto it = nextLevelNodes.find(ost.GetIndex()); - if (it != nextLevelNodes.end()) { - return it->second; - } - - MapleVector *newOriginalStVec = - alloc.GetMemPool()->New>(alloc.Adapter()); - (void)nextLevelNodes.insert(std::make_pair(ost.GetIndex(), newOriginalStVec)); - return newOriginalStVec; -} - -OriginalSt *AliasAnalysisTable::FindOrCreateAddrofSymbolOriginalSt(OriginalSt &ost) { - auto it = prevLevelNode.find(ost.GetIndex()); - if (it != prevLevelNode.end()) { - return it->second; - } - // create a new node - OriginalStTable &originalStTab = ssaTab.GetOriginalStTable(); - OriginalSt *prevLevelOst = memPool->New(originalStTab.Size(), *ost.GetMIRSymbol(), - ost.GetPuIdx(), 0, originalStTab.GetAlloc()); - originalStTab.GetOriginalStVector().push_back(prevLevelOst); - prevLevelOst->SetIndirectLev(-1); - MIRPtrType pointType(ost.GetMIRSymbol()->GetTyIdx(), PTY_ptr); - TyIdx newTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&pointType); - prevLevelOst->SetTyIdx(newTyIdx); - prevLevelOst->SetFieldID(0); - GetNextLevelNodes(*prevLevelOst)->push_back(&ost); - (void)prevLevelNode.insert(std::make_pair(ost.GetIndex(), prevLevelOst)); - return prevLevelOst; -} - -OriginalSt *AliasAnalysisTable::FindOrCreateExtraLevSymOrRegOriginalSt(OriginalSt &ost, TyIdx tyIdx, FieldID fld) { - TyIdx ptyIdxOfOst = ost.GetTyIdx(); - FieldID fldIDInOst = fld; - if (ptyIdxOfOst != tyIdx) { - (void)klassHierarchy.UpdateFieldID(tyIdx, ptyIdxOfOst, fldIDInOst); - } - MapleVector *nextLevelOsts = GetNextLevelNodes(ost); - OriginalSt *nextLevOst = FindExtraLevOriginalSt(*nextLevelOsts, fldIDInOst); - if (nextLevOst != nullptr) { - return nextLevOst; - } - - // create a new node - OriginalStTable &originalStTab = ssaTab.GetOriginalStTable(); - if (ost.IsSymbolOst()) { - nextLevOst = memPool->New(originalStTab.Size(), *ost.GetMIRSymbol(), - ost.GetPuIdx(), fldIDInOst, originalStTab.GetAlloc()); - } else { - nextLevOst = memPool->New(originalStTab.Size(), ost.GetPregIdx(), - ost.GetPuIdx(), originalStTab.GetAlloc()); - } - originalStTab.GetOriginalStVector().push_back(nextLevOst); - CHECK_FATAL(ost.GetIndirectLev() < INT8_MAX, "boundary check"); - nextLevOst->SetIndirectLev(ost.GetIndirectLev() + 1); - (void)prevLevelNode.insert(std::make_pair(nextLevOst->GetIndex(), &ost)); - tyIdx = (tyIdx == 0u) ? ost.GetTyIdx() : tyIdx; - if (tyIdx != 0u) { - // use the tyIdx info from the instruction - const MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - if (mirType->GetKind() == kTypePointer) { - const auto *ptType = static_cast(mirType); - TyIdxFieldAttrPair fieldPair = ptType->GetPointedTyIdxFldAttrPairWithFieldID(fld); - nextLevOst->SetTyIdx(fieldPair.first); - nextLevOst->SetIsFinal(fieldPair.second.GetAttr(FLDATTR_final)); - nextLevOst->SetIsPrivate(fieldPair.second.GetAttr(FLDATTR_private)); - } else { - nextLevOst->SetTyIdx(TyIdx(PTY_void)); - } - } - ASSERT(!GlobalTables::GetTypeTable().GetTypeTable().empty(), "container check"); - if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(ost.GetTyIdx())->PointsToConstString()) { - nextLevOst->SetIsFinal(true); - } - GetNextLevelNodes(ost)->push_back(nextLevOst); - ASSERT(originalStTab.GetOriginalStFromID(ost.GetIndex()) == &ost, "OriginalStTable:: index inconsistent"); - return nextLevOst; -} - -OriginalSt *AliasAnalysisTable::FindOrCreateExtraLevOriginalSt(OriginalSt &ost, TyIdx ptyIdx, FieldID fld) { - if (ost.IsSymbolOst() || ost.IsPregOst()) { - return FindOrCreateExtraLevSymOrRegOriginalSt(ost, ptyIdx, fld); - } - return nullptr; -} - -OriginalSt *AliasAnalysisTable::FindExtraLevOriginalSt(const MapleVector &nextLevelOsts, FieldID fld) { - for (OriginalSt *nextLevelOst : nextLevelOsts) { - if (nextLevelOst->GetFieldID() == fld) { - return nextLevelOst; - } - } - return nullptr; -} -} // namespace maple diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index 19c0b44a3b1f37c3490a577f75e672a5c4579da0..d9971417c0c9438b2e540ac212567d4ac1531a52 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -186,11 +186,11 @@ AliasElem *AliasClass::FindOrCreateExtraLevAliasElem(BaseNode &expr, TyIdx tyIdx } OriginalSt *newOst = nullptr; if (mirModule.IsCModule() && ainfo.ae->GetOriginalSt().GetTyIdx() != tyIdx) { - newOst = GetAliasAnalysisTable()->FindOrCreateExtraLevOriginalSt( - ainfo.ae->GetOriginalSt(), ainfo.ae->GetOriginalSt().GetTyIdx(), 0); + newOst = ssaTab.FindOrCreateExtraLevOriginalSt( + ainfo.ae->GetOst(), ainfo.ae->GetOriginalSt().GetTyIdx(), 0); } else { - newOst = GetAliasAnalysisTable()->FindOrCreateExtraLevOriginalSt( - ainfo.ae->GetOriginalSt(), ainfo.fieldID ? ainfo.ae->GetOriginalSt().GetTyIdx() : tyIdx, + newOst = ssaTab.FindOrCreateExtraLevOriginalSt( + ainfo.ae->GetOst(), ainfo.fieldID ? ainfo.ae->GetOriginalSt().GetTyIdx() : tyIdx, fieldId + ainfo.fieldID); } CHECK_FATAL(newOst != nullptr, "null ptr check"); @@ -202,7 +202,7 @@ AliasElem *AliasClass::FindOrCreateExtraLevAliasElem(BaseNode &expr, TyIdx tyIdx } AliasElem &AliasClass::FindOrCreateAliasElemOfAddrofOSt(OriginalSt &oSt) { - OriginalSt *addrofOst = GetAliasAnalysisTable()->FindOrCreateAddrofSymbolOriginalSt(oSt); + OriginalSt *addrofOst = ssaTab.FindOrCreateAddrofSymbolOriginalSt(&oSt); if (addrofOst->GetIndex() == osym2Elem.size()) { osym2Elem.push_back(nullptr); } @@ -217,12 +217,14 @@ AliasElem &AliasClass::FindOrCreateAliasElemOfAddrofZeroFieldIDOSt(OriginalSt &o } (void)FindOrCreateAliasElem(*zeroFieldIDOst); - OriginalSt *addrofOst = GetAliasAnalysisTable()->FindOrCreateAddrofSymbolOriginalSt(*zeroFieldIDOst); - auto ret = GetAliasAnalysisTable()->prevLevelNode.insert(std::make_pair(ost.GetIndex(), addrofOst)); + OriginalSt *addrofOst = ssaTab.FindOrCreateAddrofSymbolOriginalSt(zeroFieldIDOst); // if ost's preLevelNode has not been set before, we should also add ost to addrofOst's nextLevelNodes // Otherwise, we should skip here to avoid repetition in nextLevelNodes. - if (ret.second) { - GetAliasAnalysisTable()->GetNextLevelNodes(*addrofOst)->push_back(&ost); + if (ost.GetPrevLevelOst() == nullptr) { + ost.SetPrevLevelOst(addrofOst); + addrofOst->AddNextLevelOst(&ost); + } else { + ASSERT(ost.GetPrevLevelOst() == addrofOst, "prev-level-ost inconsistent"); } if (addrofOst->GetIndex() == osym2Elem.size()) { osym2Elem.push_back(nullptr); @@ -242,7 +244,7 @@ AliasInfo AliasClass::CreateAliasElemsExpr(BaseNode &expr) { } case OP_dread: { OriginalSt *ost = static_cast(expr).GetSSAVar()->GetOst(); - if (ost->GetFieldID() != 0) { + if (ost->GetFieldID() != 0 && ost->GetPrevLevelOst() == nullptr) { (void)FindOrCreateAliasElemOfAddrofZeroFieldIDOSt(*ost); } @@ -497,13 +499,13 @@ void AliasClass::CreateMirroringAliasElems(const OriginalSt *ost1, OriginalSt *o if (ost1->IsSameSymOrPreg(ost2)) { return; } - MapleVector *nextLevelNodes = GetAliasAnalysisTable()->GetNextLevelNodes(*ost1); - MapleVector::iterator it = nextLevelNodes->begin(); - for (; it != nextLevelNodes->end(); ++it) { + auto &nextLevelNodes = ost1->GetNextLevelOsts(); + auto it = nextLevelNodes.begin(); + for (; it != nextLevelNodes.end(); ++it) { OriginalSt *nextLevelOst1 = *it; AliasElem *ae1 = FindOrCreateAliasElem(*nextLevelOst1); - OriginalSt *nextLevelOst2 = GetAliasAnalysisTable()->FindOrCreateExtraLevOriginalSt( - *ost2, ost2->GetTyIdx(), nextLevelOst1->GetFieldID()); + OriginalSt *nextLevelOst2 = ssaTab.FindOrCreateExtraLevOriginalSt( + ost2, ost2->GetTyIdx(), nextLevelOst1->GetFieldID()); if (nextLevelOst2->GetIndex() == osym2Elem.size()) { osym2Elem.push_back(nullptr); ssaTab.GetVersionStTable().CreateZeroVersionSt(nextLevelOst2); @@ -689,14 +691,11 @@ void AliasClass::DumpAssignSets() { } } -bool AliasClass::IsPointedTo(OriginalSt &oSt) { - return GetAliasAnalysisTable()->GetPrevLevelNode(oSt) != nullptr; -} - void AliasClass::UnionAllPointedTos() { std::vector pointedTos; for (auto *aliasElem : id2Elem) { - if (IsPointedTo(aliasElem->GetOriginalSt())) { + // OriginalSt is pointed to by another OriginalSt + if (aliasElem->GetOriginalSt().GetPrevLevelOst() != nullptr) { aliasElem->SetNotAllDefsSeen(true); pointedTos.push_back(aliasElem); } @@ -711,10 +710,10 @@ void AliasClass::ApplyUnionForPointedTos() { bool change = false; for (AliasElem *aliaselem : id2Elem) { if (aliaselem->IsNextLevNotAllDefsSeen()) { - MapleVector *nextLevelNodes = - GetAliasAnalysisTable()->GetNextLevelNodes(aliaselem->GetOriginalSt()); - MapleVector::iterator ostit = nextLevelNodes->begin(); - for (; ostit != nextLevelNodes->end(); ++ostit) { + MapleVector &nextLevelNodes = + aliaselem->GetOriginalSt().GetNextLevelOsts(); + auto ostit = nextLevelNodes.begin(); + for (; ostit != nextLevelNodes.end(); ++ostit) { AliasElem *indae = FindAliasElem(**ostit); if (!indae->GetOriginalSt().IsFinal() && !indae->IsNotAllDefsSeen()) { indae->SetNotAllDefsSeen(true); @@ -728,10 +727,9 @@ void AliasClass::ApplyUnionForPointedTos() { if (change) { for (AliasElem *aliaselem : id2Elem) { if (aliaselem->IsNextLevNotAllDefsSeen()) { - MapleVector *nextLevelNodes = - GetAliasAnalysisTable()->GetNextLevelNodes(aliaselem->GetOriginalSt()); - MapleVector::iterator ostit = nextLevelNodes->begin(); - for (; ostit != nextLevelNodes->end(); ++ostit) { + const auto &nextLevelNodes = aliaselem->GetOriginalSt().GetNextLevelOsts(); + auto ostit = nextLevelNodes.begin(); + for (; ostit != nextLevelNodes.end(); ++ostit) { AliasElem *indae = FindAliasElem(**ostit); if (!indae->GetOriginalSt().IsFinal() && !indae->IsNotAllDefsSeen()) { indae->SetNotAllDefsSeen(true); @@ -764,9 +762,9 @@ void AliasClass::ApplyUnionForPointedTos() { for (auto setit = aliaselem->GetAssignSet()->begin(); setit != aliaselem->GetAssignSet()->end(); ++setit) { AliasElem *ae0 = id2Elem[*setit]; - MapleVector *nextLevelNodes = GetAliasAnalysisTable()->GetNextLevelNodes(ae0->GetOriginalSt()); - MapleVector::iterator ostit = nextLevelNodes->begin(); - for (; ostit != nextLevelNodes->end(); ++ostit) { + MapleVector &nextLevelNodes = ae0->GetOriginalSt().GetNextLevelOsts(); + auto ostit = nextLevelNodes.begin(); + for (; ostit != nextLevelNodes.end(); ++ostit) { AliasElem *indae = FindAliasElem(**ostit); if (!indae->GetOriginalSt().IsFinal()) { indae->SetNotAllDefsSeen(true); @@ -788,15 +786,15 @@ void AliasClass::ApplyUnionForPointedTos() { (void)tempset.erase(pickit); for (MapleSet::iterator setit = tempset.begin(); setit != tempset.end(); ++setit) { AliasElem *ae2 = id2Elem[*setit]; - MapleVector *nextLevelNodes1 = GetAliasAnalysisTable()->GetNextLevelNodes(ae1->GetOriginalSt()); - MapleVector::iterator ost1it = nextLevelNodes1->begin(); - for (; ost1it != nextLevelNodes1->end(); ++ost1it) { + auto &nextLevelNodes1 = ae1->GetOriginalSt().GetNextLevelOsts(); + auto ost1it = nextLevelNodes1.begin(); + for (; ost1it != nextLevelNodes1.end(); ++ost1it) { MIRType *mirType1 = GlobalTables::GetTypeTable().GetTypeFromTyIdx((*ost1it)->GetTyIdx()); bool ost1IsAgg = mirType1->GetPrimType() == PTY_agg; - MapleVector *nextLevelNodes2 = GetAliasAnalysisTable()->GetNextLevelNodes(ae2->GetOriginalSt()); - MapleVector::iterator ost2it = nextLevelNodes2->begin(); - for (; ost2it != nextLevelNodes2->end(); ++ost2it) { + auto &nextLevelNodes2 = ae2->GetOriginalSt().GetNextLevelOsts(); + auto ost2it = nextLevelNodes2.begin(); + for (; ost2it != nextLevelNodes2.end(); ++ost2it) { bool hasFieldid0 = (*ost1it)->GetFieldID() == 0 || (*ost2it)->GetFieldID() == 0; MIRType *mirType2 = GlobalTables::GetTypeTable().GetTypeFromTyIdx((*ost2it)->GetTyIdx()); bool ost2IsAgg = mirType2->GetPrimType() == PTY_agg; @@ -819,7 +817,7 @@ void AliasClass::ApplyUnionForPointedTos() { void AliasClass::CollectRootIDOfNextLevelNodes(const OriginalSt &ost, std::set &rootIDOfNADSs) { - for (OriginalSt *nextLevelNode : *(GetAliasAnalysisTable()->GetNextLevelNodes(ost))) { + for (OriginalSt *nextLevelNode : ost.GetNextLevelOsts()) { if (!nextLevelNode->IsFinal()) { uint32 id = FindAliasElem(*nextLevelNode)->GetClassID(); (void)rootIDOfNADSs.insert(unionFind.Root(id)); @@ -904,7 +902,7 @@ void AliasClass::UnionForNotAllDefsSeenCLang() { bool hasNotAllDefsSeen = ae->IsNotAllDefsSeen() || ostOfAe->GetMIRSymbol()->GetStorageClass() == kScFormal; if (!hasNotAllDefsSeen) { // see if any at level 1 has notAllDefsSeen set - for (OriginalSt *nextLevelNode : *GetAliasAnalysisTable()->GetNextLevelNodes(*ost)) { + for (OriginalSt *nextLevelNode : ost->GetNextLevelOsts()) { ae = osym2Elem[nextLevelNode->GetIndex()]; if (ae != nullptr && ae->IsNotAllDefsSeen()) { hasNotAllDefsSeen = true; @@ -914,7 +912,7 @@ void AliasClass::UnionForNotAllDefsSeenCLang() { } if (hasNotAllDefsSeen) { // set to true for all members at this level - for (OriginalSt *nextLevelNode : *GetAliasAnalysisTable()->GetNextLevelNodes(*ost)) { + for (OriginalSt *nextLevelNode : ost->GetNextLevelOsts()) { AliasElem *nextLevAE = osym2Elem[nextLevelNode->GetIndex()]; if (nextLevAE != nullptr) { nextLevAE->SetNotAllDefsSeen(true); @@ -1001,23 +999,20 @@ void AliasClass::ApplyUnionForStorageOverlaps() { } // work on the next indirect level - auto nextLevOsts = GetAliasAnalysisTable()->GetNextLevelNodes(*ost); - if (nextLevOsts == nullptr) { - continue; - } + auto &nextLevOsts = ost->GetNextLevelOsts(); MIRType *pointedType = static_cast(mirType)->GetPointedType(); if (pointedType->GetKind() == kTypeUnion) { // union all fields of union - UnionAllNodes(nextLevOsts); + UnionAllNodes(&nextLevOsts); continue; } - for (auto *nextLevOst : *nextLevOsts) { + for (auto *nextLevOst : nextLevOsts) { MIRType *nextLevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(nextLevOst->GetTyIdx()); if (nextLevType->HasFields()) { // union all fields if one next-level-ost has fields - UnionAllNodes(nextLevOsts); + UnionAllNodes(&nextLevOsts); break; } } @@ -1097,9 +1092,9 @@ bool AliasClass::AliasAccordingToFieldID(const OriginalSt &ostA, const OriginalS return true; } MIRType *mirTypeA = - GlobalTables::GetTypeTable().GetTypeFromTyIdx(GetAliasAnalysisTable()->GetPrevLevelNode(ostA)->GetTyIdx()); + GlobalTables::GetTypeTable().GetTypeFromTyIdx(ostA.GetPrevLevelOst()->GetTyIdx()); MIRType *mirTypeB = - GlobalTables::GetTypeTable().GetTypeFromTyIdx(GetAliasAnalysisTable()->GetPrevLevelNode(ostB)->GetTyIdx()); + GlobalTables::GetTypeTable().GetTypeFromTyIdx(ostB.GetPrevLevelOst()->GetTyIdx()); TyIdx idxA = mirTypeA->GetTypeIndex(); TyIdx idxB = mirTypeB->GetTypeIndex(); FieldID fldA = ostA.GetFieldID(); @@ -1118,8 +1113,7 @@ void AliasClass::ProcessIdsAliasWithRoot(const std::set &idsAliasW for (unsigned int idB : newGroups) { OriginalSt &ostA = id2Elem[idA]->GetOriginalSt(); OriginalSt &ostB = id2Elem[idB]->GetOriginalSt(); - if (AliasAccordingToType(GetAliasAnalysisTable()->GetPrevLevelNode(ostA)->GetTyIdx(), - GetAliasAnalysisTable()->GetPrevLevelNode(ostB)->GetTyIdx()) && + if (AliasAccordingToType(ostA.GetPrevLevelOst()->GetTyIdx(), ostB.GetPrevLevelOst()->GetTyIdx()) && AliasAccordingToFieldID(ostA, ostB)) { unionFind.Union(idA, idB); unioned = true; @@ -1162,9 +1156,9 @@ void AliasClass::UnionNextLevelOfAliasOst() { uint32 rootID = unionFind.Root(id); if (id != rootID) { auto &ost = aliasElem->GetOriginalSt(); - auto *nextLevelOsts = GetAliasAnalysisTable()->GetNextLevelNodes(ost); + auto &nextLevelOsts = ost.GetNextLevelOsts(); (void)rootId2AliasedOsts[rootID].insert( - rootId2AliasedOsts[rootID].end(), nextLevelOsts->begin(), nextLevelOsts->end()); + rootId2AliasedOsts[rootID].end(), nextLevelOsts.begin(), nextLevelOsts.end()); } } for (auto &rootIdPair : rootId2AliasedOsts) { @@ -1173,8 +1167,8 @@ void AliasClass::UnionNextLevelOfAliasOst() { continue; } auto &rootOst = id2Elem[rootIdPair.first]->GetOriginalSt(); - auto *nextLevelOstOfRoot = GetAliasAnalysisTable()->GetNextLevelNodes(rootOst); - (void)nextLevelOsts.insert(nextLevelOsts.end(), nextLevelOstOfRoot->begin(), nextLevelOstOfRoot->end()); + auto &nextLevelOstOfRoot = rootOst.GetNextLevelOsts(); + (void)nextLevelOsts.insert(nextLevelOsts.end(), nextLevelOstOfRoot.begin(), nextLevelOstOfRoot.end()); for (uint32 idA = 0; idA < nextLevelOsts.size(); ++idA) { auto *ostA = nextLevelOsts[idA]; @@ -1246,6 +1240,49 @@ void AliasClass::DumpClassSets() { } } +bool AliasClass::MayAliasBasicAA(const OriginalSt *ostA, const OriginalSt *ostB) { + if (ostA == ostB) { + return true; + } + + auto indirectLevA = ostA->GetIndirectLev(); + auto indirectLevB = ostB->GetIndirectLev(); + // address of var has no alias relation + if (indirectLevA < 0 || indirectLevB < 0) { + return false; + } + + // basicAA cannot analysis alias relation of virtual-var + if (indirectLevA > 0 || indirectLevB > 0) { + return true; + } + + // indirectLevA == 0 && indirectLevB == 0 + // different zero-level-var not alias each other + if (ostA->GetMIRSymbol() != ostB->GetMIRSymbol()) { + return false; + } + + // field of union alias with each other + if (ostA->GetMIRSymbol()->GetType()->GetKind() == kTypeUnion) { + return true; + } + + FieldID fieldIdA = ostA->GetFieldID(); + FieldID fieldIdB = ostB->GetFieldID(); + if (fieldIdA == 0 || fieldIdB == 0 || fieldIdA == fieldIdB) { + return true; + } + + auto typeA = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ostA->GetTyIdx()); + uint32 fieldNumOfOstA = typeA->NumberOfFieldIDs(); + + auto typeB = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ostB->GetTyIdx()); + uint32 fieldNumOfOstB = typeB->NumberOfFieldIDs(); + // ostA and ostB overlaps with each other in memory + return (fieldIdA <= fieldIdB + fieldNumOfOstB) && (fieldIdB <= fieldIdA + fieldNumOfOstA); +} + // here starts pass 2 code void AliasClass::InsertMayUseExpr(BaseNode &expr) { for (size_t i = 0; i < expr.NumOpnds(); ++i) { @@ -1300,7 +1337,7 @@ void AliasClass::CollectMayUseFromDefinedFinalField(std::set &mayUs continue; } - auto *prevLevelOst = aliasAnalysisTable->GetPrevLevelNode(ost); + auto *prevLevelOst = ost.GetPrevLevelOst(); if (prevLevelOst == nullptr) { continue; } @@ -1344,7 +1381,7 @@ void AliasClass::InsertMayUseReturn(const StmtNode &stmt) { // collect next_level_nodes of the ost of ReturnOpnd into mayUseOsts void AliasClass::CollectPtsToOfReturnOpnd(const OriginalSt &ost, std::set &mayUseOsts) { - for (OriginalSt *nextLevelOst : *(GetAliasAnalysisTable()->GetNextLevelNodes(ost))) { + for (OriginalSt *nextLevelOst : ost.GetNextLevelOsts()) { AliasElem *aliasElem = FindAliasElem(*nextLevelOst); if (!aliasElem->IsNotAllDefsSeen() && !aliasElem->GetOriginalSt().IsFinal()) { if (aliasElem->GetClassSet() == nullptr) { @@ -1403,8 +1440,6 @@ void AliasClass::CollectMayDefForDassign(const StmtNode &stmt, std::setGetOriginalSt(); FieldID fldIDA = ostOfLhsAe->GetFieldID(); - MIRType *lhsAeType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ostOfLhsAe->GetTyIdx()); - MIRType *lhsSymType = ostOfLhsAe->GetMIRSymbol()->GetType(); for (uint elemId : *(lhsAe->GetClassSet())) { if (elemId == lhsAe->GetClassID()) { continue; @@ -1419,29 +1454,8 @@ void AliasClass::CollectMayDefForDassign(const StmtNode &stmt, std::setIsSameSymOrPreg(ostOfLhsAe) && - fldIDA != fldIDB && - lhsSymType->GetKind() != kTypeUnion) { - MIRType *aliasAeType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ostOfAliasAe->GetTyIdx()); - if (!lhsAeType->HasFields() && !aliasAeType->HasFields()) { - continue; - } - if (lhsAeType->HasFields()) { - if ((fldIDB < fldIDA) || - (fldIDB > (fldIDA + static_cast(lhsAeType->NumberOfFieldIDs())))) { - if (!aliasAeType->HasFields()) { - continue; - } - } - } - if (aliasAeType->HasFields()) { - if (fldIDA < fldIDB || - fldIDA > (fldIDB + static_cast(aliasAeType->NumberOfFieldIDs()))) { - if (!lhsAeType->HasFields()) { - continue; - } - } - } + if (!MayAliasBasicAA(ostOfAliasAe, ostOfAliasAe)) { + continue; } (void)mayDefOsts.insert(ostOfAliasAe); } @@ -1487,7 +1501,7 @@ void AliasClass::CollectMayDefForIassign(StmtNode &stmt, std::set & OriginalSt &ostOfBaseExpr = baseAinfo.ae->GetOriginalSt(); TyIdx tyIdxOfBaseOSt = ostOfBaseExpr.GetTyIdx(); FieldID fldOfIass = iassignNode.GetFieldID() + baseAinfo.fieldID; - for (OriginalSt *nextLevelNode : *(GetAliasAnalysisTable()->GetNextLevelNodes(ostOfBaseExpr))) { + for (OriginalSt *nextLevelNode : ostOfBaseExpr.GetNextLevelOsts()) { FieldID fldOfNextLevelOSt = nextLevelNode->GetFieldID(); if (IsEquivalentField(tyIdxOfIass, fldOfIass, tyIdxOfBaseOSt, fldOfNextLevelOSt)) { lhsOst = nextLevelNode; @@ -1509,7 +1523,6 @@ void AliasClass::CollectMayDefForIassign(StmtNode &stmt, std::set & } OriginalSt *ostOfLhsAe = &lhsAe->GetOriginalSt(); TyIdx pointedTyIdx = ostOfLhsAe->GetTyIdx(); - MIRType *lhsAeType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointedTyIdx); for (unsigned int elemID : *(lhsAe->GetClassSet())) { AliasElem *aliasElem = id2Elem[elemID]; OriginalSt &ostOfAliasAE = aliasElem->GetOriginalSt(); @@ -1521,26 +1534,8 @@ void AliasClass::CollectMayDefForIassign(StmtNode &stmt, std::set & continue; } } else { - if (ostOfAliasAE.IsSameSymOrPreg(ostOfLhsAe) && - ostOfAliasAE.GetFieldID() != ostOfLhsAe->GetFieldID() && - ostOfAliasAE.GetFieldID() != 0 && ostOfLhsAe->GetFieldID() != 0) { - MIRType *aliasAeType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ostOfAliasAE.GetTyIdx()); - if (!lhsAeType->HasFields() && !aliasAeType->HasFields()) { - continue; - } - if (lhsAeType->HasFields()) { - if ((ostOfAliasAE.GetFieldID() < ostOfLhsAe->GetFieldID()) || - (ostOfAliasAE.GetFieldID() > - (ostOfLhsAe->GetFieldID() + static_cast(lhsAeType->NumberOfFieldIDs())))) { - continue; - } - } else { - if ((ostOfLhsAe->GetFieldID() < ostOfAliasAE.GetFieldID()) || - (ostOfLhsAe->GetFieldID() > - (ostOfAliasAE.GetFieldID() + static_cast(aliasAeType->NumberOfFieldIDs())))) { - continue; - } - } + if (!MayAliasBasicAA(ostOfLhsAe, &ostOfAliasAE)) { + continue; } } (void)mayDefOsts.insert(&ostOfAliasAE); @@ -1577,7 +1572,7 @@ void AliasClass::InsertMayDefIassign(StmtNode &stmt, BBId bbid) { MayDefNode &mayDef = *it; OriginalSt *ost = mayDef.GetResult()->GetOst(); if (ost->GetIndirectLev() == 1) { - mayDef.base = ssaTab.GetVersionStTable().GetZeroVersionSt(GetAliasAnalysisTable()->GetPrevLevelNode(*ost)); + mayDef.base = ssaTab.GetVersionStTable().GetZeroVersionSt(ost->GetPrevLevelOst()); } } } @@ -1595,7 +1590,7 @@ void AliasClass::InsertMayDefUseSyncOps(StmtNode &stmt, BBId bbid) { aliasSet.insert(opndAE->GetClassSet()->cbegin(), opndAE->GetClassSet()->cend()); } } else { - for (OriginalSt *nextLevelOst : *(GetAliasAnalysisTable()->GetNextLevelNodes(*oSt))) { + for (OriginalSt *nextLevelOst : oSt->GetNextLevelOsts()) { AliasElem *opndAE = osym2Elem[nextLevelOst->GetIndex()]; if (opndAE->GetClassSet() != nullptr) { aliasSet.insert(opndAE->GetClassSet()->cbegin(), opndAE->GetClassSet()->cend()); @@ -1663,7 +1658,7 @@ void AliasClass::CollectMayDefForMustDefs(const StmtNode &stmt, std::set &mayUseOsts, const StmtNode &stmt, bool isFirstOpnd) { - for (OriginalSt *nextLevelOst : *(GetAliasAnalysisTable()->GetNextLevelNodes(*ost))) { + for (OriginalSt *nextLevelOst : ost->GetNextLevelOsts()) { AliasElem *indAe = FindAliasElem(*nextLevelOst); if (indAe->GetOriginalSt().IsFinal()) { diff --git a/src/mapleall/maple_me/src/irmap_emit.cpp b/src/mapleall/maple_me/src/irmap_emit.cpp index 8b82ec408b1bfaab26fa8e9921e281798cfe5db4..c03282e655a4f2517f880136671d5bdfcfa263ed 100644 --- a/src/mapleall/maple_me/src/irmap_emit.cpp +++ b/src/mapleall/maple_me/src/irmap_emit.cpp @@ -615,5 +615,4 @@ void BB::EmitBB(SSATab &ssaTab, BlockNode &curblk, bool needAnotherPass) { stmtNodeList.set_first(bbFirstStmt); stmtNodeList.set_last(bbLastStmt); } - } // namespace maple diff --git a/src/mapleall/maple_me/src/orig_symbol.cpp b/src/mapleall/maple_me/src/orig_symbol.cpp index fb3603d2eba226ffe945238fa3b9cd09de00e1a3..0a1153c5a410db8f18324ba3b95bb775f249f6d1 100644 --- a/src/mapleall/maple_me/src/orig_symbol.cpp +++ b/src/mapleall/maple_me/src/orig_symbol.cpp @@ -13,6 +13,7 @@ * See the Mulan PSL v2 for more details. */ #include "orig_symbol.h" +#include "class_hierarchy.h" namespace maple { bool OriginalSt::Equal(const OriginalSt &ost) const { @@ -121,4 +122,87 @@ OriginalSt *OriginalStTable::FindSymbolOriginalSt(MIRSymbol &mirst) { CHECK_FATAL(it->second < originalStVector.size(), "index out of range in OriginalStTable::FindSymbolOriginalSt"); return originalStVector[it->second]; } + +OriginalSt *OriginalStTable::FindOrCreateAddrofSymbolOriginalSt(OriginalSt *ost) { + if (ost->GetPrevLevelOst() != nullptr) { + return ost->GetPrevLevelOst(); + } + // create a new node + OriginalSt *prevLevelOst = alloc.GetMemPool()->New( + originalStVector.size(), *ost->GetMIRSymbol(), ost->GetPuIdx(), 0, alloc); + originalStVector.push_back(prevLevelOst); + prevLevelOst->SetIndirectLev(-1); + MIRPtrType pointType(ost->GetMIRSymbol()->GetTyIdx(), PTY_ptr); + TyIdx newTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&pointType); + prevLevelOst->SetTyIdx(newTyIdx); + prevLevelOst->SetFieldID(0); + ost->SetPrevLevelOst(prevLevelOst); + prevLevelOst->AddNextLevelOst(ost); + return prevLevelOst; +} + +OriginalSt *OriginalStTable::FindOrCreateExtraLevSymOrRegOriginalSt(OriginalSt *ost, TyIdx tyIdx, + FieldID fld, const KlassHierarchy *klassHierarchy) { + TyIdx ptyIdxOfOst = ost->GetTyIdx(); + FieldID fldIDInOst = fld; + if (ptyIdxOfOst != tyIdx && klassHierarchy != nullptr) { + (void)klassHierarchy->UpdateFieldID(tyIdx, ptyIdxOfOst, fldIDInOst); + } + auto nextLevelOsts = ost->GetNextLevelOsts(); + OriginalSt *nextLevOst = FindExtraLevOriginalSt(nextLevelOsts, fldIDInOst); + if (nextLevOst != nullptr) { + return nextLevOst; + } + + // create a new node + if (ost->IsSymbolOst()) { + nextLevOst = alloc.GetMemPool()->New(originalStVector.size(), *ost->GetMIRSymbol(), + ost->GetPuIdx(), fldIDInOst, alloc); + } else { + nextLevOst = alloc.GetMemPool()->New(originalStVector.size(), ost->GetPregIdx(), + ost->GetPuIdx(), alloc); + } + originalStVector.push_back(nextLevOst); + CHECK_FATAL(ost->GetIndirectLev() < INT8_MAX, "boundary check"); + nextLevOst->SetIndirectLev(ost->GetIndirectLev() + 1); + nextLevOst->SetPrevLevelOst(ost); + tyIdx = (tyIdx == 0u) ? ost->GetTyIdx() : tyIdx; + if (tyIdx != 0u) { + // use the tyIdx info from the instruction + const MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); + if (mirType->GetKind() == kTypePointer) { + const auto *ptType = static_cast(mirType); + TyIdxFieldAttrPair fieldPair = ptType->GetPointedTyIdxFldAttrPairWithFieldID(fld); + nextLevOst->SetTyIdx(fieldPair.first); + nextLevOst->SetIsFinal(fieldPair.second.GetAttr(FLDATTR_final)); + nextLevOst->SetIsPrivate(fieldPair.second.GetAttr(FLDATTR_private)); + } else { + nextLevOst->SetTyIdx(TyIdx(PTY_void)); + } + } + ASSERT(!GlobalTables::GetTypeTable().GetTypeTable().empty(), "container check"); + if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(ost->GetTyIdx())->PointsToConstString()) { + nextLevOst->SetIsFinal(true); + } + ost->AddNextLevelOst(nextLevOst); + return nextLevOst; +} + +OriginalSt *OriginalStTable::FindOrCreateExtraLevOriginalSt(OriginalSt *ost, + TyIdx ptyIdx, FieldID fld) { + if (ost->IsSymbolOst() || ost->IsPregOst()) { + return FindOrCreateExtraLevSymOrRegOriginalSt(ost, ptyIdx, fld); + } + return nullptr; +} + +OriginalSt *OriginalStTable::FindExtraLevOriginalSt(const MapleVector &nextLevelOsts, + FieldID fld) { + for (OriginalSt *nextLevelOst : nextLevelOsts) { + if (nextLevelOst->GetFieldID() == fld) { + return nextLevelOst; + } + } + return nullptr; +} } // namespace maple