This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO, NewPM] Run OptimizerLastEPCallbacks from buildThinLTOPreLinkDefaultPipeline
ClosedPublic

Authored by vitalybuka on Feb 8 2021, 10:17 PM.

Details

Summary

-O1 and above don't call real optimizer pipeline in ThinLTO PreLink.
Also clang can't add PostLink OptimizerLastEPCallbacks for in-process ThinLTO.
This results in the missing sanitizer instrumentation with ThinLTO.

This is the simplest working solution which just calls
OptimizerLastEPCallbacks at the end of buildThinLTOPreLinkDefaultPipeline.

Diff Detail

Event Timeline

vitalybuka created this revision.Feb 8 2021, 10:17 PM
vitalybuka requested review of this revision.Feb 8 2021, 10:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2021, 10:17 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
vitalybuka edited the summary of this revision. (Show Details)Feb 9 2021, 3:30 AM
vitalybuka added reviewers: aeubanks, tejohnson, eugenis.

This seems like the wrong fix to me.
ThinLTO only runs the simplification pipeline pre-link, then runs it again plus the optimization pipeline. The optimization pipeline is the only place that OptimizerLastEPCallback should run (aside from the -O0 pipeline). Basically, the OptimizerLastEPCallbacks should only ever run once throughout all of compilation for a given module.

So it seems like LTO should do the same and only run the simplification pipeline pre-link, rather than just forward to buildPerModuleDefaultPipeline(), which runs both.

This seems like the wrong fix to me.
ThinLTO only runs the simplification pipeline pre-link, then runs it again plus the optimization pipeline. The optimization pipeline is the only place that OptimizerLastEPCallback should run (aside from the -O0 pipeline). Basically, the OptimizerLastEPCallbacks should only ever run once throughout all of compilation for a given module.

So it seems like LTO should do the same and only run the simplification pipeline pre-link, rather than just forward to buildPerModuleDefaultPipeline(), which runs both.

Alternative approach: register sanitizers on the backend only D96456

vitalybuka abandoned this revision.Feb 11 2021, 3:12 AM
vitalybuka reclaimed this revision.Feb 17 2021, 9:48 PM
vitalybuka retitled this revision from [ThinLTO, Sanitizers] Skip instrumentation by testing backend to [ThinLTO, NewPM] Run OptimizerLastEPCallbacks from buildThinLTOPreLinkDefaultPipeline.Feb 17 2021, 9:54 PM
vitalybuka edited the summary of this revision. (Show Details)
vitalybuka edited the summary of this revision. (Show Details)
vitalybuka edited the summary of this revision. (Show Details)

restore

Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2021, 9:56 PM

I recovered this patch as PreLink alternative to D96456.

Short term either of them will fix internal google builds.
Long term D96320 is going to be easier to maintain, e.g. if other users, without distributed LTO, like android will need sanitizers.

I tend to like this approach better for the reasons listed in D96456. @aeubanks any objections?

vitalybuka edited the summary of this revision. (Show Details)Feb 18 2021, 12:25 PM

Sorry, just got back from vacation, I'll try to take a look tomorrow

I guess this is fine. I'm worried that various OptimizerLastEPCallbacks will only expect to be run once, and adding a special case of not adding those callbacks during thinlto post link will be confusing for other uses of OptimizerLastEPCallbacks, but maybe it won't be so bad

clang/lib/CodeGen/BackendUtil.cpp
1304

what about just IsThinLTOPostLink? The Skip implies that we should skip ThinLTO post link, not that we should skip the passes.

aeubanks accepted this revision.Feb 23 2021, 1:17 PM
This revision is now accepted and ready to land.Feb 23 2021, 1:17 PM
vitalybuka marked an inline comment as done.

rename variable

This revision was landed with ongoing or failed builds.Feb 23 2021, 10:15 PM
This revision was automatically updated to reflect the committed changes.