Skip to content

Commit

Permalink
Auto merge of #67759 - nikic:llvm-10, r=<try>
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
bors committed Jan 3, 2020
2 parents c5840f9 + 26bf168 commit 97588ae
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 950 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
url = https://github.com/rust-lang/edition-guide.git
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
branch = rustc/9.0-2019-09-19
url = https://github.com/nikic/llvm-project.git
branch = rustc/10.0-2020-01-03
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
url = https://github.com/rust-embedded/book.git
10 changes: 8 additions & 2 deletions src/libprofiler_builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ fn main() {
"InstrProfilingPlatformLinux.c",
"InstrProfilingPlatformOther.c",
"InstrProfilingPlatformWindows.c",
"InstrProfilingRuntime.cc",
"InstrProfilingUtil.c",
"InstrProfilingValue.c",
"InstrProfilingWriter.c",
Expand Down Expand Up @@ -68,10 +67,17 @@ fn main() {
let root = env::var_os("RUST_COMPILER_RT_ROOT").unwrap();
let root = Path::new(&root);

let src_root = root.join("lib").join("profile");
for src in profile_sources {
cfg.file(root.join("lib").join("profile").join(src));
cfg.file(src_root.join(src));
}

// The file was renamed in LLVM 10.
let old_runtime_path = src_root.join("InstrProfilingRuntime.cc");
let new_runtime_path = src_root.join("InstrProfilingRuntime.cpp");
cfg.file(if old_runtime_path.exists() { old_runtime_path } else { new_runtime_path });

cfg.include(root.join("include"));
cfg.warnings(false);
cfg.compile("profiler-rt");
}
23 changes: 23 additions & 0 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ fn strip_function_ptr_alignment(data_layout: String) -> String {
data_layout.replace("-Fi8-", "-")
}

fn strip_x86_address_spaces(data_layout: String) -> String {
data_layout.replace("-p270:32:32-p271:32:32-p272:64:64-", "-")
}

fn add_x86_address_spaces(mut data_layout: String) -> String {
let address_spaces = "-p270:32:32-p271:32:32-p272:64:64";
if !data_layout.contains(address_spaces) && data_layout.starts_with("e-m:") {
let mut insert_pos = "e-m:?".len();
if data_layout[insert_pos..].starts_with("-p:32:32") {
insert_pos += "-p:32:32".len();
}
data_layout.insert_str(insert_pos, address_spaces);
}
data_layout
}

pub unsafe fn create_module(
tcx: TyCtxt<'_>,
llcx: &'ll llvm::Context,
Expand All @@ -156,6 +172,13 @@ pub unsafe fn create_module(
if llvm_util::get_major_version() < 9 {
target_data_layout = strip_function_ptr_alignment(target_data_layout);
}
if sess.target.target.arch == "x86" || sess.target.target.arch == "x86_64" {
if llvm_util::get_major_version() < 10 {
target_data_layout = strip_x86_address_spaces(target_data_layout);
} else {
target_data_layout = add_x86_address_spaces(target_data_layout);
}
}

// Ensure the data-layout values hardcoded remain the defaults.
if sess.target.target.options.is_builtin {
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-project
Submodule llvm-project updated 26711 files
4 changes: 4 additions & 0 deletions src/rustllvm/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ extern "C" void LLVMRustDestroyArchive(LLVMRustArchiveRef RustArchive) {
extern "C" LLVMRustArchiveIteratorRef
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef RustArchive) {
Archive *Archive = RustArchive->getBinary();
#if LLVM_VERSION_GE(10, 0)
std::unique_ptr<Error> Err = std::make_unique<Error>(Error::success());
#else
std::unique_ptr<Error> Err = llvm::make_unique<Error>(Error::success());
#endif
auto Cur = Archive->child_begin(*Err);
if (*Err) {
LLVMRustSetLastError(toString(std::move(*Err)).c_str());
Expand Down
3 changes: 1 addition & 2 deletions src/rustllvm/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ extern "C" RustLinker*
LLVMRustLinkerNew(LLVMModuleRef DstRef) {
Module *Dst = unwrap(DstRef);

auto Ret = llvm::make_unique<RustLinker>(*Dst);
return Ret.release();
return new RustLinker(*Dst);
}

extern "C" void
Expand Down
32 changes: 32 additions & 0 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/IntrinsicInst.h"
Expand Down Expand Up @@ -532,6 +533,18 @@ enum class LLVMRustFileType {
ObjectFile,
};

#if LLVM_VERSION_GE(10, 0)
static CodeGenFileType fromRust(LLVMRustFileType Type) {
switch (Type) {
case LLVMRustFileType::AssemblyFile:
return CGFT_AssemblyFile;
case LLVMRustFileType::ObjectFile:
return CGFT_ObjectFile;
default:
report_fatal_error("Bad FileType.");
}
}
#else
static TargetMachine::CodeGenFileType fromRust(LLVMRustFileType Type) {
switch (Type) {
case LLVMRustFileType::AssemblyFile:
Expand All @@ -542,6 +555,7 @@ static TargetMachine::CodeGenFileType fromRust(LLVMRustFileType Type) {
report_fatal_error("Bad FileType.");
}
}
#endif

extern "C" LLVMRustResult
LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
Expand Down Expand Up @@ -849,7 +863,11 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
int num_modules,
const char **preserved_symbols,
int num_symbols) {
#if LLVM_VERSION_GE(10, 0)
auto Ret = std::make_unique<LLVMRustThinLTOData>();
#else
auto Ret = llvm::make_unique<LLVMRustThinLTOData>();
#endif

// Load each module's summary and merge it into one combined index
for (int i = 0; i < num_modules; i++) {
Expand Down Expand Up @@ -944,13 +962,23 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
ExportedGUIDs.insert(GUID);
}
}
#if LLVM_VERSION_GE(10, 0)
auto isExported = [&](StringRef ModuleIdentifier, ValueInfo VI) {
const auto &ExportList = Ret->ExportLists.find(ModuleIdentifier);
return (ExportList != Ret->ExportLists.end() &&
ExportList->second.count(VI)) ||
ExportedGUIDs.count(VI.getGUID());
};
thinLTOInternalizeAndPromoteInIndex(Ret->Index, isExported, isPrevailing);
#else
auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
const auto &ExportList = Ret->ExportLists.find(ModuleIdentifier);
return (ExportList != Ret->ExportLists.end() &&
ExportList->second.count(GUID)) ||
ExportedGUIDs.count(GUID);
};
thinLTOInternalizeAndPromoteInIndex(Ret->Index, isExported);
#endif

return Ret.release();
}
Expand Down Expand Up @@ -1081,7 +1109,11 @@ struct LLVMRustThinLTOBuffer {

extern "C" LLVMRustThinLTOBuffer*
LLVMRustThinLTOBufferCreate(LLVMModuleRef M) {
#if LLVM_VERSION_GE(10, 0)
auto Ret = std::make_unique<LLVMRustThinLTOBuffer>();
#else
auto Ret = llvm::make_unique<LLVMRustThinLTOBuffer>();
#endif
{
raw_string_ostream OS(Ret->data);
{
Expand Down
31 changes: 31 additions & 0 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,11 @@ static DINode::DIFlags fromRust(LLVMRustDIFlags Flags) {
if (isSet(Flags & LLVMRustDIFlags::FlagAppleBlock)) {
Result |= DINode::DIFlags::FlagAppleBlock;
}
#if LLVM_VERSION_LT(10, 0)
if (isSet(Flags & LLVMRustDIFlags::FlagBlockByrefStruct)) {
Result |= DINode::DIFlags::FlagBlockByrefStruct;
}
#endif
if (isSet(Flags & LLVMRustDIFlags::FlagVirtual)) {
Result |= DINode::DIFlags::FlagVirtual;
}
Expand Down Expand Up @@ -825,6 +827,9 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable(
llvm::DIGlobalVariableExpression *VarExpr = Builder->createGlobalVariableExpression(
unwrapDI<DIDescriptor>(Context), Name, LinkageName,
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit,
#if LLVM_VERSION_GE(10, 0)
/* isDefined */ true,
#endif
InitExpr, unwrapDIPtr<MDNode>(Decl),
#if LLVM_VERSION_GE(8, 0)
/* templateParams */ nullptr,
Expand Down Expand Up @@ -998,11 +1003,19 @@ inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {

extern "C" size_t LLVMRustGetSectionName(LLVMSectionIteratorRef SI,
const char **Ptr) {
#if LLVM_VERSION_GE(10, 0)
auto NameOrErr = (*unwrap(SI))->getName();
if (!NameOrErr)
report_fatal_error(NameOrErr.takeError());
*Ptr = NameOrErr->data();
return NameOrErr->size();
#else
StringRef Ret;
if (std::error_code EC = (*unwrap(SI))->getName(Ret))
report_fatal_error(EC.message());
*Ptr = Ret.data();
return Ret.size();
#endif
}

// LLVMArrayType function does not support 64-bit ElementCount
Expand Down Expand Up @@ -1253,20 +1266,34 @@ extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B,
LLVMValueRef Dst, unsigned DstAlign,
LLVMValueRef Src, unsigned SrcAlign,
LLVMValueRef Size, bool IsVolatile) {
#if LLVM_VERSION_GE(10, 0)
return wrap(unwrap(B)->CreateMemCpy(
unwrap(Dst), MaybeAlign(DstAlign),
unwrap(Src), MaybeAlign(SrcAlign),
unwrap(Size), IsVolatile));
#else
return wrap(unwrap(B)->CreateMemCpy(
unwrap(Dst), DstAlign,
unwrap(Src), SrcAlign,
unwrap(Size), IsVolatile));
#endif
}

extern "C" LLVMValueRef LLVMRustBuildMemMove(LLVMBuilderRef B,
LLVMValueRef Dst, unsigned DstAlign,
LLVMValueRef Src, unsigned SrcAlign,
LLVMValueRef Size, bool IsVolatile) {
#if LLVM_VERSION_GE(10, 0)
return wrap(unwrap(B)->CreateMemMove(
unwrap(Dst), MaybeAlign(DstAlign),
unwrap(Src), MaybeAlign(SrcAlign),
unwrap(Size), IsVolatile));
#else
return wrap(unwrap(B)->CreateMemMove(
unwrap(Dst), DstAlign,
unwrap(Src), SrcAlign,
unwrap(Size), IsVolatile));
#endif
}

extern "C" LLVMValueRef
Expand Down Expand Up @@ -1450,7 +1477,11 @@ struct LLVMRustModuleBuffer {

extern "C" LLVMRustModuleBuffer*
LLVMRustModuleBufferCreate(LLVMModuleRef M) {
#if LLVM_VERSION_GE(10, 0)
auto Ret = std::make_unique<LLVMRustModuleBuffer>();
#else
auto Ret = llvm::make_unique<LLVMRustModuleBuffer>();
#endif
{
raw_string_ostream OS(Ret->data);
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/abi-main-signature-32bit-c-int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
fn main() {
}

// CHECK: define i32 @main(i32, i8**)
// CHECK: define i32 @main(i32{{( %0)?}}, i8**{{( %1)?}})
5 changes: 3 additions & 2 deletions src/test/codegen/bool-cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use std::cmp::Ordering;
// CHECK-LABEL: @cmp_bool
#[no_mangle]
pub fn cmp_bool(a: bool, b: bool) -> Ordering {
// LLVM 10 produces (zext a) + (sext b), but the final lowering is (zext a) - (zext b).
// CHECK: zext i1
// CHECK: zext i1
// CHECK: sub nsw
// CHECK: {{z|s}}ext i1
// CHECK: {{sub|add}} nsw
a.cmp(&b)
}
4 changes: 2 additions & 2 deletions src/test/codegen/function-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn _box(x: Box<i32>) -> Box<i32> {
x
}

// CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
// CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32){{( %0)?}})
#[no_mangle]
pub fn struct_return() -> S {
S {
Expand Down Expand Up @@ -117,7 +117,7 @@ pub fn str(_: &[u8]) {
pub fn trait_borrow(_: &Drop) {
}

// CHECK: @trait_box({}* noalias nonnull align 1, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}))
// CHECK: @trait_box({}* noalias nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
#[no_mangle]
pub fn trait_box(_: Box<Drop>) {
}
Expand Down
32 changes: 16 additions & 16 deletions src/test/codegen/intrinsics/prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,55 @@ use std::intrinsics::{prefetch_read_data, prefetch_write_data,
#[no_mangle]
pub fn check_prefetch_read_data(data: &[i8]) {
unsafe {
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 1)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 0, i32 1)
prefetch_read_data(data.as_ptr(), 0);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 1)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 1, i32 1)
prefetch_read_data(data.as_ptr(), 1);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 1)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 2, i32 1)
prefetch_read_data(data.as_ptr(), 2);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 1)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 3, i32 1)
prefetch_read_data(data.as_ptr(), 3);
}
}

#[no_mangle]
pub fn check_prefetch_write_data(data: &[i8]) {
unsafe {
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 1)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 0, i32 1)
prefetch_write_data(data.as_ptr(), 0);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 1)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 1, i32 1)
prefetch_write_data(data.as_ptr(), 1);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 1)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 2, i32 1)
prefetch_write_data(data.as_ptr(), 2);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 1)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 3, i32 1)
prefetch_write_data(data.as_ptr(), 3);
}
}

#[no_mangle]
pub fn check_prefetch_read_instruction(data: &[i8]) {
unsafe {
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 0)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 0, i32 0)
prefetch_read_instruction(data.as_ptr(), 0);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 0)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 1, i32 0)
prefetch_read_instruction(data.as_ptr(), 1);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 0)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 2, i32 0)
prefetch_read_instruction(data.as_ptr(), 2);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 0)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 0, i32 3, i32 0)
prefetch_read_instruction(data.as_ptr(), 3);
}
}

#[no_mangle]
pub fn check_prefetch_write_instruction(data: &[i8]) {
unsafe {
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 0)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 0, i32 0)
prefetch_write_instruction(data.as_ptr(), 0);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 0)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 1, i32 0)
prefetch_write_instruction(data.as_ptr(), 1);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 0)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 2, i32 0)
prefetch_write_instruction(data.as_ptr(), 2);
// CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0)
// CHECK: call void @llvm.prefetch{{.*}}(i8* %{{.*}}, i32 1, i32 3, i32 0)
prefetch_write_instruction(data.as_ptr(), 3);
}
}
1 change: 1 addition & 0 deletions src/test/codegen/issue-45222.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// compile-flags: -O
// ignore-debug: the debug assertions get in the way
// ignore-test: Codegen regression in LLVM 10

#![crate_type = "lib"]

Expand Down
Loading

0 comments on commit 97588ae

Please sign in to comment.