This is an archive of the discontinued LLVM Phabricator instance.

[NewPM][CodeGen] Introduce CodeGenPassBuilder to help build codegen pipeline
ClosedPublic

Authored by ychen on Jul 10 2020, 7:18 PM.

Details

Summary

Following up on D67687.
Please refer to the RFC here http://lists.llvm.org/pipermail/llvm-dev/2020-July/143309.html

CodeGenPassBuilder is the NPM counterpart of TargetPassConfig with below differences.

  • Debugging features (MIR print/verify, disable pass, start/stop-before/after, etc.) living in TargetPassConfig are moved to use PassInstrument as much as possible. (Implementation also lives in TargetPassConfig.cpp)
  • TargetPassConfig is a polymorphic base (virtual inheritance) to build the target-dependent pipeline whereas CodeGenPassBuilder is the CRTP base/helper to implement the target-dependent pipeline. The motivation is flexibility for targets to customize the pipeline, inlining opportunity, and fits the overall NPM value semantics design.
  • TargetPassConfig is a legacy immutable pass to declare hooks for targets to customize some target-independent codegen layer behavior. This is partially ported to TargetMachine::options. The rest, such as createMachineScheduler/createPostMachineScheduler, are left out for now. They should be implemented in LLVMTargetMachine in the future.

Diff Detail

Event Timeline

ychen created this revision.Jul 10 2020, 7:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2020, 7:18 PM
ychen updated this revision to Diff 282746.Aug 3 2020, 3:36 PM
  • update
ychen updated this revision to Diff 284930.Aug 11 2020, 4:20 PM
  • rebase. ready for review
ychen edited the summary of this revision. (Show Details)Aug 11 2020, 5:45 PM
ychen edited the summary of this revision. (Show Details)
ychen added a comment.Aug 11 2020, 5:52 PM

Hi, @arsenm @craig.topper, I'm not sure what additional reviewers I should add. Any suggestions?

arsenm added inline comments.Aug 11 2020, 5:56 PM
llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
1029–1041

Use switch?

ychen added inline comments.Aug 11 2020, 6:00 PM
llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
220

clang-tidy: error: no matching constructor for initialization of 'llvm::MachineFunctionPassManager' [clang-diagnostic-error]

Rebase issue. I'll update it later.

502

Rebase issue. I'll update it later.

ychen added inline comments.Aug 11 2020, 6:17 PM
llvm/lib/CodeGen/LLVMTargetMachine.cpp
124

Changes in this file are related to MCContext lifetime. MCContext is owned by MMI which is allocated & owned by the MachineFunctionAnalysisManager. Doing this allows us to delay the creation of MCStreamer when AsmPrinter is added to the pipeline.

