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"
}
// XXX-comment: Returns whether the code has been changed.
-bool AddsFakeConditionalBranchAfterMonotonicLoads(
+bool AddFakeConditionalBranchAfterMonotonicLoads(
const SmallVector<LoadInst*, 1>& MonotonicLoadInsts) {
bool Changed = false;
for (auto* LI : MonotonicLoadInsts) {
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<LoadInst*, 1> 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<LoadInst>(&*I);
- if (LI->getOrdering() == Monotonic) {
- MonotonicLoadInsts.push_back(LI);
- }
- break;
- }
- default: {
- break;
- }
- }
- }
- }
- bool EverMadeChange =
- AddsFakeConditionalBranchAfterMonotonicLoads(MonotonicLoadInsts);
+ bool EverMadeChange = false;
if (skipOptnoneFunction(F))
return false;
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<LoadInst*, 1> 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<LoadInst>(&*I);
+ if (LI->getOrdering() == Monotonic) {
+ MonotonicLoadInsts.push_back(LI);
+ }
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ }
+ }
+ EverMadeChange |=
+ AddFakeConditionalBranchAfterMonotonicLoads(MonotonicLoadInsts);
+
return EverMadeChange;
}
// 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<BranchInst>(BB->getTerminator());
if (!BI || !BI->isUnconditional())