Skip to content

Commit e91c899

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW15)
LLVM: llvm/llvm-project@a113a582b1a2c SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@4611812
2 parents 7581741 + 4423b83 commit e91c899

File tree

2,125 files changed

+112205
-61289
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,125 files changed

+112205
-61289
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ class BinaryFunction {
172172

173173
mutable MCSymbol *FunctionConstantIslandLabel{nullptr};
174174
mutable MCSymbol *FunctionColdConstantIslandLabel{nullptr};
175+
176+
// Returns constant island alignment
177+
uint16_t getAlignment() const { return sizeof(uint64_t); }
175178
};
176179

177180
static constexpr uint64_t COUNT_NO_PROFILE =
@@ -2047,6 +2050,10 @@ class BinaryFunction {
20472050
return *std::prev(CodeIter) <= *DataIter;
20482051
}
20492052

2053+
uint16_t getConstantIslandAlignment() const {
2054+
return Islands ? Islands->getAlignment() : 1;
2055+
}
2056+
20502057
uint64_t
20512058
estimateConstantIslandSize(const BinaryFunction *OnBehalfOf = nullptr) const {
20522059
if (!Islands)
@@ -2074,9 +2081,13 @@ class BinaryFunction {
20742081
Size += NextMarker - *DataIter;
20752082
}
20762083

2077-
if (!OnBehalfOf)
2078-
for (BinaryFunction *ExternalFunc : Islands->Dependency)
2084+
if (!OnBehalfOf) {
2085+
for (BinaryFunction *ExternalFunc : Islands->Dependency) {
2086+
Size = alignTo(Size, ExternalFunc->getConstantIslandAlignment());
20792087
Size += ExternalFunc->estimateConstantIslandSize(this);
2088+
}
2089+
}
2090+
20802091
return Size;
20812092
}
20822093

bolt/lib/Core/BinaryContext.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,17 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
155155
Twine("BOLT-ERROR: no register info for target ", TripleName));
156156

