-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[X86] [NewPM] Add New Pass Manager wiring for x86-avoid-trailing-call #166723
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
[X86] [NewPM] Add New Pass Manager wiring for x86-avoid-trailing-call #166723
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
|
@llvm/pr-subscribers-backend-x86 Author: Anshul Nigham (nigham) ChangesFull diff: https://github.com/llvm/llvm-project/pull/166723.diff 4 Files Affected:
diff --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index fa23656e23fc3..433941ae3938e 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -14,6 +14,7 @@
#ifndef LLVM_LIB_TARGET_X86_X86_H
#define LLVM_LIB_TARGET_X86_X86_H
+#include "llvm/CodeGen/MachineFunctionAnalysisManager.h"
#include "llvm/IR/Analysis.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/CodeGen.h"
@@ -104,7 +105,17 @@ FunctionPass *createX86LowerTileCopyPass();
/// CALL instruction. The pass does the same for each funclet as well. This
/// ensures that the open interval of function start and end PCs contains all
/// return addresses for the benefit of the Windows x64 unwinder.
-FunctionPass *createX86AvoidTrailingCallPass();
+class X86AvoidTrailingCallPass : public PassInfoMixin<X86AvoidTrailingCallPass> {
+ private:
+ const TargetMachine *TM;
+
+ public:
+ X86AvoidTrailingCallPass(const TargetMachine *TM) : TM(TM) {}
+ PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
+ static bool isRequired() { return true; }
+};
+
+FunctionPass *createX86AvoidTrailingCallLegacyPass();
/// Return a pass that optimizes the code-size of x86 call sequences. This is
/// done by replacing esp-relative movs with pushes.
@@ -222,7 +233,7 @@ void initializeX86FixupInstTuningPassPass(PassRegistry &);
void initializeX86FixupVectorConstantsPassPass(PassRegistry &);
void initializeWinEHStatePassPass(PassRegistry &);
void initializeX86AvoidSFBPassPass(PassRegistry &);
-void initializeX86AvoidTrailingCallPassPass(PassRegistry &);
+void initializeX86AvoidTrailingCallLegacyPassPass(PassRegistry &);
void initializeX86CallFrameOptimizationPass(PassRegistry &);
void initializeX86CmovConverterPassPass(PassRegistry &);
void initializeX86DAGToDAGISelLegacyPass(PassRegistry &);
diff --git a/llvm/lib/Target/X86/X86AvoidTrailingCall.cpp b/llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
index 2ecf49382d29f..56d05d4eee738 100644
--- a/llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
+++ b/llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
@@ -37,6 +37,8 @@
#include "X86Subtarget.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/IR/Analysis.h"
+#include "llvm/IR/PassManager.h"
#define AVOIDCALL_DESC "X86 avoid trailing call pass"
#define AVOIDCALL_NAME "x86-avoid-trailing-call"
@@ -46,9 +48,9 @@
using namespace llvm;
namespace {
-class X86AvoidTrailingCallPass : public MachineFunctionPass {
+class X86AvoidTrailingCallLegacyPass : public MachineFunctionPass {
public:
- X86AvoidTrailingCallPass() : MachineFunctionPass(ID) {}
+ X86AvoidTrailingCallLegacyPass() : MachineFunctionPass(ID) {}
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -59,13 +61,13 @@ class X86AvoidTrailingCallPass : public MachineFunctionPass {
};
} // end anonymous namespace
-char X86AvoidTrailingCallPass::ID = 0;
+char X86AvoidTrailingCallLegacyPass::ID = 0;
-FunctionPass *llvm::createX86AvoidTrailingCallPass() {
- return new X86AvoidTrailingCallPass();
+FunctionPass *llvm::createX86AvoidTrailingCallLegacyPass() {
+ return new X86AvoidTrailingCallLegacyPass();
}
-INITIALIZE_PASS(X86AvoidTrailingCallPass, AVOIDCALL_NAME, AVOIDCALL_DESC, false, false)
+INITIALIZE_PASS(X86AvoidTrailingCallLegacyPass, AVOIDCALL_NAME, AVOIDCALL_DESC, false, false)
// A real instruction is a non-meta, non-pseudo instruction. Some pseudos
// expand to nothing, and some expand to code. This logic conservatively assumes
@@ -79,7 +81,7 @@ static bool isCallInstruction(const MachineInstr &MI) {
return MI.isCall() && !MI.isReturn();
}
-bool X86AvoidTrailingCallPass::runOnMachineFunction(MachineFunction &MF) {
+bool UpdatedOnX86AvoidTrailingCallPass(MachineFunction &MF) {
const X86Subtarget &STI = MF.getSubtarget<X86Subtarget>();
const X86InstrInfo &TII = *STI.getInstrInfo();
assert(STI.isTargetWin64() && "pass only runs on Win64");
@@ -134,3 +136,19 @@ bool X86AvoidTrailingCallPass::runOnMachineFunction(MachineFunction &MF) {
return Changed;
}
+
+bool X86AvoidTrailingCallLegacyPass::runOnMachineFunction(MachineFunction &MF) {
+ return UpdatedOnX86AvoidTrailingCallPass(MF);
+}
+
+PreservedAnalyses X86AvoidTrailingCallPass::run(
+ MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
+ bool Changed = UpdatedOnX86AvoidTrailingCallPass(MF);
+ if (!Changed)
+ return PreservedAnalyses::all();
+
+ PreservedAnalyses PA = PreservedAnalyses::none();
+ PA.preserveSet<CFGAnalyses>();
+ return PA;
+}
+
diff --git a/llvm/lib/Target/X86/X86PassRegistry.def b/llvm/lib/Target/X86/X86PassRegistry.def
index db255940f8829..65b5d9bab0a37 100644
--- a/llvm/lib/Target/X86/X86PassRegistry.def
+++ b/llvm/lib/Target/X86/X86PassRegistry.def
@@ -30,13 +30,13 @@ DUMMY_FUNCTION_PASS("x86-winehstate", WinEHStatePass())
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
#endif
MACHINE_FUNCTION_PASS("x86-isel", X86ISelDAGToDAGPass(*this))
+MACHINE_FUNCTION_PASS("x86-avoid-trailing-call", X86AvoidTrailingCallPass(this))
#undef MACHINE_FUNCTION_PASS
#ifndef DUMMY_MACHINE_FUNCTION_PASS
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME)
#endif
DUMMY_MACHINE_FUNCTION_PASS("x86-avoid-SFB", X86AvoidSFBPass())
-DUMMY_MACHINE_FUNCTION_PASS("x86-avoid-trailing-call", X86AvoidTrailingCallPass())
DUMMY_MACHINE_FUNCTION_PASS("x86-cf-opt", X86CallFrameOptimization())
DUMMY_MACHINE_FUNCTION_PASS("x86-cmov-conversion", X86CmovConverterPass())
DUMMY_MACHINE_FUNCTION_PASS("x86-codege", FPS())
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 5f0bcab251e61..0c2bd7c302f33 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -90,7 +90,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
initializeX86ExecutionDomainFixPass(PR);
initializeX86DomainReassignmentPass(PR);
initializeX86AvoidSFBPassPass(PR);
- initializeX86AvoidTrailingCallPassPass(PR);
+ initializeX86AvoidTrailingCallLegacyPassPass(PR);
initializeX86SpeculativeLoadHardeningPassPass(PR);
initializeX86SpeculativeExecutionSideEffectSuppressionPass(PR);
initializeX86FlagsCopyLoweringPassPass(PR);
@@ -589,7 +589,7 @@ void X86PassConfig::addPreEmitPass2() {
// Insert extra int3 instructions after trailing call instructions to avoid
// issues in the unwinder.
if (TT.isOSWindows() && TT.isX86_64())
- addPass(createX86AvoidTrailingCallPass());
+ addPass(createX86AvoidTrailingCallLegacyPass());
// Verify basic block incoming and outgoing cfa offset and register values and
// correct CFA calculation rule where needed by inserting appropriate CFI
|
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.
Sorry, a couple nits I didn't spot initially:
- Code formatting. Running
git clang-format HEAD~1locally should fix all those. - LLVM commits are conventionally tagged in the title with square brackets. Prefixing the current title with
[X86][NewPM]I think should be sufficient.
Thanks for the quick review! Done. |
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.
LGTM.
We discussed this offline and there are no good test candidates for this pass. The only one is llvm/test/CodeGen/X86/win64-eh-empty-block-2.mir, but it runs all the way through CodeGen, so more porting work needs to be done before then.
llvm/lib/Target/X86/X86.h
Outdated
| class X86AvoidTrailingCallPass | ||
| : public PassInfoMixin<X86AvoidTrailingCallPass> { | ||
| private: | ||
| const TargetMachine *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.
| const TargetMachine *TM; | |
| const X86TargetMachine *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.
Thanks! Done.
llvm/lib/Target/X86/X86.h
Outdated
| const TargetMachine *TM; | ||
|
|
||
| public: | ||
| X86AvoidTrailingCallPass(const TargetMachine *TM) : TM(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.
| X86AvoidTrailingCallPass(const TargetMachine *TM) : TM(TM) {} | |
| X86AvoidTrailingCallPass(const X86TargetMachine *TM) : TM(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.
Thanks! Done.
| #define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) | ||
| #endif | ||
| MACHINE_FUNCTION_PASS("x86-isel", X86ISelDAGToDAGPass(*this)) | ||
| MACHINE_FUNCTION_PASS("x86-avoid-trailing-call", X86AvoidTrailingCallPass(this)) |
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.
Keep alphabetical order.
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.
Thanks! Done.
…abetical ordering of machine pass registry.
llvm/lib/Target/X86/X86.h
Outdated
| class X86AvoidTrailingCallPass | ||
| : public PassInfoMixin<X86AvoidTrailingCallPass> { | ||
| private: | ||
| const X86TargetMachine *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.
Premerge CI is failing because TM is unused. We should be able to remove it from here, the constructor, and drop the this argument to the constructor call for this pass in X86PassRegistry.def.
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.
Done, thanks!
|
@nigham Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
No description provided.