Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 0a7ed28

Browse files
committed
MachineDominators: Move applySplitCriticalEdges into the cpp file.
It's too big for inlining anyways. Also clean it up slightly. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230806 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7de1732 commit 0a7ed28

File tree

2 files changed

+68
-72
lines changed

2 files changed

+68
-72
lines changed

include/llvm/CodeGen/MachineDominators.h

+2-72
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ class MachineDominatorTree : public MachineFunctionPass {
4545
MachineBasicBlock *FromBB;
4646
MachineBasicBlock *ToBB;
4747
MachineBasicBlock *NewBB;
48-
CriticalEdge(MachineBasicBlock *FromBB, MachineBasicBlock *ToBB,
49-
MachineBasicBlock *NewBB)
50-
: FromBB(FromBB), ToBB(ToBB), NewBB(NewBB) {}
5148
};
5249

5350
/// \brief Pile up all the critical edges to be split.
@@ -67,74 +64,7 @@ class MachineDominatorTree : public MachineFunctionPass {
6764
/// the fast query path of DT as much as possible.
6865
///
6966
/// \post CriticalEdgesToSplit.empty().
70-
void applySplitCriticalEdges() const {
71-
// Bail out early if there is nothing to do.
72-
if (CriticalEdgesToSplit.empty())
73-
return;
74-
75-
// For each element in CriticalEdgesToSplit, remember whether or
76-
// not element is the new immediate domminator of its successor.
77-
// The mapping is done by index, i.e., the information for the ith
78-
// element of CriticalEdgesToSplit is the ith element of IsNewIDom.
79-
SmallVector<bool, 32> IsNewIDom;
80-
IsNewIDom.resize(CriticalEdgesToSplit.size());
81-
size_t Idx = 0;
82-
83-
// Collect all the dominance properties info, before invalidating
84-
// the underlying DT.
85-
for (CriticalEdge &Edge : CriticalEdgesToSplit) {
86-
// Update dominator information.
87-
MachineBasicBlock *Succ = Edge.ToBB;
88-
MachineDomTreeNode *SucccDTNode = DT->getNode(Succ);
89-
90-
IsNewIDom[Idx] = true;
91-
for (MachineBasicBlock *PredBB : Succ->predecessors()) {
92-
if (PredBB == Edge.NewBB)
93-
continue;
94-
// If we are in this situation:
95-
// FromBB1 FromBB2
96-
// + +
97-
// + + + +
98-
// + + + +
99-
// ... Split1 Split2 ...
100-
// + +
101-
// + +
102-
// +
103-
// Succ
104-
// Instead of checking the domiance property with Split2, we
105-
// check it with FromBB2 since Split2 is still unknown of the
106-
// underlying DT structure.
107-
if (NewBBs.count(PredBB)) {
108-
assert(PredBB->pred_size() == 1 && "A basic block resulting from a "
109-
"critical edge split has more "
110-
"than one predecessor!");
111-
PredBB = *PredBB->pred_begin();
112-
}
113-
if (!DT->dominates(SucccDTNode, DT->getNode(PredBB))) {
114-
IsNewIDom[Idx] = false;
115-
break;
116-
}
117-
}
118-
++Idx;
119-
}
120-
121-
// Now, update DT with the collected dominance properties info.
122-
Idx = 0;
123-
for (CriticalEdge &Edge : CriticalEdgesToSplit) {
124-
// We know FromBB dominates NewBB.
125-
MachineDomTreeNode *NewDTNode = DT->addNewBlock(Edge.NewBB, Edge.FromBB);
126-
MachineDomTreeNode *SucccDTNode = DT->getNode(Edge.ToBB);
127-
128-
// If all the other predecessors of "Succ" are dominated by "Succ" itself
129-
// then the new block is the new immediate dominator of "Succ". Otherwise,
130-
// the new block doesn't dominate anything.
131-
if (IsNewIDom[Idx])
132-
DT->changeImmediateDominator(SucccDTNode, NewDTNode);
133-
++Idx;
134-
}
135-
NewBBs.clear();
136-
CriticalEdgesToSplit.clear();
137-
}
67+
void applySplitCriticalEdges() const;
13868

13969
public:
14070
static char ID; // Pass ID, replacement for typeid
@@ -307,7 +237,7 @@ class MachineDominatorTree : public MachineFunctionPass {
307237
(void)Inserted;
308238
assert(Inserted &&
309239
"A basic block inserted via edge splitting cannot appear twice");
310-
CriticalEdgesToSplit.push_back(CriticalEdge(FromBB, ToBB, NewBB));
240+
CriticalEdgesToSplit.push_back({FromBB, ToBB, NewBB});
311241
}
312242
};
313243

