From f7fe3d370292d4d818ee16ea2634e4b6e9572763 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Fri, 7 Jan 2022 21:45:36 -0800 Subject: [PATCH 1/2] avoid use of PTY_ptr for pointer types in maple parser for C code, to remove inconsistency between .mpl and .bpl --- src/mapleall/maple_ir/include/mir_type.h | 1 + src/mapleall/maple_ir/src/mir_type.cpp | 5 +++++ src/mapleall/maple_ir/src/parser.cpp | 4 ++-- src/mapleall/maple_me/src/me_ivopts.cpp | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mapleall/maple_ir/include/mir_type.h b/src/mapleall/maple_ir/include/mir_type.h index fd26ca391f..e024962155 100644 --- a/src/mapleall/maple_ir/include/mir_type.h +++ b/src/mapleall/maple_ir/include/mir_type.h @@ -37,6 +37,7 @@ constexpr size_t kMaxArrayDim = 10; const std::string kJstrTypeName = "constStr"; #if MIR_FEATURE_FULL extern bool VerifyPrimType(PrimType primType1, PrimType primType2); // verify if primType1 and primType2 match +extern PrimType GetExactPtrPrimType(); // return either PTY_a64 or PTY_a32 extern uint32 GetPrimTypeSize(PrimType primType); // answer in bytes; 0 if unknown extern uint32 GetPrimTypeP2Size(PrimType primType); // answer in bytes in power-of-two. extern PrimType GetSignedPrimType(PrimType primType); // return signed version diff --git a/src/mapleall/maple_ir/src/mir_type.cpp b/src/mapleall/maple_ir/src/mir_type.cpp index b0a6652881..d2c76ddcd1 100644 --- a/src/mapleall/maple_ir/src/mir_type.cpp +++ b/src/mapleall/maple_ir/src/mir_type.cpp @@ -195,6 +195,11 @@ bool IsNoCvtNeeded(PrimType toType, PrimType fromType) { #define POINTER_SIZE 4 #define POINTER_P2SIZE 2 #endif + +PrimType GetExactPtrPrimType() { + return (POINTER_SIZE == 8) ? PTY_a64 : PTY_a32; +} + // answer in bytes; 0 if unknown uint32 GetPrimTypeSize(PrimType primType) { switch (primType) { diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index f9f55b7316..4adcdf6241 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -1214,9 +1214,9 @@ bool MIRParser::ParsePointType(TyIdx &tyIdx) { return false; } ASSERT(pointTypeIdx != 0u, "something wrong with parsing element type "); - PrimType pty = mod.IsJavaModule() ? PTY_ref : PTY_ptr; + PrimType pty = mod.IsJavaModule() ? PTY_ref : GetExactPtrPrimType(); if (pdtk == maple::TK_constStr) { - pty = PTY_ptr; + pty = GetExactPtrPrimType(); } MIRPtrType pointType(pointTypeIdx, pty); // use reference type here if (!ParseTypeAttrs(pointType.GetTypeAttrs())) { diff --git a/src/mapleall/maple_me/src/me_ivopts.cpp b/src/mapleall/maple_me/src/me_ivopts.cpp index 534a712fe8..3edd512ab3 100644 --- a/src/mapleall/maple_me/src/me_ivopts.cpp +++ b/src/mapleall/maple_me/src/me_ivopts.cpp @@ -1437,7 +1437,9 @@ MeExpr *IVOptimizer::ComputeExtraExprOfBase(MeExpr &candBase, MeExpr &groupBase, continue; } if (itGroup == groupMap.end()) { - if (itCand.second.first->GetPrimType() == PTY_ptr) { // it's not good to use one obj to form others + if (itCand.second.first->GetPrimType() == PTY_ptr || + itCand.second.first->GetPrimType() == PTY_a64 || + itCand.second.first->GetPrimType() == PTY_a32) { // it's not good to use one obj to form others replaced = false; return nullptr; } -- Gitee From 0eb49ce4c847150c17440a3a1c4d3b50130e3c3d Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Fri, 14 Jan 2022 19:25:00 -0800 Subject: [PATCH 2/2] Use MustBeAddress() instead of just checking for PTY_ptr, so it can include PTY_a32 and PTY_a64 --- src/mapleall/maple_me/src/me_predict.cpp | 8 ++++---- src/mapleall/maple_me/src/me_stmt_pre.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mapleall/maple_me/src/me_predict.cpp b/src/mapleall/maple_me/src/me_predict.cpp index 18cd057fe9..0f1e9cef8a 100644 --- a/src/mapleall/maple_me/src/me_predict.cpp +++ b/src/mapleall/maple_me/src/me_predict.cpp @@ -107,7 +107,7 @@ Predictor MePrediction::ReturnPrediction(const MeExpr *val, Prediction &predicti return kPredNoPrediction; } PrimType retType = constExpr->GetPrimType(); - if ((retType == PTY_ref || retType == PTY_ptr) && constExpr->IsZero()) { + if (MustBeAddress(retType) && constExpr->IsZero()) { // nullptr is usually not returned. prediction = kNotTaken; return kPredNullReturn; @@ -383,10 +383,10 @@ void MePrediction::PredictByOpcode(const BB *bb) { } PrimType pty = op0->GetPrimType(); - bool isCmpPtr = cmpExpr->GetOpndType() == PTY_ptr || cmpExpr->GetOpndType() == PTY_ref; + bool isCmpPtr = MustBeAddress(cmpExpr->GetOpndType()); // cmpExpr is not always real compare op, so we should check nullptr for op0 and op1 - bool isOpnd0Ptr = op0 != nullptr && (op0->GetPrimType() == PTY_ptr || op0->GetPrimType() == PTY_ref); - bool isOpnd1Ptr = op1 != nullptr && (op1->GetPrimType() == PTY_ptr || op1->GetPrimType() == PTY_ref); + bool isOpnd0Ptr = op0 != nullptr && MustBeAddress(op0->GetPrimType()); + bool isOpnd1Ptr = op1 != nullptr && MustBeAddress(op1->GetPrimType()); // Try "pointer heuristic." A comparison ptr == 0 is predicted as false. // Similarly, a comparison ptr1 == ptr2 is predicted as false. if (isCmpPtr || isOpnd0Ptr || isOpnd1Ptr) { diff --git a/src/mapleall/maple_me/src/me_stmt_pre.cpp b/src/mapleall/maple_me/src/me_stmt_pre.cpp index effd3bcd84..a7a410b5de 100755 --- a/src/mapleall/maple_me/src/me_stmt_pre.cpp +++ b/src/mapleall/maple_me/src/me_stmt_pre.cpp @@ -30,12 +30,12 @@ static bool IsParaAndRetTypeRefOrPtr(const CallMeStmt &stmt) { return false; } for (auto it : stmt.GetOpnds()) { - if (it->GetPrimType() == PTY_ref || it->GetPrimType() == PTY_ptr) { + if (MustBeAddress(it->GetPrimType())) { return true; } } const MeExpr *expr = stmt.GetAssignedLHS(); - if (expr != nullptr && (expr->GetPrimType() == PTY_ref || expr->GetPrimType() == PTY_ptr)) { + if (expr != nullptr && MustBeAddress(expr->GetPrimType())) { return true; } return false; -- Gitee