Skip to content

Commit 61e58c4

Browse files
paperchalicePaperChalice
and
PaperChalice
authored
[CodeGen] Port DwarfEHPrepare to new pass manager (#72500)
Co-authored-by: PaperChalice <[email protected]>
1 parent 82d22a1 commit 61e58c4

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===------------------- llvm/CodeGen/DwarfEHPrepare.h ----------*- C++-*--===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This pass mulches exception handling code into a form adapted to code
10+
// generation. Required if using dwarf exception handling.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CODEGEN_DWARFEHPREPARE_H
15+
#define LLVM_CODEGEN_DWARFEHPREPARE_H
16+
17+
#include "llvm/IR/PassManager.h"
18+
19+
namespace llvm {
20+
21+
class TargetMachine;
22+
23+
class DwarfEHPreparePass : public PassInfoMixin<DwarfEHPreparePass> {
24+
const TargetMachine *TM;
25+
26+
public:
27+
explicit DwarfEHPreparePass(const TargetMachine *TM_) : TM(TM_) {}
28+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
29+
};
30+
31+
} // namespace llvm
32+
33+
#endif // LLVM_CODEGEN_DWARFEHPREPARE_H

llvm/lib/CodeGen/DwarfEHPrepare.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "llvm/CodeGen/DwarfEHPrepare.h"
1415
#include "llvm/ADT/BitVector.h"
1516
#include "llvm/ADT/SmallVector.h"
1617
#include "llvm/ADT/Statistic.h"
@@ -365,6 +366,27 @@ class DwarfEHPrepareLegacyPass : public FunctionPass {
365366

366367
} // end anonymous namespace
367368

369+
PreservedAnalyses DwarfEHPreparePass::run(Function &F,
370+
FunctionAnalysisManager &FAM) {
371+
const auto &TLI = *TM->getSubtargetImpl(F)->getTargetLowering();
372+
auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(F);
373+
const TargetTransformInfo *TTI = nullptr;
374+
auto OptLevel = TM->getOptLevel();
375+
if (OptLevel != CodeGenOptLevel::None) {
376+
if (!DT)
377+
DT = &FAM.getResult<DominatorTreeAnalysis>(F);
378+
TTI = &FAM.getResult<TargetIRAnalysis>(F);
379+
}
380+
bool Changed =
381+
prepareDwarfEH(OptLevel, F, TLI, DT, TTI, TM->getTargetTriple());
382+
383+
if (!Changed)
384+
return PreservedAnalyses::all();
385+
PreservedAnalyses PA;
386+
PA.preserve<DominatorTreeAnalysis>();
387+
return PA;
388+
}
389+
368390
char DwarfEHPrepareLegacyPass::ID = 0;
369391

370392
INITIALIZE_PASS_BEGIN(DwarfEHPrepareLegacyPass, DEBUG_TYPE,

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "llvm/Analysis/TargetTransformInfo.h"
7373
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
7474
#include "llvm/Analysis/UniformityAnalysis.h"
75+
#include "llvm/CodeGen/DwarfEHPrepare.h"
7576
#include "llvm/CodeGen/ExpandLargeDivRem.h"
7677
#include "llvm/CodeGen/ExpandLargeFpConvert.h"
7778
#include "llvm/CodeGen/HardwareLoops.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ FUNCTION_PASS("memprof", MemProfilerPass())
447447
FUNCTION_PASS("declare-to-assign", llvm::AssignmentTrackingPass())
448448
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass(TM));
449449
FUNCTION_PASS("expand-large-fp-convert", ExpandLargeFpConvertPass(TM));
450+
FUNCTION_PASS("dwarfehprepare", DwarfEHPreparePass(TM));
450451
#undef FUNCTION_PASS
451452

452453
#ifndef FUNCTION_PASS_WITH_PARAMS

llvm/test/CodeGen/X86/dwarf-eh-prepare-dbg.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt -S -mtriple=x86_64-linux-gnu -dwarfehprepare < %s | FileCheck %s
3+
; RUN: opt -S -mtriple=x86_64-linux-gnu -passes=dwarfehprepare < %s | FileCheck %s
34

45
; PR57469: If _Unwind_Resume is defined in the same module and we have debug
56
; info, then the inserted _Unwind_Resume calls also need to have a dummy debug

llvm/test/CodeGen/X86/dwarf-eh-prepare.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt -mtriple=x86_64-linux-gnu -dwarfehprepare -simplifycfg-require-and-preserve-domtree=1 -run-twice < %s -S | FileCheck %s
2+
; 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
23

34
; Check basic functionality of IR-to-IR DWARF EH preparation. This should
45
; eliminate resumes. This pass requires a TargetMachine, so we put it under X86

llvm/test/CodeGen/X86/dwarf_eh_resume.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt -mtriple=x86_64-linux-gnu -dwarfehprepare -S %s | FileCheck %s
2+
; RUN: opt -mtriple=x86_64-linux-gnu -passes=dwarfehprepare -S %s | FileCheck %s
23

34
declare i32 @hoge(...)
45

0 commit comments

Comments
 (0)