Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit ccc4331

Browse files
Manually merged main:5821351343eb into amd-gfx:ca668accdd
Local branch amd-gfx Merged main:cce35994bb72 into amd-gfx:b53c56f743f7 Remote branch main 5821351 [clang][Interp] Implement __builtin_fpclassify
2 parents ca668ac + 5821351 commit ccc4331

File tree

557 files changed

+21985
-12393
lines changed

Some content is hidden

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

557 files changed

+21985
-12393
lines changed

bolt/include/bolt/Passes/ReorderFunctions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ReorderFunctions : public BinaryFunctionPass {
3232
RT_EXEC_COUNT,
3333
RT_HFSORT,
3434
RT_HFSORT_PLUS,
35+
RT_CDS,
3536
RT_PETTIS_HANSEN,
3637
RT_RANDOM,
3738
RT_USER

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,6 +2305,12 @@ void BinaryFunction::removeConditionalTailCalls() {
23052305

23062306
// This branch is no longer a conditional tail call.
23072307
BC.MIB->unsetConditionalTailCall(*CTCInstr);
2308+
2309+
// Move offset from CTCInstr to TailCallInstr.
2310+
if (std::optional<uint32_t> Offset = BC.MIB->getOffset(*CTCInstr)) {
2311+
BC.MIB->setOffset(TailCallInstr, *Offset);
2312+
BC.MIB->clearOffset(*CTCInstr);
2313+
}
23082314
}
23092315

23102316
insertBasicBlocks(std::prev(end()), std::move(NewBlocks),

bolt/lib/Passes/ReorderFunctions.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "bolt/Utils/Utils.h"
1616
#include "llvm/ADT/STLExtras.h"
1717
#include "llvm/Support/CommandLine.h"
18+
#include "llvm/Transforms/Utils/CodeLayout.h"
1819
#include <fstream>
1920

2021
#define DEBUG_TYPE "hfsort"
@@ -41,6 +42,8 @@ cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions(
4142
"use hfsort algorithm"),
4243
clEnumValN(bolt::ReorderFunctions::RT_HFSORT_PLUS, "hfsort+",
4344
"use hfsort+ algorithm"),
45+
clEnumValN(bolt::ReorderFunctions::RT_CDS, "cds",
46+
"use cache-directed sort"),
4447
clEnumValN(bolt::ReorderFunctions::RT_PETTIS_HANSEN,
4548
"pettis-hansen", "use Pettis-Hansen algorithm"),
4649
clEnumValN(bolt::ReorderFunctions::RT_RANDOM, "random",
@@ -309,6 +312,37 @@ void ReorderFunctions::runOnFunctions(BinaryContext &BC) {
309312
case RT_HFSORT_PLUS:
310313
Clusters = hfsortPlus(Cg);
311314
break;
315+
case RT_CDS: {
316+
// It is required that the sum of incoming arc weights is not greater
317+
// than the number of samples for every function. Ensuring the call graph
318+
// obeys the property before running the algorithm.
319+
Cg.adjustArcWeights();
320+
321+
// Initialize CFG nodes and their data
322+
std::vector<uint64_t> FuncSizes;
323+
std::vector<uint64_t> FuncCounts;
324+
using JumpT = std::pair<uint64_t, uint64_t>;
325+
std::vector<std::pair<JumpT, uint64_t>> CallCounts;
326+
std::vector<uint64_t> CallOffsets;
327+
for (NodeId F = 0; F < Cg.numNodes(); ++F) {
328+
FuncSizes.push_back(Cg.size(F));
329+
FuncCounts.push_back(Cg.samples(F));
330+
for (NodeId Succ : Cg.successors(F)) {
331+
const Arc &Arc = *Cg.findArc(F, Succ);
332+
auto It = std::make_pair(F, Succ);
333+
CallCounts.push_back(std::make_pair(It, Arc.weight()));
334+
CallOffsets.push_back(uint64_t(Arc.avgCallOffset()));
335+
}
336+
}
337+
338+
// Run the layout algorithm.
339+
std::vector<uint64_t> Result =
340+
applyCDSLayout(FuncSizes, FuncCounts, CallCounts, CallOffsets);
341+
342+
// Create a single cluster from the computed order of hot functions.
343+
std::vector<CallGraph::NodeId> NodeOrder(Result.begin(), Result.end());
344+
Clusters.emplace_back(Cluster(NodeOrder, Cg));
345+
} break;
312346
case RT_PETTIS_HANSEN:
313347
Clusters = pettisAndHansen(Cg);
314348
break;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,13 +1479,10 @@ std::error_code DataAggregator::parseBranchEvents() {
14791479
NumTraces += parseLBRSample(Sample, NeedsSkylakeFix);
14801480
}
14811481

1482-
for (const auto &LBR : BranchLBRs) {
1483-
const Trace &Trace = LBR.first;
1484-
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Trace.From))
1485-
BF->setHasProfileAvailable();
1486-
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Trace.To))
1487-
BF->setHasProfileAvailable();
1488-
}
1482+
for (const Trace &Trace : llvm::make_first_range(BranchLBRs))
1483+
for (const uint64_t Addr : {Trace.From, Trace.To})
1484+
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
1485+
BF->setHasProfileAvailable();
14891486

