This is an archive of the discontinued LLVM Phabricator instance.

Make NPM OptBisectInstrumentation use global singleton OptBisect
ClosedPublic

Authored by swamulism on Dec 8 2020, 4:38 PM.

Details

Summary

Currently there is an issue where the legacy pass manager uses a different OptBisect counter than the new pass manager.
This fix makes the npm OptBisectInstrumentation use the global OptBisect.

Diff Detail

Event Timeline

swamulism requested review of this revision.Dec 8 2020, 4:38 PM
swamulism created this revision.
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 8 2020, 4:38 PM

Thanks for looking into this!

Can you upload the diff with full context (e.g. use diff -U 9999 or use arcanist to upload)?

clang/lib/CodeGen/BackendUtil.cpp
1153

I took another look, if you look in LLVMContextImpl::getOptPassGate, it says the OptBisect instance must outlive the LLVMContext, which isn't true here. There's actually a global OptBisect there that we should use.

So I think we should go the opposite way. The NPM's StandardInstrumentations shouldn't contain its own OptBisect, it should inspect the IR it's receiving to get the IR's LLVMContext and call LLVMContext::getOptPassGate().

e.g. after unwrapping Any to Function *, F->getContext().getOptPassGate().

clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c
1

Something like "Make sure opt-bisect works through both pass managers" is probably better.
Also the test name doesn't need "O1" in it, just "new-pass-manager-opt-bisect.c" is good

3

don't need this

3

does this actually run the codegen passes? I thought we needed -emit-obj.

Oh and in the description

This means that when using OptBisect under the NPM it runs twice when it should only run once.

doesn't really make sense. I'd say something like

e.g. -opt-bisect-limit=1 will run both the first optional optimization pass and the first optional codegen pass, when really it should skip the codegen pass

swamulism updated this revision to Diff 311357.Dec 11 2020, 7:06 PM

Updating to set npm OptBisect to use global singleton OptBisect instead

Thank you for the comments and code review!

aeubanks added inline comments.Dec 11 2020, 7:15 PM
llvm/include/llvm/IR/OptBisect.h
58 ↗(On Diff #311357)
82 ↗(On Diff #311357)

should probably mention that this is so that multiple pass managers don't need to coordinate their uses of OptBisect

llvm/lib/IR/LLVMContextImpl.cpp
222 ↗(On Diff #311357)
llvm/lib/IR/OptBisect.cpp
58 ↗(On Diff #311357)

newline at end of file?

llvm/lib/Passes/StandardInstrumentations.cpp
28 ↗(On Diff #311357)

is this include necessary?

swamulism updated this revision to Diff 311358.Dec 11 2020, 7:26 PM
swamulism marked 5 inline comments as done.

Address comments

swamulism updated this revision to Diff 311360.Dec 11 2020, 7:30 PM

Update comment strings

swamulism retitled this revision from Set legacy pass manager OptBisect to same as NPM OptBisect to Set NPM OptBisect to use global singleton OptBisect .Dec 11 2020, 7:32 PM
swamulism edited the summary of this revision. (Show Details)
swamulism retitled this revision from Set NPM OptBisect to use global singleton OptBisect to Make NPM OptBisectInstrumentation to use global singleton OptBisect .
swamulism edited the summary of this revision. (Show Details)
swamulism retitled this revision from Make NPM OptBisectInstrumentation to use global singleton OptBisect to Make NPM OptBisectInstrumentation use global singleton OptBisect .
swamulism edited the summary of this revision. (Show Details)Dec 11 2020, 7:35 PM
aeubanks accepted this revision.Dec 11 2020, 7:36 PM
This revision is now accepted and ready to land.Dec 11 2020, 7:36 PM
This revision was landed with ongoing or failed builds.Dec 20 2020, 1:58 PM
This revision was automatically updated to reflect the committed changes.