aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
diff options
context:
space:
mode:
authorSameer Sahasrabuddhe <sameer.sahasrabuddhe@amd.com>2020-04-15 12:17:11 +0530
committerSameer Sahasrabuddhe <sameer.sahasrabuddhe@amd.com>2020-04-15 12:19:50 +0530
commit44e09b59b869a91bf47d76e8bc569d9ee91ad145 (patch)
treee9ee81e647842e6e3a9a2a2fe0a2d23a8fbcb8ea /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
parent5d3f7176c1b299d456cec7da4923be5f39e61228 (diff)
downloadllvm-44e09b59b869a91bf47d76e8bc569d9ee91ad145.zip
llvm-44e09b59b869a91bf47d76e8bc569d9ee91ad145.tar.gz
llvm-44e09b59b869a91bf47d76e8bc569d9ee91ad145.tar.bz2
Revert "Introduce fix-irreducible pass"
This reverts commit 2ada8e2525dd2653f30c8696a27162a3b1647d66. Buildbots produced compilation errors which I was not able to quickly reproduce locally. Need more time to investigate.
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/BasicBlockUtils.cpp100
1 files changed, 38 insertions, 62 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 95e2b26..d722793 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1144,62 +1144,18 @@ static void reconnectPhis(BasicBlock *Out, BasicBlock *GuardBlock,
using BBPredicates = DenseMap<BasicBlock *, PHINode *>;
using BBSetVector = SetVector<BasicBlock *>;
-// Redirects the terminator of the incoming block to the first guard
-// block in the hub. The condition of the original terminator (if it
-// was conditional) and its original successors are returned as a
-// tuple <condition, succ0, succ1>. The function additionally filters
-// out successors that are not in the set of outgoing blocks.
+// Collect predicates for each outgoing block. If control reaches the
+// Hub from an incoming block InBB, then the predicate for each
+// outgoing block OutBB decides whether control is forwarded to OutBB.
//
-// - condition is non-null iff the branch is conditional.
-// - Succ1 is non-null iff the sole/taken target is an outgoing block.
-// - Succ2 is non-null iff condition is non-null and the fallthrough
-// target is an outgoing block.
-static std::tuple<Value *, BasicBlock *, BasicBlock *>
-redirectToHub(BasicBlock *BB, BasicBlock *FirstGuardBlock,
- const BBSetVector &Outgoing) {
- auto Branch = cast<BranchInst>(BB->getTerminator());
- auto Condition = Branch->isConditional() ? Branch->getCondition() : nullptr;
-
- BasicBlock *Succ0 = Branch->getSuccessor(0);
- BasicBlock *Succ1 = nullptr;
- Succ0 = Outgoing.count(Succ0) ? Succ0 : nullptr;
-
- if (Branch->isUnconditional()) {
- Branch->setSuccessor(0, FirstGuardBlock);
- assert(Succ0);
- } else {
- Succ1 = Branch->getSuccessor(1);
- Succ1 = Outgoing.count(Succ1) ? Succ1 : nullptr;
- assert(Succ0 || Succ1);
- if (Succ0 && !Succ1) {
- Branch->setSuccessor(0, FirstGuardBlock);
- } else if (Succ1 && !Succ0) {
- Branch->setSuccessor(1, FirstGuardBlock);
- } else {
- Branch->eraseFromParent();
- BranchInst::Create(FirstGuardBlock, BB);
- }
- }
-
- assert(Succ0 || Succ1);
- return std::make_tuple(Condition, Succ0, Succ1);
-}
-
-// Capture the existing control flow as guard predicates, and redirect
-// control flow from every incoming block to the first guard block in
-// the hub.
-//
-// There is one guard predicate for each outgoing block OutBB. The
-// predicate is a PHINode with one input for each InBB which
-// represents whether the hub should transfer control flow to OutBB if
-// it arrived from InBB. These predicates are NOT ORTHOGONAL. The Hub
-// evaluates them in the same order as the Outgoing set-vector, and
-// control branches to the first outgoing block whose predicate
-// evaluates to true.
-static void convertToGuardPredicates(
- BasicBlock *FirstGuardBlock, BBPredicates &GuardPredicates,
- SmallVectorImpl<WeakVH> &DeletionCandidates, const BBSetVector &Incoming,
- const BBSetVector &Outgoing) {
+// These predicates are not orthogonal. The Hub evaluates them in the
+// same order as the Outgoing set-vector, and control branches to the
+// first outgoing block whose predicate evaluates to true.
+static void createGuardPredicates(BasicBlock *FirstGuardBlock,
+ BBPredicates &GuardPredicates,
+ SmallVectorImpl<WeakVH> &DeletionCandidates,
+ const BBSetVector &Incoming,
+ const BBSetVector &Outgoing) {
auto &Context = Incoming.front()->getContext();
auto BoolTrue = ConstantInt::getTrue(Context);
auto BoolFalse = ConstantInt::getFalse(Context);
@@ -1216,11 +1172,30 @@ static void convertToGuardPredicates(
}
for (auto In : Incoming) {
- Value *Condition;
- BasicBlock *Succ0;
- BasicBlock *Succ1;
- std::tie(Condition, Succ0, Succ1) =
- redirectToHub(In, FirstGuardBlock, Outgoing);
+ auto Branch = cast<BranchInst>(In->getTerminator());
+ BasicBlock *Succ0 = Branch->getSuccessor(0);
+ BasicBlock *Succ1 = nullptr;
+
+ Succ0 = Outgoing.count(Succ0) ? Succ0 : nullptr;
+
+ if (Branch->isUnconditional()) {
+ Branch->setSuccessor(0, FirstGuardBlock);
+ assert(Succ0);
+ } else {
+ Succ1 = Branch->getSuccessor(1);
+ Succ1 = Outgoing.count(Succ1) ? Succ1 : nullptr;
+ assert(Succ0 || Succ1);
+ if (Succ0 && !Succ1) {
+ Branch->setSuccessor(0, FirstGuardBlock);
+ } else if (Succ1 && !Succ0) {
+ Branch->setSuccessor(1, FirstGuardBlock);
+ } else {
+ Branch->eraseFromParent();
+ BranchInst::Create(FirstGuardBlock, In);
+ }
+ }
+
+ assert(Succ0 || Succ1);
// Optimization: Consider an incoming block A with both successors
// Succ0 and Succ1 in the set of outgoing blocks. The predicates
@@ -1230,6 +1205,7 @@ static void convertToGuardPredicates(
// control must reach Succ1, which means that the predicate for
// Succ1 is always true.
bool OneSuccessorDone = false;
+ auto Condition = Branch->getCondition();
for (int i = 0, e = Outgoing.size() - 1; i != e; ++i) {
auto Out = Outgoing[i];
auto Phi = GuardPredicates[Out];
@@ -1311,8 +1287,8 @@ BasicBlock *llvm::CreateControlFlowHub(
BBPredicates GuardPredicates;
SmallVector<WeakVH, 8> DeletionCandidates;
- convertToGuardPredicates(FirstGuardBlock, GuardPredicates, DeletionCandidates,
- Incoming, Outgoing);
+ createGuardPredicates(FirstGuardBlock, GuardPredicates, DeletionCandidates,
+ Incoming, Outgoing);
GuardBlocks.push_back(FirstGuardBlock);
createGuardBlocks(GuardBlocks, F, Outgoing, GuardPredicates, Prefix);