Skip to content

Commit ca9d8c0

Browse files
authored
Merge branch 'main' into main
2 parents 59b8fab + f65b35d commit ca9d8c0

File tree

4,830 files changed

+912632
-303180
lines changed

Some content is hidden

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

4,830 files changed

+912632
-303180
lines changed

.ci/generate_test_report_lib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def plural(num_tests):
9292
]
9393
)
9494
elif failures:
95-
report.extend(["", "## Failed Tests", "(click on a test name to see its output)"])
95+
report.extend(
96+
["", "## Failed Tests", "(click on a test name to see its output)"]
97+
)
9698

9799
for testsuite_name, failures in failures.items():
98100
report.extend(["", f"### {testsuite_name}"])

.ci/metrics/metrics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
# remain small.
6868
BUILDKITE_GRAPHQL_BUILDS_PER_PAGE = 50
6969

70+
7071
@dataclass
7172
class JobMetrics:
7273
job_name: str
@@ -77,6 +78,7 @@ class JobMetrics:
7778
workflow_id: int
7879
workflow_name: str
7980

81+
8082
@dataclass
8183
class GaugeMetric:
8284
name: str
@@ -258,6 +260,7 @@ def buildkite_get_metrics(
258260

259261
return output, incomplete_now
260262

263+
261264
def github_get_metrics(
262265
github_repo: github.Repository, last_workflows_seen_as_completed: set[int]
263266
) -> tuple[list[JobMetrics], int]:

.github/new-prs-labeler.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ mlgo:
702702
- llvm/unittests/CodeGen/ML*
703703
- llvm/test/CodeGen/MLRegAlloc/**
704704
- llvm/utils/mlgo-utils/**
705+
- llvm/docs/MLGO.rst
705706

706707
tools:llvm-exegesis:
707708
- llvm/tools/llvm-exegesis/**

.github/workflows/containers/github-action-ci-windows/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ RUN choco install -y handle
108108
109109
RUN pip3 install pywin32 buildbot-worker==2.8.4
110110
111-
ARG RUNNER_VERSION=2.323.0
111+
ARG RUNNER_VERSION=2.324.0
112112
ENV RUNNER_VERSION=$RUNNER_VERSION
113113
114114
RUN powershell -Command \

.github/workflows/containers/github-action-ci/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM docker.io/library/ubuntu:24.04 as base
22
ENV LLVM_SYSROOT=/opt/llvm
33

44
FROM base as stage1-toolchain
5-
ENV LLVM_VERSION=20.1.1
5+
ENV LLVM_VERSION=20.1.4
66

77
RUN apt-get update && \
88
apt-get install -y \
@@ -86,7 +86,7 @@ WORKDIR /home/gha
8686

8787
FROM ci-container as ci-container-agent
8888

89-
ENV GITHUB_RUNNER_VERSION=2.323.0
89+
ENV GITHUB_RUNNER_VERSION=2.324.0
9090

9191
RUN mkdir actions-runner && \
9292
cd actions-runner && \

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class BinaryFunction {
142142
/// Types of profile the function can use. Could be a combination.
143143
enum {
144144
PF_NONE = 0, /// No profile.
145-
PF_LBR = 1, /// Profile is based on last branch records.
146-
PF_SAMPLE = 2, /// Non-LBR sample-based profile.
145+
PF_BRANCH = 1, /// Profile is based on branches or branch stacks.
146+
PF_BASIC = 2, /// Non-branch IP sample-based profile.
147147
PF_MEMEVENT = 4, /// Profile has mem events.
148148
};
149149

@@ -392,7 +392,7 @@ class BinaryFunction {
392392
float ProfileMatchRatio{0.0f};
393393

394394
/// Raw branch count for this function in the profile.
395-
uint64_t RawBranchCount{0};
395+
uint64_t RawSampleCount{0};
396396

397397
/// Dynamically executed function bytes, used for density computation.
398398
uint64_t SampleCountInBytes{0};
@@ -804,6 +804,19 @@ class BinaryFunction {
804804
return iterator_range<const_cfi_iterator>(cie_begin(), cie_end());
805805
}
806806

807+
/// Iterate over instructions (only if CFG is unavailable or not built yet).
808+
iterator_range<InstrMapType::iterator> instrs() {
809+
assert(!hasCFG() && "Iterate over basic blocks instead");
810+
return make_range(Instructions.begin(), Instructions.end());
811+
}
812+
iterator_range<InstrMapType::const_iterator> instrs() const {
813+
assert(!hasCFG() && "Iterate over basic blocks instead");
814+
return make_range(Instructions.begin(), Instructions.end());
815+
}
816+
817+
/// Returns whether there are any labels at Offset.
818+
bool hasLabelAt(unsigned Offset) const { return Labels.count(Offset) != 0; }
819+
807820
/// Iterate over all jump tables associated with this function.
808821
iterator_range<std::map<uint64_t, JumpTable *>::const_iterator>
809822
jumpTables() const {
@@ -1893,11 +1906,11 @@ class BinaryFunction {
18931906

18941907
/// Return the raw profile information about the number of branch
18951908
/// executions corresponding to this function.
1896-
uint64_t getRawBranchCount() const { return RawBranchCount; }
1909+
uint64_t getRawSampleCount() const { return RawSampleCount; }
18971910

18981911
/// Set the profile data about the number of branch executions corresponding
18991912
/// to this function.
1900-
void setRawBranchCount(uint64_t Count) { RawBranchCount = Count; }
1913+
void setRawSampleCount(uint64_t Count) { RawSampleCount = Count; }
19011914

19021915
/// Return the number of dynamically executed bytes, from raw perf data.
19031916
uint64_t getSampleCountInBytes() const { return SampleCountInBytes; }

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MCSymbol;
4949
class raw_ostream;
5050

5151
namespace bolt {
52+
class BinaryBasicBlock;
5253
class BinaryFunction;
5354

5455
/// Different types of indirect branches encountered during disassembly.
@@ -572,6 +573,11 @@ class MCPlusBuilder {
572573
return false;
573574
}
574575

576+
virtual MCPhysReg getSignedReg(const MCInst &Inst) const {
577+
llvm_unreachable("not implemented");
578+
return getNoRegister();
579+
}
580+
575581
virtual ErrorOr<MCPhysReg> getRegUsedAsRetDest(const MCInst &Inst) const {
576582
llvm_unreachable("not implemented");
577583
return getNoRegister();
@@ -622,6 +628,54 @@ class MCPlusBuilder {
622628
return std::make_pair(getNoRegister(), getNoRegister());
623629
}
624630

631+
/// Analyzes if a pointer is checked to be authenticated successfully
632+
/// by the end of the basic block.
633+
///
634+
/// It is possible for pointer authentication instructions not to terminate
635+
/// the program abnormally on authentication failure and return some invalid
636+
/// pointer instead (like it is done on AArch64 when FEAT_FPAC is not
637+
/// implemented). This might be enough to crash on invalid memory access when
638+
/// the pointer is later used as the destination of a load, store, or branch
639+
/// instruction. On the other hand, when the pointer is not used right away,
640+
/// it may be important for the compiler to check the address explicitly not
641+
/// to introduce a signing or authentication oracle.
642+
///
643+
/// This function is intended to detect a complex, multi-instruction pointer-
644+
/// checking sequence spanning a contiguous range of instructions at the end
645+
/// of the basic block (as these sequences are expected to end with a
646+
/// conditional branch - this is how they are implemented on AArch64 by LLVM).
647+
/// If a (Reg, FirstInst) pair is returned and before execution of FirstInst
648+
/// Reg was last written to by an authentication instruction, then it is known
649+
/// that in any successor of BB either
650+
/// * the authentication instruction that last wrote to Reg succeeded, or
651+
/// * the program is terminated abnormally without introducing any signing
652+
/// or authentication oracles
653+
///
654+
/// Note that this function is not expected to repeat the results returned
655+
/// by getAuthCheckedReg(Inst, MayOverwrite) function below.
656+
virtual std::optional<std::pair<MCPhysReg, MCInst *>>
657+
getAuthCheckedReg(BinaryBasicBlock &BB) const {
658+
llvm_unreachable("not implemented");
659+
return std::nullopt;
660+
}
661+
662+
/// Returns the register that is checked to be authenticated successfully.
663+
///
664+
/// If the returned register was last written to by an authentication
665+
/// instruction and that authentication failed, then the program is known
666+
/// to be terminated abnormally as a result of execution of Inst.
667+
///
668+
/// Additionally, if MayOverwrite is false, it is known that the authenticated
669+
/// pointer is not clobbered by Inst itself.
670+
///
671+
/// Use this function for simple, single-instruction patterns instead of
672+
/// its getAuthCheckedReg(BB) counterpart.
673+
virtual MCPhysReg getAuthCheckedReg(const MCInst &Inst,
674+
bool MayOverwrite) const {
675+
llvm_unreachable("not implemented");
676+
return getNoRegister();
677+
}
678+
625679
virtual bool isTerminator(const MCInst &Inst) const;
626680

627681
virtual bool isNoop(const MCInst &Inst) const {

bolt/include/bolt/Passes/PAuthGadgetScanner.h

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "bolt/Core/BinaryContext.h"
1313
#include "bolt/Core/BinaryFunction.h"
1414
#include "bolt/Passes/BinaryPasses.h"
15-
#include "llvm/ADT/SmallSet.h"
1615
#include "llvm/Support/raw_ostream.h"
1716
#include <memory>
1817

@@ -65,6 +64,14 @@ struct MCInstInBFReference {
6564
uint64_t Offset;
6665
MCInstInBFReference(BinaryFunction *BF, uint64_t Offset)
6766
: BF(BF), Offset(Offset) {}
67+
68+
static MCInstInBFReference get(const MCInst *Inst, BinaryFunction &BF) {
69+
for (auto &I : BF.instrs())
70+
if (Inst == &I.second)
71+
return MCInstInBFReference(&BF, I.first);
72+
return {};
73+
}
74+
6875
MCInstInBFReference() : BF(nullptr), Offset(0) {}
6976
bool operator==(const MCInstInBFReference &RHS) const {
7077
return BF == RHS.BF && Offset == RHS.Offset;
@@ -104,6 +111,12 @@ struct MCInstReference {
104111
MCInstReference(BinaryFunction *BF, uint32_t Offset)
105112
: MCInstReference(MCInstInBFReference(BF, Offset)) {}
106113

114+
static MCInstReference get(const MCInst *Inst, BinaryFunction &BF) {
115+
if (BF.hasCFG())
116+
return MCInstInBBReference::get(Inst, BF);
117+
return MCInstInBFReference::get(Inst, BF);
118+
}
119+
107120
bool operator<(const MCInstReference &RHS) const {
108121
if (ParentKind != RHS.ParentKind)
109122
return ParentKind < RHS.ParentKind;
@@ -138,6 +151,16 @@ struct MCInstReference {
138151
llvm_unreachable("");
139152
}
140153

154+
operator bool() const {
155+
switch (ParentKind) {
156+
case BasicBlockParent:
157+
return U.BBRef.BB != nullptr;
158+
case FunctionParent:
159+
return U.BFRef.BF != nullptr;
160+
}
161+
llvm_unreachable("");
162+
}
163+
141164
uint64_t getAddress() const {
142165
switch (ParentKind) {
143166
case BasicBlockParent:
@@ -173,9 +196,6 @@ raw_ostream &operator<<(raw_ostream &OS, const MCInstReference &);
173196

174197
namespace PAuthGadgetScanner {
175198

176-
class SrcSafetyAnalysis;
177-
struct SrcState;
178-
179199
/// Description of a gadget kind that can be detected. Intended to be
180200
/// statically allocated to be attached to reports by reference.
181201
class GadgetKind {
@@ -184,7 +204,7 @@ class GadgetKind {
184204
public:
185205
GadgetKind(const char *Description) : Description(Description) {}
186206

187-
const StringRef getDescription() const { return Description; }
207+
StringRef getDescription() const { return Description; }
188208
};
189209

190210
/// Base report located at some instruction, without any additional information.
@@ -199,8 +219,8 @@ struct Report {
199219

200220
// The two methods below are called by Analysis::computeDetailedInfo when
201221
// iterating over the reports.
202-
virtual const ArrayRef<MCPhysReg> getAffectedRegisters() const { return {}; }
203-
virtual void setOverwritingInstrs(const ArrayRef<MCInstReference> Instrs) {}
222+
virtual ArrayRef<MCPhysReg> getAffectedRegisters() const { return {}; }
223+
virtual void setOverwritingInstrs(ArrayRef<MCInstReference> Instrs) {}
204224

205225
void printBasicInfo(raw_ostream &OS, const BinaryContext &BC,
206226
StringRef IssueKind) const;
@@ -223,19 +243,19 @@ struct GadgetReport : public Report {
223243

224244
void generateReport(raw_ostream &OS, const BinaryContext &BC) const override;
225245

226-
const ArrayRef<MCPhysReg> getAffectedRegisters() const override {
246+
ArrayRef<MCPhysReg> getAffectedRegisters() const override {
227247
return AffectedRegisters;
228248
}
229249

230-
void setOverwritingInstrs(const ArrayRef<MCInstReference> Instrs) override {
250+
void setOverwritingInstrs(ArrayRef<MCInstReference> Instrs) override {
231251
OverwritingInstrs.assign(Instrs.begin(), Instrs.end());
232252
}
233253
};
234254

235255
/// Report with a free-form message attached.
236256
struct GenericReport : public Report {
237257
std::string Text;
238-
GenericReport(MCInstReference Location, const std::string &Text)
258+
GenericReport(MCInstReference Location, StringRef Text)
239259
: Report(Location), Text(Text) {}
240260
virtual void generateReport(raw_ostream &OS,
241261
const BinaryContext &BC) const override;

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ class DataAggregator : public DataReader {
9292
uint64_t Addr;
9393
};
9494

95-
/// Used for parsing specific pre-aggregated input files.
96-
struct AggregatedLBREntry {
97-
enum Type : char { BRANCH = 0, FT, FT_EXTERNAL_ORIGIN, TRACE };
98-
Location From;
99-
Location To;
100-
uint64_t Count;
101-
uint64_t Mispreds;
102-
Type EntryType;
103-
};
104-
10595
struct Trace {
10696
uint64_t From;
10797
uint64_t To;
@@ -131,7 +121,6 @@ class DataAggregator : public DataReader {
131121
/// and use them later for processing and assigning profile.
132122
std::unordered_map<Trace, TakenBranchInfo, TraceHash> BranchLBRs;
133123
std::unordered_map<Trace, FTInfo, TraceHash> FallthroughLBRs;
134-
std::vector<AggregatedLBREntry> AggregatedLBRs;
135124
std::unordered_map<uint64_t, uint64_t> BasicSamples;
136125
std::vector<PerfMemSample> MemSamples;
137126

@@ -223,11 +212,6 @@ class DataAggregator : public DataReader {
223212
uint64_t NumTraces{0};
224213
uint64_t NumInvalidTraces{0};
225214
uint64_t NumLongRangeTraces{0};
226-
/// Specifies how many samples were recorded in cold areas if we are dealing
227-
/// with profiling data collected in a bolted binary. For LBRs, incremented
228-
/// for the source of the branch to avoid counting cold activity twice (one
229-
/// for source and another for destination).
230-
uint64_t NumColdSamples{0};
231215
uint64_t NumTotalSamples{0};
232216

233217
/// Looks into system PATH for Linux Perf and set up the aggregator to use it
@@ -257,7 +241,8 @@ class DataAggregator : public DataReader {
257241

258242
/// Semantic actions - parser hooks to interpret parsed perf samples
259243
/// Register a sample (non-LBR mode), i.e. a new hit at \p Address
260-
bool doSample(BinaryFunction &Func, const uint64_t Address, uint64_t Count);
244+
bool doBasicSample(BinaryFunction &Func, const uint64_t Address,
245+
uint64_t Count);
261246

262247
/// Register an intraprocedural branch \p Branch.
263248
bool doIntraBranch(BinaryFunction &Func, uint64_t From, uint64_t To,
@@ -422,9 +407,6 @@ class DataAggregator : public DataReader {
422407
/// an external tool.
423408
std::error_code parsePreAggregatedLBRSamples();
424409

425-
/// Process parsed pre-aggregated data.
426-
void processPreAggregated();
427-
428410
/// If \p Address falls into the binary address space based on memory
429411
/// mapping info \p MMI, then adjust it for further processing by subtracting
430412
/// the base load address. External addresses, i.e. addresses that do not
@@ -486,7 +468,6 @@ class DataAggregator : public DataReader {
486468
void dump(const PerfMemSample &Sample) const;
487469

488470
/// Profile diagnostics print methods
489-
void printColdSamplesDiagnostic() const;
490471
void printLongRangeTracesDiagnostic() const;
491472
void printBranchSamplesDiagnostics() const;
492473
void printBasicSamplesDiagnostics(uint64_t OutOfRangeSamples) const;

0 commit comments

Comments
 (0)