diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index 48d02708904973cf64a4fa31b56f29507d03b73b..7094d12549592389316625779aee7019539b36d1 100755 Binary files a/src/mapleall/bin/dex2mpl and b/src/mapleall/bin/dex2mpl differ diff --git a/src/mapleall/bin/dex2mpl_android b/src/mapleall/bin/dex2mpl_android index c63ad5ec2b337412a953f9293e1a97f2ba0ed174..c9fd5296ca6bd7de5043bb41a5592f6915a95410 100755 Binary files a/src/mapleall/bin/dex2mpl_android and b/src/mapleall/bin/dex2mpl_android differ diff --git a/src/mapleall/bin/jbc2mpl b/src/mapleall/bin/jbc2mpl index bdf1ee430b000cbf59ec4768421682ddb6c55c62..68ce9ad20f0a2e7184f37cb3641da8ea42cf3962 100755 Binary files a/src/mapleall/bin/jbc2mpl and b/src/mapleall/bin/jbc2mpl differ diff --git a/src/mapleall/maple_be/include/be/lower.h b/src/mapleall/maple_be/include/be/lower.h index 2b9d211dd30588c57cc8f539da91a474379a5eb8..c0d6f80a6632e353c3de6ed1ad8f412a0e12983a 100644 --- a/src/mapleall/maple_be/include/be/lower.h +++ b/src/mapleall/maple_be/include/be/lower.h @@ -223,7 +223,7 @@ class CGLowerer { * Such intrinsics will bypass the lowering of "assigned", * and let mplcg handle the intrinsic results which are not return values. */ - bool IsIntrinsicCallHandledAtLowerLevel(MIRIntrinsicID intrinsic); + bool IsIntrinsicCallHandledAtLowerLevel(MIRIntrinsicID intrinsic) const; bool IsIntrinsicOpHandledAtLowerLevel(MIRIntrinsicID intrinsic); diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h index 1e152eccf7184e5f9119f070acb311f8580e951e..1944235a3e26af18d479d8f4c954cc0543086c1c 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -91,7 +91,7 @@ class AArch64CGFunc : public CGFunc { void SelectDassign(DassignNode &stmt, Operand &opnd0) override; void SelectRegassign(RegassignNode &stmt, Operand &opnd0) override; void SelectAssertNull(UnaryStmtNode &stmt) override; - Operand &GenLargeAggFormalMemOpnd(MIRSymbol &sym, uint32 alignUsed, int32 offset); + Operand &GenLargeAggFormalMemOpnd(const MIRSymbol &sym, uint32 alignUsed, int32 offset); void SelectAggDassign(DassignNode &stmt) override; void SelectIassign(IassignNode &stmt) override; void SelectAggIassign(IassignNode &stmt, Operand &lhsAddrOpnd) override; @@ -438,7 +438,7 @@ class AArch64CGFunc : public CGFunc { MOperator PickStInsn(uint32 bitSize, PrimType primType, AArch64isa::MemoryOrdering memOrd = AArch64isa::kMoNone); MOperator PickLdInsn(uint32 bitSize, PrimType primType, AArch64isa::MemoryOrdering memOrd = AArch64isa::kMoNone); - MOperator PickExtInsn(PrimType dtype, PrimType stype); + MOperator PickExtInsn(PrimType dtype, PrimType stype) const; bool CheckIfSplitOffsetWithAdd(const AArch64MemOperand &memOpnd, uint32 bitLen); AArch64MemOperand &SplitOffsetWithAddInstruction(const AArch64MemOperand &memOpnd, uint32 bitLen, diff --git a/src/mapleall/maple_be/src/be/becommon.cpp b/src/mapleall/maple_be/src/be/becommon.cpp index e5ec19b66d08ed2acd6bd2b290cf97e33e49987d..046ddef80fc3d431424878bcc998a9d6b5fdd82a 100644 --- a/src/mapleall/maple_be/src/be/becommon.cpp +++ b/src/mapleall/maple_be/src/be/becommon.cpp @@ -138,7 +138,7 @@ void BECommon::ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx) { fieldTypeSize = GetTypeSize(fieldTyIdx); } uint8 fieldAlign = GetTypeAlign(fieldTyIdx); - uint8 fieldAlignBits = fieldAlign * kBitsPerByte; + uint64 fieldAlignBits = fieldAlign * kBitsPerByte; CHECK_FATAL(fieldAlign != 0, "expect fieldAlign not equal 0"); if ((fieldType->GetKind() == kTypeStruct) || (fieldType->GetKind() == kTypeClass)) { AppendStructFieldCount(structType.GetTypeIndex(), GetStructFieldCount(fieldTyIdx)); @@ -180,7 +180,7 @@ void BECommon::ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx) { /* pad alloced_size according to the field alignment */ allocedSize = RoundUp(allocedSize, fieldAlign); allocedSize += fieldTypeSize; - allocedSizeInBits = allocedSize * 8; + allocedSizeInBits = allocedSize * kBitsPerByte; } } } else { /* for unions, bitfields are treated as non-bitfields */ @@ -557,7 +557,7 @@ std::pair BECommon::GetFieldOffset(MIRStructType &structType, Fiel MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); uint32 fieldTypeSize = GetTypeSize(fieldTyIdx); uint8 fieldAlign = GetTypeAlign(fieldTyIdx); - uint8 fieldAlignBits = fieldAlign * kBitsPerByte; + uint64 fieldAlignBits = fieldAlign * kBitsPerByte; CHECK_FATAL(fieldAlign != 0, "fieldAlign should not equal 0"); if (structType.GetKind() != kTypeUnion) { if (fieldType->GetKind() == kTypeBitField) { @@ -589,7 +589,7 @@ std::pair BECommon::GetFieldOffset(MIRStructType &structType, Fiel } else { uint32 fldSizeInBits = fieldTypeSize * k8BitSize; bool leftOverBits = false; - uint32 offset = 0; + uint64 offset = 0; if (allocedSizeInBits == allocedSize * k8BitSize) { allocedSize = RoundUp(allocedSize, fieldAlign); @@ -682,7 +682,7 @@ MIRType *BECommon::BeGetOrCreatePointerType(const MIRType &pointedType) { MIRType *BECommon::BeGetOrCreateFunctionType(TyIdx tyIdx, const std::vector &vecTy, const std::vector &vecAt) { - MIRType *newType = GlobalTables::GetTypeTable().GetOrCreateFunctionType(mirModule, tyIdx, vecTy, vecAt); + MIRType *newType = GlobalTables::GetTypeTable().GetOrCreateFunctionType(tyIdx, vecTy, vecAt); if (TyIsInSizeAlignTable(*newType)) { return newType; } diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index e23f542a72550dce4b3bd1ee40069f7e5f4a57e6..d5256d9197dfcc04be378ff75303a1578e7df55d 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -3129,7 +3129,7 @@ void CGLowerer::LowerJarrayMalloc(const StmtNode &stmt, const JarrayMallocNode & blkNode.AppendStatementsFromBlock(*LowerCallAssignedStmt(*callAssign)); } -bool CGLowerer::IsIntrinsicCallHandledAtLowerLevel(MIRIntrinsicID intrinsic) { +bool CGLowerer::IsIntrinsicCallHandledAtLowerLevel(MIRIntrinsicID intrinsic) const { /* only INTRN_MPL_ATOMIC_EXCHANGE_PTR now. */ return intrinsic == INTRN_MPL_ATOMIC_EXCHANGE_PTR; } 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 145d9625cecdfb4b594ae5cc9a55c8a0efb8b7aa..bf465a808d600a989435b76e1a35b8812110e315 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -92,8 +92,6 @@ MOperator extIs[kIntByteSizeDimension][kIntByteSizeDimension] = { { MOP_undef, MOP_undef, MOP_undef, MOP_undef} /* u64/u64 */ }; -/* extended to signed ints */ - MOperator PickLdStInsn(bool isLoad, uint32 bitSize, PrimType primType, AArch64isa::MemoryOrdering memOrd) { ASSERT(__builtin_popcount(static_cast(memOrd)) <= 1, "must be kMoNone or kMoAcquire"); ASSERT(primType != PTY_ptr, "should have been lowered"); @@ -146,7 +144,7 @@ MOperator AArch64CGFunc::PickStInsn(uint32 bitSize, PrimType primType, AArch64is return PickLdStInsn(false, bitSize, primType, memOrd); } -MOperator AArch64CGFunc::PickExtInsn(PrimType dtype, PrimType stype) { +MOperator AArch64CGFunc::PickExtInsn(PrimType dtype, PrimType stype) const { int32 sBitSize = GetPrimTypeBitSize(stype); int32 dBitSize = GetPrimTypeBitSize(dtype); /* __builtin_ffs(x) returns: 0 -> 0, 1 -> 1, 2 -> 2, 4 -> 3, 8 -> 4 */ @@ -154,9 +152,9 @@ MOperator AArch64CGFunc::PickExtInsn(PrimType dtype, PrimType stype) { MOperator(*table)[kIntByteSizeDimension]; table = IsUnsignedInteger(dtype) ? uextIs : extIs; /* __builtin_ffs(x) returns: 8 -> 4, 16 -> 5, 32 -> 6, 64 -> 7 */ - uint32 row = static_cast(__builtin_ffs(static_cast(sBitSize))) - 4; + uint32 row = static_cast(__builtin_ffs(static_cast(sBitSize))) - k4BitSize; ASSERT(row <= 3, "wrong bitSize"); - uint32 col = static_cast(__builtin_ffs(static_cast(dBitSize))) - 4; + uint32 col = static_cast(__builtin_ffs(static_cast(dBitSize))) - k4BitSize; ASSERT(col <= 3, "wrong bitSize"); return table[row][col]; } @@ -468,7 +466,7 @@ void AArch64CGFunc::SelectCopyMemOpnd(Operand &dest, PrimType dtype, uint32 dsiz Insn *insn = nullptr; uint32 ssize = src.GetSize(); PrimType regTy = PTY_void; - RegOperand *loadReg; + RegOperand *loadReg = nullptr; MOperator mop = MOP_undef; if (IsPrimitiveFloat(stype)) { CHECK_FATAL(dsize == ssize, "dsize %u expect equals ssize %u", dtype, ssize); @@ -501,7 +499,6 @@ void AArch64CGFunc::SelectCopyMemOpnd(Operand &dest, PrimType dtype, uint32 dsiz } GetCurBB()->AppendInsn(*insn); - if (regTy != PTY_void && mop != MOP_undef) { GetCurBB()->AppendInsn(GetCG()->BuildInstruction(mop, dest, *loadReg)); } @@ -998,7 +995,7 @@ void AArch64CGFunc::SelectRegassign(RegassignNode &stmt, Operand &opnd0) { } } -Operand &AArch64CGFunc::GenLargeAggFormalMemOpnd(MIRSymbol &sym, uint32 align, int32 offset) { +Operand &AArch64CGFunc::GenLargeAggFormalMemOpnd(const MIRSymbol &sym, uint32 align, int32 offset) { Operand *memOpnd; if (sym.GetStorageClass() == kScFormal && GetBecommon().GetTypeSize(sym.GetTyIdx()) > k16ByteSize) { /* formal of size of greater than 16 is copied by the caller and the pointer to it is passed. */ @@ -7284,7 +7281,7 @@ Operand *AArch64CGFunc::SelectCclz(IntrinsicopNode &intrnnode) { PrimType ptype = argexpr->GetPrimType(); Operand *opnd = HandleExpr(intrnnode, *argexpr); MOperator mop; - if (GetPrimTypeSize(ptype) == 4) { + if (GetPrimTypeSize(ptype) == k4ByteSize) { mop = MOP_wclz; } else { mop = MOP_xclz; @@ -7300,7 +7297,7 @@ Operand *AArch64CGFunc::SelectCctz(IntrinsicopNode &intrnnode) { Operand *opnd = HandleExpr(intrnnode, *argexpr); MOperator clzmop; MOperator rbitmop; - if (GetPrimTypeSize(ptype) == 4) { + if (GetPrimTypeSize(ptype) == k4ByteSize) { clzmop = MOP_wclz; rbitmop = MOP_wrbit; } else { diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_optimize_common.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_optimize_common.cpp index 9161b343653f5a94320a8db94e848950acc415f3..4c5153973758edae9dfa3af467f746b80f735c64 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_optimize_common.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_optimize_common.cpp @@ -24,7 +24,7 @@ void AArch64InsnVisitor::ModifyJumpTarget(Operand &targetOperand, BB &bb) { for (Insn *insn = bb.GetLastInsn(); insn != nullptr; insn = insn->GetPrev()) { if (insn->GetMachineOpcode() == MOP_adrp_label) { LabelIdx labIdx = static_cast(targetOperand).GetLabelIndex(); - ImmOperand &immOpnd = static_cast(GetCGFunc())->CreateImmOperand(labIdx, 8, false); + ImmOperand &immOpnd = static_cast(GetCGFunc())->CreateImmOperand(labIdx, k8BitSize, false); insn->SetOperand(1, immOpnd); modified = true; } diff --git a/src/mapleall/maple_be/src/cg/cg_cfg.cpp b/src/mapleall/maple_be/src/cg/cg_cfg.cpp index 05c1945c993264ab7a8ac506423edaa02ffea91b..8296934699abd824be1bbbf2930260812fa46d79 100644 --- a/src/mapleall/maple_be/src/cg/cg_cfg.cpp +++ b/src/mapleall/maple_be/src/cg/cg_cfg.cpp @@ -450,15 +450,16 @@ BB *CGCFG::GetTargetSuc(BB &curBB, bool branchOnly, bool isGotoIf) { case BB::kBBIgoto: { for (Insn *insn = curBB.GetLastInsn(); insn != nullptr; insn = insn->GetPrev()) { if (insn->GetMachineOpcode() == MOP_adrp_label) { - LabelIdx label = static_cast(insn->GetOperand(1)).GetValue(); + int64 label = static_cast(insn->GetOperand(1)).GetValue(); for (BB *bb : curBB.GetSuccs()) { - if (bb->GetLabIdx() == label) { + if (bb->GetLabIdx() == static_cast(label)) { return bb; } } } } CHECK_FATAL(false, "Cannot find label in Igoto bb"); + break; } case BB::kBBFallthru: { return (branchOnly ? nullptr : curBB.GetNext()); diff --git a/src/mapleall/maple_ir/include/global_tables.h b/src/mapleall/maple_ir/include/global_tables.h index 614c649f3c4a63825837c63ed96f0d0978d84827..6fdf9cd7f72a7fc2aabaecc5ab80c0e1cda6ce86 100644 --- a/src/mapleall/maple_ir/include/global_tables.h +++ b/src/mapleall/maple_ir/include/global_tables.h @@ -333,8 +333,8 @@ class TypeTable { MIRArrayType *GetOrCreateArrayType(const MIRType &elem, uint32 size); // For one dimention array MIRType *GetOrCreateFarrayType(const MIRType &elem); MIRType *GetOrCreateJarrayType(const MIRType &elem); - MIRType *GetOrCreateFunctionType(MIRModule &module, TyIdx, const std::vector&, const std::vector&, - bool isVarg = false, bool isSimpCreate = false); + MIRType *GetOrCreateFunctionType(const TyIdx&, const std::vector&, const std::vector&, + bool isVarg = false); MIRType *GetOrCreateStructType(const std::string &name, const FieldVector &fields, const FieldVector &prntFields, MIRModule &module) { return GetOrCreateStructOrUnion(name, fields, prntFields, module); diff --git a/src/mapleall/maple_ir/include/mir_function.h b/src/mapleall/maple_ir/include/mir_function.h index 8e2defaa1dd29afdd9659328ec22922fd4433d14..e9f54871eb004b6fd8e6973f1124ffc9f2ba2a28 100644 --- a/src/mapleall/maple_ir/include/mir_function.h +++ b/src/mapleall/maple_ir/include/mir_function.h @@ -167,7 +167,7 @@ class MIRFunction { return funcType->GetParamTypeList().size(); } - const MapleVector &GetParamTypes() const { + auto &GetParamTypes() const { CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); return funcType->GetParamTypeList(); } @@ -390,7 +390,7 @@ class MIRFunction { void SetHasSetjmp(); bool HasSetjmp() const; - void SetReturnStruct(MIRType *retType); + void SetReturnStruct(const MIRType *retType); bool IsEmpty() const; bool IsClinit() const; diff --git a/src/mapleall/maple_ir/include/mir_parser.h b/src/mapleall/maple_ir/include/mir_parser.h index e349f1745c8e195ce96037673dc1301c98aa3e5e..9782ff0ca025dfeb767c412a40e259c1b2df6fc3 100644 --- a/src/mapleall/maple_ir/include/mir_parser.h +++ b/src/mapleall/maple_ir/include/mir_parser.h @@ -75,15 +75,15 @@ class MIRParser { bool ParsePragmaElementForAnnotation(MIRPragmaElement &elem); bool ParsePragma(MIRStructType &type); bool ParseFields(MIRStructType &type); - bool ParseStructType(TyIdx &styIdx); - bool ParseClassType(TyIdx &tyIdx); - bool ParseInterfaceType(TyIdx &sTyIdx); + bool ParseStructType(TyIdx &styIdx, const GStrIdx &strIdx = GStrIdx(0)); + bool ParseClassType(TyIdx &tyIdx, const GStrIdx &strIdx = GStrIdx(0)); + bool ParseInterfaceType(TyIdx &sTyIdx, const GStrIdx &strIdx = GStrIdx(0)); bool ParseDefinedTypename(TyIdx &tyIdx, MIRTypeKind kind = kTypeUnknown); bool ParseTypeParam(TyIdx &tyIdx); bool ParsePointType(TyIdx &tyIdx); bool ParseFuncType(TyIdx &tyIdx); bool ParseGenericInstantVector(MIRInstantVectorType &insVecType); - bool ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind = kTypeUnknown); + bool ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind = kTypeUnknown, const GStrIdx &strIdx = GStrIdx(0)); bool ParseType(TyIdx &tyIdx); bool ParseStatement(StmtNodePtr &stmt); bool ParseSpecialReg(PregIdx &pregIdx); diff --git a/src/mapleall/maple_ir/include/mir_type.h b/src/mapleall/maple_ir/include/mir_type.h index 86c5da0407b602fed620226224c60f1f7b000375..5dced4dd0af21affe7d5f95fd7685c128a824e8e 100644 --- a/src/mapleall/maple_ir/include/mir_type.h +++ b/src/mapleall/maple_ir/include/mir_type.h @@ -587,7 +587,7 @@ class MIRPtrType : public MIRType { bool IsPointedTypeVolatile(int fieldID) const; void Dump(int indent, bool dontUseName = false) const override; - TyIdxFieldAttrPair GetPointedTyIdxFldAttrPairWithFieldID(FieldID fieldID) const; + TyIdxFieldAttrPair GetPointedTyIdxFldAttrPairWithFieldID(FieldID fldId) const; TyIdx GetPointedTyIdxWithFieldID(FieldID fieldID) const; size_t GetHashIndex() const override { constexpr uint8 idxShift = 4; @@ -1114,6 +1114,7 @@ class MIRStructType : public MIRType { virtual FieldPair TraverseToFieldRef(FieldID &fieldID) const; std::string GetMplTypeName() const override; std::string GetCompactMplTypeName() const override; + FieldPair TraverseToField(FieldID fieldID) const ; protected: FieldVector fields{}; @@ -1134,8 +1135,7 @@ class MIRStructType : public MIRType { std::vector genericDeclare; std::map fieldGenericDeclare; std::vector inheritanceGeneric; - public: - FieldPair TraverseToField(FieldID fieldID) const ; + private: FieldPair TraverseToField(GStrIdx fieldStrIdx) const ; bool HasVolatileFieldInFields(const FieldVector &fieldsOfStruct) const; @@ -1498,29 +1498,16 @@ class MIRBitFieldType : public MIRType { class MIRFuncType : public MIRType { public: - MIRFuncType(MapleAllocator &ma) - : MIRType(kTypeFunction, PTY_ptr), - paramTypeList(ma.Adapter()), - paramAttrsList(ma.Adapter()) {} + MIRFuncType() : MIRType(kTypeFunction, PTY_ptr) {} - explicit MIRFuncType(const GStrIdx &strIdx, MapleAllocator &ma) - : MIRType(kTypeFunction, PTY_ptr, strIdx), - paramTypeList(ma.Adapter()), - paramAttrsList(ma.Adapter()) {} + explicit MIRFuncType(const GStrIdx &strIdx) + : MIRType(kTypeFunction, PTY_ptr, strIdx) {} - MIRFuncType(const TyIdx &retTyIdx, const std::vector &vecTy, - const std::vector &vecAt, MapleAllocator &ma) + MIRFuncType(const TyIdx &retTyIdx, const std::vector &vecTy, const std::vector &vecAt) : MIRType(kTypeFunction, PTY_ptr), retTyIdx(retTyIdx), - paramTypeList(ma.Adapter()), - paramAttrsList(ma.Adapter()) { - for (auto tyIdx : vecTy) { - paramTypeList.push_back(tyIdx); - } - for (auto tyAttr : vecAt) { - paramAttrsList.push_back(tyAttr); - } - } + paramTypeList(vecTy), + paramAttrsList(vecAt) {} ~MIRFuncType() override = default; @@ -1542,11 +1529,11 @@ class MIRFuncType : public MIRType { retTyIdx = idx; } - const MapleVector &GetParamTypeList() const { + const std::vector &GetParamTypeList() const { return paramTypeList; } - MapleVector &GetParamTypeList() { + std::vector &GetParamTypeList() { return paramTypeList; } @@ -1557,16 +1544,14 @@ class MIRFuncType : public MIRType { void SetParamTypeList(const std::vector &list) { paramTypeList.clear(); - for (auto tyIdx : list) { - paramTypeList.push_back(tyIdx); - } + (void)paramTypeList.insert(paramTypeList.begin(), list.begin(), list.end()); } - const MapleVector &GetParamAttrsList() const { + const std::vector &GetParamAttrsList() const { return paramAttrsList; } - MapleVector &GetParamAttrsList() { + std::vector &GetParamAttrsList() { return paramAttrsList; } @@ -1582,9 +1567,7 @@ class MIRFuncType : public MIRType { void SetParamAttrsList(const std::vector &list) { paramAttrsList.clear(); - for (auto tyAttr : list) { - paramAttrsList.push_back(tyAttr); - } + (void)paramAttrsList.insert(paramAttrsList.begin(), list.begin(), list.end()); } void SetNthParamAttrs(size_t i, const TypeAttrs &attrs) { @@ -1610,8 +1593,8 @@ class MIRFuncType : public MIRType { private: TyIdx retTyIdx{ 0 }; - MapleVector paramTypeList; - MapleVector paramAttrsList; + std::vector paramTypeList; + std::vector paramAttrsList; bool isVarArgs = false; }; diff --git a/src/mapleall/maple_ir/src/bin_mpl_import.cpp b/src/mapleall/maple_ir/src/bin_mpl_import.cpp index 147fe1b0bc0804e71aa7c6360d7279beb6bc3a88..9a3645c0c889e4245de8f1c7c321cddab13a5d43 100644 --- a/src/mapleall/maple_ir/src/bin_mpl_import.cpp +++ b/src/mapleall/maple_ir/src/bin_mpl_import.cpp @@ -612,7 +612,7 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { return origType->GetTypeIndex(); } case kBinKindTypeFunction: { - MIRFuncType type(strIdx, mod.GetMPAllocator()); + MIRFuncType type(strIdx); type.SetNameIsLocal(nameIsLocal); size_t idx = typTab.size(); typTab.push_back(nullptr); diff --git a/src/mapleall/maple_ir/src/global_tables.cpp b/src/mapleall/maple_ir/src/global_tables.cpp index f387526ce3dfe912de40b57db5faa4cc41970a90..d8e20f082dba9492a33bb734112c528cc96118ef 100644 --- a/src/mapleall/maple_ir/src/global_tables.cpp +++ b/src/mapleall/maple_ir/src/global_tables.cpp @@ -193,14 +193,11 @@ MIRType *TypeTable::GetOrCreateJarrayType(const MIRType &elem) { return typeTable.at(tyIdx); } -MIRType *TypeTable::GetOrCreateFunctionType(MIRModule &module, TyIdx retTyIdx, const std::vector &vecType, - const std::vector &vecAttrs, bool isVarg, bool isSimpCreate) { - auto *funcType = module.GetMemPool()->New(retTyIdx, vecType, vecAttrs, module.GetMPAllocator()); - funcType->SetVarArgs(isVarg); - if (isSimpCreate) { - return funcType; - } - TyIdx tyIdx = GetOrCreateMIRType(funcType); +MIRType *TypeTable::GetOrCreateFunctionType(const TyIdx &retTyIdx, const std::vector &vecType, + const std::vector &vecAttrs, bool isVarg) { + MIRFuncType funcType(retTyIdx, vecType, vecAttrs); + funcType.SetVarArgs(isVarg); + TyIdx tyIdx = GetOrCreateMIRType(&funcType); ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreateFunctionType"); return typeTable.at(tyIdx); } diff --git a/src/mapleall/maple_ir/src/mir_builder.cpp b/src/mapleall/maple_ir/src/mir_builder.cpp index a4c92ca4231c5d6d6066e23ec98df56b64eae3bc..ae3c1674d727ab126d7a65f99a4821084d6852cd 100644 --- a/src/mapleall/maple_ir/src/mir_builder.cpp +++ b/src/mapleall/maple_ir/src/mir_builder.cpp @@ -228,7 +228,7 @@ MIRFunction *MIRBuilder::GetOrCreateFunction(const std::string &str, TyIdx retTy } auto *fn = mirModule->GetMemPool()->New(mirModule, funcSt->GetStIdx()); fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); - MIRFuncType funcType(mirModule->GetMPAllocator()); + MIRFuncType funcType; funcType.SetRetTyIdx(retTyIdx); auto funcTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&funcType); auto *funcTypeInTypeTable = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcTyIdx)); @@ -282,7 +282,7 @@ MIRFunction *MIRBuilder::CreateFunction(const std::string &name, const MIRType & } } funcSymbol->SetTyIdx(GlobalTables::GetTypeTable().GetOrCreateFunctionType( - *mirModule, returnType.GetTypeIndex(), funcVecType, funcVecAttrs, isVarg)->GetTypeIndex()); + returnType.GetTypeIndex(), funcVecType, funcVecAttrs, isVarg)->GetTypeIndex()); auto *funcType = static_cast(funcSymbol->GetType()); fn->SetMIRFuncType(funcType); funcSymbol->SetFunction(fn); @@ -299,7 +299,7 @@ MIRFunction *MIRBuilder::CreateFunction(StIdx stIdx, bool addToTable) const { GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); } - auto *funcType = mirModule->GetMemPool()->New(mirModule->GetMPAllocator()); + auto *funcType = mirModule->GetMemPool()->New(); fn->SetMIRFuncType(funcType); return fn; } diff --git a/src/mapleall/maple_ir/src/mir_function.cpp b/src/mapleall/maple_ir/src/mir_function.cpp index aff5fa9ebf2f8433cf51c056e3094163585179b3..46a5384bee9d57a84df33092432b12e1765431bc 100644 --- a/src/mapleall/maple_ir/src/mir_function.cpp +++ b/src/mapleall/maple_ir/src/mir_function.cpp @@ -151,7 +151,7 @@ void MIRFunction::SetReturnStruct(MIRType &retType) { flag |= kFuncPropRetStruct; } } -void MIRFunction::SetReturnStruct(MIRType *retType) { +void MIRFunction::SetReturnStruct(const MIRType *retType) { switch (retType->GetKind()) { case kTypeUnion: case kTypeStruct: diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index 6571bd6ef418ad8661750e17b0202f4e4f1a3fbf..351cfa0d9ab73aa24603a7251ef09a27d5e462c1 100644 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -695,7 +695,7 @@ PUIdx MIRParser::EnterUndeclaredFunction(bool isMcount) { fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); funcSt->SetFunction(fn); - auto *funcType = mod.GetMemPool()->New(mod.GetMPAllocator()); + auto *funcType = mod.GetMemPool()->New(); fn->SetMIRFuncType(funcType); if (isMcount) { MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(PTY_void)); diff --git a/src/mapleall/maple_ir/src/mir_type.cpp b/src/mapleall/maple_ir/src/mir_type.cpp index 00cb573c316a4765c8d9beec8b6d317a91fe445a..789ec1683c21b09b2288c0f9b865a970178d9b7d 100644 --- a/src/mapleall/maple_ir/src/mir_type.cpp +++ b/src/mapleall/maple_ir/src/mir_type.cpp @@ -979,12 +979,13 @@ size_t MIRStructType::GetSize() const { // since there may be bitfields, perform a layout process for the fields size_t byteOfst = 0; size_t bitOfst = 0; + constexpr uint32 shiftNum = 3; for (size_t i = 0; i < fields.size(); ++i) { TyIdxFieldAttrPair tfap = GetTyidxFieldAttrPair(i); MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tfap.first); if (fieldType->GetKind() != kTypeBitField) { if (byteOfst * 8 < bitOfst) { - byteOfst = (bitOfst >> 3) + 1; + byteOfst = (bitOfst >> shiftNum) + 1; } byteOfst = RoundUp(byteOfst, std::max(fieldType->GetAlign(), tfap.second.GetAlign())); byteOfst += fieldType->GetSize(); @@ -993,20 +994,20 @@ size_t MIRStructType::GetSize() const { MIRBitFieldType *bitfType = static_cast(fieldType); if (bitfType->GetFieldSize() == 0) { // special case, for aligning purpose bitOfst = RoundUp(bitOfst, GetPrimTypeBitSize(bitfType->GetPrimType())); - byteOfst = bitOfst >> 3; + byteOfst = bitOfst >> shiftNum; } else { if (RoundDown(bitOfst + bitfType->GetFieldSize() - 1, GetPrimTypeBitSize(bitfType->GetPrimType())) != RoundDown(bitOfst, GetPrimTypeBitSize(bitfType->GetPrimType()))) { bitOfst = RoundUp(bitOfst, GetPrimTypeBitSize(bitfType->GetPrimType())); - byteOfst = bitOfst >> 3; + byteOfst = bitOfst >> shiftNum; } bitOfst += bitfType->GetFieldSize(); - byteOfst = bitOfst >> 3; + byteOfst = bitOfst >> shiftNum; } } } if (byteOfst * 8 < bitOfst) { - byteOfst = (bitOfst >> 3) + 1; + byteOfst = (bitOfst >> shiftNum) + 1; } byteOfst = RoundUp(byteOfst, GetAlign()); if (byteOfst == 0 && isCPlusPlus) { @@ -1446,25 +1447,25 @@ FieldPair MIRStructType::TraverseToFieldRef(FieldID &fieldID) const { return FieldPair(GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())); } - uint32 fieldidx = 0; - FieldPair curpair = fields[0]; + uint32 fieldIdx = 0; + FieldPair curPair = fields[0]; while (fieldID > 1) { - fieldID--; - MIRType *curfieldtype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(curpair.second.first); - MIRStructType *substructty = curfieldtype->EmbeddedStructType(); - if (substructty != nullptr) { - curpair = substructty->TraverseToFieldRef(fieldID); - if (fieldID == 1 && curpair.second.first != TyIdx(0)) { - return curpair; + --fieldID; + MIRType *curFieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(curPair.second.first); + MIRStructType *subStructTy = curFieldType->EmbeddedStructType(); + if (subStructTy != nullptr) { + curPair = subStructTy->TraverseToFieldRef(fieldID); + if (fieldID == 1 && curPair.second.first != TyIdx(0)) { + return curPair; } } - fieldidx++; - if (fieldidx == fields.size()) { + ++fieldIdx; + if (fieldIdx == fields.size()) { return FieldPair(GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())); } - curpair = fields[fieldidx]; + curPair = fields[fieldIdx]; } - return curpair; + return curPair; } FieldPair MIRStructType::TraverseToField(FieldID fieldID) const { @@ -1614,15 +1615,15 @@ bool MIRPtrType::IsPointedTypeVolatile(int fieldID) const { return pointedTy->IsVolatile(fieldID); } -TyIdxFieldAttrPair MIRPtrType::GetPointedTyIdxFldAttrPairWithFieldID(FieldID fldid) const { - if (fldid == 0) { +TyIdxFieldAttrPair MIRPtrType::GetPointedTyIdxFldAttrPairWithFieldID(FieldID fldId) const { + if (fldId == 0) { return TyIdxFieldAttrPair(pointedTyIdx, FieldAttrs()); } MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointedTyIdx); - MIRStructType *structty = ty->EmbeddedStructType(); - CHECK_FATAL(structty, - "MIRPtrType::GetPointedTyidxWithFieldId(): cannot have non-zero fieldID for something other than a struct"); - return structty->TraverseToField(fldid).second; + MIRStructType *structTy = ty->EmbeddedStructType(); + CHECK_FATAL(structTy, + "MIRPtrType::GetPointedTyidxWithFieldId(): cannot have non-zero fieldID for something other than a struct"); + return structTy->TraverseToField(fldId).second; } TyIdx MIRPtrType::GetPointedTyIdxWithFieldID(FieldID fieldID) const { diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index b80a4253ba9045ff79b70af7a4856f3d04b4c3ad..befbb79580671b1d4106593f6d5f3bae21e361c9 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -787,7 +787,7 @@ bool MIRParser::ParseFields(MIRStructType &type) { return false; } -bool MIRParser::ParseStructType(TyIdx &styIdx) { +bool MIRParser::ParseStructType(TyIdx &styIdx, const GStrIdx &strIdx) { MIRTypeKind tkind = kTypeInvalid; switch (lexer.GetTokenKind()) { case TK_struct: @@ -806,7 +806,7 @@ bool MIRParser::ParseStructType(TyIdx &styIdx) { Error("expect { parsing struct body"); return false; } - MIRStructType structType(tkind); + MIRStructType structType(tkind, strIdx); if (mod.GetSrcLang() == kSrcLangCPlusPlus) { structType.SetIsCPlusPlus(true); } @@ -829,7 +829,7 @@ bool MIRParser::ParseStructType(TyIdx &styIdx) { return true; } -bool MIRParser::ParseClassType(TyIdx &styidx) { +bool MIRParser::ParseClassType(TyIdx &styidx, const GStrIdx &strIdx) { MIRTypeKind tkind = (lexer.GetTokenKind() == TK_class) ? kTypeClass : kTypeClassIncomplete; TyIdx parentTypeIdx(0); if (lexer.NextToken() == TK_langle) { @@ -839,7 +839,7 @@ bool MIRParser::ParseClassType(TyIdx &styidx) { return false; } } - MIRClassType classType(tkind); + MIRClassType classType(tkind, strIdx); classType.SetParentTyIdx(parentTypeIdx); if (!ParseFields(classType)) { return false; @@ -872,7 +872,7 @@ bool MIRParser::ParseClassType(TyIdx &styidx) { return true; } -bool MIRParser::ParseInterfaceType(TyIdx &sTyIdx) { +bool MIRParser::ParseInterfaceType(TyIdx &sTyIdx, const GStrIdx &strIdx) { MIRTypeKind tkind = (lexer.GetTokenKind() == TK_interface) ? kTypeInterface : kTypeInterfaceIncomplete; std::vector parents; TokenKind tk = lexer.NextToken(); @@ -886,7 +886,7 @@ bool MIRParser::ParseInterfaceType(TyIdx &sTyIdx) { parents.push_back(parentTypeIdx); tk = lexer.GetTokenKind(); } - MIRInterfaceType interfaceType(tkind); + MIRInterfaceType interfaceType(tkind, strIdx); interfaceType.SetParentsTyIdx(parents); if (!ParseFields(interfaceType)) { return false; @@ -1249,7 +1249,7 @@ bool MIRParser::ParseFuncType(TyIdx &tyIdx) { Error("expect return type for function type but get "); return false; } - MIRFuncType functype(retTyIdx, vecTyIdx, vecAttrs, mod.GetMPAllocator()); + MIRFuncType functype(retTyIdx, vecTyIdx, vecAttrs); functype.SetVarArgs(varargs); tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&functype); return true; @@ -1289,7 +1289,7 @@ bool MIRParser::ParseGenericInstantVector(MIRInstantVectorType &insVecType) { return false; } -bool MIRParser::ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind) { +bool MIRParser::ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind, const GStrIdx &strIdx) { if (lexer.GetTokenKind() != TK_langle) { Error("expect langle but get "); return false; @@ -1318,21 +1318,21 @@ bool MIRParser::ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind) { case TK_struct: // struct type case TK_structincomplete: // structincomplete type case TK_union: // union type - if (!ParseStructType(tyIdx)) { + if (!ParseStructType(tyIdx, strIdx)) { Error("struct/union type wrong when parsing derived type at "); return false; } break; case TK_class: // class type case TK_classincomplete: - if (!ParseClassType(tyIdx)) { + if (!ParseClassType(tyIdx, strIdx)) { Error("class type wrong when parsing derived type at "); return false; } break; case TK_interface: // interface type case TK_interfaceincomplete: - if (!ParseInterfaceType(tyIdx)) { + if (!ParseInterfaceType(tyIdx, strIdx)) { Error("interface type wrong when parsing derived type at "); return false; } @@ -1514,7 +1514,7 @@ bool MIRParser::ParseTypedef() { Error("expect primitive type after typedef but get "); return false; } - } else if (!ParseDerivedType(tyIdx, kTypeUnknown)) { + } else if (!ParseDerivedType(tyIdx, kTypeUnknown, strIdx)) { Error("error passing derived type at "); return false; } @@ -1525,17 +1525,12 @@ bool MIRParser::ParseTypedef() { mod.CurFunction()->SetGStrIdxToTyIdx(strIdx, tyIdx); ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetNameStrIdx() == 0u) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameStrIdx(strIdx); GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameIsLocal(true); } } else { prevTyIdx = mod.GetTypeNameTab()->GetTyIdxFromGStrIdx(strIdx); mod.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyIdx); mod.PushbackTypeDefOrder(strIdx); - ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); - if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetNameStrIdx() == 0u) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameStrIdx(strIdx); - } } if (prevTyIdx != TyIdx(0) && prevTyIdx != tyIdx) { @@ -1849,7 +1844,7 @@ bool MIRParser::ParsePrototype(MIRFunction &func, MIRSymbol &funcSymbol, TyIdx & MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); func.SetReturnStruct(*retType); MIRType *funcType = - GlobalTables::GetTypeTable().GetOrCreateFunctionType(mod, tyIdx, vecTy, vecAt, varArgs, false); + GlobalTables::GetTypeTable().GetOrCreateFunctionType(tyIdx, vecTy, vecAt, varArgs); funcTyIdx = funcType->GetTypeIndex(); funcSymbol.SetTyIdx(funcTyIdx); func.SetMIRFuncType(static_cast(funcType)); diff --git a/src/mapleall/maple_me/src/ipa_side_effect.cpp b/src/mapleall/maple_me/src/ipa_side_effect.cpp index 8095e1a6aa4715248702105c8425d44bea2af65b..68dc662be8bd74f8fb155fb22c47a81577eb910e 100644 --- a/src/mapleall/maple_me/src/ipa_side_effect.cpp +++ b/src/mapleall/maple_me/src/ipa_side_effect.cpp @@ -932,7 +932,8 @@ bool IpaSideEffect::UpdateSideEffectWithStmt(MeStmt &meStmt, case OP_interfaceicallassigned: case OP_customcallassigned: case OP_polymorphiccallassigned: - case OP_icallassigned: { + case OP_icallassigned: + case OP_superclasscallassigned: { hasPrivateDef = hasThrException = true; SetHasDef(); for (size_t i = 0; i < meStmt.NumMeStmtOpnds(); ++i) { diff --git a/src/mplfe/common/src/fe_type_manager.cpp b/src/mplfe/common/src/fe_type_manager.cpp index 599d7f00e885402299179de86d93d09dc9dcf818..2ecd786738f7a7b653e809f51ef08ca84db77b58 100644 --- a/src/mplfe/common/src/fe_type_manager.cpp +++ b/src/mplfe/common/src/fe_type_manager.cpp @@ -469,8 +469,7 @@ MIRFunction *FETypeManager::CreateFunction(const GStrIdx &nameIdx, const TyIdx & argsAttr.emplace_back(TypeAttrs()); } mirFunc->SetBaseClassFuncNames(nameIdx); - funcSymbol->SetTyIdx(GlobalTables::GetTypeTable().GetOrCreateFunctionType(module, retTypeIdx, - argsTypeIdx, argsAttr, + funcSymbol->SetTyIdx(GlobalTables::GetTypeTable().GetOrCreateFunctionType(retTypeIdx, argsTypeIdx, argsAttr, isVarg)->GetTypeIndex()); funcSymbol->SetFunction(mirFunc); MIRFuncType *functype = static_cast(funcSymbol->GetType());