Skip to content

[CodeGen] Port DwarfEHPrepare to new pass manager #72500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions llvm/include/llvm/CodeGen/DwarfEHPrepare.h
Original file line number Diff line number Diff line change
@@ -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> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DwarfEHPass or DwarfEHPreparePass ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DwarfEHPreparePass, we have some inconsistently named pass/file combinations and it's kind of annoying

const TargetMachine *TM;

public:
explicit DwarfEHPreparePass(const TargetMachine *TM_) : TM(TM_) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

} // namespace llvm

#endif // LLVM_CODEGEN_DWARFEHPREPARE_H
22 changes: 22 additions & 0 deletions llvm/lib/CodeGen/DwarfEHPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/CodeGen/DwarfEHPrepare.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
Expand Down Expand Up @@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take the triple from the module instead of the TM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getTargetTriple method in Module returns std::string rather than Triple.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about that wart, it should really store the parsed form


if (!Changed)
return PreservedAnalyses::all();
PreservedAnalyses PA;
PA.preserve<DominatorTreeAnalysis>();
return PA;
}

char DwarfEHPrepareLegacyPass::ID = 0;

INITIALIZE_PASS_BEGIN(DwarfEHPrepareLegacyPass, DEBUG_TYPE,
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/X86/dwarf-eh-prepare-dbg.ll
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/X86/dwarf_eh_resume.ll
Original file line number Diff line number Diff line change
@@ -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(...)

Expand Down