X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FCodeGenPrepare.cpp;h=1a07bfc0c3577f71585153b63635d87173c47479;hb=5666fc71f0e2ed2c0400d8bca079a1dd3f33fe53;hp=9ada111eaa92e683b1b40db7883fc116115880b2;hpb=0e59c4e3e8f8e105834d137cccb1e1bb731b5a13;p=oota-llvm.git diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index 9ada111eaa9..1a07bfc0c35 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -729,10 +729,16 @@ void AddFakeConditionalBranch(Instruction* SplitInst, Value* Condition) { TerminatorInst* ThenTerm = nullptr; TerminatorInst* ElseTerm = nullptr; SplitBlockAndInsertIfThenElse(Condition, SplitInst, &ThenTerm, &ElseTerm); + assert(ThenTerm && ElseTerm && + "Then/Else terminators cannot be empty after basic block spliting"); auto* ThenBB = ThenTerm->getParent(); auto* ElseBB = ElseTerm->getParent(); + auto* TailBB = ThenBB->getSingleSuccessor(); + assert(TailBB && "Tail block cannot be empty after basic block spliting"); + ThenBB->disableCanEliminateBlock(); ThenBB->disableCanEliminateBlock(); + TailBB->disableCanEliminateBlock(); ThenBB->setName(BB->getName() + "Then.Fake"); ElseBB->setName(BB->getName() + "Else.Fake"); DEBUG(dbgs() << "Add fake conditional branch:\n" @@ -750,7 +756,7 @@ void TaintRelaxedLoads(LoadInst* LI) { } // XXX-comment: Returns whether the code has been changed. -bool AddsFakeConditionalBranchAfterMonotonicLoads( +bool AddFakeConditionalBranchAfterMonotonicLoads( const SmallVector& MonotonicLoadInsts) { bool Changed = false; for (auto* LI : MonotonicLoadInsts) { @@ -1032,29 +1038,7 @@ bool StoreDependOnValue(StoreInst* SI, Value* Dep) { bool CodeGenPrepare::runOnFunction(Function &F) { - // XXX-comment: Delay dealing with relaxed loads in this function to avoid - // further changes done by other passes (e.g., SimplifyCFG). - - // Collect all the relaxed loads. - SmallVector MonotonicLoadInsts; - for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { - if (I->isAtomic()) { - switch (I->getOpcode()) { - case Instruction::Load: { - auto* LI = dyn_cast(&*I); - if (LI->getOrdering() == Monotonic) { - MonotonicLoadInsts.push_back(LI); - } - break; - } - default: { - break; - } - } - } - } - bool EverMadeChange = - AddsFakeConditionalBranchAfterMonotonicLoads(MonotonicLoadInsts); + bool EverMadeChange = false; if (skipOptnoneFunction(F)) return false; @@ -1169,6 +1153,29 @@ bool CodeGenPrepare::runOnFunction(Function &F) { EverMadeChange |= simplifyOffsetableRelocate(*I); } + // XXX-comment: Delay dealing with relaxed loads in this function to avoid + // further changes done by other passes (e.g., SimplifyCFG). + // Collect all the relaxed loads. + SmallVector MonotonicLoadInsts; + for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { + if (I->isAtomic()) { + switch (I->getOpcode()) { + case Instruction::Load: { + auto* LI = dyn_cast(&*I); + if (LI->getOrdering() == Monotonic) { + MonotonicLoadInsts.push_back(LI); + } + break; + } + default: { + break; + } + } + } + } + EverMadeChange |= + AddFakeConditionalBranchAfterMonotonicLoads(MonotonicLoadInsts); + return EverMadeChange; } @@ -1215,11 +1222,6 @@ bool CodeGenPrepare::eliminateMostlyEmptyBlocks(Function &F) { // Note that this intentionally skips the entry block. for (Function::iterator I = std::next(F.begin()), E = F.end(); I != E;) { BasicBlock *BB = &*I++; - // XXX-disabled: Do not eliminate the added fake basic block. - if (!BB->getCanEliminateBlock()) { - continue; - } - // If this block doesn't end with an uncond branch, ignore it. BranchInst *BI = dyn_cast(BB->getTerminator()); if (!BI || !BI->isUnconditional())