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] Allow CodeGenPassBuilder to add module pass after function pass #77084

Merged
merged 4 commits into from
Jan 12, 2024

Conversation

paperchalice
Copy link
Contributor

In fact, there are several backends, e.g. AArch64, AMDGPU etc. add module pass after function pass, this patch removes this constraint. This patch also adds a simple unit test for CodeGenPassBuilder.

Comment on lines 192 to 193
if constexpr (is_detected<is_module_pass_t, PassT>::value &&
!is_detected<is_function_pass_t, PassT>::value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are both conditions necessary? Can there really be a pass that is both a module and function pass?

Copy link
Contributor Author

@paperchalice paperchalice Jan 10, 2024

Choose a reason for hiding this comment

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

It seems ok to define two run methods with different ir unit in one pass, pass manager will pick the right one. Here is redundant, will remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

lgtm with nits

addPass(createFunctionToLoopPassAdaptor(
LoopStrengthReducePass(), /*UseMemorySSA*/ true, Opt.DebugPM));
addPass(createFunctionToLoopPassAdaptor(LoopStrengthReducePass(),
/*UseMemorySSA*/ true));
Copy link
Contributor

Choose a reason for hiding this comment

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

Something weird happened here with whitespace? Is GitHub showing tabs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least in my local editor, it is whitespace.

"test",
"-print-pipeline-passes",
};
int argc = sizeof(argv) / sizeof(char *);
Copy link
Contributor

Choose a reason for hiding this comment

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

this can use std::size

"FinalizeISelPass,EarlyTailDuplicatePass,OptimizePHIsPass,"
"StackColoringPass,LocalStackSlotPass,DeadMachineInstructionElimPass,"
"EarlyMachineLICMPass,MachineCSEPass,MachineSinkingPass,"
"PeepholeOptimizerPass,DeadMachineInstructionElimPass,"
Copy link
Contributor

Choose a reason for hiding this comment

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

At some point we should probably do something about codegen passes not using the same naming convention as IR passes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, currently only PassT::name() is available.

auto PassName = PIC.getPassNameForClassName(Name);
return PassName.empty() ? Name : PassName;
});
char ExpectedMIRPipeline[] =
Copy link
Contributor

Choose a reason for hiding this comment

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

const?

auto PassName = PIC.getPassNameForClassName(Name);
return PassName.empty() ? Name : PassName;
});
char ExpectedIRPipeline[] =
Copy link
Contributor

Choose a reason for hiding this comment

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

const?

@paperchalice
Copy link
Contributor Author

Address the comments above.

addPass(createFunctionToLoopPassAdaptor(
LoopStrengthReducePass(), /*UseMemorySSA*/ true, Opt.DebugPM));
addPass(createFunctionToLoopPassAdaptor(LoopStrengthReducePass(),
/*UseMemorySSA*/ true));
Copy link
Contributor

Choose a reason for hiding this comment

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

UseMemorySSA= so clang-format recognizes it

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.

makes sense, some comments

"Only module pass and function pass are supported.");

// Add Function Pass
if constexpr (is_detected<is_function_pass_t, PassT>::value)
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency, add braces here when else block uses braces

return PassName.empty() ? Name : PassName;
});
const char ExpectedMIRPipeline[] =
"FinalizeISelPass,EarlyTailDuplicatePass,OptimizePHIsPass,"
Copy link
Contributor

Choose a reason for hiding this comment

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

imo checking the exact pipeline should be a normal lit tests, having it as a unit test is annoying to update since it takes so long to compile unittests.

for now since we don't have the infra to do this from llc this is ok, but add a TODO to move this to a normal lit test once we can do that

Copy link
Contributor

Choose a reason for hiding this comment

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

to prevent having to update this as we keep making changes in this space, I'd just check that no-op-module,function(no-op-function,no-op-function,no-op-function),no-op-module is a substring

}

void SetUp() override {
std::string TripleName = Triple::normalize(sys::getDefaultTargetTriple());
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't the pipeline going to be inconsistent depending on the default target triple?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will depend on the specific target, but I noticed there is a BogusTargetMachine in unittests/CodeGen/MFCommon.inc, will use it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uh,CodeGenPassBuilder needs MCAsmInfo but BogusTargetMachine doesn't provide it, but now we can ignore it and use default target machine because currently the pipeline provider is not the target machine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be slightly safer to just pick a target machine and go with it, and disable the test if the target's not built

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be slightly safer to just pick a target machine and go with it, and disable the test if the target's not built

Pick the default target machine and skip test when default target is not built now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think arsenm meant choose a specific target like x86_64-linux-gnu and bail if that target isn't available (I think you did this in a different patch's test)


static const char *argv[] = {
"test",
"-print-pipeline-passes",
Copy link
Contributor

Choose a reason for hiding this comment

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

oh man this is a huge hack, but I guess this goes along with the TODO I suggested below

"lower-constant-intrinsics,UnreachableBlockElimPass,consthoist,"
"ReplaceWithVeclib,partially-inline-libcalls,ee-instrument<post-inline>,"
"scalarize-masked-mem-intrin,ExpandReductionsPass,codegenprepare,"
"dwarf-eh-prepare),no-op-module,function(no-op-function,no-op-function,"
Copy link
Contributor

Choose a reason for hiding this comment

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

no-op-function/module are getting recognized just because we happen to have the same name for the NoOpFunction/ModulePass in PassBuilder.cpp, that's not very evident or nice. let's just move those in PassBuilder.cpp to the header PassBuilder.h so unittests can use them

…n pass

In fact, there are several backends, e.g. AArch64, AMDGPU etc. add module pass after function pass, this patch removes this constraint.
This patch also adds a simple unit test for `CodeGenPassBuilder`
@paperchalice
Copy link
Contributor Author

Address comments above.

@paperchalice
Copy link
Contributor Author

Smoke test looks good, will land this if no further comments.

@pravinjagtap pravinjagtap self-requested a review January 11, 2024 12:52
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 after the one test comment is addressed

@paperchalice paperchalice merged commit ae1c1ed into llvm:main Jan 12, 2024
4 checks passed
@nico
Copy link
Contributor

nico commented Jan 12, 2024

Looks like this might be breaking tests on Mac: http://45.33.8.238/macm1/76477/step_11.txt

Please take a look. Does the failure make sense to you?

@paperchalice
Copy link
Contributor Author

paperchalice commented Jan 12, 2024

Looks like this might be breaking tests on Mac: http://45.33.8.238/macm1/76477/step_11.txt

Please take a look. Does the failure make sense to you?

I noticed that, fix pr is opened #77860.

@paperchalice
Copy link
Contributor Author

If build bots still report error, feel free to revert it.

@paperchalice paperchalice deleted the cgpassbuildertest branch January 20, 2024 10:48
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
…n pass (llvm#77084)

In fact, there are several backends, e.g. AArch64, AMDGPU etc. add
module pass after function pass, this patch removes this constraint.
This patch also adds a simple unit test for `CodeGenPassBuilder`.
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.

4 participants