14901487
auto printColored = [](raw_ostream &OS, float Percent, float T1, float T2) {
14911488
OS << " (";
@@ -1721,12 +1718,9 @@ std::error_code DataAggregator::parsePreAggregatedLBRSamples() {
17211718
if (std::error_code EC = AggrEntry.getError())
17221719
return EC;
17231720

1724-
if (BinaryFunction *BF =
1725-
getBinaryFunctionContainingAddress(AggrEntry->From.Offset))
1726-
BF->setHasProfileAvailable();
1727-
if (BinaryFunction *BF =
1728-
getBinaryFunctionContainingAddress(AggrEntry->To.Offset))
1729-
BF->setHasProfileAvailable();
1721+
for (const uint64_t Addr : {AggrEntry->From.Offset, AggrEntry->To.Offset})
1722+
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
1723+
BF->setHasProfileAvailable();
17301724

17311725
AggregatedLBRs.emplace_back(std::move(AggrEntry.get()));
17321726
}

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
344344
continue;
345345

346346
yaml::bolt::BinaryFunctionProfile &YamlBF = *PI->getValue();
347-
if (profileMatches(YamlBF, Function))
347+
if (profileMatches(YamlBF, Function)) {
348348
matchProfileToFunction(YamlBF, Function);
349+
break;
350+
}
349351
}
350352
}
351353

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ void DWARFRewriter::updateUnitDebugInfo(
839839
case dwarf::DW_TAG_inlined_subroutine:
840840
case dwarf::DW_TAG_try_block:
841841
case dwarf::DW_TAG_catch_block: {
842-
uint64_t RangesSectionOffset = RangesSectionWriter.getEmptyRangesOffset();
842+
uint64_t RangesSectionOffset = 0;
843843
Expected<DWARFAddressRangesVector> RangesOrError =
844844
getDIEAddressRanges(*Die, Unit);
845845
const BinaryFunction *Function =
@@ -865,6 +865,10 @@ void DWARFRewriter::updateUnitDebugInfo(
865865
}
866866
} else if (!RangesOrError) {
867867
consumeError(RangesOrError.takeError());
868+
} else {
869+
OutputRanges.push_back({0, !RangesOrError->empty()
870+
? RangesOrError.get().front().HighPC
871+
: 0});
868872
}
869873
DIEValue LowPCVal = Die->findAttribute(dwarf::DW_AT_low_pc);
870874
DIEValue HighPCVal = Die->findAttribute(dwarf::DW_AT_high_pc);

0 commit comments

Comments
 (0)