From ca75461829572b8eb63688083c82597db6c69c6c Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Sun, 22 May 2022 21:17:42 -0700 Subject: [PATCH] Moved the lowering of icall to icallproto from LMBCLowerer to MIRLower, so icallproto is exposed to mplme and mplcg even in non-lmbc compiles This is only done when language is C. This also means icallprotoassigned needs to be added as a new opcode. Made all the mplme and lowering phases handle icallproto. --- src/mapleall/maple_be/src/be/lower.cpp | 27 +++-- .../src/cg/aarch64/aarch64_cgfunc.cpp | 11 +- src/mapleall/maple_be/src/cg/memlayout.cpp | 6 +- .../maple_ir/include/ir_safe_cast_traits.def | 4 +- src/mapleall/maple_ir/include/mir_builder.h | 2 + src/mapleall/maple_ir/include/mir_lower.h | 1 + src/mapleall/maple_ir/include/mir_nodes.h | 2 +- src/mapleall/maple_ir/include/mir_parser.h | 1 + src/mapleall/maple_ir/include/opcode_info.h | 1 + src/mapleall/maple_ir/include/opcodes.def | 1 + src/mapleall/maple_ir/include/opcodes.h | 4 +- src/mapleall/maple_ir/src/bin_func_export.cpp | 1 + src/mapleall/maple_ir/src/bin_func_import.cpp | 1 + src/mapleall/maple_ir/src/mir_builder.cpp | 24 ++++ src/mapleall/maple_ir/src/mir_lower.cpp | 107 +++++++++++++++++ src/mapleall/maple_ir/src/mir_nodes.cpp | 4 +- src/mapleall/maple_ir/src/mir_parser.cpp | 14 ++- src/mapleall/maple_me/include/lmbc_lower.h | 1 - src/mapleall/maple_me/src/alias_class.cpp | 8 +- src/mapleall/maple_me/src/code_factoring.cpp | 4 +- .../src/demand_driven_alias_analysis.cpp | 4 +- src/mapleall/maple_me/src/irmap_build.cpp | 7 +- src/mapleall/maple_me/src/irmap_emit.cpp | 5 +- src/mapleall/maple_me/src/lfo_dep_test.cpp | 2 + src/mapleall/maple_me/src/lmbc_lower.cpp | 108 ++---------------- src/mapleall/maple_me/src/me_cfg.cpp | 2 + src/mapleall/maple_me/src/me_function.cpp | 4 +- .../maple_me/src/me_lower_globals.cpp | 13 ++- src/mapleall/maple_me/src/me_rename2preg.cpp | 1 + src/mapleall/maple_me/src/me_side_effect.cpp | 4 +- src/mapleall/maple_me/src/me_stmt_pre.cpp | 4 +- src/mapleall/maple_me/src/pme_emit.cpp | 9 +- src/mapleall/maple_me/src/ssa_devirtual.cpp | 4 +- src/mapleall/maple_me/src/ssa_pre.cpp | 2 + src/mapleall/mpl2mpl/src/constantfold.cpp | 6 +- 35 files changed, 262 insertions(+), 137 deletions(-) diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index 0a37734957..7aa697f714 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -1100,7 +1100,7 @@ void CGLowerer::LowerCallStmt(StmtNode &stmt, StmtNode *&nextStmt, BlockNode &ne return; } - if ((newStmt->GetOpCode() == OP_call) || (newStmt->GetOpCode() == OP_icall)) { + if (newStmt->GetOpCode() == OP_call || newStmt->GetOpCode() == OP_icall || newStmt->GetOpCode() == OP_icallproto) { newStmt = LowerCall(static_cast(*newStmt), nextStmt, newBlk, retty, uselvar); } newStmt->SetSrcPos(stmt.GetSrcPos()); @@ -1171,7 +1171,12 @@ StmtNode *CGLowerer::GenIntrinsiccallNode(const StmtNode &stmt, PUIdx &funcCalle StmtNode *CGLowerer::GenIcallNode(PUIdx &funcCalled, IcallNode &origCall) { StmtNode *newCall = nullptr; - newCall = mirModule.GetMIRBuilder()->CreateStmtIcall(origCall.GetNopnd()); + if (origCall.GetOpCode() == OP_icallassigned) { + newCall = mirModule.GetMIRBuilder()->CreateStmtIcall(origCall.GetNopnd()); + } else { + newCall = mirModule.GetMIRBuilder()->CreateStmtIcallproto(origCall.GetNopnd()); + static_cast(newCall)->SetRetTyIdx(static_cast(origCall).GetRetTyIdx()); + } newCall->SetSrcPos(origCall.GetSrcPos()); CHECK_FATAL(newCall != nullptr, "nullptr is not expected"); funcCalled = kFuncNotFound; @@ -1372,6 +1377,7 @@ BlockNode *CGLowerer::LowerCallAssignedStmt(StmtNode &stmt, bool uselvar) { static_cast(newCall)->SetReturnVec(*p2nRets); break; } + case OP_icallprotoassigned: case OP_icallassigned: { auto &origCall = static_cast(stmt); newCall = GenIcallNode(funcCalled, origCall); @@ -1495,13 +1501,18 @@ bool CGLowerer::LowerStructReturn(BlockNode &newBlk, StmtNode *stmt, CallNode *callStmt = mirModule.GetMIRBuilder()->CreateStmtCall(callNode->GetPUIdx(), callNode->GetNopnd()); callStmt->SetSrcPos(callNode->GetSrcPos()); newBlk.AddStatement(callStmt); - } else if (stmt->GetOpCode() == OP_icallassigned) { + } else if (stmt->GetOpCode() == OP_icallassigned || stmt->GetOpCode() == OP_icallprotoassigned) { auto *icallNode = static_cast(stmt); for (size_t i = 0; i < icallNode->GetNopndSize(); ++i) { BaseNode *newOpnd = LowerExpr(*icallNode, *icallNode->GetNopndAt(i), newBlk); icallNode->SetOpnd(newOpnd, i); } - IcallNode *icallStmt = mirModule.GetMIRBuilder()->CreateStmtIcall(icallNode->GetNopnd()); + IcallNode *icallStmt = nullptr; + if (stmt->GetOpCode() == OP_icallassigned) { + mirModule.GetMIRBuilder()->CreateStmtIcall(icallNode->GetNopnd()); + } else { + mirModule.GetMIRBuilder()->CreateStmtIcallproto(icallNode->GetNopnd()); + } icallStmt->SetSrcPos(icallNode->GetSrcPos()); newBlk.AddStatement(icallStmt); } else { @@ -1840,7 +1851,8 @@ BlockNode *CGLowerer::LowerBlock(BlockNode &block) { break; } case OP_callassigned: - case OP_icallassigned: { + case OP_icallassigned: + case OP_icallprotoassigned: { // pass the addr of lvar if this is a struct call assignment bool lvar = false; if (LowerStructReturn(*newBlk, stmt, nextStmt, lvar, &block)) { @@ -1861,6 +1873,7 @@ BlockNode *CGLowerer::LowerBlock(BlockNode &block) { case OP_intrinsiccall: case OP_call: case OP_icall: + case OP_icallproto: #if TARGARM32 || TARGAARCH64 || TARGRISCV64 || TARGX86_64 LowerCallStmt(*stmt, nextStmt, *newBlk); #else @@ -2104,7 +2117,7 @@ StmtNode *CGLowerer::LowerCall( } MIRType *retType = nullptr; - if (callNode.op == OP_icall) { + if (callNode.op == OP_icall || callNode.op == OP_icallproto) { if (retTy == nullptr) { return &callNode; } else { @@ -2150,7 +2163,7 @@ StmtNode *CGLowerer::LowerCall( addrofNode->SetStIdx(dsgnSt->GetStIdx()); addrofNode->SetFieldID(0); - if (callNode.op == OP_icall) { + if (callNode.op == OP_icall || callNode.op == OP_icallproto) { auto ond = callNode.GetNopnd().begin(); newNopnd.emplace_back(*ond); newNopnd.emplace_back(addrofNode); diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 63a9cab4c3..4e56498e0e 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -7655,7 +7655,7 @@ void AArch64CGFunc::SelectParmListPreprocess(const StmtNode &naryNode, size_t st */ void AArch64CGFunc::SelectParmList(StmtNode &naryNode, ListOperand &srcOpnds, bool isCallNative) { size_t i = 0; - if ((naryNode.GetOpCode() == OP_icall) || isCallNative) { + if (naryNode.GetOpCode() == OP_icall || naryNode.GetOpCode() == OP_icallproto || isCallNative) { i++; } SelectParmListPreprocess(naryNode, i); @@ -7670,8 +7670,11 @@ void AArch64CGFunc::SelectParmList(StmtNode &naryNode, ListOperand &srcOpnds, bo BaseNode *argExpr = naryNode.Opnd(i); PrimType primType = argExpr->GetPrimType(); ASSERT(primType != PTY_void, "primType should not be void"); - auto calleePuIdx = static_cast(naryNode).GetPUIdx(); - auto *callee = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(calleePuIdx); + MIRFunction *callee = nullptr; + if (dynamic_cast(&naryNode) != nullptr) { + auto calleePuIdx = static_cast(naryNode).GetPUIdx(); + callee = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(calleePuIdx); + } if (callee != nullptr && pnum < callee->GetFormalCount() && callee->GetFormal(pnum) != nullptr) { is64x1vec = callee->GetFormal(pnum)->GetAttr(ATTR_oneelem_simd); } @@ -8276,7 +8279,7 @@ void AArch64CGFunc::SelectIcall(IcallNode &icallNode, Operand &srcOpnd) { RegOperand *regOpnd = static_cast(fptrOpnd); Insn &callInsn = GetCG()->BuildInstruction(MOP_xblr, *regOpnd, *srcOpnds); - MIRType *retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(icallNode.GetRetTyIdx()); + MIRType *retType = icallNode.GetCallReturnType(); if (retType != nullptr) { callInsn.SetRetSize(static_cast(retType->GetSize())); callInsn.SetIsCallReturnUnsigned(IsUnsignedInteger(retType->GetPrimType())); diff --git a/src/mapleall/maple_be/src/cg/memlayout.cpp b/src/mapleall/maple_be/src/cg/memlayout.cpp index 57e45e8a2d..1b636207c6 100644 --- a/src/mapleall/maple_be/src/cg/memlayout.cpp +++ b/src/mapleall/maple_be/src/cg/memlayout.cpp @@ -38,7 +38,7 @@ uint32 MemLayout::FindLargestActualArea(int32 &aggCopySize) { uint32 maxCopyStackSize = 0; // Size of aggregate param stack copy requirement for (; stmt != nullptr; stmt = stmt->GetNext()) { Opcode opCode = stmt->GetOpCode(); - if (opCode < OP_call || opCode > OP_xintrinsiccallassigned) { + if ((opCode < OP_call || opCode > OP_xintrinsiccallassigned) && opCode != OP_icallproto) { continue; } if (opCode == OP_intrinsiccallwithtypeassigned || opCode == OP_intrinsiccallwithtype || @@ -54,9 +54,9 @@ uint32 MemLayout::FindLargestActualArea(int32 &aggCopySize) { * if the following check fails, most likely dex has invoke-custom etc * that is not supported yet */ - DCHECK((opCode == OP_call || opCode == OP_icall), "Not lowered to call or icall?"); + DCHECK((opCode == OP_call || opCode == OP_icall || opCode == OP_icallproto), "Not lowered to call or icall?"); int32 copySize; - uint32 size = ComputeStackSpaceRequirementForCall(*stmt, copySize, opCode == OP_icall); + uint32 size = ComputeStackSpaceRequirementForCall(*stmt, copySize, opCode == OP_icall || opCode == OP_icallproto); if (size > maxParamStackSize) { maxParamStackSize = size; } diff --git a/src/mapleall/maple_ir/include/ir_safe_cast_traits.def b/src/mapleall/maple_ir/include/ir_safe_cast_traits.def index 1439b49d57..14ed1a367b 100644 --- a/src/mapleall/maple_ir/include/ir_safe_cast_traits.def +++ b/src/mapleall/maple_ir/include/ir_safe_cast_traits.def @@ -224,7 +224,9 @@ REGISTER_SAFE_CAST(CallNode, from.GetOpCode() == OP_call || from.GetOpCode() == OP_virtualicallassigned || instance_of(from)); REGISTER_SAFE_CAST(IcallNode, from.GetOpCode() == OP_icall || - from.GetOpCode() == OP_icallassigned); + from.GetOpCode() == OP_icallassigned || + from.GetOpCode() == OP_icallproto || + from.GetOpCode() == OP_icallprotoassigned); REGISTER_SAFE_CAST(IntrinsiccallNode, from.GetOpCode() == OP_intrinsiccall || from.GetOpCode() == OP_intrinsiccallwithtype || from.GetOpCode() == OP_xintrinsiccall || diff --git a/src/mapleall/maple_ir/include/mir_builder.h b/src/mapleall/maple_ir/include/mir_builder.h index ac3215724e..64f6a2723c 100755 --- a/src/mapleall/maple_ir/include/mir_builder.h +++ b/src/mapleall/maple_ir/include/mir_builder.h @@ -262,6 +262,8 @@ class MIRBuilder { IcallNode *CreateStmtIcall(const MapleVector &args); IcallNode *CreateStmtIcallAssigned(const MapleVector &args, const MIRSymbol &ret); + IcallNode *CreateStmtIcallproto(const MapleVector &args); + IcallNode *CreateStmtIcallprotoAssigned(const MapleVector &args, const MIRSymbol &ret); // For Call, VirtualCall, SuperclassCall, InterfaceCall IntrinsiccallNode *CreateStmtIntrinsicCall(MIRIntrinsicID idx, const MapleVector &arguments, TyIdx tyIdx = TyIdx()); diff --git a/src/mapleall/maple_ir/include/mir_lower.h b/src/mapleall/maple_ir/include/mir_lower.h index 332a6de89f..be479f65a6 100644 --- a/src/mapleall/maple_ir/include/mir_lower.h +++ b/src/mapleall/maple_ir/include/mir_lower.h @@ -86,6 +86,7 @@ class MIRLower { ForeachelemNode *ExpandArrayMrtForeachelemBlock(ForeachelemNode &node); BlockNode *ExpandArrayMrtBlock(BlockNode &block); void AddArrayMrtMpl(BaseNode &exp, BlockNode &newblk); + MIRFuncType *FuncTypeFromFuncPtrExpr(BaseNode *x); void SetLowerME() { lowerPhase |= kShiftLowerMe; } diff --git a/src/mapleall/maple_ir/include/mir_nodes.h b/src/mapleall/maple_ir/include/mir_nodes.h index f782bdc03b..de813522e6 100755 --- a/src/mapleall/maple_ir/include/mir_nodes.h +++ b/src/mapleall/maple_ir/include/mir_nodes.h @@ -3303,7 +3303,7 @@ class CallNode : public NaryStmtNode { CallReturnVector returnValues; }; -// icall and icallproto +// icall, icallassigned, icallproto and icallprotoassigned class IcallNode : public NaryStmtNode { public: IcallNode(MapleAllocator &allocator, Opcode o) diff --git a/src/mapleall/maple_ir/include/mir_parser.h b/src/mapleall/maple_ir/include/mir_parser.h index d05c844f31..3b9a688a58 100755 --- a/src/mapleall/maple_ir/include/mir_parser.h +++ b/src/mapleall/maple_ir/include/mir_parser.h @@ -129,6 +129,7 @@ class MIRParser { bool ParseStmtIcall(StmtNodePtr&); bool ParseStmtIcallassigned(StmtNodePtr&); bool ParseStmtIcallproto(StmtNodePtr&); + bool ParseStmtIcallprotoassigned(StmtNodePtr&); bool ParseStmtIntrinsiccall(StmtNodePtr&, bool isAssigned); bool ParseStmtIntrinsiccall(StmtNodePtr&); bool ParseStmtIntrinsiccallassigned(StmtNodePtr&); diff --git a/src/mapleall/maple_ir/include/opcode_info.h b/src/mapleall/maple_ir/include/opcode_info.h index 814f15b2f2..5a82646b11 100644 --- a/src/mapleall/maple_ir/include/opcode_info.h +++ b/src/mapleall/maple_ir/include/opcode_info.h @@ -117,6 +117,7 @@ class OpcodeTable { bool IsICall(Opcode o) const { ASSERT(o < OP_last, "invalid opcode"); return o == OP_icall || o == OP_icallassigned || + o == OP_icallproto || o == OP_icallprotoassigned || o == OP_virtualicall || o == OP_virtualicallassigned || o == OP_interfaceicall || o == OP_interfaceicallassigned; } diff --git a/src/mapleall/maple_ir/include/opcodes.def b/src/mapleall/maple_ir/include/opcodes.def index 34cfb51c8d..0e842141ed 100755 --- a/src/mapleall/maple_ir/include/opcodes.def +++ b/src/mapleall/maple_ir/include/opcodes.def @@ -221,3 +221,4 @@ OPCODE(iassignspoff, IassignFPoffNode, OPCODEISSTMT, 8) OPCODE(blkassignoff, BlkassignoffNode, OPCODEISSTMT, 8) OPCODE(icallproto, IcallNode, (OPCODEISSTMT | OPCODEISVARSIZE | OPCODEHASSSAUSE | OPCODEHASSSADEF | OPCODEISCALL), 8) + OPCODE(icallprotoassigned, IcallNode, (OPCODEISSTMT | OPCODEISVARSIZE | OPCODEHASSSAUSE | OPCODEHASSSADEF | OPCODEISCALL | OPCODEISCALLASSIGNED), 8) diff --git a/src/mapleall/maple_ir/include/opcodes.h b/src/mapleall/maple_ir/include/opcodes.h index ea4ed2c1c9..b9f5e0f8c5 100644 --- a/src/mapleall/maple_ir/include/opcodes.h +++ b/src/mapleall/maple_ir/include/opcodes.h @@ -50,7 +50,7 @@ inline constexpr bool IsCallAssigned(Opcode code) { code == OP_virtualicallassigned || code == OP_superclasscallassigned || code == OP_interfacecallassigned || code == OP_interfaceicallassigned || code == OP_customcallassigned || code == OP_polymorphiccallassigned || - code == OP_icallassigned || code == OP_intrinsiccallassigned || + code == OP_icallassigned || code == OP_icallprotoassigned || code == OP_intrinsiccallassigned || code == OP_xintrinsiccallassigned || code == OP_intrinsiccallwithtypeassigned); } @@ -113,6 +113,8 @@ constexpr bool IsStmtMustRequire(Opcode opcode) { case OP_polymorphiccallassigned: case OP_icall: case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: case OP_intrinsiccall: case OP_xintrinsiccall: case OP_intrinsiccallassigned: diff --git a/src/mapleall/maple_ir/src/bin_func_export.cpp b/src/mapleall/maple_ir/src/bin_func_export.cpp index 5117ed8ed0..12a7fdf0f6 100644 --- a/src/mapleall/maple_ir/src/bin_func_export.cpp +++ b/src/mapleall/maple_ir/src/bin_func_export.cpp @@ -500,6 +500,7 @@ void BinaryMplExport::OutputBlockNode(BlockNode *block) { WriteNum(static_cast(s->NumOpnds())); break; } + case OP_icallprotoassigned: case OP_icallassigned: { IcallNode *icallnode = static_cast(s); OutputTypeViaTypeName(icallnode->GetRetTyIdx()); diff --git a/src/mapleall/maple_ir/src/bin_func_import.cpp b/src/mapleall/maple_ir/src/bin_func_import.cpp index d18aac9f58..d2ad3cb789 100644 --- a/src/mapleall/maple_ir/src/bin_func_import.cpp +++ b/src/mapleall/maple_ir/src/bin_func_import.cpp @@ -644,6 +644,7 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { stmt = s; break; } + case OP_icallprotoassigned: case OP_icallassigned: { IcallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetRetTyIdx(ImportType()); diff --git a/src/mapleall/maple_ir/src/mir_builder.cpp b/src/mapleall/maple_ir/src/mir_builder.cpp index 20d46306c0..f1aa2583e4 100755 --- a/src/mapleall/maple_ir/src/mir_builder.cpp +++ b/src/mapleall/maple_ir/src/mir_builder.cpp @@ -835,6 +835,13 @@ IcallNode *MIRBuilder::CreateStmtIcall(const MapleVector &args) { return stmt; } +IcallNode *MIRBuilder::CreateStmtIcallproto(const MapleVector &args) { + auto *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), OP_icallproto); + ASSERT(stmt != nullptr, "stmt is null"); + stmt->SetOpnds(args); + return stmt; +} + IcallNode *MIRBuilder::CreateStmtIcallAssigned(const MapleVector &args, const MIRSymbol &ret) { auto *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), OP_icallassigned); CallReturnVector nrets(GetCurrentFuncCodeMpAllocator()->Adapter()); @@ -852,6 +859,23 @@ IcallNode *MIRBuilder::CreateStmtIcallAssigned(const MapleVector &arg return stmt; } +IcallNode *MIRBuilder::CreateStmtIcallprotoAssigned(const MapleVector &args, const MIRSymbol &ret) { + auto *stmt = GetCurrentFuncCodeMp()->New(*GetCurrentFuncCodeMpAllocator(), OP_icallprotoassigned); + CallReturnVector nrets(GetCurrentFuncCodeMpAllocator()->Adapter()); + CHECK_FATAL((ret.GetStorageClass() == kScAuto || ret.GetStorageClass() == kScFormal || + ret.GetStorageClass() == kScExtern || ret.GetStorageClass() == kScGlobal), + "unknown classtype! check it!"); + nrets.emplace_back(CallReturnPair(ret.GetStIdx(), RegFieldPair(0, 0))); + stmt->SetNumOpnds(args.size()); + stmt->GetNopnd().resize(stmt->GetNumOpnds()); + stmt->SetReturnVec(nrets); + for (size_t i = 0; i < stmt->GetNopndSize(); ++i) { + stmt->SetNOpndAt(i, args.at(i)); + } + stmt->SetRetTyIdx(ret.GetTyIdx()); + return stmt; +} + IntrinsiccallNode *MIRBuilder::CreateStmtIntrinsicCall(MIRIntrinsicID idx, const MapleVector &arguments, TyIdx tyIdx) { auto *stmt = GetCurrentFuncCodeMp()->New( diff --git a/src/mapleall/maple_ir/src/mir_lower.cpp b/src/mapleall/maple_ir/src/mir_lower.cpp index 99dbd04c3f..aa5cb0131c 100644 --- a/src/mapleall/maple_ir/src/mir_lower.cpp +++ b/src/mapleall/maple_ir/src/mir_lower.cpp @@ -530,6 +530,19 @@ BlockNode *MIRLower::LowerBlock(BlockNode &block) { case OP_doloop: newBlock->AppendStatementsFromBlock(*LowerDoloopStmt(static_cast(*stmt))); break; + case OP_icallassigned: + case OP_icall: { + if (mirModule.IsCModule()) { + // convert to icallproto/icallprotoassigned + IcallNode *ic = static_cast(stmt); + ic->SetOpCode(stmt->GetOpCode() == OP_icall ? OP_icallproto : OP_icallprotoassigned); + MIRFuncType *funcType = FuncTypeFromFuncPtrExpr(stmt->Opnd(0)); + CHECK_FATAL(funcType != nullptr, "MIRLower::LowerBlock: cannot find prototype for icall"); + ic->SetRetTyIdx(funcType->GetTypeIndex()); + } + newBlock->AddStatement(stmt); + break; + } case OP_block: tmp = LowerBlock(static_cast(*stmt)); newBlock->AppendStatementsFromBlock(*tmp); @@ -985,6 +998,100 @@ void MIRLower::ExpandArrayMrt(MIRFunction &func) { } } +MIRFuncType *MIRLower::FuncTypeFromFuncPtrExpr(BaseNode *x) { + MIRFuncType *res = nullptr; + MIRFunction *func = mirModule.CurFunction(); + switch (x->GetOpCode()) { + case OP_regread: { + RegreadNode *regread = static_cast(x); + MIRPreg *preg = func->GetPregTab()->PregFromPregIdx(regread->GetRegIdx()); + // see if it is promoted from a symbol + if (preg->GetOp() == OP_dread) { + const MIRSymbol *symbol = preg->rematInfo.sym; + MIRType *mirType = symbol->GetType(); + if (preg->fieldID != 0) { + MIRStructType *structty = static_cast(mirType); + FieldPair thepair = structty->TraverseToField(preg->fieldID); + mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); + } + + if (mirType->GetKind() == kTypePointer) { + res = static_cast(mirType)->GetPointedFuncType(); + } + if (res != nullptr) { + break; + } + } + // check if a formal promoted to preg + for (FormalDef &formalDef : func->GetFormalDefVec()) { + if (!formalDef.formalSym->IsPreg()) { + continue; + } + if (formalDef.formalSym->GetPreg() == preg) { + MIRType *mirType = formalDef.formalSym->GetType(); + if (mirType->GetKind() == kTypePointer) { + res = static_cast(mirType)->GetPointedFuncType(); + } + break; + } + } + break; + } + case OP_dread: { + DreadNode *dread = static_cast(x); + MIRSymbol *symbol = func->GetLocalOrGlobalSymbol(dread->GetStIdx()); + MIRType *mirType = symbol->GetType(); + if (dread->GetFieldID() != 0) { + MIRStructType *structty = static_cast(mirType); + FieldPair thepair = structty->TraverseToField(dread->GetFieldID()); + mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); + } + if (mirType->GetKind() == kTypePointer) { + res = static_cast(mirType)->GetPointedFuncType(); + } + break; + } + case OP_iread: { + IreadNode *iread = static_cast(x); + MIRPtrType *ptrType = static_cast(iread->GetType()); + MIRType *mirType = ptrType->GetPointedType(); + if (mirType->GetKind() == kTypeFunction) { + res = static_cast(mirType); + } else if (mirType->GetKind() == kTypePointer) { + res = static_cast(mirType)->GetPointedFuncType(); + } + break; + } + case OP_addroffunc: { + AddroffuncNode *addrofFunc = static_cast(x); + PUIdx puIdx = addrofFunc->GetPUIdx(); + MIRFunction *f = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puIdx); + res = f->GetMIRFuncType(); + break; + } + case OP_retype: { + MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx( + static_cast(x)->GetTyIdx()); + if (mirType->GetKind() == kTypePointer) { + res = static_cast(mirType)->GetPointedFuncType(); + } + if (res == nullptr) { + res = FuncTypeFromFuncPtrExpr(x->Opnd(0)); + } + break; + } + case OP_select: { + res = FuncTypeFromFuncPtrExpr(x->Opnd(1)); + if (res == nullptr) { + res = FuncTypeFromFuncPtrExpr(x->Opnd(2)); + } + break; + } + default: CHECK_FATAL(false, "LMBCLowerer::FuncTypeFromFuncPtrExpr: NYI"); + } + return res; +} + const std::set MIRLower::kSetArrayHotFunc = {}; bool MIRLower::ShouldOptArrayMrt(const MIRFunction &func) { diff --git a/src/mapleall/maple_ir/src/mir_nodes.cpp b/src/mapleall/maple_ir/src/mir_nodes.cpp index 573346e739..30d77f2775 100755 --- a/src/mapleall/maple_ir/src/mir_nodes.cpp +++ b/src/mapleall/maple_ir/src/mir_nodes.cpp @@ -1198,7 +1198,7 @@ MIRType *IcallNode::GetCallReturnType() { if (op == OP_icall || op == OP_icallassigned) { return GlobalTables::GetTypeTable().GetTypeFromTyIdx(retTyIdx); } - // icallproto + // icallproto or icallprotoassigned MIRFuncType *funcType = static_cast( GlobalTables::GetTypeTable().GetTypeFromTyIdx(retTyIdx)); return GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcType->GetRetTyIdx()); @@ -1223,7 +1223,7 @@ const MIRSymbol *IcallNode::GetCallReturnSymbol(const MIRModule &mod) const { void IcallNode::Dump(int32 indent, bool newline) const { StmtNode::DumpBase(indent); - if (op == OP_icallproto) { + if (op == OP_icallproto || op == OP_icallprotoassigned) { LogInfo::MapleLogger() << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(retTyIdx)->Dump(indent + 1); } diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index b4bf8cf4ce..9ec14e0a63 100755 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -930,9 +930,14 @@ bool MIRParser::ParseStmtIcall(StmtNodePtr &stmt, Opcode op) { // . . . // dassign } // icallproto (, , ..., ) + // icallprotoassigned (, , ..., ) { + // dassign + // dassign + // . . . + // dassign } IcallNode *iCallStmt = mod.CurFuncCodeMemPool()->New(mod, op); lexer.NextToken(); - if (op == OP_icallproto) { + if (op == OP_icallproto || op == OP_icallprotoassigned) { TyIdx tyIdx(0); if (!ParseDerivedType(tyIdx)) { Error("error parsing type in ParseStmtIcall for icallproto at "); @@ -946,7 +951,7 @@ bool MIRParser::ParseStmtIcall(StmtNodePtr &stmt, Opcode op) { } iCallStmt->SetNOpnd(opndsVec); iCallStmt->SetNumOpnds(opndsVec.size()); - if (op == OP_icallassigned) { + if (op == OP_icallassigned || op == OP_icallprotoassigned) { CallReturnVector retsVec(mod.CurFuncCodeMemPoolAllocator()->Adapter()); if (!ParseCallReturns(retsVec)) { return false; @@ -970,6 +975,10 @@ bool MIRParser::ParseStmtIcallproto(StmtNodePtr &stmt) { return ParseStmtIcall(stmt, OP_icallproto); } +bool MIRParser::ParseStmtIcallprotoassigned(StmtNodePtr &stmt) { + return ParseStmtIcall(stmt, OP_icallprotoassigned); +} + bool MIRParser::ParseStmtIntrinsiccall(StmtNodePtr &stmt, bool isAssigned) { Opcode o = !isAssigned ? (lexer.GetTokenKind() == TK_intrinsiccall ? OP_intrinsiccall : OP_xintrinsiccall) : (lexer.GetTokenKind() == TK_intrinsiccallassigned ? OP_intrinsiccallassigned @@ -3404,6 +3413,7 @@ std::map MIRParser::InitFuncPtrMapForPar funcPtrMap[TK_icall] = &MIRParser::ParseStmtIcall; funcPtrMap[TK_icallassigned] = &MIRParser::ParseStmtIcallassigned; funcPtrMap[TK_icallproto] = &MIRParser::ParseStmtIcallproto; + funcPtrMap[TK_icallprotoassigned] = &MIRParser::ParseStmtIcallprotoassigned; funcPtrMap[TK_intrinsiccall] = &MIRParser::ParseStmtIntrinsiccall; funcPtrMap[TK_intrinsiccallassigned] = &MIRParser::ParseStmtIntrinsiccallassigned; funcPtrMap[TK_xintrinsiccall] = &MIRParser::ParseStmtIntrinsiccall; diff --git a/src/mapleall/maple_me/include/lmbc_lower.h b/src/mapleall/maple_me/include/lmbc_lower.h index 9462204fd7..ce8ede27c6 100644 --- a/src/mapleall/maple_me/include/lmbc_lower.h +++ b/src/mapleall/maple_me/include/lmbc_lower.h @@ -40,7 +40,6 @@ class LMBCLowerer { void LowerIassign(IassignNode *, BlockNode *); void LowerAggIassign(IassignNode *, MIRType *type, int32 offset, BlockNode *); void LowerReturn(NaryStmtNode *retNode, BlockNode *newblk); - MIRFuncType *FuncTypeFromFuncPtrExpr(BaseNode *x); void LowerCall(NaryStmtNode *callNode, BlockNode *newblk); BlockNode *LowerBlock(BlockNode *); void LoadFormalsAssignedToPregs(); diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index cad15495dd..a7ba5ee299 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -1017,7 +1017,9 @@ void AliasClass::ApplyUnionForCopies(StmtNode &stmt) { } case OP_asm: case OP_icall: - case OP_icallassigned: { + case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: { for (uint32 i = 0; i < stmt.NumOpnds(); ++i) { const AliasInfo &ainfo = CreateAliasInfoExpr(*stmt.Opnd(i)); if (stmt.GetOpCode() != OP_asm && i == 0) { @@ -2563,6 +2565,7 @@ void AliasClass::GenericInsertMayDefUse(StmtNode &stmt, BBId bbID) { case OP_customcallassigned: case OP_polymorphiccallassigned: case OP_icallassigned: + case OP_icallprotoassigned: case OP_virtualcall: case OP_virtualicall: case OP_superclasscall: @@ -2570,7 +2573,8 @@ void AliasClass::GenericInsertMayDefUse(StmtNode &stmt, BBId bbID) { case OP_interfaceicall: case OP_customcall: case OP_polymorphiccall: - case OP_icall: { + case OP_icall: + case OP_icallproto: { InsertMayDefUseCall(stmt, bbID, false); return; } diff --git a/src/mapleall/maple_me/src/code_factoring.cpp b/src/mapleall/maple_me/src/code_factoring.cpp index 6cabb59adc..2f40e7b821 100644 --- a/src/mapleall/maple_me/src/code_factoring.cpp +++ b/src/mapleall/maple_me/src/code_factoring.cpp @@ -122,7 +122,9 @@ bool FactoringOptimizer::IsIdenticalStmt(StmtNode *stmt1, StmtNode *stmt2) { break; } case OP_icall: - case OP_icallassigned: { + case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: { auto *icall1 = static_cast(stmt1); auto *icall2 = static_cast(stmt2); if (icall1->GetRetTyIdx() != icall2->GetRetTyIdx() || diff --git a/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp b/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp index 97c3057661..f9bf87a81d 100644 --- a/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp +++ b/src/mapleall/maple_me/src/demand_driven_alias_analysis.cpp @@ -641,7 +641,9 @@ void PEGBuilder::BuildPEGNodeInStmt(const StmtNode *stmt) { break; } case OP_icall: - case OP_icallassigned: { + case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: { BuildPEGNodeInIcall(static_cast(stmt)); break; } diff --git a/src/mapleall/maple_me/src/irmap_build.cpp b/src/mapleall/maple_me/src/irmap_build.cpp index de0f996965..4d070cfa22 100755 --- a/src/mapleall/maple_me/src/irmap_build.cpp +++ b/src/mapleall/maple_me/src/irmap_build.cpp @@ -795,7 +795,7 @@ MeStmt *IRMapBuild::BuildCallMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { MeStmt *IRMapBuild::BuildNaryMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { Opcode op = stmt.GetOpCode(); - NaryMeStmt *naryMeStmt = (op == OP_icall || op == OP_icallassigned) + NaryMeStmt *naryMeStmt = (op == OP_icall || op == OP_icallassigned || op == OP_icallproto || op == OP_icallprotoassigned) ? static_cast(irMap->NewInPool(&stmt)) : static_cast(irMap->NewInPool(&stmt)); auto &naryStmtNode = static_cast(stmt); @@ -810,6 +810,9 @@ MeStmt *IRMapBuild::BuildNaryMeStmt(StmtNode &stmt, AccessSSANodes &ssaPart) { if (propagater) { propagater->PropUpdateChiListDef(*naryMeStmt->GetChiList()); } + if (op == OP_icallproto || op == OP_icallprotoassigned) { + static_cast(naryMeStmt)->SetRetTyIdx(static_cast(stmt).GetRetTyIdx()); + } return naryMeStmt; } @@ -910,6 +913,8 @@ void IRMapBuild::InitMeStmtFactory() { RegisterFactoryFunction(OP_polymorphiccallassigned, &IRMapBuild::BuildCallMeStmt); RegisterFactoryFunction(OP_icall, &IRMapBuild::BuildNaryMeStmt); RegisterFactoryFunction(OP_icallassigned, &IRMapBuild::BuildNaryMeStmt); + RegisterFactoryFunction(OP_icallproto, &IRMapBuild::BuildNaryMeStmt); + RegisterFactoryFunction(OP_icallprotoassigned, &IRMapBuild::BuildNaryMeStmt); RegisterFactoryFunction(OP_intrinsiccall, &IRMapBuild::BuildNaryMeStmt); RegisterFactoryFunction(OP_xintrinsiccall, &IRMapBuild::BuildNaryMeStmt); RegisterFactoryFunction(OP_intrinsiccallwithtype, &IRMapBuild::BuildNaryMeStmt); diff --git a/src/mapleall/maple_me/src/irmap_emit.cpp b/src/mapleall/maple_me/src/irmap_emit.cpp index 824e7c7e53..7fcbd3804b 100755 --- a/src/mapleall/maple_me/src/irmap_emit.cpp +++ b/src/mapleall/maple_me/src/irmap_emit.cpp @@ -412,7 +412,7 @@ MIRFunction &CallMeStmt::GetTargetFunction() { } StmtNode &CallMeStmt::EmitStmt(SSATab &ssaTab) { - if (GetOp() != OP_icall && GetOp() != OP_icallassigned) { + if (GetOp() != OP_icall && GetOp() != OP_icallassigned && GetOp() != OP_icallproto && GetOp() != OP_icallprotoassigned) { auto *callNode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(ssaTab.GetModule(), Opcode(GetOp())); callNode->SetPUIdx(puIdx); @@ -496,6 +496,9 @@ StmtNode &IcallMeStmt::EmitStmt(SSATab &ssaTab) { } } } + if (GetOp() == OP_icallproto || GetOp() == OP_icallprotoassigned) { + icallNode->SetRetTyIdx(retTyIdx); + } return *icallNode; } diff --git a/src/mapleall/maple_me/src/lfo_dep_test.cpp b/src/mapleall/maple_me/src/lfo_dep_test.cpp index 19a523e138..ac3340e843 100644 --- a/src/mapleall/maple_me/src/lfo_dep_test.cpp +++ b/src/mapleall/maple_me/src/lfo_dep_test.cpp @@ -66,6 +66,8 @@ void LfoDepInfo::CreateDoloopInfo(BlockNode *block, DoloopInfo *parent) { case OP_callassigned: case OP_icall: case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: case OP_return: case OP_throw: case OP_asm: diff --git a/src/mapleall/maple_me/src/lmbc_lower.cpp b/src/mapleall/maple_me/src/lmbc_lower.cpp index 925592b455..feb6f1370d 100644 --- a/src/mapleall/maple_me/src/lmbc_lower.cpp +++ b/src/mapleall/maple_me/src/lmbc_lower.cpp @@ -363,101 +363,11 @@ void LMBCLowerer::LowerReturn(NaryStmtNode *retNode, BlockNode *newblk) { newblk->AddStatement(retNode); } -MIRFuncType *LMBCLowerer::FuncTypeFromFuncPtrExpr(BaseNode *x) { - MIRFuncType *res = nullptr; - switch (x->GetOpCode()) { - case OP_regread: { - RegreadNode *regread = static_cast(x); - MIRPreg *preg = func->GetPregTab()->PregFromPregIdx(regread->GetRegIdx()); - // see if it is promoted from a symbol - if (preg->GetOp() == OP_dread) { - const MIRSymbol *symbol = preg->rematInfo.sym; - MIRType *mirType = symbol->GetType(); - if (preg->fieldID != 0) { - MIRStructType *structty = static_cast(mirType); - FieldPair thepair = structty->TraverseToField(preg->fieldID); - mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); - } - - if (mirType->GetKind() == kTypePointer) { - res = static_cast(mirType)->GetPointedFuncType(); - } - if (res != nullptr) { - break; - } - } - // check if a formal promoted to preg - for (FormalDef &formalDef : func->GetFormalDefVec()) { - if (!formalDef.formalSym->IsPreg()) { - continue; - } - if (formalDef.formalSym->GetPreg() == preg) { - MIRType *mirType = formalDef.formalSym->GetType(); - if (mirType->GetKind() == kTypePointer) { - res = static_cast(mirType)->GetPointedFuncType(); - } - break; - } - } - break; - } - case OP_dread: { - DreadNode *dread = static_cast(x); - MIRSymbol *symbol = func->GetLocalOrGlobalSymbol(dread->GetStIdx()); - MIRType *mirType = symbol->GetType(); - if (dread->GetFieldID() != 0) { - MIRStructType *structty = static_cast(mirType); - FieldPair thepair = structty->TraverseToField(dread->GetFieldID()); - mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); - } - if (mirType->GetKind() == kTypePointer) { - res = static_cast(mirType)->GetPointedFuncType(); - } - break; - } - case OP_iread: { - IreadNode *iread = static_cast(x); - MIRPtrType *ptrType = static_cast(iread->GetType()); - MIRType *mirType = ptrType->GetPointedType(); - if (mirType->GetKind() == kTypePointer) { - res = static_cast(mirType)->GetPointedFuncType(); - } - break; - } - case OP_addroffunc: { - AddroffuncNode *addrofFunc = static_cast(x); - PUIdx puIdx = addrofFunc->GetPUIdx(); - MIRFunction *f = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puIdx); - res = f->GetMIRFuncType(); - break; - } - case OP_retype: { - MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx( - static_cast(x)->GetTyIdx()); - if (mirType->GetKind() == kTypePointer) { - res = static_cast(mirType)->GetPointedFuncType(); - } - if (res == nullptr) { - res = FuncTypeFromFuncPtrExpr(x->Opnd(0)); - } - break; - } - case OP_select: { - res = FuncTypeFromFuncPtrExpr(x->Opnd(1)); - if (res == nullptr) { - res = FuncTypeFromFuncPtrExpr(x->Opnd(2)); - } - break; - } - default: CHECK_FATAL(false, "LMBCLowerer::FuncTypeFromFuncPtrExpr: NYI"); - } - return res; -} - void LMBCLowerer::LowerCall(NaryStmtNode *naryStmt, BlockNode *newblk) { // go through each parameter uint32 i = 0; - if (naryStmt->GetOpCode() == OP_icall || naryStmt->GetOpCode() == OP_icallassigned) { + if (naryStmt->GetOpCode() == OP_icall || naryStmt->GetOpCode() == OP_icallassigned || + naryStmt->GetOpCode() == OP_icallproto || naryStmt->GetOpCode() == OP_icallprotoassigned) { i = 1; } ParmLocator parmlocator; @@ -517,14 +427,10 @@ void LMBCLowerer::LowerCall(NaryStmtNode *naryStmt, BlockNode *newblk) { } } BaseNode *opnd0 = nullptr; - if (naryStmt->GetOpCode() == OP_icall || naryStmt->GetOpCode() == OP_icallassigned) { + if (naryStmt->GetOpCode() == OP_icall || naryStmt->GetOpCode() == OP_icallassigned || + naryStmt->GetOpCode() == OP_icallproto || naryStmt->GetOpCode() == OP_icallprotoassigned) { opnd0 = naryStmt->Opnd(0); naryStmt->GetNopnd().clear(); // remove the call operands - // convert to OP_icallproto by finding the function prototype and record in stmt - naryStmt->SetOpCode(OP_icallproto); - MIRFuncType *funcType = FuncTypeFromFuncPtrExpr(opnd0); - CHECK_FATAL(funcType != nullptr, "LMBCLowerer::LowerCall: cannot find prototype for icall"); - static_cast(naryStmt)->SetRetTyIdx(funcType->GetTypeIndex()); // add back the function pointer operand naryStmt->GetNopnd().push_back(LowerExpr(opnd0)); naryStmt->SetNumOpnds(1); @@ -571,7 +477,11 @@ BlockNode *LMBCLowerer::LowerBlock(BlockNode *block) { } } case OP_call: - case OP_icall: { + case OP_callassigned: + case OP_icall: + case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: { LowerCall(static_cast(stmt), newblk); break; } diff --git a/src/mapleall/maple_me/src/me_cfg.cpp b/src/mapleall/maple_me/src/me_cfg.cpp index 77df584b5f..23fa685448 100644 --- a/src/mapleall/maple_me/src/me_cfg.cpp +++ b/src/mapleall/maple_me/src/me_cfg.cpp @@ -260,6 +260,7 @@ bool MeCFG::FindUse(const StmtNode &stmt, StIdx stIdx) const { case OP_customcall: case OP_polymorphiccall: case OP_icall: + case OP_icallproto: case OP_intrinsiccall: case OP_xintrinsiccall: case OP_intrinsiccallwithtype: @@ -272,6 +273,7 @@ bool MeCFG::FindUse(const StmtNode &stmt, StIdx stIdx) const { case OP_customcallassigned: case OP_polymorphiccallassigned: case OP_icallassigned: + case OP_icallprotoassigned: case OP_intrinsiccallassigned: case OP_xintrinsiccallassigned: case OP_intrinsiccallwithtypeassigned: diff --git a/src/mapleall/maple_me/src/me_function.cpp b/src/mapleall/maple_me/src/me_function.cpp index fbd85db0fd..c32f9bff88 100755 --- a/src/mapleall/maple_me/src/me_function.cpp +++ b/src/mapleall/maple_me/src/me_function.cpp @@ -301,7 +301,9 @@ void MeFunction::CloneBBMeStmts(BB &srcBB, BB &destBB, std::map(&stmt); newStmt = irmap->NewInPool(static_cast(icallStmt), icallStmt->GetRetTyIdx(), icallStmt->GetStmtID()); diff --git a/src/mapleall/maple_me/src/me_lower_globals.cpp b/src/mapleall/maple_me/src/me_lower_globals.cpp index c14dd5c764..fdf2df8e3f 100644 --- a/src/mapleall/maple_me/src/me_lower_globals.cpp +++ b/src/mapleall/maple_me/src/me_lower_globals.cpp @@ -185,7 +185,12 @@ void MeLowerGlobals::Run() { MeExpr *addroffuncExpr = irMap->CreateAddroffuncMeExpr(callee.GetPuidx()); auto insertpos = callStmt.GetOpnds().begin(); callStmt.InsertOpnds(insertpos, addroffuncExpr); - IcallMeStmt *icallStmt = irMap->NewInPool(stmt.GetOp() == OP_call ? OP_icall : OP_icallassigned); + IcallMeStmt *icallStmt = nullptr; + if (func.GetMIRModule().IsCModule()) { + icallStmt = irMap->NewInPool(stmt.GetOp() == OP_call ? OP_icallproto : OP_icallprotoassigned); + } else { + icallStmt = irMap->NewInPool(stmt.GetOp() == OP_call ? OP_icall : OP_icallassigned); + } icallStmt->SetIsLive(callStmt.GetIsLive()); icallStmt->SetSrcPos(callStmt.GetSrcPosition()); for (MeExpr *o : callStmt.GetOpnds()) { @@ -193,7 +198,11 @@ void MeLowerGlobals::Run() { } icallStmt->GetMuList()->insert(callStmt.GetMuList()->begin(), callStmt.GetMuList()->end()); icallStmt->GetChiList()->insert(callStmt.GetChiList()->begin(), callStmt.GetChiList()->end()); - icallStmt->SetRetTyIdx(callee.GetReturnTyIdx()); + if (func.GetMIRModule().IsCModule()) { + icallStmt->SetRetTyIdx(callee.GetMIRFuncType()->GetTypeIndex()); + } else { + icallStmt->SetRetTyIdx(callee.GetReturnTyIdx()); + } if (stmt.GetOp() != OP_call) { if (callStmt.NeedDecref()) { icallStmt->EnableNeedDecref(); diff --git a/src/mapleall/maple_me/src/me_rename2preg.cpp b/src/mapleall/maple_me/src/me_rename2preg.cpp index 42792b51a0..6eb810cad0 100644 --- a/src/mapleall/maple_me/src/me_rename2preg.cpp +++ b/src/mapleall/maple_me/src/me_rename2preg.cpp @@ -317,6 +317,7 @@ void SSARename2Preg::Rename2PregStmt(MeStmt *stmt) { case OP_customcallassigned: case OP_polymorphiccallassigned: case OP_icallassigned: + case OP_icallprotoassigned: case OP_intrinsiccallassigned: case OP_xintrinsiccallassigned: case OP_intrinsiccallwithtypeassigned: { diff --git a/src/mapleall/maple_me/src/me_side_effect.cpp b/src/mapleall/maple_me/src/me_side_effect.cpp index ad493a9e01..2df2f0a2c5 100644 --- a/src/mapleall/maple_me/src/me_side_effect.cpp +++ b/src/mapleall/maple_me/src/me_side_effect.cpp @@ -932,6 +932,7 @@ bool IpaSideEffect::UpdateSideEffectWithStmt(MeStmt &meStmt, case OP_customcallassigned: case OP_polymorphiccallassigned: case OP_icallassigned: + case OP_icallprotoassigned: case OP_superclasscallassigned: case OP_asm: { hasPrivateDef = hasThrException = true; @@ -958,7 +959,8 @@ bool IpaSideEffect::UpdateSideEffectWithStmt(MeStmt &meStmt, case OP_interfaceicall: case OP_customcall: case OP_polymorphiccall: - case OP_icall: { + case OP_icall: + case OP_icallproto: { hasPrivateDef = hasThrException = true; SetHasDef(); for (size_t i = 0; i < meStmt.NumMeStmtOpnds(); ++i) { diff --git a/src/mapleall/maple_me/src/me_stmt_pre.cpp b/src/mapleall/maple_me/src/me_stmt_pre.cpp index edc435d6be..a84bf412e6 100755 --- a/src/mapleall/maple_me/src/me_stmt_pre.cpp +++ b/src/mapleall/maple_me/src/me_stmt_pre.cpp @@ -966,7 +966,9 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { break; } case OP_icall: - case OP_icallassigned: { + case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: { auto &icallMeStmt = static_cast(stmt); VersionStackChiListUpdate(*icallMeStmt.GetChiList()); break; diff --git a/src/mapleall/maple_me/src/pme_emit.cpp b/src/mapleall/maple_me/src/pme_emit.cpp index 4e6c7b2ab9..6d4ffe3a89 100755 --- a/src/mapleall/maple_me/src/pme_emit.cpp +++ b/src/mapleall/maple_me/src/pme_emit.cpp @@ -485,10 +485,12 @@ StmtNode* PreMeEmitter::EmitPreMeStmt(MeStmt *mestmt, BaseNode *parent) { return callnode; } case OP_icall: - case OP_icallassigned: { + case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: { IcallMeStmt *icallMeStmt = static_cast (mestmt); IcallNode *icallnode = - codeMP->New(*codeMPAlloc, OP_icallassigned, icallMeStmt->GetRetTyIdx()); + codeMP->New(*codeMPAlloc, OP_icallprotoassigned, icallMeStmt->GetRetTyIdx()); for (uint32 i = 0; i < icallMeStmt->GetOpnds().size(); i++) { icallnode->GetNopnd().push_back(EmitPreMeExpr(icallMeStmt->GetOpnd(i), icallnode)); } @@ -509,6 +511,9 @@ StmtNode* PreMeEmitter::EmitPreMeStmt(MeStmt *mestmt, BaseNode *parent) { icallnode->SetRetTyIdx(TyIdx(preg->GetPrimType())); } } + if (mestmt->GetOp() == OP_icallproto || mestmt->GetOp() == OP_icallprotoassigned) { + icallnode->SetRetTyIdx(icallMeStmt->GetRetTyIdx()); + } icallnode->CopySafeRegionAttr(mestmt->GetStmtAttr()); icallnode->SetOriginalID(mestmt->GetOriginalId()); PreMeStmtExtensionMap[icallnode->GetStmtID()] = pmeExt; diff --git a/src/mapleall/maple_me/src/ssa_devirtual.cpp b/src/mapleall/maple_me/src/ssa_devirtual.cpp index 15a609e427..f46e8e06ce 100644 --- a/src/mapleall/maple_me/src/ssa_devirtual.cpp +++ b/src/mapleall/maple_me/src/ssa_devirtual.cpp @@ -534,7 +534,9 @@ void SSADevirtual::TraversalMeStmt(MeStmt &meStmt) { break; } case OP_icall: - case OP_icallassigned: { + case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: { auto *icallMeStmt = static_cast(&meStmt); const MapleVector &opnds = icallMeStmt->GetOpnds(); for (size_t i = 0; i < opnds.size(); ++i) { diff --git a/src/mapleall/maple_me/src/ssa_pre.cpp b/src/mapleall/maple_me/src/ssa_pre.cpp index e55c00254a..82014d7026 100644 --- a/src/mapleall/maple_me/src/ssa_pre.cpp +++ b/src/mapleall/maple_me/src/ssa_pre.cpp @@ -1660,6 +1660,7 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE case OP_customcall: case OP_polymorphiccall: case OP_icall: + case OP_icallproto: case OP_callassigned: case OP_virtualcallassigned: case OP_virtualicallassigned: @@ -1669,6 +1670,7 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE case OP_customcallassigned: case OP_polymorphiccallassigned: case OP_icallassigned: + case OP_icallprotoassigned: case OP_asm: { auto *naryMeStmt = static_cast(meStmt); const MapleVector &opnds = naryMeStmt->GetOpnds(); diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index 4d29f018a3..ca0e556196 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -162,6 +162,8 @@ StmtNode *ConstantFold::Simplify(StmtNode *node) { return SimplifyNary(static_cast(node)); case OP_icall: case OP_icallassigned: + case OP_icallproto: + case OP_icallprotoassigned: return SimplifyIcall(static_cast(node)); case OP_asm: return SimplifyAsm(static_cast(node)); @@ -2468,8 +2470,8 @@ StmtNode *ConstantFold::SimplifyIcall(IcallNode *node) { AddroffuncNode *addrofNode = static_cast(node->GetNopndAt(0)); CallNode *callNode = mirModule->CurFuncCodeMemPool()->New(*mirModule, - node->GetOpCode() == OP_icall ? OP_call : OP_callassigned); - if (node->GetOpCode() == OP_icallassigned) { + (node->GetOpCode() == OP_icall || node->GetOpCode() == OP_icallproto) ? OP_call : OP_callassigned); + if (node->GetOpCode() == OP_icallassigned || node->GetOpCode() == OP_icallprotoassigned) { callNode->SetReturnVec(node->GetReturnVec()); } callNode->SetPUIdx(addrofNode->GetPUIdx()); -- Gitee