diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index af146aba35591389b90faf8dc5778d2dff1325cb..85c8dc5d9f078ebcd85a80c5066121df18a98fd9 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 3f7553b0a8ac9a6a9b324462c499046b091cc846..45d9757b35beae3cdf0314d827b7dec13b410171 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 90b77d87903d009cf1f1e8d79dee6e8504533b7b..c1e0b8225bb2efd214e5d44dc9a342de93aa60c8 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 65b7f3c8074565972961a0f2e20af50e8ace5cb4..1bcaa04f6ae14b0deb8327b48aef6b4f1fd94a04 100644 --- a/src/mapleall/maple_be/BUILD.gn +++ b/src/mapleall/maple_be/BUILD.gn @@ -25,8 +25,9 @@ include_directories = [ "${MAPLEALL_ROOT}/mempool/include", "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_phase/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", "${MAPLE_ROOT}/third_party/dwarf/include", + "//../ThirdParty/bounds_checking_function/include" ] deps_libcg = [] @@ -225,7 +226,7 @@ executable("maplegen") { "${MAPLEALL_ROOT}/maple_be/mdgen/src/mdrecord.cpp", ] deps = [ - "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", + "//../ThirdParty/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/mempool:libmempool", "${MAPLEALL_ROOT}/maple_util:libmplutil", ] @@ -236,6 +237,6 @@ executable("maplegen") { "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] } diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index caaef19a8cd93e8f97e70b7c71013bfd4a7df761..9e7c56f8d57c767f4e57756263bb483c32ef09fe 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -180,7 +180,7 @@ BaseNode *CGLowerer::LowerIaddrof(const IreadNode &iaddrof) { uint32 loweredPtrType = static_cast(LOWERED_PTR_TYPE); MIRIntConst *offsetConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - offset, *GlobalTables::GetTypeTable().GetTypeTable().at(loweredPtrType), 0 /* fieldID */); + offset, *GlobalTables::GetTypeTable().GetTypeTable().at(loweredPtrType)); BaseNode *offsetNode = mirModule.CurFuncCodeMemPool()->New(offsetConst); offsetNode->SetPrimType(LOWERED_PTR_TYPE); @@ -348,7 +348,7 @@ BaseNode *CGLowerer::LowerFarray(ArrayNode &array) { } MIRIntConst *eleConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(eleOffset, arrayType, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(eleOffset, arrayType); BaseNode *offsetNode = mirModule.CurFuncCodeMemPool()->New(eleConst); offsetNode->SetPrimType(array.GetPrimType()); @@ -366,11 +366,11 @@ BaseNode *CGLowerer::LowerFarray(ArrayNode &array) { if ((farrayType->GetKind() == kTypeJArray) && (resNode->GetOpCode() == OP_constval)) { ConstvalNode *idxNode = static_cast(resNode); int64 idx = safe_cast(idxNode->GetConstVal())->GetValue(); - MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx * eSize, arrayType, 0 /* fieldID */); + MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx * eSize, arrayType); rMul = mirModule.CurFuncCodeMemPool()->New(eConst); rMul->SetPrimType(array.GetPrimType()); } else { - MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(eSize, arrayType, 0 /* fieldID */); + MIRIntConst *eConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(eSize, arrayType); BaseNode *eSizeNode = mirModule.CurFuncCodeMemPool()->New(eConst); eSizeNode->SetPrimType(array.GetPrimType()); rMul = mirModule.CurFuncCodeMemPool()->New(OP_mul); @@ -384,7 +384,7 @@ BaseNode *CGLowerer::LowerFarray(ArrayNode &array) { if (farrayType->GetKind() == kTypeJArray) { BaseNode *jarrayBaseNode = mirModule.CurFuncCodeMemPool()->New(OP_add); MIRIntConst *arrayHeaderNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(AArch64RTSupport::kArrayContentOffset), arrayType, 0 /* fieldID */); + static_cast(AArch64RTSupport::kArrayContentOffset), arrayType); BaseNode *arrayHeaderCstNode = mirModule.CurFuncCodeMemPool()->New(arrayHeaderNode); arrayHeaderCstNode->SetPrimType(array.GetPrimType()); jarrayBaseNode->SetPrimType(array.GetPrimType()); @@ -484,7 +484,7 @@ BaseNode *CGLowerer::LowerArray(ArrayNode &array, const BaseNode &parent) { ConstvalNode *idxNode = static_cast(resNode); int64 idx = safe_cast(idxNode->GetConstVal())->GetValue(); MIRIntConst *eConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx * eSize, arrayTypes, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx * eSize, arrayTypes); rMul = mirModule.CurFuncCodeMemPool()->New(eConst); rMul->SetPrimType(array.GetPrimType()); if (dim == 1) { @@ -492,7 +492,7 @@ BaseNode *CGLowerer::LowerArray(ArrayNode &array, const BaseNode &parent) { } } else { MIRIntConst *eConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(eSize, arrayTypes, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(eSize, arrayTypes); BaseNode *tmpNode = mirModule.CurFuncCodeMemPool()->New(eConst); tmpNode->SetPrimType(array.GetPrimType()); rMul = mirModule.CurFuncCodeMemPool()->New(OP_mul); @@ -692,7 +692,7 @@ BaseNode *CGLowerer::LowerDreadBitfield(DreadNode &dread) { "LowerIassignBitField: subscript out of range"); MIRType &type = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(loweredPtrType); constNode->SetConstVal( - GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, type, 0 /* fieldID */)); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, type)); BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); addNode->SetPrimType(LOWERED_PTR_TYPE); @@ -749,7 +749,7 @@ BaseNode *CGLowerer::LowerIreadBitfield(IreadNode &iread) { uint32 loweredPtrType = static_cast(LOWERED_PTR_TYPE); MIRType &mirType = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(loweredPtrType); constNode->SetConstVal( - GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0 /* fieldID */)); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType)); BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); addNode->SetPrimType(LOWERED_PTR_TYPE); @@ -885,7 +885,7 @@ StmtNode *CGLowerer::LowerDassignBitfield(DassignNode &dassign, BlockNode &newBl "LowerIassignBitField: subscript out of range"); MIRType &mirType = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(loweredPtrType); constNode->SetConstVal( - GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0 /* fieldID */)); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType)); BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); addNode->SetPrimType(LOWERED_PTR_TYPE); @@ -956,7 +956,7 @@ StmtNode *CGLowerer::LowerIassignBitfield(IassignNode &iassign, BlockNode &newBl uint32 loweredPtrType = static_cast(LOWERED_PTR_TYPE); MIRType &mirType = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(loweredPtrType); constNode->SetConstVal( - GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType, 0 /* fieldID */)); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(byteBitOffsets.first, mirType)); BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); addNode->SetPrimType(LOWERED_PTR_TYPE); @@ -1927,7 +1927,7 @@ BaseNode *CGLowerer::MergeToCvtType(PrimType dType, PrimType sType, BaseNode &sr IreadNode &CGLowerer::GetLenNode(BaseNode &opnd0) { MIRIntConst *arrayHeaderNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( static_cast(AArch64RTSupport::kArrayLengthOffset), - *GlobalTables::GetTypeTable().GetTypeFromTyIdx(opnd0.GetPrimType()), 0 /* fieldID */); + *GlobalTables::GetTypeTable().GetTypeFromTyIdx(opnd0.GetPrimType())); BaseNode *arrayHeaderCstNode = mirModule.CurFuncCodeMemPool()->New(arrayHeaderNode); arrayHeaderCstNode->SetPrimType(opnd0.GetPrimType()); MIRType *addrType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(opnd0.GetPrimType()); @@ -2162,7 +2162,7 @@ void CGLowerer::LowerResetStmt(StmtNode &stmt, BlockNode &block) { UnaryStmtNode &unaryStmtNode = static_cast(stmt); AddrofNode *addrofNode = static_cast(unaryStmtNode.GetRHS()); MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(PTY_ref); - MIRConst *constVal = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); + MIRConst *constVal = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); ConstvalNode *exprConst = mirModule.CurFuncCodeMemPool()->New(); exprConst->SetPrimType(type.GetPrimType()); exprConst->SetConstVal(constVal); @@ -2403,7 +2403,7 @@ BaseNode *CGLowerer::LowerIntrinJavaArrayLength(const BaseNode &parent, Intrinsi ((parent.GetOpCode() == OP_regassign) || (parent.GetOpCode() == OP_dassign) || (parent.GetOpCode() == OP_ge))) { MIRType *addrType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(arrAddr->GetPrimType())); MIRIntConst *arrayHeaderNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(AArch64RTSupport::kArrayLengthOffset), *addrType, 0 /* fieldID */); + static_cast(AArch64RTSupport::kArrayLengthOffset), *addrType); BaseNode *arrayHeaderCstNode = mirModule.CurFuncCodeMemPool()->New(arrayHeaderNode); arrayHeaderCstNode->SetPrimType(arrAddr->GetPrimType()); @@ -2922,7 +2922,7 @@ StmtNode *CGLowerer::LowerSyncEnterSyncExit(StmtNode &stmt) { /* Just as ParseNaryStmt do for syncenter */ MIRType &intType = *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_i32); /* default 2 for __sync_enter_fast() */ - MIRIntConst *intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(2, intType, 0 /* fieldID */); + MIRIntConst *intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(2, intType); ConstvalNode *exprConst = mirModule.GetMemPool()->New(); exprConst->SetPrimType(PTY_i32); exprConst->SetConstVal(intConst); diff --git a/src/mapleall/maple_be/src/be/switch_lowerer.cpp b/src/mapleall/maple_be/src/be/switch_lowerer.cpp index 4d240489d761a24a240ef387e3b024e20d8c11d8..59b1cc81a6a015ff31c088253c8a497c8c7aafbf 100644 --- a/src/mapleall/maple_be/src/be/switch_lowerer.cpp +++ b/src/mapleall/maple_be/src/be/switch_lowerer.cpp @@ -132,7 +132,7 @@ CompareNode *SwitchLowerer::BuildCmpNode(Opcode opCode, uint32 idx) { MIRType &type = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(stmt->GetSwitchOpnd()->GetPrimType())); MIRConst *constVal = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(stmt->GetCasePair(idx).first, type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(stmt->GetCasePair(idx).first, type); ConstvalNode *exprConst = mirModule.CurFuncCodeMemPool()->New(); exprConst->SetPrimType(stmt->GetSwitchOpnd()->GetPrimType()); exprConst->SetConstVal(constVal); 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 30dc17766aad0a90c2ed4bcc4e0016f06457a70c..0174782923a62dd1c3b2f3da6ec32148a60310cd 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -4116,7 +4116,7 @@ void AArch64CGFunc::SelectRangeGoto(RangeGotoNode &rangeGotoNode, Operand &srcOp LabelIdx labelIdx = itPair.second; GetCurBB()->PushBackRangeGotoLabel(labelIdx); MIRConst *mirConst = memPool->New(labelIdx, GetFunction().GetPuidx(), *etype); - arrayConst->PushBack(mirConst); + arrayConst->AddItem(mirConst, 0); } MIRSymbol *lblSt = GetFunction().GetSymTab()->CreateSymbol(kScopeLocal); diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index 114b4adf509f5d63168b310be00158e20c10c0a6..bcef38c68da47adde1c0215d1489a5fecd74d35a 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -1181,10 +1181,9 @@ void Emitter::EmitIntConst(const MIRSymbol &mirSymbol, MIRAggConst &aggConst, ui std::string reflectStrTabPrefix = isHotReflectStr ? hotStr : kReflectionStrtabPrefixStr; std::string strTabName = reflectStrTabPrefix + cg->GetMIRModule()->GetFileNameAsPostfix(); /* left shift 2 bit to get low 30 bit data for MIRIntConst */ - elemConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - index >> 2, elemConst->GetType(), elemConst->GetFieldId()); + elemConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(index >> 2, elemConst->GetType()); intConst = safe_cast(elemConst); - aggConst.SetConstVecItem(idx, *intConst); + aggConst.SetItem(idx, intConst, aggConst.GetFieldIdItem(idx)); #ifdef USE_32BIT_REF if (stName.find(ITAB_CONFLICT_PREFIX_STR) == 0) { EmitScalarConstant(*elemConst, false, true); @@ -1536,7 +1535,7 @@ void Emitter::EmitStructConstant(MIRConst &mirConst) { uint32 size = Globals::GetInstance()->GetBECommon()->GetTypeSize(structType.GetTypeIndex()); uint32 fieldIdx = 1; if (structType.GetKind() == kTypeUnion) { - fieldIdx = structCt.GetConstVecItem(0)->GetFieldId(); + fieldIdx = structCt.GetFieldIdItem(0); } for (uint32 i = 0; i < num; ++i) { if (((i + 1) == num) && cg->GetMIRModule()->GetSrcLang() == kSrcLangC) { @@ -1556,8 +1555,7 @@ void Emitter::EmitStructConstant(MIRConst &mirConst) { uint8 charBitWidth = GetPrimTypeSize(PTY_i8) * kBitsPerByte; if (elemType->GetKind() == kTypeBitField) { if (elemConst == nullptr) { - MIRIntConst *zeroFill = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *elemType, fieldIdx); - CHECK_FATAL(zeroFill->GetFieldId() == fieldIdx, "EmitStructConst: fieldID not set correctly"); + MIRIntConst *zeroFill = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *elemType); elemConst = zeroFill; } uint64 fieldOffset = @@ -1854,14 +1852,13 @@ void Emitter::MarkVtabOrItabEndFlag(const std::vector &mirSymbolVec) #ifdef USE_32BIT_REF /* #define COLD VTAB ITAB END FLAG 0X4000000000000000 */ tabConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(tabConst->GetValue()) | 0X40000000, tabConst->GetType(), tabConst->GetFieldId()); + static_cast(tabConst->GetValue()) | 0X40000000, tabConst->GetType()); #else /* #define COLD VTAB ITAB END FLAG 0X4000000000000000 */ tabConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(static_cast(tabConst->GetValue()) | 0X4000000000000000), - tabConst->GetType(), tabConst->GetFieldId()); + static_cast(static_cast(tabConst->GetValue()) | 0X4000000000000000), tabConst->GetType()); #endif - aggConst->SetConstVecItem(size - 1, *tabConst); + aggConst->SetItem(size - 1, tabConst, aggConst->GetFieldIdItem(size - 1)); } } } diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index 5c06347ddce2ae7e74351358c7db40fd40b7626f..e9983e02d5b8429d9021d158f389bb34cdd093f9 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -34,7 +34,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_phase/include", "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", "${MAPLE_ROOT}/third_party/dwarf_h/include", ] @@ -57,7 +57,7 @@ executable("maple") { deps = [ ":libdriver_option", ":liboption_parser", - "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", + "//../ThirdParty/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_be:libcg", "${MAPLEALL_ROOT}/maple_be:libmplad", "${MAPLEALL_ROOT}/maple_be:libmplbe", @@ -92,7 +92,7 @@ static_library("liboption_parser") { "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] output_dir = "${root_out_dir}/lib/${HOST_ARCH}" } diff --git a/src/mapleall/maple_ipa/BUILD.gn b/src/mapleall/maple_ipa/BUILD.gn index 74c85c121484b5198dbc89a897d3076bf06fc32a..9477325ed21041227ac8257d9e7a3f83fcb775ff 100755 --- a/src/mapleall/maple_ipa/BUILD.gn +++ b/src/mapleall/maple_ipa/BUILD.gn @@ -21,7 +21,7 @@ include_directories = [ "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/maple_phase/include", "${MAPLEALL_ROOT}/maple_driver/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] src_libmplipa = [ diff --git a/src/mapleall/maple_ir/BUILD.gn b/src/mapleall/maple_ir/BUILD.gn index 3b4dea929cc34350673e7dd99661c932cae71190..e8be8bc50561f6ac491db7a5dae301840aabdf0f 100755 --- a/src/mapleall/maple_ir/BUILD.gn +++ b/src/mapleall/maple_ir/BUILD.gn @@ -18,7 +18,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/maple_phase/include", @@ -78,7 +78,7 @@ executable("irbuild") { include_dirs = include_directories deps = [ ":libmplir", - "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", + "//../ThirdParty/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_driver:liboption_parser", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", "${MAPLEALL_ROOT}/maple_phase:libmplphase", @@ -94,7 +94,7 @@ executable("mpldbg") { include_dirs = include_directories deps = [ ":libmplir", - "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", + "//../ThirdParty/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_driver:liboption_parser", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", "${MAPLEALL_ROOT}/maple_phase:libmplphase", diff --git a/src/mapleall/maple_ir/include/bin_mpl_import.h b/src/mapleall/maple_ir/include/bin_mpl_import.h index 1970d73ba25621337d34d33e300050b3c7d37c70..5ea94e90b9bf605ab3918b1167568ff454f856a6 100644 --- a/src/mapleall/maple_ir/include/bin_mpl_import.h +++ b/src/mapleall/maple_ir/include/bin_mpl_import.h @@ -93,7 +93,7 @@ class BinaryMplImport { void InsertInHashTable(MIRType &ptype); void SetupEHRootType(); void UpdateMethodSymbols(); - void ImportConstBase(MIRConstKind &kind, MIRTypePtr &type, uint32 &fieldID); + void ImportConstBase(MIRConstKind &kind, MIRTypePtr &type); MIRConst *ImportConst(MIRFunction *func); GStrIdx ImportStr(); UStrIdx ImportUsrStr(); diff --git a/src/mapleall/maple_ir/include/global_tables.h b/src/mapleall/maple_ir/include/global_tables.h index 4d7ca4441d54dc82b1803e9076b51dbb5eae6ce6..666876a45b988f1e6dd9cdb88ed0dccf7d89e3a9 100644 --- a/src/mapleall/maple_ir/include/global_tables.h +++ b/src/mapleall/maple_ir/include/global_tables.h @@ -504,9 +504,9 @@ class FPConstTable { ~FPConstTable(); // get the const from floatConstTable or create a new one - MIRFloatConst *GetOrCreateFloatConst(float fval, uint32 fieldID); + MIRFloatConst *GetOrCreateFloatConst(float fval); // get the const from doubleConstTable or create a new one - MIRDoubleConst *GetOrCreateDoubleConst(double fval, uint32 fieldID); + MIRDoubleConst *GetOrCreateDoubleConst(double fval); static std::unique_ptr Create() { auto p = std::unique_ptr(new FPConstTable()); @@ -541,7 +541,7 @@ class IntConstTable { IntConstTable &operator=(const IntConstTable &p) = delete; ~IntConstTable(); - MIRIntConst *GetOrCreateIntConst(int64 val, MIRType &type, uint32 fieldID); + MIRIntConst *GetOrCreateIntConst(int64 val, MIRType &type); static std::unique_ptr Create() { auto p = std::unique_ptr(new IntConstTable()); @@ -550,8 +550,8 @@ class IntConstTable { private: IntConstTable() = default; - MIRIntConst *DoGetOrCreateIntConst(int64 val, MIRType &type, uint32 fieldID); - MIRIntConst *DoGetOrCreateIntConstTreadSafe(int64 val, MIRType &type, uint32 fieldID); + MIRIntConst *DoGetOrCreateIntConst(int64 val, MIRType &type); + MIRIntConst *DoGetOrCreateIntConstTreadSafe(int64 val, MIRType &type); std::shared_timed_mutex mtx; std::unordered_map intConstTable; }; diff --git a/src/mapleall/maple_ir/include/mir_const.h b/src/mapleall/maple_ir/include/mir_const.h index ee190922c9e3fdd57f5890c02a39a6e7b94b4ae0..3f08d5ba65e5afdfc176f4fc3bb88bebcc7f5d01 100644 --- a/src/mapleall/maple_ir/include/mir_const.h +++ b/src/mapleall/maple_ir/include/mir_const.h @@ -39,19 +39,13 @@ enum MIRConstKind { class MIRConst { public: - explicit MIRConst(MIRType &type, MIRConstKind constKind = kConstInvalid, uint32 fieldID = 0) - : type(&type), kind(constKind), fieldID(fieldID) {} + explicit MIRConst(MIRType &type, MIRConstKind constKind = kConstInvalid) + : type(&type), kind(constKind) {} virtual ~MIRConst() = default; - virtual void Dump(const MIRSymbolTable *localSymTab = nullptr) const; - - uint32 GetFieldId() const { - return fieldID; - } - - void SetFieldID(uint32 fieldIdx) { - fieldID = fieldIdx; + virtual void Dump(const MIRSymbolTable *localSymTab = nullptr) const { + (void)localSymTab; } virtual bool IsZero() const { @@ -94,15 +88,12 @@ class MIRConst { private: MIRType *type; MIRConstKind kind; - - protected: - uint32 fieldID; }; class MIRIntConst : public MIRConst { public: using value_type = int64; - MIRIntConst(int64 val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, kConstInt, fieldID), value(val) { + MIRIntConst(int64 val, MIRType &type) : MIRConst(type, kConstInt), value(val) { if (!IsPrimitiveDynType(type.GetPrimType())) { Trunc(GetPrimTypeBitSize(type.GetPrimType())); } @@ -163,11 +154,11 @@ class MIRIntConst : public MIRConst { class MIRAddrofConst : public MIRConst { public: - MIRAddrofConst(StIdx sy, FieldID fi, MIRType &ty, uint32 fieldID = 0) - : MIRConst(ty, kConstAddrof, fieldID), stIdx(sy), fldID(fi), offset(0) {} + MIRAddrofConst(StIdx sy, FieldID fi, MIRType &ty) + : MIRConst(ty, kConstAddrof), stIdx(sy), fldID(fi), offset(0) {} - MIRAddrofConst(StIdx sy, FieldID fi, MIRType &ty, int32 ofst, uint32 fieldID = 0) - : MIRConst(ty, kConstAddrof, fieldID), stIdx(sy), fldID(fi), offset(ofst) {} + MIRAddrofConst(StIdx sy, FieldID fi, MIRType &ty, int32 ofst) + : MIRConst(ty, kConstAddrof), stIdx(sy), fldID(fi), offset(ofst) {} ~MIRAddrofConst() = default; @@ -199,8 +190,8 @@ class MIRAddrofConst : public MIRConst { class MIRAddroffuncConst : public MIRConst { public: - MIRAddroffuncConst(PUIdx idx, MIRType &ty, uint32 fieldID = 0) - : MIRConst(ty, kConstAddrofFunc, fieldID), puIdx(idx) {} + MIRAddroffuncConst(PUIdx idx, MIRType &ty) + : MIRConst(ty, kConstAddrofFunc), puIdx(idx) {} ~MIRAddroffuncConst() = default; @@ -222,8 +213,8 @@ class MIRAddroffuncConst : public MIRConst { class MIRLblConst : public MIRConst { public: - MIRLblConst(LabelIdx val, PUIdx pidx, MIRType &type, uint32 fieldID = 0) - : MIRConst(type, kConstLblConst, fieldID), value(val), puIdx(pidx) {} + MIRLblConst(LabelIdx val, PUIdx pidx, MIRType &type) + : MIRConst(type, kConstLblConst), value(val), puIdx(pidx) {} ~MIRLblConst() = default; @@ -249,9 +240,9 @@ class MIRLblConst : public MIRConst { class MIRStrConst : public MIRConst { public: - MIRStrConst(UStrIdx val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, kConstStrConst, fieldID), value(val) {} + MIRStrConst(UStrIdx val, MIRType &type) : MIRConst(type, kConstStrConst), value(val) {} - MIRStrConst(const std::string &str, MIRType &type, uint32 fieldID = 0); + MIRStrConst(const std::string &str, MIRType &type); ~MIRStrConst() = default; @@ -277,10 +268,9 @@ class MIRStrConst : public MIRConst { class MIRStr16Const : public MIRConst { public: - MIRStr16Const(const U16StrIdx &val, MIRType &type, uint32 fieldID = 0) - : MIRConst(type, kConstStr16Const, fieldID), value(val) {} + MIRStr16Const(const U16StrIdx &val, MIRType &type) : MIRConst(type, kConstStr16Const), value(val) {} - MIRStr16Const(const std::u16string &str, MIRType &type, uint32 fieldID = 0); + MIRStr16Const(const std::u16string &str, MIRType &type); ~MIRStr16Const() = default; static PrimType GetPrimType() { @@ -306,7 +296,7 @@ class MIRStr16Const : public MIRConst { class MIRFloatConst : public MIRConst { public: using value_type = float; - MIRFloatConst(float val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, kConstFloatConst, fieldID) { + MIRFloatConst(float val, MIRType &type) : MIRConst(type, kConstFloatConst) { value.floatValue = val; } @@ -372,7 +362,7 @@ class MIRFloatConst : public MIRConst { class MIRDoubleConst : public MIRConst { public: using value_type = double; - MIRDoubleConst(double val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, kConstDoubleConst, fieldID) { + MIRDoubleConst(double val, MIRType &type) : MIRConst(type, kConstDoubleConst) { value.dValue = val; } @@ -439,8 +429,7 @@ class MIRDoubleConst : public MIRConst { class MIRFloat128Const : public MIRConst { public: - MIRFloat128Const(const uint64 &val, MIRType &type, uint32 fieldID = 0) - : MIRConst(type, kConstFloat128Const, fieldID) { + MIRFloat128Const(const uint64 &val, MIRType &type) : MIRConst(type, kConstFloat128Const) { value = &val; } @@ -484,23 +473,27 @@ class MIRFloat128Const : public MIRConst { class MIRAggConst : public MIRConst { public: - MIRAggConst(MIRModule &mod, MIRType &type, uint32 fieldID = 0) - : MIRConst(type, kConstAggConst, fieldID), constVec(mod.GetMPAllocator().Adapter()) {} + MIRAggConst(MIRModule &mod, MIRType &type) + : MIRConst(type, kConstAggConst), + constVec(mod.GetMPAllocator().Adapter()), + fieldIdVec(mod.GetMPAllocator().Adapter()) {} ~MIRAggConst() = default; MIRConst *GetAggConstElement(unsigned int fieldidx) { - for (size_t i = 0; i < constVec.size(); ++i) { - if (constVec[i] == nullptr) { - CHECK_FATAL(false, "exist nullptr in constVec"); - } - if (fieldidx == constVec[i]->GetFieldId()) { + for (size_t i = 0; i < fieldIdVec.size(); ++i) { + if (fieldidx == fieldIdVec[i]) { return constVec[i]; } } return nullptr; } + void SetFieldIdOfElement(uint32 index, uint32 fieldId) { + ASSERT(index < fieldIdVec.size(), "index out of range"); + fieldIdVec[index] = fieldId; + } + const MapleVector &GetConstVec() const { return constVec; } @@ -519,12 +512,24 @@ class MIRAggConst : public MIRConst { return constVec[index]; } - void SetConstVecItem(uint32 index, MIRConst &mirConst) { + uint32 GetFieldIdItem(size_t index) const { + ASSERT(index < fieldIdVec.size(), "index out of range"); + return fieldIdVec[index]; + } + + void SetItem(uint32 index, MIRConst *mirConst, uint32 fieldId) { CHECK_FATAL(index < constVec.size(), "index out of range"); - constVec[index] = &mirConst; + constVec[index] = mirConst; + fieldIdVec[index] = fieldId; } + + void AddItem(MIRConst *mirConst, uint32 fieldId) { + constVec.push_back(mirConst); + fieldIdVec.push_back(fieldId); + } + void PushBack(MIRConst *elem) { - constVec.push_back(elem); + AddItem(elem, 0); } void Dump(const MIRSymbolTable *localSymTab) const override; @@ -536,13 +541,14 @@ class MIRAggConst : public MIRConst { private: MapleVector constVec; + MapleVector fieldIdVec; }; // the const has one or more symbols class MIRStConst : public MIRConst { public: - MIRStConst(MIRModule &mod, MIRType &type, uint32 fieldID = 0) - : MIRConst(type, kConstStConst, fieldID), + MIRStConst(MIRModule &mod, MIRType &type) + : MIRConst(type, kConstStConst), stVec(mod.GetMPAllocator().Adapter()), stOffsetVec(mod.GetMPAllocator().Adapter()) {} diff --git a/src/mapleall/maple_ir/include/mir_parser.h b/src/mapleall/maple_ir/include/mir_parser.h index 9782ff0ca025dfeb767c412a40e259c1b2df6fc3..74009f5ab98cb8dd4fcce651dbd70ac22633e436 100644 --- a/src/mapleall/maple_ir/include/mir_parser.h +++ b/src/mapleall/maple_ir/include/mir_parser.h @@ -54,7 +54,7 @@ class MIRParser { bool IsStatement(TokenKind tk) const; PrimType GetPrimitiveType(TokenKind tk) const; MIRIntrinsicID GetIntrinsicID(TokenKind tk) const; - bool ParseScalarValue(MIRConstPtr&, MIRType&, uint32 fieldID); + bool ParseScalarValue(MIRConstPtr&, MIRType&); bool ParseConstAddrLeafExpr(MIRConstPtr&); bool ParseInitValue(MIRConstPtr&, TyIdx, bool allowEmpty = false); bool ParseDeclaredSt(StIdx&); diff --git a/src/mapleall/maple_ir/src/bin_mpl_export.cpp b/src/mapleall/maple_ir/src/bin_mpl_export.cpp index 26e6aa9ff1614f7e4651d550f9bc42ebf59d7825..22bc6768270942bfcdb4cc01c8a7af96ba4354bf 100644 --- a/src/mapleall/maple_ir/src/bin_mpl_export.cpp +++ b/src/mapleall/maple_ir/src/bin_mpl_export.cpp @@ -106,6 +106,7 @@ void OutputConstAgg(const MIRConst &constVal, BinaryMplExport &mplExport) { size_t size = aggConst.GetConstVec().size(); mplExport.WriteNum(size); for (size_t i = 0; i < size; ++i) { + mplExport.WriteNum(aggConst.GetFieldIdItem(i)); mplExport.OutputConst(aggConst.GetConstVecItem(i)); } } @@ -396,7 +397,6 @@ void BinaryMplExport::DumpBuf(const std::string &name) { void BinaryMplExport::OutputConstBase(const MIRConst &constVal) { WriteNum(constVal.GetKind()); OutputTypeViaTypeName(constVal.GetType().GetTypeIndex()); - WriteNum(constVal.GetFieldId()); } void BinaryMplExport::OutputConst(MIRConst *constVal) { diff --git a/src/mapleall/maple_ir/src/bin_mpl_import.cpp b/src/mapleall/maple_ir/src/bin_mpl_import.cpp index 2ac33c8b175d7737052f81f717c5e0501244482f..b72991d35a1d767c9f8616491fe5ee7b9ab607f5 100644 --- a/src/mapleall/maple_ir/src/bin_mpl_import.cpp +++ b/src/mapleall/maple_ir/src/bin_mpl_import.cpp @@ -89,14 +89,10 @@ void BinaryMplImport::ReadFileAt(const std::string &name, int32 offset) { CHECK_FATAL(result == static_cast(size), "Error while reading the binary file: %s", name.c_str()); } -void BinaryMplImport::ImportConstBase(MIRConstKind &kind, MIRTypePtr &type, uint32 &fieldID) { +void BinaryMplImport::ImportConstBase(MIRConstKind &kind, MIRTypePtr &type) { kind = static_cast(ReadNum()); TyIdx tyidx = ImportType(); type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); - int64 tmp = ReadNum(); - CHECK_FATAL(tmp <= INT_MAX, "num out of range"); - CHECK_FATAL(tmp >= INT_MIN, "num out of range"); - fieldID = static_cast(tmp); } MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { @@ -107,40 +103,39 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { MIRConstKind kind; MIRType *type = nullptr; - uint32 fieldID; MemPool *memPool = (func == nullptr) ? mod.GetMemPool() : func->GetCodeMempool(); - ImportConstBase(kind, type, fieldID); + ImportConstBase(kind, type); switch (tag) { case kBinKindConstInt: - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(ReadNum(), *type, fieldID); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(ReadNum(), *type); case kBinKindConstAddrof: { MIRSymbol *sym = InSymbol(func); CHECK_FATAL(sym != nullptr, "null ptr check"); FieldID fi = ReadNum(); int32 ofst = ReadNum(); - return memPool->New(sym->GetStIdx(), fi, *type, ofst, fieldID); + return memPool->New(sym->GetStIdx(), fi, *type, ofst); } case kBinKindConstAddrofLocal: { uint32 fullidx = ReadNum(); FieldID fi = ReadNum(); int32 ofst = ReadNum(); - return memPool->New(StIdx(fullidx), fi, *type, ofst, fieldID); + return memPool->New(StIdx(fullidx), fi, *type, ofst); } case kBinKindConstAddrofFunc: { PUIdx puIdx = ImportFunction(); - return memPool->New(puIdx, *type, fieldID); + return memPool->New(puIdx, *type); } case kBinKindConstAddrofLabel: { LabelIdx lidx = ReadNum(); PUIdx puIdx = func->GetPuidx(); - MIRLblConst *lblConst = memPool->New(lidx, puIdx, *type, fieldID); + MIRLblConst *lblConst = memPool->New(lidx, puIdx, *type); (void)func->GetLabelTab()->addrTakenLabels.insert(lidx); return lblConst; } case kBinKindConstStr: { UStrIdx ustr = ImportUsrStr(); - return memPool->New(ustr, *type, fieldID); + return memPool->New(ustr, *type); } case kBinKindConstStr16: { Conststr16Node *cs; @@ -154,7 +149,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { std::u16string str16; (void)namemangler::UTF8ToUTF16(str16, ostr.str()); cs->SetStrIdx(GlobalTables::GetU16StrTable().GetOrCreateStrIdxFromName(str16)); - return memPool->New(cs->GetStrIdx(), *type, fieldID); + return memPool->New(cs->GetStrIdx(), *type); } case kBinKindConstFloat: { union { @@ -163,7 +158,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { } value; value.ivalue = ReadNum(); - return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(value.fvalue, fieldID); + return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(value.fvalue); } case kBinKindConstDouble: { union { @@ -172,18 +167,20 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { } value; value.ivalue = ReadNum(); - return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(value.dvalue, fieldID); + return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(value.dvalue); } case kBinKindConstAgg: { - MIRAggConst *aggConst = mod.GetMemPool()->New(mod, *type, fieldID); + MIRAggConst *aggConst = mod.GetMemPool()->New(mod, *type); int64 size = ReadNum(); for (int64 i = 0; i < size; ++i) { - aggConst->PushBack(ImportConst(func)); + auto fieldId = static_cast(ReadInt64()); + auto fieldConst = ImportConst(func); + aggConst->AddItem(fieldConst, fieldId); } return aggConst; } case kBinKindConstSt: { - MIRStConst *stConst = mod.GetMemPool()->New(mod, *type, fieldID); + MIRStConst *stConst = mod.GetMemPool()->New(mod, *type); int64 size = ReadNum(); for (int64 i = 0; i < size; ++i) { stConst->PushbackSymbolToSt(InSymbol(func)); diff --git a/src/mapleall/maple_ir/src/global_tables.cpp b/src/mapleall/maple_ir/src/global_tables.cpp index 60a06942bdd2b8f85e0bbc7fb2e597a9792c7ba5..4de8a15012c688ffc09df8acfc43602b89a7c4e8 100644 --- a/src/mapleall/maple_ir/src/global_tables.cpp +++ b/src/mapleall/maple_ir/src/global_tables.cpp @@ -262,25 +262,25 @@ void FPConstTable::PostInit() { minusZeroDoubleConst = new MIRDoubleConst(-0.0, typeDouble); } -MIRIntConst *IntConstTable::GetOrCreateIntConst(int64 val, MIRType &type, uint32 fieldID) { +MIRIntConst *IntConstTable::GetOrCreateIntConst(int64 val, MIRType &type) { if (ThreadEnv::IsMeParallel()) { - return DoGetOrCreateIntConstTreadSafe(val, type, fieldID); + return DoGetOrCreateIntConstTreadSafe(val, type); } - return DoGetOrCreateIntConst(val, type, fieldID); + return DoGetOrCreateIntConst(val, type); } -MIRIntConst *IntConstTable::DoGetOrCreateIntConst(int64 val, MIRType &type, uint32 fieldID) { - uint64 idid = static_cast(type.GetTypeIndex()) + (static_cast(fieldID) << 32); // shift bit is 32 +MIRIntConst *IntConstTable::DoGetOrCreateIntConst(int64 val, MIRType &type) { + uint64 idid = static_cast(type.GetTypeIndex()); // shift bit is 32 IntConstKey key(val, idid); if (intConstTable.find(key) != intConstTable.end()) { return intConstTable[key]; } - intConstTable[key] = new MIRIntConst(val, type, fieldID); + intConstTable[key] = new MIRIntConst(val, type); return intConstTable[key]; } -MIRIntConst *IntConstTable::DoGetOrCreateIntConstTreadSafe(int64 val, MIRType &type, uint32 fieldID) { - uint64 idid = static_cast(type.GetTypeIndex()) + (static_cast(fieldID) << 32); // shift bit is 32 +MIRIntConst *IntConstTable::DoGetOrCreateIntConstTreadSafe(int64 val, MIRType &type) { + uint64 idid = static_cast(type.GetTypeIndex()); // shift bit is 32 IntConstKey key(val, idid); { std::shared_lock lock(mtx); @@ -289,7 +289,7 @@ MIRIntConst *IntConstTable::DoGetOrCreateIntConstTreadSafe(int64 val, MIRType &t } } std::unique_lock lock(mtx); - intConstTable[key] = new MIRIntConst(val, type, fieldID); + intConstTable[key] = new MIRIntConst(val, type); return intConstTable[key]; } @@ -299,12 +299,7 @@ IntConstTable::~IntConstTable() { } } -MIRFloatConst *FPConstTable::GetOrCreateFloatConst(float floatVal, uint32 fieldID) { - if (fieldID != 0) { - MIRFloatConst *fconst = - new MIRFloatConst(floatVal, *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f32), fieldID); - return fconst; - } +MIRFloatConst *FPConstTable::GetOrCreateFloatConst(float floatVal) { if (std::isnan(floatVal)) { return nanFloatConst; } @@ -348,12 +343,7 @@ MIRFloatConst *FPConstTable::DoGetOrCreateFloatConstThreadSafe(float floatVal) { return floatConst; } -MIRDoubleConst *FPConstTable::GetOrCreateDoubleConst(double doubleVal, uint32 fieldID) { - if (fieldID != 0) { - MIRDoubleConst *dconst = - new MIRDoubleConst(doubleVal, *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f64), fieldID); - return dconst; - } +MIRDoubleConst *FPConstTable::GetOrCreateDoubleConst(double doubleVal) { if (std::isnan(doubleVal)) { return nanDoubleConst; } diff --git a/src/mapleall/maple_ir/src/mir_builder.cpp b/src/mapleall/maple_ir/src/mir_builder.cpp index ae3c1674d727ab126d7a65f99a4821084d6852cd..e8324121ac0d3acda612c5f22a0de3a903ccb646 100644 --- a/src/mapleall/maple_ir/src/mir_builder.cpp +++ b/src/mapleall/maple_ir/src/mir_builder.cpp @@ -20,8 +20,8 @@ namespace maple { // This is for compiler-generated metadata 1-level struct void MIRBuilder::AddIntFieldConst(const MIRStructType &sType, MIRAggConst &newConst, uint32 fieldID, int64 constValue) { auto *fieldConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - constValue, *sType.GetElemType(fieldID - 1), fieldID); - newConst.PushBack(fieldConst); + constValue, *sType.GetElemType(fieldID - 1)); + newConst.AddItem(fieldConst, fieldID); } // This is for compiler-generated metadata 1-level struct @@ -30,8 +30,7 @@ void MIRBuilder::AddAddrofFieldConst(const MIRStructType &structType, MIRAggCons AddrofNode *fieldExpr = CreateExprAddrof(0, fieldSymbol, mirModule->GetMemPool()); auto *fieldConst = mirModule->GetMemPool()->New(fieldExpr->GetStIdx(), fieldExpr->GetFieldID(), *structType.GetElemType(fieldID - 1)); - fieldConst->SetFieldID(fieldID); - newConst.PushBack(fieldConst); + newConst.AddItem(fieldConst, fieldID); } // This is for compiler-generated metadata 1-level struct @@ -40,14 +39,14 @@ void MIRBuilder::AddAddroffuncFieldConst(const MIRStructType &structType, MIRAgg MIRConst *fieldConst = nullptr; MIRFunction *vMethod = funcSymbol.GetFunction(); if (vMethod->IsAbstract()) { - fieldConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *structType.GetElemType(fieldID - 1), fieldID); + fieldConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *structType.GetElemType(fieldID - 1)); } else { AddroffuncNode *addrofFuncExpr = CreateExprAddroffunc(funcSymbol.GetFunction()->GetPuidx(), mirModule->GetMemPool()); fieldConst = mirModule->GetMemPool()->New(addrofFuncExpr->GetPUIdx(), - *structType.GetElemType(fieldID - 1), fieldID); + *structType.GetElemType(fieldID - 1)); } - newConst.PushBack(fieldConst); + newConst.AddItem(fieldConst, fieldID); } // fieldID is continuously being updated during traversal; @@ -478,8 +477,7 @@ ConstvalNode *MIRBuilder::CreateConstval(MIRConst *mirConst) { ConstvalNode *MIRBuilder::CreateIntConst(int64 val, PrimType pty) { auto *mirConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetPrimType(pty), - 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetPrimType(pty)); return GetCurrentFuncCodeMp()->New(pty, mirConst); } @@ -502,8 +500,7 @@ ConstvalNode *MIRBuilder::CreateFloat128Const(const uint64 *val) { } ConstvalNode *MIRBuilder::GetConstInt(MemPool &memPool, int val) { - auto *mirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetInt64(), - 0 /* fieldID */); + auto *mirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetInt64()); return memPool.New(PTY_i32, mirConst); } diff --git a/src/mapleall/maple_ir/src/mir_const.cpp b/src/mapleall/maple_ir/src/mir_const.cpp index 3a45856eb80c26f259f00c88e6aa501fade17d1f..f7b4e8974a5c8330ff1f12e11dbca1da93f52c6e 100644 --- a/src/mapleall/maple_ir/src/mir_const.cpp +++ b/src/mapleall/maple_ir/src/mir_const.cpp @@ -21,15 +21,7 @@ #if MIR_FEATURE_FULL namespace maple { -void MIRConst::Dump(const MIRSymbolTable *localSymTab) const { - (void)localSymTab; - if (fieldID) { - LogInfo::MapleLogger() << fieldID << "= "; - } -} - -void MIRIntConst::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); +void MIRIntConst::Dump(const MIRSymbolTable*) const { constexpr int64 valThreshold = 1024; if (value <= valThreshold) { LogInfo::MapleLogger() << value; @@ -89,7 +81,6 @@ int64 MIRIntConst::GetValueUnderType() const { } void MIRAddrofConst::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); LogInfo::MapleLogger() << "addrof " << GetPrimTypeName(PTY_ptr); const MIRSymbol *sym = stIdx.IsGlobal() ? GlobalTables::GetGsymTable().GetSymbolFromStidx(stIdx.Idx()) : localSymTab->GetSymbolFromStIdx(stIdx.Idx()); @@ -118,8 +109,7 @@ bool MIRAddrofConst::operator==(const MIRConst &rhs) const { return (stIdx == rhsA.stIdx) && (fldID == rhsA.fldID); } -void MIRAddroffuncConst::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); +void MIRAddroffuncConst::Dump(const MIRSymbolTable*) const { LogInfo::MapleLogger() << "addroffunc " << GetPrimTypeName(PTY_ptr); MIRFunction *func = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puIdx); LogInfo::MapleLogger() << " &" << GlobalTables::GetGsymTable().GetSymbolFromStidx(func->GetStIdx().Idx())->GetName(); @@ -136,8 +126,7 @@ bool MIRAddroffuncConst::operator==(const MIRConst &rhs) const { return (&GetType() == &rhs.GetType()) && (puIdx == rhsAf.puIdx); } -void MIRLblConst::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); +void MIRLblConst::Dump(const MIRSymbolTable*) const { LogInfo::MapleLogger() << "addroflabel " << GetPrimTypeName(PTY_ptr); MIRFunction *func = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puIdx); LogInfo::MapleLogger() << " @" << func->GetLabelName(value); @@ -221,19 +210,16 @@ bool MIRAggConst::operator==(const MIRConst &rhs) const { return true; } -void MIRFloatConst::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); +void MIRFloatConst::Dump(const MIRSymbolTable*) const { LogInfo::MapleLogger() << std::setprecision(std::numeric_limits::max_digits10) << value.floatValue << "f"; } -void MIRDoubleConst::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); +void MIRDoubleConst::Dump(const MIRSymbolTable*) const { LogInfo::MapleLogger() << std::setprecision(std::numeric_limits::max_digits10) << value.dValue; } -void MIRFloat128Const::Dump(const MIRSymbolTable *localSymTab) const { +void MIRFloat128Const::Dump(const MIRSymbolTable*) const { constexpr int fieldWidth = 16; - MIRConst::Dump(localSymTab); std::ios::fmtflags f(LogInfo::MapleLogger().flags()); LogInfo::MapleLogger().setf(std::ios::uppercase); LogInfo::MapleLogger() << "0xL" << std::hex << std::setfill('0') << std::setw(fieldWidth) << value[0] @@ -242,10 +228,12 @@ void MIRFloat128Const::Dump(const MIRSymbolTable *localSymTab) const { } void MIRAggConst::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); LogInfo::MapleLogger() << "["; size_t size = constVec.size(); for (size_t i = 0; i < size; ++i) { + if (fieldIdVec[i] != 0) { + LogInfo::MapleLogger() << fieldIdVec[i] << "= "; + } constVec[i]->Dump(localSymTab); if (i != size - 1) { LogInfo::MapleLogger() << ", "; @@ -254,11 +242,10 @@ void MIRAggConst::Dump(const MIRSymbolTable *localSymTab) const { LogInfo::MapleLogger() << "]"; } -MIRStrConst::MIRStrConst(const std::string &str, MIRType &type, uint32 fieldID) - : MIRConst(type, kConstStrConst, fieldID), value(GlobalTables::GetUStrTable().GetOrCreateStrIdxFromName(str)) {} +MIRStrConst::MIRStrConst(const std::string &str, MIRType &type) + : MIRConst(type, kConstStrConst), value(GlobalTables::GetUStrTable().GetOrCreateStrIdxFromName(str)) {} -void MIRStrConst::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); +void MIRStrConst::Dump(const MIRSymbolTable*) const { LogInfo::MapleLogger() << "conststr " << GetPrimTypeName(GetType().GetPrimType()); const std::string &dumpStr = GlobalTables::GetUStrTable().GetStringFromStrIdx(value); PrintString(dumpStr); @@ -275,12 +262,11 @@ bool MIRStrConst::operator==(const MIRConst &rhs) const { return (&rhs.GetType() == &GetType()) && (value == rhsCs.value); } -MIRStr16Const::MIRStr16Const(const std::u16string &str, MIRType &type, uint32 fieldID) - : MIRConst(type, kConstStr16Const, fieldID), +MIRStr16Const::MIRStr16Const(const std::u16string &str, MIRType &type) + : MIRConst(type, kConstStr16Const), value(GlobalTables::GetU16StrTable().GetOrCreateStrIdxFromName(str)) {} -void MIRStr16Const::Dump(const MIRSymbolTable *localSymTab) const { - MIRConst::Dump(localSymTab); +void MIRStr16Const::Dump(const MIRSymbolTable*) const { LogInfo::MapleLogger() << "conststr16 " << GetPrimTypeName(GetType().GetPrimType()); std::u16string str16 = GlobalTables::GetU16StrTable().GetStringFromStrIdx(value); // UTF-16 string are dumped as UTF-8 string in mpl to keep the printable chars in ascii form diff --git a/src/mapleall/maple_ir/src/mir_nodes.cpp b/src/mapleall/maple_ir/src/mir_nodes.cpp index c02fe724b3954924e594fa514b21d7c6d06641bb..2be22a775df938e279e258a65bfaccc2c6c5d440 100644 --- a/src/mapleall/maple_ir/src/mir_nodes.cpp +++ b/src/mapleall/maple_ir/src/mir_nodes.cpp @@ -465,7 +465,7 @@ MIRType *ArrayNode::GetArrayType(const TypeTable &tt) { const BaseNode *ArrayNode::GetDim(const MIRModule &mod, TypeTable &tt, int i) const { const auto *arrayType = static_cast(GetArrayType(tt)); auto *mirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - i, *tt.GetTypeFromTyIdx(arrayType->GetElemTyIdx()), 0 /* fieldID */); + i, *tt.GetTypeFromTyIdx(arrayType->GetElemTyIdx())); return mod.CurFuncCodeMemPool()->New(mirConst); } BaseNode *ArrayNode::GetDim(const MIRModule &mod, TypeTable &tt, int i) { diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index a7c5b5980145d35df759ce23e9d903a94913f8eb..30a7cd60f4a4f6f64acec3b70d82411e93d4e5ca 100644 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -1311,7 +1311,7 @@ bool MIRParser::ParseNaryStmt(StmtNodePtr &stmt, Opcode op) { } else { MIRType *intType = GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_i32); // default 2 for __sync_enter_fast() - MIRIntConst *intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(2, *intType, 0); + MIRIntConst *intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(2, *intType); ConstvalNode *exprConst = mod.GetMemPool()->New(); exprConst->SetPrimType(PTY_i32); exprConst->SetConstVal(intConst); @@ -1871,8 +1871,7 @@ bool MIRParser::ParseExprConstval(BaseNodePtr &expr) { exprConst->SetPrimType(GetPrimitiveType(typeTk)); lexer.NextToken(); MIRConst *constVal = nullptr; - if (!ParseScalarValue(constVal, *GlobalTables::GetTypeTable().GetPrimType(exprConst->GetPrimType()), - 0 /* fieldID */)) { + if (!ParseScalarValue(constVal, *GlobalTables::GetTypeTable().GetPrimType(exprConst->GetPrimType()))) { Error("expect scalar type but get "); return false; } @@ -2600,27 +2599,27 @@ bool MIRParser::ParseExprIntrinsicop(BaseNodePtr &expr) { return true; } -bool MIRParser::ParseScalarValue(MIRConstPtr &stype, MIRType &type, uint32 fieldID) { +bool MIRParser::ParseScalarValue(MIRConstPtr &stype, MIRType &type) { PrimType ptp = type.GetPrimType(); if (IsPrimitiveInteger(ptp) || IsPrimitiveDynType(ptp) || ptp == PTY_gen) { if (lexer.GetTokenKind() != TK_intconst) { Error("constant value incompatible with integer type at "); return false; } - stype = GlobalTables::GetIntConstTable().GetOrCreateIntConst(lexer.GetTheIntVal(), type, fieldID); + stype = GlobalTables::GetIntConstTable().GetOrCreateIntConst(lexer.GetTheIntVal(), type); } else if (ptp == PTY_f32) { if (lexer.GetTokenKind() != TK_floatconst) { Error("constant value incompatible with single-precision float type at "); return false; } - MIRFloatConst *fConst = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(lexer.GetTheFloatVal(), fieldID); + MIRFloatConst *fConst = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(lexer.GetTheFloatVal()); stype = fConst; } else if (ptp == PTY_f64) { if (lexer.GetTokenKind() != TK_doubleconst && lexer.GetTokenKind() != TK_intconst) { Error("constant value incompatible with double-precision float type at "); return false; } - MIRDoubleConst *dconst = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(lexer.GetTheDoubleVal(), fieldID); + MIRDoubleConst *dconst = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(lexer.GetTheDoubleVal()); stype = dconst; } else { return false; diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index 69c15421bbf571c39ab84dbfb570a009f0400241..0781540088348ba7a25283eb3abb21de8ea8bda0 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -2006,7 +2006,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp if (tokenKind != TK_lbrack) { // scalar MIRConst *mirConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(mirConst, type, 0 /* fieldID */)) { + if (!ParseScalarValue(mirConst, type)) { Error("ParseInitValue expect scalar value"); return false; } @@ -2028,7 +2028,6 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp MIRType *elemType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(arrayType.GetElemTyIdx()); MIRAggConst *newConst = mod.GetMemPool()->New(mod, type); theConst = newConst; - MapleVector &constvec = newConst->GetConstVec(); tokenKind = lexer.NextToken(); if (tokenKind == TK_rbrack) { if (allowEmpty) { @@ -2043,7 +2042,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp // parse single const or another dimension array MIRConst *subConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(subConst, *elemType, 0 /* fieldID */)) { + if (!ParseScalarValue(subConst, *elemType)) { Error("ParseInitValue expect scalar value"); return false; } @@ -2080,7 +2079,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp Error("expect const value or group of const values but get "); return false; } - constvec.push_back(subConst); + newConst->AddItem(subConst, 0); // parse comma or rbrack tokenKind = lexer.GetTokenKind(); if (tokenKind == TK_coma) { @@ -2097,7 +2096,6 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp uint32 theFieldIdx; TyIdx fieldTyIdx; theConst = newConst; - MapleVector &constvec = newConst->GetConstVec(); tokenKind = lexer.NextToken(); if (tokenKind == TK_rbrack) { if (allowEmpty) { @@ -2127,7 +2125,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp tokenKind = lexer.NextToken(); MIRConst *subConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(subConst, *GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx), theFieldIdx)) { + if (!ParseScalarValue(subConst, *GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx))) { Error("ParseInitValue expect scalar value"); return false; } @@ -2147,8 +2145,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx, bool allowEmp return false; } ASSERT(subConst != nullptr, "subConst is null in MIRParser::ParseInitValue"); - subConst->SetFieldID(theFieldIdx); - constvec.push_back(subConst); + newConst->AddItem(subConst, theFieldIdx); tokenKind = lexer.GetTokenKind(); // parse comma or rbrack if (tokenKind == TK_coma) { diff --git a/src/mapleall/maple_me/BUILD.gn b/src/mapleall/maple_me/BUILD.gn index 3a4869221e94526b14694eb77d3d67d21f67ed46..af26501e5f11cf1788d494fd275215157497e8b4 100755 --- a/src/mapleall/maple_me/BUILD.gn +++ b/src/mapleall/maple_me/BUILD.gn @@ -15,7 +15,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/mpl2mpl/include", diff --git a/src/mapleall/maple_me/include/me_ssu_pre.h b/src/mapleall/maple_me/include/me_ssu_pre.h index 0f6d84579d9fe71f11edf982aed7c9b80519a517..d6686f00e77a75bd53a23315894c9768677e5809 100644 --- a/src/mapleall/maple_me/include/me_ssu_pre.h +++ b/src/mapleall/maple_me/include/me_ssu_pre.h @@ -387,11 +387,12 @@ class MeSSUPre { // step 2 methods void Rename(); // step 1 methods - void GetIterPdomFrontier(BB *bb, MapleSet *pdfset) { + void GetIterPdomFrontier(const BB *bb, MapleSet *pdfset) const { for (BBId bbid : dom->iterPdomFrontier[bb->GetBBId()]) { - pdfset->insert(dom->GetPdtDfnItem(bbid)); + (void)pdfset->insert(dom->GetPdtDfnItem(bbid)); } } + void FormLambdas(); void FormLambdaRes(); void CreateSortedOccs(); diff --git a/src/mapleall/maple_me/include/ssa_pre.h b/src/mapleall/maple_me/include/ssa_pre.h index 56489fd62ec04a33b389027c02ce619aea5e9bc9..f34556ed1d75a5ca149fc3273b77c6a7e8697615 100644 --- a/src/mapleall/maple_me/include/ssa_pre.h +++ b/src/mapleall/maple_me/include/ssa_pre.h @@ -75,11 +75,12 @@ class SSAPre { virtual PUIdx GetPUIdx() const = 0; virtual void SetCurFunction(PUIdx) const {} - void GetIterDomFrontier(BB *bb, MapleSet *dfset) { + void GetIterDomFrontier(const BB *bb, MapleSet *dfset) const { for (BBId bbid : dom->iterDomFrontier[bb->GetBBId()]) { - dfset->insert(dom->GetDtDfnItem(bbid)); + (void)dfset->insert(dom->GetDtDfnItem(bbid)); } } + void SetSpillAtCatch(bool status) { spillAtCatch = status; } diff --git a/src/mapleall/maple_me/src/irmap.cpp b/src/mapleall/maple_me/src/irmap.cpp index 99a13c823e79b59f62405e9027f4c5afb444d848..8ff33c0e4d3d287164c087f3211d27e07a378db8 100644 --- a/src/mapleall/maple_me/src/irmap.cpp +++ b/src/mapleall/maple_me/src/irmap.cpp @@ -452,8 +452,7 @@ MeExpr *IRMap::CreateConstMeExpr(PrimType pType, MIRConst &mirConst) { MeExpr *IRMap::CreateIntConstMeExpr(int64 value, PrimType pType) { auto *intConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(value, *GlobalTables::GetTypeTable().GetPrimType(pType), - 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(value, *GlobalTables::GetTypeTable().GetPrimType(pType)); return CreateConstMeExpr(pType, *intConst); } diff --git a/src/mapleall/maple_me/src/irmap_emit.cpp b/src/mapleall/maple_me/src/irmap_emit.cpp index 75ccd188507be99f763c6f9dfa6af9345d0aebc5..cfbb04f203667d742ca609c6570829bcd9af5172 100644 --- a/src/mapleall/maple_me/src/irmap_emit.cpp +++ b/src/mapleall/maple_me/src/irmap_emit.cpp @@ -57,7 +57,7 @@ BaseNode &ConstMeExpr::EmitExpr(SSATab &ssaTab) { if (IsPrimitiveInteger(exprConst->GetPrimType())) { auto *intConst = safe_cast(exprConst->GetConstVal()); MIRIntConst *newIntConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(intConst->GetValueUnderType(), - intConst->GetType(), intConst->GetFieldId()); + intConst->GetType()); exprConst->SetConstVal(newIntConst); } return *exprConst; diff --git a/src/mapleall/maple_me/src/me_profile_gen.cpp b/src/mapleall/maple_me/src/me_profile_gen.cpp index 77bc04253dda9addd4755b1aa15f456aa9a4255f..84677f80f82c0cfed9c52ca025e253f47aef287c 100644 --- a/src/mapleall/maple_me/src/me_profile_gen.cpp +++ b/src/mapleall/maple_me/src/me_profile_gen.cpp @@ -103,7 +103,7 @@ void MeProfGen::InstrumentFunc() { for (auto *bb : instrumentBBs) { MIRIntConst *indexConst = func->GetMIRModule().GetMemPool()->New(0, *GlobalTables::GetTypeTable().GetUInt32()); - bbProfileTab->PushBack(indexConst); + bbProfileTab->AddItem(indexConst, 0); InstrumentBB(*bb); } diff --git a/src/mapleall/maple_me/src/me_ssa_epre.cpp b/src/mapleall/maple_me/src/me_ssa_epre.cpp index 793cd5927c56b30a7bda4c27d3742093ea3f6625..8d86ef897a2a6217ed3b7a6fb8aeef2bf7f1935c 100644 --- a/src/mapleall/maple_me/src/me_ssa_epre.cpp +++ b/src/mapleall/maple_me/src/me_ssa_epre.cpp @@ -28,7 +28,6 @@ const std::set propWhiteList { // accumulate the BBs that are in the iterated dominance frontiers of bb in // the set dfSet, visiting each BB only once namespace maple { - void MeSSAEPre::BuildWorkList() { const MapleVector &preOrderDt = dom->GetDtPreOrder(); for (auto &bbID : preOrderDt) { diff --git a/src/mapleall/maple_me/src/prop.cpp b/src/mapleall/maple_me/src/prop.cpp index d6e588de52cd56ad2a27834c216cc88803e4bd1f..7f1a2f83e1cd0e4a69cc92369e0499e1be2012b4 100644 --- a/src/mapleall/maple_me/src/prop.cpp +++ b/src/mapleall/maple_me/src/prop.cpp @@ -279,7 +279,7 @@ MeExpr *Prop::CheckTruncation(MeExpr *lhs, MeExpr *rhs) const { return irMap.HashMeExpr(opmeexpr); } if (IsPrimitiveInteger(lhsTy->GetPrimType()) && - lhsTy->GetPrimType() != PTY_ptr && lhsTy->GetPrimType() != PTY_ref && + lhsTy->GetPrimType() != PTY_ptr && lhsTy->GetPrimType() != PTY_ref && GetPrimTypeSize(lhsTy->GetPrimType()) < rhs->GetPrimType()) { if (GetPrimTypeSize(lhsTy->GetPrimType()) >= 4) { return irMap.CreateMeExprTypeCvt(lhsTy->GetPrimType(), rhs->GetPrimType(), *rhs); @@ -306,7 +306,8 @@ MeExpr *Prop::CheckTruncation(MeExpr *lhs, MeExpr *rhs) const { rhsTy = GlobalTables::GetTypeTable().GetTypeFromTyIdx(rhsvarx->GetOst()->GetTyIdx()); } else if (rhs->GetMeOp() == kMeOpIvar) { IvarMeExpr *rhsivarx = static_cast(rhs); - MIRPtrType *rhsPtrType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(rhsivarx->GetTyIdx())); + MIRPtrType *rhsPtrType = + static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(rhsivarx->GetTyIdx())); rhsTy = rhsPtrType->GetPointedType(); if (rhsivarx->GetFieldID() != 0) { rhsTy = static_cast(rhsTy)->GetFieldType(rhsivarx->GetFieldID()); diff --git a/src/mapleall/maple_phase/BUILD.gn b/src/mapleall/maple_phase/BUILD.gn index 5a3f135099279f99875958a17eb02491ca923310..559d3d7420df30f4113f7045dcd6e1105cf2ffb2 100644 --- a/src/mapleall/maple_phase/BUILD.gn +++ b/src/mapleall/maple_phase/BUILD.gn @@ -20,7 +20,7 @@ include_libmplphase = [ "${MAPLEALL_ROOT}/maple_phase/include", "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mpl2mpl/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", "${MAPLEALL_ROOT}/maple_driver/include", ] diff --git a/src/mapleall/maple_util/BUILD.gn b/src/mapleall/maple_util/BUILD.gn index 73b8db9948d8833d9edee73768e20140363c328c..b2d8339b2e08d688c17374cfbdb3de83512e75a2 100755 --- a/src/mapleall/maple_util/BUILD.gn +++ b/src/mapleall/maple_util/BUILD.gn @@ -32,7 +32,7 @@ include_libmplutil = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", "${MAPLEALL_ROOT}/maple_driver/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] configs = [ "${MAPLEALL_ROOT}:mapleallcompilecfg" ] diff --git a/src/mapleall/mempool/BUILD.gn b/src/mapleall/mempool/BUILD.gn index 386f797efe551d4594b478872302f54cfbacd2c8..470c4ba8c594362b2ad97d8818a52003c42506d2 100644 --- a/src/mapleall/mempool/BUILD.gn +++ b/src/mapleall/mempool/BUILD.gn @@ -7,7 +7,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] configs = [ "${MAPLEALL_ROOT}:mapleallcompilecfg" ] @@ -28,7 +28,7 @@ executable("MemPool") { deps = [ ":libmempool", - "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", + "//../ThirdParty/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_driver:liboption_parser", "${MAPLEALL_ROOT}/maple_util:libmplutil", ] diff --git a/src/mapleall/mpl2mpl/BUILD.gn b/src/mapleall/mpl2mpl/BUILD.gn index f70d8aabe9c7b172c8c857d71ac677d0565113d5..bfa9080a520a3110dc3ab5cc1c8abafb543062eb 100755 --- a/src/mapleall/mpl2mpl/BUILD.gn +++ b/src/mapleall/mpl2mpl/BUILD.gn @@ -21,7 +21,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] src_libmpl2mpl = [ diff --git a/src/mapleall/mpl2mpl/src/coderelayout.cpp b/src/mapleall/mpl2mpl/src/coderelayout.cpp index ac3acad23a2522fc05c8d8647b11999fd0f0ca21..710cc90407b7a09d0bd335ac2f964e72b9db6311 100644 --- a/src/mapleall/mpl2mpl/src/coderelayout.cpp +++ b/src/mapleall/mpl2mpl/src/coderelayout.cpp @@ -220,8 +220,8 @@ MIRSymbol *CodeReLayout::GenStrSym(const std::string &str) { staticSym->SetStorageClass(kScFstatic); for (const char &c : newStr) { MIRConst *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - c, *GlobalTables::GetTypeTable().GetUInt8(), 0 /* fieldID */); - strTabAggConst->PushBack(newConst); + c, *GlobalTables::GetTypeTable().GetUInt8()); + strTabAggConst->AddItem(newConst, 0); } staticSym->SetKonst(strTabAggConst); return staticSym; @@ -273,7 +273,7 @@ void CodeReLayout::GenLayoutSym() { fieldConst = GetMIRModule().GetMemPool()->New(addroffuncExpr->GetPUIdx(), *GlobalTables::GetTypeTable().GetVoidPtr()); - funcLayoutConst->PushBack(fieldConst); + funcLayoutConst->AddItem(fieldConst, 0); funcIdx += layoutCount[i]; } std::string funcLayoutSymName = namemangler::kFunctionLayoutStr + GetMIRModule().GetFileNameAsPostfix(); diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index 149cefa0db73fdb8b50542bca326630dfd6a102c..95e7aa1dd9bad14bf57443dc86e5428eab120a57 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -415,10 +415,10 @@ MIRIntConst *ConstantFold::FoldIntConstComparisonMIRConst(Opcode opcode, PrimTyp // form the constant MIRIntConst *constValue = nullptr; if (type.GetPrimType() == PTY_dyni32) { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); constValue->SetValue(kJsTypeNumberInHigh32Bit | (static_cast(result))); } else { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result, type, 0 /* fieldID */); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result, type); } return constValue; } @@ -621,13 +621,13 @@ MIRConst *ConstantFold::FoldIntConstBinaryMIRConst(Opcode opcode, PrimType resul // form the constant MIRIntConst *constValue = nullptr; if (type.GetPrimType() == PTY_dyni32) { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); constValue->SetValue(kJsTypeNumberInHigh32Bit | (static_cast(result32))); } else if (useResult64) { constValue = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type); } else { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result32, type, 0 /* fieldID */); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result32, type); } return constValue; } @@ -743,9 +743,9 @@ ConstvalNode *ConstantFold::FoldFPConstBinary(Opcode opcode, PrimType resultType break; } if (resultType == PTY_f64) { - resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(constValueDouble, 0)); + resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(constValueDouble)); } else { - resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateFloatConst(constValueFloat, 0)); + resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateFloatConst(constValueFloat)); } return resultConst; } @@ -854,7 +854,7 @@ MIRIntConst *ConstantFold::FoldFPConstComparisonMIRConst(Opcode opcode, PrimType break; } MIRIntConst *resultConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(constValue, type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(constValue, type); return resultConst; } @@ -977,13 +977,13 @@ ConstvalNode *ConstantFold::FoldIntConstUnary(Opcode opcode, PrimType resultType // form the constant MIRIntConst *constValue = nullptr; if (type.GetPrimType() == PTY_dyni32) { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); constValue->SetValue(kJsTypeNumberInHigh32Bit | (static_cast(result32))); } else if (useResult64) { constValue = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type); } else { - constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result32, type, 0 /* fieldID */); + constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result32, type); } // form the ConstvalNode ConstvalNode *resultConst = mirModule->CurFuncCodeMemPool()->New(); @@ -1029,9 +1029,9 @@ ConstvalNode *ConstantFold::FoldFPConstUnary(Opcode opcode, PrimType resultType, auto *resultConst = mirModule->CurFuncCodeMemPool()->New(); resultConst->SetPrimType(resultType); if (resultType == PTY_f32) { - resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateFloatConst(constValue, 0)); + resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateFloatConst(constValue)); } else { - resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(constValue, 0)); + resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(constValue)); } return resultConst; } @@ -1061,7 +1061,7 @@ std::pair ConstantFold::FoldSizeoftype(SizeoftypeNode *node) c ConstvalNode *constValueNode = mirModule->CurFuncCodeMemPool()->New(); constValueNode->SetPrimType(node->GetPrimType()); constValueNode->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(size), resultType, 0 /* fieldID */)); + static_cast(size), resultType)); result = constValueNode; } return std::make_pair(result, 0); @@ -1173,7 +1173,7 @@ ConstvalNode *ConstantFold::FoldCeil(const ConstvalNode &cst, PrimType fromType, return nullptr; } resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(floatValue), resultType, 0 /* fieldID */)); + static_cast(floatValue), resultType)); } else { const MIRDoubleConst *constValue = safe_cast(cst.GetConstVal()); ASSERT_NOT_NULL(constValue); @@ -1182,7 +1182,7 @@ ConstvalNode *ConstantFold::FoldCeil(const ConstvalNode &cst, PrimType fromType, return nullptr; } resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(doubleValue), resultType, 0 /* fieldID */)); + static_cast(doubleValue), resultType)); } return resultConst; } @@ -1216,8 +1216,7 @@ MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst &cst, PrimType fromType return nullptr; } floatValue = CalIntValueFromFloatValue(floatValue, resultType); - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType, - 0 /* fieldID */); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType); } else { const auto &constValue = static_cast(cst); double doubleValue = floor(constValue.GetValue()); @@ -1225,8 +1224,7 @@ MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst &cst, PrimType fromType return nullptr; } doubleValue = CalIntValueFromFloatValue(doubleValue, resultType); - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType, - 0 /* fieldID */); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType); } } @@ -1245,29 +1243,27 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst &cst, PrimType fromType if (FloatToIntOverflow(floatValue, toType)) { return nullptr; } - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType, - 0 /* fieldID */); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType); } else if (fromType == PTY_f64) { const auto &constValue = static_cast(cst); double doubleValue = round(constValue.GetValue()); if (DoubleToIntOverflow(doubleValue, toType)) { return nullptr; } - return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType, - 0 /* fieldID */); + return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType); } else if (toType == PTY_f32 && IsPrimitiveInteger(fromType)) { const auto &constValue = static_cast(cst); if (IsSignedInteger(fromType)) { int64 fromValue = constValue.GetValue(); float floatValue = round(static_cast(fromValue)); if (static_cast(floatValue) == fromValue) { - return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue, 0); + return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue); } } else { uint64 fromValue = static_cast(constValue.GetValue()); float floatValue = round(static_cast(fromValue)); if (static_cast(floatValue) == fromValue) { - return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue, 0); + return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue); } } } else if (toType == PTY_f64 && IsPrimitiveInteger(fromType)) { @@ -1276,13 +1272,13 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst &cst, PrimType fromType int64 fromValue = constValue.GetValue(); double doubleValue = round(static_cast(fromValue)); if (static_cast(doubleValue) == fromValue) { - return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue, 0); + return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue); } } else { uint64 fromValue = static_cast(constValue.GetValue()); double doubleValue = round(static_cast(fromValue)); if (static_cast(doubleValue) == fromValue) { - return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue, 0); + return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue); } } } @@ -1308,7 +1304,7 @@ ConstvalNode *ConstantFold::FoldTrunk(const ConstvalNode &cst, PrimType fromType return nullptr; } resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(floatValue), resultType, 0 /* fieldID */)); + static_cast(floatValue), resultType)); } else { const MIRDoubleConst *constValue = safe_cast(cst.GetConstVal()); CHECK_NULL_FATAL(constValue); @@ -1317,7 +1313,7 @@ ConstvalNode *ConstantFold::FoldTrunk(const ConstvalNode &cst, PrimType fromType return nullptr; } resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(doubleValue), resultType, 0 /* fieldID */)); + static_cast(doubleValue), resultType)); } return resultConst; } @@ -1342,7 +1338,7 @@ MIRConst *ConstantFold::FoldTypeCvtMIRConst(const MIRConst &cst, PrimType fromTy ASSERT_NOT_NULL(constVal); MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(toType); toConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(constVal->GetValue(), type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(constVal->GetValue(), type); } return toConst; } @@ -1352,15 +1348,15 @@ MIRConst *ConstantFold::FoldTypeCvtMIRConst(const MIRConst &cst, PrimType fromTy ASSERT(GetPrimTypeBitSize(toType) == 32, "We suppot F32 and F64"); const MIRDoubleConst *fromValue = safe_cast(cst); ASSERT_NOT_NULL(fromValue); - float floutValue = static_cast(fromValue->GetValue()); - MIRFloatConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floutValue, 0); + float floatValue = static_cast(fromValue->GetValue()); + MIRFloatConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue); toConst = toValue; } else { ASSERT(GetPrimTypeBitSize(toType) == 64, "We suppot F32 and F64"); const MIRFloatConst *fromValue = safe_cast(cst); ASSERT_NOT_NULL(fromValue); double doubleValue = static_cast(fromValue->GetValue()); - MIRDoubleConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue, 0); + MIRDoubleConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue); toConst = toValue; } return toConst; @@ -1449,7 +1445,7 @@ MIRConst *ConstantFold::FoldSignExtendMIRConst(Opcode opcode, PrimType resultTyp } MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(resultType); MIRIntConst *constValue = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(result64), type); return constValue; } @@ -1511,7 +1507,8 @@ std::pair ConstantFold::FoldIread(IreadNode *node) { } MIRPtrType *ptrType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(node->GetTyIdx())); if (ptrType->GetPointedType() == msyType) { - result = mirModule->CurFuncCodeMemPool()->New(OP_dread, node->GetPrimType(), addrofNode->GetStIdx(), node->GetFieldID() + addrofNode->GetFieldID()); + result = mirModule->CurFuncCodeMemPool()->New( + OP_dread, node->GetPrimType(), addrofNode->GetStIdx(), node->GetFieldID() + addrofNode->GetFieldID()); } } return std::make_pair(result, 0); @@ -1823,7 +1820,7 @@ std::pair ConstantFold::FoldDepositbits(DepositbitsNode *node) resultConst->SetPrimType(node->GetPrimType()); MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(node->GetPrimType()); MIRIntConst *constValue = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); uint64 op0ExtractVal = 0; uint64 op1ExtractVal = 0; uint64 mask0 = (1LLU << (bitsSize + bitsOffset)) - 1; @@ -1833,7 +1830,7 @@ std::pair ConstantFold::FoldDepositbits(DepositbitsNode *node) op1ExtractVal = (static_cast(intConst1->GetValue()) << bitsOffset) & ((1ULL << (bitsSize + bitsOffset)) - 1); constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - op0ExtractVal | op1ExtractVal, constValue->GetType(), constValue->GetFieldId()); + op0ExtractVal | op1ExtractVal, constValue->GetType()); resultConst->SetConstVal(constValue); result = resultConst; } else { diff --git a/src/mapleall/mpl2mpl/src/muid_replacement.cpp b/src/mapleall/mpl2mpl/src/muid_replacement.cpp index 215cc77fae9a259fd2a080091df7020ca28e5052..d41676f261cdbcc3cedbf8429dc5d65d0379b791 100644 --- a/src/mapleall/mpl2mpl/src/muid_replacement.cpp +++ b/src/mapleall/mpl2mpl/src/muid_replacement.cpp @@ -195,11 +195,11 @@ void MUIDReplacement::GenArrayClassCache() { for (auto arrayClassName : arrayClassSet) { uint32 typeNameIdx = ReflectionAnalysis::FindOrInsertRepeatString(arrayClassName); MIRIntConst *nameConstValue = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(typeNameIdx, *mType, 0 /* fieldID */); - arrayClassNameConst->PushBack(nameConstValue); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(typeNameIdx, *mType); + arrayClassNameConst->AddItem(nameConstValue, 0); MIRIntConst *constValue = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(arrayClassCacheMagicNumber, *mType, 0 /* fieldID */); - arrayClassConst->PushBack(constValue); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(arrayClassCacheMagicNumber, *mType); + arrayClassConst->AddItem(constValue, 0); } MIRSymbol *arrayClassNameSt = GetMIRModule().GetMIRBuilder()->CreateGlobalDecl( namemangler::kArrayClassCacheNameTable + GetMIRModule().GetFileNameAsPostfix(), *arrayType); @@ -563,9 +563,8 @@ void MUIDReplacement::GenerateFuncDefTable() { // Use the muid index for now. It will be back-filled once we have the whole vector. MIRIntConst *indexConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(keyVal.second.second, - *GlobalTables::GetTypeTable().GetUInt32(), - 0 /* fieldID */); - muidIdxTabConst->PushBack(indexConst); + *GlobalTables::GetTypeTable().GetUInt32()); + muidIdxTabConst->AddItem(indexConst, 0); } FieldVector parentFields; FieldVector fields; @@ -616,9 +615,8 @@ void MUIDReplacement::GenerateFuncDefTable() { MIRAggConst *funcCallTimesConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), muidIdxArrayType); for (size_t start = 0; start < arraySize; ++start) { MIRIntConst *indexConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *GlobalTables::GetTypeTable().GetUInt32(), - 0 /* fieldID */); - funcCallTimesConst->PushBack(indexConst); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *GlobalTables::GetTypeTable().GetUInt32()); + funcCallTimesConst->AddItem(indexConst, 0); } if (arraySize) { std::string funcProfileName = namemangler::kFunctionProfileTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); @@ -646,16 +644,14 @@ void MUIDReplacement::GenerateFuncDefTable() { auto *indexConst = safe_cast(muidIdxTabConst->GetConstVecItem(muidIdx)); uint32 tempIdx = (static_cast(indexConst->GetValue()) & weakFuncFlag) | idx; indexConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(tempIdx, - *GlobalTables::GetTypeTable().GetUInt32(), - 0 /* fieldID */); - muidIdxTabConst->SetConstVecItem(muidIdx, *indexConst); + *GlobalTables::GetTypeTable().GetUInt32()); + muidIdxTabConst->SetItem(muidIdx, indexConst, 0); if (reflectionList.find(mirFunc->GetName()) != reflectionList.end()) { auto *tempConst = safe_cast(muidIdxTabConst->GetConstVecItem(idx)); tempIdx = weakFuncFlag | static_cast(tempConst->GetValue()); tempConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(tempIdx, - *GlobalTables::GetTypeTable().GetUInt32(), - 0 /* fieldID */); - muidIdxTabConst->SetConstVecItem(idx, *tempConst); + *GlobalTables::GetTypeTable().GetUInt32()); + muidIdxTabConst->SetItem(idx, tempConst, 0); } if (Options::profileFunc) { InsertFunctionProfile(*mirFunc, idx); @@ -675,7 +671,7 @@ void MUIDReplacement::GenerateFuncDefTable() { *funcProfInfEntryConst, funcProfInfFieldID++, funcProfInf->counterStart); builder->AddIntFieldConst(*funcProfInfTabEntryType, *funcProfInfEntryConst, funcProfInfFieldID++, funcProfInf->counterEnd); - funcProfInfTabConst->PushBack(funcProfInfEntryConst); + funcProfInfTabConst->AddItem(funcProfInfEntryConst, 0); } // Store the real idx of funcdefTab, for ReplaceAddroffuncConst->FindIndexFromDefTable defMuidIdxMap[muid] = idx; @@ -704,15 +700,15 @@ void MUIDReplacement::GenerateFuncDefTable() { uint32 muidFieldID = 1; // To be processed by runtime builder->AddAddroffuncFieldConst(*funcDefTabEntryType, *entryConst, fieldID++, *funcSymbol); - funcDefTabConst->PushBack(entryConst); + funcDefTabConst->AddItem(entryConst, 0); // To be emitted as method size by CG builder->AddAddroffuncFieldConst(*funcInfTabEntryType, *funcInfEntryConst, funcInfFieldID++, *funcSymbol); // To be emitted as method name by CG builder->AddAddroffuncFieldConst(*funcInfTabEntryType, *funcInfEntryConst, funcInfFieldID++, *funcSymbol); - funcInfTabConst->PushBack(funcInfEntryConst); + funcInfTabConst->AddItem(funcInfEntryConst, 0); builder->AddIntFieldConst(*funcDefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[0]); builder->AddIntFieldConst(*funcDefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[1]); - funcDefMuidTabConst->PushBack(muidEntryConst); + funcDefMuidTabConst->AddItem(muidEntryConst, 0); mplMuidStr += muid.ToStr(); } if (!funcDefTabConst->GetConstVec().empty()) { @@ -771,8 +767,8 @@ void MUIDReplacement::ReplaceMethodMetaFuncAddr(MIRSymbol &funcSymbol, int64 ind MIRConst *elem = agg->GetConstVecItem(0); if (elem->GetKind() == kConstAddrofFunc) { MIRType &type = elem->GetType(); - MIRConst *constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(index, type, 1); - agg->SetConstVecItem(0, *constNode); + MIRConst *constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(index, type); + agg->SetItem(0, constNode, 1); } } @@ -800,9 +796,9 @@ void MUIDReplacement::GenerateDataDefTable() { MIRConst *elemConst = aggConst->GetConstVecItem(static_cast(ClassProperty::kShadow)); auto *intConst = safe_cast(elemConst); // We use 0 as flag of not lazy. - intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - idx, intConst->GetType(), intConst->GetFieldId()); - aggConst->SetConstVecItem(static_cast(ClassProperty::kShadow), *intConst); + intConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx, intConst->GetType()); + aggConst->SetItem(static_cast(ClassProperty::kShadow), intConst, + aggConst->GetFieldIdItem(static_cast(ClassProperty::kShadow))); } else { ReplaceFieldMetaStaticAddr(*mirSymbol, idx - 1); } @@ -840,10 +836,10 @@ void MUIDReplacement::GenerateDataDefTable() { uint32 muidFieldID = 1; // Will be emitted as 0 and processed by runtime builder->AddAddrofFieldConst(*dataDefTabEntryType, *entryConst, fieldID++, *mirSymbol); - dataDefTabConst->PushBack(entryConst); + dataDefTabConst->AddItem(entryConst, 0); builder->AddIntFieldConst(*dataDefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[0]); builder->AddIntFieldConst(*dataDefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[1]); - dataDefMuidTabConst->PushBack(muidEntryConst); + dataDefMuidTabConst->AddItem(muidEntryConst, 0); mplMuidStr += muid.ToStr(); if (trace) { LogInfo::MapleLogger() << "dataDefMap, MUID: " << muid.ToStr() << ", Variable Name: " << mirSymbol->GetName() @@ -895,8 +891,8 @@ void MUIDReplacement::ReplaceFieldMetaStaticAddr(const MIRSymbol &mirSymbol, uin MIRType &type = elem->GetType(); int64 idx = index * 2 + 1; // add flag to indicate that it's def tab index for emit. - MIRConst *constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx, type, 1); - agg->SetConstVecItem(0, *constNode); + MIRConst *constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(idx, type); + agg->SetItem(0, constNode, 1); (void)idx; } @@ -962,7 +958,7 @@ void MUIDReplacement::GenerateUnifiedUndefTable() { uint32 muidFieldID = 1; // to be filled by runtime builder->AddIntFieldConst(*unifiedUndefTabEntryType, *entryConst, fieldID++, 0); - funcUndefTabConst->PushBack(entryConst); + funcUndefTabConst->AddItem(entryConst, 0); if (sourceFileMethodMap.find(muid) != sourceFileMethodMap.end()) { uint32 fileIndex = sourceFileMethodMap[muid].sourceFileIndex; uint32 classIndex = sourceFileMethodMap[muid].sourceClassIndex; @@ -978,7 +974,7 @@ void MUIDReplacement::GenerateUnifiedUndefTable() { builder->AddIntFieldConst(*unifiedUndefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[0]); builder->AddIntFieldConst(*unifiedUndefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[1]); } - funcUndefMuidTabConst->PushBack(muidEntryConst); + funcUndefMuidTabConst->AddItem(muidEntryConst, 0); } if (!funcUndefTabConst->GetConstVec().empty()) { std::string funcUndefTabName = namemangler::kMuidFuncUndefTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); @@ -1007,11 +1003,11 @@ void MUIDReplacement::GenerateUnifiedUndefTable() { MIRSymbol *mirSymbol = keyVal.second.first; MUID muid = keyVal.first; MIRAggConst *muidEntryConst = - GetMIRModule().GetMemPool()->New(GetMIRModule(), *unifiedUndefMuidTabEntryType); + GetMIRModule().GetMemPool()->New(GetMIRModule(), *unifiedUndefMuidTabEntryType); uint32 muidFieldID = 1; // Will be emitted as 0 and filled by runtime builder->AddAddrofFieldConst(*unifiedUndefTabEntryType, *entryConst, fieldID++, *mirSymbol); - dataUndefTabConst->PushBack(entryConst); + dataUndefTabConst->AddItem(entryConst, 0); if (sourceIndexMap.find(muid) != sourceIndexMap.end()) { SourceIndexPair pairIndex = sourceIndexMap[muid]; uint32 value = (pairIndex.first << kShiftBit16) + pairIndex.second; @@ -1029,7 +1025,7 @@ void MUIDReplacement::GenerateUnifiedUndefTable() { builder->AddIntFieldConst(*unifiedUndefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[0]); builder->AddIntFieldConst(*unifiedUndefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[1]); } - dataUndefMuidTabConst->PushBack(muidEntryConst); + dataUndefMuidTabConst->AddItem(muidEntryConst, 0); mplMuidStr += muid.ToStr(); if (trace) { LogInfo::MapleLogger() << "dataUndefMap, MUID: " << muid.ToStr() << ", Variable Name: " << mirSymbol->GetName() @@ -1063,7 +1059,7 @@ void MUIDReplacement::InitRangeTabUseSym(std::vector &workList, MIRS builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); } - rangeTabConst.PushBack(entryConst); + rangeTabConst.AddItem(entryConst, 0); } } @@ -1087,7 +1083,7 @@ void MUIDReplacement::GenerateRangeTable() { MUID mplMd5 = GetMUID(item); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, mplMd5.data.words[0]); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, mplMd5.data.words[1]); - rangeTabConst->PushBack(entryConst); + rangeTabConst->AddItem(entryConst, 0); } for (uint32 i = RangeIdx::kVtabAndItab; i < RangeIdx::kOldMaxNum; ++i) { // Use an integer to mark which entry is for which table @@ -1098,13 +1094,13 @@ void MUIDReplacement::GenerateRangeTable() { if (st == nullptr) { builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); - rangeTabConst->PushBack(entryConst); + rangeTabConst->AddItem(entryConst, 0); continue; } } builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, i); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, i); - rangeTabConst->PushBack(entryConst); + rangeTabConst->AddItem(entryConst, 0); } // Please refer to mrt/compiler-rt/include/mpl_linker.h for the layout std::vector workList = { @@ -1128,7 +1124,7 @@ void MUIDReplacement::GenerateRangeTable() { MIRAggConst *entryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), rangeTabEntryType); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, i); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, i); - rangeTabConst->PushBack(entryConst); + rangeTabConst->AddItem(entryConst, 0); } std::string bbProfileName = namemangler::kBBProfileTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); MIRSymbol *funcProfCounterTabSym = GetSymbolFromName(bbProfileName); @@ -1229,21 +1225,21 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, b // this is an index into the funcDefTab constexpr uint64 idxIntoFuncDefTabFlag = 2u; constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(((offset + 1) << KReservedBits) + idxIntoFuncDefTabFlag), voidType, 0 /* fieldID */); + static_cast(((offset + 1) << KReservedBits) + idxIntoFuncDefTabFlag), voidType); } else if (isVtab && func->IsAbstract()) { MIRType &type = *GlobalTables::GetTypeTable().GetVoidPtr(); - constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); + constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); } else { ASSERT(func->GetFuncSymbol() != nullptr, "null ptr check!"); offset = FindIndexFromUndefTable(*(func->GetFuncSymbol()), true); // The second least significant bit is set to 0, indicating // this is an index into the funcUndefTab constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((offset + 1) << KReservedBits), - voidType, 0 /* fieldID */); + voidType); } if (fieldID != 0xffffffff) { constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(constNode->GetValue(), - constNode->GetType(), fieldID); + constNode->GetType()); } entry = constNode; } @@ -1271,10 +1267,10 @@ void MUIDReplacement::ReplaceFieldTypeTable(const std::string &name) { CHECK_NULL_FATAL(mirConst); if (mirConst->GetKind() == kConstInt) { MIRIntConst *newIntConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(mirConst)->GetValue(), mirConst->GetType(), index + 1); - aggrC->SetConstVecItem(index, *newIntConst); + static_cast(mirConst)->GetValue(), mirConst->GetType()); + aggrC->SetItem(index, newIntConst, index + 1); } else { - aggrC->GetConstVecItem(index)->SetFieldID(index + 1); + aggrC->SetFieldIdOfElement(index, index + 1); } } } else if (oldTabEntry->GetKind() == kConstAddrof) { @@ -1302,10 +1298,10 @@ void MUIDReplacement::ReplaceDataTable(const std::string &name) { MIRConstPtr mirConst = aggrC->GetConstVecItem(i); if (mirConst->GetKind() == kConstInt) { MIRIntConst *newIntConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(mirConst)->GetValue(), mirConst->GetType(), static_cast(i + 1)); - aggrC->SetConstVecItem(static_cast(i), *newIntConst); + static_cast(mirConst)->GetValue(), mirConst->GetType()); + aggrC->SetItem(static_cast(i), newIntConst, static_cast(i + 1)); } else { - aggrC->GetConstVecItem(i)->SetFieldID(i + 1); + aggrC->SetFieldIdOfElement(i, i + 1); } } } else if (oldTabEntry->GetKind() == kConstAddrof) { @@ -1331,10 +1327,10 @@ void MUIDReplacement::ReplaceDecoupleKeyTable(MIRAggConst* oldConst) { MIRConstPtr mirConst = aggrC->GetConstVecItem(i); if (mirConst->GetKind() == kConstInt) { MIRIntConst *newIntConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(mirConst)->GetValue(), mirConst->GetType(), static_cast(i + 1)); - aggrC->SetConstVecItem(static_cast(i), *newIntConst); + static_cast(mirConst)->GetValue(), mirConst->GetType()); + aggrC->SetItem(static_cast(i), newIntConst, static_cast(i + 1)); } else { - aggrC->GetConstVecItem(i)->SetFieldID(i + 1); + aggrC->SetFieldIdOfElement(i, i + 1); } } } @@ -1360,11 +1356,11 @@ void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry, bool muidIndex32Mod) if (addrSym->GetStorageClass() != kScExtern) { offset = FindIndexFromDefTable(*addrSym, false); constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(GetDefOrUndefOffsetWithMask(offset, true, - muidIndex32Mod), voidType, 0 /* fieldID */); + muidIndex32Mod), voidType); } else { offset = FindIndexFromUndefTable(*addrSym, false); constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(GetDefOrUndefOffsetWithMask(offset, false, - muidIndex32Mod), voidType, 0 /* fieldID */); + muidIndex32Mod), voidType); } entry = constNode; } @@ -1808,7 +1804,7 @@ void MUIDReplacement::GenerateGlobalRootList() { ASSERT(PTY_ptr < GlobalTables::GetTypeTable().GetTypeTable().size(), "index out of bound"); MIRType &ptrType = *GlobalTables::GetTypeTable().GetTypeTable()[PTY_ptr]; MIRConst *constNode = GetMIRModule().GetMemPool()->New(symbol->GetStIdx(), 0, ptrType); - newConst->PushBack(constNode); + newConst->AddItem(constNode, 0); } std::string gcRootsName = namemangler::kGcRootList; if (!newConst->GetConstVec().empty()) { @@ -1826,11 +1822,11 @@ void MUIDReplacement::GenerateCompilerVersionNum() { MIRAggConst *newConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); MIRType &type = *GlobalTables::GetTypeTable().GetInt32(); MIRConst *firstConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(Version::kMajorMplVersion, type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(Version::kMajorMplVersion, type); MIRConst *secondConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(Version::kMinorCompilerVersion, type, 0 /* fieldID */); - newConst->PushBack(firstConst); - newConst->PushBack(secondConst); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(Version::kMinorCompilerVersion, type); + newConst->AddItem(firstConst, 0); + newConst->AddItem(secondConst, 0); std::string symName = namemangler::kCompilerVersionNum + GetMIRModule().GetFileNameAsPostfix(); MIRSymbol *versionNum = builder->CreateGlobalDecl(symName, arrayType); versionNum->SetKonst(newConst); @@ -1843,14 +1839,14 @@ void MUIDReplacement::GenericSourceMuid() { MIRAggConst *newConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); for (const char &c : Options::sourceMuid) { MIRConst *charConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - c, *GlobalTables::GetTypeTable().GetUInt8(), 0 /* fieldID */); - newConst->GetConstVec().push_back(charConst); + c, *GlobalTables::GetTypeTable().GetUInt8()); + newConst->AddItem(charConst, 0); } MIRType &type = *GlobalTables::GetTypeTable().GetInt64(); - MIRConst *slotConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type, 0 /* fieldID */); - newConst->GetConstVec().push_back(slotConst); - newConst->GetConstVec().push_back(slotConst); + MIRConst *slotConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); + newConst->AddItem(slotConst, 0); + newConst->AddItem(slotConst, 0); std::string symName = namemangler::kSourceMuid + GetMIRModule().GetFileNameAsPostfix(); MIRSymbol *sourceMuid = builder->CreateGlobalDecl(symName, arrayType); sourceMuid->SetKonst(newConst); @@ -1860,7 +1856,7 @@ void MUIDReplacement::GenericSourceMuid() { void MUIDReplacement::GenCompilerMfileStatus() { MIRType &type = *GlobalTables::GetTypeTable().GetInt32(); MIRConst *intConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(Options::gcOnly ? 1 : 0, type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(Options::gcOnly ? 1 : 0, type); std::string symName = namemangler::kCompilerMfileStatus + GetMIRModule().GetFileNameAsPostfix(); MIRSymbol *mfileStatus = builder->CreateGlobalDecl(symName.c_str(), type); mfileStatus->SetKonst(intConst); @@ -1987,7 +1983,7 @@ void MUIDReplacement::GenerateTables() { value |= 0x4; } MIRConst *newConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(value), type, 0 /* fieldID */); + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(value), type); std::string decoupleOption = namemangler::kDecoupleOption + GetMIRModule().GetFileNameAsPostfix(); MIRSymbol *decoupleSt = builder->CreateGlobalDecl(decoupleOption, type); decoupleSt->SetKonst(newConst); diff --git a/src/mapleall/mpl2mpl/src/native_stub_func.cpp b/src/mapleall/mpl2mpl/src/native_stub_func.cpp index 9ce5221fdb8e761ac76a0ded8f51c6d32fceda55..4122e75013e9eb7196589ec3d1867f8266acc79f 100644 --- a/src/mapleall/mpl2mpl/src/native_stub_func.cpp +++ b/src/mapleall/mpl2mpl/src/native_stub_func.cpp @@ -309,8 +309,8 @@ void NativeStubFuncGeneration::GenerateRegFuncTabEntry() { uint64 locIdx = regFuncTabConst->GetConstVec().size(); auto *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((locIdx << locIdxShift) | locIdxMask), - *GlobalTables::GetTypeTable().GetVoidPtr(), 0 /* fieldID */); - regFuncTabConst->PushBack(newConst); + *GlobalTables::GetTypeTable().GetVoidPtr()); + regFuncTabConst->AddItem(newConst, 0); } void NativeStubFuncGeneration::GenerateRegFuncTab() { @@ -331,11 +331,11 @@ void NativeStubFuncGeneration::GenerateRegTabEntry(const MIRFunction &func) { uint32 classIdx = ReflectionAnalysis::FindOrInsertRepeatString(base, true); // always used // Using MIRIntConst instead of MIRStruct for RegTable. auto *baseConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - classIdx, *GlobalTables::GetTypeTable().GetVoidPtr(), 0 /* fieldID */); - regTableConst->PushBack(baseConst); + classIdx, *GlobalTables::GetTypeTable().GetVoidPtr()); + regTableConst->AddItem(baseConst, 0); auto *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - baseFuncNameWithTypeIdx, *GlobalTables::GetTypeTable().GetVoidPtr(), 0 /* fieldID */); - regTableConst->PushBack(newConst); + baseFuncNameWithTypeIdx, *GlobalTables::GetTypeTable().GetVoidPtr()); + regTableConst->AddItem(newConst, 0); } void NativeStubFuncGeneration::GenerateRegisteredNativeFuncCall(MIRFunction &func, const MIRFunction &nativeFunc, diff --git a/src/mapleall/mpl2mpl/src/reflection_analysis.cpp b/src/mapleall/mpl2mpl/src/reflection_analysis.cpp index 254461aa241b05fa7ef77df1a415513b8da45ece..cf4c6c11c6049e26ef52f96b3c48b4895c596c86 100644 --- a/src/mapleall/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mapleall/mpl2mpl/src/reflection_analysis.cpp @@ -858,7 +858,7 @@ void ReflectionAnalysis::GenMethodMeta(const Klass &klass, MIRStructType &method // @padding mirBuilder.AddIntFieldConst(methodsInfoType, newConst, fieldID, 0); #endif - aggConst.PushBack(&newConst); + aggConst.AddItem(&newConst, 0); } MIRSymbol *ReflectionAnalysis::GenMethodsMeta(const Klass &klass, @@ -897,7 +897,7 @@ MIRSymbol *ReflectionAnalysis::GenMethodAddrData(const MIRSymbol &funcSym) { // skip abstract func. if (!func->IsAbstract()) { mirBuilder.AddAddroffuncFieldConst(methodAddrType, *newconst, 1, funcSym); - aggconst->GetConstVec().push_back(newconst); + aggconst->AddItem(newconst, 0); methodAddrSt = GetOrCreateSymbol(namemangler::kMethodAddrDataPrefixStr + func->GetName(), methodAddrArrayType.GetTypeIndex(), true); methodAddrSt->SetStorageClass(kScFstatic); @@ -1027,7 +1027,7 @@ void ReflectionAnalysis::GenMethodMetaCompact(const Klass &klass, MIRStructType uint8 byteValue = byte; mirBuilder.AddIntFieldConst(methodsInfoCompactType, newConstCompact, fieldIDCompact, byteValue); } - aggConst.PushBack(&newConstCompact); + aggConst.AddItem(&newConstCompact, 0); } MIRSymbol *ReflectionAnalysis::GenMethodsMetaCompact(const Klass &klass, @@ -1120,7 +1120,7 @@ MIRSymbol *ReflectionAnalysis::GenFieldOffsetData(const Klass &klass, std::pair< MIRAggConst *newConst = module.GetMemPool()->New(module, fieldOffsetType); constexpr uint32_t fieldId = 1; GenFieldOffsetConst(*newConst, klass, fieldOffsetType, fieldInfo, fieldId); - aggConst->GetConstVec().push_back(newConst); + aggConst->AddItem(newConst, 0); FieldPair fieldP = fieldInfo.first; std::string originFieldname = GlobalTables::GetStrTable().GetStringFromStrIdx(fieldP.first); @@ -1158,7 +1158,7 @@ MIRSymbol *ReflectionAnalysis::GenSuperClassMetaData(std::list superClas MIRSymbol *dklassSt = GetOrCreateSymbol(CLASSINFO_PREFIX_STR + (*it)->GetKlassName(), classMetadataTyIdx); MIRAggConst *newConst = module.GetMemPool()->New(module, superclassMetadataType); mirBuilder.AddAddrofFieldConst(superclassMetadataType, *newConst, 1, *dklassSt); - aggconst->PushBack(newConst); + aggconst->AddItem(newConst, 0); } superclassArraySt = GetOrCreateSymbol(superClassArrayInfo, arrayType.GetTypeIndex(), true); // Direct access to superclassinfo is only possible within a .so. @@ -1248,7 +1248,7 @@ void ReflectionAnalysis::GenFieldMeta(const Klass &klass, MIRStructType &fieldsI } else { mirBuilder.AddIntFieldConst(fieldsInfoType, *newConst, fieldID, 0); } - aggConst.GetConstVec().push_back(newConst); + aggConst.AddItem(newConst, 0); } MIRSymbol *ReflectionAnalysis::GenFieldsMeta(const Klass &klass, std::vector> &fieldsVector, @@ -1319,7 +1319,7 @@ void ReflectionAnalysis::GenFieldMetaCompact(const Klass &klass, MIRStructType & uint8 byteValue = byte; mirBuilder.AddIntFieldConst(fieldsInfoCompactType, *newConstCompact, fieldID, byteValue); } - aggConstCompact.GetConstVec().push_back(newConstCompact); + aggConstCompact.AddItem(newConstCompact, 0); (void)fieldIDCompact; } @@ -2133,7 +2133,7 @@ void ReflectionAnalysis::GenClassHashMetaData() { MIRType *ptrType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(PTY_ptr); MIRConst *classConst = module.GetMemPool()->New(classExpr->GetStIdx(), classExpr->GetFieldID(), *ptrType); - bucketAggconst->PushBack(classConst); + bucketAggconst->AddItem(classConst, 0); } bucketSt->SetKonst(bucketAggconst); } @@ -2152,8 +2152,8 @@ static void ReflectionAnalysisGenStrTab(MIRModule &mirModule, const std::string strTabSt->SetStorageClass(kScFstatic); for (char c : strTab) { MIRConst *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - c, *GlobalTables::GetTypeTable().GetUInt8(), 0 /* fieldID */); - strTabAggconst->PushBack(newConst); + c, *GlobalTables::GetTypeTable().GetUInt8()); + strTabAggconst->AddItem(newConst, 0); } strTabSt->SetKonst(strTabAggconst); } diff --git a/src/mapleall/mpl2mpl/src/vtable_analysis.cpp b/src/mapleall/mpl2mpl/src/vtable_analysis.cpp index 100b876cdc618346273f7c0fb1e3df315d00fa28..5f7cd5a8f860c4621acfb0179d940993c5135b0c 100644 --- a/src/mapleall/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mapleall/mpl2mpl/src/vtable_analysis.cpp @@ -35,8 +35,8 @@ VtableAnalysis::VtableAnalysis(MIRModule &mod, KlassHierarchy *kh, bool dump) : voidPtrType = GlobalTables::GetTypeTable().GetVoidPtr(); // zeroConst and oneConst are shared amony itab entries. It is safe to share them because // they are never removed by anybody. - zeroConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *voidPtrType, 0 /* fieldID */); - oneConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(1, *voidPtrType, 0 /* fieldID */); + zeroConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *voidPtrType); + oneConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(1, *voidPtrType); for (Klass *klass : klassHierarchy->GetTopoSortedKlasses()) { ASSERT(klass != nullptr, "null ptr check!"); GenVtableList(*klass); @@ -188,7 +188,7 @@ void VtableAnalysis::GenVtableDefinition(const Klass &klass) { GetMIRModule().GetMemPool()); auto *constNode = GetMIRModule().GetMemPool()->New(addrofFuncNode->GetPUIdx(), *voidPtrType); - newConst->PushBack(constNode); + newConst->AddItem(constNode, 0); } // We also need to generate vtable and itable even if the class does not // have any virtual method, or does not implement any interface. Such a @@ -199,7 +199,7 @@ void VtableAnalysis::GenVtableDefinition(const Klass &klass) { // postpone this step to mplcg, where mplcg discovers all classes that does // not have any vtable or itable. if (newConst->GetConstVec().empty()) { - newConst->PushBack(zeroConst); + newConst->AddItem(zeroConst, 0); } GenTableSymbol(VTAB_PREFIX_STR, klass.GetKlassName(), *newConst); } @@ -299,10 +299,10 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { ASSERT_NOT_NULL(firstItabEmitArray); for (MIRFunction *func : firstItabVec) { if (func != nullptr) { - firstItabEmitArray->PushBack( - GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType)); + firstItabEmitArray->AddItem( + GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType), 0); } else { - firstItabEmitArray->PushBack(zeroConst); + firstItabEmitArray->AddItem(zeroConst, 0); } } // initialize conflict solution array @@ -310,22 +310,22 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { auto *secondItabEmitArray = GetMIRModule().GetMemPool()->New(GetMIRModule(), *voidPtrType); // remember count in secondItabVec count = ((secondConflictList.size() | (1ULL << (kShiftCountBit - 1))) << kShiftCountBit) + count; - secondItabEmitArray->PushBack( - GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(count), - *voidPtrType, 0 /* fieldID */)); - secondItabEmitArray->PushBack(oneConst); // padding + secondItabEmitArray->AddItem( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(count), *voidPtrType), + 0); + secondItabEmitArray->AddItem(oneConst, 0); // padding for (uint32 i = 0; i < kItabSecondHashSize; ++i) { if (!secondItab[i] && !secondConflictFlag[i]) { continue; } else { - secondItabEmitArray->PushBack( - GlobalTables::GetIntConstTable().GetOrCreateIntConst(i, *voidPtrType, 0 /* fieldID */)); + secondItabEmitArray->AddItem( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(i, *voidPtrType), 0); if (secondItab[i]) { - secondItabEmitArray->PushBack( - GetMIRModule().GetMemPool()->New(secondItab[i]->GetPuidx(), *voidPtrType)); + secondItabEmitArray->AddItem( + GetMIRModule().GetMemPool()->New(secondItab[i]->GetPuidx(), *voidPtrType), 0); } else { // it measn it was conflict again in the second hash - secondItabEmitArray->PushBack(oneConst); + secondItabEmitArray->AddItem(oneConst, 0); } } } @@ -333,17 +333,17 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { ASSERT_NOT_NULL(func); const std::string &signatureName = DecodeBaseNameWithType(*func); uint32 nameIdx = ReflectionAnalysis::FindOrInsertRepeatString(signatureName); - secondItabEmitArray->PushBack( - GlobalTables::GetIntConstTable().GetOrCreateIntConst(nameIdx, *voidPtrType, 0 /* fieldID */)); - secondItabEmitArray->PushBack( - GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType)); + secondItabEmitArray->AddItem( + GlobalTables::GetIntConstTable().GetOrCreateIntConst(nameIdx, *voidPtrType), 0); + secondItabEmitArray->AddItem( + GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType), 0); } // Create the second-level itable, in which hashcode is looked up by binary searching GenTableSymbol(ITAB_CONFLICT_PREFIX_STR, klass.GetKlassName(), *secondItabEmitArray); // push the conflict symbol to the first-level itable StIdx symIdx = GlobalTables::GetGsymTable().GetStIdxFromStrIdx( GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(ITAB_CONFLICT_PREFIX_STR + klass.GetKlassName())); - firstItabEmitArray->PushBack(GetMIRModule().GetMemPool()->New(symIdx, 0, *voidPtrType)); + firstItabEmitArray->AddItem(GetMIRModule().GetMemPool()->New(symIdx, 0, *voidPtrType), 0); } GenTableSymbol(ITAB_PREFIX_STR, klass.GetKlassName(), *firstItabEmitArray); } diff --git a/src/mplfe/BUILD.gn b/src/mplfe/BUILD.gn index 396dbaab18501a50052763a78e62be1d85a22c45..d953f636a3a9e1fd59dfbb8be54670f3183e8f90 100644 --- a/src/mplfe/BUILD.gn +++ b/src/mplfe/BUILD.gn @@ -37,11 +37,10 @@ include_directories = [ "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", "${MPLFE_ROOT}/ast_input/include", "${MPLFE_ROOT}/ast_input/lib", "${LLVMINC}", - "//../third-party/cfe-8.0.0.src/tools", "//../ThirdParty/cfe-8.0.0.src/tools", ] @@ -109,7 +108,7 @@ executable("mplfe") { ":lib_mplfe_bc_input", ":lib_mplfe_dex_input", ":lib_mplfe_util", - "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", + "//../ThirdParty/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_driver:libdriver_option", "${MAPLEALL_ROOT}/maple_ir:libmplir", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", @@ -131,7 +130,7 @@ include_jbc_input_directories = [ "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] static_library("lib_mplfe_jbc_input") { @@ -166,7 +165,7 @@ include_bc_input_directories = [ "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] static_library("lib_mplfe_bc_input") { @@ -195,7 +194,7 @@ include_dex_input_directories = [ "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", ] static_library("lib_mplfe_dex_input") { diff --git a/src/mplfe/ast_input/include/ast_decl.h b/src/mplfe/ast_input/include/ast_decl.h index c631145de587095b047a6f2910aa502b7846bf95..9c1374d3978a7270af7bf19ce2c7b84d79ba042d 100644 --- a/src/mplfe/ast_input/include/ast_decl.h +++ b/src/mplfe/ast_input/include/ast_decl.h @@ -26,7 +26,7 @@ namespace maple { class ASTDecl { public: ASTDecl(const std::string &srcFile, const std::string &nameIn, const std::vector &typeDescIn) - : srcFileName(srcFile), name(nameIn), typeDesc(typeDescIn) {} + : isGlobalDecl(false), srcFileName(srcFile), name(nameIn), typeDesc(typeDescIn) {} virtual ~ASTDecl() = default; const std::string &GetSrcFileName() const; const std::string &GetName() const; @@ -35,7 +35,16 @@ class ASTDecl { return genAttrs; } + void SetGlobal(bool isGlobal) { + isGlobalDecl = isGlobal; + } + + bool IsGlobal() const { + return isGlobalDecl; + } + protected: + bool isGlobalDecl; const std::string srcFileName; std::string name; std::vector typeDesc; @@ -109,20 +118,6 @@ class ASTStruct : public ASTDecl { std::list methods; }; -union VarValue { - bool b; - uint8 u8; - int8 i8; - uint16 u16; - int16 i16; - uint32 u32; - int32 i32; - float f32; - uint64 u64 = 0; - int64 i64; - double d; -}; - class ASTVar : public ASTDecl { public: ASTVar(const std::string &srcFile, const std::string &nameIn, const std::vector &typeDescIn, @@ -131,23 +126,17 @@ class ASTVar : public ASTDecl { genAttrs = genAttrsIn; } virtual ~ASTVar() = default; -}; -class ASTPrimitiveVar : public ASTVar { - public: - ASTPrimitiveVar(const std::string &srcFile, const std::string &varName, const std::vector &typeDescIn, - VarValue value, const GenericAttrs &genAttrsIn) - : ASTVar(srcFile, varName, typeDescIn, genAttrsIn) { - val = value; + void SetInitExpr(ASTExpr *init) { + initExpr = init; } - ~ASTPrimitiveVar() = default; - VarValue GetVal() const { - return val; + ASTExpr *GetInitExpr() const { + return initExpr; } private: - VarValue val; + ASTExpr *initExpr = nullptr; }; } // namespace maple #endif // MPLFE_AST_INPUT_INCLUDE_AST_DECL_H diff --git a/src/mplfe/ast_input/include/ast_decl_builder.h b/src/mplfe/ast_input/include/ast_decl_builder.h index 012e9af00ebc19ad6759b19d4c1318ebc29fdaff..4fb2d3733d0c4ecf9a86bbcc94e6e81d26e66c53 100644 --- a/src/mplfe/ast_input/include/ast_decl_builder.h +++ b/src/mplfe/ast_input/include/ast_decl_builder.h @@ -23,10 +23,9 @@ ASTDecl *ASTDeclBuilder(MapleAllocator &allocator, const std::string &srcFile, return allocator.GetMemPool()->New(srcFile, nameIn, typeDescIn); } -ASTPrimitiveVar *ASTPrimitiveVarBuilder(MapleAllocator &allocator, const std::string &srcFile, - const std::string &varName, const std::vector &desc, - VarValue val, const GenericAttrs &genAttrsIn) { - return allocator.GetMemPool()->New(srcFile, varName, desc, val, genAttrsIn); +ASTVar *ASTVarBuilder(MapleAllocator &allocator, const std::string &srcFile, + const std::string &varName, const std::vector &desc, const GenericAttrs &genAttrsIn) { + return allocator.GetMemPool()->New(srcFile, varName, desc, genAttrsIn); } ASTFunc *ASTFuncBuilder(MapleAllocator &allocator, const std::string &srcFile, const std::string &nameIn, diff --git a/src/mplfe/ast_input/include/ast_expr.h b/src/mplfe/ast_input/include/ast_expr.h index b5009e4903dad6153cfb5b7476cb8c728be28fe7..93962d1d93558c6ba615b7dbad0cccbd7b2c7331 100644 --- a/src/mplfe/ast_input/include/ast_expr.h +++ b/src/mplfe/ast_input/include/ast_expr.h @@ -800,8 +800,17 @@ class ASTCharacterLiteral : public ASTExpr { ASTCharacterLiteral() : ASTExpr(kASTCharacterLiteral) {} ~ASTCharacterLiteral() = default; + int8 GetVal() const { + return val; + } + + void SetVal(int8 valIn) { + val = valIn; + } + private: UniqueFEIRExpr Emit2FEExprImpl(std::list &stmts) const override; + int8 val; }; class ASTVAArgExpr : public ASTExpr { @@ -849,7 +858,17 @@ class ASTImaginaryLiteral : public ASTExpr { child = astExpr; } + void SetComplexType(MIRType *structType) { + complexType = structType; + } + + void SetElemType(MIRType *type) { + elemType = type; + } + private: + MIRType *complexType = nullptr; + MIRType *elemType = nullptr; ASTExpr *child = nullptr; UniqueFEIRExpr Emit2FEExprImpl(std::list &stmts) const override; }; diff --git a/src/mplfe/ast_input/include/ast_input.h b/src/mplfe/ast_input/include/ast_input.h index 07ce3cc837836a5ded4fab98cc9b6512f9c7dff4..50977cfee2beaea7be98d180c5ba1e9d4b2d1fb7 100644 --- a/src/mplfe/ast_input/include/ast_input.h +++ b/src/mplfe/ast_input/include/ast_input.h @@ -47,11 +47,11 @@ class ASTInput { astFuncs.emplace_back(astFunc); } - const MapleList &GetASTVars() const { + const MapleList &GetASTVars() const { return astVars; } - void AddASTPrimitiveVar(ASTPrimitiveVar *astVar) { + void AddASTVar(ASTVar *astVar) { astVars.emplace_back(astVar); } @@ -62,7 +62,7 @@ class ASTInput { MapleList astStructs; MapleList astFuncs; - MapleList astVars; + MapleList astVars; }; } #endif // MPLFE_AST_INPUT_INCLUDE_AST_INPUT_H \ No newline at end of file diff --git a/src/mplfe/ast_input/include/ast_parser.h b/src/mplfe/ast_input/include/ast_parser.h index 2947f12fddab53c486d4e39abefd3e40e029d99b..d7a076173efed1d83d1e0297bcf137d100dea7d4 100644 --- a/src/mplfe/ast_input/include/ast_parser.h +++ b/src/mplfe/ast_input/include/ast_parser.h @@ -34,7 +34,7 @@ class ASTParser { bool RetrieveStructs(MapleAllocator &allocator, MapleList &structs); bool RetrieveFuncs(MapleAllocator &allocator, MapleList &funcs); - bool RetrieveGlobalVars(MapleAllocator &allocator, MapleList &vars); + bool RetrieveGlobalVars(MapleAllocator &allocator, MapleList &vars); const std::string &GetSourceFileName() const; const uint32 GetFileIdx() const; @@ -130,7 +130,6 @@ ASTDecl *ProcessDecl(MapleAllocator &allocator, const clang::Decl &decl); private: void TraverseDecl(clang::Decl *decl, std::function const &functor); - VarValue GetVarInitVal(MapleAllocator &allocator, clang::VarDecl varDecl); uint32 fileIdx; const std::string fileName; std::unique_ptr astFile; diff --git a/src/mplfe/ast_input/include/ast_struct2fe_helper.h b/src/mplfe/ast_input/include/ast_struct2fe_helper.h index 7fb4af3dabed2c939ae6a61a769befbbc663b032..6783ef3b50f2d855350d6fdeb35f958edacf340f 100644 --- a/src/mplfe/ast_input/include/ast_struct2fe_helper.h +++ b/src/mplfe/ast_input/include/ast_struct2fe_helper.h @@ -45,14 +45,14 @@ class ASTStruct2FEHelper : public FEInputStructHelper { class ASTGlobalVar2FEHelper : public FEInputGlobalVarHelper { public: - ASTGlobalVar2FEHelper(MapleAllocator &allocatorIn, const ASTPrimitiveVar &varIn) + ASTGlobalVar2FEHelper(MapleAllocator &allocatorIn, const ASTVar &varIn) : FEInputGlobalVarHelper(allocatorIn), astVar(varIn) {} ~ASTGlobalVar2FEHelper() = default; protected: bool ProcessDeclImpl(MapleAllocator &allocator) override; - const ASTPrimitiveVar &astVar; + const ASTVar &astVar; }; class ASTStructField2FEHelper : public FEInputFieldHelper { diff --git a/src/mplfe/ast_input/lib/ast_macros.h b/src/mplfe/ast_input/lib/ast_macros.h index 2469e1e85b5b358a7ba6b65ae878a04622aaee56..9e319854d0f8d7f5140c7f1df3e43732a13ac7ed 100644 --- a/src/mplfe/ast_input/lib/ast_macros.h +++ b/src/mplfe/ast_input/lib/ast_macros.h @@ -176,19 +176,6 @@ const int kDefaultIndent = 1; << '\n'; \ } \ } while (0); - -// timing stmt -#define TIMEIT(message, stmt) \ - if (maple::ast2mplDebug == CHECKTIME) { \ - struct timeval start, end; \ - gettimeofday(&start, nullptr); \ - stmt; \ - gettimeofday(&end, nullptr); \ - float t = ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)) * 1.0 / 1000000.0; \ - printf("%s: %f sec\n", message, t); \ - } else { \ - stmt; \ - } #else #define DUMPINFO(stmtClass, s) @@ -205,7 +192,6 @@ const int kDefaultIndent = 1; #define DEBUGPRINT_NN_LEVEL(var0, var1, level) #define DEBUGPRINT_VV_LEVEL(var0, var1, level) #define DEBUGPRINT_SV_LEVEL(val0, var, level) -#define TIMEIT(message, stmt) stmt #endif #define DEBUGPRINT00 DEBUGPRINT_N(0) diff --git a/src/mplfe/ast_input/lib/ast_util.cpp b/src/mplfe/ast_input/lib/ast_util.cpp index cc6c2afaa9d5381f13558c20f1b48d711d7bdc8b..37399ce1878aa0c974a6d82686897e0d33bad542 100644 --- a/src/mplfe/ast_input/lib/ast_util.cpp +++ b/src/mplfe/ast_input/lib/ast_util.cpp @@ -19,6 +19,7 @@ #include "mir_nodes.h" #include "mir_builder.h" #include "ast_macros.h" +#include "fe_utils_ast.h" namespace maple { int ast2mplDebug = 0; @@ -206,37 +207,6 @@ Opcode ASTUtil::CvtUnaryOpcode(uint32_t opcode) { } } -const std::string ASTUtil::Type2Label(PrimType primType) { - switch (primType) { - case PTY_u1: - return "B"; - case PTY_i8: - return "A"; - case PTY_u8: - return "C"; - case PTY_i16: - return "S"; - case PTY_u16: - return "T"; - case PTY_i32: - return "I"; - case PTY_u32: - return "M"; - case PTY_i64: - return "O"; - case PTY_u64: - return "Q"; - case PTY_f32: - return "F"; - case PTY_f64: - return "D"; - case PTY_void: - return "V"; - default: - return "R"; - } -} - uint32 ASTUtil::GetDim(MIRType &type) { MIRType *ptrType = &type; if (type.GetKind() == kTypePointer) { @@ -265,7 +235,7 @@ std::string ASTUtil::GetTypeString(MIRType &type) { } switch (type.GetKind()) { case kTypeScalar: - ss << Type2Label(type.GetPrimType()); + ss << FEUtilAST::Type2Label(type.GetPrimType()); break; case kTypeStruct: case kTypeClass: diff --git a/src/mplfe/ast_input/lib/ast_util.h b/src/mplfe/ast_input/lib/ast_util.h index 0fa8bb2b9b2078e5c7cf95a3c24008d0a8aed793..3b29774bb2371c390bf24519c74783f51f5d458b 100644 --- a/src/mplfe/ast_input/lib/ast_util.h +++ b/src/mplfe/ast_input/lib/ast_util.h @@ -41,7 +41,6 @@ class ASTUtil { static uint32 GetDim(MIRType &type); static std::string GetTypeString(MIRType &type); - static const std::string Type2Label(PrimType primType); static MIRType *CvtPrimType(const clang::QualType type); static Opcode CvtUnaryOpcode(uint32_t opcode); diff --git a/src/mplfe/ast_input/src/ast_expr.cpp b/src/mplfe/ast_input/src/ast_expr.cpp index c44c8f83535158891545b35a345a471c76357a29..49550063880d55b829ed8ff8085d7ad5a4c2f88a 100644 --- a/src/mplfe/ast_input/src/ast_expr.cpp +++ b/src/mplfe/ast_input/src/ast_expr.cpp @@ -19,6 +19,7 @@ #include "feir_builder.h" #include "fe_utils_ast.h" #include "feir_type_helper.h" +#include "fe_manager.h" namespace maple { // ---------- ASTExpr ---------- @@ -28,16 +29,34 @@ UniqueFEIRExpr ASTExpr::Emit2FEExpr(std::list &stmts) const { // ---------- ASTRefExpr --------- UniqueFEIRExpr ASTDeclRefExpr::Emit2FEExprImpl(std::list &stmts) const { - PrimType primType = var->GetTypeDesc().front()->GetPrimType(); - // A method is required to determine whether the var is global, need to update - UniqueFEIRVar feirVar = FEIRBuilder::CreateVarName(var->GetName(), primType, true, false); + UniqueFEIRVar feirVar = FEIRBuilder::CreateVarNameForC(var->GetName(), *(var->GetTypeDesc().front()), + var->IsGlobal(), false); UniqueFEIRExpr feirRefExpr = FEIRBuilder::CreateExprDRead(std::move(feirVar)); return feirRefExpr; } // ---------- ASTCallExpr ---------- UniqueFEIRExpr ASTCallExpr::Emit2FEExprImpl(std::list &stmts) const { - CHECK_FATAL(false, "NIY"); + // callassigned &funcName + StructElemNameIdx *nameIdx = FEManager::GetManager().GetStructElemMempool()->New(funcName); + FEStructMethodInfo *info = static_cast( + FEManager::GetTypeManager().RegisterStructMethodInfo(*nameIdx, kSrcLangC, false)); + std::unique_ptr callStmt = std::make_unique( + *info, OP_callassigned, nullptr, false); + // args + for (int32 i = args.size() - 1; i >= 0; --i) { + UniqueFEIRExpr expr = args[i]->Emit2FEExpr(stmts); + callStmt->AddExprArgReverse(std::move(expr)); + } + // return + if (retType->GetPrimType() != PTY_void) { + const std::string &varName = FEUtils::GetSequentialName("retVar_"); + UniqueFEIRVar var = FEIRBuilder::CreateVarNameForC(varName, *retType, false, false); + UniqueFEIRVar dreadVar = var->Clone(); + callStmt->SetVar(std::move(var)); + stmts.emplace_back(std::move(callStmt)); + return FEIRBuilder::CreateExprDRead(std::move(dreadVar)); + } return nullptr; } @@ -95,9 +114,9 @@ UniqueFEIRExpr ASTUOPostIncExpr::Emit2FEExprImpl(std::list &stmt PrimType subPrimType = subType->GetPrimType(); // postinc_1 = a, subVar attr need update - UniqueFEIRVar selfVar = FEIRBuilder::CreateVarName(refName, subPrimType, true, false); + UniqueFEIRVar selfVar = FEIRBuilder::CreateVarNameForC(refName, *subType, false, false); UniqueFEIRVar selfMoveVar = selfVar->Clone(); - UniqueFEIRVar tempVar = FEIRBuilder::CreateVarName(FEUtils::GetSequentialName("postinc_"), subPrimType); + UniqueFEIRVar tempVar = FEIRBuilder::CreateVarNameForC(FEUtils::GetSequentialName("postinc_"), *subType); UniqueFEIRVar tempMoveVar = tempVar->Clone(); UniqueFEIRExpr readSelfExpr = FEIRBuilder::CreateExprDRead(std::move(selfMoveVar)); UniqueFEIRStmt readSelfstmt = FEIRBuilder::CreateStmtDAssign(std::move(tempMoveVar), std::move(readSelfExpr)); @@ -132,9 +151,9 @@ UniqueFEIRExpr ASTUOPostDecExpr::Emit2FEExprImpl(std::list &stmt PrimType subPrimType = subType->GetPrimType(); // postdec_1 = a, selfVar attr need update - UniqueFEIRVar selfVar = FEIRBuilder::CreateVarName(refName, subPrimType, true, false); + UniqueFEIRVar selfVar = FEIRBuilder::CreateVarNameForC(refName, *subType, false, false); UniqueFEIRVar selfMoveVar = selfVar->Clone(); - UniqueFEIRVar tempVar = FEIRBuilder::CreateVarName(FEUtils::GetSequentialName("postinc_"), subPrimType); + UniqueFEIRVar tempVar = FEIRBuilder::CreateVarNameForC(FEUtils::GetSequentialName("postinc_"), *subType); UniqueFEIRVar tempMoveVar = tempVar->Clone(); UniqueFEIRExpr readSelfExpr = FEIRBuilder::CreateExprDRead(std::move(selfMoveVar)); UniqueFEIRStmt readSelfstmt = FEIRBuilder::CreateStmtDAssign(std::move(tempMoveVar), @@ -182,7 +201,7 @@ UniqueFEIRExpr ASTUOPreIncExpr::Emit2FEExprImpl(std::list &stmts // a = a + 1, selfVar attr need update UniqueFEIRExpr astUOPreIncExpr = FEIRBuilder::CreateExprMathBinary(OP_add, std::move(childFEIRExpr), std::move(incDecExpr)); - UniqueFEIRVar selfVar = FEIRBuilder::CreateVarName(refName, subPrimType, true, false); + UniqueFEIRVar selfVar = FEIRBuilder::CreateVarNameForC(refName, *subType, false, false); UniqueFEIRVar selfMoveVar = selfVar->Clone(); UniqueFEIRStmt stmt = FEIRBuilder::CreateStmtDAssign(std::move(selfMoveVar), std::move(astUOPreIncExpr)); stmts.emplace_back(std::move(stmt)); @@ -211,7 +230,7 @@ UniqueFEIRExpr ASTUOPreDecExpr::Emit2FEExprImpl(std::list &stmts // a = a - 1, selfVar attr need update UniqueFEIRExpr astUOPreIncExpr = FEIRBuilder::CreateExprMathBinary(OP_sub, std::move(childFEIRExpr), std::move(incDecExpr)); - UniqueFEIRVar selfVar = FEIRBuilder::CreateVarName(refName, subPrimType, true, false); + UniqueFEIRVar selfVar = FEIRBuilder::CreateVarNameForC(refName, *subType, false, false); UniqueFEIRVar selfMoveVar = selfVar->Clone(); UniqueFEIRStmt stmt = FEIRBuilder::CreateStmtDAssign(std::move(selfMoveVar), std::move(astUOPreIncExpr)); stmts.emplace_back(std::move(stmt)); @@ -227,9 +246,9 @@ UniqueFEIRExpr ASTUOAddrOfExpr::Emit2FEExprImpl(std::list &stmts UniqueFEIRExpr addrOfExpr; if (childExpr->GetASTOp() == kASTOpRef) { ASTDecl *var = static_cast(childExpr)->GetASTDecl(); - PrimType primType = var->GetTypeDesc().front()->GetPrimType(); // var attr should update - UniqueFEIRVar addrOfVar = FEIRBuilder::CreateVarName(var->GetName(), primType, true, false); + UniqueFEIRVar addrOfVar = FEIRBuilder::CreateVarNameForC(var->GetName(), *(var->GetTypeDesc().front()), + false, false); addrOfExpr = FEIRBuilder::CreateExprAddrofVar(std::move(addrOfVar)); } else { // other potential expr should concern UniqueFEIRExpr childFEIRExpr; @@ -516,7 +535,10 @@ UniqueFEIRExpr ASTBOPtrMemI::Emit2FEExprImpl(std::list &stmts) c // ---------- ASTParenExpr ---------- UniqueFEIRExpr ASTParenExpr::Emit2FEExprImpl(std::list &stmts) const { - return child->Emit2FEExpr(stmts); + ASTExpr *childExpr = child; + CHECK_FATAL(childExpr != nullptr, "childExpr is nullptr"); + UniqueFEIRExpr childFEIRExpr = childExpr->Emit2FEExpr(stmts); + return childFEIRExpr; } // ---------- ASTIntegerLiteral ---------- @@ -539,8 +561,8 @@ UniqueFEIRExpr ASTFloatingLiteral::Emit2FEExprImpl(std::list &st // ---------- ASTCharacterLiteral ---------- UniqueFEIRExpr ASTCharacterLiteral::Emit2FEExprImpl(std::list &stmts) const { - CHECK_FATAL(false, "NIY"); - return nullptr; + UniqueFEIRExpr constExpr = FEIRBuilder::CreateExprConstI8(val); + return constExpr; } // ---------- ASTConditionalOperator ---------- @@ -557,8 +579,23 @@ UniqueFEIRExpr ASTConstantExpr::Emit2FEExprImpl(std::list &stmts // ---------- ASTImaginaryLiteral ---------- UniqueFEIRExpr ASTImaginaryLiteral::Emit2FEExprImpl(std::list &stmts) const { - CHECK_FATAL(false, "NIY"); - return nullptr; + CHECK_NULL_FATAL(complexType); + GStrIdx nameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(FEUtils::GetSequentialName("Complex_")); + UniqueFEIRVar complexVar = FEIRBuilder::CreateVarNameForC(nameIdx, *complexType); + UniqueFEIRVar clonedComplexVar = complexVar->Clone(); + UniqueFEIRVar clonedComplexVar2 = complexVar->Clone(); + // real number + UniqueFEIRExpr zeroConstExpr = FEIRBuilder::CreateExprZeroConst(elemType->GetPrimType()); + UniqueFEIRStmt realStmt = std::make_unique(std::move(complexVar), std::move(zeroConstExpr), 1); + stmts.emplace_back(std::move(realStmt)); + // imaginary number + CHECK_FATAL(child != nullptr, "childExpr is nullptr"); + UniqueFEIRExpr childFEIRExpr = child->Emit2FEExpr(stmts); + UniqueFEIRStmt imagStmt = std::make_unique(std::move(clonedComplexVar), std::move(childFEIRExpr), 2); + stmts.emplace_back(std::move(imagStmt)); + // return expr to parent operation + UniqueFEIRExpr expr = FEIRBuilder::CreateExprDRead(std::move(clonedComplexVar2)); + return expr; } // ---------- ASTCompoundAssignOperatorExpr ---------- diff --git a/src/mplfe/ast_input/src/ast_parser.cpp b/src/mplfe/ast_input/src/ast_parser.cpp index 950af04c3ba15917f9c9f55972d88969374533ef..5ffc1ea262a81b3d9f7bb541dbe8d46562f2b721 100644 --- a/src/mplfe/ast_input/src/ast_parser.cpp +++ b/src/mplfe/ast_input/src/ast_parser.cpp @@ -924,8 +924,15 @@ ASTExpr *ASTParser::ProcessExprConstantExpr(MapleAllocator &allocator, const cla } ASTExpr *ASTParser::ProcessExprImaginaryLiteral(MapleAllocator &allocator, const clang::ImaginaryLiteral &expr) { + clang::QualType complexQualType = expr.getType().getCanonicalType(); + MIRType *complexType = astFile->CvtType(complexQualType); + CHECK_NULL_FATAL(complexType); + clang::QualType elemQualType = llvm::cast(complexQualType)->getElementType(); + MIRType *elemType = astFile->CvtType(elemQualType); + CHECK_NULL_FATAL(elemType); ASTImaginaryLiteral *astImaginaryLiteral = ASTExprBuilder(allocator); - ASSERT(astImaginaryLiteral != nullptr, "astImaginaryLiteral is nullptr"); + astImaginaryLiteral->SetComplexType(complexType); + astImaginaryLiteral->SetElemType(elemType); ASTExpr *astExpr = ProcessExpr(allocator, expr.getSubExpr()); if (astExpr == nullptr) { return nullptr; @@ -982,6 +989,13 @@ ASTExpr *ASTParser::ProcessExprParenExpr(MapleAllocator &allocator, const clang: ASTExpr *ASTParser::ProcessExprCharacterLiteral(MapleAllocator &allocator, const clang::CharacterLiteral &expr) { ASTCharacterLiteral *astCharacterLiteral = ASTExprBuilder(allocator); ASSERT(astCharacterLiteral != nullptr, "astCharacterLiteral is nullptr"); + const clang::QualType qualType = expr.getType(); + const auto *type = llvm::cast(qualType.getTypePtr()); + clang::BuiltinType::Kind kind = type->getKind(); + if (qualType->isPromotableIntegerType()) { + kind = clang::BuiltinType::Int; + } + astCharacterLiteral->SetVal(expr.getValue()); return astCharacterLiteral; } @@ -1033,6 +1047,7 @@ ASTExpr *ASTParser::ProcessExprImplicitCastExpr(MapleAllocator &allocator, const case clang::CK_ArrayToPointerDecay: case clang::CK_FunctionToPointerDecay: case clang::CK_FloatingCast: + case clang::CK_IntegralCast: case clang::CK_LValueToRValue: { ASTExpr *astExpr = ProcessExpr(allocator, expr.getSubExpr()); if (astExpr == nullptr) { @@ -1385,8 +1400,11 @@ ASTDecl *ASTParser::ProcessDeclVarDecl(MapleAllocator &allocator, const clang::V } GenericAttrs attrs; astFile->CollectAttrs(varDecl, attrs, kPublic); - VarValue val = GetVarInitVal(allocator, varDecl); - return ASTPrimitiveVarBuilder(allocator, fileName, varName, std::vector{varType}, val, attrs); + ASTVar *astVar = ASTVarBuilder(allocator, fileName, varName, std::vector{varType}, attrs); + if (varDecl.hasInit()) { + astVar->SetInitExpr(ProcessExpr(allocator, varDecl.getInit())); + } + return astVar; } bool ASTParser::RetrieveStructs(MapleAllocator &allocator, MapleList &structs) { @@ -1416,52 +1434,15 @@ bool ASTParser::RetrieveFuncs(MapleAllocator &allocator, MapleList &fu return true; } -VarValue ASTParser::GetVarInitVal(MapleAllocator &allocator, clang::VarDecl varDecl) { - VarValue value; - if (!varDecl.hasInit()) { - return value; - } - const clang::Expr *init = varDecl.getInit(); - init = llvm::isa(init) ? llvm::cast(init)->getSubExpr() : init; - init = llvm::isa(init) ? - llvm::cast(init)->getSubExpr() : init; - if (init->getType().getTypePtr()->isDependentType()) { - return value; - } - ASTExpr *expr = ProcessExpr(allocator, init); - switch (init->getStmtClass()) { - case clang::Stmt::IntegerLiteralClass: { - ASTIntegerLiteral *intExpr = static_cast(expr); - value.u64 = intExpr->GetVal(); - break; - } - case clang::Stmt::FloatingLiteralClass: { - ASTFloatingLiteral *floatExpr = static_cast(expr); - value.d = floatExpr->GetVal(); - break; - } - case clang::Stmt::ImplicitCastExprClass: { - ASTImplicitCastExpr *implicitCastExpr = static_cast(expr); - if (llvm::cast(init)->getCastKind() == clang::CK_FloatingCast) { - ASTFloatingLiteral *floatExpr = static_cast(implicitCastExpr->GetASTExpr()); - value.f32 = floatExpr->GetVal(); - } - break; - } - default: - break; - } - return value; -} - // seperate MP with astparser -bool ASTParser::RetrieveGlobalVars(MapleAllocator &allocator, MapleList &vars) { +bool ASTParser::RetrieveGlobalVars(MapleAllocator &allocator, MapleList &vars) { for (auto &decl : globalVarDecles) { clang::VarDecl varDecl = llvm::cast(*decl); - ASTPrimitiveVar *val = static_cast(ProcessDecl(allocator, varDecl)); + ASTVar *val = static_cast(ProcessDecl(allocator, varDecl)); if (val == nullptr) { return false; } + val->SetGlobal(true); vars.emplace_back(val); } return true; diff --git a/src/mplfe/ast_input/src/ast_stmt.cpp b/src/mplfe/ast_input/src/ast_stmt.cpp index d1d3395167a2caaa6968320528ae20e37920f1f7..68623eb449d277a347f3029f03500ea184e2bae4 100644 --- a/src/mplfe/ast_input/src/ast_stmt.cpp +++ b/src/mplfe/ast_input/src/ast_stmt.cpp @@ -135,8 +135,17 @@ std::list ASTNullStmt::Emit2FEStmtImpl() const { // ---------- ASTDeclStmt ---------- std::list ASTDeclStmt::Emit2FEStmtImpl() const { - CHECK_FATAL(false, "NYI"); std::list stmts; + for (auto decl : subDecls) { + auto localVar = static_cast(decl); + if (localVar->GetInitExpr() != nullptr) { + UniqueFEIRVar feirVar = FEIRBuilder::CreateVarNameForC(localVar->GetName(), *(localVar->GetTypeDesc().front()), + false, false); + UniqueFEIRExpr expr = localVar->GetInitExpr()->Emit2FEExpr(stmts); + UniqueFEIRStmt stmt = FEIRBuilder::CreateStmtDAssign(std::move(feirVar), std::move(expr)); + stmts.emplace_back(std::move(stmt)); + } + } return stmts; } @@ -161,7 +170,7 @@ std::list ASTCallExprStmt::Emit2FEStmtImpl() const { PrimType primType = callExpr->GetRetType()->GetPrimType(); if (primType != PTY_void) { const std::string &varName = FEUtils::GetSequentialName("retVar_"); - UniqueFEIRVar var = FEIRBuilder::CreateVarName(varName, primType, false, false); + UniqueFEIRVar var = FEIRBuilder::CreateVarNameForC(varName, *(callExpr->GetRetType()), false, false); callStmt->SetVar(std::move(var)); } stmts.emplace_back(std::move(callStmt)); diff --git a/src/mplfe/ast_input/src/ast_struct2fe_helper.cpp b/src/mplfe/ast_input/src/ast_struct2fe_helper.cpp index 270159904334586a73ef90bdfea9c9ea6f68150d..dc22e8d7519ca56bfe0784777d4e9aa575adf55e 100644 --- a/src/mplfe/ast_input/src/ast_struct2fe_helper.cpp +++ b/src/mplfe/ast_input/src/ast_struct2fe_helper.cpp @@ -142,21 +142,30 @@ bool ASTGlobalVar2FEHelper::ProcessDeclImpl(MapleAllocator &allocator) { if (mirSymbol == nullptr) { return false; } + mirSymbol->SetAttrs(astVar.GetGenericAttrs().ConvertToTypeAttrs()); PrimType primType = type->GetPrimType(); if (primType != PTY_ref && primType != PTY_agg && primType != PTY_ptr) { MIRConst *cst = nullptr; + std::list stmts; + ASTExpr *initExpr = astVar.GetInitExpr(); + if (initExpr == nullptr) { + return true; + } + UniqueFEIRExpr expr = initExpr->Emit2FEExpr(stmts); + FEIRExprConst *constExpr = static_cast(expr.get()); switch (primType) { + case PTY_i8: case PTY_i32: case PTY_u32: case PTY_i64: case PTY_u64: - cst = allocator.GetMemPool()->New(static_cast(astVar.GetVal().u64), *type); + cst = allocator.GetMemPool()->New(static_cast(constExpr->GetValue().u64), *type); break; case PTY_f32: - cst = allocator.GetMemPool()->New(astVar.GetVal().f32, *type); + cst = allocator.GetMemPool()->New(constExpr->GetValue().f32, *type); break; case PTY_f64: - cst = allocator.GetMemPool()->New(astVar.GetVal().d, *type); + cst = allocator.GetMemPool()->New(constExpr->GetValue().f64, *type); break; default: CHECK_FATAL(false, "unsupported type."); @@ -164,7 +173,6 @@ bool ASTGlobalVar2FEHelper::ProcessDeclImpl(MapleAllocator &allocator) { } mirSymbol->SetKonst(cst); } - mirSymbol->SetAttrs(astVar.GetGenericAttrs().ConvertToTypeAttrs()); return true; } diff --git a/src/mplfe/bc_input/include/bc_instruction.h b/src/mplfe/bc_input/include/bc_instruction.h index 713f4364ea912864abec139e16bb1c2d7b848a4f..6fad4dc71c7c2b462c877e963fd099c09a585b98 100644 --- a/src/mplfe/bc_input/include/bc_instruction.h +++ b/src/mplfe/bc_input/include/bc_instruction.h @@ -54,7 +54,7 @@ class BCInstruction { uint32 GetPC() const; uint8 GetOpcode() const; std::vector GetTargets() const; - void SetDefultTarget(BCInstruction *inst); + void SetDefaultTarget(BCInstruction *inst); void AddHandler(BCInstruction *handler); void SetWidth(uint8 size); uint8 GetWidth() const; @@ -118,8 +118,8 @@ struct BCReg; struct TypeInferItem; struct BCRegTypeItem { - BCRegTypeItem(const GStrIdx &idx, bool isIndeterminateIn = false, bool isDefIn = false) - : typeNameIdx(idx), isIndeterminate(isIndeterminateIn), isDef(isDefIn) {} + BCRegTypeItem(const GStrIdx &idx, bool isIndeterminateIn = false, bool isFromDefIn = false) + : typeNameIdx(idx), isIndeterminate(isIndeterminateIn), isFromDef(isFromDefIn) {} BCRegTypeItem(const BCRegTypeItem &item) : typeNameIdx(item.typeNameIdx), isIndeterminate(item.isIndeterminate) {} ~BCRegTypeItem() = default; @@ -133,6 +133,7 @@ struct BCRegTypeItem { void Copy(const BCRegTypeItem &src) { typeNameIdx = src.typeNameIdx; isIndeterminate = src.isIndeterminate; + isFromDef = src.isFromDef; } bool operator==(const BCRegTypeItem &item) const { return typeNameIdx == item.typeNameIdx; @@ -155,7 +156,8 @@ struct BCRegTypeItem { GStrIdx typeNameIdx; bool isIndeterminate = false; - bool isDef = false; + // means `is def ` or `come from def` + bool isFromDef = false; uint32 pos = UINT32_MAX; }; @@ -225,7 +227,7 @@ class BCRegType { static BCRegTypeItem *GetMostPreciseType(const MapleList &types); - void AddElemType(BCRegType *item) { + void AddElemType(BCRegTypeItem *item) { elemTypes.emplace(item); } @@ -265,7 +267,7 @@ class BCRegType { MapleList *typesUsedAs = nullptr; MapleList fuzzyTypesUsedAs; bool precisified = false; - MapleSet elemTypes; + MapleSet elemTypes; uint32 pos = UINT32_MAX; // `0` for args, `pc + 1` for local defs MapleVector livesBegins; @@ -334,11 +336,11 @@ struct TypeInferItem { } void InsertUniqueAliveType(TypeInferItem *end, BCRegTypeItem *type) { - std::vector workList; - uint32 index = 0; if (end != nullptr && end->reg == this->reg && end->reg->regType->IsBefore(this->beginPos, end->beginPos)) { return; } + std::vector workList; + uint32 index = 0; workList.emplace_back(this); while (index < workList.size()) { auto currItem = workList[index++]; @@ -352,7 +354,7 @@ struct TypeInferItem { } if (!duplicate) { currItem->aliveUsedTypes->emplace_back(type); - reg->regType->UpdateFuzzyUsedSet(type); + currItem->reg->regType->UpdateFuzzyUsedSet(type); } // insert into its prevs cyclely for (auto prev : currItem->prevs) { diff --git a/src/mplfe/bc_input/src/bc_class.cpp b/src/mplfe/bc_input/src/bc_class.cpp index 4c19db1e187c094256f9b35b43a191a5fa577114..e1f102eeb88910017e5fe4afbb3bd45237f43809 100644 --- a/src/mplfe/bc_input/src/bc_class.cpp +++ b/src/mplfe/bc_input/src/bc_class.cpp @@ -165,10 +165,7 @@ void BCClassMethod::ProcessInstructions() { } if (inst->IsSwitch() && itor != pcBCInstructionMap->end()) { itor->second->SetInstructionKind(kTarget); - inst->SetDefultTarget(itor->second); - if (visitedPcSet.emplace(itor->first).second == false) { - multiInDegreeSet.emplace(itor->first); - } + inst->SetDefaultTarget(itor->second); } } if (itor == pcBCInstructionMap->end()) { @@ -307,6 +304,7 @@ void BCClassMethod::Traverse(std::listGetPC() + 1, defedReg, nullptr); @@ -326,6 +324,11 @@ void BCClassMethod::Traverse(std::listIsConditionBranch() || currInst->IsSwitch()) { + Traverse(pcDefedRegsList, dominances, visitedSet); + } } } auto normalTargets = currInst->GetTargets(); @@ -342,6 +345,7 @@ void BCClassMethod::Traverse(std::list BCInstruction::GetTargets() const { return GetTargetsImpl(); } -void BCInstruction::SetDefultTarget(BCInstruction *inst) { +void BCInstruction::SetDefaultTarget(BCInstruction *inst) { defaultTarget = inst; } @@ -318,7 +318,7 @@ bool BCRegTypeItem::IsMorePreciseType(const BCRegTypeItem &typeItemIn) const { } else if (isIndeterminate && typeItemIn.isIndeterminate) { return name1Idx == BCUtil::GetJavaObjectNameMplIdx(); } else { - return isDef ? + return isFromDef ? (name0Idx == BCUtil::GetJavaObjectNameMplIdx() || name1Idx != BCUtil::GetJavaObjectNameMplIdx()) : (name0Idx != BCUtil::GetJavaObjectNameMplIdx() || name1Idx == BCUtil::GetJavaObjectNameMplIdx()); } @@ -378,7 +378,9 @@ void BCRegType::PrecisifyTypes(bool isTry) { } } } - PrecisifyElemTypes(realType); + if (!realType->isIndeterminate) { + PrecisifyElemTypes(realType); + } } void BCRegType::PrecisifyRelatedTypes(BCRegTypeItem *realType) { @@ -391,9 +393,7 @@ void BCRegType::PrecisifyRelatedTypes(BCRegTypeItem *realType) { realType = GetMostPreciseType(*typesUsedAs); if (realType != nullptr) { for (auto &fuzzyTy : fuzzyTypesUsedAs) { - if (fuzzyTy->isIndeterminate) { - fuzzyTy->Copy(*realType); - } + fuzzyTy->Copy(*realType); } } } @@ -408,20 +408,12 @@ void BCRegType::PrecisifyRelatedTypes(BCRegTypeItem *realType) { void BCRegType::PrecisifyElemTypes(BCRegTypeItem *arrayType) { for (auto elem : elemTypes) { - if (elem->IsIndeterminate()) { + if (elem->isIndeterminate) { const std::string &arrTypeName = GlobalTables::GetStrTable().GetStringFromStrIdx(arrayType->typeNameIdx); if (arrTypeName.size() > 1 && arrTypeName.at(0) == 'A') { GStrIdx elemTypeIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(arrTypeName.substr(1)); - if (elem->IsPrecisified()) { - for (auto &e : elem->fuzzyTypesUsedAs) { - if (e->isIndeterminate) { - e->typeNameIdx = elemTypeIdx; - e->isIndeterminate = false; - } - } - } else { - elem->regTypeItem->typeNameIdx = elemTypeIdx; - } + elem->typeNameIdx = elemTypeIdx; + elem->isIndeterminate = false; } else { CHECK_FATAL(curReg.regValue != nullptr, "Not an array type or const 0"); } diff --git a/src/mplfe/common/include/fe_type_manager.h b/src/mplfe/common/include/fe_type_manager.h index 15147af0b30abfd79b389cab458c252037cdd120..e3208c823b8299bedde073e77dea5d82660579c6 100644 --- a/src/mplfe/common/include/fe_type_manager.h +++ b/src/mplfe/common/include/fe_type_manager.h @@ -111,6 +111,7 @@ class FETypeManager { MIRStructType *GetOrCreateStructType(const std::string &name); MIRStructType *CreateStructType(const std::string &name); + MIRType *GetOrCreateComplexStructType(const MIRType &elemType); MIRStructType *GetOrCreateClassOrInterfaceType(const GStrIdx &nameIdx, bool isInterface, FETypeFlag typeFlag, bool &isCreate); MIRStructType *GetOrCreateClassOrInterfaceType(const std::string &name, bool isInterface, FETypeFlag typeFlag, diff --git a/src/mplfe/common/include/fe_utils_ast.h b/src/mplfe/common/include/fe_utils_ast.h index 8c1b3a7ed4cebe91f611dac008cbabdeca2d26b6..7ca86a52146ad2217ba12c52b2cf892dd451abb7 100644 --- a/src/mplfe/common/include/fe_utils_ast.h +++ b/src/mplfe/common/include/fe_utils_ast.h @@ -22,6 +22,7 @@ namespace maple { class FEUtilAST { public: static PrimType GetTypeFromASTTypeName(const std::string &typeName); + static const std::string Type2Label(PrimType primType); private: FEUtilAST() = default; diff --git a/src/mplfe/common/include/feir_builder.h b/src/mplfe/common/include/feir_builder.h index 6cdc86c7864414545194f6c40425ebece0cdec66..1be7defc1a70b61e58e791e89cd7719716169165 100644 --- a/src/mplfe/common/include/feir_builder.h +++ b/src/mplfe/common/include/feir_builder.h @@ -37,6 +37,10 @@ class FEIRBuilder { bool withType = false); static UniqueFEIRVar CreateVarName(const std::string &name, PrimType primType, bool isGlobal = false, bool withType = false); + static UniqueFEIRVar CreateVarNameForC(GStrIdx nameIdx, MIRType &mirType, bool isGlobal = false, + bool withType = false, TypeDim dim = 0); + static UniqueFEIRVar CreateVarNameForC(const std::string &name, MIRType &mirType, bool isGlobal = false, + bool withType = false, TypeDim dim = 0); // Expr static UniqueFEIRExpr CreateExprDRead(UniqueFEIRVar srcVar); static UniqueFEIRExpr CreateExprAddrof(const std::vector &array); @@ -52,6 +56,7 @@ class FEIRBuilder { static UniqueFEIRExpr CreateExprConstI64(int64 val); static UniqueFEIRExpr CreateExprConstF32(float val); static UniqueFEIRExpr CreateExprConstF64(double val); + static UniqueFEIRExpr CreateExprZeroConst(PrimType primType); static UniqueFEIRExpr CreateExprMathUnary(Opcode op, UniqueFEIRVar var0); static UniqueFEIRExpr CreateExprMathUnary(Opcode op, UniqueFEIRExpr expr); static UniqueFEIRExpr CreateExprMathBinary(Opcode op, UniqueFEIRVar var0, UniqueFEIRVar var1); diff --git a/src/mplfe/common/include/feir_stmt.h b/src/mplfe/common/include/feir_stmt.h index f2f6803d00f82bf86d4d472be734f2f6318cc13e..589f1a7456224130ed2824f94b8ff380c4e0d7e3 100644 --- a/src/mplfe/common/include/feir_stmt.h +++ b/src/mplfe/common/include/feir_stmt.h @@ -339,6 +339,20 @@ class FEIRExpr { using UniqueFEIRExpr = std::unique_ptr; // ---------- FEIRExprConst ---------- +union ConstExprValue { + bool b; + uint8 u8; + int8 i8; + uint16 u16; + int16 i16; + uint32 u32; + int32 i32; + float f32; + uint64 u64 = 0; + int64 i64; + double f64; +}; + class FEIRExprConst : public FEIRExpr { public: FEIRExprConst(); @@ -349,12 +363,9 @@ class FEIRExprConst : public FEIRExpr { ~FEIRExprConst() = default; FEIRExprConst(const FEIRExprConst&) = delete; FEIRExprConst& operator=(const FEIRExprConst&) = delete; - uint64 GetValueRaw() const { - return value.raw; - } - void SetValueRaw(uint64 argValue) { - value.raw = argValue; + ConstExprValue GetValue() const { + return value; } protected: @@ -363,13 +374,7 @@ class FEIRExprConst : public FEIRExpr { private: void CheckRawValue2SetZero(); - union { - int64 valueI64; - uint64 valueU64; - float valueF32; - double valueF64; - uint64 raw; - } value; + ConstExprValue value; }; // ---------- FEIRExprDRead ---------- diff --git a/src/mplfe/common/include/feir_type.h b/src/mplfe/common/include/feir_type.h index c43462816fa1c3dcd83fd11e7a19a3061ac578f5..803ab0838c553c140beadbab732c091bad78e77f 100644 --- a/src/mplfe/common/include/feir_type.h +++ b/src/mplfe/common/include/feir_type.h @@ -29,6 +29,7 @@ enum FEIRTypeKind { kFEIRTypeDefault, kFEIRTypeByName, kFEIRTypePointer, + kFEIRTypenNative }; class FEIRType { @@ -278,6 +279,36 @@ class FEIRTypeByName : public FEIRTypeDefault { std::string typeName; }; + +// ---------- FEIRTypeNative ---------- +// MIRType is enclosed directly in FEIRTypeNative. +// Right now, FEIRTypeNative is only used for c-language. +// Because var type is translated as MIRType directly in stage of ast parse. +class FEIRTypeNative : public FEIRTypeDefault { + public: + FEIRTypeNative(MIRType &argMIRType, TypeDim argDim = 0); + ~FEIRTypeNative() = default; + FEIRTypeNative(const FEIRTypeNative&) = delete; + FEIRTypeNative &operator=(const FEIRTypeNative&) = delete; + + protected: + std::unique_ptr CloneImpl() const override; + MIRType *GenerateMIRTypeImpl(bool usePtr, PrimType ptyPtr) const override; + bool IsEqualToImpl(const FEIRType &argType) const override; + size_t HashImpl() const override; + bool IsScalarImpl() const override; + bool IsPreciseImpl() const override { + return true; + } + + bool IsValidImpl() const override { + return true; + } + + private: + MIRType &mirType; +}; + // ---------- FEIRTypePointer ---------- class FEIRTypePointer : public FEIRType { public: diff --git a/src/mplfe/common/src/fe_type_manager.cpp b/src/mplfe/common/src/fe_type_manager.cpp index 68388535cb08c1206c31d3391d2996102187414b..9fc1a309fa0e28a72f58810798be9ba348bc71fe 100644 --- a/src/mplfe/common/src/fe_type_manager.cpp +++ b/src/mplfe/common/src/fe_type_manager.cpp @@ -23,6 +23,7 @@ #include "feir_type_helper.h" #include "fe_macros.h" #include "types_def.h" +#include "fe_utils_ast.h" namespace maple { const UniqueFEIRType FETypeManager::kPrimFEIRTypeUnknown = std::make_unique(PTY_unknown); @@ -217,6 +218,28 @@ MIRStructType *FETypeManager::GetOrCreateStructType(const std::string &name) { return structType; } +/* + * create MIRStructType for complex number, e.g. + * type $Complex|F + */ +MIRType *FETypeManager::GetOrCreateComplexStructType(const MIRType &elemType) { + const std::string typeName = "Complex|" + FEUtilAST::Type2Label(elemType.GetPrimType()); + MIRStructType *structType = GetOrCreateStructType(typeName); + if (structType->GetFields().size() == 0) { + GStrIdx realStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("real"); + GStrIdx imagStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("imag"); + FieldAttrs fieldAttrs; + TyIdxFieldAttrPair pair(elemType.GetTypeIndex(), fieldAttrs); + FieldPair realPair(realStrIdx, pair); + FieldPair imagePair(imagStrIdx, pair); + structType->GetFields().push_back(realPair); + structType->GetFields().push_back(imagePair); + } + return structType; +} + MIRStructType *FETypeManager::GetClassOrInterfaceType(const GStrIdx &nameIdx) const { auto it = structNameTypeMap.find(nameIdx); if (it == structNameTypeMap.end()) { diff --git a/src/mplfe/common/src/fe_utils_ast.cpp b/src/mplfe/common/src/fe_utils_ast.cpp index afcfe871d278c82c891d52f89526016148f23e58..dfece44405f54e58227856c35eeb327047f70f60 100644 --- a/src/mplfe/common/src/fe_utils_ast.cpp +++ b/src/mplfe/common/src/fe_utils_ast.cpp @@ -34,4 +34,35 @@ PrimType FEUtilAST::GetTypeFromASTTypeName(const std::string &typeName) { CHECK_FATAL(it != mapASTTypeNameToType.end(), "Can not find typeName %s", typeName.c_str()); return it->second; } + +const std::string FEUtilAST::Type2Label(PrimType primType) { + switch (primType) { + case PTY_u1: + return "B"; + case PTY_i8: + return "A"; + case PTY_u8: + return "C"; + case PTY_i16: + return "S"; + case PTY_u16: + return "T"; + case PTY_i32: + return "I"; + case PTY_u32: + return "M"; + case PTY_i64: + return "O"; + case PTY_u64: + return "Q"; + case PTY_f32: + return "F"; + case PTY_f64: + return "D"; + case PTY_void: + return "V"; + default: + return "R"; + } +} } // namespace maple diff --git a/src/mplfe/common/src/feir_builder.cpp b/src/mplfe/common/src/feir_builder.cpp index d3f0e32daf3c3edfd2b60b68873ed44844a956df..4022391f19d74dec9e589a4a6d406873d3484245 100644 --- a/src/mplfe/common/src/feir_builder.cpp +++ b/src/mplfe/common/src/feir_builder.cpp @@ -85,6 +85,20 @@ UniqueFEIRVar FEIRBuilder::CreateVarName(const std::string &name, PrimType primT } } +UniqueFEIRVar FEIRBuilder::CreateVarNameForC(GStrIdx nameIdx, MIRType &mirType, bool isGlobal, bool withType, + TypeDim dim) { + UniqueFEIRType type = std::make_unique(mirType, dim); + UniqueFEIRVar var = std::make_unique(nameIdx, std::move(type), withType); + var->SetGlobal(isGlobal); + return var; +} + +UniqueFEIRVar FEIRBuilder::CreateVarNameForC(const std::string &name, MIRType &mirType, bool isGlobal, bool withType, + TypeDim dim) { + GStrIdx nameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); + return CreateVarNameForC(nameIdx, mirType, isGlobal, withType, dim); +} + UniqueFEIRExpr FEIRBuilder::CreateExprDRead(UniqueFEIRVar srcVar) { UniqueFEIRExpr expr = std::make_unique(std::move(srcVar)); CHECK_NULL_FATAL(expr); @@ -143,6 +157,21 @@ UniqueFEIRExpr FEIRBuilder::CreateExprConstF64(double val) { return std::make_unique(val); } +UniqueFEIRExpr FEIRBuilder::CreateExprZeroConst(PrimType primType) { + switch (primType) { + case PTY_f32: + return CreateExprConstF32(0.0f); + case PTY_f64: + return CreateExprConstF64(0.0); + case PTY_f128: + // Not Implemented + CHECK_FATAL(false, "Not Implemented"); + return nullptr; + default: + return std::make_unique(int64{ 0 }, primType); + } +} + UniqueFEIRExpr FEIRBuilder::CreateExprMathUnary(Opcode op, UniqueFEIRVar var0) { UniqueFEIRExpr opnd0 = CreateExprDRead(std::move(var0)); return std::make_unique(op, std::move(opnd0)); diff --git a/src/mplfe/common/src/feir_stmt.cpp b/src/mplfe/common/src/feir_stmt.cpp index a1f255b3cf0eb56c2ae08c3021d81bb23038ccb9..02d4de0c233744351768b38f15728862432c0a68 100644 --- a/src/mplfe/common/src/feir_stmt.cpp +++ b/src/mplfe/common/src/feir_stmt.cpp @@ -1662,14 +1662,14 @@ FEIRExprConst::FEIRExprConst() : FEIRExpr(FEIRNodeKind::kExprConst) { ASSERT(type != nullptr, "type is nullptr"); type->SetPrimType(PTY_i32); - value.raw = 0; + value.u64 = 0; } FEIRExprConst::FEIRExprConst(int64 val, PrimType argType) : FEIRExpr(FEIRNodeKind::kExprConst) { ASSERT(type != nullptr, "type is nullptr"); type->SetPrimType(argType); - value.valueI64 = val; + value.i64 = val; CheckRawValue2SetZero(); } @@ -1677,7 +1677,7 @@ FEIRExprConst::FEIRExprConst(uint64 val, PrimType argType) : FEIRExpr(FEIRNodeKind::kExprConst) { ASSERT(type != nullptr, "type is nullptr"); type->SetPrimType(argType); - value.valueU64 = val; + value.u64 = val; CheckRawValue2SetZero(); } @@ -1685,7 +1685,7 @@ FEIRExprConst::FEIRExprConst(float val) : FEIRExpr(FEIRNodeKind::kExprConst) { ASSERT(type != nullptr, "type is nullptr"); type->SetPrimType(PTY_f32); - value.valueF32 = val; + value.f32 = val; CheckRawValue2SetZero(); } @@ -1693,14 +1693,14 @@ FEIRExprConst::FEIRExprConst(double val) : FEIRExpr(FEIRNodeKind::kExprConst) { ASSERT(type != nullptr, "type is nullptr"); type->SetPrimType(PTY_f64); - value.valueF64 = val; + value.f64 = val; CheckRawValue2SetZero(); } std::unique_ptr FEIRExprConst::CloneImpl() const { std::unique_ptr expr = std::make_unique(); FEIRExprConst *exprConst = static_cast(expr.get()); - exprConst->value.raw = value.raw; + exprConst->value.u64 = value.u64; ASSERT(type != nullptr, "type is nullptr"); exprConst->type->SetPrimType(type->GetPrimType()); exprConst->CheckRawValue2SetZero(); @@ -1721,11 +1721,11 @@ BaseNode *FEIRExprConst::GenMIRNodeImpl(MIRBuilder &mirBuilder) const { case PTY_i64: case PTY_ref: case PTY_ptr: - return mirBuilder.CreateIntConst(value.valueI64, primType); + return mirBuilder.CreateIntConst(value.i64, primType); case PTY_f32: - return mirBuilder.CreateFloatConst(value.valueF32); + return mirBuilder.CreateFloatConst(value.f32); case PTY_f64: - return mirBuilder.CreateDoubleConst(value.valueF64); + return mirBuilder.CreateDoubleConst(value.f64); default: ERR(kLncErr, "unsupported const kind"); return nullptr; @@ -1733,7 +1733,7 @@ BaseNode *FEIRExprConst::GenMIRNodeImpl(MIRBuilder &mirBuilder) const { } void FEIRExprConst::CheckRawValue2SetZero() { - if (value.raw == 0) { + if (value.u64 == 0) { type->SetZero(true); } } @@ -2290,8 +2290,8 @@ void FEIRExprBinary::SetExprTypeByOpCompare() { PrimType primTypeOpnd0 = opnd0->GetPrimType(); PrimType primTypeOpnd1 = opnd1->GetPrimType(); CHECK_FATAL(primTypeOpnd0 == primTypeOpnd1 || - (opnd0->GetKind() == kExprConst && static_cast(opnd0.get())->GetValueRaw() == 0) || - (opnd1->GetKind() == kExprConst && static_cast(opnd1.get())->GetValueRaw() == 0), + (opnd0->GetKind() == kExprConst && static_cast(opnd0.get())->GetValue().u64 == 0) || + (opnd1->GetKind() == kExprConst && static_cast(opnd1.get())->GetValue().u64 == 0), "primtype of opnds must be the same"); type->SetPrimType(PTY_i32); } diff --git a/src/mplfe/common/src/feir_type.cpp b/src/mplfe/common/src/feir_type.cpp index e481fca7f8912076ddb971a6c3b2231d0c4962fb..a371cd248fc109c6b93b70c68f08c9421d187f0b 100644 --- a/src/mplfe/common/src/feir_type.cpp +++ b/src/mplfe/common/src/feir_type.cpp @@ -437,4 +437,39 @@ PrimType FEIRTypePointer::GetPrimTypeImpl() const { void FEIRTypePointer::SetPrimTypeImpl(PrimType pt) { CHECK_FATAL(false, "PrimType %d should not run here", pt); } + +// ---------- FEIRTypeNative ---------- +FEIRTypeNative::FEIRTypeNative(MIRType &argMIRtype, TypeDim argDim) + : FEIRTypeDefault(argMIRtype.GetPrimType(), argMIRtype.GetNameStrIdx(), argDim), + mirType(argMIRtype) { + kind = kFEIRTypenNative; + // Right now, FEIRTypeNative is only used for c-language. + srcLang = kSrcLangC; +} + +std::unique_ptr FEIRTypeNative::CloneImpl() const { + std::unique_ptr newType = std::make_unique(mirType, dim); + return newType; +} + +MIRType *FEIRTypeNative::GenerateMIRTypeImpl(bool usePtr, PrimType ptyPtr) const { + // To optimize for array type + return &mirType; +} + +bool FEIRTypeNative::IsEqualToImpl(const FEIRType &argType) const { + if (!FEIRTypeDefault::IsEqualToImpl(argType)) { + return false; + } + const FEIRTypeNative &argTypeNative = static_cast(argType); + return &argTypeNative.mirType == &mirType; +} + +size_t FEIRTypeNative::HashImpl() const { + return mirType.GetHashIndex(); +} + +bool FEIRTypeNative::IsScalarImpl() const { + return mirType.IsScalarType(); +} } // namespace maple diff --git a/src/mplfe/dex_input/src/dex_op.cpp b/src/mplfe/dex_input/src/dex_op.cpp index 93cbe9f76d37b7b0b591d2950df34fa1a865819f..899dda86202027e45b0bdd1dc046d24a0c3aa88d 100644 --- a/src/mplfe/dex_input/src/dex_op.cpp +++ b/src/mplfe/dex_input/src/dex_op.cpp @@ -1040,7 +1040,7 @@ void DexOpAget::ParseImpl(BCClassMethod &method) { void DexOpAget::SetRegTypeInTypeInferImpl() { if (vB.regType != nullptr && vC.regType != nullptr) { - vB.regType->AddElemType(vA.regType); + vB.regType->AddElemType(vA.regTypeItem); } } @@ -1140,7 +1140,7 @@ void DexOpAput::ParseImpl(BCClassMethod &method) { void DexOpAput::SetRegTypeInTypeInferImpl() { if (vA.regType != nullptr && vB.regType != nullptr && vC.regType != nullptr) { - vB.regType->AddElemType(vA.regType); + vB.regType->AddElemType(vA.regTypeItem); } } diff --git a/src/mplfe/test/BUILD.gn b/src/mplfe/test/BUILD.gn index 14957d4f5e8e4c24a190f88e64273cd75e9b056f..e776d86c0674fb07eabf7fc53aebe6ff417f5ebe 100644 --- a/src/mplfe/test/BUILD.gn +++ b/src/mplfe/test/BUILD.gn @@ -24,7 +24,7 @@ cflags += [ include_directories = [ "${MPLFE_ROOT}/common/include", "${MPLFE_ROOT}/jbc_input/include", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include", + "//../ThirdParty/bounds_checking_function/include", "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", @@ -66,7 +66,7 @@ executable("mplfeUT") { ] include_dirs = include_directories deps = [ - "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", + "//../ThirdParty/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_ir:libmplir", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", "${MPLFE_ROOT}:lib_mplfe_jbc_input", diff --git a/src/mplfe/test/fe_type_manager_test.cpp b/src/mplfe/test/fe_type_manager_test.cpp index be4135dca2686c7737449fd725092fbc07bbacba..4817a268531aa8744e0936e473097b36ce9f7ad0 100644 --- a/src/mplfe/test/fe_type_manager_test.cpp +++ b/src/mplfe/test/fe_type_manager_test.cpp @@ -177,4 +177,19 @@ TEST_F(FETypeManagerTest, GetOrCreateTypeFromName) { EXPECT_EQ(GetBufferString(), "<* <[] <* <[] <* <$Ljava_2Flang_2FObject_3B>>>>>>"); RestoreCout(); } + +TEST_F(FETypeManagerTest, GetOrCreateComplexStructType) { + MIRType *elemType = GlobalTables::GetTypeTable().GetInt32(); + MIRType *type = FEManager::GetTypeManager().GetOrCreateComplexStructType(*elemType); + ASSERT_NE(type, nullptr); + EXPECT_EQ(type->IsStructType(), true); + std::string mplName = type->GetCompactMplTypeName(); + EXPECT_EQ(mplName, "Complex|I"); + MIRStructType *structType = static_cast(type); + ASSERT_EQ(structType->GetFields().size(), 2); + EXPECT_EQ(GlobalTables::GetStrTable().GetStringFromStrIdx(structType->GetFields()[0].first), "real"); + EXPECT_EQ(structType->GetFields()[0].second.first == PTY_i32, true); + EXPECT_EQ(GlobalTables::GetStrTable().GetStringFromStrIdx(structType->GetFields()[1].first), "imag"); + EXPECT_EQ(structType->GetFields()[1].second.first == PTY_i32, true); +} } // namespace maple \ No newline at end of file diff --git a/src/mplfe/test/feir_stmt_test.cpp b/src/mplfe/test/feir_stmt_test.cpp index c2dc761f8de5db7611aa18fda278621cf4c039cf..3736e32a98599bf91c5b5bed0f0a2bea30a9a35a 100644 --- a/src/mplfe/test/feir_stmt_test.cpp +++ b/src/mplfe/test/feir_stmt_test.cpp @@ -136,10 +136,10 @@ TEST_F(FEIRStmtTest, FEIRExprTypeCvtMode2) { } TEST_F(FEIRStmtTest, FEIRExprTypeCvtMode3) { - std::unique_ptr typeVar = FEIRTypeHelper::CreateTypeByJavaName("Ljava/lang/Object;", false, true); + std::unique_ptr typeVar = FEIRTypeHelper::CreateTypeByJavaName("Ltest/lang/Object;", false, true); std::unique_ptr varReg = std::make_unique(0, std::move(typeVar)); std::unique_ptr exprDRead = std::make_unique(std::move(varReg)); - std::unique_ptr typeDst = FEIRTypeHelper::CreateTypeByJavaName("Ljava/lang/String;", false, true); + std::unique_ptr typeDst = FEIRTypeHelper::CreateTypeByJavaName("Ltest/lang/String;", false, true); std::unique_ptr expr = std::make_unique(std::move(typeDst), OP_retype, std::move(exprDRead)); std::unique_ptr expr2 = expr->Clone(); @@ -147,7 +147,7 @@ TEST_F(FEIRStmtTest, FEIRExprTypeCvtMode3) { RedirectCout(); baseNode->Dump(); std::string dumpStr = GetBufferString(); - std::string pattern = std::string("retype ref <\\* <\\$Ljava_2Flang_2FString_3B>> \\(dread ref %Reg0_") + + std::string pattern = std::string("retype ref <\\* <\\$Ltest_2Flang_2FString_3B>> \\(dread ref %Reg0_") + MPLFEUTRegx::RefIndex(MPLFEUTRegx::kAnyNumber) + "\\)" + MPLFEUTRegx::Any(); EXPECT_EQ(MPLFEUTRegx::Match(dumpStr, pattern), true); RestoreCout(); diff --git a/src/mplfe/test/feir_type_test.cpp b/src/mplfe/test/feir_type_test.cpp index bd953c1852a26bf28fae74c87fd1bda9b60290ce..267bbcb835ecf668bb164435f77166d7ceb97b25 100644 --- a/src/mplfe/test/feir_type_test.cpp +++ b/src/mplfe/test/feir_type_test.cpp @@ -289,4 +289,36 @@ TEST_F(FEIRTypeDefaultTest, UseFEIRTypeKey) { EXPECT_NE(testSet.find(FEIRTypeKey(type3)), testSet.end()); EXPECT_NE(testSet.find(FEIRTypeKey(type4)), testSet.end()); } + +TEST_F(FEIRTypeDefaultTest, FEIRTypeNative_create) { + RedirectCout(); + MIRType *mirType = GlobalTables::GetTypeTable().GetInt32(); + FEIRTypeNative type(*mirType); + EXPECT_EQ(type.IsRef(), false); + EXPECT_EQ(type.IsArray(), false); + EXPECT_EQ(type.IsPrecise(), true); + EXPECT_EQ(type.IsValid(), true); + type.GenerateMIRType()->Dump(0); + EXPECT_EQ(GetBufferString(), "i32"); + + MIRType *mirType1 = GlobalTables::GetTypeTable().GetRef(); + FEIRTypeNative type1(*mirType1); + EXPECT_EQ(type1.IsRef(), true); + EXPECT_EQ(type1.IsArray(), false); + EXPECT_EQ(type1.IsPrecise(), true); + EXPECT_EQ(type1.IsValid(), true); + type1.GenerateMIRType()->Dump(0); + EXPECT_EQ(GetBufferString(), "ref"); + RestoreCout(); +} + +TEST_F(FEIRTypeDefaultTest, FEIRTypeNative_equal) { + UniqueFEIRType type1 = std::make_unique(*GlobalTables::GetTypeTable().GetInt32()); + UniqueFEIRType type2 = std::make_unique(*GlobalTables::GetTypeTable().GetInt64()); + UniqueFEIRType type3 = std::make_unique(*GlobalTables::GetTypeTable().GetRef()); + UniqueFEIRType type4 = type1->Clone(); + EXPECT_EQ(type1->IsEqualTo(type2), false); + EXPECT_EQ(type1->IsEqualTo(type3), false); + EXPECT_EQ(type1->IsEqualTo(type4), true); +} } // namespace maple \ No newline at end of file diff --git a/src/mplfe/test/feir_var_test.cpp b/src/mplfe/test/feir_var_test.cpp index da5f76f55146668d12511875f8d7b703232bcd7f..6927b595ee9b67abf8f5f4291ee12623be39f6b6 100644 --- a/src/mplfe/test/feir_var_test.cpp +++ b/src/mplfe/test/feir_var_test.cpp @@ -31,7 +31,7 @@ class FEIRVarTest : public FEIRTestBase { }; TEST_F(FEIRVarTest, FEIRVarReg) { - std::unique_ptr type = FEIRTypeHelper::CreateTypeByJavaName("Ljava/lang/Object;", false, true); + std::unique_ptr type = FEIRTypeHelper::CreateTypeByJavaName("Ltest/lang/Object;", false, true); FEIRVarReg varReg(1, std::move(type)); varReg.SetGlobal(false); MIRSymbol *symbol = varReg.GenerateMIRSymbol(mirBuilder); @@ -48,17 +48,17 @@ TEST_F(FEIRVarTest, FEIRVarReg) { } TEST_F(FEIRVarTest, FEIRVarName) { - std::unique_ptr type = FEIRTypeHelper::CreateTypeByJavaName("Ljava/lang/Object;", false, true); - GStrIdx nameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("Ljava_2Flang_2FObject_3B_7Cklass"); + std::unique_ptr type = FEIRTypeHelper::CreateTypeByJavaName("Ltest/lang/Object;", false, true); + GStrIdx nameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("Ltest_2Flang_2FObject_3B_7Cklass"); FEIRVarName varName(nameIdx, std::move(type)); varName.SetGlobal(true); MIRSymbol *symbol = varName.GenerateMIRSymbol(mirBuilder); RedirectCout(); std::string symbolName = symbol->GetName(); - EXPECT_EQ(symbolName, "Ljava_2Flang_2FObject_3B_7Cklass"); + EXPECT_EQ(symbolName, "Ltest_2Flang_2FObject_3B_7Cklass"); symbol->Dump(false, 0); std::string symbolDump = GetBufferString(); - std::string strPattern2 = std::string("var \\$") + "Ljava_2Flang_2FObject_3B_7Cklass" + MPLFEUTRegx::Any(); + std::string strPattern2 = std::string("var \\$") + "Ltest_2Flang_2FObject_3B_7Cklass" + MPLFEUTRegx::Any(); EXPECT_EQ(MPLFEUTRegx::Match(symbolDump, strPattern2), true); RestoreCout(); } @@ -73,10 +73,10 @@ TEST_F(FEIRVarTest, FEIRVarTransDirect) { EXPECT_EQ(GetBufferString(), "<$Ljava_2Flang_2FObject_3B>"); ClearBufferString(); - UniqueFEIRType type2 = FEIRTypeHelper::CreateTypeByJavaName("Ljava/lang/Object;", false, true); + UniqueFEIRType type2 = FEIRTypeHelper::CreateTypeByJavaName("Ltest/lang/Object;", false, true); UniqueFEIRType type2T = trans.GetType(type2); type2T->GenerateMIRType()->Dump(0); - EXPECT_EQ(GetBufferString(), "<* <$Ljava_2Flang_2FObject_3B>>"); + EXPECT_EQ(GetBufferString(), "<* <$Ltest_2Flang_2FObject_3B>>"); ClearBufferString(); UniqueFEIRType type3 = FEIRTypeHelper::CreateTypeByJavaName("I", false, false); diff --git a/src/mrt/BUILD.gn b/src/mrt/BUILD.gn index 0fc08ec7d835ac699d7e23016113467bd4fc8273..5c8f98bd22df88029cb91e9f6664456391551aad 100644 --- a/src/mrt/BUILD.gn +++ b/src/mrt/BUILD.gn @@ -192,7 +192,7 @@ group("maple-rt") { deps = [ "${MAPLE_MRT_ROOT}/compiler-rt:libmplcompiler-rt", "${MAPLE_MRT_ROOT}/dexinterface:libdexinterface", - "${MAPLE_ROOT}/third_party/bounds_checking_function:libhuawei_secure_c", + "//../ThirdParty/bounds_checking_function:libhuawei_secure_c", "${MAPLE_MRT_ROOT}/interpreter:libzterp", "${MAPLE_MRT_ROOT}/libcore-static-binding-jni:libcore-static-binding-jni", "${MAPLE_MRT_ROOT}/maplert:libmaplert", diff --git a/src/mrt/compiler-rt/BUILD.gn b/src/mrt/compiler-rt/BUILD.gn index a16f1c1ed7b4ebb03b6a0771ed98b80f773d03b3..5090c45afa4a9df46eec96a3ca578a67968a3593 100644 --- a/src/mrt/compiler-rt/BUILD.gn +++ b/src/mrt/compiler-rt/BUILD.gn @@ -82,7 +82,7 @@ include_common = [ "include", "public-headers", "${AOSP_ROOT}/libnativehelper/include_jni", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include/", + "//../ThirdParty/bounds_checking_function/include/", "${MAPLE_MRT_ROOT}/maplert/include", "${MAPLE_MRT_ROOT}/maplert/public-headers/", "${MAPLE_MRT_ROOT}/libmrtbase/include/", diff --git a/src/mrt/libcore-static-binding-jni/BUILD.gn b/src/mrt/libcore-static-binding-jni/BUILD.gn index d5e19077306aeb3f3a4539a3380f212cbf2af84f..61596d966d1d18d36cebb9ae2a7920a484ea7017 100644 --- a/src/mrt/libcore-static-binding-jni/BUILD.gn +++ b/src/mrt/libcore-static-binding-jni/BUILD.gn @@ -38,7 +38,7 @@ include_common = [ "${MAPLE_MRT_ROOT}/libmrtbase/include", "${MAPLE_MRT_ROOT}/libmrtbase/include/linux", "${MAPLE_MRT_ROOT}/maplert/public-headers", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include/", + "//../ThirdParty/bounds_checking_function/include/", "${MAPLE_MRT_ROOT}/dexinterface", "${MAPLE_MRT_ROOT}/interpreter/zterp", "${MAPLE_MRT_ROOT}", diff --git a/src/mrt/maplert/BUILD.gn b/src/mrt/maplert/BUILD.gn index 6797fc11aebb3a67ac03a37d3cecf6b8ef5e465a..9794f72928b79f78c91bb018ef28cb94c9b3c09c 100644 --- a/src/mrt/maplert/BUILD.gn +++ b/src/mrt/maplert/BUILD.gn @@ -56,7 +56,7 @@ sources_common = [ include_common = [ "${MAPLE_MRT_ROOT}/maplert/include", "${AOSP_ROOT}/libnativehelper/include_jni", - "${MAPLE_ROOT}/third_party/bounds_checking_function/include/", + "//../ThirdParty/bounds_checking_function/include/", "${MAPLE_MRT_ROOT}/compiler-rt/include", "${MAPLE_MRT_ROOT}/compiler-rt/public-headers", "${MAPLE_MRT_ROOT}/maplert/public-headers",