diff --git a/build/config.gni b/build/config.gni index f6ce51249f1f4abece5ebb9f0d23eabc69a0e79f..9cb3428df1726a4c63e89a32572c0c87443cc9a8 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 501c7255f8af8c8486d1149aed7d4a761a0c0093..8d27416f8dcf7aa52f98bd74dbfbf4313ccff962 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_be/include/be/common_utils.h b/src/mapleall/maple_be/include/be/common_utils.h index e3b514d2b0980733a25e84072ca9fc5063076198..a487d101a7d4316b5cec7308238f104186a94d45 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 94a31e94d9a8b2a9c293bddbda7d69c94325b7d3..d6b86cfca29364a290c8e3f9cc1b3132fb83240f 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 79ca62de99959b23194b7adcdc98d8f4c3db2cc1..02f9a7e1f28b2e635f77f4c9b99c6b100ef5e07c 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 d60b55bee677fc32e383457abc840c0adbbb27f2..eee252fb218fa7987414a255c56de5ef022ac3a5 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 94933caf1ae60fcc7d3d559060ae08b6bc4192f3..2fca02d1698c2e129686fce1a5a30252600a29dc 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 7b091a64c5bf3f6c0f89afb174c45f0f5e5d9423..ba3790b5cd9f0137e407b407c7a9af12cf4022a8 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 bcef38c68da47adde1c0215d1489a5fecd74d35a..615ca4cce2c57bbc02a2838f5650c5f6f4e63df7 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 1c4a2166cf711c83eaee4ed1e991fa8d7078b915..571e49127d84815cce5b587d5d4496b05b92c027 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 f5b1ddc2cd86835e9192a91cfb01e82d93987efd..23740be246aba7bbe8396007019e561e919fc4e2 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_me/include/me_function.h b/src/mapleall/maple_me/include/me_function.h index ad220806f749459a0a2c89bcfd8431f24a3301cd..47f801f28b784dd35294dd9b3134dbb56337e70e 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 fdee58c29b6d43e725c60fc5c0afbbc8c2f25715..cb19c1202ea028948e28ed435bb386f2487b8384 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 d4a6dbfac04e3fd5842b801ca639a46616ff1993..aba7e492851af6622b2b76f3cd55fd00a89e8142 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 961bad39f469f60dad71fe7bff2f15db0738db00..8e461ef08723a23b7f3f606601c4f77daa82618f 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 c0d799c4a8fd4261a347f68d22b1f2a283613664..705347dd178547dbfeb4c3d3b5adfebdbe6487ba 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/mapleall/maple_util/include/mpl_number.h b/src/mapleall/maple_util/include/mpl_number.h index 7c649136cdea8ed78d59f30314674baac1e674f5..27395925e79da70c52b30e3af085c5d1b833d403 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/mplfe/BUILD.gn b/src/mplfe/BUILD.gn index 4951fd9f5a760123b6334d8f4d9686f73774f555..35ba2cf82b0a49284de71007492853c40883ce92 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 3bb966044d63f0640fd3a541aa669dab62677d7f..03086e91a6c89389b58167bab8014267a5b1bbb3 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 dd7f2ca3f5f2aca1999f90540cfa720b435f35bc..6c62eb00e5f1080bd18bdd160fbb9fc8efe84e10 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 82220d2d9fd18d8ca9ce5d98b2c572202b447b82..d5b498eed7174155d63abec059b965577bea382b 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 30f924dcff0f10a93be368a53f96454c90ed9717..042aaa72084e38dfa758044e3c0834a96d25214e 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 099cc19781336112e4ad5c8878467cded60bda6b..09711b5055e70a27ba3822210063ebd147aaab48 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 83f41e0173a33e770e87d231b3d0c589d5fb8804..9547217686771691694d67c54a130ba66a00d87a 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 a1f92e259c1ccd9bda83a75c22ab5f9025934e66..3855f40fc76a7b14971c730fb8c17c6b95e31c38 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 0242f9a282e01a81c6f61290eaec5b78baa78949..de76844e2bc959621da52625132ca508d22c900e 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 967674f065dee0ab4a27b8d01b3fc21e1dae006c..515288c0a51ea2d18c1c6eea5a69ec5271b4ec33 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 3736e32a98599bf91c5b5bed0f0a2bea30a9a35a..c568edd6b82226af80b5b588e3cc41cfa3132ca6 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 a93b4b55db293e7fee0ad2f23baf226ff6067da9..17db7f2ce755c79a8842036ddbd93f93529355b7 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/third_party/cfe-8.0.0.src b/third_party/cfe-8.0.0.src deleted file mode 120000 index 2c2069a2f26fe301277df3eec9fe4b54ba5441b7..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..f846ad906ecfcdb64843e197baff8c6b87f3bfd6 --- /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 2583de33fe5bdf730537e8e63307487074254322..e4b307f2d717a6b67ffebc70864b3f1564adb624 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++