[llvm] [CodeGen] Port DwarfEHPrepare to new pass manager (PR #72500)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 02:24:29 PST 2023
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/72500
>From 4d4de4d276bf17868e78c2aec26ca883ba3aaeab Mon Sep 17 00:00:00 2001
From: PaperChalice <example at example.com>
Date: Thu, 16 Nov 2023 18:19:56 +0800
Subject: [PATCH] [CodeGen] Port DwarfEHPrepare to new pass manager
---
llvm/include/llvm/CodeGen/DwarfEHPrepare.h | 37 +++++++++++++++++++
llvm/lib/CodeGen/DwarfEHPrepare.cpp | 17 +++++++++
llvm/lib/Passes/PassBuilder.cpp | 1 +
llvm/lib/Passes/PassRegistry.def | 1 +
llvm/test/CodeGen/X86/dwarf-eh-prepare-dbg.ll | 1 +
llvm/test/CodeGen/X86/dwarf-eh-prepare.ll | 1 +
llvm/test/CodeGen/X86/dwarf_eh_resume.ll | 1 +
7 files changed, 59 insertions(+)
create mode 100644 llvm/include/llvm/CodeGen/DwarfEHPrepare.h
diff --git a/llvm/include/llvm/CodeGen/DwarfEHPrepare.h b/llvm/include/llvm/CodeGen/DwarfEHPrepare.h
new file mode 100644
index 000000000000000..9716a1008ce569b
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/DwarfEHPrepare.h
@@ -0,0 +1,37 @@
+//===------------------- 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;
+ CodeGenOptLevel OptLevel;
+
+public:
+ explicit DwarfEHPreparePass(
+ const TargetMachine *TM_,
+ CodeGenOptLevel OptLevel_ = CodeGenOptLevel::Default)
+ : TM(TM_), OptLevel(OptLevel_) {}
+ 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..9fc389ab3821795 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,22 @@ class DwarfEHPrepareLegacyPass : public FunctionPass {
} // end anonymous namespace
+PreservedAnalyses DwarfEHPreparePass::run(Function &F,
+ FunctionAnalysisManager &FAM) {
+ const auto &TLI = *TM->getSubtargetImpl(F)->getTargetLowering();
+ auto *DT = &FAM.getResult<DominatorTreeAnalysis>(F);
+ const TargetTransformInfo *TTI = nullptr;
+ if (OptLevel != CodeGenOptLevel::None)
+ 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 2067fc473b522db..24a266c58375505 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -446,6 +446,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..70e62e95ee02b7e 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 -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