[PATCH] D156850: [NFC][Coroutines] Use a reverse post-order to guide the computation about cross suspend infomation to reach a fixed point faster.
Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 20:23:34 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG132bb5cc5fd5: [NFC][Coroutines] Use a reverse post-order to guide the computation about cross… (authored by witstorm95, committed by Chuanqi Xu <chuaniq.xcq at alibaba-inc.com>).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156850/new/
https://reviews.llvm.org/D156850
Files:
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Index: llvm/lib/Transforms/Coroutines/CoroFrame.cpp
===================================================================
--- llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -63,7 +63,7 @@
llvm::sort(V);
}
- size_t blockToIndex(BasicBlock *BB) const {
+ size_t blockToIndex(BasicBlock const *BB) const {
auto *I = llvm::lower_bound(V, BB);
assert(I != V.end() && *I == BB && "BasicBlockNumberng: Unknown block");
return I - V.begin();
@@ -112,10 +112,11 @@
}
/// Compute the BlockData for the current function in one iteration.
- /// Returns whether the BlockData changes in this iteration.
/// Initialize - Whether this is the first iteration, we can optimize
/// the initial case a little bit by manual loop switch.
- template <bool Initialize = false> bool computeBlockData();
+ /// Returns whether the BlockData changes in this iteration.
+ template <bool Initialize = false>
+ bool computeBlockData(const ReversePostOrderTraversal<Function *> &RPOT);
public:
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -223,12 +224,14 @@
}
#endif
-template <bool Initialize> bool SuspendCrossingInfo::computeBlockData() {
- const size_t N = Mapping.size();
+template <bool Initialize>
+bool SuspendCrossingInfo::computeBlockData(
+ const ReversePostOrderTraversal<Function *> &RPOT) {
bool Changed = false;
- for (size_t I = 0; I < N; ++I) {
- auto &B = Block[I];
+ for (const BasicBlock *BB : RPOT) {
+ auto BBNo = Mapping.blockToIndex(BB);
+ auto &B = Block[BBNo];
// We don't need to count the predecessors when initialization.
if constexpr (!Initialize)
@@ -261,7 +264,7 @@
}
if (B.Suspend) {
- // If block S is a suspend block, it should kill all of the blocks it
+ // If block B is a suspend block, it should kill all of the blocks it
// consumes.
B.Kills |= B.Consumes;
} else if (B.End) {
@@ -273,8 +276,8 @@
} else {
// This is reached when B block it not Suspend nor coro.end and it
// need to make sure that it is not in the kill set.
- B.KillLoop |= B.Kills[I];
- B.Kills.reset(I);
+ B.KillLoop |= B.Kills[BBNo];
+ B.Kills.reset(BBNo);
}
if constexpr (!Initialize) {
@@ -283,9 +286,6 @@
}
}
- if constexpr (Initialize)
- return true;
-
return Changed;
}
@@ -325,9 +325,11 @@
markSuspendBlock(Save);
}
- computeBlockData</*Initialize=*/true>();
-
- while (computeBlockData())
+ // It is considered to be faster to use RPO traversal for forward-edges
+ // dataflow analysis.
+ ReversePostOrderTraversal<Function *> RPOT(&F);
+ computeBlockData</*Initialize=*/true>(RPOT);
+ while (computeBlockData</*Initialize*/ false>(RPOT))
;
LLVM_DEBUG(dump());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156850.548449.patch
Type: text/x-patch
Size: 2831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230809/a7540d5c/attachment.bin>
More information about the llvm-commits
mailing list