lib/CodeGen/MachineDominators.cpp

+66
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "llvm/CodeGen/MachineDominators.h"
1616
#include "llvm/CodeGen/Passes.h"
17+
#include "llvm/ADT/SmallBitVector.h"
1718

1819
using namespace llvm;
1920

@@ -59,3 +60,68 @@ void MachineDominatorTree::releaseMemory() {
5960
void MachineDominatorTree::print(raw_ostream &OS, const Module*) const {
6061
DT->print(OS);
6162
}
63+
64+
void MachineDominatorTree::applySplitCriticalEdges() const {
65+
// Bail out early if there is nothing to do.
66+
if (CriticalEdgesToSplit.empty())
67+
return;
68+
69+
// For each element in CriticalEdgesToSplit, remember whether or not element
70+
// is the new immediate domminator of its successor. The mapping is done by
71+
// index, i.e., the information for the ith element of CriticalEdgesToSplit is
72+
// the ith element of IsNewIDom.
73+
SmallBitVector IsNewIDom(CriticalEdgesToSplit.size(), true);
74+
size_t Idx = 0;
75+
76+
// Collect all the dominance properties info, before invalidating
77+
// the underlying DT.
78+
for (CriticalEdge &Edge : CriticalEdgesToSplit) {
79+
// Update dominator information.
80+
MachineBasicBlock *Succ = Edge.ToBB;
81+
MachineDomTreeNode *SuccDTNode = DT->getNode(Succ);
82+
83+
for (MachineBasicBlock *PredBB : Succ->predecessors()) {
84+
if (PredBB == Edge.NewBB)
85+
continue;
86+
// If we are in this situation:
87+
// FromBB1 FromBB2
88+
// + +
89+
// + + + +
90+
// + + + +
91+
// ... Split1 Split2 ...
92+
// + +
93+
// + +
94+
// +
95+
// Succ
96+
// Instead of checking the domiance property with Split2, we check it with
97+
// FromBB2 since Split2 is still unknown of the underlying DT structure.
98+
if (NewBBs.count(PredBB)) {
99+
assert(PredBB->pred_size() == 1 && "A basic block resulting from a "
100+
"critical edge split has more "
101+
"than one predecessor!");
102+
PredBB = *PredBB->pred_begin();
103+
}
104+
if (!DT->dominates(SuccDTNode, DT->getNode(PredBB))) {
105+
IsNewIDom[Idx] = false;
106+
break;
107+
}
108+
}
109+
++Idx;
110+
}
111+
112+
// Now, update DT with the collected dominance properties info.
113+
Idx = 0;
114+
for (CriticalEdge &Edge : CriticalEdgesToSplit) {
115+
// We know FromBB dominates NewBB.
116+
MachineDomTreeNode *NewDTNode = DT->addNewBlock(Edge.NewBB, Edge.FromBB);
117+
118+
// If all the other predecessors of "Succ" are dominated by "Succ" itself
119+
// then the new block is the new immediate dominator of "Succ". Otherwise,
120+
// the new block doesn't dominate anything.
121+
if (IsNewIDom[Idx])
122+
DT->changeImmediateDominator(DT->getNode(Edge.ToBB), NewDTNode);
123+
++Idx;
124+
}
125+
NewBBs.clear();
126+
CriticalEdgesToSplit.clear();
127+
}

0 commit comments

Comments
 (0)