Page MenuHomePhabricator

[NFC] Do not run CGProfilePass when -fno-integrated-as is on
Needs ReviewPublic

Authored by zhizhouy on May 29 2019, 1:53 PM.

Details

Summary

CGProfilePass is run by default in certain new pass manager optimization pipeline. Assemblers other than llvm as (such as gnu as) cannot recognize the .cgprofile entries generated and emitted from this pass, causing build time error.

This patch adds a new opt option "enable-npm-call-graph-profile" (on by default) and we turn it off when "-fno-integrated-as" is specified in clang.

Since CGProfilePass only exists in new pass manager, it's a bit awkward that we will pass a nop -mllvm option if legacy pass manager is used.
-DENABLE_EXPERIMENTAL_NEW_PASS_MANAGER when building LLVM will be a good solution to make this consistent.
Further opinions are welcome.

Diff Detail

Repository
rL LLVM

Event Timeline

zhizhouy created this revision.May 29 2019, 1:53 PM

I find it a bit odd to have clang care about this, but I suppose it is the driver that knows which features tools support. I also have an issue with the name as CGProfilePass doesn't actually do the sorting. I would just keep the option as -enable-call-graph-profile-emission or something like that.

IIUC, user will always call clang to pass integrated as flag. Actually I also used to consider checking UseIntegratedAS-ish in PassBuilder,
but looking for a codegen options in PassBuilder seems going to break the integrity. Solutions for this is appreciated.

I also have an issue with the name as CGProfilePass doesn't actually do the sorting

Sorry I mis-used the "sort" here, changing it to "enable-npm-call-graph-profile" to match the other newpm options in PassBuilder.

zhizhouy updated this revision to Diff 202057.May 29 2019, 2:34 PM

Renaming the opt.

zhizhouy edited the summary of this revision. (Show Details)May 29 2019, 2:39 PM
manojgupta added inline comments.May 29 2019, 2:41 PM
clang/lib/Driver/ToolChains/Clang.cpp
4000

llvm MC assembler? llvm-as is for converting text ll to bitcode files.

zhizhouy updated this revision to Diff 202065.May 29 2019, 2:46 PM
zhizhouy marked 2 inline comments as done.
zhizhouy edited the summary of this revision. (Show Details)

Fixed comment.

clang/lib/Driver/ToolChains/Clang.cpp
4000

Thanks for correction.

IIUC, user will always call clang to pass integrated as flag. Actually I also used to consider checking UseIntegratedAS-ish in PassBuilder,
but looking for a codegen options in PassBuilder seems going to break the integrity. Solutions for this is appreciated.

There are frontends and users of llvm other than clang.

Also all of the other options there are useful for experimenting with new passes, none of them are required for correctness, and none of them are ever set by clang.

Adding Chandler to see if he has a good solution.

Friendly ping :)

chandlerc added inline comments.Jul 11 2019, 5:40 PM
clang/lib/Driver/ToolChains/Clang.cpp
3999–4003

the call garph profile stuff needs to be a Clang CodeGenOpt IMO. Then it can be used to set a bool in the pass builder's option struct (see my other comment).

We can then set the CodeGenOpt based on whether we are using the integrated assembler.

We could also have a separate flag for setting the codegen opt for getting this profile information, and make the driver diagnose an incompatible combination of no-integrated-as and that flag. But we'll still end up threading that flag through to Clang's codegen layer, and then into the pass manager.

llvm/lib/Passes/PassBuilder.cpp
946

We shouldn't just use the cl::opt here. We need a flag in the pass builder's options struct. We can default it from the cl::opt.

You should add a test that uses the cl::opt to flip the default back and forth and get the different behavior in LLVM directly against the opt tool. Then the LLVM part of this can land.