This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Serialize `build_native_tool`
ClosedPublic

Authored by chapuni on Apr 24 2023, 8:57 AM.

Details

Summary

To prevent race in NATIVE, let each action depend on preceding action.

For example,

  • llvm-tblgen-host depends on the target's llvm-tblgen.
  • clang-tblgen-host depends on the target's clang-tblgen and llvm-tblgen-host.

This is rework for D54153.
build_native_tool has been introduced since D60024.

Diff Detail

Event Timeline

chapuni created this revision.Apr 24 2023, 8:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 8:57 AM
Herald added a subscriber: ekilmer. · View Herald Transcript
chapuni requested review of this revision.Apr 24 2023, 8:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 8:57 AM

I have checked with just only Ninja generator.

chapuni updated this revision to Diff 516812.Apr 25 2023, 8:13 AM
  • Add a comment line

I think this looks reasonable, and the logic seems mostly better than the one before. As far as I can see with the current code in git, there's nothing stopping from building e.g. lldb-tablegen-host and clang-tablegen-host at the same time, is that right?

This code works best if the tablegens are processed in a roughly topological order, e.g. in a build with clang and lldb, I guess it's better if clang is listed before lldb in LLVM_ENABLE_PROJECTS, because otherwise clang-tablegen-host would build lldb-tablegen-host before?

I think this looks reasonable, and the logic seems mostly better than the one before. As far as I can see with the current code in git, there's nothing stopping from building e.g. lldb-tablegen-host and clang-tablegen-host at the same time, is that right?

I haven't experienced lldb, though, I guess lldb-tablegen-host and clang-tablegen-host would be scheduled in parallel.

This code works best if the tablegens are processed in a roughly topological order, e.g. in a build with clang and lldb, I guess it's better if clang is listed before lldb in LLVM_ENABLE_PROJECTS, because otherwise clang-tablegen-host would build lldb-tablegen-host before?

I think such optimization would not gain the big win. Nested CMake invocation would be evil and far from optimal I suppose.
I just wanted to introduce consistency.

That said, I will not stop someone's proposing better scheduling.

This code works best if the tablegens are processed in a roughly topological order, e.g. in a build with clang and lldb, I guess it's better if clang is listed before lldb in LLVM_ENABLE_PROJECTS, because otherwise clang-tablegen-host would build lldb-tablegen-host before?

I think such optimization would not gain the big win.

I can try to check if this happens or not.

Nested CMake invocation would be evil and far from optimal I suppose.

I don't quite understand what you refer to here?

I just wanted to introduce consistency.

That said, I will not stop someone's proposing better scheduling.

I don't think it's necessarily worth spending effort on at this point, I just wanted to note the pros and cons. Doing things suboptimally (in a case where it's trivial for the user to fix it) is totally fine, compared to doing things in an unspecified possibly broken way.

beanz added a comment.Apr 26 2023, 5:36 PM

This feels like it could have unintended and unfortunate consequences. Does this not make mlir-tablegen depend on clang-tablegen? If it does that could increase iteration loops where native tools are involved by building unrelated things that don't strictly need to be built or have a dependency.

I'm curious where you're seeing race conditions with the native builds. Makefile and Ninja generators shouldn't race (makefile because of the job server model and Ninja because of the use of the console pool).

This feels like it could have unintended and unfortunate consequences.

I know this is far from optimal rather than suboptimal. I don't intend any optimizations.

Does this not make mlir-tablegen depend on clang-tablegen? If it does that could increase iteration loops where native tools are involved by building unrelated things that don't strictly need to be built or have a dependency.

I know this will introduce longer dependency chain. That said, subsequent NATIVE's actions would not rebuild preceding artifacts (unless the builder would be silly).

I'm curious where you're seeing race conditions with the native builds. Makefile and Ninja generators shouldn't race (makefile because of the job server model and Ninja because of the use of the console pool).

I have just followed D54153 and I haven't met any matters in my use cases. I haven't thought this logic could be optimized (in this).

At the moment I would like to land this unconditionally. I think we could exclude this conditionally later.

beanz added a comment.Apr 27 2023, 8:18 AM

This will regress build times for Makefile and Ninja builds, particularly clean builds (which is what GitHub Actions, Azure Pipelines, and Google Cloud Pipelines all do).

Please restrict the change to only impact Visual Studio which I think is the only generator that can be impacted by the race condition. Xcode may be sub-optimal with the current behavior but probably isn't impacted by the race because the filesystem locking behavior is likely NTFS-specific.

chapuni updated this revision to Diff 517729.Apr 27 2023, 3:13 PM
  • Restrict the change only for "Visual Studio"
beanz accepted this revision.Apr 27 2023, 3:19 PM

LGTM. Thank you!

This revision is now accepted and ready to land.Apr 27 2023, 3:19 PM
This revision was landed with ongoing or failed builds.Apr 29 2023, 12:54 AM
This revision was automatically updated to reflect the committed changes.