From 6846f2de384829467f1115817a1dce19ba5fd9d7 Mon Sep 17 00:00:00 2001 From: binaryfz Date: Wed, 21 Apr 2021 15:06:03 +0800 Subject: [PATCH 1/2] [thirdparty]upgrade LLVM ver to 10.0.0 --- build/config.gni | 6 +- build/config/BUILDCONFIG.gn | 2 + src/mapleall/maple_me/include/me_function.h | 1 - src/mapleall/maple_me/src/alias_class.cpp | 6 +- src/mapleall/maple_me/src/hdse.cpp | 7 +- src/mapleall/maple_me/src/me_delegate_rc.cpp | 4 + src/mapleall/maple_me/src/me_function.cpp | 43 ---------- src/mapleall/maple_me/src/me_loop_canon.cpp | 19 ++--- src/mplfe/BUILD.gn | 3 +- src/mplfe/ast_input/include/ast_parser.h | 2 +- src/mplfe/ast_input/src/ast_expr.cpp | 26 +++++- src/mplfe/ast_input/src/ast_parser.cpp | 10 +-- src/mplfe/ast_input/src/ast_stmt.cpp | 12 ++- src/mplfe/common/include/feir_builder.h | 3 + src/mplfe/common/include/feir_stmt.h | 33 +++++--- src/mplfe/common/src/fe_struct_elem_info.cpp | 8 +- src/mplfe/common/src/feir_builder.cpp | 12 +++ src/mplfe/common/src/feir_stmt.cpp | 80 ++++++++++++------- src/mplfe/test/feir_stmt_test.cpp | 40 ++++++++++ src/mplfe/test/jbc_class2fe_helper_test.cpp | 1 - src/mrt/deplibs/libmplandroid.so | Bin 2975136 -> 2975136 bytes third_party/cfe-8.0.0.src | 1 - third_party/clang-10.0.0.src | 1 + tools/setup_tools.sh | 16 ++-- 24 files changed, 207 insertions(+), 129 deletions(-) delete mode 120000 third_party/cfe-8.0.0.src create mode 120000 third_party/clang-10.0.0.src diff --git a/build/config.gni b/build/config.gni index f6ce51249f..9cb3428df1 100644 --- a/build/config.gni +++ b/build/config.gni @@ -15,14 +15,14 @@ # Toolchain setup if (OLD_OS == "1") { - CLANG_PATH = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04" + CLANG_PATH = "${MAPLE_ROOT}/tools/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04" } else { CLANG_PATH = "/usr" } LLVMINC = "${CLANG_PATH}/include" LLVMLIBDIR = "${CLANG_PATH}/lib" -CFE_SRC_DIR = "${MAPLE_ROOT}/../third-party/cfe-8.0.0.src" -CFE_SRC_PATH = "${MAPLE_ROOT}/../ThirdParty/cfe-8.0.0.src" +CFE_SRC_DIR = "${MAPLE_ROOT}/../third-party/clang-10.0.0.src" +CFE_SRC_PATH = "${MAPLE_ROOT}/third_party/clang-10.0.0.src" ANDROID_GCC_PATH = "${MAPLE_ROOT}/tools/gcc" ANDROID_CLANG_PATH = "${MAPLE_ROOT}/tools/clang-r353983c" diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 501c7255f8..8d27416f8d 100755 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -128,6 +128,8 @@ cflags_cc += [ "-fPIE", "-fvisibility=hidden", "-pipe", + "-Wno-c99-designator", + "-Wno-range-loop-construct", "-Werror", "-Wdate-time", "-Wfloat-equal", diff --git a/src/mapleall/maple_me/include/me_function.h b/src/mapleall/maple_me/include/me_function.h index ad220806f7..47f801f28b 100644 --- a/src/mapleall/maple_me/include/me_function.h +++ b/src/mapleall/maple_me/include/me_function.h @@ -518,7 +518,6 @@ class MeFunction : public FuncEmit { std::vector &lowestOrder, std::vector &inStack, std::stack &visitStack); void CreateBasicBlocks(); void SetTryBlockInfo(const StmtNode *nextStmt, StmtNode *tryStmt, BB *lastTryBB, BB *curBB, BB *newBB); - void RemoveEhEdgesInSyncRegion(); MIRFunction *CurFunction() const { return mirModule.CurFunction(); } diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index fdee58c29b..cb19c1202e 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -994,9 +994,8 @@ void AliasClass::CollectMayDefForDassign(const StmtNode &stmt, std::setHasFields()) { - if ((ostOfAliasAe->GetFieldID() < ostOfLhsAe->GetFieldID()) || - (ostOfAliasAe->GetFieldID() > - (ostOfLhsAe->GetFieldID() + static_cast(lhsAeType->NumberOfFieldIDs())))) { + if ((fldIDB < fldIDA) || + (fldIDB > (fldIDA + static_cast(lhsAeType->NumberOfFieldIDs())))) { if (!aliasAeType->HasFields()) { continue; } @@ -1011,6 +1010,7 @@ void AliasClass::CollectMayDefForDassign(const StmtNode &stmt, std::setIsMeStmtEmpty()) { + if (cdBB == &bb) { + continue; + } + if (cdBB->IsMeStmtEmpty()) { + CHECK_FATAL(cdBB->GetAttributes(kBBAttrIsTry), "empty bb in pdom frontier must have try attributes"); + MarkLastStmtInPDomBBRequired(*cdBB); continue; } auto &lastStmt = cdBB->GetMeStmts().back(); diff --git a/src/mapleall/maple_me/src/me_delegate_rc.cpp b/src/mapleall/maple_me/src/me_delegate_rc.cpp index d4a6dbfac0..aba7e49285 100644 --- a/src/mapleall/maple_me/src/me_delegate_rc.cpp +++ b/src/mapleall/maple_me/src/me_delegate_rc.cpp @@ -280,6 +280,10 @@ bool DelegateRC::ContainAllTheUses(const VarMeExpr &rhsVar, const MeStmt &fromSt if (MayThrowException(*cur)) { return false; } + // function call contains yieldpoint, we cant not optimize across a call + if (kOpcodeInfo.IsCall(cur->GetOp()) && !IsIntrinsic(*cur)) { + return false; + } if (IsCleanUpStmt(*cur)) { continue; } diff --git a/src/mapleall/maple_me/src/me_function.cpp b/src/mapleall/maple_me/src/me_function.cpp index 961bad39f4..8e461ef087 100644 --- a/src/mapleall/maple_me/src/me_function.cpp +++ b/src/mapleall/maple_me/src/me_function.cpp @@ -481,7 +481,6 @@ void MeFunction::Prepare(unsigned long rangeNum) { /* there's no basicblock generated */ return; } - RemoveEhEdgesInSyncRegion(); theCFG = memPool->New(*this); theCFG->BuildMirCFG(); if (MeOption::optLevel > mapleOption::kLevelZero) { @@ -647,48 +646,6 @@ LabelIdx MeFunction::GetOrCreateBBLabel(BB &bb) { return label; } -// Recognize the following kind of simple pattern and remove corresponding EH edges -// @label78044 catch { <* void> } -// dassign %Reg0_R524935 0 (regread ptr %%thrownval) -// syncexit (dread ref %Reg8_R460958) -// endtry -// throw (dread ptr %Reg0_R524935) -void MeFunction::RemoveEhEdgesInSyncRegion() { - if (endTryBB2TryBB.size() != 1) { - return; - } - for (auto &pair : endTryBB2TryBB) { - BB *tryBB = pair.second; - BB *endtryBB = pair.first; - CHECK_FATAL(tryBB != nullptr, "null ptr check "); - CHECK_FATAL(endtryBB != nullptr, "null ptr check "); - // Filter out complex cases - if (!(endtryBB->GetAttributes(kBBAttrIsCatch) || endtryBB->GetAttributes(kBBAttrIsJSCatch)) || - endtryBB->GetKind() != kBBFallthru || !endtryBB->GetAttributes(kBBAttrIsTryEnd) || - !endtryBB->GetAttributes(kBBAttrIsJSFinally) || endtryBB->GetStmtNodes().back().GetOpCode() != OP_syncexit || - tryBB->GetStmtNodes().back().GetOpCode() != OP_try) { - return; - } - for (auto &bbTryPair : bbTryNodeMap) { - BB *bb = bbTryPair.first; - if (bb != tryBB && bb != endtryBB) { - for (auto &stmt : bb->GetStmtNodes()) { - if (stmt.GetOpCode() == OP_try || stmt.GetOpCode() == OP_catch || stmt.GetOpCode() == OP_throw) { - return; - } - } - } - } - // Unmark unnecessary isTry flags - for (auto &bbTryPair : bbTryNodeMap) { - BB *bb = bbTryPair.first; - if (bb != tryBB && bb != endtryBB) { - bb->ClearAttributes(kBBAttrIsTry); - } - } - } -} - void MeFunction::BuildSCCDFS(BB &bb, uint32 &visitIndex, std::vector &sccNodes, std::vector &visitedOrder, std::vector &lowestOrder, std::vector &inStack, std::stack &visitStack) { diff --git a/src/mapleall/maple_me/src/me_loop_canon.cpp b/src/mapleall/maple_me/src/me_loop_canon.cpp index c0d799c4a8..705347dd17 100644 --- a/src/mapleall/maple_me/src/me_loop_canon.cpp +++ b/src/mapleall/maple_me/src/me_loop_canon.cpp @@ -470,22 +470,15 @@ void MeDoLoopCanon::SplitCondGotBB(MeFunction &func, LoopDesc &loop) { exitBB->RemoveStmtNode(&stmt); } } + auto label = exitBB->GetBBLabel(); + if (label != 0) { + newFallthru->SetBBLabel(label); + func.SetLabelBBAt(label, newFallthru); + exitBB->SetBBLabel(0); + } while (exitBB->GetPred().size() > 0) { auto *pred = exitBB->GetPred(0); pred->ReplaceSucc(exitBB, newFallthru); - if (pred->GetStmtNodes().empty()) { - continue; - } - StmtNode *lastStmt = &(pred->GetStmtNodes().back()); - if ((lastStmt->GetOpCode() == OP_brtrue || lastStmt->GetOpCode() == OP_brfalse) && - static_cast(lastStmt)->GetOffset() == exitBB->GetBBLabel()) { - LabelIdx label = func.GetOrCreateBBLabel(*newFallthru); - static_cast(lastStmt)->SetOffset(label); - } else if (lastStmt->GetOpCode() == OP_goto && - static_cast(lastStmt)->GetOffset() == exitBB->GetBBLabel()) { - LabelIdx label = func.GetOrCreateBBLabel(*newFallthru); - static_cast(lastStmt)->SetOffset(label); - } } exitBB->RemoveAllPred(); newFallthru->AddSucc(*exitBB); diff --git a/src/mplfe/BUILD.gn b/src/mplfe/BUILD.gn index 4951fd9f5a..35ba2cf82b 100644 --- a/src/mplfe/BUILD.gn +++ b/src/mplfe/BUILD.gn @@ -41,7 +41,7 @@ include_directories = [ "${MPLFE_ROOT}/ast_input/include", "${MPLFE_ROOT}/ast_input/lib", "${LLVMINC}", - "${THIRD_PARTY_ROOT}/cfe-8.0.0.src/tools", + "${THIRD_PARTY_ROOT}/clang-10.0.0.src/tools", ] static_library("lib_mplfe_util") { @@ -268,6 +268,7 @@ static_library("lib_ast_interface") { output_dir = "${root_out_dir}/ar" libs = [ "${LLVMLIBDIR}/libclang.so", + "${LLVMLIBDIR}/libclang-cpp.so", "${LLVMLIBDIR}/libclangFrontend.a", "${LLVMLIBDIR}/libclangDriver.a", "${LLVMLIBDIR}/libclangSerialization.a", diff --git a/src/mplfe/ast_input/include/ast_parser.h b/src/mplfe/ast_input/include/ast_parser.h index 3bb966044d..03086e91a6 100644 --- a/src/mplfe/ast_input/include/ast_parser.h +++ b/src/mplfe/ast_input/include/ast_parser.h @@ -77,7 +77,7 @@ class ASTParser { const clang::Expr *PeelParen(const clang::Expr &expr); ASTUnaryOperatorExpr *AllocUnaryOperatorExpr(MapleAllocator &allocator, const clang::UnaryOperator &expr); ASTExpr *ProcessExpr(MapleAllocator &allocator, const clang::Expr *expr); - ASTBinaryOperatorExpr *AllocBinaryOperatorExpr(MapleAllocator &allocator, const clang::BinaryOperator bo); + ASTBinaryOperatorExpr *AllocBinaryOperatorExpr(MapleAllocator &allocator, const clang::BinaryOperator &bo); #define PROCESS_EXPR(CLASS) ProcessExpr##CLASS(MapleAllocator&, const clang::CLASS&) ASTExpr *PROCESS_EXPR(UnaryOperator); ASTExpr *PROCESS_EXPR(NoInitExpr); diff --git a/src/mplfe/ast_input/src/ast_expr.cpp b/src/mplfe/ast_input/src/ast_expr.cpp index dd7f2ca3f5..6c62eb00e5 100644 --- a/src/mplfe/ast_input/src/ast_expr.cpp +++ b/src/mplfe/ast_input/src/ast_expr.cpp @@ -531,8 +531,30 @@ UniqueFEIRExpr ASTCharacterLiteral::Emit2FEExprImpl(std::list &s // ---------- ASTConditionalOperator ---------- UniqueFEIRExpr ASTConditionalOperator::Emit2FEExprImpl(std::list &stmts) const { - CHECK_FATAL(false, "NIY"); - return nullptr; + UniqueFEIRExpr condFEIRExpr = condExpr->Emit2FEExpr(stmts); + std::list trueStmts; + UniqueFEIRExpr trueFEIRExpr = trueExpr->Emit2FEExpr(trueStmts); + std::list falseStmts; + UniqueFEIRExpr falseFEIRExpr = falseExpr->Emit2FEExpr(falseStmts); + // There are no extra nested statements in the expressions, (e.g., a < 1 ? 1 : 2), use ternary FEIRExpr + if (trueStmts.empty() && falseStmts.empty()) { + return FEIRBuilder::CreateExprTernary(OP_select, std::move(condFEIRExpr), + std::move(trueFEIRExpr), std::move(falseFEIRExpr)); + } + // Otherwise, (e.g., a < 1 ? 1 : a++) create a temporary var to hold the return trueExpr or falseExpr value + CHECK_FATAL(trueFEIRExpr->GetPrimType() == falseFEIRExpr->GetPrimType(), + "The types of trueFEIRExpr and falseFEIRExpr are inconsistent"); + MIRType *retType = trueFEIRExpr->GetType()->GenerateMIRTypeAuto(); + UniqueFEIRVar tempVar = FEIRBuilder::CreateVarNameForC(FEUtils::GetSequentialName("levVar_"), *retType); + UniqueFEIRVar tempVarCloned1 = tempVar->Clone(); + UniqueFEIRVar tempVarCloned2 = tempVar->Clone(); + UniqueFEIRStmt retTrueStmt = FEIRBuilder::CreateStmtDAssign(std::move(tempVar), std::move(trueFEIRExpr)); + trueStmts.emplace_back(std::move(retTrueStmt)); + UniqueFEIRStmt retFalseStmt = FEIRBuilder::CreateStmtDAssign(std::move(tempVarCloned1), std::move(falseFEIRExpr)); + falseStmts.emplace_back(std::move(retFalseStmt)); + UniqueFEIRStmt stmtIf = FEIRBuilder::CreateStmtIf(std::move(condFEIRExpr), trueStmts, falseStmts); + stmts.emplace_back(std::move(stmtIf)); + return FEIRBuilder::CreateExprDRead(std::move(tempVarCloned2)); } // ---------- ASTConstantExpr ---------- diff --git a/src/mplfe/ast_input/src/ast_parser.cpp b/src/mplfe/ast_input/src/ast_parser.cpp index 82220d2d9f..d5b498eed7 100644 --- a/src/mplfe/ast_input/src/ast_parser.cpp +++ b/src/mplfe/ast_input/src/ast_parser.cpp @@ -39,7 +39,7 @@ bool ASTParser::Verify() { return true; } -ASTBinaryOperatorExpr *ASTParser::AllocBinaryOperatorExpr(MapleAllocator &allocator, const clang::BinaryOperator bo) { +ASTBinaryOperatorExpr *ASTParser::AllocBinaryOperatorExpr(MapleAllocator &allocator, const clang::BinaryOperator &bo) { if (bo.isAssignmentOp() && !bo.isCompoundAssignmentOp()) { if (bo.isCompoundAssignmentOp()) { auto *expr = ASTDeclsBuilder::ASTExprBuilder(allocator); @@ -1474,8 +1474,8 @@ bool ASTParser::RetrieveStructs(MapleAllocator &allocator, MapleList bool ASTParser::RetrieveFuncs(MapleAllocator &allocator, MapleList &funcs) { for (auto &func : funcDecles) { - clang::FunctionDecl funcDecl = llvm::cast(*func); - ASTFunc *af = static_cast(ProcessDecl(allocator, funcDecl)); + clang::FunctionDecl *funcDecl = llvm::cast(func); + ASTFunc *af = static_cast(ProcessDecl(allocator, *funcDecl)); if (af == nullptr) { return false; } @@ -1488,8 +1488,8 @@ bool ASTParser::RetrieveFuncs(MapleAllocator &allocator, MapleList &fu // seperate MP with astparser bool ASTParser::RetrieveGlobalVars(MapleAllocator &allocator, MapleList &vars) { for (auto &decl : globalVarDecles) { - clang::VarDecl varDecl = llvm::cast(*decl); - ASTVar *val = static_cast(ProcessDecl(allocator, varDecl)); + clang::VarDecl *varDecl = llvm::cast(decl); + ASTVar *val = static_cast(ProcessDecl(allocator, *varDecl)); if (val == nullptr) { return false; } diff --git a/src/mplfe/ast_input/src/ast_stmt.cpp b/src/mplfe/ast_input/src/ast_stmt.cpp index 30f924dcff..042aaa7208 100644 --- a/src/mplfe/ast_input/src/ast_stmt.cpp +++ b/src/mplfe/ast_input/src/ast_stmt.cpp @@ -60,13 +60,10 @@ void ASTDeclRefExpr::SetASTDecl(ASTDecl *astDecl) { std::list ASTIfStmt::Emit2FEStmtImpl() const { std::list stmts; std::list thenStmts = thenStmt->Emit2FEStmt(); + std::list elseStmts = elseStmt->Emit2FEStmt(); UniqueFEIRExpr condFEExpr = condExpr->Emit2FEExpr(stmts); - std::unique_ptr ifStmt = std::make_unique(std::move(condFEExpr), std::move(thenStmts)); - if (elseStmt != nullptr) { - std::list elseStmts = elseStmt->Emit2FEStmt(); - ifStmt->SetHasElse(true); - ifStmt->SetElseStmts(std::move(elseStmts)); - } + UniqueFEIRStmt ifStmt; + ifStmt = FEIRBuilder::CreateStmtIf(std::move(condFEExpr), thenStmts, elseStmts); stmts.emplace_back(std::move(ifStmt)); return stmts; } @@ -268,8 +265,9 @@ std::list ASTVAArgExprStmt::Emit2FEStmtImpl() const { // ---------- ASTConditionalOperatorStmt ---------- std::list ASTConditionalOperatorStmt::Emit2FEStmtImpl() const { - CHECK_FATAL(false, "NYI"); std::list stmts; + auto astExpr = exprs.front(); + astExpr->Emit2FEExpr(stmts); return stmts; } diff --git a/src/mplfe/common/include/feir_builder.h b/src/mplfe/common/include/feir_builder.h index 099cc19781..09711b5055 100644 --- a/src/mplfe/common/include/feir_builder.h +++ b/src/mplfe/common/include/feir_builder.h @@ -84,6 +84,9 @@ class FEIRBuilder { static UniqueFEIRStmt CreateStmtGoto(std::string labelName); static UniqueFEIRStmt CreateStmtCondGoto(uint32 targetLabelIdx, Opcode op, UniqueFEIRExpr expr); static UniqueFEIRStmt CreateStmtSwitch(UniqueFEIRExpr expr); + static UniqueFEIRStmt CreateStmtIfWithoutElse(UniqueFEIRExpr cond, std::list &thenStmts); + static UniqueFEIRStmt CreateStmtIf(UniqueFEIRExpr cond, std::list &thenStmts, + std::list &elseStmts); static UniqueFEIRStmt CreateStmtJavaConstClass(UniqueFEIRVar dstVar, UniqueFEIRType type); static UniqueFEIRStmt CreateStmtJavaConstString(UniqueFEIRVar dstVar, const std::string &strVal); static UniqueFEIRStmt CreateStmtJavaCheckCast(UniqueFEIRVar dstVar, UniqueFEIRVar srcVar, UniqueFEIRType type); diff --git a/src/mplfe/common/include/feir_stmt.h b/src/mplfe/common/include/feir_stmt.h index 83f41e0173..9547217686 100644 --- a/src/mplfe/common/include/feir_stmt.h +++ b/src/mplfe/common/include/feir_stmt.h @@ -1052,7 +1052,7 @@ class FEIRStmtDAssign : public FEIRStmtAssign { std::string fieldName; }; -// ---------- FEIRStmtDAssign ---------- +// ---------- FEIRStmtIAssign ---------- class FEIRStmtIAssign : public FEIRStmt { public: FEIRStmtIAssign(UniqueFEIRType argAddrType, UniqueFEIRExpr argAddrExpr, UniqueFEIRExpr argBaseExpr, FieldID id) @@ -1941,28 +1941,43 @@ class FEIRStmtPesudoCommentForInst : public FEIRStmtPesudoComment { uint32 pc = invalid; }; +// ---------- FEIRStmtIf ---------- class FEIRStmtIf : public FEIRStmt { public: - FEIRStmtIf(UniqueFEIRExpr argCondExpr, std::list argThenStmts) - : FEIRStmt(FEIRNodeKind::kStmtIf), - condExpr(std::move(argCondExpr)), - thenStmts(std::move(argThenStmts)) {} + FEIRStmtIf(UniqueFEIRExpr argCondExpr, std::list &argThenStmts); + FEIRStmtIf(UniqueFEIRExpr argCondExpr, + std::list &argThenStmts, + std::list &argElseStmts); ~FEIRStmtIf() = default; + void SetCondExpr(UniqueFEIRExpr argCondExpr) { + CHECK_NULL_FATAL(argCondExpr); + condExpr = std::move(argCondExpr); + } + void SetHasElse(bool argHasElse) { hasElse = argHasElse; } - void SetElseStmts(std::list argElseStmts) { - elseStmts = std::move(argElseStmts); + void SetThenStmts(std::list &stmts) { + std::move(begin(stmts), end(stmts), std::inserter(thenStmts, end(thenStmts))); + } + + void SetElseStmts(std::list &stmts) { + std::move(begin(stmts), end(stmts), std::inserter(elseStmts, end(elseStmts))); } protected: - bool IsBranchImpl() const override { + std::string DumpDotStringImpl() const override; + std::list GenMIRStmtsImpl(MIRBuilder &mirBuilder) const override; + + bool IsFallThroughImpl() const override { return true; } - std::list GenMIRStmtsImpl(MIRBuilder &mirBuilder) const override; + bool IsBranchImpl() const override { + return true; + } private: UniqueFEIRExpr condExpr; diff --git a/src/mplfe/common/src/fe_struct_elem_info.cpp b/src/mplfe/common/src/fe_struct_elem_info.cpp index a1f92e259c..3855f40fc7 100644 --- a/src/mplfe/common/src/fe_struct_elem_info.cpp +++ b/src/mplfe/common/src/fe_struct_elem_info.cpp @@ -64,6 +64,10 @@ void FEStructFieldInfo::PrepareImpl(MIRBuilder &mirBuilder, bool argIsStatic) { actualContainer = GetStructName(); const std::string stdActualContainer = actualContainer.c_str(); std::string rawName = stdActualContainer + namemangler::kNameSplitterStr + GetElemName(); + if (isStatic && + FEOptions::GetInstance().GetModeJavaStaticFieldName() != FEOptions::ModeJavaStaticFieldName::kNoType) { + rawName = rawName + namemangler::kNameSplitterStr + GetSignatureName(); + } fieldNameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(rawName); MIRStructType *structType = FEManager::GetTypeManager().GetStructTypeFromName(stdActualContainer); if (structType == nullptr) { @@ -75,7 +79,6 @@ void FEStructFieldInfo::PrepareImpl(MIRBuilder &mirBuilder, bool argIsStatic) { if (isDefined) { return; } - rawName = rawName + namemangler::kNameSplitterStr + GetSignatureName(); WARN(kLncErr, "use undefined %s field %s", argIsStatic ? "static" : "", rawName.c_str()); isPrepared = true; isStatic = argIsStatic; @@ -105,6 +108,9 @@ void FEStructFieldInfo::PrepareStaticField(const MIRStructType &structType) { std::string ownerStructName = structType.GetName(); const std::string &fieldName = GetElemName(); std::string fullName = ownerStructName + namemangler::kNameSplitterStr + fieldName; + if (FEOptions::GetInstance().GetModeJavaStaticFieldName() != FEOptions::ModeJavaStaticFieldName::kNoType) { + fullName += namemangler::kNameSplitterStr + GetSignatureName(); + } fieldNameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(fullName); isPrepared = true; isStatic = true; diff --git a/src/mplfe/common/src/feir_builder.cpp b/src/mplfe/common/src/feir_builder.cpp index 0242f9a282..de76844e2b 100644 --- a/src/mplfe/common/src/feir_builder.cpp +++ b/src/mplfe/common/src/feir_builder.cpp @@ -301,6 +301,18 @@ UniqueFEIRStmt FEIRBuilder::CreateStmtSwitch(UniqueFEIRExpr expr) { return stmt; } +UniqueFEIRStmt FEIRBuilder::CreateStmtIfWithoutElse(UniqueFEIRExpr cond, std::list &thenStmts) { + UniqueFEIRStmt stmt = std::make_unique(std::move(cond), thenStmts); + return stmt; +} + +UniqueFEIRStmt FEIRBuilder::CreateStmtIf(UniqueFEIRExpr cond, + std::list &thenStmts, + std::list &elseStmts) { + UniqueFEIRStmt stmt = std::make_unique(std::move(cond), thenStmts, elseStmts); + return stmt; +} + UniqueFEIRStmt FEIRBuilder::CreateStmtJavaConstClass(UniqueFEIRVar dstVar, UniqueFEIRType type) { UniqueFEIRType dstType = FETypeManager::kFEIRTypeJavaClass->Clone(); dstVar->SetType(std::move(dstType)); diff --git a/src/mplfe/common/src/feir_stmt.cpp b/src/mplfe/common/src/feir_stmt.cpp index 967674f065..515288c0a5 100644 --- a/src/mplfe/common/src/feir_stmt.cpp +++ b/src/mplfe/common/src/feir_stmt.cpp @@ -909,6 +909,57 @@ std::string FEIRStmtSwitch2::DumpDotStringImpl() const { return ss.str(); } +// ---------- FEIRStmtIf ---------- +FEIRStmtIf::FEIRStmtIf(UniqueFEIRExpr argCondExpr, std::list &argThenStmts) + : FEIRStmt(FEIRNodeKind::kStmtIf) { + SetCondExpr(std::move(argCondExpr)); + hasElse = false; + SetThenStmts(argThenStmts); +} + +FEIRStmtIf::FEIRStmtIf(UniqueFEIRExpr argCondExpr, + std::list &argThenStmts, + std::list &argElseStmts) + : FEIRStmt(FEIRNodeKind::kStmtIf) { + SetCondExpr(std::move(argCondExpr)); + SetThenStmts(argThenStmts); + if (argElseStmts.empty()) { + hasElse = false; + } else { + hasElse = true; + SetElseStmts(argElseStmts); + } +} + +std::list FEIRStmtIf::GenMIRStmtsImpl(MIRBuilder &mirBuilder) const { + BaseNode *condBase = condExpr->GenMIRNode(mirBuilder); + IfStmtNode *stmt; + if (hasElse) { + stmt = mirBuilder.CreateStmtIfThenElse(condBase); + } else { + stmt = mirBuilder.CreateStmtIf(condBase); + } + for (const auto &thenStmt : thenStmts) { + for(auto thenNode : thenStmt->GenMIRStmts(mirBuilder)) { + stmt->GetThenPart()->AddStatement(thenNode); + } + } + if (hasElse) { + for (const auto &elseStmt : elseStmts) { + for(auto elseNode : elseStmt->GenMIRStmts(mirBuilder)) { + stmt->GetElsePart()->AddStatement(elseNode); + } + } + } + return std::list({ stmt }); +} + +std::string FEIRStmtIf::DumpDotStringImpl() const { + std::stringstream ss; + ss << " " << id << ": " << GetFEIRNodeKindDescription(kind); + return ss.str(); +} + // ---------- FEIRStmtSwitchForC ---------- FEIRStmtSwitchForC::FEIRStmtSwitchForC(UniqueFEIRExpr argCondExpr, bool argHasDefault) : FEIRStmt(FEIRNodeKind::kStmtSwitch), @@ -3409,35 +3460,6 @@ std::list FEIRStmtIAssign::GenMIRStmtsImpl(MIRBuilder &mirBuilder) co return ans; } -std::list FEIRStmtIf::GenMIRStmtsImpl(MIRBuilder &mirBuilder) const { - std::list stmts; - IfStmtNode *ifNode; - BaseNode *condNode = condExpr->GenMIRNode(mirBuilder); - if (hasElse) { - ifNode = mirBuilder.CreateStmtIfThenElse(condNode); - } else { - ifNode = mirBuilder.CreateStmtIf(condNode); - } - BlockNode *thenBlock = ifNode->GetThenPart(); - for (auto &stmt : thenStmts) { - std::list mirStmts = stmt->GenMIRStmts(mirBuilder); - for (auto stmtNode : mirStmts) { - thenBlock->AddStatement(stmtNode); - } - } - if (hasElse) { - BlockNode *elseBlock = ifNode->GetElsePart(); - for (auto &stmt : elseStmts) { - std::list mirStmts = stmt->GenMIRStmts(mirBuilder); - for (auto stmtNode : mirStmts) { - elseBlock->AddStatement(stmtNode); - } - } - } - stmts.emplace_back(ifNode); - return stmts; -} - std::list FEIRStmtDoWhile::GenMIRStmtsImpl(MIRBuilder &mirBuilder) const { std::list stmts; auto *whileStmtNode = mirBuilder.GetCurrentFuncCodeMp()->New(opcode); diff --git a/src/mplfe/test/feir_stmt_test.cpp b/src/mplfe/test/feir_stmt_test.cpp index 3736e32a98..c568edd6b8 100644 --- a/src/mplfe/test/feir_stmt_test.cpp +++ b/src/mplfe/test/feir_stmt_test.cpp @@ -297,6 +297,46 @@ TEST_F(FEIRStmtTest, FEIRExprTernary_add) { EXPECT_EQ(expr2->IsAddrof(), false); } +// ---------- FEIRStmtIf ---------- +TEST_F(FEIRStmtTest, FEIRStmtIf) { + // CondExpr + UniqueFEIRVar varReg = FEIRBuilder::CreateVarReg(0, PTY_u1); + std::unique_ptr exprDReadReg = std::make_unique(std::move(varReg)); + // ThenStmts + UniqueFEIRVar dstVar = FEIRBuilder::CreateVarReg(0, PTY_i32); + UniqueFEIRVar dstVar1 = dstVar->Clone(); + UniqueFEIRVar srcVar = std::make_unique(1, PTY_i32); + UniqueFEIRExpr exprDRead = std::make_unique(std::move(srcVar)); + UniqueFEIRExpr exprDRead1 = exprDRead->Clone(); + UniqueFEIRStmt stmtDAssign = std::make_unique(std::move(dstVar), std::move(exprDRead)); + std::list thenStmts; + thenStmts.emplace_back(std::move(stmtDAssign)); + // ElseStmts + UniqueFEIRVar dstVar2 = dstVar1->Clone(); + UniqueFEIRExpr exprDRead2 = exprDRead1->Clone(); + UniqueFEIRStmt stmtDAssign1 = std::make_unique(std::move(dstVar1), std::move(exprDRead1)); + UniqueFEIRStmt stmtDAssign2 = std::make_unique(std::move(dstVar2), std::move(exprDRead2)); + std::list elseStmts; + elseStmts.emplace_back(std::move(stmtDAssign1)); + elseStmts.emplace_back(std::move(stmtDAssign2)); + + std::unique_ptr stmt = + std::make_unique(std::move(exprDReadReg), thenStmts, elseStmts); + std::list baseNodes = stmt->GenMIRStmts(mirBuilder); + RedirectCout(); + baseNodes.front()->Dump(); + std::string pattern = + "if (dread u1 %Reg0_Z) {\n"\ + " dassign %Reg0_I 0 (dread i32 %Reg1_I)\n"\ + "}\n"\ + "else {\n"\ + " dassign %Reg0_I 0 (dread i32 %Reg1_I)\n"\ + " dassign %Reg0_I 0 (dread i32 %Reg1_I)\n"\ + "}\n\n"; + EXPECT_EQ(GetBufferString(), pattern); + RestoreCout(); +} + // ---------- FEIRStmtDAssign ---------- TEST_F(FEIRStmtTest, FEIRStmtDAssign) { std::unique_ptr type = FEIRTypeHelper::CreateTypeByJavaName("Ljava/lang/String;", false, true); diff --git a/src/mplfe/test/jbc_class2fe_helper_test.cpp b/src/mplfe/test/jbc_class2fe_helper_test.cpp index a93b4b55db..17db7f2ce7 100644 --- a/src/mplfe/test/jbc_class2fe_helper_test.cpp +++ b/src/mplfe/test/jbc_class2fe_helper_test.cpp @@ -312,7 +312,6 @@ TEST_F(JBCClassField2FEHelperTest, ProcessDeclWithContainer_Instance) { ON_CALL(field, GetName()).WillByDefault(::testing::Return("field")); ON_CALL(field, GetDescription()).WillByDefault(::testing::Return("Ljava/lang/Object;")); JBCClassField2FEHelper fieldHelper(allocator, field); - std::cout << "field name : " << field.jbc::JBCClassElem::GetName() << std::endl; ASSERT_EQ(fieldHelper.ProcessDeclWithContainer(allocator), true); // check field name std::string fieldName = GlobalTables::GetStrTable().GetStringFromStrIdx(fieldHelper.mirFieldPair.first); diff --git a/src/mrt/deplibs/libmplandroid.so b/src/mrt/deplibs/libmplandroid.so index 48552d4c7d630b5a718984b1cd2a20c40f042154..69ce02e3388c0780bc66cfed65f426cc7e61ec6c 100755 GIT binary patch delta 206 zcmWm7xfOyy6hP54E~qH3!{Qee_q_&kV>>dS02-hK13jeVG%<9-Gq~~1%Ad;c`AYf{ zt>Uy2|7|2OqR>DSEwo{wgD!fo(Z>J|h8SUt38t7q!-WSQ0p|EW3xrr=g*75hshq)DO9* z5?IHtrg^use^GK(qN4!=CM+~zqlGpcbl{?k9{TVwzz{wHgcxCr38wfzGt9BT5)opo WkYJ4z8*GtbhdmC+QM{Ct@6!*y+EZ)* diff --git a/third_party/cfe-8.0.0.src b/third_party/cfe-8.0.0.src deleted file mode 120000 index 2c2069a2f2..0000000000 --- a/third_party/cfe-8.0.0.src +++ /dev/null @@ -1 +0,0 @@ -../../ThirdParty/cfe-8.0.0.src \ No newline at end of file diff --git a/third_party/clang-10.0.0.src b/third_party/clang-10.0.0.src new file mode 120000 index 0000000000..f846ad906e --- /dev/null +++ b/third_party/clang-10.0.0.src @@ -0,0 +1 @@ +../../ThirdParty/clang-10.0.0.src \ No newline at end of file diff --git a/tools/setup_tools.sh b/tools/setup_tools.sh index 2583de33fe..e4b307f2d7 100755 --- a/tools/setup_tools.sh +++ b/tools/setup_tools.sh @@ -32,12 +32,12 @@ ANDROID_SRCDIR=$MAPLE_ROOT/../android/$ANDROID_VERSION ANDROID_DIR=$MAPLE_ROOT/android if [ "$OLD_OS" == "1" ]; then - if [ ! -f $TOOLS/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang ]; then + if [ ! -f $TOOLS/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang ]; then cd $TOOLS - echo Start wget llvm-8.0.0 ... - wget https://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz + echo Start wget llvm-10.0.0 ... + wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz echo unpacking clang+llvm ... - tar xf clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz + tar xf clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz echo Downloaded clang+llvm. fi fi @@ -168,10 +168,10 @@ fi mkdir -p ${TOOL_BIN_PATH} if [ "$OLD_OS" == "1" ]; then - ln -s -f ${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++ ${TOOL_BIN_PATH}/clang++ - ln -s -f ${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang ${TOOL_BIN_PATH}/clang - ln -s -f ${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar ${TOOL_BIN_PATH}/llvm-ar - ln -s -f ${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ranlib ${TOOL_BIN_PATH}/llvm-ranlib + ln -s -f ${MAPLE_ROOT}/tools/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ ${TOOL_BIN_PATH}/clang++ + ln -s -f ${MAPLE_ROOT}/tools/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang ${TOOL_BIN_PATH}/clang + ln -s -f ${MAPLE_ROOT}/tools/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/llvm-ar ${TOOL_BIN_PATH}/llvm-ar + ln -s -f ${MAPLE_ROOT}/tools/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/llvm-ranlib ${TOOL_BIN_PATH}/llvm-ranlib ln -s -f /usr/bin/qemu-aarch64 ${TOOL_BIN_PATH}/qemu-aarch64 else ln -s -f /usr/bin/clang++ ${TOOL_BIN_PATH}/clang++ -- Gitee From 22aec0e7ab190fceb55c01cd6c7d05ca4c0a8464 Mon Sep 17 00:00:00 2001 From: binaryfz Date: Wed, 21 Apr 2021 16:51:34 +0800 Subject: [PATCH 2/2] [mplcg]Do not allow scheduler to move memory ops across calls for C --- .../maple_be/include/be/common_utils.h | 1 + .../include/cg/aarch64/aarch64_cgfunc.h | 20 +++---- .../include/cg/aarch64/aarch64_operand.h | 31 ++++++++++- src/mapleall/maple_be/include/cg/datainfo.h | 13 ++++- .../src/cg/aarch64/aarch64_cgfunc.cpp | 50 +++++++++++------- .../src/cg/aarch64/aarch64_dependence.cpp | 3 ++ src/mapleall/maple_be/src/cg/emit.cpp | 1 - src/mapleall/maple_be/src/cg/live.cpp | 4 +- src/mapleall/maple_ir/include/types_def.h | 15 ++++++ src/mapleall/maple_util/include/mpl_number.h | 9 ++++ src/mrt/deplibs/libmplandroid.so | Bin 2975136 -> 2975136 bytes 11 files changed, 114 insertions(+), 33 deletions(-) diff --git a/src/mapleall/maple_be/include/be/common_utils.h b/src/mapleall/maple_be/include/be/common_utils.h index e3b514d2b0..a487d101a7 100644 --- a/src/mapleall/maple_be/include/be/common_utils.h +++ b/src/mapleall/maple_be/include/be/common_utils.h @@ -42,6 +42,7 @@ constexpr uint32 k48BitSize = 48; constexpr uint32 k56BitSize = 56; constexpr uint32 k64BitSize = 64; constexpr uint32 k128BitSize = 128; +constexpr uint32 k256BitSize = 256; constexpr uint32 k1ByteSize = 1; constexpr uint32 k2ByteSize = 2; diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h index 94a31e94d9..d6b86cfca2 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -31,12 +31,12 @@ class AArch64CGFunc : public CGFunc { : CGFunc(mod, c, f, b, memPool, mallocator, funcId), calleeSavedRegs(mallocator.Adapter()), formalRegList(mallocator.Adapter()), - phyRegOperandTable(std::less(), mallocator.Adapter()), + phyRegOperandTable(mallocator.Adapter()), hashLabelOpndTable(mallocator.Adapter()), - hashOfstOpndTable(std::less(), mallocator.Adapter()), - hashMemOpndTable(std::less(), mallocator.Adapter()), - memOpndsRequiringOffsetAdjustment(std::less(), mallocator.Adapter()), - memOpndsForStkPassedArguments(std::less(), mallocator.Adapter()), + hashOfstOpndTable(mallocator.Adapter()), + hashMemOpndTable(mallocator.Adapter()), + memOpndsRequiringOffsetAdjustment(mallocator.Adapter()), + memOpndsForStkPassedArguments(mallocator.Adapter()), immOpndsRequiringOffsetAdjustment(mallocator.Adapter()), immOpndsRequiringOffsetAdjustmentForRefloc(mallocator.Adapter()) { uCatch.regNOCatch = 0; @@ -516,16 +516,16 @@ class AArch64CGFunc : public CGFunc { Insn *yieldPointInsn = nullptr; /* The insn of yield point at the entry of the func. */ IntrinsiccallNode *cleanEANode = nullptr; - MapleMap phyRegOperandTable; /* machine register operand table */ + MapleUnorderedMap phyRegOperandTable; /* machine register operand table */ MapleUnorderedMap hashLabelOpndTable; - MapleMap hashOfstOpndTable; - MapleMap hashMemOpndTable; + MapleUnorderedMap hashOfstOpndTable; + MapleUnorderedMap hashMemOpndTable; /* * Local variables, formal parameters that are passed via registers * need offset adjustment after callee-saved registers are known. */ - MapleMap memOpndsRequiringOffsetAdjustment; - MapleMap memOpndsForStkPassedArguments; + MapleUnorderedMap memOpndsRequiringOffsetAdjustment; + MapleUnorderedMap memOpndsForStkPassedArguments; MapleUnorderedMap immOpndsRequiringOffsetAdjustment; MapleUnorderedMap immOpndsRequiringOffsetAdjustmentForRefloc; union { diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_operand.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_operand.h index 79ca62de99..02f9a7e1f2 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_operand.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_operand.h @@ -727,6 +727,14 @@ class AArch64MemOperand : public MemOperand { GetSymbol() == opnd.GetSymbol() && GetSize() < opnd.GetSize()); } + bool operator==(const AArch64MemOperand &opnd) const { + return (GetSize() == opnd.GetSize()) && (addrMode == opnd.addrMode) && + (GetBaseRegister() == opnd.GetBaseRegister()) && + (GetIndexRegister() == opnd.GetIndexRegister()) && + (GetSymbol() == opnd.GetSymbol()) && + (GetOffsetOperand() == opnd.GetOffsetOperand()); + } + bool Less(const Operand &right) const override; bool NoAlias(AArch64MemOperand &rightOpnd) const; @@ -1035,5 +1043,26 @@ class CommentOperand : public Operand { const MapleString comment; }; } /* namespace maplebe */ - +namespace std { +template<> /* function-template-specialization */ +class std::hash { + public: + size_t operator()(const maplebe::AArch64MemOperand &x) const { + std::size_t seed = 0; + hash_combine(seed, x.GetAddrMode()); + hash_combine(seed, x.GetSize()); + maplebe::RegOperand *xb = x.GetBaseRegister(); + maplebe::RegOperand *xi = x.GetIndexRegister(); + if (xb != nullptr) { + hash_combine(seed, xb->GetRegisterNumber()); + hash_combine(seed, xb->GetSize()); + } + if (xi != nullptr) { + hash_combine(seed, xi->GetRegisterNumber()); + hash_combine(seed, xi->GetSize()); + } + return seed; + } +}; +} #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_OPERAND_H */ diff --git a/src/mapleall/maple_be/include/cg/datainfo.h b/src/mapleall/maple_be/include/cg/datainfo.h index d60b55bee6..eee252fb21 100644 --- a/src/mapleall/maple_be/include/cg/datainfo.h +++ b/src/mapleall/maple_be/include/cg/datainfo.h @@ -75,7 +75,7 @@ class DataInfo { bool IsEqual(const DataInfo &secondInfo) const { auto infoSize = static_cast(info.size()); ASSERT(infoSize == secondInfo.GetInfo().size(), "two dataInfo's size different"); - for (int32 i = 0; i != infoSize; i++) { + for (int32 i = 0; i != infoSize; ++i) { if (info[i] != secondInfo.GetElem(i)) { return false; } @@ -83,6 +83,17 @@ class DataInfo { return true; } + bool IsEqual(const MapleVector &LiveInfoBak) const { + size_t infoSize = info.size(); + ASSERT(infoSize == LiveInfoBak.size(), "two dataInfo's size different"); + for (size_t i = 0; i != infoSize; ++i) { + if (info[i] != LiveInfoBak[i]) { + return false; + } + } + return true; + } + void AndBits(const DataInfo &secondInfo) { auto infoSize = static_cast(info.size()); ASSERT(infoSize == secondInfo.GetInfo().size(), "two dataInfo's size different"); 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 94933caf1a..2fca02d169 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -1996,13 +1996,13 @@ Operand *SelectLiteral(T *c, MIRFunction *func, uint32 labelIdx, AArch64CGFunc * return static_cast(&cgFunc->GetOrCreateMemOpnd(*st, 0, typeBitSize)); } if (T::GetPrimType() == PTY_f32) { - return (fabs(c->GetValue()) < std::numeric_limits::denorm_min()) - ? static_cast(&cgFunc->GetOrCreateFpZeroOperand(typeBitSize)) - : static_cast(&cgFunc->GetOrCreateMemOpnd(*st, 0, typeBitSize)); + return (fabs(c->GetValue()) < std::numeric_limits::denorm_min()) ? + static_cast(&cgFunc->GetOrCreateFpZeroOperand(typeBitSize)) : + static_cast(&cgFunc->GetOrCreateMemOpnd(*st, 0, typeBitSize)); } else if (T::GetPrimType() == PTY_f64) { - return (fabs(c->GetValue()) < std::numeric_limits::denorm_min()) - ? static_cast(&cgFunc->GetOrCreateFpZeroOperand(typeBitSize)) - : static_cast(&cgFunc->GetOrCreateMemOpnd(*st, 0, typeBitSize)); + return (fabs(c->GetValue()) < std::numeric_limits::denorm_min()) ? + static_cast(&cgFunc->GetOrCreateFpZeroOperand(typeBitSize)) : + static_cast(&cgFunc->GetOrCreateMemOpnd(*st, 0, typeBitSize)); } else { CHECK_FATAL(false, "Unsupported const type"); } @@ -6250,16 +6250,25 @@ RegOperand &AArch64CGFunc::GetOrCreateSpecialRegisterOperand(PregIdx sregIdx, Pr AArch64RegOperand &AArch64CGFunc::GetOrCreatePhysicalRegisterOperand(AArch64reg regNO, uint32 size, RegType kind, uint32 flag) { - size = (size <= k32BitSize) ? k32BitSize : k64BitSize; - - auto it = phyRegOperandTable.find(AArch64RegOperand(regNO, size, kind, flag)); - if (it != phyRegOperandTable.end()) { - return *(it->second); + uint64 aarch64PhyRegIdx = regNO; + ASSERT(flag == 0, "Do not expect flag here"); + if (size <= k32BitSize) { + size = k32BitSize; + aarch64PhyRegIdx = aarch64PhyRegIdx << 1; + } else { + size = k64BitSize; + aarch64PhyRegIdx = (aarch64PhyRegIdx << 1) + 1; + } + ASSERT(aarch64PhyRegIdx < k256BitSize, "phyRegOperandTable index out of range"); + AArch64RegOperand *phyRegOpnd = nullptr; + auto phyRegIt = phyRegOperandTable.find(aarch64PhyRegIdx); + if (phyRegIt != phyRegOperandTable.end()) { + phyRegOpnd = phyRegOperandTable[aarch64PhyRegIdx]; + } else { + phyRegOpnd = memPool->New(regNO, size, kind, flag); + phyRegOperandTable.insert({aarch64PhyRegIdx, phyRegOpnd}); } - - AArch64RegOperand *o = memPool->New(regNO, size, kind, flag); - phyRegOperandTable[*o] = o; - return *o; + return *phyRegOpnd; } const LabelOperand *AArch64CGFunc::GetLabelOperand(LabelIdx labIdx) const { @@ -6296,13 +6305,18 @@ LabelOperand &AArch64CGFunc::CreateFuncLabelOperand(const MIRSymbol &funcSymbol) } AArch64OfstOperand &AArch64CGFunc::GetOrCreateOfstOpnd(uint32 offset, uint32 size) { - AArch64OfstOperand tOfstOpnd(offset, size); - auto it = hashOfstOpndTable.find(tOfstOpnd); + uint64 aarch64OfstRegIdx = offset; + aarch64OfstRegIdx = (aarch64OfstRegIdx << 1); + if (size == k64BitSize) { + ++aarch64OfstRegIdx; + } + ASSERT(size == k32BitSize || size == k64BitSize, "ofStOpnd size check"); + auto it = hashOfstOpndTable.find(aarch64OfstRegIdx); if (it != hashOfstOpndTable.end()) { return *it->second; } AArch64OfstOperand *res = memPool->New(offset, size); - hashOfstOpndTable[tOfstOpnd] = res; + hashOfstOpndTable[aarch64OfstRegIdx] = res; return *res; } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_dependence.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_dependence.cpp index 7b091a64c5..ba3790b5cd 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_dependence.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_dependence.cpp @@ -840,6 +840,9 @@ void AArch64DepAnalysis::BuildSpecialInsnDependency(Insn &insn, DepNode &depNode (target.GetName() == "MCC_CleanupLocalStackRefSkip")) { /* UseStackMemory. */ BuildDepsUseStack(insn); + } else if (cgFunc.GetMirModule().GetSrcLang() == kSrcLangC) { + /* potential C aliasing. */ + BuildDepsDirtyStack(insn); } } BuildDepsDirtyHeap(insn); diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index bcef38c68d..615ca4cce2 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -1523,7 +1523,6 @@ void Emitter::EmitStructConstant(MIRConst &mirConst) { MIRType &mirType = mirConst.GetType(); MIRAggConst &structCt = static_cast(mirConst); MIRStructType &structType = static_cast(mirType); - ASSERT(structType.GetKind() != kTypeUnion, "NYI, not support now."); /* all elements of struct. */ uint8 num; if (structType.GetKind() == kTypeUnion) { diff --git a/src/mapleall/maple_be/src/cg/live.cpp b/src/mapleall/maple_be/src/cg/live.cpp index 1c4a2166cf..571e49127d 100644 --- a/src/mapleall/maple_be/src/cg/live.cpp +++ b/src/mapleall/maple_be/src/cg/live.cpp @@ -56,7 +56,7 @@ void LiveAnalysis::InitAndGetDefUse() { /* Out[BB] = Union all of In[Succs(BB)] */ bool LiveAnalysis::GenerateLiveOut(BB &bb) { - DataInfo bbLiveOutBak = *(bb.GetLiveOut()); + const MapleVectorbbLiveOutBak(bb.GetLiveOut()->GetInfo()); for (auto succBB : bb.GetSuccs()) { if (succBB->GetLiveInChange() && !succBB->GetLiveIn()->NoneBit()) { bb.LiveOutOrBits(*succBB->GetLiveIn()); @@ -81,7 +81,7 @@ bool LiveAnalysis::GenerateLiveOut(BB &bb) { /* In[BB] = use[BB] Union (Out[BB]-def[BB]) */ bool LiveAnalysis::GenerateLiveIn(BB &bb) { - DataInfo bbLiveInBak = *(bb.GetLiveIn()); + const MapleVectorbbLiveInBak(bb.GetLiveIn()->GetInfo()); if (!bb.GetInsertUse()) { bb.SetLiveInInfo(*bb.GetUse()); bb.SetInsertUse(true); diff --git a/src/mapleall/maple_ir/include/types_def.h b/src/mapleall/maple_ir/include/types_def.h index f5b1ddc2cd..23740be246 100644 --- a/src/mapleall/maple_ir/include/types_def.h +++ b/src/mapleall/maple_ir/include/types_def.h @@ -20,6 +20,7 @@ // reinventing our own primitive types. #include #include +#include #include "mpl_number.h" namespace maple { @@ -107,6 +108,8 @@ class StIdx { // scope nesting level + symbol table index }; using LabelIdx = uint32; +using phyRegIdx = uint64; +using OfstRegIdx = uint64; using LabelIDOrder = uint32; using PUIdx = uint32; using PregIdx = int32; @@ -133,4 +136,16 @@ constexpr uint8 kOperandNumUnary = 1; constexpr uint8 kOperandNumBinary = 2; constexpr uint8 kOperandNumTernary = 3; } // namespace maple +namespace std { +template<> // function-template-specialization +class std::hash { + public: + size_t operator()(const maple::StIdx &x) const { + std::size_t seed = 0; + hash_combine(seed, x.Scope()); + hash_combine(seed, x.Idx()); + return seed; + } +}; +} #endif // MAPLE_IR_INCLUDE_TYPES_DEF_H diff --git a/src/mapleall/maple_util/include/mpl_number.h b/src/mapleall/maple_util/include/mpl_number.h index 7c649136cd..27395925e7 100644 --- a/src/mapleall/maple_util/include/mpl_number.h +++ b/src/mapleall/maple_util/include/mpl_number.h @@ -286,5 +286,14 @@ namespace std { inline string to_string(maple::utils::Number val) { return std::to_string(val.get()); } + +template +inline void hash_combine(std::size_t& seed, const T& v) { + std::hash hasher; + size_t hasecode = 0x9e3779b9; + size_t leftShift = 6; + size_t rightShift = 2; + seed ^= hasher(v) + hasecode + (seed << leftShift) + (seed >> rightShift); +} } #endif // MAPLE_UTIL_INCLUDE_MPL_NUMBER_H \ No newline at end of file diff --git a/src/mrt/deplibs/libmplandroid.so b/src/mrt/deplibs/libmplandroid.so index 69ce02e3388c0780bc66cfed65f426cc7e61ec6c..48552d4c7d630b5a718984b1cd2a20c40f042154 100755 GIT binary patch delta 209 zcmWm7OBR7(7=YnYiG-+JK9`aR)f&w0$}uo@Y@j7H;Fy}*gYz%NYw(Pp>hshq)DO9* z5?IHtrg^use^GK(qN4!=CM+~zqlGpcbl{?k9{TVwzz{wHgcxCr38wfzGt9BT5)opo WkYJ4z8*GtbhdmC+QM{Ct@6!*y+EZ)* delta 206 zcmWm7xfOyy6hP54E~qH3!{Qee_q_&kV>>dS02-hK13jeVG%<9-Gq~~1%Ad;c`AYf{ zt>Uy2|7|2OqR>DSEwo{wgD!fo(Z>J|h8SUt38t7q!-WSQ0p|EW3xrr=g*75