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(); - AU.addRequired(); + AU.addUsedIfAvailable(); } /// 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().getDomTree(); + if (auto *DTWP = getAnalysisIfAvailable()) + DT = &DTWP->getDomTree(); + else + DT = nullptr; TLI = TM->getSubtargetImpl(Fn)->getTargetLowering(); bool Changed = InsertUnwindResumeCalls(Fn); DT = nullptr; 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,6 +503,8 @@ LLVM_FALLTHROUGH; case ExceptionHandling::DwarfCFI: case ExceptionHandling::ARM: + if (getOptLevel() != CodeGenOpt::None) + addPass(&DominatorTreeWrapperPass::ID); addPass(createDwarfEHPass(TM)); break; case ExceptionHandling::WinEH: @@ -509,6 +512,8 @@ // 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: 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