Skip to content
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] Let PassBuilder support machine passes #76320

Merged
merged 2 commits into from
Jan 13, 2024

Conversation

paperchalice
Copy link
Contributor

PassBuilder would be a better place to parse MIR pipeline. We can reuse the code to support parsing pass with parameters and targets can reuse registerPassBuilderCallbacks to register the target specific passes. PassBuilder also has ability to check whether a Pass is a machine pass, so it can replace part of the work of LLVMTargetMachine::getPassNameFromLegacyName.

@paperchalice
Copy link
Contributor Author

paperchalice commented Dec 24, 2023

In fact, PassBuilder would also be a better place to handle --start-after etc. Should we distinguish between the optimization passes and codegen passes?

@paperchalice paperchalice force-pushed the NPM/CodeGen/pass-builder branch 3 times, most recently from 461fd04 to 5fdf4e8 Compare December 25, 2023 04:10
Copy link

github-actions bot commented Dec 25, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

}
};

Result run(MachineFunction &IR, MachineFunctionAnalysisManager::Base &AM) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why MachineFunctionAnalysisManager is designed this way. An InnerAnalysisManagerProxy<IRUnit, MachineFunction> seems also OK.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm yeah MachineFunctionAnalysisManager does not fit in with the other analysis managers

it should be an alias for AnalysisManager<MachineFunction>, and then we should have a proxy for module and function analyses (correct me if I'm misunderstanding your question)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After looking at the code, I seem to understand the reason for this, MachineFunctionPassManager need get result from MachineModuleAnalysis which is a module analysis.

Copy link
Contributor

Choose a reason for hiding this comment

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

is there any specific reason it can't follow the rest of the new pass manager design and use proxies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MachineFunctionPassManager can run on module directly (see the runin MachinePassManager), which seems a contrary to the pass manager's design.

@paperchalice
Copy link
Contributor Author

Ping @aeubanks @arsenm.

@paperchalice paperchalice force-pushed the NPM/CodeGen/pass-builder branch 2 times, most recently from 22e44a8 to c8c0931 Compare January 8, 2024 06:19
@aeubanks
Copy link
Contributor

aeubanks commented Jan 8, 2024

at a high level, I think it makes sense to consolidate handling machine passes into PassBuilder

however, it's unfortunate that this cements the Passes -> CodeGen dependency. it would be great if people could use PassBuilder to only run IR passes without pulling in all of CodeGen. but if MachineFunction is part of CodeGen, we can't really avoid that dependency

@paperchalice
Copy link
Contributor Author

at a high level, I think it makes sense to consolidate handling machine passes into PassBuilder

however, it's unfortunate that this cements the Passes -> CodeGen dependency. it would be great if people could use PassBuilder to only run IR passes without pulling in all of CodeGen. but if MachineFunction is part of CodeGen, we can't really avoid that dependency

Unfortunately, some IR pass and IR pass option tests need to verify the result in machine code form, an example is global-merge in AArch64 backend.

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

lg with nits

@@ -73,6 +73,7 @@
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
#include "llvm/Analysis/UniformityAnalysis.h"
#include "llvm/CodeGen/CallBrPrepare.h"
#include "llvm/CodeGen/CodeGenPassBuilder.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this include necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All dummy passes (DUMMY_*_PASS in MachinePassRegistry.def) are declared in this header.

Copy link
Contributor

@aeubanks aeubanks Jan 11, 2024

Choose a reason for hiding this comment

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

oh man I don't think having those DUMMY_*_PASS was a great idea. we should just add passes to the pipeline as we port them. we really shouldn't have to include CodeGenPassBuilder.h from PassBuilder

can you just not #define DUMMY_*_PASS below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will remove them later.

@@ -463,8 +463,7 @@ class LLVMTargetMachine : public TargetMachine {
}

virtual std::pair<StringRef, bool> getPassNameFromLegacyName(StringRef) {
llvm_unreachable(
"getPassNameFromLegacyName parseMIRPipeline is not overridden");
llvm_unreachable("getPassNameFromLegacyName is not overridden");
Copy link
Contributor

Choose a reason for hiding this comment

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

please submit this change separately (no review required)

@@ -0,0 +1,499 @@
//===- unittests/MIR/PassBuilderCallbacksTest.cpp - PB Callback Tests --===//
Copy link
Contributor

Choose a reason for hiding this comment

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

ultra nit: line this up

@paperchalice paperchalice force-pushed the NPM/CodeGen/pass-builder branch 2 times, most recently from c465a51 to 02c92b6 Compare January 11, 2024 06:38
@paperchalice
Copy link
Contributor Author

Address the comments above.

`PassBuilder` would be a better place to parse MIR pipeline. We can reuse the code to support parsing pass with parameters and targets can reuse `registerPassBuilderCallbacks` to register the target specific passes. `PassBuilder` also has ability to check whether a Pass is a machine pass, so it can replace part of the work of `LLVMTargetMachine::getPassNameFromLegacyName`.
@paperchalice
Copy link
Contributor Author

Remove CodeGenPassBuilder.h and DUMMY_*_PASS, then no machine passes are included now, because currently no machine pass uses MACHINE_*_PASS.

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

lg as is, the analysis manager stuff can be fixed later on as the current design is already in tree

@paperchalice
Copy link
Contributor Author

Wrap TM with std::unique_ptr to avoid sanitizer error.

@paperchalice paperchalice merged commit 8566cd6 into llvm:main Jan 13, 2024
4 checks passed
@paperchalice paperchalice deleted the NPM/CodeGen/pass-builder branch January 13, 2024 11:40
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
`PassBuilder` would be a better place to parse MIR pipeline. We can
reuse the code to support parsing pass with parameters and targets can
reuse `registerPassBuilderCallbacks` to register the target specific
passes. `PassBuilder` also has ability to check whether a Pass is a
machine pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants