[llvm] 61e58c4 - [CodeGen] Port DwarfEHPrepare to new pass manager (#72500)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 28 00:53:29 PST 2023
Author: paperchalice
Date: 2023-11-28T17:53:25+09:00
New Revision: 61e58c4dc1001597c48d59a37884a534ab37b47b
URL: https://github.com/llvm/llvm-project/commit/61e58c4dc1001597c48d59a37884a534ab37b47b
DIFF: https://github.com/llvm/llvm-project/commit/61e58c4dc1001597c48d59a37884a534ab37b47b.diff
LOG: [CodeGen] Port DwarfEHPrepare to new pass manager (#72500)
Co-authored-by: PaperChalice <example at example.com>
Added:
llvm/include/llvm/CodeGen/DwarfEHPrepare.h
Modified:
llvm/lib/CodeGen/DwarfEHPrepare.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/test/CodeGen/X86/dwarf-eh-prepare-dbg.ll
llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
llvm/test/CodeGen/X86/dwarf_eh_resume.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/DwarfEHPrepare.h b/llvm/include/llvm/CodeGen/DwarfEHPrepare.h
new file mode 100644
index 000000000000000..3f625cd89808a22
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/DwarfEHPrepare.h
@@ -0,0 +1,33 @@
+//===------------------- llvm/CodeGen/DwarfEHPrepare.h ----------*- C++-*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass mulches exception handling code into a form adapted to code
+// generation. Required if using dwarf exception handling.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_DWARFEHPREPARE_H
+#define LLVM_CODEGEN_DWARFEHPREPARE_H
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+class TargetMachine;
+
+class DwarfEHPreparePass : public PassInfoMixin<DwarfEHPreparePass> {
+ const TargetMachine *TM;
+
+public:
+ explicit DwarfEHPreparePass(const TargetMachine *TM_) : TM(TM_) {}
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_DWARFEHPREPARE_H
diff --git a/llvm/lib/CodeGen/DwarfEHPrepare.cpp b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
index 50cb010bbfc36d0..a44aaf33c6a4997 100644
--- a/llvm/lib/CodeGen/DwarfEHPrepare.cpp
+++ b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/DwarfEHPrepare.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
@@ -365,6 +366,27 @@ class DwarfEHPrepareLegacyPass : public FunctionPass {
} // end anonymous namespace
+PreservedAnalyses DwarfEHPreparePass::run(Function &F,
+ FunctionAnalysisManager &FAM) {
+ const auto &TLI = *TM->getSubtargetImpl(F)->getTargetLowering();
+ auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(F);
+ const TargetTransformInfo *TTI = nullptr;
+ auto OptLevel = TM->getOptLevel();
+ if (OptLevel != CodeGenOptLevel::None) {
+ if (!DT)
+ DT = &FAM.getResult<DominatorTreeAnalysis>(F);
+ TTI = &FAM.getResult<TargetIRAnalysis>(F);
+ }
+ bool Changed =
+ prepareDwarfEH(OptLevel, F, TLI, DT, TTI, TM->getTargetTriple());
+
+ if (!Changed)
+ return PreservedAnalyses::all();
+ PreservedAnalyses PA;
+ PA.preserve<DominatorTreeAnalysis>();
+ return PA;
+}
+
char DwarfEHPrepareLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(DwarfEHPrepareLegacyPass, DEBUG_TYPE,
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index dd9d799f9d55dcc..e06370c5463fa09 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -72,6 +72,7 @@
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
#include "llvm/Analysis/UniformityAnalysis.h"
+#include "llvm/CodeGen/DwarfEHPrepare.h"
#include "llvm/CodeGen/ExpandLargeDivRem.h"
#include "llvm/CodeGen/ExpandLargeFpConvert.h"
#include "llvm/CodeGen/HardwareLoops.h"
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 199a8e4622e35a3..3a9a37a231f8d2f 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -447,6 +447,7 @@ FUNCTION_PASS("memprof", MemProfilerPass())
FUNCTION_PASS("declare-to-assign", llvm::AssignmentTrackingPass())
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass(TM));
FUNCTION_PASS("expand-large-fp-convert", ExpandLargeFpConvertPass(TM));
+FUNCTION_PASS("dwarfehprepare", DwarfEHPreparePass(TM));
#undef FUNCTION_PASS
#ifndef FUNCTION_PASS_WITH_PARAMS
diff --git a/llvm/test/CodeGen/X86/dwarf-eh-prepare-dbg.ll b/llvm/test/CodeGen/X86/dwarf-eh-prepare-dbg.ll
index 094f6bf415b64b2..651e196a4ed76ec 100644
--- a/llvm/test/CodeGen/X86/dwarf-eh-prepare-dbg.ll
+++ b/llvm/test/CodeGen/X86/dwarf-eh-prepare-dbg.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -mtriple=x86_64-linux-gnu -dwarfehprepare < %s | FileCheck %s
+; RUN: opt -S -mtriple=x86_64-linux-gnu -passes=dwarfehprepare < %s | FileCheck %s
; PR57469: If _Unwind_Resume is defined in the same module and we have debug
; info, then the inserted _Unwind_Resume calls also need to have a dummy debug
diff --git a/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll b/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
index 67e9f16343ae4b6..6778601cfbf6d0d 100644
--- a/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
+++ b/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
@@ -1,4 +1,5 @@
; RUN: opt -mtriple=x86_64-linux-gnu -dwarfehprepare -simplifycfg-require-and-preserve-domtree=1 -run-twice < %s -S | FileCheck %s
+; RUN: opt -mtriple=x86_64-linux-gnu -passes=dwarfehprepare -codegen-opt-level=2 -simplifycfg-require-and-preserve-domtree=1 -run-twice < %s -S | FileCheck %s
; Check basic functionality of IR-to-IR DWARF EH preparation. This should
; eliminate resumes. This pass requires a TargetMachine, so we put it under X86
diff --git a/llvm/test/CodeGen/X86/dwarf_eh_resume.ll b/llvm/test/CodeGen/X86/dwarf_eh_resume.ll
index 20ef3fbf5965085..90fad00b68bd81c 100644
--- a/llvm/test/CodeGen/X86/dwarf_eh_resume.ll
+++ b/llvm/test/CodeGen/X86/dwarf_eh_resume.ll
@@ -1,4 +1,5 @@
; RUN: opt -mtriple=x86_64-linux-gnu -dwarfehprepare -S %s | FileCheck %s
+; RUN: opt -mtriple=x86_64-linux-gnu -passes=dwarfehprepare -S %s | FileCheck %s
declare i32 @hoge(...)
More information about the llvm-commits
mailing list