-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[CodeGen] Port DwarfEHPrepare to new pass manager #72500
Conversation
@llvm/pr-subscribers-debuginfo Author: None (paperchalice) ChangesFull diff: https://github.com/llvm/llvm-project/pull/72500.diff 7 Files Affected:
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..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(...)
|
@llvm/pr-subscribers-backend-x86 Author: None (paperchalice) ChangesFull diff: https://github.com/llvm/llvm-project/pull/72500.diff 7 Files Affected:
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..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(...)
|
d270b33
to
4d4de4d
Compare
|
||
class TargetMachine; | ||
|
||
class DwarfEHPreparePass : public PassInfoMixin<DwarfEHPreparePass> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DwarfEHPass
or DwarfEHPreparePass
?
There was a problem hiding this comment.
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
public: | ||
explicit DwarfEHPreparePass( | ||
const TargetMachine *TM_, | ||
CodeGenOptLevel OptLevel_ = CodeGenOptLevel::Default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, TargetMachine
already provide getOptLevel() method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If TM is required, just take it from there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another inconsistence, the CodeGenOptLevel
in opt
is controlled by
llvm-project/llvm/tools/opt/opt.cpp
Lines 178 to 180 in 5d59e97
static cl::opt<unsigned> CodeGenOptLevelCL( | |
"codegen-opt-level", | |
cl::desc("Override optimization level for codegen hooks, legacy PM only")); |
llvm-project/llvm/tools/opt/opt.cpp
Lines 641 to 643 in 5d59e97
Expected<std::unique_ptr<TargetMachine>> ExpectedTM = | |
codegen::createTargetMachineForTriple(ModuleTriple.str(), | |
GetCodeGenOptLevel()); |
So, the default value is
CodeGenOptLevel::None
in opt
.
4d4de4d
to
bed620d
Compare
|
||
class TargetMachine; | ||
|
||
class DwarfEHPreparePass : public PassInfoMixin<DwarfEHPreparePass> { |
There was a problem hiding this comment.
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
public: | ||
explicit DwarfEHPreparePass( | ||
const TargetMachine *TM_, | ||
CodeGenOptLevel OptLevel_ = CodeGenOptLevel::Default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If TM is required, just take it from there
TTI = &FAM.getResult<TargetIRAnalysis>(F); | ||
} | ||
bool Changed = | ||
prepareDwarfEH(OptLevel, F, TLI, DT, TTI, TM->getTargetTriple()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
bed620d
to
8007ea7
Compare
CI looks good, I'd appreciate if this pull request can be merged. |
oops? Co-authored-by: PaperChalice example@example.com |
Oh, I forgot to modify git configuration, this commit is made from another machine which is for my private usage. 😓 |
No description provided.