[PATCH] D75032: [MachineVerifier] Doing ::calcRegsPassed in RPO: ~35% faster MV
Roman Tereshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 13:16:12 PST 2020
rtereshin updated this revision to Diff 246288.
rtereshin marked an inline comment as done.
rtereshin added a comment.
Trimming down the comments a little bit as requested.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75032/new/
https://reviews.llvm.org/D75032
Files:
llvm/lib/CodeGen/MachineVerifier.cpp
Index: llvm/lib/CodeGen/MachineVerifier.cpp
===================================================================
--- llvm/lib/CodeGen/MachineVerifier.cpp
+++ llvm/lib/CodeGen/MachineVerifier.cpp
@@ -24,6 +24,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetOperations.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -2126,34 +2127,46 @@
// can pass through an MBB live, but may not be live every time. It is assumed
// that all vregsPassed sets are empty before the call.
void MachineVerifier::calcRegsPassed() {
+ // This is a forward dataflow, doing it in RPO. A standard map serves as a
+ // priority (sorting by RPO number) queue, deduplicating worklist, and an RPO
+ // number to MBB mapping all at once.
+ std::map<unsigned, const MachineBasicBlock *> RPOWorklist;
+ DenseMap<const MachineBasicBlock *, unsigned> RPONumbers;
+ if (MF->empty()) {
+ // ReversePostOrderTraversal doesn't handle empty functions.
+ return;
+ }
+ for (const MachineBasicBlock *MBB :
+ ReversePostOrderTraversal<const MachineFunction *>(MF)) {
+ // Careful with the evaluation order, fetch next number before allocating.
+ unsigned Number = RPONumbers.size();
+ RPONumbers[MBB] = Number;
+ }
// First push live-out regs to successors' vregsPassed. Remember the MBBs that
// have any vregsPassed.
- SmallPtrSet<const MachineBasicBlock*, 8> todo;
- for (const auto &MBB : *MF) {
+ for (const MachineBasicBlock &MBB : *MF) {
BBInfo &MInfo = MBBInfoMap[&MBB];
if (!MInfo.reachable)
continue;
- for (MachineBasicBlock::const_succ_iterator SuI = MBB.succ_begin(),
- SuE = MBB.succ_end(); SuI != SuE; ++SuI) {
- BBInfo &SInfo = MBBInfoMap[*SuI];
+ for (const MachineBasicBlock *Succ : MBB.successors()) {
+ BBInfo &SInfo = MBBInfoMap[Succ];
if (SInfo.addPassed(MInfo.regsLiveOut))
- todo.insert(*SuI);
+ RPOWorklist.emplace(RPONumbers[Succ], Succ);
}
}
- // Iteratively push vregsPassed to successors. This will converge to the same
- // final state regardless of DenseSet iteration order.
- while (!todo.empty()) {
- const MachineBasicBlock *MBB = *todo.begin();
- todo.erase(MBB);
+ // Iteratively push vregsPassed to successors.
+ while (!RPOWorklist.empty()) {
+ auto Next = RPOWorklist.begin();
+ const MachineBasicBlock *MBB = Next->second;
+ RPOWorklist.erase(Next);
BBInfo &MInfo = MBBInfoMap[MBB];
- for (MachineBasicBlock::const_succ_iterator SuI = MBB->succ_begin(),
- SuE = MBB->succ_end(); SuI != SuE; ++SuI) {
- if (*SuI == MBB)
+ for (const MachineBasicBlock *Succ : MBB->successors()) {
+ if (Succ == MBB)
continue;
- BBInfo &SInfo = MBBInfoMap[*SuI];
+ BBInfo &SInfo = MBBInfoMap[Succ];
if (SInfo.addPassed(MInfo.vregsPassed))
- todo.insert(*SuI);
+ RPOWorklist.emplace(RPONumbers[Succ], Succ);
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75032.246288.patch
Type: text/x-patch
Size: 3061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200224/a8ce7bfa/attachment-0001.bin>
More information about the llvm-commits
mailing list