[llvm] [BOLT] Speed up dataflow analysis with RPO (PR #183704)
Haibo Jiang via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 4 18:03:35 PST 2026
https://github.com/Jianghibo updated https://github.com/llvm/llvm-project/pull/183704
>From 02a55df61f54197c868bc70e9d7bae7c944ce5cc Mon Sep 17 00:00:00 2001
From: jianghaibo <jianghaibo9 at huawei.com>
Date: Fri, 27 Feb 2026 16:54:27 +0800
Subject: [PATCH] [BOLT] Speed up dataflow analysis with RPO
---
bolt/include/bolt/Passes/DataflowAnalysis.h | 45 +++++++++++++++------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/bolt/include/bolt/Passes/DataflowAnalysis.h b/bolt/include/bolt/Passes/DataflowAnalysis.h
index f6ca39cf6f860..3b182abb231fc 100644
--- a/bolt/include/bolt/Passes/DataflowAnalysis.h
+++ b/bolt/include/bolt/Passes/DataflowAnalysis.h
@@ -11,6 +11,7 @@
#include "bolt/Core/BinaryContext.h"
#include "bolt/Core/BinaryFunction.h"
+#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/Support/Errc.h"
#include <optional>
#include <queue>
@@ -332,23 +333,41 @@ class DataflowAnalysis {
}
std::queue<BinaryBasicBlock *> Worklist;
- // TODO: Pushing this in a DFS ordering will greatly speed up the dataflow
- // performance.
+ DenseSet<BinaryBasicBlock *> BBs;
if (!Backward) {
+ llvm::ReversePostOrderTraversal<BinaryFunction *> RPOT(&Func);
+ for (BinaryBasicBlock *BB : RPOT) {
+ Worklist.push(BB);
+ BBs.insert(BB);
+ }
+ } else {
+ for (BinaryBasicBlock *BB : post_order(&Func)) {
+ Worklist.push(BB);
+ BBs.insert(BB);
+ }
+ }
+
+ // Reverse post-order and post-order will leave unreachable basic
+ // blocks. Here will identify and add them to the worklist.
+ if (BBs.size() != Func.size()) {
for (BinaryBasicBlock &BB : Func) {
- Worklist.push(&BB);
- MCInst *Prev = nullptr;
- for (MCInst &Inst : BB) {
- PrevPoint[&Inst] = Prev ? ProgramPoint(Prev) : ProgramPoint(&BB);
- Prev = &Inst;
+ if (!BBs.count(&BB)) {
+ Worklist.push(&BB);
+ BBs.insert(&BB);
}
}
- } else {
- for (BinaryBasicBlock &BB : llvm::reverse(Func)) {
- Worklist.push(&BB);
- MCInst *Prev = nullptr;
- for (MCInst &Inst : llvm::reverse(BB)) {
- PrevPoint[&Inst] = Prev ? ProgramPoint(Prev) : ProgramPoint(&BB);
+ }
+
+ for (auto *BB : BBs) {
+ MCInst *Prev = nullptr;
+ if (!Backward) {
+ for (MCInst &Inst : *BB) {
+ PrevPoint[&Inst] = Prev ? ProgramPoint(Prev) : ProgramPoint(BB);
+ Prev = &Inst;
+ }
+ } else {
+ for (MCInst &Inst : llvm::reverse(*BB)) {
+ PrevPoint[&Inst] = Prev ? ProgramPoint(Prev) : ProgramPoint(BB);
Prev = &Inst;
}
}
More information about the llvm-commits
mailing list