summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_llvm/src/llvm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs11
-rw-r--r--compiler/rustc_codegen_llvm/src/llvm/ffi.rs133
-rw-r--r--compiler/rustc_codegen_llvm/src/llvm_util.rs53
3 files changed, 33 insertions, 164 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs b/compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs
index 64db4f746..7d9489702 100644
--- a/compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs
@@ -83,17 +83,6 @@ impl<'a> Child<'a> {
}
}
}
-
- pub fn data(&self) -> &'a [u8] {
- unsafe {
- let mut data_len = 0;
- let data_ptr = super::LLVMRustArchiveChildData(self.raw, &mut data_len);
- if data_ptr.is_null() {
- panic!("failed to read data from archive child");
- }
- slice::from_raw_parts(data_ptr as *const u8, data_len as usize)
- }
- }
}
impl<'a> Drop for Child<'a> {
diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
index 3139f93bf..42cb694c0 100644
--- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
@@ -400,27 +400,6 @@ impl AtomicOrdering {
}
}
-/// LLVMRustSynchronizationScope
-#[derive(Copy, Clone)]
-#[repr(C)]
-pub enum SynchronizationScope {
- SingleThread,
- CrossThread,
-}
-
-impl SynchronizationScope {
- pub fn from_generic(sc: rustc_codegen_ssa::common::SynchronizationScope) -> Self {
- match sc {
- rustc_codegen_ssa::common::SynchronizationScope::SingleThread => {
- SynchronizationScope::SingleThread
- }
- rustc_codegen_ssa::common::SynchronizationScope::CrossThread => {
- SynchronizationScope::CrossThread
- }
- }
- }
-}
-
/// LLVMRustFileType
#[derive(Copy, Clone)]
#[repr(C)]
@@ -1096,7 +1075,7 @@ extern "C" {
pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
- pub fn LLVMConstIntGetZExtValue(ConstantVal: &ConstantInt) -> c_ulonglong;
+ pub fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;
pub fn LLVMRustConstInt128Get(
ConstantVal: &ConstantInt,
SExt: bool,
@@ -1782,16 +1761,18 @@ extern "C" {
Order: AtomicOrdering,
) -> &'a Value;
- pub fn LLVMRustBuildAtomicCmpXchg<'a>(
+ pub fn LLVMBuildAtomicCmpXchg<'a>(
B: &Builder<'a>,
LHS: &'a Value,
CMP: &'a Value,
RHS: &'a Value,
Order: AtomicOrdering,
FailureOrder: AtomicOrdering,
- Weak: Bool,
+ SingleThreaded: Bool,
) -> &'a Value;
+ pub fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);
+
pub fn LLVMBuildAtomicRMW<'a>(
B: &Builder<'a>,
Op: AtomicRmwBinOp,
@@ -1801,27 +1782,19 @@ extern "C" {
SingleThreaded: Bool,
) -> &'a Value;
- pub fn LLVMRustBuildAtomicFence(
- B: &Builder<'_>,
+ pub fn LLVMBuildFence<'a>(
+ B: &Builder<'a>,
Order: AtomicOrdering,
- Scope: SynchronizationScope,
- );
+ SingleThreaded: Bool,
+ Name: *const c_char,
+ ) -> &'a Value;
/// Writes a module to the specified path. Returns 0 on success.
pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
- /// Creates a pass manager.
+ /// Creates a legacy pass manager -- only used for final codegen.
pub fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;
- /// Creates a function-by-function pass manager
- pub fn LLVMCreateFunctionPassManagerForModule(M: &Module) -> &mut PassManager<'_>;
-
- /// Disposes a pass manager.
- pub fn LLVMDisposePassManager<'a>(PM: &'a mut PassManager<'a>);
-
- /// Runs a pass manager on a module.
- pub fn LLVMRunPassManager<'a>(PM: &PassManager<'a>, M: &'a Module) -> Bool;
-
pub fn LLVMInitializePasses();
pub fn LLVMTimeTraceProfilerInitialize();
@@ -1832,32 +1805,6 @@ extern "C" {
pub fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
- pub fn LLVMRustPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
- pub fn LLVMRustPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
- pub fn LLVMRustPassManagerBuilderUseInlinerWithThreshold(
- PMB: &PassManagerBuilder,
- threshold: c_uint,
- );
- pub fn LLVMRustPassManagerBuilderPopulateModulePassManager(
- PMB: &PassManagerBuilder,
- PM: &PassManager<'_>,
- );
-
- pub fn LLVMRustPassManagerBuilderPopulateFunctionPassManager(
- PMB: &PassManagerBuilder,
- PM: &PassManager<'_>,
- );
- pub fn LLVMRustPassManagerBuilderPopulateLTOPassManager(
- PMB: &PassManagerBuilder,
- PM: &PassManager<'_>,
- Internalize: Bool,
- RunInliner: Bool,
- );
- pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
- PMB: &PassManagerBuilder,
- PM: &PassManager<'_>,
- );
-
pub fn LLVMGetHostCPUFeatures() -> *mut c_char;
pub fn LLVMDisposeMessage(message: *mut c_char);
@@ -2079,6 +2026,19 @@ extern "C" {
Ty: &'a DIType,
) -> &'a DIType;
+ pub fn LLVMRustDIBuilderCreateStaticMemberType<'a>(
+ Builder: &DIBuilder<'a>,
+ Scope: &'a DIDescriptor,
+ Name: *const c_char,
+ NameLen: size_t,
+ File: &'a DIFile,
+ LineNo: c_uint,
+ Ty: &'a DIType,
+ Flags: DIFlags,
+ val: Option<&'a Value>,
+ AlignInBits: u32,
+ ) -> &'a DIDerivedType;
+
pub fn LLVMRustDIBuilderCreateLexicalBlock<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
@@ -2249,22 +2209,6 @@ extern "C" {
pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
- pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> Option<&'static mut Pass>;
- pub fn LLVMRustCreateAddressSanitizerFunctionPass(Recover: bool) -> &'static mut Pass;
- pub fn LLVMRustCreateModuleAddressSanitizerPass(Recover: bool) -> &'static mut Pass;
- pub fn LLVMRustCreateMemorySanitizerPass(
- TrackOrigins: c_int,
- Recover: bool,
- ) -> &'static mut Pass;
- pub fn LLVMRustCreateThreadSanitizerPass() -> &'static mut Pass;
- pub fn LLVMRustCreateHWAddressSanitizerPass(Recover: bool) -> &'static mut Pass;
- pub fn LLVMRustAddPass(PM: &PassManager<'_>, Pass: &'static mut Pass);
- pub fn LLVMRustAddLastExtensionPasses(
- PMB: &PassManagerBuilder,
- Passes: *const &'static mut Pass,
- NumPasses: size_t,
- );
-
pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
@@ -2298,29 +2242,11 @@ extern "C" {
SplitDwarfFile: *const c_char,
) -> Option<&'static mut TargetMachine>;
pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
- pub fn LLVMRustAddBuilderLibraryInfo<'a>(
- PMB: &'a PassManagerBuilder,
- M: &'a Module,
- DisableSimplifyLibCalls: bool,
- );
- pub fn LLVMRustConfigurePassManagerBuilder(
- PMB: &PassManagerBuilder,
- OptLevel: CodeGenOptLevel,
- MergeFunctions: bool,
- SLPVectorize: bool,
- LoopVectorize: bool,
- PrepareForThinLTO: bool,
- PGOGenPath: *const c_char,
- PGOUsePath: *const c_char,
- PGOSampleUsePath: *const c_char,
- SizeLevel: c_int,
- );
pub fn LLVMRustAddLibraryInfo<'a>(
PM: &PassManager<'a>,
M: &'a Module,
DisableSimplifyLibCalls: bool,
);
- pub fn LLVMRustRunFunctionPassManager<'a>(PM: &PassManager<'a>, M: &'a Module);
pub fn LLVMRustWriteOutputFile<'a>(
T: &'a TargetMachine,
PM: &PassManager<'a>,
@@ -2329,7 +2255,7 @@ extern "C" {
DwoOutput: *const c_char,
FileType: FileType,
) -> LLVMRustResult;
- pub fn LLVMRustOptimizeWithNewPassManager<'a>(
+ pub fn LLVMRustOptimize<'a>(
M: &'a Module,
TM: &'a TargetMachine,
OptLevel: PassBuilderOptLevel,
@@ -2347,6 +2273,7 @@ extern "C" {
PGOGenPath: *const c_char,
PGOUsePath: *const c_char,
InstrumentCoverage: bool,
+ InstrProfileOutput: *const c_char,
InstrumentGCOV: bool,
PGOSampleUsePath: *const c_char,
DebugInfoForProfiling: bool,
@@ -2366,7 +2293,6 @@ extern "C" {
pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
pub fn LLVMRustPrintPasses();
pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
- pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
@@ -2375,7 +2301,6 @@ extern "C" {
AIR: &ArchiveIterator<'a>,
) -> Option<&'a mut ArchiveChild<'a>>;
pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
- pub fn LLVMRustArchiveChildData(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
pub fn LLVMRustArchiveChildFree<'a>(ACR: &'a mut ArchiveChild<'a>);
pub fn LLVMRustArchiveIteratorFree<'a>(AIR: &'a mut ArchiveIterator<'a>);
pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
@@ -2410,12 +2335,6 @@ extern "C" {
cookie_out: &mut c_uint,
) -> &'a SMDiagnostic;
- pub fn LLVMRustSetInlineAsmDiagnosticHandler(
- C: &Context,
- H: InlineAsmDiagHandlerTy,
- CX: *mut c_void,
- );
-
#[allow(improper_ctypes)]
pub fn LLVMRustUnpackSMDiagnostic(
d: &SMDiagnostic,
diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs
index a0a640473..2fd58567c 100644
--- a/compiler/rustc_codegen_llvm/src/llvm_util.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs
@@ -1,7 +1,6 @@
use crate::back::write::create_informational_target_machine;
-use crate::{llvm, llvm_util};
+use crate::llvm;
use libc::c_int;
-use libloading::Library;
use rustc_codegen_ssa::target_features::{
supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES,
};
@@ -15,9 +14,7 @@ use rustc_span::symbol::Symbol;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use smallvec::{smallvec, SmallVec};
use std::ffi::{CStr, CString};
-use tracing::debug;
-use std::mem;
use std::path::Path;
use std::ptr;
use std::slice;
@@ -92,16 +89,6 @@ unsafe fn configure_llvm(sess: &Session) {
add("-generate-arange-section", false);
}
- // Disable the machine outliner by default in LLVM versions 11 and LLVM
- // version 12, where it leads to miscompilation.
- //
- // Ref:
- // - https://github.com/rust-lang/rust/issues/85351
- // - https://reviews.llvm.org/D103167
- if llvm_util::get_version() < (13, 0, 0) {
- add("-enable-machine-outliner=never", false);
- }
-
match sess.opts.unstable_opts.merge_functions.unwrap_or(sess.target.merge_functions) {
MergeFunctions::Disabled | MergeFunctions::Trampolines => {}
MergeFunctions::Aliases => {
@@ -131,22 +118,6 @@ unsafe fn configure_llvm(sess: &Session) {
llvm::LLVMInitializePasses();
- // Use the legacy plugin registration if we don't use the new pass manager
- if !should_use_new_llvm_pass_manager(
- &sess.opts.unstable_opts.new_llvm_pass_manager,
- &sess.target.arch,
- ) {
- // Register LLVM plugins by loading them into the compiler process.
- for plugin in &sess.opts.unstable_opts.llvm_plugins {
- let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e));
- debug!("LLVM plugin loaded successfully {:?} ({})", lib, plugin);
-
- // Intentionally leak the dynamic library. We can't ever unload it
- // since the library can make things that will live arbitrarily long.
- mem::forget(lib);
- }
- }
-
rustc_llvm::initialize_available_targets();
llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr());
@@ -165,6 +136,10 @@ pub fn time_trace_profiler_finish(file_name: &Path) {
//
// To find a list of LLVM's names, check llvm-project/llvm/include/llvm/Support/*TargetParser.def
// where the * matches the architecture's name
+//
+// For targets not present in the above location, see llvm-project/llvm/lib/Target/{ARCH}/*.td
+// where `{ARCH}` is the architecture name. Look for instances of `SubtargetFeature`.
+//
// Beware to not use the llvm github project for this, but check the git submodule
// found in src/llvm-project
// Though note that Rust can also be build with an external precompiled version of LLVM
@@ -440,6 +415,8 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
.features
.split(',')
.filter(|v| !v.is_empty() && backend_feature_name(v).is_some())
+ // Drop +atomics-32 feature introduced in LLVM 15.
+ .filter(|v| *v != "+atomics-32" || get_version() >= (15, 0, 0))
.map(String::from),
);
@@ -544,19 +521,3 @@ pub fn tune_cpu(sess: &Session) -> Option<&str> {
let name = sess.opts.unstable_opts.tune_cpu.as_ref()?;
Some(handle_native(name))
}
-
-pub(crate) fn should_use_new_llvm_pass_manager(user_opt: &Option<bool>, target_arch: &str) -> bool {
- // The new pass manager is enabled by default for LLVM >= 13.
- // This matches Clang, which also enables it since Clang 13.
-
- // Since LLVM 15, the legacy pass manager is no longer supported.
- if llvm_util::get_version() >= (15, 0, 0) {
- return true;
- }
-
- // There are some perf issues with the new pass manager when targeting
- // s390x with LLVM 13, so enable the new pass manager only with LLVM 14.
- // See https://github.com/rust-lang/rust/issues/89609.
- let min_version = if target_arch == "s390x" { 14 } else { 13 };
- user_opt.unwrap_or_else(|| llvm_util::get_version() >= (min_version, 0, 0))
-}