This is an archive of the discontinued LLVM Phabricator instance.

Emit metadata if there is a profile hash mismatch
ClosedPublic

Authored by tmsriram on Jan 26 2021, 7:18 PM.

Details

Summary

This patch emits "instr_prof_hash_mismatch" function annotation metadata if there is a hash mismatch while applying instrumented profiles.

During the PGO optimized build using instrumented profiles, if the CFG of the function has changed since generating the profile, a hash mismatch is encountered. This patch emits this information as annotation metadata. We plan to use this with Propeller which is done at the machine IR level. Propeller is usually applied on top of PGO and a hash mismatch during PGO could be used to detect source drift.

Diff Detail

Event Timeline

tmsriram created this revision.Jan 26 2021, 7:18 PM
tmsriram requested review of this revision.Jan 26 2021, 7:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2021, 7:18 PM
davidxl added inline comments.Jan 26 2021, 8:16 PM
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
1254

Do you need to check the string as well?

tmsriram added inline comments.Jan 26 2021, 8:23 PM
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
1254

Thanks. I was debating what to do here, I had it as checking the string first. However, I noticed function metadata with annotation is only added here so I was not sure. Let me change it to explicitly check the string.

tmsriram updated this revision to Diff 319458.Jan 26 2021, 9:14 PM

Check if metadata already exists.

tmsriram updated this revision to Diff 319461.Jan 26 2021, 9:14 PM
tmsriram marked an inline comment as done.

Update patch.

snehasish added inline comments.Jan 26 2021, 9:22 PM
llvm/test/Transforms/PGOProfile/hash_mismatch_metadata.ll
2

Would it be useful to add a test to check that existing metadata is preserved?

davidxl added inline comments.Jan 26 2021, 9:28 PM
llvm/test/Transforms/PGOProfile/hash_mismatch_metadata.ll
2

That (end-to-end) can be added as a profile runtime test.

tmsriram added inline comments.Jan 26 2021, 9:30 PM
llvm/test/Transforms/PGOProfile/hash_mismatch_metadata.ll
2

I wasnt sure how to do it but I found a way. I can introduce a synthetic annotation. Let me update.

tmsriram updated this revision to Diff 319465.Jan 26 2021, 9:37 PM
tmsriram marked 2 inline comments as done.

Update test to check if the old metadata is retained and the new one is not duplicated.

tmsriram updated this revision to Diff 319467.Jan 26 2021, 9:40 PM

Update patch.

This revision is now accepted and ready to land.Jan 26 2021, 9:56 PM
xur accepted this revision.Jan 26 2021, 10:08 PM

lgtm too

This revision was automatically updated to reflect the committed changes.