From c4771d36dc85b64f8ac73cc3807563d0469c500f Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Mon, 2 Apr 2018 15:57:20 -0700 Subject: [PATCH] Converts relaxed loads to acquire loads when necessary --- lib/CodeGen/CodeGenPrepare.cpp | 38 ++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index f4ff3787e63..3eaeaa2360c 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -1016,6 +1016,41 @@ bool AddFakeConditionalBranchAfterMonotonicLoads( return Changed; } +// XXX-comment: Returns whether the code has been changed. +bool ConvertMonotonicLoadsToAcquire(SmallSet& MonotonicLoadInsts) +{ + bool Changed = false; + while (!MonotonicLoadInsts.empty()) { + auto* LI = *MonotonicLoadInsts.begin(); + MonotonicLoadInsts.erase(LI); + SmallVector ChainedBB; + auto* FirstInst = findFirstStoreCondBranchInst(LI, &ChainedBB); + if (FirstInst != nullptr) { + if (FirstInst->getOpcode() == Instruction::Store) { + if (StoreAddressDependOnValue(dyn_cast(FirstInst), LI)) { + continue; + } + } else if (FirstInst->getOpcode() == Instruction::Br) { + if (ConditionalBranchDependsOnValue(dyn_cast(FirstInst), + LI)) { + continue; + } + } else { + IntrinsicInst* II = dyn_cast(FirstInst); + if (!II || II->getIntrinsicID() != Intrinsic::aarch64_stlxr) { + dbgs() << "FirstInst=" << *FirstInst << "\n"; + assert(false && "findFirstStoreCondBranchInst() should return a " + "store/condition branch instruction"); + } + } + } + + // We really need convert the load to acquire. + LI->setOrdering(Acquire); + } + return Changed; +} + /**** Implementations of public methods for dependence tainting ****/ Value* GetUntaintedAddress(Value* CurrentAddress) { auto* OrAddress = getOrAddress(CurrentAddress); @@ -1406,8 +1441,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) { } } } - EverMadeChange |= - AddFakeConditionalBranchAfterMonotonicLoads(MonotonicLoadInsts, DT); + EverMadeChange |= ConvertMonotonicLoadsToAcquire(MonotonicLoadInsts); return EverMadeChange; } -- 2.34.1