ykjit / yk

yk packages
https://ykjit.github.io/yk/
Other
32 stars 7 forks source link

BlockDisambiguate Pass doesn't implement logic for `indirectbr` #440

Open vext01 opened 2 years ago

vext01 commented 2 years ago

This will be needed for #414.

It will be something like:

diff --git a/llvm/lib/Transforms/Yk/BlockDisambiguate.cpp b/llvm/lib/Transforms/Yk/BlockDisambiguate.cpp
index 270b37f70264..55b6493d9651 100644
--- a/llvm/lib/Transforms/Yk/BlockDisambiguate.cpp
+++ b/llvm/lib/Transforms/Yk/BlockDisambiguate.cpp
@@ -191,7 +191,6 @@ private:
     std::vector<BasicBlock *> NewBBs;
     for (BasicBlock &BB : F) {
       Instruction *TI = BB.getTerminator();
-      assert(!isa<IndirectBrInst>(TI)); // YKFIXME: not implemented.
       if (isa<BranchInst>(TI)) {
         BranchInst *BI = cast<BranchInst>(TI);
         for (unsigned SuccIdx = 0; SuccIdx < BI->getNumSuccessors();
@@ -212,6 +211,16 @@ private:
             SI->setSuccessor(SuccIdx, DBB);
           }
         }
+      } else if (isa<IndirectBrInst>(TI)) {
+        IndirectBrInst *IBI = cast<IndirectBrInst>(TI);
+        for (unsigned SuccIdx = 0; SuccIdx < IBI->getNumSuccessors();
+             SuccIdx++) {
+          BasicBlock *SuccBB = IBI->getSuccessor(SuccIdx);
+          if (SuccBB == &BB) {
+            BasicBlock *DBB = makeDisambiguationBB(Context, &BB, NewBBs);
+            IBI->setSuccessor(SuccIdx, DBB);
+          }
+        }
       }
     }
ltratt commented 1 year ago

@vext01 I doubt this one is still relevant?