Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the minimum external LLVM to 16. #117947

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: mingw-check-tidy
os: ubuntu-20.04-4core-16gb
env: {}
- name: x86_64-gnu-llvm-15
- name: x86_64-gnu-llvm-16
env:
ENABLE_GCC_CODEGEN: "1"
os: ubuntu-20.04-16core-64gb
Expand Down Expand Up @@ -302,10 +302,6 @@ jobs:
env:
RUST_BACKTRACE: 1
os: ubuntu-20.04-8core-32gb
- name: x86_64-gnu-llvm-15
env:
RUST_BACKTRACE: 1
os: ubuntu-20.04-8core-32gb
- name: x86_64-gnu-nopt
os: ubuntu-20.04-4core-16gb
env: {}
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@ pub unsafe fn create_module<'ll>(

let mut target_data_layout = sess.target.data_layout.to_string();
let llvm_version = llvm_util::get_version();
if llvm_version < (16, 0, 0) {
if sess.target.arch == "s390x" {
// LLVM 16 data layout changed to always set 64-bit vector alignment,
// which is conditional in earlier LLVM versions.
// https://reviews.llvm.org/D131158 for the discussion.
target_data_layout = target_data_layout.replace("-v128:64", "");
} else if sess.target.arch == "riscv64" {
// LLVM 16 introduced this change so as to produce more efficient code.
// See https://reviews.llvm.org/D116735 for the discussion.
target_data_layout = target_data_layout.replace("-n32:64-", "-n64-");
}
}
if llvm_version < (17, 0, 0) {
if sess.target.arch.starts_with("powerpc") {
// LLVM 17 specifies function pointer alignment for ppc:
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/Linker/Linker.h"

#if LLVM_VERSION_GE(16, 0)
#include "llvm/TargetParser/Triple.h"
#else
#include "llvm/ADT/Triple.h"
#endif

extern "C" void LLVMRustSetLastError(const char *);

Expand Down
27 changes: 0 additions & 27 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ enum class LLVMRustCodeModel {
None,
};

#if LLVM_VERSION_LT(16, 0)
static Optional<CodeModel::Model>
#else
static std::optional<CodeModel::Model>
#endif
fromRust(LLVMRustCodeModel Model) {
switch (Model) {
case LLVMRustCodeModel::Tiny:
Expand All @@ -222,11 +218,7 @@ fromRust(LLVMRustCodeModel Model) {
case LLVMRustCodeModel::Large:
return CodeModel::Large;
case LLVMRustCodeModel::None:
#if LLVM_VERSION_LT(16, 0)
return None;
#else
return std::nullopt;
#endif
default:
report_fatal_error("Bad CodeModel.");
}
Expand Down Expand Up @@ -452,15 +444,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
if (OutputObjFile) {
Options.ObjectFilenameForDebug = OutputObjFile;
}
#if LLVM_VERSION_GE(16, 0)
if (!strcmp("zlib", DebugInfoCompression) && llvm::compression::zlib::isAvailable()) {
Options.CompressDebugSections = DebugCompressionType::Zlib;
} else if (!strcmp("zstd", DebugInfoCompression) && llvm::compression::zstd::isAvailable()) {
Options.CompressDebugSections = DebugCompressionType::Zstd;
} else if (!strcmp("none", DebugInfoCompression)) {
Options.CompressDebugSections = DebugCompressionType::None;
}
#endif

Options.RelaxELFRelocations = RelaxELFRelocations;
Options.UseInitArray = UseInitArray;
Expand Down Expand Up @@ -734,22 +724,14 @@ LLVMRustOptimize(
bool DebugPassManager = false;

PassInstrumentationCallbacks PIC;
#if LLVM_VERSION_LT(16, 0)
StandardInstrumentations SI(DebugPassManager);
#else
StandardInstrumentations SI(TheModule->getContext(), DebugPassManager);
#endif
SI.registerCallbacks(PIC);

if (LlvmSelfProfiler){
LLVMSelfProfileInitializeCallbacks(PIC,LlvmSelfProfiler,BeforePassCallback,AfterPassCallback);
}

#if LLVM_VERSION_LT(16, 0)
Optional<PGOOptions> PGOOpt;
#else
std::optional<PGOOptions> PGOOpt;
#endif
#if LLVM_VERSION_GE(17, 0)
auto FS = vfs::getRealFileSystem();
#endif
Expand Down Expand Up @@ -882,12 +864,7 @@ LLVMRustOptimize(
/*EagerChecks=*/true);
OptimizerLastEPCallbacks.push_back(
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
#if LLVM_VERSION_LT(16, 0)
MPM.addPass(ModuleMemorySanitizerPass(Options));
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
#else
MPM.addPass(MemorySanitizerPass(Options));
#endif
}
);
}
Expand All @@ -912,11 +889,7 @@ LLVMRustOptimize(
/*UseAfterScope=*/true,
AsanDetectStackUseAfterReturnMode::Runtime,
};
#if LLVM_VERSION_LT(16, 0)
MPM.addPass(ModuleAddressSanitizerPass(opts));
#else
MPM.addPass(AddressSanitizerPass(opts));
#endif
}
);
}
Expand Down
51 changes: 1 addition & 50 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@
#include "llvm/Remarks/RemarkSerializer.h"
#include "llvm/Remarks/RemarkFormat.h"
#include "llvm/Support/ToolOutputFile.h"
#if LLVM_VERSION_GE(16, 0)
#include "llvm/Support/ModRef.h"
#endif
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFFImportFile.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Pass.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/Support/Signals.h"
#if LLVM_VERSION_LT(16, 0)
#include "llvm/ADT/Optional.h"
#endif

