Skip to content

Commit 97588ae

Browse files
committed
Auto merge of #67759 - nikic:llvm-10, r=<try>
[WIP] Update to LLVM 10 LLVM 10 is going to be branched soon, so it's a good time to start finding all those tasty new miscompiles and performance regressions ;) r? @ghost
2 parents c5840f9 + 26bf168 commit 97588ae

25 files changed

+131
-950
lines changed

.gitmodules

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
url = https://github.com/rust-lang/edition-guide.git
4040
[submodule "src/llvm-project"]
4141
path = src/llvm-project
42-
url = https://github.com/rust-lang/llvm-project.git
43-
branch = rustc/9.0-2019-09-19
42+
url = https://github.com/nikic/llvm-project.git
43+
branch = rustc/10.0-2020-01-03
4444
[submodule "src/doc/embedded-book"]
4545
path = src/doc/embedded-book
4646
url = https://github.com/rust-embedded/book.git

src/libprofiler_builtins/build.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ fn main() {
2121
"InstrProfilingPlatformLinux.c",
2222
"InstrProfilingPlatformOther.c",
2323
"InstrProfilingPlatformWindows.c",
24-
"InstrProfilingRuntime.cc",
2524
"InstrProfilingUtil.c",
2625
"InstrProfilingValue.c",
2726
"InstrProfilingWriter.c",
@@ -68,10 +67,17 @@ fn main() {
6867
let root = env::var_os("RUST_COMPILER_RT_ROOT").unwrap();
6968
let root = Path::new(&root);
7069

70+
let src_root = root.join("lib").join("profile");
7171
for src in profile_sources {
72-
cfg.file(root.join("lib").join("profile").join(src));
72+
cfg.file(src_root.join(src));
7373
}
7474

75+
// The file was renamed in LLVM 10.
76+
let old_runtime_path = src_root.join("InstrProfilingRuntime.cc");
77+
let new_runtime_path = src_root.join("InstrProfilingRuntime.cpp");
78+
cfg.file(if old_runtime_path.exists() { old_runtime_path } else { new_runtime_path });
79+
80+
cfg.include(root.join("include"));
7581
cfg.warnings(false);
7682
cfg.compile("profiler-rt");
7783
}

src/librustc_codegen_llvm/context.rs

+23
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ fn strip_function_ptr_alignment(data_layout: String) -> String {
143143
data_layout.replace("-Fi8-", "-")
144144
}
145145

146+
fn strip_x86_address_spaces(data_layout: String) -> String {
147+
data_layout.replace("-p270:32:32-p271:32:32-p272:64:64-", "-")
148+
}
149+
150+
fn add_x86_address_spaces(mut data_layout: String) -> String {
151+
let address_spaces = "-p270:32:32-p271:32:32-p272:64:64";
152+
if !data_layout.contains(address_spaces) && data_layout.starts_with("e-m:") {
153+
let mut insert_pos = "e-m:?".len();
154+
if data_layout[insert_pos..].starts_with("-p:32:32") {
155+
insert_pos += "-p:32:32".len();
156+
}
157+
data_layout.insert_str(insert_pos, address_spaces);
158+
}
159+
data_layout
160+
}
161+
146162
pub unsafe fn create_module(
147163
tcx: TyCtxt<'_>,
148164
llcx: &'ll llvm::Context,
@@ -156,6 +172,13 @@ pub unsafe fn create_module(
156172
if llvm_util::get_major_version() < 9 {
157173
target_data_layout = strip_function_ptr_alignment(target_data_layout);
158174
}
175+
if sess.target.target.arch == "x86" || sess.target.target.arch == "x86_64" {
176+
if llvm_util::get_major_version() < 10 {
177+
target_data_layout = strip_x86_address_spaces(target_data_layout);
178+
} else {
179+
target_data_layout = add_x86_address_spaces(target_data_layout);
180+
}
181+
}
159182

160183
// Ensure the data-layout values hardcoded remain the defaults.
161184
if sess.target.target.options.is_builtin {

src/llvm-project

Submodule llvm-project updated 26711 files

src/rustllvm/ArchiveWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ extern "C" void LLVMRustDestroyArchive(LLVMRustArchiveRef RustArchive) {
8989
extern "C" LLVMRustArchiveIteratorRef
9090
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef RustArchive) {
9191
Archive *Archive = RustArchive->getBinary();
92+
#if LLVM_VERSION_GE(10, 0)
93+
std::unique_ptr<Error> Err = std::make_unique<Error>(Error::success());
94+
#else
9295
std::unique_ptr<Error> Err = llvm::make_unique<Error>(Error::success());
96+
#endif
9397
auto Cur = Archive->child_begin(*Err);
9498
if (*Err) {
9599
LLVMRustSetLastError(toString(std::move(*Err)).c_str());

src/rustllvm/Linker.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ extern "C" RustLinker*
1818
LLVMRustLinkerNew(LLVMModuleRef DstRef) {
1919
Module *Dst = unwrap(DstRef);
2020

21-
auto Ret = llvm::make_unique<RustLinker>(*Dst);
22-
return Ret.release();
21+
return new RustLinker(*Dst);
2322
}
2423

2524
extern "C" void

src/rustllvm/PassWrapper.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "llvm/Analysis/TargetLibraryInfo.h"
99
#include "llvm/Analysis/TargetTransformInfo.h"
1010
#include "llvm/CodeGen/TargetSubtargetInfo.h"
11+
#include "llvm/InitializePasses.h"
1112
#include "llvm/IR/AutoUpgrade.h"
1213
#include "llvm/IR/AssemblyAnnotationWriter.h"
1314
#include "llvm/IR/IntrinsicInst.h"
@@ -532,6 +533,18 @@ enum class LLVMRustFileType {
532533
ObjectFile,
533534
};
534535

536+
#if LLVM_VERSION_GE(10, 0)
537+
static CodeGenFileType fromRust(LLVMRustFileType Type) {
538+
switch (Type) {
539+
case LLVMRustFileType::AssemblyFile:
540+
return CGFT_AssemblyFile;
541+
case LLVMRustFileType::ObjectFile:
542+
return CGFT_ObjectFile;
543+
default:
544+
report_fatal_error("Bad FileType.");
545+
}
546+
}
547+
#else
535548
static TargetMachine::CodeGenFileType fromRust(LLVMRustFileType Type) {
536549
switch (Type) {
537550
case LLVMRustFileType::AssemblyFile:
@@ -542,6 +555,7 @@ static TargetMachine::CodeGenFileType fromRust(LLVMRustFileType Type) {
542555
report_fatal_error("Bad FileType.");
543556
}
544557
}
558+
#endif
545559

546560
extern "C" LLVMRustResult
547561
LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
@@ -849,7 +863,11 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
849863
int num_modules,
850864
const char **preserved_symbols,
851865
int num_symbols) {
866+
#if LLVM_VERSION_GE(10, 0)
867+
auto Ret = std::make_unique<LLVMRustThinLTOData>();
868+
#else
852869
auto Ret = llvm::make_unique<LLVMRustThinLTOData>();
870+
#endif
853871

854872
// Load each module's summary and merge it into one combined index
855873
for (int i = 0; i < num_modules; i++) {
@@ -944,13 +962,23 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
944962
ExportedGUIDs.insert(GUID);
945963
}
946964
}
965+
#if LLVM_VERSION_GE(10, 0)
966+
auto isExported = [&](StringRef ModuleIdentifier, ValueInfo VI) {
967+
const auto &ExportList = Ret->ExportLists.find(ModuleIdentifier);
968+
return (ExportList != Ret->ExportLists.end() &&
969+
ExportList->second.count(VI)) ||
970+
ExportedGUIDs.count(VI.getGUID());
971+
};
972+
thinLTOInternalizeAndPromoteInIndex(Ret->Index, isExported, isPrevailing);
973+
#else
947974
auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
948975
const auto &ExportList = Ret->ExportLists.find(ModuleIdentifier);
949976
return (ExportList != Ret->ExportLists.end() &&
950977
ExportList->second.count(GUID)) ||
951978
ExportedGUIDs.count(GUID);
952979
};
953980
thinLTOInternalizeAndPromoteInIndex(Ret->Index, isExported);
981+
#endif
954982

955983
return Ret.release();
956984
}
@@ -1081,7 +1109,11 @@ struct LLVMRustThinLTOBuffer {
10811109

10821110
extern "C" LLVMRustThinLTOBuffer*
10831111
LLVMRustThinLTOBufferCreate(LLVMModuleRef M) {
1112+
#if LLVM_VERSION_GE(10, 0)
1113+
auto Ret = std::make_unique<LLVMRustThinLTOBuffer>();
1114+
#else
10841115
auto Ret = llvm::make_unique<LLVMRustThinLTOBuffer>();
1116+
#endif
10851117
{
10861118
raw_string_ostream OS(Ret->data);
10871119
{

src/rustllvm/RustWrapper.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,11 @@ static DINode::DIFlags fromRust(LLVMRustDIFlags Flags) {
496496
if (isSet(Flags & LLVMRustDIFlags::FlagAppleBlock)) {
497497
Result |= DINode::DIFlags::FlagAppleBlock;
498498
}
499+
#if LLVM_VERSION_LT(10, 0)
499500
if (isSet(Flags & LLVMRustDIFlags::FlagBlockByrefStruct)) {
500501
Result |= DINode::DIFlags::FlagBlockByrefStruct;
501502
}
503+
#endif
502504
if (isSet(Flags & LLVMRustDIFlags::FlagVirtual)) {
503505
Result |= DINode::DIFlags::FlagVirtual;
504506
}
@@ -825,6 +827,9 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable(
825827
llvm::DIGlobalVariableExpression *VarExpr = Builder->createGlobalVariableExpression(
826828
unwrapDI<DIDescriptor>(Context), Name, LinkageName,
827829
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit,
830+
#if LLVM_VERSION_GE(10, 0)
831+
/* isDefined */ true,
832+
#endif
828833
InitExpr, unwrapDIPtr<MDNode>(Decl),
829834
#if LLVM_VERSION_GE(8, 0)
830835
/* templateParams */ nullptr,
@@ -998,11 +1003,19 @@ inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
9981003

9991004
extern "C" size_t LLVMRustGetSectionName(LLVMSectionIteratorRef SI,
10001005
const char **Ptr) {
1006+
#if LLVM_VERSION_GE(10, 0)
1007+
auto NameOrErr = (*unwrap(SI))->getName();
1008+
if (!NameOrErr)
1009+
report_fatal_error(NameOrErr.takeError());
1010+
*Ptr = NameOrErr->data();
1011+
return NameOrErr->size();
1012+
#else
10011013
StringRef Ret;
10021014
if (std::error_code EC = (*unwrap(SI))->getName(Ret))
10031015
report_fatal_error(EC.message());
10041016
*Ptr = Ret.data();
10051017
return Ret.size();
1018+
#endif
10061019
}
10071020

10081021
// LLVMArrayType function does not support 64-bit ElementCount
@@ -1253,20 +1266,34 @@ extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B,
12531266
LLVMValueRef Dst, unsigned DstAlign,
12541267
LLVMValueRef Src, unsigned SrcAlign,
12551268
LLVMValueRef Size, bool IsVolatile) {
1269+
#if LLVM_VERSION_GE(10, 0)
1270+
return wrap(unwrap(B)->CreateMemCpy(
1271+
unwrap(Dst), MaybeAlign(DstAlign),
1272+
unwrap(Src), MaybeAlign(SrcAlign),
1273+
unwrap(Size), IsVolatile));
1274+
#else
12561275
return wrap(unwrap(B)->CreateMemCpy(
12571276
unwrap(Dst), DstAlign,
12581277
unwrap(Src), SrcAlign,
12591278
unwrap(Size), IsVolatile));
1279+
#endif
12601280
}
12611281

12621282
extern "C" LLVMValueRef LLVMRustBuildMemMove(LLVMBuilderRef B,
12631283
LLVMValueRef Dst, unsigned DstAlign,
12641284
LLVMValueRef Src, unsigned SrcAlign,
12651285
LLVMValueRef Size, bool IsVolatile) {
1286+
#if LLVM_VERSION_GE(10, 0)
1287+
return wrap(unwrap(B)->CreateMemMove(
1288+
unwrap(Dst), MaybeAlign(DstAlign),
1289+
unwrap(Src), MaybeAlign(SrcAlign),
1290+
unwrap(Size), IsVolatile));
1291+
#else
12661292
return wrap(unwrap(B)->CreateMemMove(
12671293
unwrap(Dst), DstAlign,
12681294
unwrap(Src), SrcAlign,
12691295
unwrap(Size), IsVolatile));
1296+
#endif
12701297
}
12711298

12721299
extern "C" LLVMValueRef
@@ -1450,7 +1477,11 @@ struct LLVMRustModuleBuffer {
14501477

14511478
extern "C" LLVMRustModuleBuffer*
14521479
LLVMRustModuleBufferCreate(LLVMModuleRef M) {
1480+
#if LLVM_VERSION_GE(10, 0)
1481+
auto Ret = std::make_unique<LLVMRustModuleBuffer>();
1482+
#else
14531483
auto Ret = llvm::make_unique<LLVMRustModuleBuffer>();
1484+
#endif
14541485
{
14551486
raw_string_ostream OS(Ret->data);
14561487
{

src/test/codegen/abi-main-signature-32bit-c-int.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
fn main() {
88
}
99

10-
// CHECK: define i32 @main(i32, i8**)
10+
// CHECK: define i32 @main(i32{{( %0)?}}, i8**{{( %1)?}})

src/test/codegen/bool-cmp.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use std::cmp::Ordering;
1010
// CHECK-LABEL: @cmp_bool
1111
#[no_mangle]
1212
pub fn cmp_bool(a: bool, b: bool) -> Ordering {
13+
// LLVM 10 produces (zext a) + (sext b), but the final lowering is (zext a) - (zext b).
1314
// CHECK: zext i1
14-
// CHECK: zext i1
15-
// CHECK: sub nsw
15+
// CHECK: {{z|s}}ext i1
16+
// CHECK: {{sub|add}} nsw
1617
a.cmp(&b)
1718
}

src/test/codegen/function-arguments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn _box(x: Box<i32>) -> Box<i32> {
7373
x
7474
}
7575

76-
// CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
76+
// CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32){{( %0)?}})
7777
#[no_mangle]
7878
pub fn struct_return() -> S {
7979
S {
@@ -117,7 +117,7 @@ pub fn str(_: &[u8]) {
117117
pub fn trait_borrow(_: &Drop) {
118118
}
119119

120-
// CHECK: @trait_box({}* noalias nonnull align 1, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}))
120+
// CHECK: @trait_box({}* noalias nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
121121
#[no_mangle]
122122
pub fn trait_box(_: Box<Drop>) {
123123
}

src/test/codegen/intrinsics/prefetch.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,55 @@ use std::intrinsics::{prefetch_read_data, prefetch_write_data,
99
#[no_mangle]
1010
pub fn check_prefetch_read_data(data: &[i8]) {
1111
unsafe {
12-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 1)
12+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 0, i32 1)
1313
prefetch_read_data(data.as_ptr(), 0);
14-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 1)
14+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 1, i32 1)
1515
prefetch_read_data(data.as_ptr(), 1);
16-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 1)
16+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 2, i32 1)
1717
prefetch_read_data(data.as_ptr(), 2);
18-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 1)
18+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 3, i32 1)
1919
prefetch_read_data(data.as_ptr(), 3);
2020
}
2121
}
2222

2323
#[no_mangle]
2424
pub fn check_prefetch_write_data(data: &[i8]) {
2525
unsafe {
26-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 1)
26+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 0, i32 1)
2727
prefetch_write_data(data.as_ptr(), 0);
28-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 1)
28+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 1, i32 1)
2929
prefetch_write_data(data.as_ptr(), 1);
30-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 1)
30+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 2, i32 1)
3131
prefetch_write_data(data.as_ptr(), 2);
32-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 1)
32+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 3, i32 1)
3333
prefetch_write_data(data.as_ptr(), 3);
3434
}
3535
}
3636

3737
#[no_mangle]
3838
pub fn check_prefetch_read_instruction(data: &[i8]) {
3939
unsafe {
40-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 0)
40+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 0, i32 0)
4141
prefetch_read_instruction(data.as_ptr(), 0);
42-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 0)
42+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 1, i32 0)
4343
prefetch_read_instruction(data.as_ptr(), 1);
44-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 0)
44+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 2, i32 0)
4545
prefetch_read_instruction(data.as_ptr(), 2);
46-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 0)
46+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 3, i32 0)
4747
prefetch_read_instruction(data.as_ptr(), 3);
4848
}
4949
}
5050

5151
#[no_mangle]
5252
pub fn check_prefetch_write_instruction(data: &[i8]) {
5353
unsafe {
54-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 0)
54+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 0, i32 0)
5555
prefetch_write_instruction(data.as_ptr(), 0);
56-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 0)
56+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 1, i32 0)
5757
prefetch_write_instruction(data.as_ptr(), 1);
58-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 0)
58+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 2, i32 0)
5959
prefetch_write_instruction(data.as_ptr(), 2);
60-
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0)
60+
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 3, i32 0)
6161
prefetch_write_instruction(data.as_ptr(), 3);
6262
}
6363
}

src/test/codegen/issue-45222.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// compile-flags: -O
22
// ignore-debug: the debug assertions get in the way
3+
// ignore-test: Codegen regression in LLVM 10
34

45
#![crate_type = "lib"]
56

0 commit comments

Comments
 (0)