Loading src/passes/findAsserts.cpp +24 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #include "identifyFunctions.hpp" #include "llvm/IR/Dominators.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/DomTreeUpdater.h" using namespace llvm; Loading @@ -15,6 +16,7 @@ void addCalledAsserts(ModuleBundle& mod, FBoolMap& containsAssert) if (auto* call = dyn_cast<CallBase>(&I)) { if (containsAssert[call->getCalledFunction()]) { fBundle.calledAsserts[call] = nullptr; fBundle.BBscontainAssert[&BB] = true; } } } Loading Loading @@ -49,24 +51,44 @@ void subdivideEdgesBeforeFailed(ModuleBundle& mod) DominatorTree DT(*origF); LoopInfo LI(DT); DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy); SmallVector<std::pair<BasicBlock*, BasicBlock*>, 16> edgesToSplit; SmallVector<BasicBlock*, 16> addFakePred; for (auto& [BB, contains] : fBundle.BBscontainAssert) { // outs() << *BB << '\n'; if (contains) { // outs() << *BB << '\n'; for (auto* predBB : predecessors(BB)) { if (LI.isLoopHeader(predBB)) { edgesToSplit.emplace_back(predBB, BB); } } // add fake predecessor if on a loop and has multiple preds if (LI.getLoopFor(BB) && pred_size(BB) > 1) { addFakePred.emplace_back(BB); } } } for (auto& [predBB, BB] : edgesToSplit) { SplitEdge(predBB, BB); } SplitEdge(predBB, BB, &DT); } for (auto& BB : addFakePred) { auto* firstNonPhi = BB->getFirstNonPHI(); auto* newBB = SplitBlock(BB, BB->getFirstNonPHI(), &DT, &LI, nullptr, "", false); // outs() << *newBB << '\n'; // outs() << *BB << '\n'; // newBB now contains the old content of BB, BB is the predecessor fBundle.BBscontainAssert[newBB] = true; fBundle.BBscontainAssert[BB] = false; } // outs() << *origF << '\n'; } } bool findAsserts(ModuleBundle& mod) Loading Loading
src/passes/findAsserts.cpp +24 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #include "identifyFunctions.hpp" #include "llvm/IR/Dominators.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/DomTreeUpdater.h" using namespace llvm; Loading @@ -15,6 +16,7 @@ void addCalledAsserts(ModuleBundle& mod, FBoolMap& containsAssert) if (auto* call = dyn_cast<CallBase>(&I)) { if (containsAssert[call->getCalledFunction()]) { fBundle.calledAsserts[call] = nullptr; fBundle.BBscontainAssert[&BB] = true; } } } Loading Loading @@ -49,24 +51,44 @@ void subdivideEdgesBeforeFailed(ModuleBundle& mod) DominatorTree DT(*origF); LoopInfo LI(DT); DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy); SmallVector<std::pair<BasicBlock*, BasicBlock*>, 16> edgesToSplit; SmallVector<BasicBlock*, 16> addFakePred; for (auto& [BB, contains] : fBundle.BBscontainAssert) { // outs() << *BB << '\n'; if (contains) { // outs() << *BB << '\n'; for (auto* predBB : predecessors(BB)) { if (LI.isLoopHeader(predBB)) { edgesToSplit.emplace_back(predBB, BB); } } // add fake predecessor if on a loop and has multiple preds if (LI.getLoopFor(BB) && pred_size(BB) > 1) { addFakePred.emplace_back(BB); } } } for (auto& [predBB, BB] : edgesToSplit) { SplitEdge(predBB, BB); } SplitEdge(predBB, BB, &DT); } for (auto& BB : addFakePred) { auto* firstNonPhi = BB->getFirstNonPHI(); auto* newBB = SplitBlock(BB, BB->getFirstNonPHI(), &DT, &LI, nullptr, "", false); // outs() << *newBB << '\n'; // outs() << *BB << '\n'; // newBB now contains the old content of BB, BB is the predecessor fBundle.BBscontainAssert[newBB] = true; fBundle.BBscontainAssert[BB] = false; } // outs() << *origF << '\n'; } } bool findAsserts(ModuleBundle& mod) Loading