[PATCH] D41886: [CodeGen][ShrinkWrapping] NFC: Replace isIrreducibleCFG by generic implementation.
Diego Caballero via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 9 15:23:35 PST 2018
dcaballe created this revision.
dcaballe added reviewers: qcolombet, aadg, hfinkel.
The Machine-specific version of ‘isIrreducibleCFG’ utility function in ShrinkWrap was generalized for any kind of CFG in https://reviews.llvm.org/D40874.
This patch replaces the Machine-specific version with the generic version.
https://reviews.llvm.org/D40874 needs to be approved before committing this patch.
Thanks,
Diego
https://reviews.llvm.org/D41886
Files:
lib/CodeGen/ShrinkWrap.cpp
Index: lib/CodeGen/ShrinkWrap.cpp
===================================================================
--- lib/CodeGen/ShrinkWrap.cpp
+++ lib/CodeGen/ShrinkWrap.cpp
@@ -53,6 +53,7 @@
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/CFG.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineDominators.h"
@@ -413,50 +414,16 @@
}
}
-/// Check whether the edge (\p SrcBB, \p DestBB) is a backedge according to MLI.
-/// I.e., check if it exists a loop that contains SrcBB and where DestBB is the
-/// loop header.
-static bool isProperBackedge(const MachineLoopInfo &MLI,
- const MachineBasicBlock *SrcBB,
- const MachineBasicBlock *DestBB) {
- for (const MachineLoop *Loop = MLI.getLoopFor(SrcBB); Loop;
- Loop = Loop->getParentLoop()) {
- if (Loop->getHeader() == DestBB)
- return true;
- }
- return false;
-}
-
-/// Check if the CFG of \p MF is irreducible.
-static bool isIrreducibleCFG(const MachineFunction &MF,
- const MachineLoopInfo &MLI) {
- const MachineBasicBlock *Entry = &*MF.begin();
- ReversePostOrderTraversal<const MachineBasicBlock *> RPOT(Entry);
- BitVector VisitedBB(MF.getNumBlockIDs());
- for (const MachineBasicBlock *MBB : RPOT) {
- VisitedBB.set(MBB->getNumber());
- for (const MachineBasicBlock *SuccBB : MBB->successors()) {
- if (!VisitedBB.test(SuccBB->getNumber()))
- continue;
- // We already visited SuccBB, thus MBB->SuccBB must be a backedge.
- // Check that the head matches what we have in the loop information.
- // Otherwise, we have an irreducible graph.
- if (!isProperBackedge(MLI, MBB, SuccBB))
- return true;
- }
- }
- return false;
-}
-
bool ShrinkWrap::runOnMachineFunction(MachineFunction &MF) {
if (skipFunction(MF.getFunction()) || MF.empty() || !isShrinkWrapEnabled(MF))
return false;
DEBUG(dbgs() << "**** Analysing " << MF.getName() << '\n');
init(MF);
- if (isIrreducibleCFG(MF, *MLI)) {
+ ReversePostOrderTraversal<MachineBasicBlock *> RPOT(&*MF.begin());
+ if (containsIrreducibleCFG<MachineBasicBlock *>(RPOT, *MLI)) {
// If MF is irreducible, a block may be in a loop without
// MachineLoopInfo reporting it. I.e., we may use the
// post-dominance property in loops, which lead to incorrect
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41886.129169.patch
Type: text/x-patch
Size: 2500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180109/1f2aa3ff/attachment.bin>
More information about the llvm-commits
mailing list