This is an archive of the discontinued LLVM Phabricator instance.

[FuzzMutate] Module size heuristics
ClosedPublic

Authored by oakrc on May 5 2023, 1:44 PM.

Details

Summary

IRMutation::mutateModule() currently requires the bitcode size of the module.
To compute the bitcode size, one way is to write the module to a buffer using
BitcodeWriter and calculating the buffer size. This would be fine for a single
mutation, but infeasible for repeated mutations due to the large overhead. It
turns out that the only IR strategy weight calculation method that depends on
the current module size is InstDeleterStrategy, which deletes instructions more
frequently as the module size approaches a given max size. However, there is no
real need for the size to be in bytes of bitcode, so we can use a different
metric. One alternative is to let the size be the number of objects in the
Module, including instructions, basic blocks, globals, and aliases. Although
getting the number of instructions is still O(n), it should have significantly
less overhead than BitcodeWriter. This suggestion would cause a change to the
IRMutator API, since IRMutator::mutateModule() can calculate the Module size
itself.

Diff Detail

Event Timeline

oakrc created this revision.May 5 2023, 1:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 1:44 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
oakrc requested review of this revision.May 5 2023, 1:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 1:44 PM
Peter added inline comments.May 5 2023, 2:07 PM
llvm/include/llvm/FuzzMutate/IRMutator.h
74

Can you add comments here about the change and the semantics of size?

oakrc updated this revision to Diff 519985.May 5 2023, 2:58 PM

Fix usage of IRMutator::mutateModule in llvm-isel-fuzzer. MaxSize provided is
in bytes of bitcode but we can give it to IRMutator as a reference. writeModule
will silently refuse to save new module if actual bitcode size exceeds MaxSize.

oakrc updated this revision to Diff 519986.May 5 2023, 3:03 PM

Add comments to clarify the meaning of getModuleSize and MaxSize.

oakrc marked an inline comment as done.May 5 2023, 3:09 PM
oakrc updated this revision to Diff 519992.May 5 2023, 3:28 PM

Fix another usage in llvm-opt-fuzzer. Did a recursive grep and there should be
no other usage left.

Peter accepted this revision.May 5 2023, 3:43 PM
This revision is now accepted and ready to land.May 5 2023, 3:43 PM
This revision was automatically updated to reflect the committed changes.