llvm.org GIT mirror llvm / e9106e2
Do not verify MachimeDominatorTree if it is not calculated If dominator tree is not calculated or is invalidated, set corresponding pointer in the pass state to nullptr. Such pointer value will indicate that operations with dominator tree are not allowed. In particular, it allows to skip verification for such pass state. The dominator tree is not calculated if the machine dominator pass was skipped, it occures in the case of entities with linkage available_externally. The change fixes some test fails observed when expensive checks are enabled. Differential Revision: https://reviews.llvm.org/D29280 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296742 91177308-0d34-0410-b5e6-96231b3b80d8 Serge Pavlov 3 years ago
3 changed file(s) with 19 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
2020 #include "llvm/CodeGen/MachineFunctionPass.h"
2121 #include "llvm/Support/GenericDomTree.h"
2222 #include "llvm/Support/GenericDomTreeConstruction.h"
23 #include
2324
2425 namespace llvm {
2526
5960 mutable SmallSet NewBBs;
6061
6162 /// The DominatorTreeBase that is used to compute a normal dominator tree
62 DominatorTreeBase* DT;
63 std::unique_ptr> DT;
6364
6465 /// \brief Apply all the recorded critical edges to the DT.
6566 /// This updates the underlying DT information in a way that uses
7374
7475 MachineDominatorTree();
7576
76 ~MachineDominatorTree() override;
77
7877 DominatorTreeBase &getBase() {
78 if (!DT)
79 DT.reset(new DominatorTreeBase(false));
7980 applySplitCriticalEdges();
8081 return *DT;
8182 }
243244 CriticalEdgesToSplit.push_back({FromBB, ToBB, NewBB});
244245 }
245246
246 /// \brief Returns *false* if the other dominator tree matches this dominator
247 /// tree.
248 inline bool compare(const MachineDominatorTree &Other) const {
249 const MachineDomTreeNode *R = getRootNode();
250 const MachineDomTreeNode *OtherR = Other.getRootNode();
251
252 if (!R || !OtherR || R->getBlock() != OtherR->getBlock())
253 return true;
254
255 if (DT->compare(*Other.DT))
256 return true;
257
258 return false;
259 }
260
261247 /// \brief Verify the correctness of the domtree by re-computing it.
262248 ///
263249 /// This should only be used for debugging as it aborts the program if the
4848 bool MachineDominatorTree::runOnMachineFunction(MachineFunction &F) {
4949 CriticalEdgesToSplit.clear();
5050 NewBBs.clear();
51 DT.reset(new DominatorTreeBase(false));
5152 DT->recalculate(F);
52
5353 return false;
5454 }
5555
5656 MachineDominatorTree::MachineDominatorTree()
5757 : MachineFunctionPass(ID) {
5858 initializeMachineDominatorTreePass(*PassRegistry::getPassRegistry());
59 DT = new DominatorTreeBase(false);
60 }
61
62 MachineDominatorTree::~MachineDominatorTree() {
63 delete DT;
6459 }
6560
6661 void MachineDominatorTree::releaseMemory() {
67 DT->releaseMemory();
62 CriticalEdgesToSplit.clear();
63 DT.reset(nullptr);
6864 }
6965
7066 void MachineDominatorTree::verifyAnalysis() const {
71 if (VerifyMachineDomInfo)
67 if (DT && VerifyMachineDomInfo)
7268 verifyDomTree();
7369 }
7470
7571 void MachineDominatorTree::print(raw_ostream &OS, const Module*) const {
76 DT->print(OS);
72 if (DT)
73 DT->print(OS);
7774 }
7875
7976 void MachineDominatorTree::applySplitCriticalEdges() const {
142139 }
143140
144141 void MachineDominatorTree::verifyDomTree() const {
142 if (!DT)
143 return;
145144 MachineFunction &F = *getRoot()->getParent();
146145
147 MachineDominatorTree OtherDT;
148 OtherDT.DT->recalculate(F);
149 if (compare(OtherDT)) {
146 DominatorTreeBase OtherDT(false);
147 OtherDT.recalculate(F);
148 if (getRootNode()->getBlock() != OtherDT.getRootNode()->getBlock() ||
149 DT->compare(OtherDT)) {
150150 errs() << "MachineDominatorTree is not up to date!\nComputed:\n";
151 print(errs(), nullptr);
151 DT->print(errs());
152152 errs() << "\nActual:\n";
153 OtherDT.print(errs(), nullptr);
153 OtherDT.print(errs());
154154 abort();
155155 }
156156 }
None ; RUN: llc < %s | not grep test_
0 ; RUN: llc -verify-machine-dom-info < %s | not grep test_
11
22 ; test_function should not be emitted to the .s file.
33 define available_externally i32 @test_function() {