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

Common CLI flags registry #990

Closed
wants to merge 6 commits into from

Conversation

adam-smnk
Copy link
Contributor

Moves CLI flags used to control pipelines behavior to a common registry.

This cleanup allows to remove the overhead of piping options through multiple layers of pass bundles. Now, the common CLI flags are globally accessible and can be pulled directly as a dependency by any pass bundle.

Note that individual passes should be self contained and define all necessary options.

@adam-smnk adam-smnk added the benchmark Benchmark base targets label Dec 4, 2024
@adam-smnk adam-smnk added benchmark Benchmark base targets and removed benchmark Benchmark base targets labels Dec 4, 2024
@adam-smnk
Copy link
Contributor Author

No benchmark regressions.

@adam-smnk
Copy link
Contributor Author

@KavithaTipturMadhu This should help with flags through pass bundles.
If still needed, we can also extend and add printing to different parts of the pipeline.

namespace opt {

// Print MLIR before lowering
extern llvm::cl::opt<std::string> printMLIR;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, that's odd. extern is supposed to be used in a C file when another C file declares your variable, not in a header.

It's also bad form to initialize everything statically before _main. This is why we have things like pass options, etc.

I don't think this is a step forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

extern is normally rather redundant as that's header's job to provide declarations. However, explicit extern can be useful to make intention more obvious in certain cases. This seems to be a common pattern for CLI options across LLVM headers.

CLI flags are global object anyway, this doesn't change their initialization or lifetime - only helps with scope. The main idea is to have a central place that has all the flags gathered together and easily accessible by pass bundles. This eliminates the need to create multiple duplicate pass options only to pipe a flag to a single pass nested deep within 5 other bundles.

I agree it shouldn't be misused for controlling individual passes like convert X to Y.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps to put this more simply, this header is a collection of available singletons.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm worried we'll leak anyway because not there's no indication where this flag will have an effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the other hand, currently it takes jumping across multiple files to track down the origin of option's value.
Plus, CLI flags generally define desired values. Now if they have defaults, these values have to be propagated through all pass option defaults. Otherwise running default-pipeline vs other standalone pass can be much different.

I think between the two, this has potentially fewer points of failure and requires less maintenance but ultimately I'm fine with either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's just an experimental alternative - I'm not fully sure it's better.

If you don't feel convinced, then let's leave things as they are.

Copy link
Contributor

Choose a reason for hiding this comment

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

the thing is, we should be working to remove the bundles (in favour of schedules) and this churn will not help Kavitha's PR that much anyway. mlir-runner has moved from statically initialized arguments to structure based use to avoid the init cost. I'm not convinced this is a good idea.

@adam-smnk
Copy link
Contributor Author

Not necessarily beneficial - closing.

@adam-smnk adam-smnk closed this Dec 5, 2024
@adam-smnk
Copy link
Contributor Author

Note for future reference: there is actually a nice utility llvm::ManagedStatic for managing globals.
The CLI flags could also be wrapped into structs to group them logically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark Benchmark base targets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants