profile on-demand loading was added for ExtBinary format profile in https://reviews.llvm.org/rL374233, but currently profile on-demand loading doesn't work well with profile remapping. The patch adds the support.
Suppose a function in the current module has outline instance in the profile. The function name in the module is different from the name of the outline instance, but remapper knows the two names are equal. When loading profile on-demand, the outline instance has to be loaded with remapper's help.
Before the patch, the steps to read the profile is as follows:
- create the profile reader
- profile reader read the profile.
- create the profile remapper
- remapper set the underlying reader.
- reset the profile reader to remapper.
With the patch, the steps to read the profile is changed to:
- create the profile reader
- create the profile remapper
- profile reader set the underlying remapper.
- profile reader read the profile.
- remapper set the underlying reader.
- reset the profile reader to remapper.
If client calls getSamplesFor before reading profile, RemappingApplied would be set without doing anything. Then even if client later calls read followed by getSamplesFor, remapping will never be applied. Probably not a big deal though as it's kind of corner case. But alternatively we could eliminate that possibility by calling applyRemapping right after reading profile, e.g. have read from base class call something like readImpl and applyRemapping, and different readers only override readImpl instead of read.