This is an archive of the discontinued LLVM Phabricator instance.

[PseudoProbe] Encode/Decode FS discriminator
ClosedPublic

Authored by hoy on Apr 5 2023, 11:54 AM.

Details

Summary

Encoding FS discriminators for block probes. Decoding them correspondingly.

The encoding/decoding of FS discriminators are conditional, only for probes with a non-zero discriminator. This saves encoding size, also ensures downwards-compatiblity.

Diff Detail

Event Timeline

hoy created this revision.Apr 5 2023, 11:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 11:54 AM
hoy requested review of this revision.Apr 5 2023, 11:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 11:54 AM
hoy updated this revision to Diff 514427.Apr 17 2023, 2:56 PM

Rebasing

wenlei added inline comments.May 8 2023, 5:46 PM
llvm/include/llvm/IR/PseudoProbe.h
34

At this layer, there's nothing specific to FS. I think we can just call it HasDiscriminator. This is essentially discriminator to probe, and we just currently use it for FSDiscriminator.

Then s/FSDiscriminator/Discriminator/g for this entire patch.

llvm/include/llvm/MC/MCPseudoProbe.h
114

can we use 32bit here?

llvm/lib/MC/MCAsmStreamer.cpp
2346

should we skip if disc is 0, meaning no disc?

hoy added inline comments.May 8 2023, 10:47 PM
llvm/include/llvm/IR/PseudoProbe.h
34

I initially used "Discriminator" but switched to FSDiscriminator since pseudo probe itself has a unique id and shouldn't need the discriminator concept to be distinguished. WDYT? I don't have a strong preference though.

llvm/include/llvm/MC/MCPseudoProbe.h
114

Yes, 32-bit should be enough for now.

llvm/lib/MC/MCAsmStreamer.cpp
2346

This is for easy handling on the decoding side, which looks for this field unconditionally. The asm form of probes is mostly for debugging, and we haven't optimized for it.

wenlei added inline comments.May 9 2023, 9:13 AM
llvm/include/llvm/IR/PseudoProbe.h
34

but switched to FSDiscriminator since pseudo probe itself has a unique id and shouldn't need the discriminator concept

I don't understand the reasoning - the fact that we are now using FSDiscriminator contradicts that statement. FSDiscriminator is one kind of discriminator.

I think it's perhaps better to just call it discriminator at this layer.

llvm/lib/MC/MCAsmStreamer.cpp
2346

But I thought that is what the PseudoProbeAttributes is for - i.e. discriminator field only exists when attribute is set, and decoder is supposed to check attribute first before reading the field..

llvm/lib/MC/MCParser/AsmParser.cpp
5854–5857

any reasons for these field to all use int64?

hoy added inline comments.May 9 2023, 11:24 AM
llvm/include/llvm/IR/PseudoProbe.h
34

Discriminator sounds a bit general to me, and I'm not sure if it can cause any confusion like one may question why it is needed since probe id is always unique. Maybe it was just me. If you just look at the encoding layer one may not get a full picture that probe id is unique in the first place and having a general discriminator may make sense. On the other hand, FSDiscriminator is very specific and clear.

llvm/lib/MC/MCAsmStreamer.cpp
2346

Yeah, the binary decoder currently does that. Makes sense for the asm decoder to also do that.

llvm/lib/MC/MCParser/AsmParser.cpp
5854–5857

because parseIntToken takes int64 as the parameter.

hoy updated this revision to Diff 520763.May 9 2023, 11:24 AM

Addressing comments.

wenlei accepted this revision.May 10 2023, 9:17 AM

lgtm with a nit, thanks.

llvm/include/llvm/IR/PseudoProbe.h
34

I see that you want to use "FSDiscriminator" to remind people that it's only for FS. But we have to accept that FSDiscriminator one kind of a Discriminator. Probe id is unique when it's assigned, but it's no longer unique after duplication, which is where discriminator or FSDiscriminator comes in. Anyways, thanks for making the change.

95

nit: these helper function seem to start with lower case initial?

This revision is now accepted and ready to land.May 10 2023, 9:17 AM
hoy added inline comments.May 10 2023, 9:58 AM
llvm/include/llvm/IR/PseudoProbe.h
95

Good catch.

hoy updated this revision to Diff 521023.May 10 2023, 9:59 AM

Updating D147651: [PseudoProbe] Encode/Decode FS discriminator

This revision was landed with ongoing or failed builds.May 10 2023, 11:34 AM
This revision was automatically updated to reflect the committed changes.