From ac3ed09a9f1e4ad97ca45cb8bbd931a0d5af7167 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Fri, 22 Apr 2022 20:04:18 -0700 Subject: [PATCH 1/3] Define new opcode icallproto that provides the prototype in the instruction icallproto is the lowered form of icall formed by LMBCLowerer. Without this, mplcg would not be able to get the function prototype of the function pointer used in icall in lmbc. --- src/mapleall/maple_ir/include/mir_nodes.h | 3 +- src/mapleall/maple_ir/include/mir_parser.h | 3 +- src/mapleall/maple_ir/include/opcodes.def | 1 + 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/bin_mpl_import.cpp | 1 - src/mapleall/maple_ir/src/mir_nodes.cpp | 11 ++- src/mapleall/maple_ir/src/mir_parser.cpp | 24 ++++-- src/mapleall/maple_me/include/lmbc_lower.h | 1 + src/mapleall/maple_me/src/lmbc_lower.cpp | 79 ++++++++++++++++++- 10 files changed, 115 insertions(+), 10 deletions(-) diff --git a/src/mapleall/maple_ir/include/mir_nodes.h b/src/mapleall/maple_ir/include/mir_nodes.h index e14704bbc7..454a3aa0e7 100755 --- a/src/mapleall/maple_ir/include/mir_nodes.h +++ b/src/mapleall/maple_ir/include/mir_nodes.h @@ -3210,6 +3210,7 @@ class CallNode : public NaryStmtNode { CallReturnVector returnValues; }; +// icall and icallproto class IcallNode : public NaryStmtNode { public: IcallNode(MapleAllocator &allocator, Opcode o) @@ -3285,7 +3286,7 @@ class IcallNode : public NaryStmtNode { } private: - TyIdx retTyIdx; // return type for callee + TyIdx retTyIdx; // for icall: return type for callee; for icallproto: the prototye // the 0th operand is the function pointer CallReturnVector returnValues; }; diff --git a/src/mapleall/maple_ir/include/mir_parser.h b/src/mapleall/maple_ir/include/mir_parser.h index 249b619b07..d05c844f31 100755 --- a/src/mapleall/maple_ir/include/mir_parser.h +++ b/src/mapleall/maple_ir/include/mir_parser.h @@ -125,9 +125,10 @@ class MIRParser { PUIdx EnterUndeclaredFunction(bool isMcount = false); // for -pg in order to add "void _mcount()" bool ParseStmtCall(StmtNodePtr&); bool ParseStmtCallMcount(StmtNodePtr&); // for -pg in order to add "void _mcount()" to all the functions - bool ParseStmtIcall(StmtNodePtr&, bool isAssigned); + bool ParseStmtIcall(StmtNodePtr&, Opcode op); bool ParseStmtIcall(StmtNodePtr&); bool ParseStmtIcallassigned(StmtNodePtr&); + bool ParseStmtIcallproto(StmtNodePtr&); bool ParseStmtIntrinsiccall(StmtNodePtr&, bool isAssigned); bool ParseStmtIntrinsiccall(StmtNodePtr&); bool ParseStmtIntrinsiccallassigned(StmtNodePtr&); diff --git a/src/mapleall/maple_ir/include/opcodes.def b/src/mapleall/maple_ir/include/opcodes.def index d1265eda42..34cfb51c8d 100755 --- a/src/mapleall/maple_ir/include/opcodes.def +++ b/src/mapleall/maple_ir/include/opcodes.def @@ -220,3 +220,4 @@ OPCODE(dassignoff, DassignoffNode, (OPCODEISSTMT | OPCODEHASSSADEF), 8) OPCODE(iassignspoff, IassignFPoffNode, OPCODEISSTMT, 8) OPCODE(blkassignoff, BlkassignoffNode, OPCODEISSTMT, 8) + OPCODE(icallproto, IcallNode, (OPCODEISSTMT | OPCODEISVARSIZE | OPCODEHASSSAUSE | OPCODEHASSSADEF | OPCODEISCALL), 8) diff --git a/src/mapleall/maple_ir/src/bin_func_export.cpp b/src/mapleall/maple_ir/src/bin_func_export.cpp index 843a7693ca..5117ed8ed0 100644 --- a/src/mapleall/maple_ir/src/bin_func_export.cpp +++ b/src/mapleall/maple_ir/src/bin_func_export.cpp @@ -493,6 +493,7 @@ void BinaryMplExport::OutputBlockNode(BlockNode *block) { WriteNum(static_cast(s->NumOpnds())); break; } + case OP_icallproto: case OP_icall: { 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 f956ed2070..d18aac9f58 100644 --- a/src/mapleall/maple_ir/src/bin_func_import.cpp +++ b/src/mapleall/maple_ir/src/bin_func_import.cpp @@ -632,6 +632,7 @@ BlockNode *BinaryMplImport::ImportBlockNode(MIRFunction *func) { stmt = s; break; } + case OP_icallproto: case OP_icall: { IcallNode *s = func->GetCodeMemPool()->New(mod, op); s->SetRetTyIdx(ImportType()); diff --git a/src/mapleall/maple_ir/src/bin_mpl_import.cpp b/src/mapleall/maple_ir/src/bin_mpl_import.cpp index 9d09296ea1..08d2ff06a5 100644 --- a/src/mapleall/maple_ir/src/bin_mpl_import.cpp +++ b/src/mapleall/maple_ir/src/bin_mpl_import.cpp @@ -817,7 +817,6 @@ TyIdx BinaryMplImport::ImportTypeNonJava() { type.GetParamAttrsList().push_back(ImportTypeAttrs()); } GlobalTables::GetTypeTable().CreateMirTypeNodeAt(type, tyIdxUsed, &mod, false, false); - CHECK_FATAL(type.GetRetTyIdx() != TyIdx(0), "ImportTypeNonJava: retTyIdx cannot be 0"); return tyIdxUsed; } case kBinKindTypeParam: { diff --git a/src/mapleall/maple_ir/src/mir_nodes.cpp b/src/mapleall/maple_ir/src/mir_nodes.cpp index b20e80f889..4611246c1b 100755 --- a/src/mapleall/maple_ir/src/mir_nodes.cpp +++ b/src/mapleall/maple_ir/src/mir_nodes.cpp @@ -1128,7 +1128,12 @@ void CallNode::Dump(int32 indent, bool newline) const { } MIRType *IcallNode::GetCallReturnType() { - return GlobalTables::GetTypeTable().GetTypeFromTyIdx(retTyIdx); + if (op == OP_icall || op == OP_icallassigned) { + return GlobalTables::GetTypeTable().GetTypeFromTyIdx(retTyIdx); + } + // icallproto + MIRFuncType *funcType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(retTyIdx)); + return GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcType->GetRetTyIdx()); } const MIRSymbol *IcallNode::GetCallReturnSymbol(const MIRModule &mod) const { @@ -1150,6 +1155,10 @@ const MIRSymbol *IcallNode::GetCallReturnSymbol(const MIRModule &mod) const { void IcallNode::Dump(int32 indent, bool newline) const { StmtNode::DumpBase(indent); + if (op == OP_icallproto) { + LogInfo::MapleLogger() << " "; + GlobalTables::GetTypeTable().GetTypeFromTyIdx(retTyIdx)->Dump(indent + 1); + } NaryOpnds::Dump(indent); if (kOpcodeInfo.IsCallAssigned(GetOpCode())) { DumpCallReturns(*theMIRModule, this->returnValues, indent); diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index 37daecc54a..6d4c28b105 100755 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -922,22 +922,31 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { return true; } -bool MIRParser::ParseStmtIcall(StmtNodePtr &stmt, bool isAssigned) { +bool MIRParser::ParseStmtIcall(StmtNodePtr &stmt, Opcode op) { // syntax: icall (, , ..., ) // icallassigned (, ..., ) { // dassign // dassign // . . . // dassign } - auto *iCallStmt = mod.CurFuncCodeMemPool()->New(mod, !isAssigned ? OP_icall : OP_icallassigned); + // icallproto (, , ..., ) + IcallNode *iCallStmt = mod.CurFuncCodeMemPool()->New(mod, op); lexer.NextToken(); + if (op == OP_icallproto) { + TyIdx tyIdx(0); + if (!ParseDerivedType(tyIdx)) { + Error("error parsing type in ParseStmtIcall for icallproto at "); + return false; + } + iCallStmt->SetRetTyIdx(tyIdx); + } MapleVector opndsVec(mod.CurFuncCodeMemPoolAllocator()->Adapter()); if (!ParseExprNaryOperand(opndsVec)) { return false; } iCallStmt->SetNOpnd(opndsVec); iCallStmt->SetNumOpnds(opndsVec.size()); - if (isAssigned) { + if (op == OP_icallassigned) { CallReturnVector retsVec(mod.CurFuncCodeMemPoolAllocator()->Adapter()); if (!ParseCallReturns(retsVec)) { return false; @@ -950,11 +959,15 @@ bool MIRParser::ParseStmtIcall(StmtNodePtr &stmt, bool isAssigned) { } bool MIRParser::ParseStmtIcall(StmtNodePtr &stmt) { - return ParseStmtIcall(stmt, false); + return ParseStmtIcall(stmt, OP_icall); } bool MIRParser::ParseStmtIcallassigned(StmtNodePtr &stmt) { - return ParseStmtIcall(stmt, true); + return ParseStmtIcall(stmt, OP_icallassigned); +} + +bool MIRParser::ParseStmtIcallproto(StmtNodePtr &stmt) { + return ParseStmtIcall(stmt, OP_icallproto); } bool MIRParser::ParseStmtIntrinsiccall(StmtNodePtr &stmt, bool isAssigned) { @@ -3399,6 +3412,7 @@ std::map MIRParser::InitFuncPtrMapForPar funcPtrMap[TK_interfacecallinstantassigned] = &MIRParser::ParseStmtCall; funcPtrMap[TK_icall] = &MIRParser::ParseStmtIcall; funcPtrMap[TK_icallassigned] = &MIRParser::ParseStmtIcallassigned; + funcPtrMap[TK_icallproto] = &MIRParser::ParseStmtIcallproto; 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 90f056cfcb..a49aca1ce2 100644 --- a/src/mapleall/maple_me/include/lmbc_lower.h +++ b/src/mapleall/maple_me/include/lmbc_lower.h @@ -47,6 +47,7 @@ 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/lmbc_lower.cpp b/src/mapleall/maple_me/src/lmbc_lower.cpp index 746fbeabc9..e01a3e6e37 100644 --- a/src/mapleall/maple_me/src/lmbc_lower.cpp +++ b/src/mapleall/maple_me/src/lmbc_lower.cpp @@ -333,6 +333,78 @@ 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); + // must be a formal promoted to preg + for (FormalDef &formalDef : func->GetFormalDefVec()) { + if (!formalDef.formalSym->IsPreg()) { + continue; + } + if (formalDef.formalSym->GetPreg() == func->GetPregTab()->PregFromPregIdx(regread->GetRegIdx())) { + MIRType *mirType = formalDef.formalSym->GetType(); + if (mirType->GetKind() == kTypePointer) { + res = dynamic_cast(static_cast(mirType)->GetPointedType()); + } else { + res = dynamic_cast(mirType); + } + 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 = dynamic_cast(mirType); + CHECK_FATAL(structty, "LMBCLowerer::FuncTypeFromFuncPtrExpr: non-zero fieldID for non-structure"); + FieldPair thepair = structty->TraverseToField(dread->GetFieldID()); + mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); + } + if (mirType->GetKind() == kTypePointer) { + res = dynamic_cast(static_cast(mirType)->GetPointedType()); + } else { + res = dynamic_cast(mirType); + } + break; + } + case OP_iread: { + IreadNode *iread = static_cast(x); + MIRPtrType *ptrType = dynamic_cast(iread->GetType()); + MIRType *mirType = ptrType->GetPointedType(); + if (iread->GetFieldID() != 0) { + MIRStructType *structty = dynamic_cast(mirType); + CHECK_FATAL(structty, "LMBCLowerer::FuncTypeFromFuncPtrExpr: non-zero fieldID for non-structure"); + FieldPair thepair = structty->TraverseToField(iread->GetFieldID()); + mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); + } + if (mirType->GetKind() == kTypePointer) { + res = dynamic_cast(static_cast(mirType)->GetPointedType()); + } else { + res = dynamic_cast(mirType); + } + 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: { + res = FuncTypeFromFuncPtrExpr(x->Opnd(0)); + break; + } + default: CHECK_FATAL(false, "LMBCLowerer::FuncTypeFromFuncPtrExpr: NYI"); + } + return res; +} + void LMBCLowerer::LowerCall(NaryStmtNode *naryStmt, BlockNode *newblk) { // go through each parameter uint32 i = 0; @@ -394,7 +466,12 @@ void LMBCLowerer::LowerCall(NaryStmtNode *naryStmt, BlockNode *newblk) { if (naryStmt->GetOpCode() == OP_icall || naryStmt->GetOpCode() == OP_icallassigned) { opnd0 = naryStmt->Opnd(0); naryStmt->GetNopnd().clear(); // remove the call operands - naryStmt->GetNopnd().push_back(opnd0); + // convert to OP_icallproto by finding the function prototype and record in stmt + naryStmt->SetOpCode(OP_icallproto); + MIRFuncType *funcType = FuncTypeFromFuncPtrExpr(opnd0); + static_cast(naryStmt)->SetRetTyIdx(funcType->GetTypeIndex()); + // add back the function pointer operand + naryStmt->GetNopnd().push_back(LowerExpr(opnd0)); naryStmt->SetNumOpnds(1); } else { naryStmt->GetNopnd().clear(); // remove the call operands -- Gitee From dc10185202122fc25cafb61fe5cc21edfb490d37 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Sat, 23 Apr 2022 17:13:09 -0700 Subject: [PATCH 2/3] Fixed some issues found in testing lowering of icall to icallproto --- src/mapleall/maple_be/src/be/lower.cpp | 4 ++- src/mapleall/maple_me/src/lmbc_lower.cpp | 42 +++++++++++++++++++----- src/mapleall/maple_me/src/prop.cpp | 6 ++++ src/mapleall/maple_me/src/ssa_epre.cpp | 3 +- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index c5f2333920..267e17d280 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -2480,8 +2480,10 @@ BaseNode *CGLowerer::LowerExpr(BaseNode &parent, BaseNode &expr, BlockNode &blkN case OP_select: if (IsComplexSelect(static_cast(expr))) { return LowerComplexSelect(static_cast(expr), parent, blkNode); - } else { + } else if (mirModule.GetFlavor() != kFlavorLmbc) { return SplitTernaryNodeResult(static_cast(expr), parent, blkNode); + } else { + return &expr; } case OP_sizeoftype: { diff --git a/src/mapleall/maple_me/src/lmbc_lower.cpp b/src/mapleall/maple_me/src/lmbc_lower.cpp index e01a3e6e37..5660778bbc 100644 --- a/src/mapleall/maple_me/src/lmbc_lower.cpp +++ b/src/mapleall/maple_me/src/lmbc_lower.cpp @@ -338,12 +338,26 @@ MIRFuncType *LMBCLowerer::FuncTypeFromFuncPtrExpr(BaseNode *x) { switch (x->GetOpCode()) { case OP_regread: { RegreadNode *regread = static_cast(x); - // must be a formal promoted to preg + 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 (mirType->GetKind() == kTypePointer) { + res = dynamic_cast(static_cast(mirType)->GetPointedType()); + } else { + res = dynamic_cast(mirType); + } + 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() == func->GetPregTab()->PregFromPregIdx(regread->GetRegIdx())) { + if (formalDef.formalSym->GetPreg() == preg) { MIRType *mirType = formalDef.formalSym->GetType(); if (mirType->GetKind() == kTypePointer) { res = dynamic_cast(static_cast(mirType)->GetPointedType()); @@ -376,12 +390,6 @@ MIRFuncType *LMBCLowerer::FuncTypeFromFuncPtrExpr(BaseNode *x) { IreadNode *iread = static_cast(x); MIRPtrType *ptrType = dynamic_cast(iread->GetType()); MIRType *mirType = ptrType->GetPointedType(); - if (iread->GetFieldID() != 0) { - MIRStructType *structty = dynamic_cast(mirType); - CHECK_FATAL(structty, "LMBCLowerer::FuncTypeFromFuncPtrExpr: non-zero fieldID for non-structure"); - FieldPair thepair = structty->TraverseToField(iread->GetFieldID()); - mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); - } if (mirType->GetKind() == kTypePointer) { res = dynamic_cast(static_cast(mirType)->GetPointedType()); } else { @@ -397,7 +405,22 @@ MIRFuncType *LMBCLowerer::FuncTypeFromFuncPtrExpr(BaseNode *x) { break; } case OP_retype: { - res = FuncTypeFromFuncPtrExpr(x->Opnd(0)); + MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast(x)->GetTyIdx()); + if (mirType->GetKind() == kTypePointer) { + res = dynamic_cast(static_cast(mirType)->GetPointedType()); + } else { + res = dynamic_cast(mirType); + } + 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"); @@ -469,6 +492,7 @@ void LMBCLowerer::LowerCall(NaryStmtNode *naryStmt, BlockNode *newblk) { // 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)); diff --git a/src/mapleall/maple_me/src/prop.cpp b/src/mapleall/maple_me/src/prop.cpp index 307b93af10..010399bc95 100644 --- a/src/mapleall/maple_me/src/prop.cpp +++ b/src/mapleall/maple_me/src/prop.cpp @@ -642,6 +642,12 @@ MeExpr &Prop::PropVar(VarMeExpr &varMeExpr, bool atParm, bool checkPhi) { propsPerformed >= propLimit) { return varMeExpr; } + if (st->GetType() && st->GetType()->GetKind() == kTypePointer) { + MIRPtrType *ptrType = static_cast(st->GetType()); + if (ptrType->GetPointedType()->GetKind() == kTypeFunction) { + return varMeExpr; + } + } if (varMeExpr.GetDefBy() == kDefByStmt) { DassignMeStmt *defStmt = static_cast(varMeExpr.GetDefStmt()); diff --git a/src/mapleall/maple_me/src/ssa_epre.cpp b/src/mapleall/maple_me/src/ssa_epre.cpp index 34e1f1812a..9ddf02c99a 100644 --- a/src/mapleall/maple_me/src/ssa_epre.cpp +++ b/src/mapleall/maple_me/src/ssa_epre.cpp @@ -368,7 +368,8 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b if (!epreIncludeRef && meOpExpr->GetPrimType() == PTY_ref) { break; } - if (meOpExpr->GetOp() == OP_gcmallocjarray || meOpExpr->GetOp() == OP_gcmalloc) { + if (meOpExpr->GetOp() == OP_gcmallocjarray || meOpExpr->GetOp() == OP_gcmalloc || + meOpExpr->GetOp() == OP_retype) { break; } if (isRebuild && !hasTempVarAs1Opnd) { -- Gitee From 1f1383557ec55922b642a3d98149b85e7224215a Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Tue, 26 Apr 2022 20:58:02 -0700 Subject: [PATCH 3/3] Do not promote addroffunc to preg under -genlmbc because the preg will lose the prototype info --- src/mapleall/maple_me/include/me_function.h | 1 + src/mapleall/maple_me/src/me_phase_manager.cpp | 3 +++ src/mapleall/maple_me/src/me_ssa_lpre.cpp | 3 +++ 3 files changed, 7 insertions(+) diff --git a/src/mapleall/maple_me/include/me_function.h b/src/mapleall/maple_me/include/me_function.h index 024d6e40b7..3929edf431 100644 --- a/src/mapleall/maple_me/include/me_function.h +++ b/src/mapleall/maple_me/include/me_function.h @@ -402,6 +402,7 @@ class MeFunction : public FuncEmit { uint32 hdseRuns = 0; // number of times hdse phase has been run uint32 hpropRuns = 0; // number of times hprop phase has been run uint32 vrpRuns = 0; // number of times vrp phase has been run + bool genLMBC = false; // whether outputing lmbc (low maple bytecode) }; } // namespace maple #endif // MAPLE_ME_INCLUDE_ME_FUNCTION_H diff --git a/src/mapleall/maple_me/src/me_phase_manager.cpp b/src/mapleall/maple_me/src/me_phase_manager.cpp index 9194d92325..0177039ff3 100644 --- a/src/mapleall/maple_me/src/me_phase_manager.cpp +++ b/src/mapleall/maple_me/src/me_phase_manager.cpp @@ -100,6 +100,9 @@ bool MeFuncPM::PhaseRun(maple::MIRModule &m) { auto meFuncStackMP = std::make_unique(memPoolCtrler, ""); MemPool *versMP = new ThreadLocalMemPool(memPoolCtrler, "first verst mempool"); MeFunction &meFunc = *(meFuncMP->New(&m, func, meFuncMP.get(), *meFuncStackMP, versMP, meInput)); + if (genLMBC) { + meFunc.genLMBC = true; + } func->SetMeFunc(&meFunc); meFunc.PartialInit(); #if DEBUG diff --git a/src/mapleall/maple_me/src/me_ssa_lpre.cpp b/src/mapleall/maple_me/src/me_ssa_lpre.cpp index d43864ea98..1fa9b83126 100644 --- a/src/mapleall/maple_me/src/me_ssa_lpre.cpp +++ b/src/mapleall/maple_me/src/me_ssa_lpre.cpp @@ -375,6 +375,9 @@ void MeSSALPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, if (!MeOption::lpre4Address) { break; } + if (func->genLMBC) { + break; + } CreateRealOcc(meStmt, seqStmt, meExpr, false); break; } -- Gitee