@@ -44,26 +44,52 @@ struct PseudoProbeDwarfDiscriminator {
4444 // 32-bit integer which is organized as:
4545 // [2:0] - 0x7, this is reserved for regular discriminator,
4646 // see DWARF discriminator encoding rule
47- // [18:3] - probe id
47+ // if the [28:28] bit is zero:
48+ // [18:3] for probe id.
49+ // else:
50+ // [15:3] for probe id, [18:16] for dwarf base discriminator.
4851 // [25:19] - probe distribution factor
49- // [28:26] - probe type, see PseudoProbeType
50- // [31:29] - reserved for probe attributes
52+ // [27:26] - probe type, see PseudoProbeType
53+ // [28:28] - indicates whether dwarf base discriminator is encoded.
54+ // [30:29] - reserved for probe attributes
5155 static uint32_t packProbeData (uint32_t Index, uint32_t Type, uint32_t Flags,
52- uint32_t Factor) {
56+ uint32_t Factor,
57+ uint32_t DwarfBaseDiscriminator) {
5358 assert (Index <= 0xFFFF && " Probe index too big to encode, exceeding 2^16" );
54- assert (Type <= 0x7 && " Probe type too big to encode, exceeding 7 " );
59+ assert (Type <= 0x3 && " Probe type too big to encode, exceeding 3 " );
5560 assert (Flags <= 0x7 );
5661 assert (Factor <= 100 &&
5762 " Probe distribution factor too big to encode, exceeding 100" );
58- return (Index << 3 ) | (Factor << 19 ) | (Type << 26 ) | 0x7 ;
63+ uint32_t V = (Index << 3 ) | (Factor << 19 ) | (Type << 26 ) | 0x7 ;
64+ // If both the probe id and dwarf base discriminator is small, the probe id
65+ // space is shared with the dwarf base discriminator, this is to make the
66+ // probe-based build to be compatible with the dwarf-based profile. Pack the
67+ // dwarf base discriminator into [18:16] and set the [28:28] bit.
68+ if (Index <= 0x1FFF && DwarfBaseDiscriminator <= 0x7 )
69+ V |= (1 << 28 ) | (DwarfBaseDiscriminator << 16 );
70+ return V;
5971 }
6072
6173 static uint32_t extractProbeIndex (uint32_t Value) {
74+ if (isDwarfBaseDiscriminatorEncoded (Value))
75+ return (Value >> 3 ) & 0x1FFF ;
6276 return (Value >> 3 ) & 0xFFFF ;
6377 }
6478
79+ static uint32_t extractDwarfBaseDiscriminator (uint32_t Value) {
80+ if (isDwarfBaseDiscriminatorEncoded (Value))
81+ return (Value >> 16 ) & 0x7 ;
82+ // Return an invalid value to indicate the dwarf base discriminator is not
83+ // encoded.
84+ return 0xFFFFFFFF ;
85+ }
86+
87+ static uint32_t isDwarfBaseDiscriminatorEncoded (uint32_t Value) {
88+ return (Value >> 28 ) & 0x1 ;
89+ }
90+
6591 static uint32_t extractProbeType (uint32_t Value) {
66- return (Value >> 26 ) & 0x7 ;
92+ return (Value >> 26 ) & 0x3 ;
6793 }
6894
6995 static uint32_t extractProbeAttributes (uint32_t Value) {
0 commit comments