]> granicus.if.org Git - llvm/commitdiff
[Dominators][CodeGen] Add MachinePostDominatorTree verification
authorJakub Kuderski <kubakuderski@gmail.com>
Tue, 1 Oct 2019 15:23:27 +0000 (15:23 +0000)
committerJakub Kuderski <kubakuderski@gmail.com>
Tue, 1 Oct 2019 15:23:27 +0000 (15:23 +0000)
Summary:
This patch implements Machine PostDominator Tree verification and ensures that the verification doesn't fail the in-tree tests.

MPDT verification can be enabled using `verify-machine-dom-info` -- the same flag used by Machine Dominator Tree verification.

Flipping the flag revealed that MachineSink falsely claimed to preserve CFG and MDT/MPDT. This patch fixes that.

Reviewers: arsenm, hliao, rampitec, vpykhtin, grosser

Reviewed By: hliao

Subscribers: wdng, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D68235

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373341 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachinePostDominators.h
lib/CodeGen/MachineDominators.cpp
lib/CodeGen/MachinePostDominators.cpp
lib/CodeGen/MachineSink.cpp
test/CodeGen/AArch64/O3-pipeline.ll

index a0c2c78de8d4cce9d01e09e2b2007480b82195a2..cb258b5e7b2170afb2e12d135ca5886828c73fbb 100644 (file)
@@ -85,6 +85,7 @@ public:
   bool runOnMachineFunction(MachineFunction &MF) override;
   void getAnalysisUsage(AnalysisUsage &AU) const override;
   void releaseMemory() override { PDT.reset(nullptr); }
+  void verifyAnalysis() const override;
   void print(llvm::raw_ostream &OS, const Module *M = nullptr) const override;
 };
 } //end of namespace llvm
index 1dfba8638c2271abc34fae562ef8823957f4189b..b569ca42d68277af64920e2f13fe90e32db47dee 100644 (file)
 
 using namespace llvm;
 
+namespace llvm {
 // Always verify dominfo if expensive checking is enabled.
 #ifdef EXPENSIVE_CHECKS
-static bool VerifyMachineDomInfo = true;
+bool VerifyMachineDomInfo = true;
 #else
-static bool VerifyMachineDomInfo = false;
+bool VerifyMachineDomInfo = false;
 #endif
+} // namespace llvm
+
 static cl::opt<bool, true> VerifyMachineDomInfoX(
     "verify-machine-dom-info", cl::location(VerifyMachineDomInfo), cl::Hidden,
     cl::desc("Verify machine dominator info (time consuming)"));
index f2fc9f814f821b216a2176a65501c786b1ebf84e..f4daff667e86df70202bca25143bda8165e8db5e 100644 (file)
 
 #include "llvm/CodeGen/MachinePostDominators.h"
 
-#include "llvm/ADT/STLExtras.h"
-
 using namespace llvm;
 
 namespace llvm {
 template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
-}
+
+extern bool VerifyMachineDomInfo;
+} // namespace llvm
 
 char MachinePostDominatorTree::ID = 0;
 
@@ -63,6 +63,15 @@ MachineBasicBlock *MachinePostDominatorTree::findNearestCommonDominator(
   return NCD;
 }
 
+void MachinePostDominatorTree::verifyAnalysis() const {
+  if (PDT && VerifyMachineDomInfo)
+    if (!PDT->verify(PostDomTreeT::VerificationLevel::Basic)) {
+      errs() << "MachinePostDominatorTree verification failed\n";
+
+      abort();
+    }
+}
+
 void MachinePostDominatorTree::print(llvm::raw_ostream &OS,
                                      const Module *M) const {
   PDT->print(OS);
index 8f0d436dfa50505037affb8d53d8c18a4b938595..27a2e7023f222ffa0704baf2940e8cec2d476560 100644 (file)
@@ -115,15 +115,12 @@ namespace {
     bool runOnMachineFunction(MachineFunction &MF) override;
 
     void getAnalysisUsage(AnalysisUsage &AU) const override {
-      AU.setPreservesCFG();
       MachineFunctionPass::getAnalysisUsage(AU);
       AU.addRequired<AAResultsWrapperPass>();
       AU.addRequired<MachineDominatorTree>();
       AU.addRequired<MachinePostDominatorTree>();
       AU.addRequired<MachineLoopInfo>();
       AU.addRequired<MachineBranchProbabilityInfo>();
-      AU.addPreserved<MachineDominatorTree>();
-      AU.addPreserved<MachinePostDominatorTree>();
       AU.addPreserved<MachineLoopInfo>();
       if (UseBlockFreqInfo)
         AU.addRequired<MachineBlockFrequencyInfo>();
index 2d5f6675100581ae066b548f84fafa5c7af1ba17..37540652c2fe600d001ab5921a8f3386909e7676 100644 (file)
 ; CHECK-NEXT:       Live Variable Analysis
 ; CHECK-NEXT:       Eliminate PHI nodes for register allocation
 ; CHECK-NEXT:       Two-Address instruction pass
+; CHECK-NEXT:       MachineDominator Tree Construction
 ; CHECK-NEXT:       Slot index numbering
 ; CHECK-NEXT:       Live Interval Analysis
 ; CHECK-NEXT:       Simple Register Coalescing