diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index d99fae37d3ccfb47c2aabb28f1c6a52c1a85216d..6b10930c2a4fe2dcf571c5793810c08b6b9f1d23 100755 Binary files a/src/mapleall/bin/dex2mpl and b/src/mapleall/bin/dex2mpl differ diff --git a/src/mapleall/bin/dex2mpl_android b/src/mapleall/bin/dex2mpl_android index 1eed48ec21c3b5ba2a8ada6c717b4a1ff2cd1ec1..11d0815fb7a36fae79059f9b2e895d310bc2323f 100755 Binary files a/src/mapleall/bin/dex2mpl_android and b/src/mapleall/bin/dex2mpl_android differ diff --git a/src/mapleall/bin/jbc2mpl b/src/mapleall/bin/jbc2mpl index c456172d1843e3563e1219f37b1ae61acad73e74..09dacbe91267cdfa8cff8b9e503a5174131fa331 100755 Binary files a/src/mapleall/bin/jbc2mpl and b/src/mapleall/bin/jbc2mpl differ diff --git a/src/mapleall/maple_ir/include/mir_type.h b/src/mapleall/maple_ir/include/mir_type.h index e14688ee5cc558c6fe57df2c02a980de92b8319c..53c324fc74e76a71ec7ca03ec366a6ec7c34b2f4 100755 --- a/src/mapleall/maple_ir/include/mir_type.h +++ b/src/mapleall/maple_ir/include/mir_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/mapleall/maple_me/src/me_phase_manager.cpp b/src/mapleall/maple_me/src/me_phase_manager.cpp index 3d6c73fea4ff83c4f101913eba6a06fdbe5f22bb..c46ae32705abd694f5b0a55eb1c147c8345c4cb9 100644 --- a/src/mapleall/maple_me/src/me_phase_manager.cpp +++ b/src/mapleall/maple_me/src/me_phase_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -156,7 +156,7 @@ void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::s #endif // call constant folding maple::ConstantFold cf(mirModule); - cf.Simplify(mirFunc->GetBody()); + (void)cf.Simplify(mirFunc->GetBody()); func.Prepare(rangeNum); if (timePhases) { diff --git a/src/mapleall/mpl2mpl/include/constantfold.h b/src/mapleall/mpl2mpl/include/constantfold.h index ecc8c4bbc53ff60f55c81b894d0ab9ab8bffd83d..45c172fb8f78d32222638e10ad9a99f889b8f166 100644 --- a/src/mapleall/mpl2mpl/include/constantfold.h +++ b/src/mapleall/mpl2mpl/include/constantfold.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -58,6 +58,8 @@ class ConstantFold : public FuncOptimizeImpl { StmtNode *SimplifyCondGoto(CondGotoNode *node); StmtNode *SimplifyCondGotoSelect(CondGotoNode *node) const; StmtNode *SimplifyDassign(DassignNode *node); + StmtNode *SimplifyIassignWithAddrofBaseNode(IassignNode &node, const AddrofNode &base); + StmtNode *SimplifyIassignWithIaddrofBaseNode(IassignNode &node, const IaddrofNode &base); StmtNode *SimplifyIassign(IassignNode *node); StmtNode *SimplifyNary(NaryStmtNode *node); StmtNode *SimplifyIcall(IcallNode *node); @@ -88,9 +90,10 @@ class ConstantFold : public FuncOptimizeImpl { const ConstvalNode &const1) const; ConstvalNode *FoldConstBinary(Opcode opcode, PrimType resultType, const ConstvalNode &const0, const ConstvalNode &const1) const; - ConstvalNode *FoldIntConstComparison(Opcode opcode, PrimType resultType, PrimType opndType, const ConstvalNode &const0, - const ConstvalNode &const1) const; - MIRIntConst *FoldIntConstComparisonMIRConst(Opcode, PrimType, PrimType, const MIRIntConst&, const MIRIntConst&) const; + ConstvalNode *FoldIntConstComparison(Opcode opcode, PrimType resultType, PrimType opndType, + const ConstvalNode &const0, const ConstvalNode &const1) const; + MIRIntConst *FoldIntConstComparisonMIRConst(Opcode, PrimType, PrimType, const MIRIntConst&, + const MIRIntConst&) const; ConstvalNode *FoldIntConstBinary(Opcode opcode, PrimType resultType, const ConstvalNode &const0, const ConstvalNode &const1) const; ConstvalNode *FoldFPConstComparison(Opcode opcode, PrimType resultType, PrimType opndType, const ConstvalNode &const0, diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index b843f563c12ff91fab6f069c0f41cbb65881ff8e..b7c21d68e94e59782fbaba8db2b22cbd42962ec2 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2021] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -274,7 +274,8 @@ MIRIntConst *ConstantFold::FoldIntConstComparisonMIRConst(Opcode opcode, PrimTyp bool greater = (intConst0.GetValue() > intConst1.GetValue()); bool equal = (intConst0.GetValue() == intConst1.GetValue()); bool less = (intConst0.GetValue() < intConst1.GetValue()); - bool use64 = GetPrimTypeSize(opndType) == 8; + constexpr uint32 eightBytes = 8; + bool use64 = GetPrimTypeSize(opndType) == eightBytes; switch (opcode) { case OP_eq: { if (use64) { @@ -879,7 +880,7 @@ ConstvalNode *ConstantFold::FoldConstComparison(Opcode opcode, PrimType resultTy const ConstvalNode &const0, const ConstvalNode &const1) const { ConstvalNode *returnValue = nullptr; if (IsPrimitiveInteger(opndType) || IsPrimitiveDynInteger(opndType)) { - returnValue = FoldIntConstComparison(opcode, resultType, opndType, const0, const1); + returnValue = FoldIntConstComparison(opcode, resultType, opndType, const0, const1); } else if (opndType == PTY_f32 || opndType == PTY_f64) { returnValue = FoldFPConstComparison(opcode, resultType, opndType, const0, const1); } else { @@ -1249,7 +1250,7 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst &cst, PrimType fromType return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue); } } else { - uint64 fromValue = constValue.GetValue(); + uint64 fromValue = static_cast(constValue.GetValue()); float floatValue = round(static_cast(fromValue)); if (static_cast(floatValue) == fromValue) { return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue); @@ -1264,7 +1265,7 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst &cst, PrimType fromType return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue); } } else { - uint64 fromValue = constValue.GetValue(); + uint64 fromValue = static_cast(constValue.GetValue()); double doubleValue = round(static_cast(fromValue)); if (static_cast(doubleValue) == fromValue) { return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue); @@ -1578,14 +1579,14 @@ std::pair ConstantFold::FoldBinary(BinaryNode *node) { } else { // when cst is zero // 0 || X -> (X != 0); - result = mirModule->CurFuncCodeMemPool()->New(OP_ne, primType, r->GetPrimType(), r, - mirModule->GetMIRBuilder()->CreateIntConst(0, r->GetPrimType())); + result = mirModule->CurFuncCodeMemPool()->New( + OP_ne, primType, r->GetPrimType(), r, mirModule->GetMIRBuilder()->CreateIntConst(0, r->GetPrimType())); } } else if ((op == OP_cand || op == OP_land) && cst != 0) { // 5 && X -> (X != 0) sum = 0; - result = mirModule->CurFuncCodeMemPool()->New(OP_ne, primType, r->GetPrimType(), r, - mirModule->GetMIRBuilder()->CreateIntConst(0, r->GetPrimType())); + result = mirModule->CurFuncCodeMemPool()->New( + OP_ne, primType, r->GetPrimType(), r, mirModule->GetMIRBuilder()->CreateIntConst(0, r->GetPrimType())); } else if ((op == OP_bior || op == OP_bxor) && cst == 0) { // 0 | X -> X // 0 ^ X -> X @@ -1761,7 +1762,7 @@ std::pair ConstantFold::FoldCompare(CompareNode *node) { ConstvalNode *lConst = safe_cast(lp.first); ConstvalNode *rConst = safe_cast(rp.first); if (lConst != nullptr && rConst != nullptr && !IsPrimitiveDynType(node->GetOpndType())) { - result = FoldConstComparison(node->GetOpCode(), node->GetPrimType(), node->GetOpndType(), + result = FoldConstComparison(node->GetOpCode(), node->GetPrimType(), node->GetOpndType(), *lConst, *rConst); } else { BaseNode *l = PairToExpr(node->Opnd(0)->GetPrimType(), lp); @@ -1935,6 +1936,65 @@ StmtNode *ConstantFold::SimplifyDassign(DassignNode *node) { return node; } +StmtNode *ConstantFold::SimplifyIassignWithAddrofBaseNode(IassignNode &node, const AddrofNode &base) { + auto *mirTypeOfIass = GlobalTables::GetTypeTable().GetTypeFromTyIdx(node.GetTyIdx()); + if (!mirTypeOfIass->IsMIRPtrType()) { + return &node; + } + auto *iassPtType = static_cast(mirTypeOfIass); + + MIRSymbol *lhsSym = mirModule->CurFunction()->GetLocalOrGlobalSymbol(base.GetStIdx()); + TyIdx lhsTyIdx = lhsSym->GetTyIdx(); + if (base.GetFieldID() != 0) { + auto *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(lhsTyIdx); + if (!mirType->IsStructType()) { + return &node; + } + lhsTyIdx = static_cast(mirType)->GetFieldType(base.GetFieldID())->GetTypeIndex(); + } + if (iassPtType->GetPointedTyIdx() == lhsTyIdx) { + DassignNode *dassignNode = mirModule->CurFuncCodeMemPool()->New(); + dassignNode->SetStIdx(base.GetStIdx()); + dassignNode->SetRHS(node.GetRHS()); + dassignNode->SetFieldID(base.GetFieldID() + node.GetFieldID()); + return dassignNode; + } + return &node; +} + +StmtNode *ConstantFold::SimplifyIassignWithIaddrofBaseNode(IassignNode &node, const IaddrofNode &base) { + auto *mirTypeOfIass = GlobalTables::GetTypeTable().GetTypeFromTyIdx(node.GetTyIdx()); + if (!mirTypeOfIass->IsMIRPtrType()) { + return &node; + } + auto *iassPtType = static_cast(mirTypeOfIass); + + if (base.GetFieldID() == 0) { + // this iaddrof is redundant + node.SetAddrExpr(base.Opnd(0)); + return &node; + } + + auto *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(base.GetTyIdx()); + if (!mirType->IsMIRPtrType()) { + return &node; + } + auto *iaddrofPtType = static_cast(mirType); + + MIRStructType *lhsStructTy = + static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(iaddrofPtType->GetPointedTyIdx())); + TyIdx lhsTyIdx = lhsStructTy->GetFieldType(base.GetFieldID())->GetTypeIndex(); + if (iassPtType->GetPointedTyIdx() == lhsTyIdx) { + // eliminate the iaddrof by updating the iassign's fieldID and tyIdx + node.SetFieldID(node.GetFieldID() + base.GetFieldID()); + node.SetTyIdx(base.GetTyIdx()); + node.SetOpnd(base.Opnd(0), 0); + // recursive call for the new iassign + return SimplifyIassign(&node); + } + return &node; +} + StmtNode *ConstantFold::SimplifyIassign(IassignNode *node) { CHECK_NULL_FATAL(node); BaseNode *returnValue = nullptr; @@ -1946,55 +2006,19 @@ StmtNode *ConstantFold::SimplifyIassign(IassignNode *node) { if (returnValue != nullptr) { node->SetRHS(returnValue); } - MIRPtrType *iassPtType = dynamic_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(node->GetTyIdx())); - if (iassPtType == nullptr) { + auto *mirTypeOfIass = GlobalTables::GetTypeTable().GetTypeFromTyIdx(node->GetTyIdx()); + if (!mirTypeOfIass->IsMIRPtrType()) { return node; } + auto *opnd = node->Opnd(0); ASSERT_NOT_NULL(opnd); switch (opnd->GetOpCode()) { case OP_addrof: { - AddrofNode *addrofNode = static_cast(opnd); - MIRSymbol *lhsSym = mirModule->CurFunction()->GetLocalOrGlobalSymbol(addrofNode->GetStIdx()); - TyIdx lhsTyIdx = lhsSym->GetTyIdx(); - if (addrofNode->GetFieldID() != 0) { - MIRStructType *lhsStructTy = dynamic_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(lhsTyIdx)); - if (lhsStructTy == nullptr) { - break; - } - lhsTyIdx = lhsStructTy->GetFieldType(addrofNode->GetFieldID())->GetTypeIndex(); - } - if (iassPtType->GetPointedTyIdx() == lhsTyIdx) { - DassignNode *dassignNode = mirModule->CurFuncCodeMemPool()->New(); - dassignNode->SetStIdx(addrofNode->GetStIdx()); - dassignNode->SetRHS(node->GetRHS()); - dassignNode->SetFieldID(addrofNode->GetFieldID() + node->GetFieldID()); - return dassignNode; - } - break; + return SimplifyIassignWithAddrofBaseNode(*node, static_cast(*opnd)); } case OP_iaddrof: { - IreadNode *iaddrofNode = static_cast(opnd); - MIRPtrType *iaddrofPtType = dynamic_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(iaddrofNode->GetTyIdx())); - if (iaddrofPtType == nullptr) { - break; - } - if (iaddrofNode->GetFieldID() == 0) { - // this iaddrof is redundant - node->SetAddrExpr(iaddrofNode->Opnd(0)); - break; - } - MIRStructType *lhsStructTy = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(iaddrofPtType->GetPointedTyIdx())); - TyIdx lhsTyIdx = lhsStructTy->GetFieldType(iaddrofNode->GetFieldID())->GetTypeIndex(); - if (iassPtType->GetPointedTyIdx() == lhsTyIdx) { - // eliminate the iaddrof by updating the iassign's fieldID and tyIdx - node->SetFieldID(node->GetFieldID() + iaddrofNode->GetFieldID()); - node->SetTyIdx(iaddrofNode->GetTyIdx()); - node->SetOpnd(iaddrofNode->Opnd(0), 0); - // recursive call for the new iassign - return SimplifyIassign(node); - } - break; + return SimplifyIassignWithIaddrofBaseNode(*node, static_cast(*opnd)); } default: break;