Skip to content

Commit ad92d65

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:6ae657b08d624f9634fa6ebbf5d6fd7a22dc3b4d into amd-gfx:57a9efc3a4ac
Local branch amd-gfx 57a9efc Merged main:2f91e98120f168b7ded6cb34d546dba178515cc4 into amd-gfx:58ed5842fd7a Remote branch main 6ae657b [lldb] Adapt Plugins/Process/Windows to new Status API
2 parents 57a9efc + 6ae657b commit ad92d65

File tree

1,070 files changed

+31865
-12248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,070 files changed

+31865
-12248
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,42 @@ jobs:
191191
**/CMakeError.log
192192
**/CMakeOutput.log
193193
**/crash_diagnostics/*
194+
195+
macos:
196+
runs-on: macos-14
197+
needs: [ stage1 ]
198+
strategy:
199+
fail-fast: true
200+
matrix:
201+
config: [
202+
generic-cxx03,
203+
generic-cxx23,
204+
generic-modules,
205+
apple-configuration
206+
]
207+
steps:
208+
- uses: actions/checkout@v4
209+
- uses: maxim-lobanov/setup-xcode@v1
210+
with:
211+
xcode-version: 'latest-stable'
212+
- uses: seanmiddleditch/gha-setup-ninja@master
213+
- name: Build and test
214+
run: |
215+
python3 -m venv .venv
216+
source .venv/bin/activate
217+
python -m pip install psutil
218+
bash libcxx/utils/ci/run-buildbot ${{ matrix.config }}
219+
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
220+
if: always() # Upload artifacts even if the build or test suite fails
221+
with:
222+
name: macos-${{ matrix.config }}-results
223+
path: |
224+
**/test-results.xml
225+
**/*.abilist
226+
**/CMakeError.log
227+
**/CMakeOutput.log
228+
**/crash_diagnostics/*
229+
194230
windows:
195231
runs-on: windows-2022
196232
needs: [ stage1 ]

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,8 @@ class BinaryFunction {
16921692

16931693
void setPseudo(bool Pseudo) { IsPseudo = Pseudo; }
16941694

1695+
void setPreserveNops(bool Value) { PreserveNops = Value; }
1696+
16951697
BinaryFunction &setUsesGnuArgsSize(bool Uses = true) {
16961698
UsesGnuArgsSize = Uses;
16971699
return *this;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,22 +1339,10 @@ Error BinaryFunction::disassemble() {
13391339
BC.getBinaryFunctionContainingAddress(TargetAddress))
13401340
TargetFunc->setIgnored();
13411341

1342-
if (IsCall && containsAddress(TargetAddress)) {
1343-
if (TargetAddress == getAddress()) {
1344-
// Recursive call.
1345-
TargetSymbol = getSymbol();
1346-
} else {
1347-
if (BC.isX86()) {
1348-
// Dangerous old-style x86 PIC code. We may need to freeze this
1349-
// function, so preserve the function as is for now.
1350-
PreserveNops = true;
1351-
} else {
1352-
BC.errs() << "BOLT-WARNING: internal call detected at 0x"
1353-
<< Twine::utohexstr(AbsoluteInstrAddr)
1354-
<< " in function " << *this << ". Skipping.\n";
1355-
IsSimple = false;
1356-
}
1357-
}
1342+
if (IsCall && TargetAddress == getAddress()) {
1343+
// A recursive call. Calls to internal blocks are handled by
1344+
// ValidateInternalCalls pass.
1345+
TargetSymbol = getSymbol();
13581346
}
13591347

13601348
if (!TargetSymbol) {

bolt/lib/Passes/ValidateInternalCalls.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,24 +302,27 @@ bool ValidateInternalCalls::analyzeFunction(BinaryFunction &Function) const {
302302
}
303303

304304
Error ValidateInternalCalls::runOnFunctions(BinaryContext &BC) {
305-
if (!BC.isX86())
306-
return Error::success();
307-
308305
// Look for functions that need validation. This should be pretty rare.
309306
std::set<BinaryFunction *> NeedsValidation;
310307
for (auto &BFI : BC.getBinaryFunctions()) {
311308
BinaryFunction &Function = BFI.second;
312309
for (BinaryBasicBlock &BB : Function) {
313310
for (MCInst &Inst : BB) {
314311
if (getInternalCallTarget(Function, Inst)) {
312+
BC.errs() << "BOLT-WARNING: internal call detected in function "
313+
<< Function << '\n';
315314
NeedsValidation.insert(&Function);
316315
Function.setSimple(false);
316+
Function.setPreserveNops(true);
317317
break;
318318
}
319319
}
320320
}
321321
}
322322

323+
if (!BC.isX86())
324+
return Error::success();
325+
323326
// Skip validation for non-relocation mode
324327
if (!BC.HasRelocations)
325328
return Error::success();

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,17 +2415,15 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
24152415
Fragments.insert(BF);
24162416
for (const BinaryFunction *F : Fragments) {
24172417
const uint64_t FuncAddr = F->getAddress();
2418-
const auto &FragmentProbes =
2419-
llvm::make_range(ProbeMap.lower_bound(FuncAddr),
2420-
ProbeMap.lower_bound(FuncAddr + F->getSize()));
2421-
for (const auto &[OutputAddress, Probes] : FragmentProbes) {
2418+
for (const MCDecodedPseudoProbe &Probe :
2419+
ProbeMap.find(FuncAddr, FuncAddr + F->getSize())) {
2420+
const uint32_t OutputAddress = Probe.getAddress();
24222421
const uint32_t InputOffset = BAT->translate(
24232422
FuncAddr, OutputAddress - FuncAddr, /*IsBranchSrc=*/true);
24242423
const unsigned BlockIndex = getBlock(InputOffset).second;
2425-
for (const MCDecodedPseudoProbe &Probe : Probes)
2426-
YamlBF.Blocks[BlockIndex].PseudoProbes.emplace_back(
2427-
yaml::bolt::PseudoProbeInfo{Probe.getGuid(), Probe.getIndex(),
2428-
Probe.getType()});
2424+
YamlBF.Blocks[BlockIndex].PseudoProbes.emplace_back(
2425+
yaml::bolt::PseudoProbeInfo{Probe.getGuid(), Probe.getIndex(),
2426+
Probe.getType()});
24292427
}
24302428
}
24312429
}

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,10 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS,
193193
const uint64_t FuncAddr = BF.getAddress();
194194
const std::pair<uint64_t, uint64_t> &BlockRange =
195195
BB->getInputAddressRange();
196-
const auto &BlockProbes =
197-
llvm::make_range(ProbeMap.lower_bound(FuncAddr + BlockRange.first),
198-
ProbeMap.lower_bound(FuncAddr + BlockRange.second));
199-
for (const auto &[_, Probes] : BlockProbes)
200-
for (const MCDecodedPseudoProbe &Probe : Probes)
201-
YamlBB.PseudoProbes.emplace_back(yaml::bolt::PseudoProbeInfo{
202-
Probe.getGuid(), Probe.getIndex(), Probe.getType()});
196+
for (const MCDecodedPseudoProbe &Probe : ProbeMap.find(
197+
FuncAddr + BlockRange.first, FuncAddr + BlockRange.second))
198+
YamlBB.PseudoProbes.emplace_back(yaml::bolt::PseudoProbeInfo{
199+
Probe.getGuid(), Probe.getIndex(), Probe.getType()});
203200
}
204201

