This is an archive of the discontinued LLVM Phabricator instance.

[TLI] Support for per-Function TLI that overrides available libfuncs
ClosedPublic

Authored by tejohnson on Sep 23 2019, 8:53 AM.

Details

Summary

Follow-on to D66428 and D71193, to build the TLI per-function so
that -fno-builtin* handling can be migrated to use function attributes.
See discussion on D61634 for background. This is an enabler for fixing
handling of these options for LTO, for example.

With D71193, the -fno-builtin* flags are converted to function
attributes, so we can now set this information per-function on the TLI.

In this patch, the TLI constructor is changed to take a Function, which
can be used to override the available builtins. The TLI is augmented
with an array that can be used to specify which builtins are not
available for the corresponding function. The available function checks
are changed to consult this override before checking the underlying
module level baseline TLII. New code is added to set this override
array based on the attributes.

I also removed the code that sets availability in the TLII in clang from
the options, which is no longer needed.

I removed a per-Triple caching of TLII objects in the analysis object,
as it is based on the Module's Triple which is the same for all
functions in any case. Is there a case where we would be compiling
multiple Modules with different Triples in one compilation?

Finally, I have changed the legacy analysis wrapper to create and use
the new PM analysis class (TargetLibraryAnalysis) in getTLI. This is
consistent with the behavior of getTTI for the legacy
TargetTransformInfo analysis. This change means that getTLI now creates
a new TLI on each call (although that should be very cheap as we cache
the module level TLII, and computing the per-function
attribute based availability should also be reasonably efficient).
I measured the compile time for a large C++ file with tens of thousands
of functions and as expected there was no increase.

Diff Detail

Event Timeline

tejohnson created this revision.Sep 23 2019, 8:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 23 2019, 8:53 AM
gchatelet added inline comments.Sep 23 2019, 11:29 AM
include/llvm/Analysis/TargetLibraryInfo.h
229

Can we use llvm/ADT/BitVector.h instead?

tejohnson marked 2 inline comments as done.Sep 23 2019, 4:11 PM
tejohnson added inline comments.
include/llvm/Analysis/TargetLibraryInfo.h
229

Good idea.

tejohnson updated this revision to Diff 221429.Sep 23 2019, 4:11 PM
tejohnson marked an inline comment as done.

Use BitVector

Update after D71193 committed, converting -fno-builtin* options to attributes.

Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2019, 11:30 AM
tejohnson edited the summary of this revision. (Show Details)Dec 13 2019, 11:33 AM

Please take a look. This is now updated to reflect the commit of D71193, which translated the options to the new attributes. I also removed some comments that I realized didn't make sense, as we need to keep a baseline availability array on the base TLII since that is set based on the architecture. We simply override this for no-builtin* attributes on the function. I removed the code from clang that was setting up the availability array based on the options, and all tests pass.

hfinkel accepted this revision.Dec 13 2019, 6:01 PM

Please take a look. This is now updated to reflect the commit of D71193, which translated the options to the new attributes. I also removed some comments that I realized didn't make sense, as we need to keep a baseline availability array on the base TLII since that is set based on the architecture. We simply override this for no-builtin* attributes on the function. I removed the code from clang that was setting up the availability array based on the options, and all tests pass.

LGTM.

llvm/include/llvm/Analysis/TargetLibraryInfo.h
52 ↗(On Diff #233841)

Unintentional new whitespace?

This revision is now accepted and ready to land.Dec 13 2019, 6:01 PM
gchatelet accepted this revision.Dec 15 2019, 3:50 AM

Thx !

llvm/include/llvm/Analysis/TargetLibraryInfo.h
227 ↗(On Diff #233841)

I don't think you need the LLVM_ATTRIBUTE_UNUSED here

229 ↗(On Diff #233841)

[optional] rewrite as if (!F) return; to reduce nesting depth.

236 ↗(On Diff #233841)

Inline so you don't allocate the string (consumeFront takes a StringRef)

tejohnson marked 6 inline comments as done.Dec 16 2019, 9:14 AM
tejohnson updated this revision to Diff 234090.Dec 16 2019, 9:15 AM

Address comments

This revision was automatically updated to reflect the committed changes.