arsenm added inline comments.Aug 12 2020, 5:36 AM
llvm/include/llvm/CodeGen/CGPassBuilderOption.h
41–43 ↗(On Diff #284930)

I think these need longer names and documentation comments

ychen updated this revision to Diff 285530.Aug 13 2020, 5:19 PM
ychen edited the summary of this revision. (Show Details)
  • address feedback
llvm/include/llvm/CodeGen/CGPassBuilderOption.h
41–43 ↗(On Diff #284930)

Sounds great. Comments added. I could do a followup patch for longer names. My intention was to make this close to a pure porting patch. WYDT? I don't mind put the renaming here though because they should be straightforward.

gentle ping?

arsenm added inline comments.Aug 18 2020, 11:52 AM
llvm/include/llvm/CodeGen/CGPassBuilderOption.h
41–43 ↗(On Diff #284930)

It's not like it's sharing the actual code, so might as well improve over the old system

ychen added inline comments.Aug 18 2020, 3:35 PM
llvm/include/llvm/CodeGen/CGPassBuilderOption.h
41–43 ↗(On Diff #284930)

Thanks. Will do.

For pass disabling variables, how about prefixing the pass NPM name with Disable ?

arsenm added inline comments.Aug 18 2020, 3:45 PM
llvm/include/llvm/CodeGen/CGPassBuilderOption.h
41–43 ↗(On Diff #284930)

That would certainly be more consistent

ychen updated this revision to Diff 286427.Aug 18 2020, 4:39 PM
  • address feedback
ychen marked an inline comment as done.Aug 18 2020, 4:40 PM
ychen added a comment.Aug 24 2020, 9:26 AM

Gentle ping?

arsenm added inline comments.Aug 27 2020, 6:43 AM
llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
206

Typo 'sures'

212

I don't understand why this is optional

226

Braces

ychen updated this revision to Diff 288675.Aug 28 2020, 12:35 PM
  • address feedback
ychen marked 2 inline comments as done.Aug 28 2020, 12:36 PM
ychen added inline comments.
llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
212

I was thinking of making this check optional. Seems not needed for now.

ychen updated this revision to Diff 289989.Sep 4 2020, 10:16 AM
  • Missed a move for returned AsmStreamer.

Hello, any more concern I could address to move this forward? Thanks.

arsenm accepted this revision.Sep 11 2020, 1:33 PM

LGTM with nits

llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
132

Add braces

828

Add braces

840

Commented out code

936

Add braces

This revision is now accepted and ready to land.Sep 11 2020, 1:33 PM
ychen updated this revision to Diff 291352.Sep 11 2020, 3:53 PM
  • address feedback
This revision was landed with ongoing or failed builds.Sep 11 2020, 4:41 PM
This revision was automatically updated to reflect the committed changes.
ychen added a comment.Sep 11 2020, 4:43 PM

@arsenm Thanks for the review!

aeubanks added inline comments.
llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
14–15

I believe this is explicitly not supported in the new PM

llvm/include/llvm/CodeGen/MachinePassRegistry.def
39–48

Is the intention that codegen IR passes will exist in both PassRegistry.def and MachinePassRegistry.def? Since people still generally use opt to test those passes.

llvm/include/llvm/Passes/StandardInstrumentations.h
145–146 ↗(On Diff #291357)

The declaration doesn't seem like it belongs here, it should probably go in TargetPassConfig.h since it's not part of StandardInstrumentation.

aeubanks added inline comments.Dec 21 2020, 10:47 AM
llvm/include/llvm/CodeGen/MachinePassRegistry.def
39–48

Oh I finally noticed the AddIRPasses. Maybe using a PassBuilder with backends doing something similar to registerPassBuilderCallbacks would require less duplicated code to parse user pipelines? Not sure if we'd really need the assert that module passes must come before function passes.

llvm/lib/CodeGen/CodeGenPassBuilder.cpp
24

I assume this is to support one pass depending on another? As mentioned before, I believe the new PM explicitly doesn't support that (I can dig up a video where Chandler said that was a terrible idea if you want)

ychen marked an inline comment as done.Dec 21 2020, 1:10 PM
ychen added inline comments.
llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
14–15

I'll remove this TODO. It was an anchor to remind myself about an existing feature. Under NPM, one target could manually add the required pass into the pipeline.

llvm/include/llvm/CodeGen/MachinePassRegistry.def
39–48

Is the intention that codegen IR passes will exist in both PassRegistry.def and MachinePassRegistry.def? Since people still generally use opt to test those passes.

Yes, that was the intention.

Oh I finally noticed the AddIRPasses. Maybe using a PassBuilder with backends doing something similar to registerPassBuilderCallbacks would require less duplicated code to parse user pipelines?

AddIRPasses is for targets to add their own pre-codegen IR pipeline which uses a different/new IR pass manager than the optimizer IR pipeline. The user pipelines parsing part for testing would be in the following patches.

Not sure if we'd really need the assert that module passes must come before function passes.

It is not required but a nice thing to have with a little bit of complicity only in the class AddIRPass. It makes function passes have better localities.

llvm/lib/CodeGen/CodeGenPassBuilder.cpp
24

This is a straightforward way to implement TargetPassConfig::insertPass. The alternative is to use PassRegsitery.def pass string name to uniquely identify a pass however I'd prefer the pass string name only for debugging tools. Or we could look into moving targets away from using TargetPassConfig::insertPass if it is possible. With that said, we could keep this design, move over the related tests, and then reconsider other choices later since this is only involving changes to class AddMachinePass.

ychen reopened this revision.Dec 21 2020, 1:10 PM
This revision is now accepted and ready to land.Dec 21 2020, 1:10 PM
ychen planned changes to this revision.Dec 21 2020, 1:10 PM
ychen updated this revision to Diff 313186.Dec 21 2020, 1:10 PM
This revision is now accepted and ready to land.Dec 21 2020, 1:10 PM
ychen requested review of this revision.Dec 21 2020, 1:11 PM
aeubanks accepted this revision.Dec 28 2020, 10:14 AM

Sorry, I thought you were going to remove the TODO, otherwise LGTM.

llvm/lib/CodeGen/CodeGenPassBuilder.cpp
24

insertPass looks very legacy PM-like, we should try to come up with a better solution, but we can do that later.

This revision is now accepted and ready to land.Dec 28 2020, 10:14 AM
ychen updated this revision to Diff 313914.Dec 28 2020, 4:57 PM
  • Remove obsolete TODO
This revision was landed with ongoing or failed builds.Dec 28 2020, 5:40 PM
This revision was automatically updated to reflect the committed changes.