205202
YamlBF.Blocks.emplace_back(YamlBB);

bolt/lib/Rewrite/PseudoProbeRewriter.cpp

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ void PseudoProbeRewriter::parsePseudoProbe() {
143143
if (!ProbeDecoder.buildAddress2ProbeMap(
144144
reinterpret_cast<const uint8_t *>(Contents.data()), Contents.size(),
145145
GuidFilter, FuncStartAddrs)) {
146-
ProbeDecoder.getAddress2ProbesMap().clear();
147146
errs() << "BOLT-WARNING: fail in building Address2ProbeMap\n";
148147
return;
149148
}
@@ -156,7 +155,8 @@ void PseudoProbeRewriter::parsePseudoProbe() {
156155
ProbeDecoder.printProbesForAllAddresses(outs());
157156
}
158157

159-
for (const auto &[GUID, FuncDesc] : ProbeDecoder.getGUID2FuncDescMap()) {
158+
for (const auto &FuncDesc : ProbeDecoder.getGUID2FuncDescMap()) {
159+
uint64_t GUID = FuncDesc.FuncGUID;
160160
if (!FuncStartAddrs.contains(GUID))
161161
continue;
162162
BinaryFunction *BF = BC.getBinaryFunctionAtAddress(FuncStartAddrs[GUID]);
@@ -174,59 +174,50 @@ void PseudoProbeRewriter::updatePseudoProbes() {
174174
AddressProbesMap &Address2ProbesMap = ProbeDecoder.getAddress2ProbesMap();
175175
const GUIDProbeFunctionMap &GUID2Func = ProbeDecoder.getGUID2FuncDescMap();
176176

177-
for (auto &AP : Address2ProbesMap) {
178-
BinaryFunction *F = BC.getBinaryFunctionContainingAddress(AP.first);
177+
for (MCDecodedPseudoProbe &Probe : Address2ProbesMap) {
178+
uint64_t Address = Probe.getAddress();
179+
BinaryFunction *F = BC.getBinaryFunctionContainingAddress(Address);
179180
// If F is removed, eliminate all probes inside it from inline tree
180181
// Setting probes' addresses as INT64_MAX means elimination
181182
if (!F) {
182-
for (MCDecodedPseudoProbe &Probe : AP.second)
183-
Probe.setAddress(INT64_MAX);
183+
Probe.setAddress(INT64_MAX);
184184
continue;
185185
}
186186
// If F is not emitted, the function will remain in the same address as its
187187
// input
188188
if (!F->isEmitted())
189189
continue;
190190

191-
uint64_t Offset = AP.first - F->getAddress();
191+
uint64_t Offset = Address - F->getAddress();
192192
const BinaryBasicBlock *BB = F->getBasicBlockContainingOffset(Offset);
193193
uint64_t BlkOutputAddress = BB->getOutputAddressRange().first;
194194
// Check if block output address is defined.
195195
// If not, such block is removed from binary. Then remove the probes from
196196
// inline tree
197197
if (BlkOutputAddress == 0) {
198-
for (MCDecodedPseudoProbe &Probe : AP.second)
199-
Probe.setAddress(INT64_MAX);
198+
Probe.setAddress(INT64_MAX);
200199
continue;
201200
}
202201

203-
unsigned ProbeTrack = AP.second.size();
204-
std::list<MCDecodedPseudoProbe>::iterator Probe = AP.second.begin();
205-
while (ProbeTrack != 0) {
206-
if (Probe->isBlock()) {
207-
Probe->setAddress(BlkOutputAddress);
208-
} else if (Probe->isCall()) {
209-
// A call probe may be duplicated due to ICP
210-
// Go through output of InputOffsetToAddressMap to collect all related
211-
// probes
212-
auto CallOutputAddresses = BC.getIOAddressMap().lookupAll(AP.first);
213-
auto CallOutputAddress = CallOutputAddresses.first;
214-
if (CallOutputAddress == CallOutputAddresses.second) {
215-
Probe->setAddress(INT64_MAX);
216-
} else {
217-
Probe->setAddress(CallOutputAddress->second);
218-
CallOutputAddress = std::next(CallOutputAddress);
219-
}
220-
221-
while (CallOutputAddress != CallOutputAddresses.second) {
222-
AP.second.push_back(*Probe);
223-
AP.second.back().setAddress(CallOutputAddress->second);
224-
Probe->getInlineTreeNode()->addProbes(&(AP.second.back()));
225-
CallOutputAddress = std::next(CallOutputAddress);
226-
}
202+
if (Probe.isBlock()) {
203+
Probe.setAddress(BlkOutputAddress);
204+
} else if (Probe.isCall()) {
205+
// A call probe may be duplicated due to ICP
206+
// Go through output of InputOffsetToAddressMap to collect all related
207+
// probes
208+
auto CallOutputAddresses = BC.getIOAddressMap().lookupAll(Address);
209+
auto CallOutputAddress = CallOutputAddresses.first;
210+
if (CallOutputAddress == CallOutputAddresses.second) {
211+
Probe.setAddress(INT64_MAX);
212+
} else {
213+
Probe.setAddress(CallOutputAddress->second);
214+
CallOutputAddress = std::next(CallOutputAddress);
215+
}
216+
217+
while (CallOutputAddress != CallOutputAddresses.second) {
218+
ProbeDecoder.addInjectedProbe(Probe, CallOutputAddress->second);
219+
CallOutputAddress = std::next(CallOutputAddress);
227220
}
228-
Probe = std::next(Probe);
229-
ProbeTrack--;
230221
}
231222
}
232223

@@ -242,22 +233,16 @@ void PseudoProbeRewriter::updatePseudoProbes() {
242233
BinaryBlock.getName();
243234

244235
// scan all addresses -> correlate probe to block when print out
245-
std::vector<uint64_t> Addresses;
246-
for (auto &Entry : Address2ProbesMap)
247-
Addresses.push_back(Entry.first);
248-
llvm::sort(Addresses);
249-
for (uint64_t Key : Addresses) {
250-
for (MCDecodedPseudoProbe &Probe : Address2ProbesMap[Key]) {
251-
if (Probe.getAddress() == INT64_MAX)
252-
outs() << "Deleted Probe: ";
253-
else
254-
outs() << "Address: " << format_hex(Probe.getAddress(), 8) << " ";
255-
Probe.print(outs(), GUID2Func, true);
256-
// print block name only if the probe is block type and undeleted.
257-
if (Probe.isBlock() && Probe.getAddress() != INT64_MAX)
258-
outs() << format_hex(Probe.getAddress(), 8) << " Probe is in "
259-
<< Addr2BlockNames[Probe.getAddress()] << "\n";
260-
}
236+
for (MCDecodedPseudoProbe &Probe : Address2ProbesMap) {
237+
if (Probe.getAddress() == INT64_MAX)
238+
outs() << "Deleted Probe: ";
239+
else
240+
outs() << "Address: " << format_hex(Probe.getAddress(), 8) << " ";
241+
Probe.print(outs(), GUID2Func, true);
242+
// print block name only if the probe is block type and undeleted.
243+
if (Probe.isBlock() && Probe.getAddress() != INT64_MAX)
244+
outs() << format_hex(Probe.getAddress(), 8) << " Probe is in "
245+
<< Addr2BlockNames[Probe.getAddress()] << "\n";
261246
}
262247
outs() << "=======================================\n";
263248
}
@@ -333,7 +318,7 @@ void PseudoProbeRewriter::encodePseudoProbes() {
333318
ProbeDecoder.getDummyInlineRoot();
334319
for (auto Child = Root.getChildren().begin();
335320
Child != Root.getChildren().end(); ++Child)
336-
Inlinees[Child->first] = Child->second.get();
321+
Inlinees[Child->getInlineSite()] = &*Child;
337322

338323
for (auto Inlinee : Inlinees)
339324
// INT64_MAX is "placeholder" of unused callsite index field in the pair
@@ -359,25 +344,37 @@ void PseudoProbeRewriter::encodePseudoProbes() {
359344
EmitInt(Cur->Guid, 8);
360345
// Emit number of probes in this node
361346
uint64_t Deleted = 0;
362-
for (MCDecodedPseudoProbe *&Probe : Cur->getProbes())
347+
for (MCDecodedPseudoProbe *&Probe :
348+
llvm::make_pointer_range(Cur->getProbes()))
363349
if (Probe->getAddress() == INT64_MAX)
364350
Deleted++;
365351
LLVM_DEBUG(dbgs() << "Deleted Probes:" << Deleted << "\n");
366-
uint64_t ProbesSize = Cur->getProbes().size() - Deleted;
352+
size_t InjectedProbes = ProbeDecoder.getNumInjectedProbes(Cur);
353+
uint64_t ProbesSize = Cur->getProbes().size() - Deleted + InjectedProbes;
367354
EmitULEB128IntValue(ProbesSize);
368355
// Emit number of direct inlinees
369356
EmitULEB128IntValue(Cur->getChildren().size());
370357
// Emit probes in this group
371-
for (MCDecodedPseudoProbe *&Probe : Cur->getProbes()) {
358+
for (MCDecodedPseudoProbe *&Probe :
359+
llvm::make_pointer_range(Cur->getProbes())) {
372360
if (Probe->getAddress() == INT64_MAX)
373361
continue;
374362
EmitDecodedPseudoProbe(Probe);
375363
LastProbe = Probe;
376364
}
365+
if (InjectedProbes) {
366+
for (MCDecodedPseudoProbe *&Probe :
367+
llvm::make_pointer_range(ProbeDecoder.getInjectedProbes(Cur))) {
368+
if (Probe->getAddress() == INT64_MAX)
369+
continue;
370+
EmitDecodedPseudoProbe(Probe);
371+
LastProbe = Probe;
372+
}
373+
}
377374

378375
for (auto Child = Cur->getChildren().begin();
379376
Child != Cur->getChildren().end(); ++Child)
380-
Inlinees[Child->first] = Child->second.get();
377+
Inlinees[Child->getInlineSite()] = &*Child;
381378
for (const auto &Inlinee : Inlinees) {
382379
assert(Cur->Guid != 0 && "non root tree node must have nonzero Guid");
383380
NextNodes.push_back({std::get<1>(Inlinee.first), Inlinee.second});

0 commit comments

Comments
 (0)