This is an archive of the discontinued LLVM Phabricator instance.

[FS-AFDO] Assign discriminators to pseudo probes
ClosedPublic

Authored by hoy on Mar 30 2023, 5:37 PM.

Details

Summary

This is the first change for FS-AFDO integration with CSSPGO. There are more patches coming.

With pseudo probes, we do not assign FS discriminators to any other instructions since we will be using only probes for profile correlation.

Also call instructions are excluded since their dwarf discriminators are used for other purposes, i.e, storing probe ids. Since they are not getting a FS discriminator, they will also be excluded from MIR profile loading. The corresponding changes will be in the subsequent patches.

Diff Detail

Event Timeline

hoy created this revision.Mar 30 2023, 5:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2023, 5:37 PM
hoy requested review of this revision.Mar 30 2023, 5:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2023, 5:37 PM
wenlei added inline comments.Mar 30 2023, 10:19 PM
llvm/lib/CodeGen/MIRFSDiscriminator.cpp
134–141

nit:

if ((ImprovedFSDiscriminator && I.isMetaInstruction()) || 
    (HasPseudoProbe && !I.isPseudoProbe()) {
  continue;
}
hoy added inline comments.Mar 31 2023, 9:07 AM
llvm/lib/CodeGen/MIRFSDiscriminator.cpp
134–141

Actually we need to go with the probe check first because probe is also a meta instruction.

Also call instructions are excluded since their dwarf discriminators are used for other purposes, i.e, storing probe ids.

How/where do we handle the FS discriminator for call probes? Or will that be handled in a separate patch?

llvm/lib/CodeGen/MIRFSDiscriminator.cpp
134–141

Ok, but when HasPseudoProbe is false, are we still going to have probe instructions? I thought we won't.

hoy added a comment.Apr 4 2023, 9:10 AM

Also call instructions are excluded since their dwarf discriminators are used for other purposes, i.e, storing probe ids.

How/where do we handle the FS discriminator for call probes? Or will that be handled in a separate patch?

They'll be handled separately. Basically they will be ignored in MIR sample loading.

llvm/lib/CodeGen/MIRFSDiscriminator.cpp
134–141

Right, when HasPseudoProbe is false we don't have probes. But ImprovedFSDiscriminator and HasPseudoProbe can be true at the same time, so checking ImprovedFSDiscriminator && I.isMetaInstruction()) first will ignore all probe instructions.

Also call instructions are excluded since their dwarf discriminators are used for other purposes, i.e, storing probe ids.

How/where do we handle the FS discriminator for call probes? Or will that be handled in a separate patch?

They'll be handled separately. Basically they will be ignored in MIR sample loading.

So you will need a separate patch to handle them, right? Without that, they are being ignored MIR sample loading. Perhaps worth clarifying in your change description.

My understand is: this is the first (of the two?) change for FS-AFDO integration with CSSPGO, where we handle non-call probes, and call probes will be handled in the 2nd patch.

This is to reduce hash conflicts.

May be nitpicking but this can be confusing too. I thought it's not about conflict. When we have probe (i.e. CSSPGO is on), the anchors are probes instead of debug lines, so we just naturally assign FS discriminators on the probe (anchors) instead. Of course, since we have less probes than general instructions, hash collision is less likely to happen.

llvm/lib/CodeGen/MIRFSDiscriminator.cpp
134–141

Ok, thanks for clarification. It's a bit tricky..

hoy added a comment.Apr 4 2023, 10:57 AM

Also call instructions are excluded since their dwarf discriminators are used for other purposes, i.e, storing probe ids.

How/where do we handle the FS discriminator for call probes? Or will that be handled in a separate patch?

They'll be handled separately. Basically they will be ignored in MIR sample loading.

So you will need a separate patch to handle them, right? Without that, they are being ignored MIR sample loading. Perhaps worth clarifying in your change description.

My understand is: this is the first (of the two?) change for FS-AFDO integration with CSSPGO, where we handle non-call probes, and call probes will be handled in the 2nd patch.

Yes, there will be a separate change for probe integration with MIR sample loading and call probes will be handled there.

This is to reduce hash conflicts.

May be nitpicking but this can be confusing too. I thought it's not about conflict. When we have probe (i.e. CSSPGO is on), the anchors are probes instead of debug lines, so we just naturally assign FS discriminators on the probe (anchors) instead. Of course, since we have less probes than general instructions, hash collision is less likely to happen.

Right, we don't need to handle dwarf lines if we only want to use probe as the anchors. But handling probes and lines exclusively basically means we cannot do dual profiles for FS-AFDO. I think if hash conflict was not an issue we wouldn't go exclusive.

Also call instructions are excluded since their dwarf discriminators are used for other purposes, i.e, storing probe ids.

How/where do we handle the FS discriminator for call probes? Or will that be handled in a separate patch?

They'll be handled separately. Basically they will be ignored in MIR sample loading.

So you will need a separate patch to handle them, right? Without that, they are being ignored MIR sample loading. Perhaps worth clarifying in your change description.

My understand is: this is the first (of the two?) change for FS-AFDO integration with CSSPGO, where we handle non-call probes, and call probes will be handled in the 2nd patch.

Yes, there will be a separate change for probe integration with MIR sample loading and call probes will be handled there.

Ok, please update the description to clarify. I would add something like "this is the first (of the two) change for FS-AFDO integration with CSSPGO, where we handle non-call probes, and call probes will be handled in the 2nd patch."

This is to reduce hash conflicts.

May be nitpicking but this can be confusing too. I thought it's not about conflict. When we have probe (i.e. CSSPGO is on), the anchors are probes instead of debug lines, so we just naturally assign FS discriminators on the probe (anchors) instead. Of course, since we have less probes than general instructions, hash collision is less likely to happen.

Right, we don't need to handle dwarf lines if we only want to use probe as the anchors. But handling probes and lines exclusively basically means we cannot do dual profiles for FS-AFDO. I think if hash conflict was not an issue we wouldn't go exclusive.

I see what you mean now, I wasn't thinking about making them co-exist. Again, please make it clear in the change description so people understand it better.

Otherwise lgtm, thanks.

hoy edited the summary of this revision. (Show Details)Apr 4 2023, 2:37 PM
hoy added a comment.Apr 4 2023, 2:45 PM

Also call instructions are excluded since their dwarf discriminators are used for other purposes, i.e, storing probe ids.

How/where do we handle the FS discriminator for call probes? Or will that be handled in a separate patch?

They'll be handled separately. Basically they will be ignored in MIR sample loading.

So you will need a separate patch to handle them, right? Without that, they are being ignored MIR sample loading. Perhaps worth clarifying in your change description.

My understand is: this is the first (of the two?) change for FS-AFDO integration with CSSPGO, where we handle non-call probes, and call probes will be handled in the 2nd patch.

Yes, there will be a separate change for probe integration with MIR sample loading and call probes will be handled there.

Ok, please update the description to clarify. I would add something like "this is the first (of the two) change for FS-AFDO integration with CSSPGO, where we handle non-call probes, and call probes will be handled in the 2nd patch."

This is to reduce hash conflicts.

May be nitpicking but this can be confusing too. I thought it's not about conflict. When we have probe (i.e. CSSPGO is on), the anchors are probes instead of debug lines, so we just naturally assign FS discriminators on the probe (anchors) instead. Of course, since we have less probes than general instructions, hash collision is less likely to happen.

Right, we don't need to handle dwarf lines if we only want to use probe as the anchors. But handling probes and lines exclusively basically means we cannot do dual profiles for FS-AFDO. I think if hash conflict was not an issue we wouldn't go exclusive.

I see what you mean now, I wasn't thinking about making them co-exist. Again, please make it clear in the change description so people understand it better.

Otherwise lgtm, thanks.

Sounds good, summary updated.

wenlei accepted this revision.Apr 4 2023, 3:14 PM

On second thought, if we want AFDO and CSSPGO to co-exist when FS is on, we could assign discriminators independently for probe and non-probe instructions? That way there's no more collisions in each of the two category, and when loading profile, we ignore probe for AFDO, ignore non-probe for CSSPGO?

This revision is now accepted and ready to land.Apr 4 2023, 3:14 PM
hoy added a comment.Apr 4 2023, 3:22 PM

On second thought, if we want AFDO and CSSPGO to co-exist when FS is on, we could assign discriminators independently for probe and non-probe instructions? That way there's no more collisions in each of the two category, and when loading profile, we ignore probe for AFDO, ignore non-probe for CSSPGO?

Yes, I thought about that too. We would need two set of maps, one for each.

The profile loading should naturally work as is with the IR sample loader. The loader knows what type of profiles it sees and uses lines or probes accordingly.

hoy edited the summary of this revision. (Show Details)Apr 4 2023, 3:30 PM
hoy edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.