diff --git a/src/bin/maple b/src/bin/maple index c3543af63c18d10936afba2934f94c3acdc21525..76b51d98cabe92190c9f7a1e12bda186874d9042 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/maple_be/include/cg/cgbb.h b/src/maple_be/include/cg/cgbb.h index f2d92c0696bdee1d16cb6c0e9a1fdbaa2d0f14eb..136774320a598c84aeec78acea4ae3d134a763dc 100644 --- a/src/maple_be/include/cg/cgbb.h +++ b/src/maple_be/include/cg/cgbb.h @@ -556,6 +556,9 @@ class BB { void SetLastLoc(const Insn *arg) { lastLoc = arg; } + DataInfo *GetLiveIn() { + return liveIn; + } const DataInfo *GetLiveIn() const { return liveIn; } @@ -577,6 +580,9 @@ class BB { void LiveInClearDataInfo() { liveIn->ClearDataInfo(); } + DataInfo *GetLiveOut() { + return liveOut; + } const DataInfo *GetLiveOut() const { return liveOut; } diff --git a/src/maple_be/include/cg/datainfo.h b/src/maple_be/include/cg/datainfo.h index 545d0a4a1cd1c1c210642ebc306fb09681b7be5e..b8698e6c67420c8ab6a05a25e66512e67ecc5be8 100644 --- a/src/maple_be/include/cg/datainfo.h +++ b/src/maple_be/include/cg/datainfo.h @@ -14,12 +14,17 @@ */ #ifndef MAPLEBE_INCLUDE_CG_DATAINFO_H #define MAPLEBE_INCLUDE_CG_DATAINFO_H -#include namespace maplebe { class DataInfo { public: - explicit DataInfo(uint32 bitNum) : info(bitNum / kWordSize + 1, 0ULL) {} + explicit DataInfo(uint32 bitNum, MemPool &mp) + : allocator(&mp), + info(allocator.Adapter()) { + for (uint64 i = 0;i < (bitNum / kWordSize + 1); ++i) { + info.push_back(0); + } + } ~DataInfo() = default; @@ -59,7 +64,7 @@ class DataInfo { return info.size() * kWordSize; } - const std::vector &GetInfo() const { + const MapleVector &GetInfo() const { return info; } @@ -140,8 +145,8 @@ class DataInfo { return bitNO / kWordSize; } - std::set GetBitsOfInfo() const { - std::set wordRes; + MapleSet GetBitsOfInfo() { + MapleSet wordRes(allocator.Adapter()); wordRes.clear(); for (size_t i = 0; i != info.size(); ++i) { uint32 result = 0; @@ -178,13 +183,13 @@ class DataInfo { void ClearDataInfo() { info.clear(); - info.shrink_to_fit(); } private: /* long type has 8 bytes, 64 bits */ static constexpr int32 kWordSize = 64; - std::vector info; + MapleAllocator allocator; + MapleVector info; }; } /* namespace maplebe */ #endif /* MAPLEBE_INCLUDE_CG_INSN_H */ diff --git a/src/maple_be/include/cg/live.h b/src/maple_be/include/cg/live.h index 8016d4983f46577d235f008ace0c24bd9071fbc1..20c2b202ccf2acf75955da160dde29d5df0345b2 100644 --- a/src/maple_be/include/cg/live.h +++ b/src/maple_be/include/cg/live.h @@ -42,19 +42,19 @@ class LiveAnalysis : public AnalysisResult { void EnlargeSpaceForLiveAnalysis(BB &currBB); DataInfo *NewLiveIn(uint32 maxRegCount) { - return memPool->New(maxRegCount); + return memPool->New(maxRegCount, *memPool); } DataInfo *NewLiveOut(uint32 maxRegCount) { - return memPool->New(maxRegCount); + return memPool->New(maxRegCount, *memPool); } DataInfo *NewDef(uint32 maxRegCount) { - return memPool->New(maxRegCount); + return memPool->New(maxRegCount, *memPool); } DataInfo *NewUse(uint32 maxRegCount) { - return memPool->New(maxRegCount); + return memPool->New(maxRegCount, *memPool); } virtual void GetBBDefUse(BB &bb) = 0; diff --git a/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index f5749c81ced7b9849f9921e2b696dd89b7bbd3c4..57619fac5c0e754ce9d80964418cc09ff404b124 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -4572,10 +4572,9 @@ void AArch64CGFunc::SelectParmList(StmtNode &naryNode, AArch64ListOperand &srcOp srcOpnds.PushOpnd(parmRegOpnd); } else { /* store to the memory segment for stack-passsed arguments. */ Operand &actMemOpnd = CreateMemOpnd(RSP, ploc.memOffset, GetPrimTypeBitSize(primType)); - uint32 dataSize = GetPrimTypeBitSize(primType); - dataSize = dataSize <= k32BitSize ? k32BitSize : dataSize; GetCurBB()->AppendInsn( - GetCG()->BuildInstruction(PickStInsn(dataSize, primType), *expRegOpnd, actMemOpnd)); + GetCG()->BuildInstruction(PickStInsn(GetPrimTypeBitSize(primType), primType), *expRegOpnd, + actMemOpnd)); } ASSERT(ploc.reg1 == 0, "SelectCall NYI"); } diff --git a/src/maple_be/src/cg/live.cpp b/src/maple_be/src/cg/live.cpp index 346403be1674a73faf232a925b41ed1698b47f6b..b17b3acbf43d438a2dac0483fd66435a58c73fa7 100644 --- a/src/maple_be/src/cg/live.cpp +++ b/src/maple_be/src/cg/live.cpp @@ -92,7 +92,7 @@ bool LiveAnalysis::GenerateLiveIn(BB &bb) { if (!bb.GetEhSuccs().empty()) { /* If bb has eh successors, check if multi-gen exists. */ - DataInfo allInOfEhSuccs(cgFunc->GetMaxVReg()); + DataInfo allInOfEhSuccs(cgFunc->GetMaxVReg(), *memPool); for (auto ehSucc : bb.GetEhSuccs()) { allInOfEhSuccs.OrBits(*ehSucc->GetLiveIn()); } @@ -129,17 +129,11 @@ void LiveAnalysis::BuildInOutforFunc() { /* only reset to liveout/in_regno in schedule and ra phase. */ void LiveAnalysis::ResetLiveSet() { - std::set setResult; FOR_ALL_BB(bb, cgFunc) { - setResult.clear(); - setResult = bb->GetLiveIn()->GetBitsOfInfo(); - for (const auto &rNO : setResult) { + for (const auto &rNO : bb->GetLiveIn()->GetBitsOfInfo()) { bb->InsertLiveInRegNO(rNO); } - setResult.clear(); - - setResult = bb->GetLiveOut()->GetBitsOfInfo(); - for (const auto &rNO : setResult) { + for (const auto &rNO : bb->GetLiveOut()->GetBitsOfInfo()) { bb->InsertLiveOutRegNO(rNO); } } diff --git a/src/maple_me/include/dse.h b/src/maple_me/include/dse.h index 33b31557a3d57c7df75cbcc3fe1cd31e4c734650..959f77f78223bb92b03c85477fa7554a8a18a478 100644 --- a/src/maple_me/include/dse.h +++ b/src/maple_me/include/dse.h @@ -103,6 +103,7 @@ class DSE { workList.push_front(symbol); } + bool ExprHasSideEffect(const BaseNode &expr) const; bool ExprNonDeletable(const BaseNode &expr) const; bool HasNonDeletableExpr(const StmtNode &stmt) const; bool StmtMustRequired(const StmtNode &stmt, const BB &bb) const; diff --git a/src/maple_me/include/hdse.h b/src/maple_me/include/hdse.h index cebd3e7b1e5cb5f977ed3dc2b8b02f5f7b3ee20e..e0eda7c81bd8d4d219297645aeeb1101ca7310d0 100644 --- a/src/maple_me/include/hdse.h +++ b/src/maple_me/include/hdse.h @@ -52,6 +52,7 @@ class HDSE { void MarkPhiRequired(VarOrRegPhiNode &mePhiNode); void MarkMuListRequired(MapleMap&); void MarkChiNodeRequired(ChiMeNode &chiNode); + bool ExprHasSideEffect(const MeExpr &meExpr) const; bool ExprNonDeletable(const MeExpr &expr) const; bool StmtMustRequired(const MeStmt &stmt, const BB &bb) const; void MarkStmtRequired(MeStmt &stmt); diff --git a/src/maple_me/src/dse.cpp b/src/maple_me/src/dse.cpp index 67265b7432992599355b67e486c7530a5c0f458d..3c0e82eb5be3dc8574cdc1c8a9343428e074abb5 100644 --- a/src/maple_me/src/dse.cpp +++ b/src/maple_me/src/dse.cpp @@ -34,8 +34,26 @@ namespace maple { using namespace utils; +bool DSE::ExprHasSideEffect(const BaseNode &expr) const { + Opcode op = expr.GetOpCode(); + if (kOpcodeInfo.HasSideEffect(op)) { + return true; + } + // may throw exception + if (op == OP_gcmallocjarray || op == OP_gcpermallocjarray) { + return true; + } + // create a instance of interface + if (op == OP_gcmalloc || op == OP_gcpermalloc) { + auto &gcMallocNode = static_cast(expr); + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(gcMallocNode.GetTyIdx()); + return type->GetKind() == kTypeInterface; + } + return false; +} + bool DSE::ExprNonDeletable(const BaseNode &expr) const { - if (kOpcodeInfo.HasSideEffect(expr.GetOpCode())) { + if (ExprHasSideEffect(expr)) { return true; } switch (expr.GetOpCode()) { @@ -53,10 +71,6 @@ bool DSE::ExprNonDeletable(const BaseNode &expr) const { auto ®readNode = static_cast(expr); return (regreadNode.GetRegIdx() == -kSregThrownval); } - case OP_gcmallocjarray: - case OP_gcpermallocjarray: - // may throw exception - return true; case OP_intrinsicop: { auto &node = static_cast(expr); const IntrinDesc &intrinDesc = node.GetIntrinDesc(); diff --git a/src/maple_me/src/hdse.cpp b/src/maple_me/src/hdse.cpp index 806aaaa6f67df831d8d82eb2ad2117f5205dd631..45e4ac20e884d786bf0203708ca83571f1a4e7c8 100644 --- a/src/maple_me/src/hdse.cpp +++ b/src/maple_me/src/hdse.cpp @@ -177,8 +177,26 @@ void HDSE::PropagateUseLive(MeExpr &meExpr) { } } +bool HDSE::ExprHasSideEffect(const MeExpr &meExpr) const { + Opcode op = meExpr.GetOp(); + if (kOpcodeInfo.HasSideEffect(op)) { + return true; + } + // may throw exception + if (op == OP_gcmallocjarray || op == OP_gcpermallocjarray) { + return true; + } + // create a instance of interface + if (op == OP_gcmalloc || op == OP_gcpermalloc) { + auto &gcMallocMeExpr = static_cast(meExpr); + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(gcMallocMeExpr.GetTyIdx()); + return type->GetKind() == kTypeInterface; + } + return false; +} + bool HDSE::ExprNonDeletable(const MeExpr &meExpr) const { - if (kOpcodeInfo.HasSideEffect(meExpr.GetOp())) { + if (ExprHasSideEffect(meExpr)) { return true; } switch (meExpr.GetMeOp()) { @@ -194,12 +212,6 @@ bool HDSE::ExprNonDeletable(const MeExpr &meExpr) const { auto &opIvar = static_cast(meExpr); return opIvar.IsVolatile() || ExprNonDeletable(*opIvar.GetBase()); } - case kMeOpOp: { - if (meExpr.GetOp() == OP_gcmallocjarray) { - return true; - } - break; - } case kMeOpNary: { auto &opNary = static_cast(meExpr); if (meExpr.GetOp() == OP_intrinsicop) { diff --git a/src/maple_util/include/version.h b/src/maple_util/include/version.h index 24c043563e12c3e7c7fe3c2886f37242c9e3ff0c..0889c710138b323048f218ba9a8f9b553321e3d6 100644 --- a/src/maple_util/include/version.h +++ b/src/maple_util/include/version.h @@ -16,7 +16,7 @@ #define MAPLE_UTIL_INCLUDE_VERSION_H namespace Version { -static constexpr const int kMajorMplVersion = 3; +static constexpr const int kMajorMplVersion = 4; static constexpr const int kMinorCompilerVersion = 0; static constexpr const int kMinorRuntimeVersion = 0; } diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index 54acb553163d073eb243ddbb87c6ffeef43f6497..1ff672192c61924050fb7d253bb233cf8e513ddf 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -265,11 +265,7 @@ void NativeStubFuncGeneration::ProcessFunc(MIRFunction *func) { void NativeStubFuncGeneration::GenerateRegFuncTabEntryType() { MIRArrayType &arrayType = -#ifdef USE_ARM32_MACRO - *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt32(), 0); -#else *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetVoidPtr(), 0); -#endif regFuncTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); std::string regFuncTab = NameMangler::kRegJNIFuncTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); regFuncSymbol = builder->CreateSymbol(regFuncTabConst->GetType().GetTypeIndex(), regFuncTab, kStVar, @@ -286,11 +282,7 @@ void NativeStubFuncGeneration::GenerateRegFuncTabEntry() { uint64 locIdx = regFuncTabConst->GetConstVec().size(); auto *newConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((locIdx << locIdxShift) | locIdxMask), -#ifdef USE_ARM32_MACRO - *GlobalTables::GetTypeTable().GetUInt32()); -#else *GlobalTables::GetTypeTable().GetVoidPtr()); -#endif regFuncTabConst->PushBack(newConst); } diff --git a/src/mplfe/BUILD.gn b/src/mplfe/BUILD.gn index 7077f8d9e8cbc8e0239f8aae57a7317b7a488f62..30e61b18e10f5dad09af1fc5abe8fffa4a05fd3f 100644 --- a/src/mplfe/BUILD.gn +++ b/src/mplfe/BUILD.gn @@ -118,6 +118,7 @@ static_library("lib_mplfe_jbc_input") { "${MAPLEALL_ROOT}/mplfe/jbc_input/src/jbc_class_const_pool.cpp", "${MAPLEALL_ROOT}/mplfe/jbc_input/src/jbc_compiler_component.cpp", "${MAPLEALL_ROOT}/mplfe/jbc_input/src/jbc_function.cpp", + "${MAPLEALL_ROOT}/mplfe/jbc_input/src/jbc_function_context.cpp", "${MAPLEALL_ROOT}/mplfe/jbc_input/src/jbc_input.cpp", "${MAPLEALL_ROOT}/mplfe/jbc_input/src/jbc_opcode.cpp", "${MAPLEALL_ROOT}/mplfe/jbc_input/src/jbc_opcode_helper.cpp", diff --git a/src/mplfe/common/include/fe_config_parallel.h b/src/mplfe/common/include/fe_config_parallel.h index ff504b6187d04dc4f73ed2f07fcefe33f7587b83..41f08e68e2fa4c86f60cf5749d98d77e7d3a1ed2 100644 --- a/src/mplfe/common/include/fe_config_parallel.h +++ b/src/mplfe/common/include/fe_config_parallel.h @@ -45,7 +45,7 @@ class FEConfigParallel { return enableParallel && (nThread > 1); } - void RegisterRunThreadID(std::thread::id tid) { + void RegisterRunThreadID(const std::thread::id &tid) { mtx.lock(); CHECK_FATAL(runThreadIDs.insert(tid).second == true, "failed to register thread id"); mtx.unlock(); diff --git a/src/mplfe/common/include/fe_options.h b/src/mplfe/common/include/fe_options.h index 62e9e72783c8766716dab6b0018a5c617d10fb95..bcc0c557feca65742584d3d7784c870c1422b2c1 100644 --- a/src/mplfe/common/include/fe_options.h +++ b/src/mplfe/common/include/fe_options.h @@ -229,6 +229,14 @@ class FEOptions { return isDumpJBCErrorOnly; } + void SetIsEmitJBCLocalVarInfo(bool flag) { + isEmitJBCLocalVarInfo = flag; + } + + bool IsEmitJBCLocalVarInfo() const { + return isEmitJBCLocalVarInfo; + } + // parallel void SetNThreads(uint32 n) { nthreads = n; @@ -294,11 +302,12 @@ class FEOptions { ModeJavaStaticFieldName modeJavaStaticField = ModeJavaStaticFieldName::kNoType; bool isJBCUseImpreciseType = false; bool isJBCInfoUsePathName = false; - bool isDumpJBCStmt; - bool isDumpJBCBB; - bool isDumpJBCAll; - bool isDumpJBCErrorOnly; + bool isDumpJBCStmt = false; + bool isDumpJBCBB = false; + bool isDumpJBCAll = false; + bool isDumpJBCErrorOnly = false; std::set dumpJBCFuncNames; + bool isEmitJBCLocalVarInfo = false; // general stmt/bb/cfg debug options bool isDumpGenCFGGraph = false; diff --git a/src/mplfe/common/include/fe_struct_elem_info.h b/src/mplfe/common/include/fe_struct_elem_info.h index 0a5d1fcae610473362e465d47c9f946c490050fd..6c33000a0fd5ca180cca1cbf767cb6e402ccd514 100644 --- a/src/mplfe/common/include/fe_struct_elem_info.h +++ b/src/mplfe/common/include/fe_struct_elem_info.h @@ -119,7 +119,7 @@ class FEStructFieldInfo : public FEStructElemInfo { LLT_PRIVATE: void LoadFieldType(); void LoadFieldTypeJava(); - void PrepareStaticField(MIRStructType &structType); + void PrepareStaticField(const MIRStructType &structType); void PrepareNonStaticField(MIRStructType &structType, MIRBuilder &mirBuilder); bool SearchStructFieldJava(MIRStructType &structType, MIRBuilder &mirBuilder, bool argIsStatic, bool allowPrivate = true); diff --git a/src/mplfe/common/include/fe_type_manager.h b/src/mplfe/common/include/fe_type_manager.h index 49dc0dc856bf50551de1df364d1f879a80d999aa..393f6ee7b43990e68e6221d25295401383b9d460 100644 --- a/src/mplfe/common/include/fe_type_manager.h +++ b/src/mplfe/common/include/fe_type_manager.h @@ -134,8 +134,8 @@ class FETypeManager { // ---------- methods for StructElemInfo ---------- // structIdx = 0: global field/function without owner structure - FEStructElemInfo *RegisterStructFieldInfo(const GStrIdx &fullNameIdx, MIRSrcLang srcLang, bool isStatic); - FEStructElemInfo *RegisterStructMethodInfo(const GStrIdx &fullNameIdx, MIRSrcLang srcLang, bool isStatic); + FEStructElemInfo *RegisterStructFieldInfo(const GStrIdx &fullNameIdx, MIRSrcLang argSrcLang, bool isStatic); + FEStructElemInfo *RegisterStructMethodInfo(const GStrIdx &fullNameIdx, MIRSrcLang argSrcLang, bool isStatic); FEStructElemInfo *GetStructElemInfo(const GStrIdx &fullNameIdx) const; // ---------- methods for MIRFunction ---------- @@ -166,8 +166,8 @@ class FETypeManager { void InitMCCFunctions(); MIRFunction *GetMCCFunction(const std::string &funcName) const; MIRFunction *GetMCCFunction(const GStrIdx &funcNameIdx) const; - MIRFunction *GetMCCGetOrInsertLiteral() const { - return funcMCCGetOrInsertLiteral; + PUIdx GetPuIdxForMCCGetOrInsertLiteral() const { + return funcMCCGetOrInsertLiteral->GetPuidx(); } // anti-proguard diff --git a/src/mplfe/common/include/feir_stmt.h b/src/mplfe/common/include/feir_stmt.h index 7bf0f6bb05cffd4898ab2995e2364cff68d16860..440d6c91b5051a63a10e8aa693c8637e72ea3356 100644 --- a/src/mplfe/common/include/feir_stmt.h +++ b/src/mplfe/common/include/feir_stmt.h @@ -694,8 +694,8 @@ class FEIRStmtJavaMultiANewArray : public FEIRStmtAssign { public: FEIRStmtJavaMultiANewArray(std::unique_ptr argVar, std::unique_ptr argType); ~FEIRStmtJavaMultiANewArray() = default; - void AddVarSize(std::unique_ptr varSize); - void AddVarSizeRev(std::unique_ptr varSize); + void AddVarSize(std::unique_ptr argVarSize); + void AddVarSizeRev(std::unique_ptr argVarSize); protected: std::list GenMIRStmtsImpl(MIRBuilder &mirBuilder) const override; diff --git a/src/mplfe/common/include/feir_type.h b/src/mplfe/common/include/feir_type.h index 612e960ec0a689f16c6951381ae2e58203fa0085..ec6235304e817d0d2ae857061ba141fde5398b83 100644 --- a/src/mplfe/common/include/feir_type.h +++ b/src/mplfe/common/include/feir_type.h @@ -36,7 +36,11 @@ class FEIRType { virtual ~FEIRType() = default; static std::unique_ptr NewType(FEIRTypeKind argKind = kFEIRTypeDefault); static std::map> InitLangConfig(); - MIRType *GenerateMIRTypeAuto(MIRSrcLang srcLang) const; + MIRType *GenerateMIRTypeAuto(MIRSrcLang argSrcLang) const; + MIRType *GenerateMIRTypeAuto() const { + return GenerateMIRTypeAuto(srcLang); + } + bool IsSameKind(const FEIRType &type) const { return kind == type.kind; } @@ -69,7 +73,7 @@ class FEIRType { return CloneImpl(); } - MIRType *GenerateMIRType(MIRSrcLang srcLang, bool usePtr) const { + MIRType *GenerateMIRType(MIRSrcLang argSrcLang, bool usePtr) const { return GenerateMIRType(usePtr); } @@ -146,6 +150,7 @@ class FEIRType { FEIRTypeKind kind : 7; bool isZero : 1; + MIRSrcLang srcLang : 8; }; // class FEIRType using UniqueFEIRType = std::unique_ptr; diff --git a/src/mplfe/common/include/mplfe_options.h b/src/mplfe/common/include/mplfe_options.h index bcac6e2bf10fd198161d90c7a107b363fd1a63e9..b74e873935e2f448e802b091d780cba21654a37a 100644 --- a/src/mplfe/common/include/mplfe_options.h +++ b/src/mplfe/common/include/mplfe_options.h @@ -75,6 +75,7 @@ class MPLFEOptions { bool ProcessDumpJBCAll(const mapleOption::Option &opt); bool ProcessDumpJBCErrorOnly(const mapleOption::Option &opt); bool ProcessDumpJBCFuncName(const mapleOption::Option &opt); + bool ProcessEmitJBCLocalVarInfo(const mapleOption::Option &opt); // general stmt/bb/cfg debug options bool ProcessDumpGeneralCFGGraph(const mapleOption::Option &opt); diff --git a/src/mplfe/common/src/fe_java_string_manager.cpp b/src/mplfe/common/src/fe_java_string_manager.cpp index 347fef0c68673b84e44c9f12e0574b4dea499641..14e83c8e5cb06d368bd16643d0726fd6636a91f5 100644 --- a/src/mplfe/common/src/fe_java_string_manager.cpp +++ b/src/mplfe/common/src/fe_java_string_manager.cpp @@ -34,7 +34,7 @@ void FEJavaStringManager::LoadProfilingData(const std::string &profileFileName) std::string literalName; while (std::getline(inFile, literalName)) { if (!literalName.empty()) { - preloadSet.insert(literalName); + (void)preloadSet.insert(literalName); } } inFile.close(); @@ -61,7 +61,7 @@ MIRSymbol *FEJavaStringManager::GetLiteralPtrVar(const std::u16string &strU16) c MIRSymbol *FEJavaStringManager::CreateLiteralVar(MIRBuilder &mirBuilder, const std::string &str, bool isFieldValue) { std::u16string strU16; - NameMangler::UTF8ToUTF16(strU16, str); + (void)NameMangler::UTF8ToUTF16(strU16, str); return CreateLiteralVar(mirBuilder, strU16, isFieldValue); } @@ -88,10 +88,10 @@ MIRSymbol *FEJavaStringManager::CreateLiteralVar(MIRBuilder &mirBuilder, const s bool isHotLiteral = false; if (preloadSet.find(literalGlobalName) != preloadSet.end()) { isHotLiteral = true; - literalSet.insert(literalVar); + (void)literalSet.insert(literalVar); } if (isFieldValue) { - fieldValueSet.insert(literalVar); + (void)fieldValueSet.insert(literalVar); } if (isFieldValue || isHotLiteral) { std::string literalGlobalPtrName = NameMangler::kPtrPrefixStr + literalGlobalName; @@ -103,13 +103,13 @@ MIRSymbol *FEJavaStringManager::CreateLiteralVar(MIRBuilder &mirBuilder, const s literalVarPtr->SetKonst(cst); literalMap[literalVar] = literalVarPtr; } - GlobalTables::GetConstPool().GetConstU16StringPool().insert(std::make_pair(strU16, literalVar)); + (void)GlobalTables::GetConstPool().GetConstU16StringPool().insert(std::make_pair(strU16, literalVar)); return literalVar; } MIRSymbol *FEJavaStringManager::GetLiteralVar(const std::string &str) const { std::u16string strU16; - NameMangler::UTF8ToUTF16(strU16, str); + (void)NameMangler::UTF8ToUTF16(strU16, str); return GetLiteralVar(strU16); } diff --git a/src/mplfe/common/src/fe_options.cpp b/src/mplfe/common/src/fe_options.cpp index a73eba9b28847106287803c75b49bac9ad5f54a6..5e2352d4be041acef28085bf7386f348223785af 100644 --- a/src/mplfe/common/src/fe_options.cpp +++ b/src/mplfe/common/src/fe_options.cpp @@ -23,10 +23,6 @@ FEOptions::FEOptions() outputName(""), dumpLevel(kDumpLevelDisable), isDumpTime(false), - isDumpJBCStmt(false), - isDumpJBCBB(false), - isDumpJBCAll(false), - isDumpJBCErrorOnly(false), nthreads(0), dumpThreadTime(false) {} diff --git a/src/mplfe/common/src/fe_struct_elem_info.cpp b/src/mplfe/common/src/fe_struct_elem_info.cpp index 77e271510414a50420eb81c7859c4d489a552b7b..f1b6d3f8d5c13bbf4964cda8734042221f5174d0 100644 --- a/src/mplfe/common/src/fe_struct_elem_info.cpp +++ b/src/mplfe/common/src/fe_struct_elem_info.cpp @@ -114,7 +114,7 @@ void FEStructFieldInfo::LoadFieldTypeJava() { static_cast(fieldType.get())->LoadFromJavaTypeName(GetSignatureName(), true); } -void FEStructFieldInfo::PrepareStaticField(MIRStructType &structType) { +void FEStructFieldInfo::PrepareStaticField(const MIRStructType &structType) { std::string ownerStructName = structType.GetName(); const std::string &fieldName = GetElemName(); std::string fullName = ownerStructName + NameMangler::kNameSplitterStr + fieldName; @@ -126,10 +126,10 @@ void FEStructFieldInfo::PrepareStaticField(MIRStructType &structType) { void FEStructFieldInfo::PrepareNonStaticField(MIRStructType &structType, MIRBuilder &mirBuilder) { FEIRTypeDefault feType(PTY_unknown); feType.LoadFromJavaTypeName(GetSignatureName(), true); - MIRType *fieldType = feType.GenerateMIRTypeAuto(srcLang); + MIRType *fieldMIRType = feType.GenerateMIRTypeAuto(srcLang); uint32 idx = 0; uint32 idx1 = 0; - mirBuilder.TraverseToNamedFieldWithType(structType, elemNameIdx, fieldType->GetTypeIndex(), idx1, idx); + mirBuilder.TraverseToNamedFieldWithType(structType, elemNameIdx, fieldMIRType->GetTypeIndex(), idx1, idx); fieldID = idx; isPrepared = true; isStatic = false; @@ -204,8 +204,8 @@ bool FEStructFieldInfo::SearchStructFieldJava(const TyIdx &tyIdx, MIRBuilder &mi } bool FEStructFieldInfo::CompareFieldType(const FieldPair &fieldPair) const { - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldPair.second.first); - std::string typeName = fieldType->GetCompactMplTypeName(); + MIRType *fieldMIRType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldPair.second.first); + std::string typeName = fieldMIRType->GetCompactMplTypeName(); if (GetSignatureName().compare(typeName) == 0) { return true; } else { diff --git a/src/mplfe/common/src/fe_type_manager.cpp b/src/mplfe/common/src/fe_type_manager.cpp index a0dfaae74a2a54b30b50981ee31a94c8c1428a8b..c92489daefe2edca4f50f8908347a3e63e8689c1 100644 --- a/src/mplfe/common/src/fe_type_manager.cpp +++ b/src/mplfe/common/src/fe_type_manager.cpp @@ -43,7 +43,8 @@ FETypeManager::FETypeManager(MIRModule &moduleIn) mp(memPoolCtrler.NewMemPool("mempool for FETypeManager")), allocator(mp), builder(&module), - srcLang(kSrcLangJava) { + srcLang(kSrcLangJava), + funcMCCGetOrInsertLiteral(nullptr) { static_cast(kFEIRTypeJavaObject.get())->LoadFromJavaTypeName("Ljava/lang/Object;", false); static_cast(kFEIRTypeJavaClass.get())->LoadFromJavaTypeName("Ljava/lang/Class;", false); static_cast(kFEIRTypeJavaString.get())->LoadFromJavaTypeName("Ljava/lang/String;", false); @@ -303,13 +304,13 @@ void FETypeManager::AddClassToModule(const MIRStructType &structType) { module.AddClass(structType.GetTypeIndex()); } -FEStructElemInfo *FETypeManager::RegisterStructFieldInfo(const GStrIdx &fullNameIdx, MIRSrcLang srcLang, +FEStructElemInfo *FETypeManager::RegisterStructFieldInfo(const GStrIdx &fullNameIdx, MIRSrcLang argSrcLang, bool isStatic) { FEStructElemInfo *ptrInfo = GetStructElemInfo(fullNameIdx); if (ptrInfo != nullptr) { return ptrInfo; } - UniqueFEStructElemInfo info = std::make_unique(fullNameIdx, srcLang, isStatic); + UniqueFEStructElemInfo info = std::make_unique(fullNameIdx, argSrcLang, isStatic); ptrInfo = info.get(); listStructElemInfo.push_back(std::move(info)); CHECK_FATAL(mapStructElemInfo.insert(std::make_pair(fullNameIdx, ptrInfo)).second == true, @@ -317,13 +318,13 @@ FEStructElemInfo *FETypeManager::RegisterStructFieldInfo(const GStrIdx &fullName return ptrInfo; } -FEStructElemInfo *FETypeManager::RegisterStructMethodInfo(const GStrIdx &fullNameIdx, MIRSrcLang srcLang, +FEStructElemInfo *FETypeManager::RegisterStructMethodInfo(const GStrIdx &fullNameIdx, MIRSrcLang argSrcLang, bool isStatic) { FEStructElemInfo *ptrInfo = GetStructElemInfo(fullNameIdx); if (ptrInfo != nullptr) { return ptrInfo; } - UniqueFEStructElemInfo info = std::make_unique(fullNameIdx, srcLang, isStatic); + UniqueFEStructElemInfo info = std::make_unique(fullNameIdx, argSrcLang, isStatic); ptrInfo = info.get(); listStructElemInfo.push_back(std::move(info)); CHECK_FATAL(mapStructElemInfo.insert(std::make_pair(fullNameIdx, ptrInfo)).second == true, diff --git a/src/mplfe/common/src/feir_builder.cpp b/src/mplfe/common/src/feir_builder.cpp index 6262f9a813808f26e056e9f36dec6cf69ffd43d0..edf5c84d11b8fb8da650672065a0b9f99ea304a9 100644 --- a/src/mplfe/common/src/feir_builder.cpp +++ b/src/mplfe/common/src/feir_builder.cpp @@ -195,7 +195,7 @@ UniqueFEIRStmt FEIRBuilder::CreateStmtJavaConstClass(UniqueFEIRVar dstVar, Uniqu } UniqueFEIRStmt FEIRBuilder::CreateStmtJavaConstString(UniqueFEIRVar dstVar, const GStrIdx &strIdx) { - UniqueFEIRType dstType = FETypeManager::kFEIRTypeJavaClass->Clone(); + UniqueFEIRType dstType = FETypeManager::kFEIRTypeJavaString->Clone(); dstVar->SetType(std::move(dstType)); UniqueFEIRStmt stmt = std::make_unique(std::move(dstVar), strIdx); return stmt; diff --git a/src/mplfe/common/src/feir_stmt.cpp b/src/mplfe/common/src/feir_stmt.cpp index d9b89bae0017a15ddab9af11246ff94ed6f35be8..cf87a4143eb988011aa7bf3b0926ea3e111fc7d7 100644 --- a/src/mplfe/common/src/feir_stmt.cpp +++ b/src/mplfe/common/src/feir_stmt.cpp @@ -215,7 +215,7 @@ std::list FEIRStmtJavaConstString::GenMIRStmtsImpl(MIRBuilder &mirBui MapleVector args(mirBuilder.GetCurrentFuncCodeMpAllocator()->Adapter()); args.push_back(mirBuilder.CreateExprAddrof(0, *literalVal)); StmtNode *stmtCreate = mirBuilder.CreateStmtCallAssigned( - FEManager::GetTypeManager().GetMCCGetOrInsertLiteral()->GetPuidx(), args, symbolLocal, OP_callassigned); + FEManager::GetTypeManager().GetPuIdxForMCCGetOrInsertLiteral(), args, symbolLocal, OP_callassigned); ans.push_back(stmtCreate); literalValPtr = symbolLocal; } @@ -237,15 +237,15 @@ FEIRStmtJavaMultiANewArray::FEIRStmtJavaMultiANewArray(std::unique_ptr : FEIRStmtAssign(FEIRNodeKind::kStmtJavaMultiANewArray, std::move(argVar)), type(std::move(argType)) {} -void FEIRStmtJavaMultiANewArray::AddVarSize(std::unique_ptr varSize) { - varSize->SetType(FETypeManager::kPrimFEIRTypeI32->Clone()); - UniqueFEIRExpr expr = FEIRBuilder::CreateExprDRead(std::move(varSize)); +void FEIRStmtJavaMultiANewArray::AddVarSize(std::unique_ptr argVarSize) { + argVarSize->SetType(FETypeManager::kPrimFEIRTypeI32->Clone()); + UniqueFEIRExpr expr = FEIRBuilder::CreateExprDRead(std::move(argVarSize)); exprSizes.push_back(std::move(expr)); } -void FEIRStmtJavaMultiANewArray::AddVarSizeRev(std::unique_ptr varSize) { - varSize->SetType(FETypeManager::kPrimFEIRTypeI32->Clone()); - UniqueFEIRExpr expr = FEIRBuilder::CreateExprDRead(std::move(varSize)); +void FEIRStmtJavaMultiANewArray::AddVarSizeRev(std::unique_ptr argVarSize) { + argVarSize->SetType(FETypeManager::kPrimFEIRTypeI32->Clone()); + UniqueFEIRExpr expr = FEIRBuilder::CreateExprDRead(std::move(argVarSize)); exprSizes.push_front(std::move(expr)); } @@ -264,7 +264,7 @@ std::list FEIRStmtJavaMultiANewArray::GenMIRStmtsImpl(MIRBuilder &mir // class annotation FEIRStmtJavaConstClass feStmtConstClass(GetVarClass()->Clone(), GetTypeAnnotation()->Clone()); std::list stmtsConstClass = feStmtConstClass.GenMIRStmts(mirBuilder); - ans.insert(ans.end(), stmtsConstClass.begin(), stmtsConstClass.end()); + (void)ans.insert(ans.end(), stmtsConstClass.begin(), stmtsConstClass.end()); // invoke newInstance UniqueFEIRVar varRetCall = var->Clone(); varRetCall->SetType(FETypeManager::kFEIRTypeJavaObject->Clone()); @@ -272,13 +272,13 @@ std::list FEIRStmtJavaMultiANewArray::GenMIRStmtsImpl(MIRBuilder &mir feStmtCall.AddExprArg(FEIRBuilder::CreateExprDRead(GetVarClass()->Clone())); feStmtCall.AddExprArg(FEIRBuilder::CreateExprDRead(GetVarSize()->Clone())); std::list stmtsCall = feStmtCall.GenMIRStmts(mirBuilder); - ans.insert(ans.end(), stmtsCall.begin(), stmtsCall.end()); + (void)ans.insert(ans.end(), stmtsCall.begin(), stmtsCall.end()); // check cast var->SetType(type->Clone()); UniqueFEIRExpr expr = std::make_unique(std::move(varRetCall)); FEIRStmtJavaTypeCheck feStmtCheck(var->Clone(), std::move(expr), type->Clone(), FEIRStmtJavaTypeCheck::kCheckCast); std::list stmtsCheck = feStmtCheck.GenMIRStmts(mirBuilder); - ans.insert(ans.end(), stmtsCheck.begin(), stmtsCheck.end()); + (void)ans.insert(ans.end(), stmtsCheck.begin(), stmtsCheck.end()); return ans; } @@ -289,7 +289,7 @@ const UniqueFEIRVar &FEIRStmtJavaMultiANewArray::GetVarSize() { MPLFE_PARALLEL_FORBIDDEN(); GStrIdx varNameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("tmpsize"); UniqueFEIRType varSizeType = FETypeManager::kPrimFEIRTypeI32->Clone(); - varSizeType->ArrayIncrDim(); + (void)varSizeType->ArrayIncrDim(); varSize = std::make_unique(varNameIdx, std::move(varSizeType), true); return varSize; } diff --git a/src/mplfe/common/src/feir_type.cpp b/src/mplfe/common/src/feir_type.cpp index 0b6261352b9c359a2109826d0f27bcd3a4bbfc17..b36e6a382213d53c01c17d71869a41db1f9dcd8b 100644 --- a/src/mplfe/common/src/feir_type.cpp +++ b/src/mplfe/common/src/feir_type.cpp @@ -24,7 +24,7 @@ namespace maple { std::map> FEIRType::langConfig = FEIRType::InitLangConfig(); FEIRType::FEIRType(FEIRTypeKind argKind) - : kind(argKind), isZero(false) {} + : kind(argKind), isZero(false), srcLang(kSrcLangJava) {} void FEIRType::CopyFromImpl(const FEIRType &type) { kind = type.kind; @@ -62,11 +62,11 @@ std::map> FEIRType::InitLangConfig() { return ans; } -MIRType *FEIRType::GenerateMIRTypeAuto(MIRSrcLang srcLang) const { +MIRType *FEIRType::GenerateMIRTypeAuto(MIRSrcLang argSrcLang) const { MPLFE_PARALLEL_FORBIDDEN(); - auto it = langConfig.find(srcLang); + auto it = langConfig.find(argSrcLang); if (it == langConfig.end()) { - CHECK_FATAL(kLncErr, "unsupported language"); + CHECK_FATAL(false, "unsupported language"); return nullptr; } return GenerateMIRType(std::get<0>(it->second), std::get<1>(it->second)); diff --git a/src/mplfe/common/src/feir_var.cpp b/src/mplfe/common/src/feir_var.cpp index f359a97877327bf1f9c06b97059c5d2c237f4374..7cae8f3e1657ec70e29633a554d99717ed45c38a 100644 --- a/src/mplfe/common/src/feir_var.cpp +++ b/src/mplfe/common/src/feir_var.cpp @@ -94,22 +94,16 @@ FEIRVar::FEIRVar(FEIRVarKind argKind, std::unique_ptr argType) MIRSymbol *FEIRVar::GenerateGlobalMIRSymbolImpl(MIRBuilder &builder) const { MPLFE_PARALLEL_FORBIDDEN(); - MIRType *mirType = type->GenerateMIRType(); - CHECK_NULL_FATAL(mirType); - MIRType *mirPtrType = (type->IsScalar()) ? mirType : GlobalTables::GetTypeTable().GetOrCreatePointerType(*mirType); - CHECK_NULL_FATAL(mirPtrType); - std::string name = GetName(*mirPtrType); - return builder.GetOrCreateGlobalDecl(name, *mirPtrType); + MIRType *mirType = type->GenerateMIRTypeAuto(); + std::string name = GetName(*mirType); + return builder.GetOrCreateGlobalDecl(name, *mirType); } MIRSymbol *FEIRVar::GenerateLocalMIRSymbolImpl(MIRBuilder &builder) const { MPLFE_PARALLEL_FORBIDDEN(); - MIRType *mirType = type->GenerateMIRType(); - CHECK_NULL_FATAL(mirType); - MIRType *mirPtrType = (type->IsScalar()) ? mirType : GlobalTables::GetTypeTable().GetOrCreatePointerType(*mirType); - CHECK_NULL_FATAL(mirPtrType); - std::string name = GetName(*mirPtrType); - return builder.GetOrCreateLocalDecl(name, *mirPtrType); + MIRType *mirType = type->GenerateMIRTypeAuto(); + std::string name = GetName(*mirType); + return builder.GetOrCreateLocalDecl(name, *mirType); } MIRSymbol *FEIRVar::GenerateMIRSymbolImpl(MIRBuilder &builder) const { diff --git a/src/mplfe/common/src/mplfe_options.cpp b/src/mplfe/common/src/mplfe_options.cpp index bf4747b206e597ea40fe3c88e71899c86534c3ff..f2a33962fa60d55d3593ca14cc1f6a22e0b11a9a 100644 --- a/src/mplfe/common/src/mplfe_options.cpp +++ b/src/mplfe/common/src/mplfe_options.cpp @@ -48,6 +48,7 @@ enum OptionIndex : uint32 { kDumpJBCAll, kDumpJBCErrorOnly, kDumpJBCFuncName, + kEmitJBCLocalVarInfo, // general stmt/bb/cfg debug options kDumpGenCFGGraph, // multi-thread control options @@ -161,6 +162,10 @@ const mapleOption::Descriptor kUsage[] = { mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyRequired, " --dump-general-cfg-graph=graph.dot\n" " : dump General CFG into graphviz dot file" }, + { static_cast(kEmitJBCLocalVarInfo), 0, "", "emit-jbc-localvar-info", + mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyNone, + " --emit-jbc-localvar-info\n" + " : emit jbc's LocalVar Info in mpl using comments" }, // multi-thread control { static_cast(kUnknown), 0, "", "", mapleOption::kBuildTypeAll, mapleOption::kArgCheckPolicyUnknown, @@ -236,6 +241,8 @@ bool MPLFEOptions::InitFactory() { &MPLFEOptions::ProcessDumpJBCErrorOnly); RegisterFactoryFunction(static_cast(kDumpJBCFuncName), &MPLFEOptions::ProcessDumpJBCFuncName); + RegisterFactoryFunction(static_cast(kEmitJBCLocalVarInfo), + &MPLFEOptions::ProcessEmitJBCLocalVarInfo); // general stmt/bb/cfg debug options RegisterFactoryFunction(static_cast(kDumpGenCFGGraph), @@ -439,6 +446,11 @@ bool MPLFEOptions::ProcessDumpJBCFuncName(const mapleOption::Option &opt) { return true; } +bool MPLFEOptions::ProcessEmitJBCLocalVarInfo(const mapleOption::Option &opt) { + FEOptions::GetInstance().SetIsEmitJBCLocalVarInfo(true); + return true; +} + // general stmt/bb/cfg debug options bool MPLFEOptions::ProcessDumpGeneralCFGGraph(const mapleOption::Option &opt) { FEOptions::GetInstance().SetIsDumpGeneralCFGGraph(true); diff --git a/src/mplfe/jbc_input/include/jbc_attr.h b/src/mplfe/jbc_input/include/jbc_attr.h index 426e9f963a33f4a44415b828ff1ebe69fe4fddf0..1cc6bc20a57c8dc319da4fe30087c4d2acc5926b 100644 --- a/src/mplfe/jbc_input/include/jbc_attr.h +++ b/src/mplfe/jbc_input/include/jbc_attr.h @@ -24,6 +24,9 @@ namespace maple { namespace jbc { +const static uint32 kInvalidPC = UINT32_MAX; +const static uint32 kMaxPC32 = 0x0000FFFF; + enum JBCAttrKind : uint8 { kAttrUnknown, kAttrRaw, @@ -72,6 +75,7 @@ class JBCAttrMap { void RegisterAttr(JBCAttr *attr); std::list GetAttrs(JBCAttrKind kind) const; const JBCAttr *GetAttr(JBCAttrKind kind) const; + bool PreProcess(const JBCConstPool &constPool); private: MapleAllocator &allocator; @@ -92,6 +96,39 @@ class JBCAttrRaw : public JBCAttr { uint8 *rawData; }; +struct JavaAttrLocalVariableInfoItem { + JavaAttrLocalVariableInfoItem() : slotIdx(0), start(0), length(0), nameIdx(0), typeNameIdx(0), signatureNameIdx(0) {} + + uint16 slotIdx; + uint16 start; + uint16 length; + GStrIdx nameIdx; // in java format + GStrIdx typeNameIdx; // in java format + GStrIdx signatureNameIdx; // in java format +}; + +class JBCAttrLocalVariableInfo { + public: + explicit JBCAttrLocalVariableInfo(MapleAllocator &argAllocator); + ~JBCAttrLocalVariableInfo() = default; + void RegisterItem(const attr::LocalVariableTableItem &itemAttr); + void RegisterTypeItem(const attr::LocalVariableTypeTableItem &itemAttr); + const JavaAttrLocalVariableInfoItem &GetItemByStart(uint16 slotIdx, uint16 start) const; + uint32 GetStart(uint16 slotIdx, uint16 pc) const; + std::list EmitToStrings() const; + static bool IsInvalidLocalVariableInfoItem(const JavaAttrLocalVariableInfoItem &item); + + private: + void AddSlotStartMap(uint16 slotIdx, uint16 startPC); + void CheckItemAvaiable(uint16 slotIdx, uint16 start) const; + JavaAttrLocalVariableInfoItem *GetItemByStartInternal(uint16 slotIdx, uint16 start); + + MapleAllocator &allocator; + MapleMap> slotStartMap; // map> + MapleMap, JavaAttrLocalVariableInfoItem> itemMap; + static JavaAttrLocalVariableInfoItem kInvalidInfoItem; +}; + // ConstantValue Attribute // ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.2 class JBCAttrConstantValue : public JBCAttr { @@ -120,7 +157,7 @@ class JBCAttrCode : public JBCAttr { public: JBCAttrCode(MapleAllocator &allocator, uint16 nameIdx, uint32 length); ~JBCAttrCode(); - void InitLocalVarInfo() const; + void InitLocalVarInfo(); void SetLoadStoreType() const; const MapleMap &GetInstMap() const { return instructions; @@ -150,6 +187,14 @@ class JBCAttrCode : public JBCAttr { return attrMap.GetAttrs(kind); } + std::list GetLocalVarInfoByString() const { + return localVarInfo.EmitToStrings(); + } + + const JBCAttrLocalVariableInfo &GetLocalVarInfo() const { + return localVarInfo; + } + protected: bool ParseFileImpl(MapleAllocator &allocator, BasicIORead &io, const JBCConstPool &constPool) override; bool PreProcessImpl(const JBCConstPool &constPool) override; @@ -168,6 +213,7 @@ class JBCAttrCode : public JBCAttr { MapleVector attrs; MapleMap instructions; JBCAttrMap attrMap; + JBCAttrLocalVariableInfo localVarInfo; }; // StackMapTable Attribute @@ -342,6 +388,9 @@ class JBCAttrLocalVariableTable : public JBCAttr { public: JBCAttrLocalVariableTable(MapleAllocator &allocator, uint16 nameIdx, uint32 length); ~JBCAttrLocalVariableTable() = default; + const MapleVector &GetLocalVarInfos() const { + return localVarInfos; + } protected: bool ParseFileImpl(MapleAllocator &allocator, BasicIORead &io, const JBCConstPool &constPool) override; @@ -359,6 +408,9 @@ class JBCAttrLocalVariableTypeTable : public JBCAttr { public: JBCAttrLocalVariableTypeTable(MapleAllocator &allocator, uint16 nameIdx, uint32 length); ~JBCAttrLocalVariableTypeTable() = default; + const MapleVector &GetLocalVarTypeInfos() const { + return localVarTypeInfos; + } protected: bool ParseFileImpl(MapleAllocator &allocator, BasicIORead &io, const JBCConstPool &constPool) override; diff --git a/src/mplfe/jbc_input/include/jbc_attr_item.h b/src/mplfe/jbc_input/include/jbc_attr_item.h index ce462b68c9b03b649b3f71a62eb1a0944aa777e2..179b774601dbe307691021e7c2e071128ba118ef 100644 --- a/src/mplfe/jbc_input/include/jbc_attr_item.h +++ b/src/mplfe/jbc_input/include/jbc_attr_item.h @@ -330,6 +330,28 @@ class LocalVariableTableItem : public JBCAttrItem { return constDesc; } + uint16 GetStartPC() const { + return startPC; + } + + uint16 GetLength() const { + return length; + } + + uint16 GetIndex() const { + return index; + } + + GStrIdx GetNameStrIdx() const { + CHECK_NULL_FATAL(constName); + return constName->GetStrIdx(); + } + + GStrIdx GetDescStrIdx() const { + CHECK_NULL_FATAL(constDesc); + return constDesc->GetStrIdx(); + } + protected: bool ParseFileImpl(MapleAllocator &allocator, BasicIORead &io) override; bool PreProcessImpl(const JBCConstPool &constPool) override; @@ -341,8 +363,10 @@ class LocalVariableTableItem : public JBCAttrItem { uint16 nameIdx; uint16 descIdx; uint16 index; - JBCConstUTF8 *constName; - JBCConstUTF8 *constDesc; + const JBCConstUTF8 *constName; + const JBCConstUTF8 *constDesc; + GStrIdx nameIdxMpl; + GStrIdx descNameIdxMpl; }; // LocalVariableTypeTableItem in Attr LocalVariableTypeTable @@ -359,6 +383,28 @@ class LocalVariableTypeTableItem : public JBCAttrItem { return constSignature; } + uint16 GetStartPC() const { + return startPC; + } + + uint16 GetLength() const { + return length; + } + + uint16 GetIndex() const { + return index; + } + + GStrIdx GetNameStrIdx() const { + CHECK_NULL_FATAL(constName); + return constName->GetStrIdx(); + } + + GStrIdx GetSignatureStrIdx() const { + CHECK_NULL_FATAL(constSignature); + return constSignature->GetStrIdx(); + } + protected: bool ParseFileImpl(MapleAllocator &allocator, BasicIORead &io) override; bool PreProcessImpl(const JBCConstPool &constPool) override; @@ -370,8 +416,10 @@ class LocalVariableTypeTableItem : public JBCAttrItem { uint16 nameIdx; uint16 signatureIdx; uint16 index; - JBCConstUTF8 *constName; - JBCConstUTF8 *constSignature; + const JBCConstUTF8 *constName; + const JBCConstUTF8 *constSignature; + GStrIdx nameIdxMpl; + GStrIdx signatureNameIdxMpl; }; class ElementValueItem : public JBCAttrItem { diff --git a/src/mplfe/jbc_input/include/jbc_function.h b/src/mplfe/jbc_input/include/jbc_function.h index ee16f428d0f8bf7d03ad581315c24710a01ef8d9..9871e803b133cf6db5f6aa691663fb2cd4b39522 100644 --- a/src/mplfe/jbc_input/include/jbc_function.h +++ b/src/mplfe/jbc_input/include/jbc_function.h @@ -27,6 +27,7 @@ #include "jbc_bb.h" #include "jbc_class2fe_helper.h" #include "jbc_stack2fe_helper.h" +#include "jbc_function_context.h" namespace maple { class JBCBBPesudoCatchPred : public GeneralBB { @@ -69,6 +70,7 @@ class JBCFunction : public FEFunction { bool CheckJVMStack(const std::string &phaseName); bool GenerateArgVarList(const std::string &phaseName) override; bool ProcessFunctionArgs(const std::string &phaseName); + bool EmitLocalVarInfo(const std::string &phaseName); bool EmitToFEIRStmt(const std::string &phaseName) override; // interface implement @@ -94,16 +96,9 @@ class JBCFunction : public FEFunction { const JBCClassMethod2FEHelper &methodHelper; const jbc::JBCClassMethod &method; JBCStack2FEHelper stack2feHelper; - bool error; - std::map mapPCStmtInst; - std::map mapPCTryStmt; // key: tryStartPC, value: stmt - std::map mapPCEndTryStmt; // key: tryEndPC, value: stmt - std::map mapPCCatchStmt; // key: handlePC, value: stmt - std::map mapPCLabelStmt; // key: labelPC, value: stmt - std::map mapPCStmtLOC; // key: locPC, value: stmt - std::map mapPCCommentStmt; // key: commentPC, value: stmt - std::map> mapJsrSlotRetAddr; // key: slotIdx, value: map - GeneralBB *pesudoBBCatchPred; + JBCFunctionContext context; + bool error = false; + GeneralBB *pesudoBBCatchPred = nullptr; bool PreBuildJsrInfo(const jbc::JBCAttrCode &code); bool BuildStmtFromInstruction(const jbc::JBCAttrCode &code); diff --git a/src/mplfe/jbc_input/include/jbc_function_context.h b/src/mplfe/jbc_input/include/jbc_function_context.h new file mode 100644 index 0000000000000000000000000000000000000000..5b5df135881ca7ecde4fa9b03e2f67d7d3fb81ca --- /dev/null +++ b/src/mplfe/jbc_input/include/jbc_function_context.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +#ifndef MPLFE_INCLUDE_JBC_INPUT_JBC_FUNCTION_CONTEXT_H +#define MPLFE_INCLUDE_JBC_INPUT_JBC_FUNCTION_CONTEXT_H +#include "mir_type.h" +#include "jbc_class_const_pool.h" +#include "jbc_attr.h" +#include "jbc_stack2fe_helper.h" +#include "jbc_stmt.h" + +namespace maple { +class JBCFunctionContext { + public: + JBCFunctionContext(const jbc::JBCConstPool &argConstPool, + JBCStack2FEHelper &argStack2feHelper, + const jbc::JBCAttrCode *argCode) + : constPool(argConstPool), + stack2feHelper(argStack2feHelper), + code(argCode) {} + + ~JBCFunctionContext() { + code = nullptr; + } + + int32 RegisterJsrSlotRetAddr(uint16 slotIdx, uint32 nextPC); + void ArrangeStmts(); + + JBCStack2FEHelper &GetStack2FEHelper() { + return stack2feHelper; + } + + const jbc::JBCConstPool &GetConstPool() const { + return constPool; + } + + const jbc::JBCAttrCode *GetCode() const { + return code; + } + + const std::map &GetMapPCStmtInst() const { + return mapPCStmtInst; + } + + const std::map &GetMapPCTryStmt() const { + return mapPCTryStmt; + } + + const std::map &GetMapPCEndTryStmt() const { + return mapPCEndTryStmt; + } + + const std::map &GetMapPCCatchStmt() const { + return mapPCCatchStmt; + } + + const std::map &GetMapPCLabelStmt() const { + return mapPCLabelStmt; + } + + const std::map &GetMapPCStmtLOC() const { + return mapPCStmtLOC; + } + + const std::map &GetMapPCCommentStmt() const { + return mapPCCommentStmt; + } + + const std::map> &GetMapJsrSlotRetAddr() const { + return mapJsrSlotRetAddr; + } + + void UpdateMapPCStmtInst(uint32 pc, GeneralStmt *stmt) { + mapPCStmtInst[pc] = stmt; + } + + void UpdateMapPCTryStmt(uint32 pc, JBCStmtPesudoTry *stmt) { + mapPCTryStmt[pc] = stmt; + } + + void UpdateMapPCEndTryStmt(uint32 pc, JBCStmtPesudoEndTry *stmt) { + mapPCEndTryStmt[pc] = stmt; + } + + void UpdateMapPCCatchStmt(uint32 pc, JBCStmtPesudoCatch *stmt) { + mapPCCatchStmt[pc] = stmt; + } + + void UpdateMapPCLabelStmt(uint32 pc, JBCStmtPesudoLabel *stmt) { + mapPCLabelStmt[pc] = stmt; + } + + void UpdateMapPCStmtLOC(uint32 pc, JBCStmtPesudoLOC *stmt) { + mapPCStmtLOC[pc] = stmt; + } + + void UpdateMapPCCommentStmt(uint32 pc, JBCStmtPesudoComment *stmt) { + mapPCCommentStmt[pc] = stmt; + } + + const jbc::JBCAttrLocalVariableInfo &GetLocalVarInfo() const { + CHECK_NULL_FATAL(code); + return code->GetLocalVarInfo(); + } + + private: + const jbc::JBCConstPool &constPool; + JBCStack2FEHelper &stack2feHelper; + const jbc::JBCAttrCode *code; + std::map mapPCStmtInst; + std::map mapPCTryStmt; // key: tryStartPC, value: stmt + std::map mapPCEndTryStmt; // key: tryEndPC, value: stmt + std::map mapPCCatchStmt; // key: handlePC, value: stmt + std::map mapPCLabelStmt; // key: labelPC, value: stmt + std::map mapPCStmtLOC; // key: locPC, value: stmt + std::map mapPCCommentStmt; // key: commentPC, value: stmt + std::map> mapJsrSlotRetAddr; // key: slotIdx, value: map +}; // class JBCFunctionContext +} // namespace maple +#endif // MPLFE_INCLUDE_JBC_INPUT_JBC_FUNCTION_CONTEXT_H \ No newline at end of file diff --git a/src/mplfe/jbc_input/include/jbc_stmt.h b/src/mplfe/jbc_input/include/jbc_stmt.h index 8891034395283754084780ebc6f3d6a4138bb1b1..4ce57018d332e9d341c2ff78102583ccf6e8a1b4 100644 --- a/src/mplfe/jbc_input/include/jbc_stmt.h +++ b/src/mplfe/jbc_input/include/jbc_stmt.h @@ -36,6 +36,7 @@ enum JBCStmtKind : uint8 { kJBCStmtPesudoCatch }; +class JBCFunctionContext; class JBCStmtKindHelper { public: static std::string JBCStmtKindName(JBCStmtKind kind); @@ -55,10 +56,8 @@ class JBCStmt : public GeneralStmt { kind(argKind) {} virtual ~JBCStmt() = default; - std::list EmitToFEIR(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { - return EmitToFEIRImpl(stack2feHelper, constPool, success); + std::list EmitToFEIR(JBCFunctionContext &context, bool &success) const { + return EmitToFEIRImpl(context, success); } JBCStmtKind GetKind() const { @@ -74,9 +73,7 @@ class JBCStmt : public GeneralStmt { } protected: - virtual std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const = 0; + virtual std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const = 0; JBCStmtKind kind; }; @@ -93,15 +90,12 @@ class JBCStmtInst : public JBCStmt { bool IsStmtInstImpl() const override; void DumpImpl(const std::string &prefix) const override; std::string DumpDotStringImpl() const override; - std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const override; + std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const override; private: const jbc::JBCOp &op; - using FuncPtrEmitToFEIR = std::list (JBCStmtInst::*)(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; + using FuncPtrEmitToFEIR = + std::list (JBCStmtInst::*)(JBCFunctionContext &context, bool &success) const; static std::map funcPtrMapForEmitToFEIR; static std::map InitFuncPtrMapForEmitToFEIR(); static std::map opcodeMapForMathBinop; @@ -110,123 +104,45 @@ class JBCStmtInst : public JBCStmt { static std::map InitOpcodeMapForMathUnop(); static std::map opcodeMapForMonitor; static std::map InitOpcodeMapForMonitor(); - std::list EmitToFEIRForOpConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpConstCommon(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpAConstNull(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpIConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpLConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpFConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpDConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpBiPush(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpSiPush(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpLdc(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpLoad(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpStore(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpArrayLoad(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpArrayStore(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpPop(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpDup(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpSwap(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpMathBinop(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpMathUnop(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpMathInc(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpConvert(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpCompare(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpReturn(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpStaticFieldOpr(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpFieldOpr(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpInvoke(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpInvokeVirtual(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpInvokeStatic(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpInvokeInterface(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpInvokeSpecial(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpInvokeDynamic(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpNew(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpMultiANewArray(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpThrow(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpTypeCheck(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpMonitor(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRForOpArrayLength(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRCommon(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; - std::list EmitToFEIRCommon2(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const; + std::list EmitToFEIRForOpConst(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpConstCommon(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpAConstNull(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpIConst(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpLConst(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpFConst(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpDConst(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpBiPush(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpSiPush(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpLdc(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpLoad(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpStore(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpArrayLoad(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpArrayStore(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpPop(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpDup(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpSwap(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpMathBinop(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpMathUnop(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpMathInc(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpConvert(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpCompare(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpReturn(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpStaticFieldOpr(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpFieldOpr(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpInvoke(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpInvokeVirtual(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpInvokeStatic(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpInvokeInterface(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpInvokeSpecial(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpInvokeDynamic(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpNew(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpMultiANewArray(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpThrow(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpTypeCheck(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpMonitor(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpArrayLength(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRCommon(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRCommon2(JBCFunctionContext &context, bool &success) const; UniqueFEIRStmt GenerateStmtForConstI32(JBCStack2FEHelper &stack2feHelper, int32 val, bool &success) const; UniqueFEIRStmt GenerateStmtForConstI64(JBCStack2FEHelper &stack2feHelper, int64 val, bool &success) const; UniqueFEIRStmt GenerateStmtForConstF32(JBCStack2FEHelper &stack2feHelper, float val, bool &success) const; @@ -241,10 +157,6 @@ class JBCStmtInstBranch : public JBCStmt { public: explicit JBCStmtInstBranch(const jbc::JBCOp &argOp); ~JBCStmtInstBranch() = default; - std::list EmitToFEIRWithLabel(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const; - const jbc::JBCOp &GetOp() const { return op; } @@ -253,13 +165,9 @@ class JBCStmtInstBranch : public JBCStmt { bool IsStmtInstImpl() const override; void DumpImpl(const std::string &prefix) const override; std::string DumpDotStringImpl() const override; - std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const override; + std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const override; JBCStmtPesudoLabel *GetTarget(const std::map &mapPCStmtLabel, uint32 pc) const; - virtual std::list EmitToFEIRForOpRetImpl(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { + virtual std::list EmitToFEIRForOpRetImpl(JBCFunctionContext &context, bool &success) const { return std::list(); } @@ -274,45 +182,26 @@ class JBCStmtInstBranch : public JBCStmt { }; using FuncPtrEmitToFEIR = - std::list (JBCStmtInstBranch::*)(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const; + std::list (JBCStmtInstBranch::*)(JBCFunctionContext &context, bool &success) const; static std::map funcPtrMapForEmitToFEIR; static std::map InitFuncPtrMapForEmitToFEIR(); static std::map> opcodeMapForCondGoto; static std::map> InitOpcodeMapForCondGoto(); - std::list EmitToFEIRForOpGoto(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const; - std::list EmitToFEIRForOpBranch(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const; - std::list EmitToFEIRForOpSwitch(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const; - std::list EmitToFEIRForOpJsr(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const; - std::list EmitToFEIRForOpRet(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const; - std::list EmitToFEIRCommon(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const; + std::list EmitToFEIRForOpGoto(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpBranch(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpSwitch(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpJsr(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRForOpRet(JBCFunctionContext &context, bool &success) const; + std::list EmitToFEIRCommon(JBCFunctionContext &context, bool &success) const; }; class JBCStmtInstBranchRet : public JBCStmtInstBranch { public: - JBCStmtInstBranchRet(const jbc::JBCOp &argOp, const std::map> &argMapJsrSlotRetAddr); + JBCStmtInstBranchRet(const jbc::JBCOp &argOp); ~JBCStmtInstBranchRet() = default; protected: - std::list EmitToFEIRForOpRetImpl(JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const override; - - private: - const std::map> &mapJsrSlotRetAddr; + std::list EmitToFEIRForOpRetImpl(JBCFunctionContext &context, bool &success) const override; }; class JBCStmtPesudoLabel : public JBCStmt { @@ -333,9 +222,7 @@ class JBCStmtPesudoLabel : public JBCStmt { protected: void DumpImpl(const std::string &prefix) const override; std::string DumpDotStringImpl() const override; - std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const override; + std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const override; uint32 labelIdx; }; @@ -356,9 +243,7 @@ class JBCStmtPesudoCatch : public JBCStmtPesudoLabel { protected: void DumpImpl(const std::string &prefix) const override; std::string DumpDotStringImpl() const override; - std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const override; + std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const override; private: std::set catchTypeNames; @@ -387,9 +272,7 @@ class JBCStmtPesudoTry : public JBCStmt { protected: void DumpImpl(const std::string &prefix) const override; std::string DumpDotStringImpl() const override; - std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const override; + std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const override; private: std::vector catchStmts; @@ -407,9 +290,7 @@ class JBCStmtPesudoEndTry : public JBCStmt { protected: void DumpImpl(const std::string &prefix) const override; std::string DumpDotStringImpl() const override; - std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const override; + std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const override; }; class JBCStmtPesudoComment : public JBCStmt { @@ -428,9 +309,7 @@ class JBCStmtPesudoComment : public JBCStmt { protected: void DumpImpl(const std::string &prefix) const override; std::string DumpDotStringImpl() const override; - std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const override; + std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const override; private: std::string content = ""; @@ -472,9 +351,7 @@ class JBCStmtPesudoLOC : public JBCStmt { protected: void DumpImpl(const std::string &prefix) const override; std::string DumpDotStringImpl() const override; - std::list EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const override; + std::list EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const override; private: uint32 srcFileIdx; diff --git a/src/mplfe/jbc_input/src/jbc_attr.cpp b/src/mplfe/jbc_input/src/jbc_attr.cpp index 66b730387f0a44ed997b374f8ba33fdb6d7bee6d..2c295ed3e962eb8940fb961ea0b79e2bff840543 100644 --- a/src/mplfe/jbc_input/src/jbc_attr.cpp +++ b/src/mplfe/jbc_input/src/jbc_attr.cpp @@ -107,6 +107,23 @@ const JBCAttr *JBCAttrMap::GetAttr(JBCAttrKind kind) const { } } +bool JBCAttrMap::PreProcess(const JBCConstPool &constPool) { + bool success = true; + for (auto itList : mapAttrs) { + for (JBCAttr *attr : *(itList.second)) { + switch (attr->GetKind()) { + case kAttrLocalVariableTable: + case kAttrLocalVariableTypeTable: + success = success && attr->PreProcess(constPool); + break; + default: + break; + } + } + } + return success; +} + // ---------- JBCAttrRaw ---------- JBCAttrRaw::JBCAttrRaw(MapleAllocator &allocator, uint16 nameIdx, uint32 length) : JBCAttr(kAttrRaw, nameIdx, length), @@ -134,6 +151,147 @@ SimpleXMLElem *JBCAttrRaw::GenXmlElemImpl(MapleAllocator &allocator, const JBCCo return nullptr; } +// ---------- JBCAttrLocalVariableInfo ---------- +JavaAttrLocalVariableInfoItem JBCAttrLocalVariableInfo::kInvalidInfoItem; + +JBCAttrLocalVariableInfo::JBCAttrLocalVariableInfo(MapleAllocator &argAllocator) + : allocator(argAllocator), + slotStartMap(allocator.Adapter()), + itemMap(allocator.Adapter()) {} + +void JBCAttrLocalVariableInfo::RegisterItem(const attr::LocalVariableTableItem &itemAttr) { + uint16 slotIdx = itemAttr.GetIndex(); + uint16 startPC = itemAttr.GetStartPC(); + uint16 length = itemAttr.GetLength(); + JavaAttrLocalVariableInfoItem *item = GetItemByStartInternal(slotIdx, startPC); + if (item == nullptr) { + CheckItemAvaiable(slotIdx, startPC); + AddSlotStartMap(slotIdx, startPC); + JavaAttrLocalVariableInfoItem &itemRef = itemMap[std::make_pair(slotIdx, startPC)]; + itemRef.slotIdx = slotIdx; + itemRef.start = startPC; + itemRef.length = length; + itemRef.nameIdx = itemAttr.GetNameStrIdx(); + itemRef.typeNameIdx = itemAttr.GetDescStrIdx(); + } else { + if (item->start == startPC && item->length == length && item->nameIdx == itemAttr.GetDescStrIdx()) { + CHECK_FATAL(item->typeNameIdx == 0, "Item already defined"); + item->typeNameIdx = itemAttr.GetDescStrIdx(); + } else { + CHECK_FATAL(false, "Item mismatch in RegisterItem()"); + } + } +} + +void JBCAttrLocalVariableInfo::RegisterTypeItem(const attr::LocalVariableTypeTableItem &itemAttr) { + uint16 slotIdx = itemAttr.GetIndex(); + uint16 startPC = itemAttr.GetStartPC(); + uint16 length = itemAttr.GetLength(); + JavaAttrLocalVariableInfoItem *item = GetItemByStartInternal(slotIdx, startPC); + if (item == nullptr) { + CheckItemAvaiable(slotIdx, startPC); + AddSlotStartMap(slotIdx, startPC); + JavaAttrLocalVariableInfoItem &itemRef = itemMap[std::make_pair(slotIdx, startPC)]; + itemRef.slotIdx = slotIdx; + itemRef.start = startPC; + itemRef.length = length; + itemRef.nameIdx = itemAttr.GetNameStrIdx(); + itemRef.signatureNameIdx = itemAttr.GetSignatureStrIdx(); + } else { + if (item->start == startPC && item->length == length && item->nameIdx == itemAttr.GetNameStrIdx()) { + CHECK_FATAL(item->signatureNameIdx == 0, "Item already defined"); + item->signatureNameIdx = itemAttr.GetSignatureStrIdx(); + } else { + CHECK_FATAL(false, "Item mismatch in RegisterItem()"); + } + } +} + +const JavaAttrLocalVariableInfoItem &JBCAttrLocalVariableInfo::GetItemByStart(uint16 slotIdx, uint16 start) const { + uint32 itemPCStart = GetStart(slotIdx, start); + if (itemPCStart != start) { + return kInvalidInfoItem; + } + std::map, JavaAttrLocalVariableInfoItem>::const_iterator it = + itemMap.find(std::make_pair(slotIdx, itemPCStart)); + CHECK_FATAL(it != itemMap.end(), "Item@%d not found", start); + return it->second; +} + +JavaAttrLocalVariableInfoItem *JBCAttrLocalVariableInfo::GetItemByStartInternal(uint16 slotIdx, uint16 start) { + uint32 itemPCStart = GetStart(slotIdx, start); + if (itemPCStart != start) { + return nullptr; + } + std::map, JavaAttrLocalVariableInfoItem>::iterator it = + itemMap.find(std::make_pair(slotIdx, itemPCStart)); + CHECK_FATAL(it != itemMap.end(), "Item@%d not found", start); + return &(it->second); +} + +uint32 JBCAttrLocalVariableInfo::GetStart(uint16 slotIdx, uint16 pc) const { + MapleMap>::const_iterator it = slotStartMap.find(slotIdx); + if (it == slotStartMap.end()) { + return jbc::kInvalidPC; + } + uint32 startLast = jbc::kInvalidPC; + for (uint16 start : it->second) { + if (pc == start) { + return start; + } else if (pc < start) { + return startLast; + } + startLast = start; + } + return startLast; +} + +std::list JBCAttrLocalVariableInfo::EmitToStrings() const { + std::list ans; + std::stringstream ss; + ans.emplace_back("===== Local Variable Info ====="); + for (const std::pair, JavaAttrLocalVariableInfoItem> &itemPair : itemMap) { + const JavaAttrLocalVariableInfoItem &item = itemPair.second; + ss.str(""); + ss << "slot[" << item.slotIdx << "]: "; + ss << "start=" << item.start << ", "; + ss << "lenght=" << item.length << ", "; + ss << "name=\'" << GlobalTables::GetStrTable().GetStringFromStrIdx(item.nameIdx) << "\', "; + ss << "type=\'" << GlobalTables::GetStrTable().GetStringFromStrIdx(item.typeNameIdx) << "\', "; + ss << "signature=\'" << GlobalTables::GetStrTable().GetStringFromStrIdx(item.signatureNameIdx) << "\'"; + ans.push_back(ss.str()); + } + ans.emplace_back("==============================="); + return ans; +} + +bool JBCAttrLocalVariableInfo::IsInvalidLocalVariableInfoItem(const JavaAttrLocalVariableInfoItem &item) { + return (item.nameIdx == 0 && item.typeNameIdx == 0 && item.signatureNameIdx == 0); +} + +void JBCAttrLocalVariableInfo::AddSlotStartMap(uint16 slotIdx, uint16 startPC) { + auto it = slotStartMap.find(slotIdx); + if (it == slotStartMap.end()) { + MapleSet startSet(allocator.Adapter()); + CHECK_FATAL(startSet.insert(startPC).second, "insert failed"); + CHECK_FATAL(slotStartMap.insert(std::make_pair(slotIdx, startSet)).second, "insert failed"); + } else { + CHECK_FATAL(it->second.insert(startPC).second, "insert failed"); + } +} + +void JBCAttrLocalVariableInfo::CheckItemAvaiable(uint16 slotIdx, uint16 start) const { + uint32 itemPCStart = GetStart(slotIdx, start); + if (itemPCStart == jbc::kInvalidPC) { + return; + } + CHECK_FATAL(itemPCStart <= jbc::kMaxPC32, "Invalid PC"); + uint16 itemPCStart16 = static_cast(itemPCStart); + const JavaAttrLocalVariableInfoItem &item = GetItemByStart(slotIdx, itemPCStart16); + CHECK_FATAL(!JBCAttrLocalVariableInfo::IsInvalidLocalVariableInfoItem(item), "Item@%d not found", itemPCStart16); + CHECK_FATAL(start >= item.start + item.length, "PC range overlapped"); +} + // ---------- JBCAttrConstantValue ---------- JBCAttrConstantValue::JBCAttrConstantValue(MapleAllocator &allocator, uint16 nameIdx, uint32 length) : JBCAttr(kAttrConstantValue, nameIdx, length), @@ -171,7 +329,8 @@ JBCAttrCode::JBCAttrCode(MapleAllocator &allocator, uint16 nameIdx, uint32 lengt nAttr(0), attrs(allocator.Adapter()), instructions(allocator.Adapter()), - attrMap(allocator) {} + attrMap(allocator), + localVarInfo(allocator) {} JBCAttrCode::~JBCAttrCode() { code = nullptr; @@ -213,6 +372,8 @@ bool JBCAttrCode::PreProcessImpl(const JBCConstPool &constPool) { for (attr::ExceptionTableItem *item : exceptions) { success = success && item->PreProcess(constPool); } + success = success && attrMap.PreProcess(constPool); + InitLocalVarInfo(); return success; } @@ -221,7 +382,25 @@ SimpleXMLElem *JBCAttrCode::GenXmlElemImpl(MapleAllocator &allocator, const JBCC } // Remove const when implemented -void JBCAttrCode::InitLocalVarInfo() const { +void JBCAttrCode::InitLocalVarInfo() { + // LocalVariableTable + std::list localVars = attrMap.GetAttrs(jbc::kAttrLocalVariableTable); + for (JBCAttr *attrRaw : localVars) { + CHECK_NULL_FATAL(attrRaw); + JBCAttrLocalVariableTable *attr = static_cast(attrRaw); + for (attr::LocalVariableTableItem *itemAttr : attr->GetLocalVarInfos()) { + localVarInfo.RegisterItem(*itemAttr); + } + } + // LocalVariableTypeTable + std::list localVarTypes = attrMap.GetAttrs(jbc::kAttrLocalVariableTypeTable); + for (JBCAttr *attrRaw : localVarTypes) { + CHECK_NULL_FATAL(attrRaw); + JBCAttrLocalVariableTypeTable *attr = static_cast(attrRaw); + for (attr::LocalVariableTypeTableItem *itemAttr : attr->GetLocalVarTypeInfos()) { + localVarInfo.RegisterTypeItem(*itemAttr); + } + } } // Remove const when implemented @@ -585,7 +764,11 @@ bool JBCAttrLocalVariableTable::ParseFileImpl(MapleAllocator &allocator, BasicIO } bool JBCAttrLocalVariableTable::PreProcessImpl(const JBCConstPool &constPool) { - return true; + bool success = true; + for (attr::LocalVariableTableItem *info : localVarInfos) { + success = success && info->PreProcess(constPool); + } + return success; } SimpleXMLElem *JBCAttrLocalVariableTable::GenXmlElemImpl(MapleAllocator &allocator, const JBCConstPool &constPool, @@ -612,7 +795,11 @@ bool JBCAttrLocalVariableTypeTable::ParseFileImpl(MapleAllocator &allocator, Bas } bool JBCAttrLocalVariableTypeTable::PreProcessImpl(const JBCConstPool &constPool) { - return true; + bool success = true; + for (attr::LocalVariableTypeTableItem *info : localVarTypeInfos) { + success = success && info->PreProcess(constPool); + } + return success; } SimpleXMLElem *JBCAttrLocalVariableTypeTable::GenXmlElemImpl(MapleAllocator &allocator, const JBCConstPool &constPool, diff --git a/src/mplfe/jbc_input/src/jbc_attr_item.cpp b/src/mplfe/jbc_input/src/jbc_attr_item.cpp index 1c55c8aac059696df02fcdbd8cbb375bcdd81ab2..6f03388a30a9827cb9dea09339fd507df6cdcbb1 100644 --- a/src/mplfe/jbc_input/src/jbc_attr_item.cpp +++ b/src/mplfe/jbc_input/src/jbc_attr_item.cpp @@ -17,6 +17,14 @@ namespace maple { namespace jbc { namespace attr { +inline GStrIdx GetOrCreateGStrIdx(const std::string &str) { + return GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(str); +} + +inline GStrIdx GetOrCreateGStrIdxWithMangler(const std::string &str) { + return GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(NameMangler::EncodeName(str)); +} + // ---------- ExceptionTableItem ---------- ExceptionTableItem::ExceptionTableItem() : startPC(0), endPC(0), handlerPC(0), catchTypeIdx(0), catchType(nullptr) {} @@ -439,7 +447,15 @@ SimpleXMLElem *LineNumberTableItem::GenXmlElemImpl(MapleAllocator &allocator, co // ---------- LocalVariableTableItem ---------- LocalVariableTableItem::LocalVariableTableItem() - : startPC(0), length(0), nameIdx(0), descIdx(0), index(0), constName(nullptr), constDesc(nullptr) {} + : startPC(0), + length(0), + nameIdx(0), + descIdx(0), + index(0), + constName(nullptr), + constDesc(nullptr), + nameIdxMpl(0), + descNameIdxMpl(0) {} LocalVariableTableItem::~LocalVariableTableItem() { constName = nullptr; @@ -457,7 +473,14 @@ bool LocalVariableTableItem::ParseFileImpl(MapleAllocator &allocator, BasicIORea } bool LocalVariableTableItem::PreProcessImpl(const JBCConstPool &constPool) { - return false; + constName = static_cast(constPool.GetConstByIdxWithTag(nameIdx, JBCConstTag::kConstUTF8)); + constDesc = static_cast(constPool.GetConstByIdxWithTag(descIdx, JBCConstTag::kConstUTF8)); + if (constName == nullptr || constDesc == nullptr) { + return false; + } + nameIdxMpl = GetOrCreateGStrIdx(constName->GetString()); + descNameIdxMpl = GetOrCreateGStrIdxWithMangler(constDesc->GetString()); + return true; } SimpleXMLElem *LocalVariableTableItem::GenXmlElemImpl(MapleAllocator &allocator, const JBCConstPool &constPool, @@ -485,7 +508,15 @@ bool LocalVariableTypeTableItem::ParseFileImpl(MapleAllocator &allocator, BasicI } bool LocalVariableTypeTableItem::PreProcessImpl(const JBCConstPool &constPool) { - return false; + constName = static_cast(constPool.GetConstByIdxWithTag(nameIdx, JBCConstTag::kConstUTF8)); + constSignature = + static_cast(constPool.GetConstByIdxWithTag(signatureIdx, JBCConstTag::kConstUTF8)); + if (constName == nullptr || constSignature == nullptr) { + return false; + } + nameIdxMpl = GetOrCreateGStrIdx(constName->GetString()); + signatureNameIdxMpl = GetOrCreateGStrIdxWithMangler(constSignature->GetString()); + return true; } SimpleXMLElem *LocalVariableTypeTableItem::GenXmlElemImpl(MapleAllocator &allocator, const JBCConstPool &constPool, diff --git a/src/mplfe/jbc_input/src/jbc_class.cpp b/src/mplfe/jbc_input/src/jbc_class.cpp index 29a35b9d042c55833f888fafee17cb2aa69918be..86445d8e555b6af49cab84e869e174a179eb1c25 100644 --- a/src/mplfe/jbc_input/src/jbc_class.cpp +++ b/src/mplfe/jbc_input/src/jbc_class.cpp @@ -82,8 +82,14 @@ SimpleXMLElem *JBCClassMethod::GenXmlElemImpl(MapleAllocator &allocator, const J bool JBCClassMethod::PreProcess() { bool success = true; for (JBCAttr *attr : attrs) { - if (attr->GetKind() == kAttrCode) { - success = success && attr->PreProcess(klass.GetConstPool()); + switch (attr->GetKind()) { + case kAttrCode: + case kAttrLocalVariableTable: + case kAttrLocalVariableTypeTable: + success = success && attr->PreProcess(klass.GetConstPool()); + break; + default: + break; } } return success; diff --git a/src/mplfe/jbc_input/src/jbc_function.cpp b/src/mplfe/jbc_input/src/jbc_function.cpp index 28a33357f1082d9c968b8e0826523f1ddb942771..a6481c0ad4fdb6b024c96ee18ed8d486e7824a0c 100644 --- a/src/mplfe/jbc_input/src/jbc_function.cpp +++ b/src/mplfe/jbc_input/src/jbc_function.cpp @@ -26,8 +26,7 @@ JBCFunction::JBCFunction(const JBCClassMethod2FEHelper &argMethodHelper, MIRFunc : FEFunction(mirFunc, argPhaseResultTotal), methodHelper(argMethodHelper), method(methodHelper.GetMethod()), - error(false), - pesudoBBCatchPred(nullptr) { + context(method.GetConstPool(), stack2feHelper, method.GetCode()) { } JBCFunction::~JBCFunction() { @@ -57,6 +56,9 @@ void JBCFunction::ProcessImpl() { success = success && CheckJVMStack("check jvm stack"); success = success && GenerateArgVarList("gen arg var list"); success = success && ProcessFunctionArgs("process func args"); + if (FEOptions::GetInstance().IsEmitJBCLocalVarInfo()) { + success = success && EmitLocalVarInfo("emit localvar info"); + } success = success && EmitToFEIRStmt("emit to feir"); success = success && ProcessFEIRFunction(); if (!success) { @@ -176,6 +178,23 @@ bool JBCFunction::ProcessFunctionArgs(const std::string &phaseName) { return phaseResult.Finish(); } +bool JBCFunction::EmitLocalVarInfo(const std::string &phaseName) { + phaseResult.RegisterPhaseNameAndStart(phaseName); + const jbc::JBCAttrCode *code = method.GetCode(); + if (code == nullptr) { + return phaseResult.Finish(); + } + FEIRStmt *insPos = feirStmtHead; + std::list listInfo = code->GetLocalVarInfoByString(); + for (const std::string &infoStr : listInfo) { + UniqueFEIRStmt stmt = std::make_unique(infoStr); + FEIRStmt *ptrFEIRStmt = RegisterFEIRStmt(std::move(stmt)); + insPos->InsertAfter(ptrFEIRStmt); + insPos = ptrFEIRStmt; + } + return phaseResult.Finish(); +} + bool JBCFunction::EmitToFEIRStmt(const std::string &phaseName) { phaseResult.RegisterPhaseNameAndStart(phaseName); const FELinkListNode *bbNode = genBBHead->GetNext(); @@ -198,12 +217,7 @@ void JBCFunction::EmitToFEIRStmt(const JBCBB &bb) { const FELinkListNode *stmtNode = bb.GetStmtHead(); while (stmtNode != nullptr && success) { const JBCStmt *stmt = static_cast(stmtNode); - if (stmt->IsBranch()) { - const JBCStmtInstBranch *stmtBranch = static_cast(stmt); - feirStmts = stmtBranch->EmitToFEIRWithLabel(stack2feHelper, mapPCLabelStmt, success); - } else { - feirStmts = stmt->EmitToFEIR(stack2feHelper, method.GetConstPool(), success); - } + feirStmts = stmt->EmitToFEIR(context, success); AppendFEIRStmts(feirStmts); if (stmtNode == bb.GetStmtTail()) { break; @@ -331,15 +345,8 @@ bool JBCFunction::PreBuildJsrInfo(const jbc::JBCAttrCode &code) { uint16 slotIdx = opSlotOpr->GetSlotIdx(); opSlotOpr->SetAddressOpr(); opJsr->SetSlotIdx(slotIdx); - auto itInfo = mapJsrSlotRetAddr.find(slotIdx); - int32 jsrID; - if (itInfo == mapJsrSlotRetAddr.end()) { - jsrID = 0; - } else { - jsrID = itInfo->second.size(); - } + int32 jsrID = context.RegisterJsrSlotRetAddr(slotIdx, nextPC); opJsr->SetJsrID(jsrID); - mapJsrSlotRetAddr[slotIdx][jsrID] = nextPC; } return true; } @@ -375,9 +382,9 @@ bool JBCFunction::BuildStmtFromInstruction(const jbc::JBCAttrCode &code) { break; } genStmtTail->InsertBefore(stmt); - mapPCStmtInst[pc] = stmt; + context.UpdateMapPCStmtInst(pc, stmt); } - mapPCStmtInst[code.GetCodeLength()] = genStmtTail; + context.UpdateMapPCStmtInst(code.GetCodeLength(), genStmtTail); return true; } @@ -429,8 +436,9 @@ GeneralStmt *JBCFunction::BuildStmtFromInstructionForJsr(const jbc::JBCOp &op) { } GeneralStmt *JBCFunction::BuildStmtFromInstructionForRet(const jbc::JBCOp &op) { + const std::map> &mapJsrSlotRetAddr = context.GetMapJsrSlotRetAddr(); const std::unique_ptr &uniStmt = - RegisterGeneralStmtUniqueReturn(std::make_unique(op, mapJsrSlotRetAddr)); + RegisterGeneralStmtUniqueReturn(std::make_unique(op)); GeneralStmt *stmt = uniStmt.get(); stmt->SetFallThru(false); const jbc::JBCOpRet &opRet = static_cast(op); @@ -448,6 +456,7 @@ GeneralStmt *JBCFunction::BuildStmtFromInstructionForRet(const jbc::JBCOp &op) { } void JBCFunction::BuildStmtForCatch(const jbc::JBCAttrCode &code) { + const std::map &mapPCCatchStmt = context.GetMapPCCatchStmt(); const MapleVector &exceptionInfo = code.GetExceptionInfos(); for (const jbc::attr::ExceptionTableItem *item : exceptionInfo) { uint16 handlerPC = item->GetHandlerPC(); @@ -455,7 +464,7 @@ void JBCFunction::BuildStmtForCatch(const jbc::JBCAttrCode &code) { auto it = mapPCCatchStmt.find(handlerPC); if (it == mapPCCatchStmt.end()) { stmtCatch = static_cast(RegisterGeneralStmt(std::make_unique())); - mapPCCatchStmt[handlerPC] = stmtCatch; + context.UpdateMapPCCatchStmt(handlerPC, stmtCatch); } else { stmtCatch = static_cast(it->second); } @@ -468,10 +477,11 @@ void JBCFunction::BuildStmtForCatch(const jbc::JBCAttrCode &code) { } } -void JBCFunction::BuildStmtForTry(const jbc::JBCAttrCode &code) {\ +void JBCFunction::BuildStmtForTry(const jbc::JBCAttrCode &code) { std::map, std::vector> rawInfo; std::map outMapStartEnd; std::map> outMapStartCatch; + const std::map &mapPCCatchStmt = context.GetMapPCCatchStmt(); const MapleVector &exceptionInfo = code.GetExceptionInfos(); for (const jbc::attr::ExceptionTableItem *item : exceptionInfo) { uint32 start = item->GetStartPC(); @@ -487,14 +497,15 @@ void JBCFunction::BuildStmtForTry(const jbc::JBCAttrCode &code) {\ auto it = outMapStartCatch.find(startEnd.first); CHECK_FATAL(it != outMapStartCatch.end(), "catch info not exist"); for (uint32 handlerPC : it->second) { - CHECK_FATAL(mapPCCatchStmt.find(handlerPC) != mapPCCatchStmt.end(), "catch stmt not exist"); - stmtTry->AddCatchStmt(mapPCCatchStmt[handlerPC]); + auto itHandler = mapPCCatchStmt.find(handlerPC); + CHECK_FATAL(itHandler != mapPCCatchStmt.end(), "catch stmt not exist"); + stmtTry->AddCatchStmt(itHandler->second); } - mapPCTryStmt[startEnd.first] = stmtTry; + context.UpdateMapPCTryStmt(startEnd.first, stmtTry); // EndTry JBCStmtPesudoEndTry *stmtEndTry = static_cast(RegisterGeneralStmt(std::make_unique())); - mapPCEndTryStmt[startEnd.second] = stmtEndTry; + context.UpdateMapPCEndTryStmt(startEnd.second, stmtEndTry); } } @@ -590,7 +601,7 @@ void JBCFunction::BuildStmtForLOC(const jbc::JBCAttrCode &code) { static_cast(RegisterGeneralStmt(std::make_unique())); stmtLOC->SetSrcFileIdx(srcFileIdx); stmtLOC->SetLineNumber(item->GetLineNumber()); - mapPCStmtLOC[item->GetStartPC()] = stmtLOC; + context.UpdateMapPCStmtLOC(item->GetStartPC(), stmtLOC); } } @@ -627,17 +638,18 @@ void JBCFunction::BuildStmtForInstComment(const jbc::JBCAttrCode &code) { op->Dump(constPool); std::unique_ptr stmt = std::make_unique(ss.str()); JBCStmtPesudoComment *ptrStmt = static_cast(RegisterGeneralStmt(std::move(stmt))); - mapPCCommentStmt[pc] = ptrStmt; + context.UpdateMapPCCommentStmt(pc, ptrStmt); ss.str(""); } } GeneralStmt *JBCFunction::BuildAndUpdateLabel(uint32 dstPC, const std::unique_ptr &srcStmt) { + const std::map &mapPCLabelStmt = context.GetMapPCLabelStmt(); auto it = mapPCLabelStmt.find(dstPC); JBCStmtPesudoLabel *stmtLabel = nullptr; if (it == mapPCLabelStmt.end()) { stmtLabel = static_cast(RegisterGeneralStmt(std::make_unique())); - mapPCLabelStmt[dstPC] = stmtLabel; + context.UpdateMapPCLabelStmt(dstPC, stmtLabel); } else { stmtLabel = it->second; } @@ -647,37 +659,7 @@ GeneralStmt *JBCFunction::BuildAndUpdateLabel(uint32 dstPC, const std::unique_pt } void JBCFunction::ArrangeStmts() { - /* Type of stmt: inst, label, try, endtry, catch, comment, loc - * endtry - * loc - * catch - * label - * try - * comment - * inst - */ - for (const std::pair &pcInst : mapPCStmtInst) { - uint32 pc = pcInst.first; - GeneralStmt *stmtInst = pcInst.second; - if (mapPCEndTryStmt.find(pc) != mapPCEndTryStmt.end()) { - stmtInst->InsertBefore(mapPCEndTryStmt[pc]); - } - if (mapPCStmtLOC.find(pc) != mapPCStmtLOC.end()) { - stmtInst->InsertBefore(mapPCStmtLOC[pc]); - } - if (mapPCCatchStmt.find(pc) != mapPCCatchStmt.end()) { - stmtInst->InsertBefore(mapPCCatchStmt[pc]); - } - if (mapPCLabelStmt.find(pc) != mapPCLabelStmt.end()) { - stmtInst->InsertBefore(mapPCLabelStmt[pc]); - } - if (mapPCTryStmt.find(pc) != mapPCTryStmt.end()) { - stmtInst->InsertBefore(mapPCTryStmt[pc]); - } - if (mapPCCommentStmt.find(pc) != mapPCCommentStmt.end()) { - stmtInst->InsertBefore(mapPCCommentStmt[pc]); - } - } + context.ArrangeStmts(); } void JBCFunction::InitStack2FEHelper() { diff --git a/src/mplfe/jbc_input/src/jbc_function_context.cpp b/src/mplfe/jbc_input/src/jbc_function_context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9eba3336506425f3250330417ee2dd24b521816d --- /dev/null +++ b/src/mplfe/jbc_input/src/jbc_function_context.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +#include "jbc_function_context.h" + +namespace maple { +int32 JBCFunctionContext::RegisterJsrSlotRetAddr(uint16 slotIdx, uint32 nextPC) { + auto itInfo = mapJsrSlotRetAddr.find(slotIdx); + int32 jsrID; + if (itInfo == mapJsrSlotRetAddr.end()) { + jsrID = 0; + } else { + size_t size = itInfo->second.size(); + CHECK_FATAL(size < INT32_MAX, "jsr ID out of range"); + jsrID = static_cast(itInfo->second.size()); + } + mapJsrSlotRetAddr[slotIdx][jsrID] = nextPC; + return jsrID; +} + +void JBCFunctionContext::ArrangeStmts() { + /* Type of stmt: inst, label, try, endtry, catch, comment, loc + * endtry + * loc + * catch + * label + * try + * comment + * inst + */ + for (const std::pair &pcInst : mapPCStmtInst) { + uint32 pc = pcInst.first; + GeneralStmt *stmtInst = pcInst.second; + if (mapPCEndTryStmt.find(pc) != mapPCEndTryStmt.end()) { + stmtInst->InsertBefore(mapPCEndTryStmt[pc]); + } + if (mapPCStmtLOC.find(pc) != mapPCStmtLOC.end()) { + stmtInst->InsertBefore(mapPCStmtLOC[pc]); + } + if (mapPCCatchStmt.find(pc) != mapPCCatchStmt.end()) { + stmtInst->InsertBefore(mapPCCatchStmt[pc]); + } + if (mapPCLabelStmt.find(pc) != mapPCLabelStmt.end()) { + stmtInst->InsertBefore(mapPCLabelStmt[pc]); + } + if (mapPCTryStmt.find(pc) != mapPCTryStmt.end()) { + stmtInst->InsertBefore(mapPCTryStmt[pc]); + } + if (mapPCCommentStmt.find(pc) != mapPCCommentStmt.end()) { + stmtInst->InsertBefore(mapPCCommentStmt[pc]); + } + } +} +} // namespace maple \ No newline at end of file diff --git a/src/mplfe/jbc_input/src/jbc_opcode.cpp b/src/mplfe/jbc_input/src/jbc_opcode.cpp index b913ad2dc0985ef213053ec6b13c6269a6045113..e52f2853bda8defa73de5a35848cadfbb0ee8e29 100644 --- a/src/mplfe/jbc_input/src/jbc_opcode.cpp +++ b/src/mplfe/jbc_input/src/jbc_opcode.cpp @@ -1240,7 +1240,7 @@ std::string JBCOpInvoke::GetMethodDescription(const JBCConstPool &constPool) con // ---------- JBCOpJsrRet ---------- JBCOpJsr::JBCOpJsr(MapleAllocator &allocator, JBCOpcode opIn, JBCOpcodeKind kindIn, bool wideIn) - : JBCOp(allocator, opIn, kindIn, wideIn), target(0) {} + : JBCOp(allocator, opIn, kindIn, wideIn), target(0), slotIdx(0), jsrID(0) {} bool JBCOpJsr::ParseFileImpl(BasicIORead &io) { if (JBCOp::CheckNotWide(io) == false) { diff --git a/src/mplfe/jbc_input/src/jbc_stmt.cpp b/src/mplfe/jbc_input/src/jbc_stmt.cpp index 2d944f31f314b33192068ada370aa9143e22e437..ed8f845a3d15e619db639902db0faee107ffd96e 100644 --- a/src/mplfe/jbc_input/src/jbc_stmt.cpp +++ b/src/mplfe/jbc_input/src/jbc_stmt.cpp @@ -16,10 +16,11 @@ #include #include #include +#include "opcodes.h" #include "feir_stmt.h" #include "feir_builder.h" #include "fe_struct_elem_info.h" -#include "opcodes.h" +#include "jbc_function_context.h" namespace maple { // ---------- JBCStmtKindHelper ---------- @@ -82,14 +83,12 @@ std::string JBCStmtInst::DumpDotStringImpl() const { return ss.str(); } -std::list JBCStmtInst::EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const { auto it = funcPtrMapForEmitToFEIR.find(op.GetOpcodeKind()); if (it != funcPtrMapForEmitToFEIR.end()) { - return (this->*(it->second))(stack2feHelper, constPool, success); + return (this->*(it->second))(context, success); } else { - return EmitToFEIRCommon(stack2feHelper, constPool, success); + return EmitToFEIRCommon(context, success); } } @@ -179,12 +178,10 @@ std::map JBCStmtInst::InitOpcodeMapForMonitor() { return ans; } -std::list JBCStmtInst::EmitToFEIRForOpConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpConst(JBCFunctionContext &context, bool &success) const { switch (op.GetOpcode()) { case jbc::kOpAConstNull: - return EmitToFEIRForOpAConstNull(stack2feHelper, constPool, success); + return EmitToFEIRForOpAConstNull(context, success); case jbc::kOpIConstM1: case jbc::kOpIConst0: case jbc::kOpIConst1: @@ -192,25 +189,25 @@ std::list JBCStmtInst::EmitToFEIRForOpConst(JBCStack2FEHelper &s case jbc::kOpIConst3: case jbc::kOpIConst4: case jbc::kOpIConst5: - return EmitToFEIRForOpIConst(stack2feHelper, constPool, success); + return EmitToFEIRForOpIConst(context, success); case jbc::kOpLConst0: case jbc::kOpLConst1: - return EmitToFEIRForOpLConst(stack2feHelper, constPool, success); + return EmitToFEIRForOpLConst(context, success); case jbc::kOpFConst0: case jbc::kOpFConst1: case jbc::kOpFConst2: - return EmitToFEIRForOpFConst(stack2feHelper, constPool, success); + return EmitToFEIRForOpFConst(context, success); case jbc::kOpDConst0: case jbc::kOpDConst1: - return EmitToFEIRForOpDConst(stack2feHelper, constPool, success); + return EmitToFEIRForOpDConst(context, success); case jbc::kOpBiPush: - return EmitToFEIRForOpBiPush(stack2feHelper, constPool, success); + return EmitToFEIRForOpBiPush(context, success); case jbc::kOpSiPush: - return EmitToFEIRForOpSiPush(stack2feHelper, constPool, success); + return EmitToFEIRForOpSiPush(context, success); case jbc::kOpLdc: case jbc::kOpLdcW: case jbc::kOpLdc2W: - return EmitToFEIRForOpLdc(stack2feHelper, constPool, success); + return EmitToFEIRForOpLdc(context, success); default: ERR(kLncErr, "EmitToFEIRForOpConst: unsupport jbc opcode %s", jbc::JBCOp::GetOpcodeInfo().GetOpcodeName(op.GetOpcode()).c_str()); @@ -219,10 +216,10 @@ std::list JBCStmtInst::EmitToFEIRForOpConst(JBCStack2FEHelper &s } } -std::list JBCStmtInst::EmitToFEIRForOpConstCommon(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpConstCommon(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); jbc::JBCPrimType stackOutType = op.GetOutputTypesToStack(constPool); if (stackOutType != jbc::JBCPrimType::kTypeDefault) { PrimType pty = JBCStack2FEHelper::JBCStackItemTypeToPrimType(stackOutType); @@ -239,10 +236,9 @@ std::list JBCStmtInst::EmitToFEIRForOpConstCommon(JBCStack2FEHel return ans; } -std::list JBCStmtInst::EmitToFEIRForOpAConstNull(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpAConstNull(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); UniqueFEIRExpr exprConst = FEIRBuilder::CreateExprConstRefNull(); UniqueFEIRVar varDst = stack2feHelper.PushItem(PTY_ref); if (varDst == nullptr) { @@ -254,10 +250,9 @@ std::list JBCStmtInst::EmitToFEIRForOpAConstNull(JBCStack2FEHelp return ans; } -std::list JBCStmtInst::EmitToFEIRForOpIConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpIConst(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpConst &opConst = static_cast(op); int32 val = opConst.GetValueInt(); UniqueFEIRStmt stmtDAssign = GenerateStmtForConstI32(stack2feHelper, val, success); @@ -267,10 +262,9 @@ std::list JBCStmtInst::EmitToFEIRForOpIConst(JBCStack2FEHelper & return ans; } -std::list JBCStmtInst::EmitToFEIRForOpLConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpLConst(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpConst &opConst = static_cast(op); int64 val = opConst.GetValueLong(); UniqueFEIRStmt stmtDAssign = GenerateStmtForConstI64(stack2feHelper, val, success); @@ -280,10 +274,9 @@ std::list JBCStmtInst::EmitToFEIRForOpLConst(JBCStack2FEHelper & return ans; } -std::list JBCStmtInst::EmitToFEIRForOpFConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpFConst(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpConst &opConst = static_cast(op); float val = opConst.GetValueFloat(); UniqueFEIRStmt stmtDAssign = GenerateStmtForConstF32(stack2feHelper, val, success); @@ -293,10 +286,9 @@ std::list JBCStmtInst::EmitToFEIRForOpFConst(JBCStack2FEHelper & return ans; } -std::list JBCStmtInst::EmitToFEIRForOpDConst(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpDConst(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpConst &opConst = static_cast(op); double val = opConst.GetValueDouble(); UniqueFEIRStmt stmtDAssign = GenerateStmtForConstF64(stack2feHelper, val, success); @@ -306,10 +298,9 @@ std::list JBCStmtInst::EmitToFEIRForOpDConst(JBCStack2FEHelper & return ans; } -std::list JBCStmtInst::EmitToFEIRForOpBiPush(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpBiPush(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpConst &opConst = static_cast(op); int8 val = opConst.GetValueByte(); UniqueFEIRStmt stmtDAssign = GenerateStmtForConstI32(stack2feHelper, int32{ val }, success); @@ -319,10 +310,9 @@ std::list JBCStmtInst::EmitToFEIRForOpBiPush(JBCStack2FEHelper & return ans; } -std::list JBCStmtInst::EmitToFEIRForOpSiPush(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpSiPush(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpConst &opConst = static_cast(op); int16 val = opConst.GetValueShort(); UniqueFEIRStmt stmtDAssign = GenerateStmtForConstI32(stack2feHelper, int32{ val }, success); @@ -332,10 +322,10 @@ std::list JBCStmtInst::EmitToFEIRForOpSiPush(JBCStack2FEHelper & return ans; } -std::list JBCStmtInst::EmitToFEIRForOpLdc(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpLdc(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpConst &opConst = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdx(opConst.GetIndex()); if (constRaw == nullptr) { @@ -386,10 +376,9 @@ std::list JBCStmtInst::EmitToFEIRForOpLdc(JBCStack2FEHelper &sta return ans; } -std::list JBCStmtInst::EmitToFEIRForOpLoad(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpLoad(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpSlotOpr &opLoad = static_cast(op); std::vector stackInTypes = op.GetInputTypesFromStack(); CHECK_FATAL(stackInTypes.empty(), "no items should be popped"); @@ -405,10 +394,9 @@ std::list JBCStmtInst::EmitToFEIRForOpLoad(JBCStack2FEHelper &st return ans; } -std::list JBCStmtInst::EmitToFEIRForOpStore(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpStore(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpSlotOpr &opStore = static_cast(op); if (opStore.IsAddressOpr()) { UniqueFEIRVar varTmp = stack2feHelper.PopItem(PTY_a32); @@ -433,9 +421,8 @@ std::list JBCStmtInst::EmitToFEIRForOpStore(JBCStack2FEHelper &s return ans; } -std::list JBCStmtInst::EmitToFEIRForOpArrayLoad(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpArrayLoad(JBCFunctionContext &context, bool &success) const { + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); // Process In std::vector stackInTypes = op.GetInputTypesFromStack(); // ArrayLoad need 2 input opnds @@ -452,9 +439,8 @@ std::list JBCStmtInst::EmitToFEIRForOpArrayLoad(JBCStack2FEHelpe return FEIRBuilder::CreateStmtArrayLoad(std::move(varElem), std::move(varArray), std::move(varIndex), ptyElem); } -std::list JBCStmtInst::EmitToFEIRForOpArrayStore(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpArrayStore(JBCFunctionContext &context, bool &success) const { + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); // Process In std::vector stackInTypes = op.GetInputTypesFromStack(); // ArrayStore need 3 input opnds @@ -468,34 +454,30 @@ std::list JBCStmtInst::EmitToFEIRForOpArrayStore(JBCStack2FEHelp return FEIRBuilder::CreateStmtArrayStore(std::move(varElem), std::move(varArray), std::move(varIndex), ptyElem); } -std::list JBCStmtInst::EmitToFEIRForOpPop(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpPop(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); success = stack2feHelper.Pop(op.GetOpcode()); return ans; } -std::list JBCStmtInst::EmitToFEIRForOpDup(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpDup(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); success = stack2feHelper.Dup(op.GetOpcode()); return ans; } -std::list JBCStmtInst::EmitToFEIRForOpSwap(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpSwap(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); success = stack2feHelper.Swap(); return ans; } -std::list JBCStmtInst::EmitToFEIRForOpMathBinop(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpMathBinop(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); // obtain in/out types std::vector stackInTypes = op.GetInputTypesFromStack(); CHECK_FATAL(stackInTypes.size() == 2, "Not enough input opnds for math binary op"); // 2 : opnds num limit @@ -523,10 +505,9 @@ std::list JBCStmtInst::EmitToFEIRForOpMathBinop(JBCStack2FEHelpe return ans; } -std::list JBCStmtInst::EmitToFEIRForOpMathUnop(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpMathUnop(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); // obtain in/out types std::vector stackInTypes = op.GetInputTypesFromStack(); ASSERT(stackInTypes.size() == 1, "Not enough input opnds for math unary op"); @@ -552,10 +533,9 @@ std::list JBCStmtInst::EmitToFEIRForOpMathUnop(JBCStack2FEHelper return ans; } -std::list JBCStmtInst::EmitToFEIRForOpMathInc(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpMathInc(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpMathInc &opInc = static_cast(op); // no stack operation uint32 regNum = stack2feHelper.GetRegNumForSlot(opInc.GetIndex()); @@ -569,10 +549,9 @@ std::list JBCStmtInst::EmitToFEIRForOpMathInc(JBCStack2FEHelper return ans; } -std::list JBCStmtInst::EmitToFEIRForOpConvert(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpConvert(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); std::vector stackInTypes = op.GetInputTypesFromStack(); ASSERT(stackInTypes.size() == 1, "invalid in type for convert"); PrimType ptyIn = JBCStack2FEHelper::JBCStackItemTypeToPrimType(stackInTypes[0]); @@ -620,17 +599,14 @@ std::list JBCStmtInst::EmitToFEIRForOpConvert(JBCStack2FEHelper return ans; } -std::list JBCStmtInst::EmitToFEIRForOpCompare(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpCompare(JBCFunctionContext &context, bool &success) const { std::list ans; return ans; } -std::list JBCStmtInst::EmitToFEIRForOpReturn(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpReturn(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); // obtain in/out types std::vector stackInTypes = op.GetInputTypesFromStack(); if (op.GetOpcode() == jbc::kOpReturn) { @@ -652,10 +628,10 @@ std::list JBCStmtInst::EmitToFEIRForOpReturn(JBCStack2FEHelper & return ans; } -std::list JBCStmtInst::EmitToFEIRForOpStaticFieldOpr(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpStaticFieldOpr(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpFieldOpr &opField = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdxWithTag(opField.GetFieldIdx(), jbc::JBCConstTag::kConstFieldRef); @@ -678,10 +654,10 @@ std::list JBCStmtInst::EmitToFEIRForOpStaticFieldOpr(JBCStack2FE return ans; } -std::list JBCStmtInst::EmitToFEIRForOpFieldOpr(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpFieldOpr(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpFieldOpr &opField = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdxWithTag(opField.GetFieldIdx(), jbc::JBCConstTag::kConstFieldRef); @@ -706,25 +682,23 @@ std::list JBCStmtInst::EmitToFEIRForOpFieldOpr(JBCStack2FEHelper return ans; } -std::list JBCStmtInst::EmitToFEIRForOpInvoke(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpInvoke(JBCFunctionContext &context, bool &success) const { switch (op.GetOpcode()) { case jbc::kOpInvokeVirtual: - return EmitToFEIRForOpInvokeVirtual(stack2feHelper, constPool, success); + return EmitToFEIRForOpInvokeVirtual(context, success); case jbc::kOpInvokeSpecial: - return EmitToFEIRForOpInvokeSpecial(stack2feHelper, constPool, success); + return EmitToFEIRForOpInvokeSpecial(context, success); case jbc::kOpInvokeStatic: - return EmitToFEIRForOpInvokeStatic(stack2feHelper, constPool, success); + return EmitToFEIRForOpInvokeStatic(context, success); case jbc::kOpInvokeInterface: - return EmitToFEIRForOpInvokeInterface(stack2feHelper, constPool, success); + return EmitToFEIRForOpInvokeInterface(context, success); case jbc::kOpInvokeDynamic: - return EmitToFEIRForOpInvokeDynamic(stack2feHelper, constPool, success); + return EmitToFEIRForOpInvokeDynamic(context, success); default: CHECK_FATAL(false, "unsupported op: %s", op.GetOpcodeName().c_str()); break; } - return EmitToFEIRCommon2(stack2feHelper, constPool, success); + return EmitToFEIRCommon2(context, success); } void JBCStmtInst::PrepareInvokeParametersAndReturn(JBCStack2FEHelper &stack2feHelper, @@ -755,10 +729,10 @@ void JBCStmtInst::PrepareInvokeParametersAndReturn(JBCStack2FEHelper &stack2feHe } } -std::list JBCStmtInst::EmitToFEIRForOpInvokeVirtual(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpInvokeVirtual(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpInvoke &opInvoke = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdx(opInvoke.GetMethodIdx()); if (constRaw == nullptr || @@ -776,10 +750,10 @@ std::list JBCStmtInst::EmitToFEIRForOpInvokeVirtual(JBCStack2FEH return ans; } -std::list JBCStmtInst::EmitToFEIRForOpInvokeStatic(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpInvokeStatic(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpInvoke &opInvoke = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdx(opInvoke.GetMethodIdx()); if (constRaw == nullptr || @@ -797,10 +771,11 @@ std::list JBCStmtInst::EmitToFEIRForOpInvokeStatic(JBCStack2FEHe return ans; } -std::list JBCStmtInst::EmitToFEIRForOpInvokeInterface(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, +std::list JBCStmtInst::EmitToFEIRForOpInvokeInterface(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpInvoke &opInvoke = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdx(opInvoke.GetMethodIdx()); if (constRaw == nullptr || @@ -818,10 +793,10 @@ std::list JBCStmtInst::EmitToFEIRForOpInvokeInterface(JBCStack2F return ans; } -std::list JBCStmtInst::EmitToFEIRForOpInvokeSpecial(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpInvokeSpecial(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpInvoke &opInvoke = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdx(opInvoke.GetMethodIdx()); if (constRaw == nullptr || @@ -840,10 +815,10 @@ std::list JBCStmtInst::EmitToFEIRForOpInvokeSpecial(JBCStack2FEH return ans; } -std::list JBCStmtInst::EmitToFEIRForOpInvokeDynamic(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpInvokeDynamic(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpInvoke &opInvoke = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdx(opInvoke.GetMethodIdx()); if (constRaw == nullptr || constRaw->GetTag() != jbc::JBCConstTag::kConstInvokeDynamic) { @@ -859,10 +834,10 @@ std::list JBCStmtInst::EmitToFEIRForOpInvokeDynamic(JBCStack2FEH return ans; } -std::list JBCStmtInst::EmitToFEIRForOpNew(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpNew(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpNew &opNew = static_cast(op); UniqueFEIRType type = opNew.GetFEIRType(constPool)->Clone(); UniqueFEIRExpr expr(nullptr); @@ -898,10 +873,10 @@ std::list JBCStmtInst::EmitToFEIRForOpNew(JBCStack2FEHelper &sta return ans; } -std::list JBCStmtInst::EmitToFEIRForOpMultiANewArray(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpMultiANewArray(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); const jbc::JBCOpMultiANewArray &opArray = static_cast(op); const jbc::JBCConst *constRaw = constPool.GetConstByIdxWithTag(opArray.GetRefTypeIdx(), jbc::JBCConstTag::kConstClass); @@ -934,10 +909,9 @@ std::list JBCStmtInst::EmitToFEIRForOpMultiANewArray(JBCStack2FE return ans; } -std::list JBCStmtInst::EmitToFEIRForOpThrow(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpThrow(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); // obtain in/out types std::vector stackInTypes = op.GetInputTypesFromStack(); ASSERT(stackInTypes.size() == 1, "Not enough input opnds for return op"); @@ -953,10 +927,10 @@ std::list JBCStmtInst::EmitToFEIRForOpThrow(JBCStack2FEHelper &s return ans; } -std::list JBCStmtInst::EmitToFEIRForOpTypeCheck(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpTypeCheck(JBCFunctionContext &context, bool &success) const { std::list ans; + const jbc::JBCConstPool &constPool = context.GetConstPool(); + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); jbc::JBCOpcode opcode = op.GetOpcode(); const jbc::JBCOpTypeCheck &opTypeCheck = static_cast(op); PrimType ptyIn = PTY_ref; @@ -981,10 +955,9 @@ std::list JBCStmtInst::EmitToFEIRForOpTypeCheck(JBCStack2FEHelpe return ans; } -std::list JBCStmtInst::EmitToFEIRForOpMonitor(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpMonitor(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); // stack operation UniqueFEIRVar var = stack2feHelper.PopItem(PTY_ref); if (var == nullptr) { @@ -1003,10 +976,9 @@ std::list JBCStmtInst::EmitToFEIRForOpMonitor(JBCStack2FEHelper return ans; } -std::list JBCStmtInst::EmitToFEIRForOpArrayLength(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRForOpArrayLength(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); // stack operation // in UniqueFEIRVar varArray = stack2feHelper.PopItem(PTY_ref); @@ -1027,10 +999,9 @@ std::list JBCStmtInst::EmitToFEIRForOpArrayLength(JBCStack2FEHel return ans; } -std::list JBCStmtInst::EmitToFEIRCommon(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRCommon(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); std::vector stackInTypes = op.GetInputTypesFromStack(); std::reverse(stackInTypes.begin(), stackInTypes.end()); jbc::JBCPrimType stackOutType = op.GetOutputTypesToStack(); @@ -1052,10 +1023,10 @@ std::list JBCStmtInst::EmitToFEIRCommon(JBCStack2FEHelper &stack return ans; } -std::list JBCStmtInst::EmitToFEIRCommon2(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtInst::EmitToFEIRCommon2(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); + const jbc::JBCConstPool &constPool = context.GetConstPool(); std::vector stackInTypes = op.GetInputTypesFromStack(constPool); std::reverse(stackInTypes.begin(), stackInTypes.end()); jbc::JBCPrimType stackOutType = op.GetOutputTypesToStack(constPool); @@ -1156,12 +1127,13 @@ std::string JBCStmtInstBranch::DumpDotStringImpl() const { return ss.str(); } -std::list JBCStmtInstBranch::EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { - std::list ans; - FATAL(kLncFatal, "should not run here"); - return ans; +std::list JBCStmtInstBranch::EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const { + auto it = funcPtrMapForEmitToFEIR.find(op.GetOpcodeKind()); + if (it != funcPtrMapForEmitToFEIR.end()) { + return (this->*(it->second))(context, success); + } else { + return EmitToFEIRCommon(context, success); + } } JBCStmtPesudoLabel *JBCStmtInstBranch::GetTarget(const std::map &mapPCStmtLabel, @@ -1174,18 +1146,6 @@ JBCStmtPesudoLabel *JBCStmtInstBranch::GetTarget(const std::mapsecond; } -std::list JBCStmtInstBranch::EmitToFEIRWithLabel( - JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { - auto it = funcPtrMapForEmitToFEIR.find(op.GetOpcodeKind()); - if (it != funcPtrMapForEmitToFEIR.end()) { - return (this->*(it->second))(stack2feHelper, mapPCStmtLabel, success); - } else { - return EmitToFEIRCommon(stack2feHelper, mapPCStmtLabel, success); - } -} - std::map JBCStmtInstBranch::InitFuncPtrMapForEmitToFEIR() { std::map ans; ans[jbc::JBCOpcodeKind::kOpKindGoto] = &JBCStmtInstBranch::EmitToFEIRForOpGoto; @@ -1196,11 +1156,9 @@ std::map JBCStmtInstBr return ans; } -std::list JBCStmtInstBranch::EmitToFEIRForOpGoto( - JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { +std::list JBCStmtInstBranch::EmitToFEIRForOpGoto(JBCFunctionContext &context, bool &success) const { std::list ans; + const std::map &mapPCStmtLabel = context.GetMapPCLabelStmt(); const jbc::JBCOpGoto &opGoto = static_cast(op); auto it = mapPCStmtLabel.find(opGoto.GetTarget()); if (it == mapPCStmtLabel.end()) { @@ -1215,11 +1173,10 @@ std::list JBCStmtInstBranch::EmitToFEIRForOpGoto( return ans; } -std::list JBCStmtInstBranch::EmitToFEIRForOpBranch( - JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { +std::list JBCStmtInstBranch::EmitToFEIRForOpBranch(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); + const std::map &mapPCStmtLabel = context.GetMapPCLabelStmt(); const jbc::JBCOpBranch &opBranch = static_cast(op); auto itTarget = mapPCStmtLabel.find(opBranch.GetTarget()); if (itTarget == mapPCStmtLabel.end()) { @@ -1264,11 +1221,10 @@ std::list JBCStmtInstBranch::EmitToFEIRForOpBranch( return ans; } -std::list JBCStmtInstBranch::EmitToFEIRForOpSwitch( - JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { +std::list JBCStmtInstBranch::EmitToFEIRForOpSwitch(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); + const std::map &mapPCStmtLabel = context.GetMapPCLabelStmt(); const jbc::JBCOpSwitch &opSwitch = static_cast(op); UniqueFEIRVar var = stack2feHelper.PopItem(PTY_i32); if (var == nullptr) { @@ -1303,11 +1259,10 @@ std::list JBCStmtInstBranch::EmitToFEIRForOpSwitch( return ans; } -std::list JBCStmtInstBranch::EmitToFEIRForOpJsr( - JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { +std::list JBCStmtInstBranch::EmitToFEIRForOpJsr(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); + const std::map &mapPCStmtLabel = context.GetMapPCLabelStmt(); const jbc::JBCOpJsr &opJsr = static_cast(op); auto itTarget = mapPCStmtLabel.find(opJsr.GetTarget()); if (itTarget == mapPCStmtLabel.end()) { @@ -1319,7 +1274,7 @@ std::list JBCStmtInstBranch::EmitToFEIRForOpJsr( CHECK_NULL_FATAL(stmtLabel); uint32 slotRegNum = stack2feHelper.GetRegNumForSlot(opJsr.GetSlotIdx()); UniqueFEIRVar var = FEIRBuilder::CreateVarReg(slotRegNum, PTY_i32, false); - stack2feHelper.PushItem(var->Clone(), PTY_a32); + (void)stack2feHelper.PushItem(var->Clone(), PTY_a32); UniqueFEIRExpr exprConst = FEIRBuilder::CreateExprConstI32(opJsr.GetJsrID()); UniqueFEIRStmt stmtJsr = FEIRBuilder::CreateStmtDAssign(std::move(var), std::move(exprConst)); UniqueFEIRStmt stmtGoto = FEIRBuilder::CreateStmtGoto(stmtLabel->GetLabelIdx()); @@ -1328,18 +1283,13 @@ std::list JBCStmtInstBranch::EmitToFEIRForOpJsr( return ans; } -std::list JBCStmtInstBranch::EmitToFEIRForOpRet( - JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { - return EmitToFEIRForOpRetImpl(stack2feHelper, mapPCStmtLabel, success); +std::list JBCStmtInstBranch::EmitToFEIRForOpRet(JBCFunctionContext &context, bool &success) const { + return EmitToFEIRForOpRetImpl(context, success); } -std::list JBCStmtInstBranch::EmitToFEIRCommon( - JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { +std::list JBCStmtInstBranch::EmitToFEIRCommon(JBCFunctionContext &context, bool &success) const { std::list ans; + JBCStack2FEHelper &stack2feHelper = context.GetStack2FEHelper(); std::vector stackInTypes = op.GetInputTypesFromStack(); std::reverse(stackInTypes.begin(), stackInTypes.end()); jbc::JBCPrimType stackOutType = op.GetOutputTypesToStack(); @@ -1383,18 +1333,16 @@ std::map> JBCStmtInstBranch::I } // ---------- JBCStmtInstBranchRet ---------- -JBCStmtInstBranchRet::JBCStmtInstBranchRet(const jbc::JBCOp &argOp, - const std::map> &argMapJsrSlotRetAddr) - : JBCStmtInstBranch(argOp), - mapJsrSlotRetAddr(argMapJsrSlotRetAddr) { +JBCStmtInstBranchRet::JBCStmtInstBranchRet(const jbc::JBCOp &argOp) + : JBCStmtInstBranch(argOp) { kind = kJBCStmtInstBranchRet; } -std::list JBCStmtInstBranchRet::EmitToFEIRForOpRetImpl( - JBCStack2FEHelper &stack2feHelper, - const std::map &mapPCStmtLabel, - bool &success) const { +std::list JBCStmtInstBranchRet::EmitToFEIRForOpRetImpl(JBCFunctionContext &context, + bool &success) const { std::list ans; + const std::map &mapPCStmtLabel = context.GetMapPCLabelStmt(); + const std::map> &mapJsrSlotRetAddr = context.GetMapJsrSlotRetAddr(); const jbc::JBCOpRet &opRet = static_cast(op); uint16 slotIdx = opRet.GetIndex(); auto itJsrInfo = mapJsrSlotRetAddr.find(slotIdx); @@ -1454,9 +1402,7 @@ std::string JBCStmtPesudoLabel::DumpDotStringImpl() const { return ss.str(); } -std::list JBCStmtPesudoLabel::EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtPesudoLabel::EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const { std::list ans; UniqueFEIRStmt stmt = std::make_unique(labelIdx); ans.push_back(std::move(stmt)); @@ -1480,9 +1426,7 @@ std::string JBCStmtPesudoCatch::DumpDotStringImpl() const { return ss.str(); } -std::list JBCStmtPesudoCatch::EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtPesudoCatch::EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const { std::list ans; UniqueFEIRStmt stmt = std::make_unique(labelIdx); FEIRStmtPesudoCatch *feirStmt = static_cast(stmt.get()); @@ -1510,9 +1454,7 @@ std::string JBCStmtPesudoTry::DumpDotStringImpl() const { return ss.str(); } -std::list JBCStmtPesudoTry::EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtPesudoTry::EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const { std::list ans; UniqueFEIRStmt stmt = std::make_unique(); FEIRStmtPesudoJavaTry *feirStmt = static_cast(stmt.get()); @@ -1536,9 +1478,7 @@ std::string JBCStmtPesudoEndTry::DumpDotStringImpl() const { return ss.str(); } -std::list JBCStmtPesudoEndTry::EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtPesudoEndTry::EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const { std::list ans; UniqueFEIRStmt stmt = std::make_unique(); ans.push_back(std::move(stmt)); @@ -1553,9 +1493,7 @@ std::string JBCStmtPesudoComment::DumpDotStringImpl() const { return ""; } -std::list JBCStmtPesudoComment::EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtPesudoComment::EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const { std::list ans; UniqueFEIRStmt stmt = std::make_unique(content); ans.push_back(std::move(stmt)); @@ -1573,9 +1511,7 @@ std::string JBCStmtPesudoLOC::DumpDotStringImpl() const { return ss.str(); } -std::list JBCStmtPesudoLOC::EmitToFEIRImpl(JBCStack2FEHelper &stack2feHelper, - const jbc::JBCConstPool &constPool, - bool &success) const { +std::list JBCStmtPesudoLOC::EmitToFEIRImpl(JBCFunctionContext &context, bool &success) const { std::list ans; return ans; }