#include <iostream>

Expand Down Expand Up @@ -347,13 +342,7 @@ extern "C" LLVMAttributeRef LLVMRustCreateUWTableAttr(LLVMContextRef C, bool Asy
}

extern "C" LLVMAttributeRef LLVMRustCreateAllocSizeAttr(LLVMContextRef C, uint32_t ElementSizeArg) {
return wrap(Attribute::getWithAllocSizeArgs(*unwrap(C), ElementSizeArg,
#if LLVM_VERSION_LT(16, 0)
None
#else
std::nullopt
#endif
));
return wrap(Attribute::getWithAllocSizeArgs(*unwrap(C), ElementSizeArg, std::nullopt));
}

// These values **must** match ffi::AllocKindFlags.
Expand Down Expand Up @@ -416,7 +405,6 @@ enum class LLVMRustMemoryEffects {

extern "C" LLVMAttributeRef LLVMRustCreateMemoryEffectsAttr(LLVMContextRef C,
LLVMRustMemoryEffects Effects) {
#if LLVM_VERSION_GE(16, 0)
switch (Effects) {
case LLVMRustMemoryEffects::None:
return wrap(Attribute::getWithMemoryEffects(*unwrap(C), MemoryEffects::none()));
Expand All @@ -428,18 +416,6 @@ extern "C" LLVMAttributeRef LLVMRustCreateMemoryEffectsAttr(LLVMContextRef C,
default:
report_fatal_error("bad MemoryEffects.");
}
#else
switch (Effects) {
case LLVMRustMemoryEffects::None:
return wrap(Attribute::get(*unwrap(C), Attribute::ReadNone));
case LLVMRustMemoryEffects::ReadOnly:
return wrap(Attribute::get(*unwrap(C), Attribute::ReadOnly));
case LLVMRustMemoryEffects::InaccessibleMemOnly:
return wrap(Attribute::get(*unwrap(C), Attribute::InaccessibleMemOnly));
default:
report_fatal_error("bad MemoryEffects.");
}
#endif
}

// Enable a fast-math flag
Expand Down Expand Up @@ -726,18 +702,10 @@ enum class LLVMRustChecksumKind {
SHA256,
};

#if LLVM_VERSION_LT(16, 0)
static Optional<DIFile::ChecksumKind> fromRust(LLVMRustChecksumKind Kind) {
#else
static std::optional<DIFile::ChecksumKind> fromRust(LLVMRustChecksumKind Kind) {
#endif
switch (Kind) {
case LLVMRustChecksumKind::None:
#if LLVM_VERSION_LT(16, 0)
return None;
#else
return std::nullopt;
#endif
case LLVMRustChecksumKind::MD5:
return DIFile::ChecksumKind::CSK_MD5;
case LLVMRustChecksumKind::SHA1:
Expand Down Expand Up @@ -810,17 +778,8 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile(
const char *Directory, size_t DirectoryLen, LLVMRustChecksumKind CSKind,
const char *Checksum, size_t ChecksumLen) {

#if LLVM_VERSION_LT(16, 0)
Optional<DIFile::ChecksumKind> llvmCSKind = fromRust(CSKind);
#else
std::optional<DIFile::ChecksumKind> llvmCSKind = fromRust(CSKind);
#endif

#if LLVM_VERSION_LT(16, 0)
Optional<DIFile::ChecksumInfo<StringRef>> CSInfo{};
#else
std::optional<DIFile::ChecksumInfo<StringRef>> CSInfo{};
#endif
if (llvmCSKind)
CSInfo.emplace(*llvmCSKind, StringRef{Checksum, ChecksumLen});
return wrap(Builder->createFile(StringRef(Filename, FilenameLen),
Expand Down Expand Up @@ -2053,17 +2012,9 @@ extern "C" bool LLVMRustIsNonGVFunctionPointerTy(LLVMValueRef V) {
}

extern "C" bool LLVMRustLLVMHasZlibCompressionForDebugSymbols() {
#if LLVM_VERSION_GE(16, 0)
return llvm::compression::zlib::isAvailable();
#else
return false;
#endif
}

extern "C" bool LLVMRustLLVMHasZstdCompressionForDebugSymbols() {
#if LLVM_VERSION_GE(16, 0)
return llvm::compression::zstd::isAvailable();
#else
return false;
#endif
}
4 changes: 0 additions & 4 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,6 @@ pub enum StackProbeType {
}

impl StackProbeType {
// LLVM X86 targets (ix86 and x86_64) can use inline-asm stack probes starting with LLVM 16.
// Notable past issues were rust#83139 (fixed in 14) and rust#84667 (fixed in 16).
const X86: Self = Self::InlineOrCall { min_llvm_version_for_inline: (16, 0, 0) };

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some followup, we might want to remove the __rust_probestack stuff altogether, but that doesn't need to happen now.

fn from_json(json: &Json) -> Result<Self, String> {
let object = json.as_object().ok_or_else(|| "expected a JSON object")?;
let kind = object
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/targets/i386_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn target() -> Target {
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(64),
stack_probes: StackProbeType::X86,
stack_probes: StackProbeType::Inline,
..opts("ios", arch)
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn target() -> Target {
&["-Vgcc_ntox86_cxx"],
),
env: "nto70".into(),
stack_probes: StackProbeType::X86,
stack_probes: StackProbeType::Inline,
..base::nto_qnx::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn target() -> Target {
let mut base = opts("macos", arch);
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;
base.frame_pointer = FramePointer::Always;

Target {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn target() -> Target {
// https://developer.android.com/ndk/guides/abis.html#x86
base.cpu = "pentiumpro".into();
base.features = "+mmx,+sse,+sse2,+sse3,+ssse3".into();
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;

Target {
llvm_target: "i686-linux-android".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn target() -> Target {
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-znotext"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;

Target {
llvm_target: "i686-unknown-freebsd".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn target() -> Target {
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;

Target {
llvm_target: "i686-unknown-haiku".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn target() -> Target {
base.max_atomic_width = Some(64);
base.supported_sanitizers = SanitizerSet::ADDRESS;
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;

Target {
llvm_target: "i686-unknown-linux-gnu".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn target() -> Target {
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-melf_i386"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;

// The unwinder used by i686-unknown-linux-musl, the LLVM libunwind
// implementation, apparently relies on frame pointers existing... somehow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn target() -> Target {
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;

Target {
llvm_target: "i686-unknown-netbsdelf".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn target() -> Target {
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-fuse-ld=lld"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;

Target {
llvm_target: "i686-unknown-openbsd".into(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/targets/i686_wrs_vxworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn target() -> Target {
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;

Target {
llvm_target: "i686-unknown-linux-gnu".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn target() -> Target {
base.max_atomic_width = Some(128); // penryn+ supports cmpxchg16b
base.frame_pointer = FramePointer::Always;
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m64"]);
base.stack_probes = StackProbeType::X86;
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers =
SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn target() -> Target {
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(128),
stack_probes: StackProbeType::X86,
stack_probes: StackProbeType::Inline,
..base
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn target() -> Target {
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(128),
stack_probes: StackProbeType::X86,
stack_probes: StackProbeType::Inline,
..base
},
}
Expand Down
Loading
Loading