Skip to content

Commit 001af0f

Browse files
committed
[MC] Actually make .pseudoprobe created sections deterministic
Fix a18ee8b to use a comparator that actually works: assign an ordinal to registered section.
1 parent 08aeac0 commit 001af0f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

llvm/lib/MC/MCPseudoProbe.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/ADT/STLExtras.h"
1111
#include "llvm/IR/PseudoProbe.h"
1212
#include "llvm/MC/MCAsmInfo.h"
13+
#include "llvm/MC/MCAssembler.h"
1314
#include "llvm/MC/MCContext.h"
1415
#include "llvm/MC/MCExpr.h"
1516
#include "llvm/MC/MCFragment.h"
@@ -213,7 +214,12 @@ void MCPseudoProbeSections::emit(MCObjectStreamer *MCOS) {
213214
Vec.reserve(MCProbeDivisions.size());
214215
for (auto &ProbeSec : MCProbeDivisions)
215216
Vec.emplace_back(ProbeSec.first, &ProbeSec.second);
216-
llvm::sort(Vec, [](auto A, auto B) { return A.second->Guid < B.second->Guid; });
217+
for (auto I : llvm::enumerate(MCOS->getAssembler()))
218+
I.value().setOrdinal(I.index());
219+
llvm::sort(Vec, [](auto A, auto B) {
220+
return A.first->getSection().getOrdinal() <
221+
B.first->getSection().getOrdinal();
222+
});
217223
for (auto [FuncSym, RootPtr] : Vec) {
218224
const auto &Root = *RootPtr;
219225
if (auto *S = Ctx.getObjectFileInfo()->getPseudoProbeSection(

llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ entry:
109109
; CHECK-SEC: [ 5] .text.foo2 PROGBITS {{.*}} 00 AX 0 0 16
110110
; CHECK-SEC: [ 8] .text.foo3 PROGBITS {{.*}} 00 AXG 0 0 16
111111
; CHECK-SEC-COUNT-3: .pseudo_probe_desc PROGBITS
112-
; CHECK-SEC: .pseudo_probe PROGBITS {{.*}} 00 LG 8 0 1
112+
; CHECK-SEC: .pseudo_probe PROGBITS {{.*}} 00 L 3 0 1
113113
; CHECK-SEC-NEXT: .pseudo_probe PROGBITS {{.*}} 00 L 5 0 1
114-
; CHECK-SEC-NEXT: .pseudo_probe PROGBITS {{.*}} 00 L 3 0 1
114+
; CHECK-SEC-NEXT: .pseudo_probe PROGBITS {{.*}} 00 LG 8 0 1
115115
; CHECK-SEC-NOT: .rela.pseudo_probe
116116

117117
; CHECK-SEC: COMDAT group section [ 7] `.group' [foo3] contains 2 sections:
118118
; CHECK-SEC-NEXT: [Index] Name
119119
; CHECK-SEC-NEXT: [ 8] .text.foo3
120-
; CHECK-SEC-NEXT: [ 19] .pseudo_probe
120+
; CHECK-SEC-NEXT: [ 21] .pseudo_probe
121121
; CHECK-SEC-EMPTY:
122122
; CHECK-SEC-NEXT: COMDAT group section [ 10] `.group' [.pseudo_probe_desc_foo] contains 1 sections:
123123
; CHECK-SEC-NEXT: [Index] Name
@@ -137,9 +137,9 @@ entry:
137137
; CHECK-SEC2: [ 5] .text PROGBITS {{.*}} 00 AX 0 0 16
138138
; CHECK-SEC2: [ 8] .text PROGBITS {{.*}} 00 AXG 0 0 16
139139
; CHECK-SEC2-COUNT-3: .pseudo_probe_desc PROGBITS
140-
; CHECK-SEC2: .pseudo_probe PROGBITS {{.*}} 00 LG 8 0 1
140+
; CHECK-SEC2: .pseudo_probe PROGBITS {{.*}} 00 L 3 0 1
141141
; CHECK-SEC2-NEXT: .pseudo_probe PROGBITS {{.*}} 00 L 5 0 1
142-
; CHECK-SEC2-NEXT: .pseudo_probe PROGBITS {{.*}} 00 L 3 0 1
142+
; CHECK-SEC2-NEXT: .pseudo_probe PROGBITS {{.*}} 00 LG 8 0 1
143143
; CHECK-SEC2-NOT: .rela.pseudo_probe
144144

145145
!llvm.dbg.cu = !{!0}

0 commit comments

Comments
 (0)