157157
// Set up disassembler.
158-
std::unique_ptr<const MCAsmInfo> AsmInfo(
158+
std::unique_ptr<MCAsmInfo> AsmInfo(
159159
TheTarget->createMCAsmInfo(*MRI, TripleName, MCTargetOptions()));
160160
if (!AsmInfo)
161161
return createStringError(
162162
make_error_code(std::errc::not_supported),
163163
Twine("BOLT-ERROR: no assembly info for target ", TripleName));
164+
// BOLT creates "func@PLT" symbols for PLT entries. In function assembly dump
165+
// we want to emit such names as using @PLT without double quotes to convey
166+
// variant kind to the assembler. BOLT doesn't rely on the linker so we can
167+
// override the default AsmInfo behavior to emit names the way we want.
168+
AsmInfo->setAllowAtInName(true);
164169

165170
std::unique_ptr<const MCSubtargetInfo> STI(
166171
TheTarget->createMCSubtargetInfo(TripleName, "", FeaturesStr));
@@ -1529,6 +1534,9 @@ void BinaryContext::preprocessDebugInfo() {
15291534
}
15301535

15311536
bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {
1537+
if (Function.isPseudo())
1538+
return false;
1539+
15321540
if (opts::processAllFunctions())
15331541
return true;
15341542

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void BinaryEmitter::emitFunctions() {
277277
}
278278

279279
bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
280-
if (Function.size() == 0)
280+
if (Function.size() == 0 && !Function.hasIslandsInfo())
281281
return false;
282282

283283
if (Function.getState() == BinaryFunction::State::Empty)
@@ -500,6 +500,13 @@ void BinaryEmitter::emitConstantIslands(BinaryFunction &BF, bool EmitColdPart,
500500
if (Islands.DataOffsets.empty() && Islands.Dependency.empty())
501501
return;
502502

503+
// AArch64 requires CI to be aligned to 8 bytes due to access instructions
504+
// restrictions. E.g. the ldr with imm, where imm must be aligned to 8 bytes.
505+
const uint16_t Alignment = OnBehalfOf
506+
? OnBehalfOf->getConstantIslandAlignment()
507+
: BF.getConstantIslandAlignment();
508+
Streamer.emitCodeAlignment(Alignment, &*BC.STI);
509+
503510
if (!OnBehalfOf) {
504511
if (!EmitColdPart)
505512
Streamer.emitLabel(BF.getFunctionConstantIslandLabel());

bolt/lib/Passes/Aligner.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ void AlignerPass::runOnFunctions(BinaryContext &BC) {
172172
else
173173
alignMaxBytes(BF);
174174

175+
// Align objects that contains constant islands and no code
176+
// to at least 8 bytes.
177+
if (!BF.size() && BF.hasIslandsInfo()) {
178+
const uint16_t Alignment = BF.getConstantIslandAlignment();
179+
if (BF.getAlignment() < Alignment)
180+
BF.setAlignment(Alignment);
181+
182+
if (BF.getMaxAlignmentBytes() < Alignment)
183+
BF.setMaxAlignmentBytes(Alignment);
184+
185+
if (BF.getMaxColdAlignmentBytes() < Alignment)
186+
BF.setMaxColdAlignmentBytes(Alignment);
187+
}
188+
175189
if (opts::AlignBlocks && !opts::PreserveBlocksAlignment)
176190
alignBlocks(BF, Emitter.MCE.get());
177191
};

bolt/lib/Passes/LongJmp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ uint64_t LongJmpPass::tentativeLayoutRelocColdPart(
308308
LLVM_DEBUG(dbgs() << Func->getPrintName() << " cold tentative: "
309309
<< Twine::utohexstr(DotAddress) << "\n");
310310
DotAddress += Func->estimateColdSize();
311+
DotAddress = alignTo(DotAddress, Func->getConstantIslandAlignment());
311312
DotAddress += Func->estimateConstantIslandSize();
312313
}
313314
return DotAddress;
@@ -344,6 +345,11 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
344345
CurrentIndex = 0;
345346
bool ColdLayoutDone = false;
346347
for (BinaryFunction *Func : SortedFunctions) {
348+
if (!BC.shouldEmit(*Func)) {
349+
HotAddresses[Func] = Func->getAddress();
350+
continue;
351+
}
352+
347353
if (!ColdLayoutDone && CurrentIndex >= LastHotIndex) {
348354
DotAddress =
349355
tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
@@ -364,6 +370,8 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
364370
DotAddress += Func->estimateSize();
365371
else
366372
DotAddress += Func->estimateHotSize();
373+
374+
DotAddress = alignTo(DotAddress, Func->getConstantIslandAlignment());
367375
DotAddress += Func->estimateConstantIslandSize();
368376
++CurrentIndex;
369377
}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,7 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
23502350
continue;
23512351
}
23522352

2353-
if (BC->getDynamicRelocationAt(Rel.getOffset())) {
2353+
if (!IsAArch64 && BC->getDynamicRelocationAt(Rel.getOffset())) {
23542354
LLVM_DEBUG(
23552355
dbgs() << "BOLT-DEBUG: address 0x"
23562356
<< Twine::utohexstr(Rel.getOffset())
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This test checks that the constant island is aligned after BOLT tool.
2+
// In case the nop before .Lci will be removed the pointer to exit function
3+
// won't be alinged and the test will fail.
4+
5+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \
6+
# RUN: %s -o %t.o
7+
# RUN: %clang %cflags -fPIC -pie %t.o -o %t.exe -Wl,-q \
8+
# RUN: -nostartfiles -nodefaultlibs -Wl,-z,notext
9+
# RUN: llvm-bolt %t.exe -o %t.bolt -use-old-text=0 -lite=0 -trap-old-code
10+
# RUN: llvm-objdump -d --disassemble-symbols='$d' %t.bolt | FileCheck %s
11+
12+
.text
13+
.align 4
14+
.global
15+
.type dummy, %function
16+
dummy:
17+
add x0, x0, #1
18+
ret
19+
20+
.global
21+
.type exitOk, %function
22+
exitOk:
23+
mov x0, #0
24+
ret
25+
26+
.global _start
27+
.type _start, %function
28+
_start:
29+
adrp x0, .Lci
30+
ldr x0, [x0, #:lo12:.Lci]
31+
blr x0
32+
mov x0, #1
33+
ret
34+
nop
35+
# CHECK: {{0|8}} <$d>:
36+
.Lci:
37+
.xword exitOk
38+
.xword 0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This test checks that the constant island value is updated if it
2+
// has dynamic relocation.
3+
4+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \
5+
# RUN: %s -o %t.o
6+
# RUN: %clang %cflags -fPIC -pie %t.o -o %t.exe -Wl,-q -nostdlib -Wl,-z,notext
7+
# RUN: llvm-bolt %t.exe -o %t.bolt -use-old-text=0 -lite=0
8+
# RUN: llvm-objdump -j .text -dR %t.bolt | FileCheck %s
9+
10+
# CHECK: R_AARCH64_RELATIVE *ABS*+0x[[#%x,ADDR:]]
11+
# CHECK: [[#ADDR]] <exitLocal>:
12+
# CHECK: {{.*}} <$d>:
13+
# CHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]]
14+
# CHECK-NEXT: {{.*}} .word 0x00000000
15+
16+
.text
17+
.align 4
18+
.local exitLocal
19+
.type exitLocal, %function
20+
exitLocal:
21+
add x1, x1, #1
22+
add x1, x1, #1
23+
ret
24+
.size exitLocal, .-exitLocal
25+
26+
.global _start
27+
.type _start, %function
28+
_start:
29+
mov x0, #0
30+
adr x1, .Lci
31+
ldr x1, [x1]
32+
blr x1
33+
mov x0, #1
34+
bl exitLocal
35+
nop
36+
.Lci:
37+
.xword exitLocal
38+
.size _start, .-_start

bolt/test/AArch64/double_jump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ unsigned long foo(unsigned long count) {
5252
return count;
5353
}
5454

55-
int main(int argc, const char *argv[]) { return foo(38); }
55+
extern "C" int _start() { return foo(38); }

bolt/test/AArch64/lit.local.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
if config.host_arch not in ['aarch64']:
22
config.unsupported = True
3+
4+
config.substitutions.insert(
5+
0, ('%cflags',
6+
'%cflags --target=aarch64-pc-linux -nostartfiles -nostdlib -fuse-ld=lld'
7+
' -Wl,--unresolved-symbols=ignore-all'))

bolt/test/AArch64/tailcall_traps.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
.text
1919
.align 4
20-
.global main
21-
.type main, %function
22-
main:
20+
.global _start
21+
.type _start, %function
22+
_start:
2323
nop
2424
ret
25-
.size main, .-main
25+
.size _start, .-_start
2626

2727
.global foo
2828
.type foo, %function

bolt/test/AArch64/text-data.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This test checks that the data object located in text section
2+
// is properly emitted in the new section.
3+
4+
// RUN: %clang %cflags %s -o %t.exe -Wl,-q
5+
// RUN: llvm-bolt %t.exe -o %t.bolt -lite=0 -use-old-text=0
6+
// RUN: llvm-objdump -j .text -d --disassemble-symbols=arr %t.bolt | \
7+
// RUN: FileCheck %s
8+
9+
// CHECK: {{.*}} <arr>:
10+
11+
#include <stdlib.h>
12+
13+
typedef void (*FooPtr)();
14+
15+
void exitOk() { exit(0); }
16+
17+
__attribute__((section(".text"))) const FooPtr arr[] = {exitOk, NULL};
18+
19+
int main() {
20+
arr[0]();
21+
return -1;
22+
}

bolt/test/runtime/AArch64/adrrelaxationpass.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ br:
4141
.word 0xff
4242

4343
# CHECK: <main>:
44-
# CHECK-NEXT: adr x0, #28
44+
# CHECK-NEXT: adr x0, #{{[0-9][0-9]*}}
4545
# CHECK-NEXT: adrp x1, 0x{{[1-8a-f][0-9a-f]*}}
4646
# CHECK-NEXT: add x1, x1, #{{[1-8a-f][0-9a-f]*}}
4747
# CHECK-NEXT: adrp x2, 0x{{[1-8a-f][0-9a-f]*}}
4848
# CHECK-NEXT: add x2, x2, #{{[1-8a-f][0-9a-f]*}}
49-
# CHECK-NEXT: adr x3, #4
49+
# CHECK-NEXT: adr x3, #{{[0-9][0-9]*}}

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace bugprone {
2020
namespace {
2121

2222
AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
23-
return Node.getValue().getZExtValue() > N;
23+
return Node.getValue().ugt(N);
2424
}
2525

2626
AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth,

clang-tools-extra/clang-tidy/modernize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_clang_library(clangTidyModernizeModule
1111
DeprecatedIosBaseAliasesCheck.cpp
1212
LoopConvertCheck.cpp
1313
LoopConvertUtils.cpp
14+
MacroToEnumCheck.cpp
1415
MakeSharedCheck.cpp
1516
MakeSmartPtrCheck.cpp
1617
MakeUniqueCheck.cpp

0 commit comments

Comments
 (0)