[PATCH] D31641: [CodeGen] Only require DT in DwarfEHPrepare if > CodeGenOpt::None.

Ahmed Bougacha via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 19:23:27 PDT 2017


ab created this revision.

The pass only uses DT in isPotentiallyReachable, to erase unreachable
resumes.  Not having DT available should still produce valid, though
conservative, results.

Instead, only add DT to the pipeline if > CodeGenOpt::None.


https://reviews.llvm.org/D31641

Files:
  lib/CodeGen/DwarfEHPrepare.cpp
  lib/CodeGen/TargetPassConfig.cpp
  test/CodeGen/X86/O0-pipeline.ll


Index: test/CodeGen/X86/O0-pipeline.ll
===================================================================
--- test/CodeGen/X86/O0-pipeline.ll
+++ test/CodeGen/X86/O0-pipeline.ll
@@ -25,7 +25,6 @@
 ; CHECK-NEXT:       Inserts calls to mcount-like functions
 ; CHECK-NEXT:     Rewrite Symbols
 ; CHECK-NEXT:     FunctionPass Manager
-; CHECK-NEXT:       Dominator Tree Construction
 ; CHECK-NEXT:       Exception handling preparation
 ; CHECK-NEXT:       Safe Stack instrumentation pass
 ; CHECK-NEXT:       Insert stack protectors
Index: lib/CodeGen/TargetPassConfig.cpp
===================================================================
--- lib/CodeGen/TargetPassConfig.cpp
+++ lib/CodeGen/TargetPassConfig.cpp
@@ -24,6 +24,7 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/RegisterUsageInfo.h"
+#include "llvm/IR/Dominators.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Verifier.h"
@@ -502,13 +503,17 @@
     LLVM_FALLTHROUGH;
   case ExceptionHandling::DwarfCFI:
   case ExceptionHandling::ARM:
+    if (getOptLevel() != CodeGenOpt::None)
+      addPass(&DominatorTreeWrapperPass::ID);
     addPass(createDwarfEHPass(TM));
     break;
   case ExceptionHandling::WinEH:
     // We support using both GCC-style and MSVC-style exceptions on Windows, so
     // add both preparation passes. Each pass will only actually run if it
     // recognizes the personality function.
     addPass(createWinEHPass(TM));
+    if (getOptLevel() != CodeGenOpt::None)
+      addPass(&DominatorTreeWrapperPass::ID);
     addPass(createDwarfEHPass(TM));
     break;
   case ExceptionHandling::None:
Index: lib/CodeGen/DwarfEHPrepare.cpp
===================================================================
--- lib/CodeGen/DwarfEHPrepare.cpp
+++ lib/CodeGen/DwarfEHPrepare.cpp
@@ -80,7 +80,6 @@
 char DwarfEHPrepare::ID = 0;
 INITIALIZE_TM_PASS_BEGIN(DwarfEHPrepare, "dwarfehprepare",
                          "Prepare DWARF exceptions", false, false)
-INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
 INITIALIZE_TM_PASS_END(DwarfEHPrepare, "dwarfehprepare",
                        "Prepare DWARF exceptions", false, false)
@@ -91,7 +90,7 @@
 
 void DwarfEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<TargetTransformInfoWrapperPass>();
-  AU.addRequired<DominatorTreeWrapperPass>();
+  AU.addUsedIfAvailable<DominatorTreeWrapperPass>();
 }
 
 /// GetExceptionObject - Return the exception object from the value passed into
@@ -255,7 +254,10 @@
 
 bool DwarfEHPrepare::runOnFunction(Function &Fn) {
   assert(TM && "DWARF EH preparation requires a target machine");
-  DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+  if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
+    DT = &DTWP->getDomTree();
+  else
+    DT = nullptr;
   TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
   bool Changed = InsertUnwindResumeCalls(Fn);
   DT = nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31641.93989.patch
Type: text/x-patch
Size: 3079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170404/e8859bd8/attachment.bin>


More information about the llvm-commits mailing list