diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index e31b636fe5462a07668d36afacf4b9675633e90e..d08a5c3a85e60b33fabd818055592c4bf8b18050 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index e15a3bd8a7fef98693724af08bea949c10db5ebc..b2ae281b2f91d7c5e40d5a1102f177a826b882dc 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h index 94c0ad07693e1eda7b5f572c40338cacab8ed8a3..25b6343fb03ccbbbf12bf5513b9525aa191e3597 100644 --- a/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -311,7 +311,7 @@ class AArch64CGFunc : public CGFunc { bool NeedCleanup() override; void GenerateCleanupCodeForExtEpilog(BB &bb) override; Operand *GetBaseReg(const AArch64SymbolAlloc &symAlloc); - uint32 GetBaseOffset(const SymbolAlloc &symAlloc) override; + int32 GetBaseOffset(const SymbolAlloc &symAlloc) override; Operand &CreateCommentOperand(const std::string &s) { return *memPool->New(s, *memPool); @@ -557,8 +557,7 @@ class AArch64CGFunc : public CGFunc { Operand *SelectRoundOperator(RoundType roundType, const TypeCvtNode &node, Operand &opnd0); int64 GetOrCreatSpillRegLocation(regno_t vrNum) { AArch64SymbolAlloc *symLoc = static_cast(GetMemlayout()->GetLocOfSpillRegister(vrNum)); - int64 offset = GetBaseOffset(*symLoc); - return offset; + return static_cast(GetBaseOffset(*symLoc)); } void SelectCopyMemOpnd(Operand &dest, PrimType dtype, uint32 dsize, Operand &src, PrimType stype); diff --git a/src/maple_be/include/cg/cg_phases.def b/src/maple_be/include/cg/cg_phases.def index 462db1d0f1b812af4f005137425113ec16ff0309..21ed5e2f0f965b907bb5c5cca57b0e9df0067ccd 100644 --- a/src/maple_be/include/cg/cg_phases.def +++ b/src/maple_be/include/cg/cg_phases.def @@ -18,10 +18,10 @@ FUNCTPHASE(kCGFuncPhaseLAYOUTSF, CgDoLayoutSF) FUNCTPHASE(kCGFuncPhaseCREATESELABEL, CgDoCreateLabel) FUNCTPHASE(kCGFuncPhaseBUILDEHFUNC, CgDoBuildEHFunc) FUNCTPHASE(kCGFuncPhaseHANDLEFUNC, CgDoHandleFunc) -FUNCTPHASE(kCGFuncPhaesREGALLOC, CgDoRegAlloc) -FUNCTPHASE(kCGFuncPhaesMOVREGARGS, CgDoMoveRegArgs) -FUNCTPHASE(kCGFuncPhaesGENPROEPILOG, CgDoGenProEpiLog) -FUNCTPHASE(kCGFuncPhaesOFFADJFPLR, CgDoFPLROffsetAdjustment) -FUNCTPHASE(kCGFuncPhaesGENCFI, CgDoGenCfi) -FUNCTPHASE(kCGFuncPhaesYIELDPOINT, CgYieldPointInsertion) -FUNCTPHASE(kCGFuncPhaesEMIT, CgDoEmission) +FUNCTPHASE(kCGFuncPhaseREGALLOC, CgDoRegAlloc) +FUNCTPHASE(kCGFuncPhaseMOVREGARGS, CgDoMoveRegArgs) +FUNCTPHASE(kCGFuncPhaseGENPROEPILOG, CgDoGenProEpiLog) +FUNCTPHASE(kCGFuncPhaseOFFADJFPLR, CgDoFPLROffsetAdjustment) +FUNCTPHASE(kCGFuncPhaseGENCFI, CgDoGenCfi) +FUNCTPHASE(kCGFuncPhaseYIELDPOINT, CgYieldPointInsertion) +FUNCTPHASE(kCGFuncPhaseEMIT, CgDoEmission) diff --git a/src/maple_be/include/cg/cgfunc.h b/src/maple_be/include/cg/cgfunc.h index 55e7e655a0d1a239e89b57a2e7dbc18cea277b6d..b9c5384562beba4a599340b0ff51309bba80e7d3 100644 --- a/src/maple_be/include/cg/cgfunc.h +++ b/src/maple_be/include/cg/cgfunc.h @@ -231,7 +231,7 @@ class CGFunc { virtual RegOperand &GetOrCreateVirtualRegisterOperand(regno_t vRegNO) = 0; virtual RegOperand &GetOrCreateFramePointerRegOperand() = 0; virtual RegOperand &GetOrCreateStackBaseRegOperand() = 0; - virtual uint32 GetBaseOffset(const SymbolAlloc &symbolAlloc) = 0; + virtual int32 GetBaseOffset(const SymbolAlloc &symbolAlloc) = 0; virtual Operand &GetZeroOpnd(uint32 size) = 0; virtual Operand &CreateCfiRegOperand(uint32 reg, uint32 size) = 0; virtual Operand &GetTargetRetOperand(PrimType primType) = 0; @@ -785,7 +785,7 @@ class CGFunc { int64 GetPseudoRegisterSpillLocation(PregIdx idx) { const SymbolAlloc *symLoc = memLayout->GetSpillLocOfPseduoRegister(idx); - return GetBaseOffset(*symLoc); + return static_cast(GetBaseOffset(*symLoc)); } virtual MemOperand *GetPseudoRegisterSpillMemoryOperand(PregIdx idx) = 0; diff --git a/src/maple_be/src/cg/aarch64/aarch64_args.cpp b/src/maple_be/src/cg/aarch64/aarch64_args.cpp index db83fca140fdeebfb6013722f0f239d335837d83..87784959bfc78ee632d6b738e55d9b41c4df3fd2 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_args.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_args.cpp @@ -90,7 +90,7 @@ void AArch64MoveRegArgs::GenerateStpInsn(const ArgInfo &firstArgInfo, const ArgI firstArgInfo.regType); int32 limit = (secondArgInfo.stkSize > k4ByteSize) ? kStpLdpImm64UpperBound : kStpLdpImm32UpperBound; - int32 stOffset = static_cast(aarchCGFunc->GetBaseOffset(*firstArgInfo.symLoc)); + int32 stOffset = aarchCGFunc->GetBaseOffset(*firstArgInfo.symLoc); MemOperand *memOpnd = nullptr; if (stOffset > limit || baseReg != nullptr) { if (baseReg == nullptr || lastSegment != firstArgInfo.symLoc->GetMemSegment()) { @@ -120,7 +120,7 @@ void AArch64MoveRegArgs::GenerateStpInsn(const ArgInfo &firstArgInfo, const ArgI void AArch64MoveRegArgs::GenerateStrInsn(ArgInfo &argInfo) { AArch64CGFunc *aarchCGFunc = static_cast(cgFunc); - int32 stOffset = static_cast(aarchCGFunc->GetBaseOffset(*argInfo.symLoc)); + int32 stOffset = aarchCGFunc->GetBaseOffset(*argInfo.symLoc); AArch64RegOperand *baseOpnd = static_cast(aarchCGFunc->GetBaseReg(*argInfo.symLoc)); RegOperand ®Opnd = aarchCGFunc->GetOrCreatePhysicalRegisterOperand(argInfo.reg, argInfo.stkSize * kBitsPerByte, argInfo.regType); diff --git a/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 6b2f72ea1f1bc2483cfd4e9fd894758b98f67729..98a7721ec06914388a2343a551d84c036fa7341f 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -5493,7 +5493,7 @@ Operand *AArch64CGFunc::GetBaseReg(const AArch64SymbolAlloc &symAlloc) { return fsp; } -uint32 AArch64CGFunc::GetBaseOffset(const SymbolAlloc &sa) { +int32 AArch64CGFunc::GetBaseOffset(const SymbolAlloc &sa) { const AArch64SymbolAlloc *symAlloc = static_cast(&sa); /* Call Frame layout of AArch64 * Refer to V2 in aarch64_memlayout.h. @@ -5503,7 +5503,7 @@ uint32 AArch64CGFunc::GetBaseOffset(const SymbolAlloc &sa) { MemSegmentKind sgKind = symAlloc->GetMemSegment()->GetMemSegmentKind(); AArch64MemLayout *memLayout = static_cast(this->GetMemlayout()); if (sgKind == kMsArgsStkPassed) { /* for callees */ - uint32 offset = symAlloc->GetOffset(); + int32 offset = static_cast(symAlloc->GetOffset()); return offset; } else if (sgKind == kMsArgsRegPassed) { int32 baseOffset = memLayout->GetSizeOfLocals() + symAlloc->GetOffset() + memLayout->GetSizeOfRefLocals(); @@ -5519,7 +5519,7 @@ uint32 AArch64CGFunc::GetBaseOffset(const SymbolAlloc &sa) { memLayout->GetSizeOfRefLocals(); return baseOffset + sizeofFplr; } else if (sgKind == kMsArgsToStkPass) { /* this is for callers */ - return static_cast(symAlloc->GetOffset()); + return static_cast(symAlloc->GetOffset()); } else { CHECK_FATAL(false, "sgKind check"); } diff --git a/src/maple_be/src/cg/aarch64/aarch64_color_ra.cpp b/src/maple_be/src/cg/aarch64/aarch64_color_ra.cpp index 9f158ecf367182bfb6df1205b0cf0ee9b644e260..64787fa1010ed9534a26101d3662919c4d217971 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_color_ra.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_color_ra.cpp @@ -765,6 +765,7 @@ void GraphColorRegAllocator::ComputeLiveRangesForEachDefOperand(Insn &insn, bool ASSERT(numUses == 0, "should only be def opnd"); if (numDefs > 1) { multiDef = true; + needExtraSpillReg = true; } } @@ -2547,18 +2548,28 @@ MemOperand *GraphColorRegAllocator::GetSpillOrReuseMem(LiveRange &lr, uint32 reg lr.SetSpillSize((regSize <= k32) ? k32 : k64); } else { #endif /* REUSE_SPILLMEM */ - regno_t baseRegNO = kRinvalid; - MapleSet &spillRegSet = intSpillRegSet; - regno_t basis = R0; - for (auto reg : spillRegSet) { - if (isDef && (reg + basis) == lr.GetSpillReg()) { - continue; - } - baseRegNO = (reg + basis); - break; + regno_t baseRegNO; + if (!isDef) { + /* src will use its' spill reg as baseRegister when offset out-of-range + * add x16, x29, #max-offset //out-of-range + * ldr x16, [x16, #offset] //reload + * mov xd, x16 + */ + baseRegNO = lr.GetSpillReg(); + } else { + /* dest will use R17 as baseRegister when offset out-of-range + * mov x16, xs + * add x17, x29, #max-offset //out-of-range + * str x16, [x17, #offset] //spill + */ + baseRegNO = R17; } ASSERT(baseRegNO != kRinvalid, "invalid base register number"); memOpnd = GetSpillMem(lr.GetRegNO(), isDef, insn, static_cast(baseRegNO), isOutOfRange); + /* dest's spill reg can only be R15 and R16 () */ + if (isOutOfRange && isDef) { + ASSERT(lr.GetSpillReg() != R17, "can not find valid memopnd's base register"); + } #ifdef REUSE_SPILLMEM if (isOutOfRange == 0) { lr.SetSpillMem(*memOpnd); diff --git a/src/maple_be/src/cg/aarch64/aarch64_emitter.cpp b/src/maple_be/src/cg/aarch64/aarch64_emitter.cpp index d2dfa2da01537d2541d8d34b8b90f11dc1307ae6..d194bf884db2fb54afe639bf97c132a15bc4a437 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_emitter.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_emitter.cpp @@ -290,6 +290,7 @@ void AArch64Emitter::Run() { emitter.Emit("\t.align 2\n"); MIRSymbol *funcSt = GlobalTables::GetGsymTable().GetSymbolFromStidx(cgFunc->GetFunction().GetStIdx().Idx()); + if (funcSt->GetFunction()->GetAttr(FUNCATTR_weak)) { emitter.Emit("\t.weak\t" + funcSt->GetName() + "\n"); emitter.Emit("\t.hidden\t" + funcSt->GetName() + "\n"); diff --git a/src/maple_be/src/cg/cg_phasemanager.cpp b/src/maple_be/src/cg/cg_phasemanager.cpp index 7db673a17858c402112ed3bdade8db152580edd2..f3e6b93cacd390c0711513da77d151a7d125b806 100644 --- a/src/maple_be/src/cg/cg_phasemanager.cpp +++ b/src/maple_be/src/cg/cg_phasemanager.cpp @@ -41,7 +41,7 @@ void CgFuncPhaseManager::RunFuncPhase(CGFunc &func, FuncPhase &phase) { /* 3. run: skip mplcg phase except "emit" if no cfg in CGFunc */ AnalysisResult *analysisRes = nullptr; - if ((func.NumBBs() > 0) || (phase.GetPhaseID() == kCGFuncPhaesEMIT)) { + if ((func.NumBBs() > 0) || (phase.GetPhaseID() == kCGFuncPhaseEMIT)) { analysisRes = phase.Run(&func, &arFuncManager); phase.ReleaseMemPool(analysisRes == nullptr ? nullptr : analysisRes->GetMempool()); } @@ -107,7 +107,7 @@ void CgFuncPhaseManager::AddPhases(std::vector &phases) { } void CgFuncPhaseManager::Emit(CGFunc &func) { - PhaseID id = kCGFuncPhaesEMIT; + PhaseID id = kCGFuncPhaseEMIT; FuncPhase *funcPhase = static_cast(GetPhase(id)); CHECK_FATAL(funcPhase != nullptr, "p is null in CgFuncPhaseManager::Run"); @@ -147,7 +147,7 @@ void CgFuncPhaseManager::Run(CGFunc &func) { MPLTimer timer; for (auto it = PhaseSequenceBegin(); it != PhaseSequenceEnd(); it++, ++phaseIndex) { PhaseID id = GetPhaseId(it); - if (id == kCGFuncPhaesEMIT) { + if (id == kCGFuncPhaseEMIT) { continue; } FuncPhase *funcPhase = static_cast(GetPhase(id)); diff --git a/src/maple_be/src/cg/emit.cpp b/src/maple_be/src/cg/emit.cpp old mode 100755 new mode 100644 diff --git a/src/maple_ipa/src/callgraph.cpp b/src/maple_ipa/src/callgraph.cpp index fa1933fc5c58dcd84a47761ada9340553c02adeb..35d9de72b69a6473855d7294a891e3a83466ec7f 100644 --- a/src/maple_ipa/src/callgraph.cpp +++ b/src/maple_ipa/src/callgraph.cpp @@ -355,7 +355,7 @@ CGNode *CallGraph::GetOrGenCGNode(PUIdx puIdx, bool isVcall, bool isIcall) { klassVector.push_back(subKlass); } } - if (!klass->GetMIRClassType()->IsAbstract()) { + if (klass->IsClass() && !klass->GetMIRClassType()->IsAbstract()) { // If klass.foo does not exist, search superclass and find the nearest one // klass.foo does not exist auto &klassMethods = klass->GetMethods(); diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index c6166c550a128e09dea8107b2aa338b0a3b7ad91..2796df3369741d5b644bcf678ccce9a10f6e7dce 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -954,6 +954,10 @@ class MIRStructType : public MIRType { CHECK_FATAL(false, "can not use GetInfo"); } + virtual const MIRInfoPair &GetInfoElemt(size_t) const { + CHECK_FATAL(false, "can not use GetInfoElemt"); + } + virtual const std::vector &GetInfoIsString() const { CHECK_FATAL(false, "can not use GetInfoIsString"); } @@ -1088,7 +1092,7 @@ class MIRClassType : public MIRStructType { return info.size(); } - const MIRInfoPair &GetInfoElemt(size_t n) const { + const MIRInfoPair &GetInfoElemt(size_t n) const override { ASSERT(n < info.size(), "array index out of range"); return info.at(n); } @@ -1230,7 +1234,7 @@ class MIRInterfaceType : public MIRStructType { return info.size(); } - const MIRInfoPair &GetInfoElemt(size_t n) const { + const MIRInfoPair &GetInfoElemt(size_t n) const override { ASSERT(n < info.size(), "array index out of range"); return info.at(n); } diff --git a/src/mpl2mpl/include/class_hierarchy.h b/src/mpl2mpl/include/class_hierarchy.h index b2b740d6c22bcb717cc641830bb26a844434d634..c7f9e4409956a8289fa66f8f9a8cab2e0abdb5e0 100644 --- a/src/mpl2mpl/include/class_hierarchy.h +++ b/src/mpl2mpl/include/class_hierarchy.h @@ -103,10 +103,12 @@ class Klass { } MIRClassType *GetMIRClassType() const { + CHECK_FATAL(IsClass() || IsClassIncomplete(), "must"); return static_cast(structType); } MIRInterfaceType *GetMIRInterfaceType() const { + CHECK_FATAL(IsInterface() || IsInterfaceIncomplete(), "must be"); return static_cast(structType); } diff --git a/src/mpl2mpl/include/muid_replacement.h b/src/mpl2mpl/include/muid_replacement.h index 6ac7965e7257b5a2ff8a7b84909d2eb2a8700d93..fa6d62c7f7fb1c33d3908e99230d65c45a4e62cd 100644 --- a/src/mpl2mpl/include/muid_replacement.h +++ b/src/mpl2mpl/include/muid_replacement.h @@ -93,7 +93,7 @@ class MUIDReplacement : public FuncOptimizeImpl { uint32 FindIndexFromUndefTable(const MIRSymbol &mirSymbol, bool isFunc); void ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, bool isVtab); void ReplaceFuncTable(const std::string &name); - void ReplaceAddrofConst(MIRConst *&entry); + void ReplaceAddrofConst(MIRConst *&entry, bool isGlobalRootList = false); void ReplaceDataTable(const std::string &name); void ReplaceDirectInvokeOrAddroffunc(MIRFunction ¤tFunc, StmtNode &stmt); void ReplaceDassign(MIRFunction ¤tFunc, const DassignNode &dassignNode); diff --git a/src/mpl2mpl/include/reflection_analysis.h b/src/mpl2mpl/include/reflection_analysis.h index f157d4f7ff8af822939e7ce719c15e61bb4160ff..dce515ee1ca39e263af8c6a8a11d9a61d8272ce6 100644 --- a/src/mpl2mpl/include/reflection_analysis.h +++ b/src/mpl2mpl/include/reflection_analysis.h @@ -214,14 +214,14 @@ class ReflectionAnalysis : public AnalysisResult { std::unordered_map &baseNameMap, std::unordered_map &fullNameMap); void GenAllFieldHash(std::vector> &fieldV) const; - void GenAnnotation(std::map &idxNumMap, std::string &annoArr, MIRClassType &classType, + void GenAnnotation(std::map &idxNumMap, std::string &annoArr, MIRStructType &classType, PragmaKind paragKind, const std::string ¶gName, TyIdx fieldTypeIdx, std::map *paramNumArray = nullptr, int *paramIndex = nullptr); void AppendValueByType(std::string &annoArr, const MIRPragmaElement &elem); bool IsAnonymousClass(const std::string &annotationString); bool IsPrivateClass(const MIRClassType &classType) const; - bool IsStaticClass(const MIRClassType &classType) const; - int8 JudgePara(MIRClassType &ctype); + bool IsStaticClass(const MIRStructType &classType) const; + int8 JudgePara(MIRStructType &ctype); void CheckPrivateInnerAndNoSubClass(Klass &clazz, const std::string &annoArr); void ConvertMapleClassName(const std::string &mplClassName, std::string &javaDsp); @@ -230,7 +230,7 @@ class ReflectionAnalysis : public AnalysisResult { uint16 GetMethodInVtabIndex(const Klass &clazz, const MIRFunction &func) const; void GetSignatureTypeNames(std::string &signature, std::vector &typeNames); MIRSymbol *GetClinitFuncSymbol(const Klass &klass); - int SolveAnnotation(MIRClassType &classType, MIRFunction &func); + int SolveAnnotation(MIRStructType &classType, MIRFunction &func); uint32 GetTypeNameIdxFromType(const MIRType &type, const Klass &klass, const std::string &fieldName); bool IsMemberClass(const std::string &annotationString); int8_t GetAnnoFlag(const std::string &annotationString); diff --git a/src/mpl2mpl/src/class_hierarchy.cpp b/src/mpl2mpl/src/class_hierarchy.cpp index cef1f53a509e38ce7a6e56e271b93e233c4b3f87..90d5b4b15a56a65acad75f9d63b12a9d62d9e95f 100644 --- a/src/mpl2mpl/src/class_hierarchy.cpp +++ b/src/mpl2mpl/src/class_hierarchy.cpp @@ -171,7 +171,7 @@ bool Klass::IsKlassMethod(const MIRFunction *func) const { } bool Klass::ImplementsKlass() const { - if (IsInterface()) { + if (IsInterface() || IsInterfaceIncomplete()) { return false; } MIRClassType *classType = GetMIRClassType(); @@ -209,12 +209,15 @@ void Klass::CountVirtMethTopDown(const KlassHierarchy &kh) { auto *superAndImplClasses = alloc->GetMemPool()->New>(alloc->Adapter()); // Add default methods of interface. Add them first because they have lowest // priorities compared with methods defined in classes - for (TyIdx tyIdx : GetMIRClassType()->GetInterfaceImplemented()) { - Klass *interface = kh.GetKlassFromTyIdx(tyIdx); - if (interface != nullptr) { - superAndImplClasses->push_back(interface); + if (IsClass() || IsClassIncomplete()) { + for (TyIdx tyIdx : GetMIRClassType()->GetInterfaceImplemented()) { + Klass *interface = kh.GetKlassFromTyIdx(tyIdx); + if (interface != nullptr) { + superAndImplClasses->push_back(interface); + } } } + // Then add methods from superclasses for (Klass *superKlass : superKlasses) { superAndImplClasses->push_back(superKlass); diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index b61ce7df80003292ff721392d7d217ce78b5a175..d7eb9029cba8ee3e35dbaecc0a312ae959cbcc24 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -885,13 +885,14 @@ void MUIDReplacement::ReplaceDataTable(const std::string &name) { if (oldConst == nullptr) { return; } + bool isGLobalRootList = (name == NameMangler::kGcRootList) ? true : false; for (MIRConst *&oldTabEntry : oldConst->GetConstVec()) { CHECK_NULL_FATAL(oldTabEntry); if (oldTabEntry->GetKind() == kConstAggConst) { auto *aggrC = static_cast(oldTabEntry); for (size_t i = 0; i < aggrC->GetConstVec().size(); ++i) { CHECK_NULL_FATAL(aggrC->GetConstVecItem(i)); - ReplaceAddrofConst(aggrC->GetConstVecItem(i)); + ReplaceAddrofConst(aggrC->GetConstVecItem(i), isGLobalRootList); MIRConstPtr mirConst = aggrC->GetConstVecItem(i); if (mirConst->GetKind() == kConstInt) { MIRIntConst *newIntConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( @@ -902,7 +903,7 @@ void MUIDReplacement::ReplaceDataTable(const std::string &name) { } } } else if (oldTabEntry->GetKind() == kConstAddrof) { - ReplaceAddrofConst(oldTabEntry); + ReplaceAddrofConst(oldTabEntry, isGLobalRootList); } } } @@ -937,7 +938,7 @@ void MUIDReplacement::ReplaceDecoupleKeyTable(MIRAggConst* oldConst) { } } -void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry) { +void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry, bool isGlobalRootList) { if (entry->GetKind() != kConstAddrof) { return; } @@ -952,10 +953,20 @@ void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry) { MIRIntConst *constNode = nullptr; if (addrSym->GetStorageClass() != kScExtern) { offset = FindIndexFromDefTable(*addrSym, false); + if (isGlobalRootList == true) { +#ifdef USE_ARM32_MACRO + offset = (offset << 2) + 1; +#endif + } constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(offset | kFromDefIndexMask), voidType); } else { offset = FindIndexFromUndefTable(*addrSym, false); + if (isGlobalRootList == true) { +#ifdef USE_ARM32_MACRO + offset = (offset << 2) + 1; +#endif + } constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(offset | kFromUndefIndexMask), voidType); } diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index c9f59277f9942aa9c7c79609784cc2a6df40735e..ce05da2e5172101f5b499e94c273e790d2137f88 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -118,6 +118,9 @@ void NativeStubFuncGeneration::ProcessFunc(MIRFunction *func) { if (func->GetBody()->GetFirst()) { GenerateRegTabEntry(*func); GenerateRegFuncTabEntry(); + func->UnSetAttr(FUNCATTR_native); + func->UnSetAttr(FUNCATTR_fast_native); + func->UnSetAttr(FUNCATTR_critical_native); return; } func->GetBody()->ResetBlock(); diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index c9335daa4f295badc592e96ca9820956eaafa7f3..723bb59e05bc70a9312240809aafd4cec23a658e 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -290,7 +290,7 @@ uint32 GetFieldModifier(const FieldAttrs &fa) { (static_cast(fa.GetAttr(FLDATTR_hiddenapiblack)) << (kModifierHiddenApiBlack - 1)); } -uint32 GetClassAccessFlags(const MIRClassType &classType) { +uint32 GetClassAccessFlags(const MIRStructType &classType) { int32 accessFlag = 0; for (const MIRPragma *prag : classType.GetPragmaVec()) { if (prag->GetKind() == kPragmaClass) { @@ -313,7 +313,7 @@ uint32 GetClassAccessFlags(const MIRClassType &classType) { return 0; } -bool ReflectionAnalysis::IsStaticClass(const MIRClassType &classType) const { +bool ReflectionAnalysis::IsStaticClass(const MIRStructType &classType) const { return GetClassAccessFlags(classType) & 0x00000008; // # Modifier_Static 0x00000008; } @@ -337,7 +337,7 @@ static std::string GetSignatureFromFullName(const std::string &fullname) { FATAL(kLncFatal, "can not find \"|\" in fullname"); } -int ReflectionAnalysis::SolveAnnotation(MIRClassType &classType, MIRFunction &func) { +int ReflectionAnalysis::SolveAnnotation(MIRStructType &classType, MIRFunction &func) { std::string annoArray1; std::map idxNumMap; GenAnnotation(idxNumMap, annoArray1, classType, kPragmaFunc, func.GetName(), invalidIdx); @@ -581,7 +581,7 @@ bool RtRetentionPolicyCheck(const MIRSymbol &clInfo) { uint16 ReflectionAnalysis::GetMethodInVtabIndex(const Klass &klass, const MIRFunction &func) const { uint16 methodInVtabIndex = 0; bool findMethod = false; - const MIRClassType *classType = klass.GetMIRClassType(); + const MIRStructType *classType = klass.GetMIRStructType(); const MIRSymbol *vtableSymbol = GlobalTables::GetGsymTable().GetSymbolFromStrIdx( GlobalTables::GetStrTable().GetStrIdxFromName(VTAB_PREFIX_STR + klass.GetKlassName())); if (klass.IsClass() && vtableSymbol != nullptr) { @@ -755,7 +755,7 @@ void ReflectionAnalysis::GenMethodMeta(const Klass &klass, MIRStructType &method uint32 signatureIdx = FindOrInsertReflectString(signature); mirBuilder.AddIntFieldConst(methodsInfoType, newConst, fieldID++, signatureIdx); // @annotation - MIRClassType *classType = klass.GetMIRClassType(); + MIRStructType *classType = klass.GetMIRStructType(); int annotationIdx = SolveAnnotation(*classType, func); mirBuilder.AddIntFieldConst(methodsInfoType, newConst, fieldID++, annotationIdx); // @flag @@ -775,7 +775,7 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMeta(const Klass &klass, std::vector> &methodInfoVec, std::unordered_map &baseNameMp, std::unordered_map &fullNameMp) { - MIRClassType *classType = klass.GetMIRClassType(); + MIRStructType *classType = klass.GetMIRStructType(); size_t arraySize = classType->GetMethods().size(); auto &methodsInfoType = static_cast(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(methodsInfoTyIdx)); @@ -817,7 +817,7 @@ MIRSymbol *ReflectionAnalysis::GenMethodAddrData(const MIRSymbol &funcSym) { } MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass &klass) { - MIRClassType *classType = klass.GetMIRClassType(); + MIRStructType *classType = klass.GetMIRStructType(); if (classType == nullptr || classType->GetMethods().empty()) { return nullptr; } @@ -857,7 +857,7 @@ void ReflectionAnalysis::GenFieldOffsetConst(MIRAggConst &newConst, const Klass mirBuilder.AddAddrofFieldConst(type, newConst, metaFieldID, *gvarSt); } else { // Offset of the instance field, we fill the index of fields here and let CG to fill in. - MIRClassType *mirClassType = klass.GetMIRClassType(); + MIRStructType *mirClassType = klass.GetMIRStructType(); ASSERT(mirClassType != nullptr, "GetMIRClassType() returns null"); FieldID fldID = mirBuilder.GetStructFieldIDFromNameAndTypeParentFirstFoundInChild( *mirClassType, originFieldname, fieldP.second.first); @@ -887,7 +887,7 @@ MIRSymbol *ReflectionAnalysis::GenFieldOffsetData(const Klass &klass, std::pair< if (isStaticField) { fieldOffsetSymbolName += originFieldname; } else { - MIRClassType *mirClassType = klass.GetMIRClassType(); + MIRStructType *mirClassType = klass.GetMIRStructType(); FieldID fldID = mirBuilder.GetStructFieldIDFromNameAndTypeParentFirstFoundInChild( *mirClassType, originFieldname, fieldP.second.first); fieldOffsetSymbolName += klass.GetKlassName() + "_FieldID_" + std::to_string(fldID); @@ -977,7 +977,7 @@ void ReflectionAnalysis::GenFieldMeta(const Klass &klass, MIRStructType &fieldsI uint32 fieldname32Idx = FindOrInsertReflectString(fieldName); mirBuilder.AddIntFieldConst(fieldsInfoType, *newConst, fieldID++, fieldname32Idx); // @annotation - MIRClassType *classType = klass.GetMIRClassType(); + MIRStructType *classType = klass.GetMIRStructType(); std::string annoArr; std::map idxNumMap; GenAnnotation(idxNumMap, annoArr, *classType, kPragmaVar, fieldName, ty->GetTypeIndex()); @@ -1017,7 +1017,7 @@ MIRSymbol *ReflectionAnalysis::GenFieldsMeta(const Klass &klass, std::vectorGetFields(); FieldVector staticFields = classType->GetStaticFields(); ASSERT(fields.size() < fields.max_size() - staticFields.size(), "size too large"); @@ -1215,7 +1215,7 @@ std::string ReflectionAnalysis::GetAnnoValueNoArray(const MIRPragmaElement &anno return annoArray; } -void ReflectionAnalysis::GenAnnotation(std::map &idxNumMap, std::string &annoArr, MIRClassType &classType, +void ReflectionAnalysis::GenAnnotation(std::map &idxNumMap, std::string &annoArr, MIRStructType &classType, PragmaKind paragKind, const std::string ¶gName, TyIdx fieldTypeIdx, std::map *paramnumArray, int *paramIndex) { int annoNum = 0; @@ -1306,7 +1306,7 @@ void ReflectionAnalysis::GenHotClassNameString(const Klass &klass) { if (klass.IsInterface()) { return; } - MIRClassType *classType = klass.GetMIRClassType(); + MIRStructType *classType = klass.GetMIRStructType(); if (!classType->IsLocal()) { // External class. return; @@ -1326,7 +1326,7 @@ uint32 ReflectionAnalysis::FindOrInsertReflectString(const std::string &str) { } MIRSymbol *ReflectionAnalysis::GetClinitFuncSymbol(const Klass &klass) { - MIRClassType *classType = klass.GetMIRClassType(); + MIRStructType *classType = klass.GetMIRStructType(); if (classType == nullptr || classType->GetMethods().empty()) { return nullptr; } @@ -1345,9 +1345,9 @@ MIRSymbol *ReflectionAnalysis::GetClinitFuncSymbol(const Klass &klass) { void ReflectionAnalysis::GenClassMetaData(Klass &klass) { MIRModule &module = *mirModule; - MIRClassType *classType = klass.GetMIRClassType(); - ASSERT(classType != nullptr, "null ptr check!"); - if (!classType->IsLocal()) { + MIRStructType *structType = klass.GetMIRStructType(); + ASSERT(structType != nullptr, "null ptr check!"); + if (!structType->IsLocal()) { // External class. return; } @@ -1406,20 +1406,24 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { for (Klass *superClass : klass.GetSuperKlasses()) { superClassList.push_back(superClass); } - for (TyIdx const kTyIdx : classType->GetInterfaceImplemented()) { - Klass *interface = klassH->GetKlassFromTyIdx(kTyIdx); - if (interface == nullptr) { - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(kTyIdx); - LogInfo::MapleLogger() << "Error: Interface " << static_cast(type)->GetName() << " is not found" - << "\n"; - LogInfo::MapleLogger(kLlErr) << "Error: Missing interface for " << klass.GetKlassName() << "\n"; - CHECK_FATAL(false, "Missing interface"); - } - std::list::iterator it = std::find(superClassList.begin(), superClassList.end(), interface); - if (it == superClassList.end()) { - superClassList.push_back(interface); + if (structType->IsMIRClassType()) { + MIRClassType *classType = static_cast(structType); + for (TyIdx const kTyIdx : classType->GetInterfaceImplemented()) { + Klass *interface = klassH->GetKlassFromTyIdx(kTyIdx); + if (interface == nullptr) { + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(kTyIdx); + LogInfo::MapleLogger() << "Error: Interface " << static_cast(type)->GetName() << " is not found" + << "\n"; + LogInfo::MapleLogger(kLlErr) << "Error: Missing interface for " << klass.GetKlassName() << "\n"; + CHECK_FATAL(false, "Missing interface"); + } + std::list::iterator it = std::find(superClassList.begin(), superClassList.end(), interface); + if (it == superClassList.end()) { + superClassList.push_back(interface); + } } } + size_t superClassSize = superClassList.size(); if (superClassSize >= 1) { MIRSymbol *superClassSymbolType = GenSuperClassMetaData(klass, superClassList); @@ -1436,7 +1440,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { // Do annotation. std::string annoArray; std::map idxNumMap; - GenAnnotation(idxNumMap, annoArray, *classType, kPragmaClass, klass.GetKlassName(), invalidIdx); + GenAnnotation(idxNumMap, annoArray, *structType, kPragmaClass, klass.GetKlassName(), invalidIdx); bool isAnonymous = IsAnonymousClass(annoArray); CheckPrivateInnerAndNoSubClass(klass, annoArray); #ifndef USE_32BIT_REF @@ -1452,7 +1456,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { mirBuilder.AddIntFieldConst(classMetadataROType, *newConst, fieldID++, 0); #endif // USE_32BIT_REF // @modifier: For class fill ClassAccessFlags. - uint32 modifier = GetClassAccessFlags(*classType); + uint32 modifier = GetClassAccessFlags(*structType); mirBuilder.AddIntFieldConst(classMetadataROType, *newConst, fieldID++, modifier); // @annotation: Set annotation field. uint32_t signatureIdx = GetAnnoCstrIndex(idxNumMap, annoArray, false); @@ -1536,7 +1540,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { classTab.push_back(classSt); } -int8 ReflectionAnalysis::JudgePara(MIRClassType &classType) { +int8 ReflectionAnalysis::JudgePara(MIRStructType &classType) { for (MIRPragma *prag : classType.GetPragmaVec()) { if (prag->GetKind() == kPragmaClass) { if ((GlobalTables::GetTypeTable().GetTypeFromTyIdx(prag->GetTyIdx())->GetName() == diff --git a/src/mpl2mpl/src/vtable_analysis.cpp b/src/mpl2mpl/src/vtable_analysis.cpp index f8b1b941e64e9c5a95a7be24b4c44766a622cdfe..c09aeade6d69f6af1ecba23e4e82306269cf2457 100644 --- a/src/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mpl2mpl/src/vtable_analysis.cpp @@ -91,7 +91,7 @@ void VtableAnalysis::AddMethodToTable(MethodPtrVector &methodTable, MethodPair & } void VtableAnalysis::GenVtableList(const Klass &klass) { - if (klass.IsInterface()) { + if (klass.IsInterface() || klass.IsInterfaceIncomplete()) { MIRInterfaceType *iType = klass.GetMIRInterfaceType(); // add in methods from parent interfaces, note interfaces can declare/define same methods for (const Klass *parentKlass : klass.GetSuperKlasses()) {