diff --git a/build/build.sh b/build/build.sh index 5c72bf5df04b8928ff632047c84bc710e5a944e0..a833fc78272cb0f5a936fc3f114013363b7aac8d 100644 --- a/build/build.sh +++ b/build/build.sh @@ -13,6 +13,7 @@ # FIT FOR A PARTICULAR PURPOSE. # See the Mulan PSL v1 for more details. # +set -e source build/envsetup.sh option=$@ if [ "$option" = "DEBUG" ]; then diff --git a/build/config.gni b/build/config.gni new file mode 100644 index 0000000000000000000000000000000000000000..9c7d79fe171a517ce057a74be4d6a0acf5984f16 --- /dev/null +++ b/build/config.gni @@ -0,0 +1,26 @@ +# +# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. +# +# OpenArkCompiler is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# +# http://license.coscl.org.cn/MulanPSL +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v1 for more details. +# +# Toolchain setup +GN_C_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang" +GN_CXX_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++" +GN_AR_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar" +target_toolchain = "//build/toolchain:clang" +set_default_toolchain(target_toolchain) + +# Cross compile +GN_C_CROSS_COMPILER = "/usr/bin/aarch64-linux-gnu-gcc-5" +GN_CXX_CROSS_COMPILER = "/usr/bin/aarch64-linux-gnu-g++-5" +GN_AR_CROSS_COMPILER = "/usr/bin/aarch64-linux-gnu-ar" +GN_RANLIB_CROSS_COMPILER = "/usr/bin/aarch64-linux-gnu-ranlib" diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index d86ea4ce3c26b5197acc5900c8d51ec8109fe2f6..3e88d9f85bd835bbbad9a9c39321c9f0d782ed35 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -43,18 +43,7 @@ GN_LIBRARY_OUTPUT_DIRECTORY = "${GN_INSTALL_PREFIX}/output/lib" # Put all built binary files under bin GN_BINARY_OUTPUT_DIRECTORY = "${GN_INSTALL_PREFIX}/output/bin" -# Toolchain setup -GN_C_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang" -GN_CXX_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++" -GN_AR_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar" -target_toolchain = "//build/toolchain:clang" -set_default_toolchain(target_toolchain) - -# Cross compile -GN_C_CROSS_COMPILER = "/usr/bin/aarch64-linux-gnu-gcc-5" -GN_CXX_CROSS_COMPILER = "/usr/bin/aarch64-linux-gnu-g++-5" -GN_AR_CROSS_COMPILER = "/usr/bin/aarch64-linux-gnu-ar" -GN_RANLIB_CROSS_COMPILER = "/usr/bin/aarch64-linux-gnu-ranlib" +import("${MAPLE_ROOT}/build/config.gni") # C/CXX Build flags cflags = [] diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index ad1de560aa774b77faea69a1c7cac256cf8ede22..ce80cf95074a54a3022d571e57dde99960c168f4 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index ff1c863bdb610bc6720d9f9741f3e730573056f1..f10aeeb18bbeba96a01b459167cf703e94cc8306 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 4906adc29934edbfa11e0d237f4f49c9f1819b85..ce197c6660e80be61ab2d04342f195d70313e722 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 2a4d7fc89d891a3cd900a4075f3f49d5ede319ee..53d674477177435dee7d5dd778a67d7579d71917 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/BUILD.gn b/src/maple_driver/BUILD.gn index 7cb20d512ec89eb3dd9a588676d13722dba83dba..2fc98ac1bfedd0c5b2da782e68289e1147361bda 100644 --- a/src/maple_driver/BUILD.gn +++ b/src/maple_driver/BUILD.gn @@ -23,9 +23,7 @@ include_directories = [ "${MAPLEALL_ROOT}", "${MAPLEALL_ROOT}/maple_driver/defs", "${MAPLEALL_ROOT}/maple_driver/include", - "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/mpl2mpl/include", - "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/maplewpo/include", "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_phase/include", diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 6df3fd9891c19c2213f0057e64ec254b7f233529..c5c6cc66a80699ed847b901c32bec3e743f29ba6 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -213,6 +213,7 @@ class MIRModule { void DumpInlineCandidateToFile(const std::string &fileNameStr) const; const std::string &GetFileNameFromFileNum(uint32 fileNum) const; + void DumpToHeaderFile(bool binaryMplt, const std::string &outputName = ""); void DumpClassToFile(const std::string &path) const; void DumpFunctionList(bool skipBody = false) const; void DumpGlobalArraySymbol() const; diff --git a/src/maple_ir/src/mir_module.cpp b/src/maple_ir/src/mir_module.cpp index 64f00f124009aa49fde7202ffd4ba7fe2ef09e0a..539bc766fcda6946776971459aace31bea879cad 100644 --- a/src/maple_ir/src/mir_module.cpp +++ b/src/maple_ir/src/mir_module.cpp @@ -369,6 +369,47 @@ const std::string &MIRModule::GetFileNameFromFileNum(uint32 fileNum) const { return GlobalTables::GetStrTable().GetStringFromStrIdx(nameIdx); } +void MIRModule::DumpToHeaderFile(bool binaryMplt, const std::string &outputName) { + std::string outfileName; + std::string fileNameLocal = !outputName.empty() ? outputName : fileName; + std::string::size_type lastDot = fileNameLocal.find_last_of('.'); + if (lastDot == std::string::npos) { + outfileName = fileNameLocal.append(".mplt"); + } else { + outfileName = fileNameLocal.substr(0, lastDot).append(".mplt"); + } + if (binaryMplt) { + BinaryMplt binaryMpltTmp(*this); + binaryMpltTmp.Export(outfileName); + } else { + std::ofstream mpltFile; + mpltFile.open(outfileName, std::ios::trunc); + std::streambuf *backup = LogInfo::MapleLogger().rdbuf(); + LogInfo::MapleLogger().rdbuf(mpltFile.rdbuf()); // change cout's buffer to that of file + for (std::pair entity : GlobalTables::GetConstPool().GetConstU16StringPool()) { + LogInfo::MapleLogger() << "var $"; + entity.second->DumpAsLiteralVar(); + LogInfo::MapleLogger() << '\n'; + } + for (auto it = classList.begin(); it != classList.end(); ++it) { + TyIdx curTyIdx(*it); + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(curTyIdx); + const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(type->GetNameStrIdx()); + if (type->GetKind() == kTypeClass || type->GetKind() == kTypeInterface) { + auto *structType = static_cast(type); + // skip imported class/interface and incomplete types + if (!structType->IsImported() && !structType->IsIncomplete()) { + LogInfo::MapleLogger() << "type $" << name << " "; + type->Dump(1, true); + LogInfo::MapleLogger() << '\n'; + } + } + } + /* restore cout */ + LogInfo::MapleLogger().rdbuf(backup); + } +} + void MIRModule::DumpClassToFile(const std::string &path) const { std::string strPath(path); diff --git a/src/maple_me/include/me_bb_layout.h b/src/maple_me/include/me_bb_layout.h index 8ec4d491c70d4962c7b3aabef870e9f250d982f6..fcc76ac0678e47688cfe74432d940f0e24d65f11 100644 --- a/src/maple_me/include/me_bb_layout.h +++ b/src/maple_me/include/me_bb_layout.h @@ -25,6 +25,7 @@ class BBLayout : public AnalysisResult { func(f), layoutAlloc(&memPool), layoutBBs(layoutAlloc.Adapter()), + startTryBBVec(func.GetAllBBs().size(), false), laidOut(func.GetAllBBs().size(), false, layoutAlloc.Adapter()), enabledDebug(enabledDebug) { laidOut[func.GetCommonEntryBB()->GetBBId()] = true; @@ -85,9 +86,15 @@ class BBLayout : public AnalysisResult { } private: + void FixEndTryBB(BB &bb); + void FixTryBB(BB &startTryBB, BB &nextBB); + void DealWithStartTryBB(); + MeFunction &func; MapleAllocator layoutAlloc; MapleVector layoutBBs; // gives the determined layout order + std::vector startTryBBVec; // record the try BB to fix the try&endtry map + bool needDealWithTryBB = false; BBId curBBId { 0 }; // to index into func.bb_vec_ to return the next BB bool bbCreated = false; // new create bb will change mefunction::bb_vec_ and // related analysis result diff --git a/src/maple_me/include/me_function.h b/src/maple_me/include/me_function.h index e1597c33f746f511a6535bedb373ee604111b509..492fd6fc1bb071a622248ed1327a42f8d7bc349a 100644 --- a/src/maple_me/include/me_function.h +++ b/src/maple_me/include/me_function.h @@ -395,10 +395,12 @@ class MeFunction : public FuncEmit { const MapleUnorderedMap &GetEndTryBB2TryBB() const { return endTryBB2TryBB; } + const BB *GetTryBBFromEndTryBB(BB *endTryBB) const { auto it = endTryBB2TryBB.find(endTryBB); return it == endTryBB2TryBB.end() ? nullptr : it->second; } + void SetTryBBByOtherEndTryBB(BB *endTryBB, BB *otherTryBB) { endTryBB2TryBB[endTryBB] = endTryBB2TryBB[otherTryBB]; } diff --git a/src/maple_me/src/me_bb_layout.cpp b/src/maple_me/src/me_bb_layout.cpp index c0aa0c7cf7164af28d2a52031b7444931fc73a51..26ea51f7b0f7f3fe3ba16c67d4b96fc197e70642 100644 --- a/src/maple_me/src/me_bb_layout.cpp +++ b/src/maple_me/src/me_bb_layout.cpp @@ -279,6 +279,9 @@ void BBLayout::OptimizeBranchTarget(BB &bb) { if (brTargetBB->GetPred().empty()) { laidOut[brTargetBB->GetBBId()] = true; RemoveUnreachable(*brTargetBB); + if (needDealWithTryBB) { + DealWithStartTryBB(); + } } } while (true); } @@ -339,6 +342,9 @@ BB *BBLayout::GetFallThruBBSkippingEmpty(BB &bb) { oldFallThru->RemoveBBFromPred(&bb); if (oldFallThru->GetPred().empty()) { RemoveUnreachable(*oldFallThru); + if (needDealWithTryBB) { + DealWithStartTryBB(); + } } } while (true); } @@ -377,6 +383,60 @@ void BBLayout::ResolveUnconditionalFallThru(BB &bb, BB &nextBB) { } } +void BBLayout::FixEndTryBB(BB &bb) { + BBId prevID = bb.GetBBId() - 1; + for (BBId id = prevID; id != 0; --id) { + auto prevBB = func.GetBBFromID(id); + if (prevBB != nullptr) { + if (prevBB->GetAttributes(kBBAttrIsTry) && !prevBB->GetAttributes(kBBAttrIsTryEnd)) { + prevBB->SetAttributes(kBBAttrIsTryEnd); + func.SetTryBBByOtherEndTryBB(prevBB, &bb); + } + break; + } + } +} + +void BBLayout::FixTryBB(BB &startTryBB, BB &nextBB) { + if (nextBB.GetBBLabel() != 0) { + startTryBB.SetBBLabel(nextBB.GetBBLabel()); + nextBB.SetBBLabel(0); + } + startTryBB.GetPred().clear(); + for (size_t i = 0; i < nextBB.GetPred().size(); ++i) { + nextBB.GetPred(i)->ReplaceSucc(&nextBB, &startTryBB); + } + nextBB.GetPred().clear(); + startTryBB.ReplaceSucc(startTryBB.GetSucc(0), &nextBB); +} + +void BBLayout::DealWithStartTryBB() { + size_t size = startTryBBVec.size(); + for (size_t i = 0; i < size; ++i) { + if (!startTryBBVec[i]) { + continue; + } + auto curBB = func.GetBBFromID(BBId(i)); + for (size_t j = i + 1; !startTryBBVec[j] && j < size; ++j) { + auto nextBB = func.GetBBFromID(BBId(j)); + if (nextBB != nullptr) { + if (nextBB->GetAttributes(kBBAttrIsTry)) { + FixTryBB(*curBB, *nextBB); + } else { + curBB->GetSucc().clear(); + func.NullifyBBByID(curBB->GetBBId()); + } + break; + } else if (j == size - 1) { + curBB->GetSucc().clear(); + func.NullifyBBByID(curBB->GetBBId()); + } + } + startTryBBVec[i] = false; + } + needDealWithTryBB = false; +} + // remove unnessary bb whose pred size is zero // keep cfg correct to rebuild dominance void BBLayout::RemoveUnreachable(BB &bb) { @@ -388,9 +448,21 @@ void BBLayout::RemoveUnreachable(BB &bb) { MapleVector &preds = succ->GetPred(); bb.RemoveBBFromVector(preds); if (preds.empty()) { - RemoveUnreachable(*succ); + RemoveUnreachable(*succ); } } + + if (bb.GetAttributes(kBBAttrIsTry) && !bb.GetAttributes(kBBAttrIsTryEnd)) { + // identify if try bb is the start try bb + if (!bb.GetMeStmts().empty() && bb.GetMeStmts().front().GetOp() == OP_try) { + startTryBBVec[bb.GetBBId()] = true; + needDealWithTryBB = true; + return; + } + } + if (bb.GetAttributes(kBBAttrIsTryEnd)) { + FixEndTryBB(bb); + } succBBs.clear(); func.NullifyBBByID(bb.GetBBId()); } diff --git a/src/maple_me/src/ssa_epre.cpp b/src/maple_me/src/ssa_epre.cpp index 47f09a482a8f40ad5b7c32d3c9e0c8212766abca..b54acbc99726466a8f1e48018b8cc76e3993963f 100644 --- a/src/maple_me/src/ssa_epre.cpp +++ b/src/maple_me/src/ssa_epre.cpp @@ -189,7 +189,7 @@ MeExpr *SSAEPre::PhiOpndFromRes(MeRealOcc *realZ, size_t j) { case kMeOpIvar: { auto *ivarMeExpr = static_cast(exprQ); MeExpr *retOpnd = GetReplaceMeExpr(ivarMeExpr->GetBase(), ePhiBB, j); - if (retOpnd) { + if (retOpnd != nullptr) { ivarMeExpr->SetBase(retOpnd); } MeExpr *muOpnd = GetReplaceMeExpr(ivarMeExpr->GetMu(), ePhiBB, j);