[llvm] [nfc] move `isPresplitCoroSuspendExitEdge` to Analysis/CFG (PR #135849)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 15 13:52:07 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Mircea Trofin (mtrofin)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/135849.diff
6 Files Affected:
- (modified) llvm/include/llvm/Analysis/CFG.h (+19)
- (modified) llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h (-18)
- (modified) llvm/lib/Analysis/CFG.cpp (+13)
- (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (+1)
- (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp (+1)
- (modified) llvm/lib/Transforms/Utils/BasicBlockUtils.cpp (-12)
``````````diff
diff --git a/llvm/include/llvm/Analysis/CFG.h b/llvm/include/llvm/Analysis/CFG.h
index 23bc10a4a9d1b..a1fc392d3336f 100644
--- a/llvm/include/llvm/Analysis/CFG.h
+++ b/llvm/include/llvm/Analysis/CFG.h
@@ -174,6 +174,25 @@ bool containsIrreducibleCFG(RPOTraversalT &RPOTraversal, const LoopInfoT &LI) {
return false;
}
+
+// Returns true if these basic blocks belong to a presplit coroutine and the
+// edge corresponds to the 'default' case in the switch statement in the
+// pattern:
+//
+// %0 = call i8 @llvm.coro.suspend(token none, i1 false)
+// switch i8 %0, label %suspend [i8 0, label %resume
+// i8 1, label %cleanup]
+//
+// i.e. the edge to the `%suspend` BB. This edge is special in that it will
+// be elided by coroutine lowering (coro-split), and the `%suspend` BB needs
+// to be kept as-is. It's not a real CFG edge - post-lowering, it will end
+// up being a `ret`, and it must be thus lowerable to support symmetric
+// transfer. For example:
+// - this edge is not a loop exit edge if encountered in a loop (and should
+// be ignored)
+// - must not be split for PGO instrumentation, for example.
+bool isPresplitCoroSuspendExitEdge(const BasicBlock &Src,
+ const BasicBlock &Dest);
} // End llvm namespace
#endif
diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index 6faff3d1fd8e3..adc1851c2ec2f 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -610,24 +610,6 @@ void InvertBranch(BranchInst *PBI, IRBuilderBase &Builder);
// br/brcond/unreachable/ret
bool hasOnlySimpleTerminator(const Function &F);
-// Returns true if these basic blocks belong to a presplit coroutine and the
-// edge corresponds to the 'default' case in the switch statement in the
-// pattern:
-//
-// %0 = call i8 @llvm.coro.suspend(token none, i1 false)
-// switch i8 %0, label %suspend [i8 0, label %resume
-// i8 1, label %cleanup]
-//
-// i.e. the edge to the `%suspend` BB. This edge is special in that it will
-// be elided by coroutine lowering (coro-split), and the `%suspend` BB needs
-// to be kept as-is. It's not a real CFG edge - post-lowering, it will end
-// up being a `ret`, and it must be thus lowerable to support symmetric
-// transfer. For example:
-// - this edge is not a loop exit edge if encountered in a loop (and should
-// be ignored)
-// - must not be split for PGO instrumentation, for example.
-bool isPresplitCoroSuspendExitEdge(const BasicBlock &Src,
- const BasicBlock &Dest);
} // end namespace llvm
#endif // LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H
diff --git a/llvm/lib/Analysis/CFG.cpp b/llvm/lib/Analysis/CFG.cpp
index 841b835052380..ded5327c09b55 100644
--- a/llvm/lib/Analysis/CFG.cpp
+++ b/llvm/lib/Analysis/CFG.cpp
@@ -14,6 +14,7 @@
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h"
+#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
@@ -322,3 +323,15 @@ bool llvm::isPotentiallyReachable(
return isPotentiallyReachable(
A->getParent(), B->getParent(), ExclusionSet, DT, LI);
}
+
+bool llvm::isPresplitCoroSuspendExitEdge(const BasicBlock &Src,
+ const BasicBlock &Dest) {
+ assert(Src.getParent() == Dest.getParent());
+ if (!Src.getParent()->isPresplitCoroutine())
+ return false;
+ if (auto *SW = dyn_cast<SwitchInst>(Src.getTerminator()))
+ if (auto *Intr = dyn_cast<IntrinsicInst>(SW->getCondition()))
+ return Intr->getIntrinsicID() == Intrinsic::coro_suspend &&
+ SW->getDefaultDest() == &Dest;
+ return false;
+}
\ No newline at end of file
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 008c1faf0a0c3..84bf4c62c7aad 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -20,6 +20,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
+#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/Attributes.h"
diff --git a/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp b/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
index 05f364a974c6c..508a41684ed20 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
@@ -21,6 +21,7 @@
#include "llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
+#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/CtxProfAnalysis.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/IR/Analysis.h"
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 6f36e24000aa5..b78270f6309ff 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1916,15 +1916,3 @@ bool llvm::hasOnlySimpleTerminator(const Function &F) {
}
return true;
}
-
-bool llvm::isPresplitCoroSuspendExitEdge(const BasicBlock &Src,
- const BasicBlock &Dest) {
- assert(Src.getParent() == Dest.getParent());
- if (!Src.getParent()->isPresplitCoroutine())
- return false;
- if (auto *SW = dyn_cast<SwitchInst>(Src.getTerminator()))
- if (auto *Intr = dyn_cast<IntrinsicInst>(SW->getCondition()))
- return Intr->getIntrinsicID() == Intrinsic::coro_suspend &&
- SW->getDefaultDest() == &Dest;
- return false;
-}
``````````
</details>
https://github.com/llvm/llvm-project/pull/135849
More information about the llvm-commits
mailing list