Skip to content

Commit 30cdad3

Browse files
authored
Merge branch 'llvm:main' into GISel_rembyconst
2 parents 9aed4c1 + 4e30f81 commit 30cdad3

File tree

2,909 files changed

+128367
-80379
lines changed

Some content is hidden

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

2,909 files changed

+128367
-80379
lines changed

.ci/compute_projects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
DEPENDENT_RUNTIMES_TO_TEST = {
7878
"clang": {"compiler-rt"},
7979
"clang-tools-extra": {"libc"},
80+
"libc": {"libc"},
8081
".ci": {"compiler-rt", "libc"},
8182
}
8283
DEPENDENT_RUNTIMES_TO_TEST_NEEDS_RECONFIG = {

.ci/compute_projects_test.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_top_level_file(self):
187187
self.assertEqual(env_variables["runtimes_check_targets"], "")
188188
self.assertEqual(env_variables["runtimes_check_targets_needs_reconfig"], "")
189189

190-
def test_exclude_runtiems_in_projects(self):
190+
def test_exclude_libcxx_in_projects(self):
191191
env_variables = compute_projects.get_env_variables(
192192
["libcxx/CMakeLists.txt"], "Linux"
193193
)
@@ -197,6 +197,16 @@ def test_exclude_runtiems_in_projects(self):
197197
self.assertEqual(env_variables["runtimes_check_targets"], "")
198198
self.assertEqual(env_variables["runtimes_check_targets_needs_reconfig"], "")
199199

200+
def test_include_libc_in_runtimes(self):
201+
env_variables = compute_projects.get_env_variables(
202+
["libc/CMakeLists.txt"], "Linux"
203+
)
204+
self.assertEqual(env_variables["projects_to_build"], "clang;lld")
205+
self.assertEqual(env_variables["project_check_targets"], "")
206+
self.assertEqual(env_variables["runtimes_to_build"], "libc")
207+
self.assertEqual(env_variables["runtimes_check_targets"], "check-libc")
208+
self.assertEqual(env_variables["runtimes_check_targets_needs_reconfig"], "")
209+
200210
def test_exclude_docs(self):
201211
env_variables = compute_projects.get_env_variables(
202212
["llvm/docs/CIBestPractices.rst"], "Linux"

.github/copilot-instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
When performing a code review, pay close attention to code modifying a function's
2+
control flow. Could the change result in the corruption of performance profile
3+
data? Could the change result in invalid debug information, in particular for
4+
branches and calls?

.github/new-prs-labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ llvm:instcombine:
632632
- llvm/test/Transforms/InstCombine/**
633633
- llvm/test/Transforms/InstSimplify/**
634634

635+
llvm:vectorcombine:
636+
- llvm/lib/Transforms/Vectorize/VectorCombine.cpp
637+
- llvm/test/Transforms/VectorCombine/**
638+
635639
clangd:
636640
- clang-tools-extra/clangd/**
637641

.github/workflows/hlsl-test-all.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ jobs:
4343
- name: Checkout OffloadTest
4444
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4545
with:
46-
repository: llvm-beanz/offload-test-suite
46+
repository: llvm/offload-test-suite
4747
ref: main
4848
path: OffloadTest
4949
- name: Checkout Golden Images
5050
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
5151
with:
52-
repository: llvm-beanz/offload-golden-images
52+
repository: llvm/offload-golden-images
5353
ref: main
5454
path: golden-images
5555
- name: Setup Windows

.github/workflows/libcxx-restart-preempted-jobs.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ jobs:
3232
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
3333
with:
3434
script: |
35-
const failure_regex = /Process completed with exit code 1./
36-
const preemption_regex = /(The runner has received a shutdown signal)|(The operation was canceled)/
35+
// The "The run was canceled by" message comes from a user manually canceling a workflow
36+
// the "higher priority" message comes from github canceling a workflow because the user updated the change.
37+
// And the "exit code 1" message indicates a genuine failure.
38+
const failure_regex = /(Process completed with exit code 1.)|(Canceling since a higher priority waiting request)|(The run was canceled by)/
39+
const preemption_regex = /(The runner has received a shutdown signal)/
3740
3841
const wf_run = context.payload.workflow_run
3942
core.notice(`Running on "${wf_run.display_title}" by @${wf_run.actor.login} (event: ${wf_run.event})\nWorkflow run URL: ${wf_run.html_url}`)
@@ -167,7 +170,7 @@ jobs:
167170
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
168171
with:
169172
script: |
170-
const FAILURE_REGEX = /Process completed with exit code 1./
173+
const FAILURE_REGEX = /(Process completed with exit code 1.)|(Canceling since a higher priority waiting request)|(The run was canceled by)/
171174
const PREEMPTION_REGEX = /(The runner has received a shutdown signal)|(The operation was canceled)/
172175
173176
function log(msg) {

bolt/include/bolt/Core/BinarySection.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,6 @@ inline uint8_t *copyByteArray(const uint8_t *Data, uint64_t Size) {
523523
return Array;
524524
}
525525

526-
inline uint8_t *copyByteArray(StringRef Buffer) {
527-
return copyByteArray(reinterpret_cast<const uint8_t *>(Buffer.data()),
528-
Buffer.size());
529-
}
530-
531526
inline uint8_t *copyByteArray(ArrayRef<char> Buffer) {
532527
return copyByteArray(reinterpret_cast<const uint8_t *>(Buffer.data()),
533528
Buffer.size());

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "llvm/CodeGen/DIE.h"
2121
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
2222
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
23-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
2423
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
24+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2525
#include "llvm/Support/Allocator.h"
2626

2727
#include <list>

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ class MCPlusBuilder {
13931393
return getTargetSymbol(BinaryExpr->getLHS());
13941394

13951395
auto *SymbolRefExpr = dyn_cast<const MCSymbolRefExpr>(Expr);
1396-
if (SymbolRefExpr && SymbolRefExpr->getKind() == MCSymbolRefExpr::VK_None)
1396+
if (SymbolRefExpr && SymbolRefExpr->getSpecifier() == 0)
13971397
return &SymbolRefExpr->getSymbol();
13981398

13991399
return nullptr;

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ class RewriteInstance {
202202
/// Map code sections generated by BOLT.
203203
void mapCodeSections(BOLTLinker::SectionMapper MapSection);
204204

205+
/// Map code without relocating sections.
206+
void mapCodeSectionsInPlace(BOLTLinker::SectionMapper MapSection);
207+
205208
/// Map the rest of allocatable sections.
206209
void mapAllocatableSections(BOLTLinker::SectionMapper MapSection);
207210

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,10 +3328,7 @@ void BinaryFunction::duplicateConstantIslands() {
33283328

33293329
// Update instruction reference
33303330
Operand = MCOperand::createExpr(BC.MIB->getTargetExprFor(
3331-
Inst,
3332-
MCSymbolRefExpr::create(ColdSymbol, MCSymbolRefExpr::VK_None,
3333-
*BC.Ctx),
3334-
*BC.Ctx, 0));
3331+
Inst, MCSymbolRefExpr::create(ColdSymbol, *BC.Ctx), *BC.Ctx, 0));
33353332
++OpNum;
33363333
}
33373334
}

bolt/lib/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(LLVM_LINK_COMPONENTS
22
DebugInfoDWARF
3+
DebugInfoDWARFLowLevel
34
Demangle
45
MC
56
MCDisassembler

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
#include "llvm/CodeGen/DIE.h"
1515
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
1616
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
17-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
1817
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1918
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
2019
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
2120
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
21+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2222
#include "llvm/Support/Casting.h"
2323
#include "llvm/Support/Debug.h"
2424
#include "llvm/Support/ErrorHandling.h"

bolt/lib/Core/DebugNames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "bolt/Core/DebugNames.h"
1010
#include "bolt/Core/BinaryContext.h"
11-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
1211
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
12+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
1313
#include "llvm/Support/EndianStream.h"
1414
#include "llvm/Support/LEB128.h"
1515
#include <cstdint>

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,27 +1765,26 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
17651765

17661766
if (opts::ShowDensity) {
17671767
double Density = 0.0;
1768-
// Sorted by the density in descending order.
1769-
llvm::stable_sort(FuncDensityList,
1770-
[&](const std::pair<double, uint64_t> &A,
1771-
const std::pair<double, uint64_t> &B) {
1772-
if (A.first != B.first)
1773-
return A.first > B.first;
1774-
return A.second < B.second;
1775-
});
1768+
llvm::sort(FuncDensityList);
17761769

17771770
uint64_t AccumulatedSamples = 0;
1778-
uint32_t I = 0;
17791771
assert(opts::ProfileDensityCutOffHot <= 1000000 &&
17801772
"The cutoff value is greater than 1000000(100%)");
1781-
while (AccumulatedSamples <
1782-
TotalSampleCount *
1783-
static_cast<float>(opts::ProfileDensityCutOffHot) /
1784-
1000000 &&
1785-
I < FuncDensityList.size()) {
1786-
AccumulatedSamples += FuncDensityList[I].second;
1787-
Density = FuncDensityList[I].first;
1788-
I++;
1773+
// Subtract samples in zero-density functions (no fall-throughs) from
1774+
// TotalSampleCount (not used anywhere below).
1775+
for (const auto [CurDensity, CurSamples] : FuncDensityList) {
1776+
if (CurDensity != 0.0)
1777+
break;
1778+
TotalSampleCount -= CurSamples;
1779+
}
1780+
const uint64_t CutoffSampleCount =
1781+
1.f * TotalSampleCount * opts::ProfileDensityCutOffHot / 1000000;
1782+
// Process functions in decreasing density order
1783+
for (const auto [CurDensity, CurSamples] : llvm::reverse(FuncDensityList)) {
1784+
if (AccumulatedSamples >= CutoffSampleCount)
1785+
break;
1786+
AccumulatedSamples += CurSamples;
1787+
Density = CurDensity;
17891788
}
17901789
if (Density == 0.0) {
17911790
BC.errs() << "BOLT-WARNING: the output profile is empty or the "

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,7 @@ Error Instrumentation::runOnFunctions(BinaryContext &BC) {
666666
auto IsLEA = [&BC](const MCInst &Inst) { return BC.MIB->isLEA64r(Inst); };
667667
const auto LEA = std::find_if(
668668
std::next(llvm::find_if(reverse(BB), IsLEA)), BB.rend(), IsLEA);
669-
LEA->getOperand(4).setExpr(
670-
MCSymbolRefExpr::create(Target, MCSymbolRefExpr::VK_None, *BC.Ctx));
669+
LEA->getOperand(4).setExpr(MCSymbolRefExpr::create(Target, *BC.Ctx));
671670
} else {
672671
BC.errs() << "BOLT-WARNING: ___GLOBAL_init_65535 not found\n";
673672
}

bolt/lib/Passes/PAuthGadgetScanner.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,90 @@ shouldReportReturnGadget(const BinaryContext &BC, const MCInstReference &Inst,
13191319
return make_gadget_report(RetKind, Inst, *RetReg);
13201320
}
13211321

1322+
/// While BOLT already marks some of the branch instructions as tail calls,
1323+
/// this function tries to detect less obvious cases, assuming false positives
1324+
/// are acceptable as long as there are not too many of them.
1325+
///
1326+
/// It is possible that not all the instructions classified as tail calls by
1327+
/// this function are safe to be considered as such for the purpose of code
1328+
/// transformations performed by BOLT. The intention of this function is to
1329+
/// spot some of actually missed tail calls (and likely a number of unrelated
1330+
/// indirect branch instructions) as long as this doesn't increase the amount
1331+
/// of false positive reports unacceptably.
1332+
static bool shouldAnalyzeTailCallInst(const BinaryContext &BC,
1333+
const BinaryFunction &BF,
1334+
const MCInstReference &Inst) {
1335+
// Some BC.MIB->isXYZ(Inst) methods simply delegate to MCInstrDesc::isXYZ()
1336+
// (such as isBranch at the time of writing this comment), some don't (such
1337+
// as isCall). For that reason, call MCInstrDesc's methods explicitly when
1338+
// it is important.
1339+
const MCInstrDesc &Desc =
1340+
BC.MII->get(static_cast<const MCInst &>(Inst).getOpcode());
1341+
// Tail call should be a branch (but not necessarily an indirect one).
1342+
if (!Desc.isBranch())
1343+
return false;
1344+
1345+
// Always analyze the branches already marked as tail calls by BOLT.
1346+
if (BC.MIB->isTailCall(Inst))
1347+
return true;
1348+
1349+
// Try to also check the branches marked as "UNKNOWN CONTROL FLOW" - the
1350+
// below is a simplified condition from BinaryContext::printInstruction.
1351+
bool IsUnknownControlFlow =
1352+
BC.MIB->isIndirectBranch(Inst) && !BC.MIB->getJumpTable(Inst);
1353+
1354+
if (BF.hasCFG() && IsUnknownControlFlow)
1355+
return true;
1356+
1357+
return false;
1358+
}
1359+
1360+
static std::optional<PartialReport<MCPhysReg>>
1361+
shouldReportUnsafeTailCall(const BinaryContext &BC, const BinaryFunction &BF,
1362+
const MCInstReference &Inst, const SrcState &S) {
1363+
static const GadgetKind UntrustedLRKind(
1364+
"untrusted link register found before tail call");
1365+
1366+
if (!shouldAnalyzeTailCallInst(BC, BF, Inst))
1367+
return std::nullopt;
1368+
1369+
// Not only the set of registers returned by getTrustedLiveInRegs() can be
1370+
// seen as a reasonable target-independent _approximation_ of "the LR", these
1371+
// are *exactly* those registers used by SrcSafetyAnalysis to initialize the
1372+
// set of trusted registers on function entry.
1373+
// Thus, this function basically checks that the precondition expected to be
1374+
// imposed by a function call instruction (which is hardcoded into the target-
1375+
// specific getTrustedLiveInRegs() function) is also respected on tail calls.
1376+
SmallVector<MCPhysReg> RegsToCheck = BC.MIB->getTrustedLiveInRegs();
1377+
LLVM_DEBUG({
1378+
traceInst(BC, "Found tail call inst", Inst);
1379+
traceRegMask(BC, "Trusted regs", S.TrustedRegs);
1380+
});
1381+
1382+
// In musl on AArch64, the _start function sets LR to zero and calls the next
1383+
// stage initialization function at the end, something along these lines:
1384+
//
1385+
// _start:
1386+
// mov x30, #0
1387+
// ; ... other initialization ...
1388+
// b _start_c ; performs "exit" system call at some point
1389+
//
1390+
// As this would produce a false positive for every executable linked with
1391+
// such libc, ignore tail calls performed by ELF entry function.
1392+
if (BC.StartFunctionAddress &&
1393+
*BC.StartFunctionAddress == Inst.getFunction()->getAddress()) {
1394+
LLVM_DEBUG({ dbgs() << " Skipping tail call in ELF entry function.\n"; });
1395+
return std::nullopt;
1396+
}
1397+
1398+
// Returns at most one report per instruction - this is probably OK...
1399+
for (auto Reg : RegsToCheck)
1400+
if (!S.TrustedRegs[Reg])
1401+
return make_gadget_report(UntrustedLRKind, Inst, Reg);
1402+
1403+
return std::nullopt;
1404+
}
1405+
13221406
static std::optional<PartialReport<MCPhysReg>>
13231407
shouldReportCallGadget(const BinaryContext &BC, const MCInstReference &Inst,
13241408
const SrcState &S) {
@@ -1478,6 +1562,9 @@ void FunctionAnalysisContext::findUnsafeUses(
14781562
if (PacRetGadgetsOnly)
14791563
return;
14801564

1565+
if (auto Report = shouldReportUnsafeTailCall(BC, BF, Inst, S))
1566+
Reports.push_back(*Report);
1567+
14811568
if (auto Report = shouldReportCallGadget(BC, Inst, S))
14821569
Reports.push_back(*Report);
14831570
if (auto Report = shouldReportSigningOracle(BC, Inst, S))

bolt/lib/Rewrite/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(LLVM_LINK_COMPONENTS
22
Core
33
DebugInfoDWARF
4+
DebugInfoDWARFLowLevel
45
JITLink
56
MC
67
Object

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
2525
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
2626
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
27-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
2827
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
2928
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
3029
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
30+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
3131
#include "llvm/MC/MCAsmBackend.h"
3232
#include "llvm/MC/MCAssembler.h"
3333
#include "llvm/MC/MCObjectWriter.h"

0 commit comments

Comments
 (0)