Skip to content

Commit a6208ce

Browse files
authored
[nfc] move isPresplitCoroSuspendExitEdge to Analysis/CFG (llvm#135849)
1 parent 8ed397d commit a6208ce

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

Diff for: llvm/include/llvm/Analysis/CFG.h

+19
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,25 @@ bool containsIrreducibleCFG(RPOTraversalT &RPOTraversal, const LoopInfoT &LI) {
175175
return false;
176176
}
177177

178+
// Returns true if these basic blocks belong to a presplit coroutine and the
179+
// edge corresponds to the 'default' case in the switch statement in the
180+
// pattern:
181+
//
182+
// %0 = call i8 @llvm.coro.suspend(token none, i1 false)
183+
// switch i8 %0, label %suspend [i8 0, label %resume
184+
// i8 1, label %cleanup]
185+
//
186+
// i.e. the edge to the `%suspend` BB. This edge is special in that it will
187+
// be elided by coroutine lowering (coro-split), and the `%suspend` BB needs
188+
// to be kept as-is. It's not a real CFG edge - post-lowering, it will end
189+
// up being a `ret`, and it must be thus lowerable to support symmetric
190+
// transfer. For example:
191+
// - this edge is not a loop exit edge if encountered in a loop (and should
192+
// be ignored)
193+
// - must not be split for PGO instrumentation, for example.
194+
bool isPresplitCoroSuspendExitEdge(const BasicBlock &Src,
195+
const BasicBlock &Dest);
196+
178197
/// Return true if there is at least a path through which F can return, false if
179198
/// there is no such path.
180199
bool canReturn(const Function &F);

Diff for: llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h

-18
Original file line numberDiff line numberDiff line change
@@ -610,24 +610,6 @@ void InvertBranch(BranchInst *PBI, IRBuilderBase &Builder);
610610
// br/brcond/unreachable/ret
611611
bool hasOnlySimpleTerminator(const Function &F);
612612

613-
// Returns true if these basic blocks belong to a presplit coroutine and the
614-
// edge corresponds to the 'default' case in the switch statement in the
615-
// pattern:
616-
//
617-
// %0 = call i8 @llvm.coro.suspend(token none, i1 false)
618-
// switch i8 %0, label %suspend [i8 0, label %resume
619-
// i8 1, label %cleanup]
620-
//
621-
// i.e. the edge to the `%suspend` BB. This edge is special in that it will
622-
// be elided by coroutine lowering (coro-split), and the `%suspend` BB needs
623-
// to be kept as-is. It's not a real CFG edge - post-lowering, it will end
624-
// up being a `ret`, and it must be thus lowerable to support symmetric
625-
// transfer. For example:
626-
// - this edge is not a loop exit edge if encountered in a loop (and should
627-
// be ignored)
628-
// - must not be split for PGO instrumentation, for example.
629-
bool isPresplitCoroSuspendExitEdge(const BasicBlock &Src,
630-
const BasicBlock &Dest);
631613
} // end namespace llvm
632614

633615
#endif // LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H

Diff for: llvm/lib/Analysis/CFG.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/Analysis/CFG.h"
1515
#include "llvm/Analysis/LoopInfo.h"
1616
#include "llvm/IR/Dominators.h"
17+
#include "llvm/IR/IntrinsicInst.h"
1718
#include "llvm/Support/CommandLine.h"
1819

1920
using namespace llvm;
@@ -356,3 +357,15 @@ bool llvm::canReturn(const Function &F) {
356357

357358
return false;
358359
}
360+
361+
bool llvm::isPresplitCoroSuspendExitEdge(const BasicBlock &Src,
362+
const BasicBlock &Dest) {
363+
assert(Src.getParent() == Dest.getParent());
364+
if (!Src.getParent()->isPresplitCoroutine())
365+
return false;
366+
if (auto *SW = dyn_cast<SwitchInst>(Src.getTerminator()))
367+
if (auto *Intr = dyn_cast<IntrinsicInst>(SW->getCondition()))
368+
return Intr->getIntrinsicID() == Intrinsic::coro_suspend &&
369+
SW->getDefaultDest() == &Dest;
370+
return false;
371+
}

Diff for: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/Twine.h"
2121
#include "llvm/Analysis/BlockFrequencyInfo.h"
2222
#include "llvm/Analysis/BranchProbabilityInfo.h"
23+
#include "llvm/Analysis/CFG.h"
2324
#include "llvm/Analysis/LoopInfo.h"
2425
#include "llvm/Analysis/TargetLibraryInfo.h"
2526
#include "llvm/IR/Attributes.h"

Diff for: llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h"
2222
#include "llvm/ADT/STLExtras.h"
2323
#include "llvm/ADT/ScopeExit.h"
24+
#include "llvm/Analysis/CFG.h"
2425
#include "llvm/Analysis/CtxProfAnalysis.h"
2526
#include "llvm/Analysis/ProfileSummaryInfo.h"
2627
#include "llvm/IR/Analysis.h"

Diff for: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -1916,15 +1916,3 @@ bool llvm::hasOnlySimpleTerminator(const Function &F) {
19161916
}
19171917
return true;
19181918
}
1919-
1920-
bool llvm::isPresplitCoroSuspendExitEdge(const BasicBlock &Src,
1921-
const BasicBlock &Dest) {
1922-
assert(Src.getParent() == Dest.getParent());
1923-
if (!Src.getParent()->isPresplitCoroutine())
1924-
return false;
1925-
if (auto *SW = dyn_cast<SwitchInst>(Src.getTerminator()))
1926-
if (auto *Intr = dyn_cast<IntrinsicInst>(SW->getCondition()))
1927-
return Intr->getIntrinsicID() == Intrinsic::coro_suspend &&
1928-
SW->getDefaultDest() == &Dest;
1929-
return false;
1930-
}

0 commit comments

Comments
 (0)