Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a5a224

Browse files
committedSep 20, 2024
Auto merge of #130506 - nnethercote:rustc_codegen_llvm-cleanups, r=jieyouxu
`rustc_codegen_llvm` cleanups Some improvements I found while reading through this crate's code. r? `@michaelwoerister`
2 parents 2b11f26 + 1f35940 commit 1a5a224

File tree

21 files changed

+515
-648
lines changed

21 files changed

+515
-648
lines changed
 

‎compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,14 @@ impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
8080
self.const_undef(typ)
8181
}
8282

83-
fn const_int(&self, typ: Type<'gcc>, int: i64) -> RValue<'gcc> {
84-
self.gcc_int(typ, int)
85-
}
86-
87-
fn const_uint(&self, typ: Type<'gcc>, int: u64) -> RValue<'gcc> {
88-
self.gcc_uint(typ, int)
89-
}
90-
91-
fn const_uint_big(&self, typ: Type<'gcc>, num: u128) -> RValue<'gcc> {
92-
self.gcc_uint_big(typ, num)
93-
}
94-
9583
fn const_bool(&self, val: bool) -> RValue<'gcc> {
9684
self.const_uint(self.type_i1(), val as u64)
9785
}
9886

87+
fn const_i8(&self, i: i8) -> RValue<'gcc> {
88+
self.const_int(self.type_i8(), i as i64)
89+
}
90+
9991
fn const_i16(&self, i: i16) -> RValue<'gcc> {
10092
self.const_int(self.type_i16(), i as i64)
10193
}
@@ -104,8 +96,12 @@ impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
10496
self.const_int(self.type_i32(), i as i64)
10597
}
10698

107-
fn const_i8(&self, i: i8) -> RValue<'gcc> {
108-
self.const_int(self.type_i8(), i as i64)
99+
fn const_int(&self, typ: Type<'gcc>, int: i64) -> RValue<'gcc> {
100+
self.gcc_int(typ, int)
101+
}
102+
103+
fn const_u8(&self, i: u8) -> RValue<'gcc> {
104+
self.const_uint(self.type_u8(), i as u64)
109105
}
110106

111107
fn const_u32(&self, i: u32) -> RValue<'gcc> {
@@ -130,8 +126,12 @@ impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
130126
self.const_uint(self.usize_type, i)
131127
}
132128

133-
fn const_u8(&self, i: u8) -> RValue<'gcc> {
134-
self.const_uint(self.type_u8(), i as u64)
129+
fn const_uint(&self, typ: Type<'gcc>, int: u64) -> RValue<'gcc> {
130+
self.gcc_uint(typ, int)
131+
}
132+
133+
fn const_uint_big(&self, typ: Type<'gcc>, num: u128) -> RValue<'gcc> {
134+
self.gcc_uint_big(typ, num)
135135
}
136136

137137
fn const_real(&self, typ: Type<'gcc>, val: f64) -> RValue<'gcc> {

‎compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 251 additions & 292 deletions
Large diffs are not rendered by default.

‎compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
403403
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
404404
to_add.push(AttributeKind::Naked.create_attr(cx.llcx));
405405
// HACK(jubilee): "indirect branch tracking" works by attaching prologues to functions.
406-
// And it is a module-level attribute, so the alternative is pulling naked functions into new LLVM modules.
407-
// Otherwise LLVM's "naked" functions come with endbr prefixes per https://github.com/rust-lang/rust/issues/98768
406+
// And it is a module-level attribute, so the alternative is pulling naked functions into
407+
// new LLVM modules. Otherwise LLVM's "naked" functions come with endbr prefixes per
408+
// https://github.com/rust-lang/rust/issues/98768
408409
to_add.push(AttributeKind::NoCfCheck.create_attr(cx.llcx));
409410
if llvm_util::get_version() < (19, 0, 0) {
410411
// Prior to LLVM 19, branch-target-enforcement was disabled by setting the attribute to
@@ -454,7 +455,8 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
454455
flags |= AllocKindFlags::Zeroed;
455456
}
456457
to_add.push(llvm::CreateAllocKindAttr(cx.llcx, flags));
457-
// apply to return place instead of function (unlike all other attributes applied in this function)
458+
// apply to return place instead of function (unlike all other attributes applied in this
459+
// function)
458460
let no_alias = AttributeKind::NoAlias.create_attr(cx.llcx);
459461
attributes::apply_to_llfn(llfn, AttributePlace::ReturnValue, &[no_alias]);
460462
}

‎compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ fn get_bitcode_slice_from_object_data<'a>(
156156
obj: &'a [u8],
157157
cgcx: &CodegenContext<LlvmCodegenBackend>,
158158
) -> Result<&'a [u8], LtoBitcodeFromRlib> {
159-
// We're about to assume the data here is an object file with sections, but if it's raw LLVM IR that
160-
// won't work. Fortunately, if that's what we have we can just return the object directly, so we sniff
161-
// the relevant magic strings here and return.
159+
// We're about to assume the data here is an object file with sections, but if it's raw LLVM IR
160+
// that won't work. Fortunately, if that's what we have we can just return the object directly,
161+
// so we sniff the relevant magic strings here and return.
162162
if obj.starts_with(b"\xDE\xC0\x17\x0B") || obj.starts_with(b"BC\xC0\xDE") {
163163
return Ok(obj);
164164
}
165-
// We drop the "__LLVM," prefix here because on Apple platforms there's a notion of "segment name"
166-
// which in the public API for sections gets treated as part of the section name, but internally
167-
// in MachOObjectFile.cpp gets treated separately.
165+
// We drop the "__LLVM," prefix here because on Apple platforms there's a notion of "segment
166+
// name" which in the public API for sections gets treated as part of the section name, but
167+
// internally in MachOObjectFile.cpp gets treated separately.
168168
let section_name = bitcode_section_name(cgcx).trim_start_matches("__LLVM,");
169169
let mut len = 0;
170170
let data = unsafe {

‎compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl OwnedTargetMachine {
3030
data_sections: bool,
3131
unique_section_names: bool,
3232
trap_unreachable: bool,
33-
singletree: bool,
33+
singlethread: bool,
3434
verbose_asm: bool,
3535
emit_stack_size_section: bool,
3636
relax_elf_relocations: bool,
@@ -62,7 +62,7 @@ impl OwnedTargetMachine {
6262
data_sections,
6363
unique_section_names,
6464
trap_unreachable,
65-
singletree,
65+
singlethread,
6666
verbose_asm,
6767
emit_stack_size_section,
6868
relax_elf_relocations,
@@ -86,15 +86,17 @@ impl Deref for OwnedTargetMachine {
8686
type Target = llvm::TargetMachine;
8787

8888
fn deref(&self) -> &Self::Target {
89-
// SAFETY: constructing ensures we have a valid pointer created by llvm::LLVMRustCreateTargetMachine
89+
// SAFETY: constructing ensures we have a valid pointer created by
90+
// llvm::LLVMRustCreateTargetMachine.
9091
unsafe { self.tm_unique.as_ref() }
9192
}
9293
}
9394

9495
impl Drop for OwnedTargetMachine {
9596
fn drop(&mut self) {
96-
// SAFETY: constructing ensures we have a valid pointer created by llvm::LLVMRustCreateTargetMachine
97-
// OwnedTargetMachine is not copyable so there is no double free or use after free
97+
// SAFETY: constructing ensures we have a valid pointer created by
98+
// llvm::LLVMRustCreateTargetMachine OwnedTargetMachine is not copyable so there is no
99+
// double free or use after free.
98100
unsafe {
99101
llvm::LLVMRustDisposeTargetMachine(self.tm_unique.as_mut());
100102
}

‎compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::errors::{
3838
CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, UnknownCompression,
3939
WithLlvmError, WriteBytecode,
4040
};
41-
use crate::llvm::diagnostic::OptimizationDiagnosticKind;
41+
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4242
use crate::llvm::{self, DiagnosticInfo, PassManager};
4343
use crate::type_::Type;
4444
use crate::{base, common, llvm_util, LlvmCodegenBackend, ModuleLlvm};
@@ -157,7 +157,8 @@ fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel
157157
fn to_llvm_relocation_model(relocation_model: RelocModel) -> llvm::RelocModel {
158158
match relocation_model {
159159
RelocModel::Static => llvm::RelocModel::Static,
160-
// LLVM doesn't have a PIE relocation model, it represents PIE as PIC with an extra attribute.
160+
// LLVM doesn't have a PIE relocation model, it represents PIE as PIC with an extra
161+
// attribute.
161162
RelocModel::Pic | RelocModel::Pie => llvm::RelocModel::PIC,
162163
RelocModel::DynamicNoPic => llvm::RelocModel::DynamicNoPic,
163164
RelocModel::Ropi => llvm::RelocModel::ROPI,
@@ -188,8 +189,8 @@ pub(crate) fn target_machine_factory(
188189
let use_softfp = if sess.target.arch == "arm" && sess.target.abi == "eabihf" {
189190
sess.opts.cg.soft_float
190191
} else {
191-
// `validate_commandline_args_with_session_available` has already warned about this being ignored.
192-
// Let's make sure LLVM doesn't suddenly start using this flag on more targets.
192+
// `validate_commandline_args_with_session_available` has already warned about this being
193+
// ignored. Let's make sure LLVM doesn't suddenly start using this flag on more targets.
193194
false
194195
};
195196

@@ -446,13 +447,12 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
446447
column: opt.column,
447448
pass_name: &opt.pass_name,
448449
kind: match opt.kind {
449-
OptimizationDiagnosticKind::OptimizationRemark => "success",
450-
OptimizationDiagnosticKind::OptimizationMissed
451-
| OptimizationDiagnosticKind::OptimizationFailure => "missed",
452-
OptimizationDiagnosticKind::OptimizationAnalysis
453-
| OptimizationDiagnosticKind::OptimizationAnalysisFPCommute
454-
| OptimizationDiagnosticKind::OptimizationAnalysisAliasing => "analysis",
455-
OptimizationDiagnosticKind::OptimizationRemarkOther => "other",
450+
OptimizationRemark => "success",
451+
OptimizationMissed | OptimizationFailure => "missed",
452+
OptimizationAnalysis
453+
| OptimizationAnalysisFPCommute
454+
| OptimizationAnalysisAliasing => "analysis",
455+
OptimizationRemarkOther => "other",
456456
},
457457
message: &opt.message,
458458
});
@@ -945,11 +945,12 @@ fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data:
945945
}
946946

947947
fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
948-
cgcx.opts.target_triple.triple().contains("-ios")
949-
|| cgcx.opts.target_triple.triple().contains("-darwin")
950-
|| cgcx.opts.target_triple.triple().contains("-tvos")
951-
|| cgcx.opts.target_triple.triple().contains("-watchos")
952-
|| cgcx.opts.target_triple.triple().contains("-visionos")
948+
let triple = cgcx.opts.target_triple.triple();
949+
triple.contains("-ios")
950+
|| triple.contains("-darwin")
951+
|| triple.contains("-tvos")
952+
|| triple.contains("-watchos")
953+
|| triple.contains("-visionos")
953954
}
954955

955956
fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {

‎compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 32 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'ll, 'tcx> Deref for Builder<'_, 'll, 'tcx> {
120120
}
121121
}
122122

123-
macro_rules! builder_methods_for_value_instructions {
123+
macro_rules! math_builder_methods {
124124
($($name:ident($($arg:ident),*) => $llvm_capi:ident),+ $(,)?) => {
125125
$(fn $name(&mut self, $($arg: &'ll Value),*) -> &'ll Value {
126126
unsafe {
@@ -130,6 +130,18 @@ macro_rules! builder_methods_for_value_instructions {
130130
}
131131
}
132132

133+
macro_rules! set_math_builder_methods {
134+
($($name:ident($($arg:ident),*) => ($llvm_capi:ident, $llvm_set_math:ident)),+ $(,)?) => {
135+
$(fn $name(&mut self, $($arg: &'ll Value),*) -> &'ll Value {
136+
unsafe {
137+
let instr = llvm::$llvm_capi(self.llbuilder, $($arg,)* UNNAMED);
138+
llvm::$llvm_set_math(instr);
139+
instr
140+
}
141+
})+
142+
}
143+
}
144+
133145
impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
134146
type CodegenCx = CodegenCx<'ll, 'tcx>;
135147

@@ -267,7 +279,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
267279
}
268280
}
269281

270-
builder_methods_for_value_instructions! {
282+
math_builder_methods! {
271283
add(a, b) => LLVMBuildAdd,
272284
fadd(a, b) => LLVMBuildFAdd,
273285
sub(a, b) => LLVMBuildSub,
@@ -299,84 +311,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
299311
unchecked_umul(x, y) => LLVMBuildNUWMul,
300312
}
301313

302-
fn fadd_fast(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
303-
unsafe {
304-
let instr = llvm::LLVMBuildFAdd(self.llbuilder, lhs, rhs, UNNAMED);
305-
llvm::LLVMRustSetFastMath(instr);
306-
instr
307-
}
308-
}
309-
310-
fn fsub_fast(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
311-
unsafe {
312-
let instr = llvm::LLVMBuildFSub(self.llbuilder, lhs, rhs, UNNAMED);
313-
llvm::LLVMRustSetFastMath(instr);
314-
instr
315-
}
316-
}
317-
318-
fn fmul_fast(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
319-
unsafe {
320-
let instr = llvm::LLVMBuildFMul(self.llbuilder, lhs, rhs, UNNAMED);
321-
llvm::LLVMRustSetFastMath(instr);
322-
instr
323-
}
324-
}
325-
326-
fn fdiv_fast(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
327-
unsafe {
328-
let instr = llvm::LLVMBuildFDiv(self.llbuilder, lhs, rhs, UNNAMED);
329-
llvm::LLVMRustSetFastMath(instr);
330-
instr
331-
}
332-
}
333-
334-
fn frem_fast(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
335-
unsafe {
336-
let instr = llvm::LLVMBuildFRem(self.llbuilder, lhs, rhs, UNNAMED);
337-
llvm::LLVMRustSetFastMath(instr);
338-
instr
339-
}
340-
}
341-
342-
fn fadd_algebraic(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
343-
unsafe {
344-
let instr = llvm::LLVMBuildFAdd(self.llbuilder, lhs, rhs, UNNAMED);
345-
llvm::LLVMRustSetAlgebraicMath(instr);
346-
instr
347-
}
348-
}
349-
350-
fn fsub_algebraic(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
351-
unsafe {
352-
let instr = llvm::LLVMBuildFSub(self.llbuilder, lhs, rhs, UNNAMED);
353-
llvm::LLVMRustSetAlgebraicMath(instr);
354-
instr
355-
}
356-
}
357-
358-
fn fmul_algebraic(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
359-
unsafe {
360-
let instr = llvm::LLVMBuildFMul(self.llbuilder, lhs, rhs, UNNAMED);
361-
llvm::LLVMRustSetAlgebraicMath(instr);
362-
instr
363-
}
364-
}
365-
366-
fn fdiv_algebraic(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
367-
unsafe {
368-
let instr = llvm::LLVMBuildFDiv(self.llbuilder, lhs, rhs, UNNAMED);
369-
llvm::LLVMRustSetAlgebraicMath(instr);
370-
instr
371-
}
372-
}
373-
374-
fn frem_algebraic(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
375-
unsafe {
376-
let instr = llvm::LLVMBuildFRem(self.llbuilder, lhs, rhs, UNNAMED);
377-
llvm::LLVMRustSetAlgebraicMath(instr);
378-
instr
379-
}
314+
set_math_builder_methods! {
315+
fadd_fast(x, y) => (LLVMBuildFAdd, LLVMRustSetFastMath),
316+
fsub_fast(x, y) => (LLVMBuildFSub, LLVMRustSetFastMath),
317+
fmul_fast(x, y) => (LLVMBuildFMul, LLVMRustSetFastMath),
318+
fdiv_fast(x, y) => (LLVMBuildFDiv, LLVMRustSetFastMath),
319+
frem_fast(x, y) => (LLVMBuildFRem, LLVMRustSetFastMath),
320+
fadd_algebraic(x, y) => (LLVMBuildFAdd, LLVMRustSetAlgebraicMath),
321+
fsub_algebraic(x, y) => (LLVMBuildFSub, LLVMRustSetAlgebraicMath),
322+
fmul_algebraic(x, y) => (LLVMBuildFMul, LLVMRustSetAlgebraicMath),
323+
fdiv_algebraic(x, y) => (LLVMBuildFDiv, LLVMRustSetAlgebraicMath),
324+
frem_algebraic(x, y) => (LLVMBuildFRem, LLVMRustSetAlgebraicMath),
380325
}
381326

382327
fn checked_binop(
@@ -459,6 +404,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
459404
val
460405
}
461406
}
407+
462408
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: abi::Scalar) -> Self::Value {
463409
if scalar.is_bool() {
464410
return self.trunc(val, self.cx().type_i1());
@@ -727,11 +673,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
727673
// for performance. LLVM doesn't seem to care about this, and will happily treat
728674
// `!nontemporal` stores as-if they were normal stores (for reordering optimizations
729675
// etc) even on x86, despite later lowering them to MOVNT which do *not* behave like
730-
// regular stores but require special fences.
731-
// So we keep a list of architectures where `!nontemporal` is known to be truly just
732-
// a hint, and use regular stores everywhere else.
733-
// (In the future, we could alternatively ensure that an sfence gets emitted after a sequence of movnt
734-
// before any kind of synchronizing operation. But it's not clear how to do that with LLVM.)
676+
// regular stores but require special fences. So we keep a list of architectures
677+
// where `!nontemporal` is known to be truly just a hint, and use regular stores
678+
// everywhere else. (In the future, we could alternatively ensure that an sfence
679+
// gets emitted after a sequence of movnt before any kind of synchronizing
680+
// operation. But it's not clear how to do that with LLVM.)
735681
// For more context, see <https://github.com/rust-lang/rust/issues/114582> and
736682
// <https://github.com/llvm/llvm-project/issues/64521>.
737683
const WELL_BEHAVED_NONTEMPORAL_ARCHS: &[&str] =
@@ -1160,6 +1106,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11601106
(val, success)
11611107
}
11621108
}
1109+
11631110
fn atomic_rmw(
11641111
&mut self,
11651112
op: rustc_codegen_ssa::common::AtomicRmwBinOp,

‎compiler/rustc_codegen_llvm/src/callee.rs

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ use crate::value::Value;
1515

1616
/// Codegens a reference to a fn/method item, monomorphizing and
1717
/// inlining as it goes.
18-
///
19-
/// # Parameters
20-
///
21-
/// - `cx`: the crate context
22-
/// - `instance`: the instance to be instantiated
2318
pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value {
2419
let tcx = cx.tcx();
2520

@@ -106,62 +101,42 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
106101
let is_generic =
107102
instance.args.non_erasable_generics(tcx, instance.def_id()).next().is_some();
108103

109-
if is_generic {
110-
// This is a monomorphization. Its expected visibility depends
111-
// on whether we are in share-generics mode.
112-
113-
if cx.tcx.sess.opts.share_generics() {
114-
// We are in share_generics mode.
115-
104+
let is_hidden = if is_generic {
105+
// This is a monomorphization of a generic function.
106+
if !cx.tcx.sess.opts.share_generics() {
107+
// When not sharing generics, all instances are in the same
108+
// crate and have hidden visibility.
109+
true
110+
} else {
116111
if let Some(instance_def_id) = instance_def_id.as_local() {
117-
// This is a definition from the current crate. If the
118-
// definition is unreachable for downstream crates or
119-
// the current crate does not re-export generics, the
120-
// definition of the instance will have been declared
121-
// as `hidden`.
122-
if cx.tcx.is_unreachable_local_definition(instance_def_id)
112+
// This is a monomorphization of a generic function
113+
// defined in the current crate. It is hidden if:
114+
// - the definition is unreachable for downstream
115+
// crates, or
116+
// - the current crate does not re-export generics
117+
// (because the crate is a C library or executable)
118+
cx.tcx.is_unreachable_local_definition(instance_def_id)
123119
|| !cx.tcx.local_crate_exports_generics()
124-
{
125-
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
126-
}
127120
} else {
128121
// This is a monomorphization of a generic function
129-
// defined in an upstream crate.
130-
if instance.upstream_monomorphization(tcx).is_some() {
131-
// This is instantiated in another crate. It cannot
132-
// be `hidden`.
133-
} else {
134-
// This is a local instantiation of an upstream definition.
135-
// If the current crate does not re-export it
136-
// (because it is a C library or an executable), it
137-
// will have been declared `hidden`.
138-
if !cx.tcx.local_crate_exports_generics() {
139-
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
140-
}
141-
}
122+
// defined in an upstream crate. It is hidden if:
123+
// - it is instantiated in this crate, and
124+
// - the current crate does not re-export generics
125+
instance.upstream_monomorphization(tcx).is_none()
126+
&& !cx.tcx.local_crate_exports_generics()
142127
}
143-
} else {
144-
// When not sharing generics, all instances are in the same
145-
// crate and have hidden visibility
146-
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
147128
}
148129
} else {
149-
// This is a non-generic function
150-
if cx.tcx.is_codegened_item(instance_def_id) {
151-
// This is a function that is instantiated in the local crate
152-
153-
if instance_def_id.is_local() {
154-
// This is function that is defined in the local crate.
155-
// If it is not reachable, it is hidden.
156-
if !cx.tcx.is_reachable_non_generic(instance_def_id) {
157-
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
158-
}
159-
} else {
160-
// This is a function from an upstream crate that has
161-
// been instantiated here. These are always hidden.
162-
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
163-
}
164-
}
130+
// This is a non-generic function. It is hidden if:
131+
// - it is instantiated in the local crate, and
132+
// - it is defined an upstream crate (non-local), or
133+
// - it is not reachable
134+
cx.tcx.is_codegened_item(instance_def_id)
135+
&& (!instance_def_id.is_local()
136+
|| !cx.tcx.is_reachable_non_generic(instance_def_id))
137+
};
138+
if is_hidden {
139+
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
165140
}
166141

167142
// MinGW: For backward compatibility we rely on the linker to decide whether it

‎compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,14 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
126126
unsafe { llvm::LLVMGetPoison(t) }
127127
}
128128

129-
fn const_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
130-
unsafe { llvm::LLVMConstInt(t, i as u64, True) }
131-
}
132-
133-
fn const_uint(&self, t: &'ll Type, i: u64) -> &'ll Value {
134-
unsafe { llvm::LLVMConstInt(t, i, False) }
135-
}
136-
137-
fn const_uint_big(&self, t: &'ll Type, u: u128) -> &'ll Value {
138-
unsafe {
139-
let words = [u as u64, (u >> 64) as u64];
140-
llvm::LLVMConstIntOfArbitraryPrecision(t, 2, words.as_ptr())
141-
}
142-
}
143-
144129
fn const_bool(&self, val: bool) -> &'ll Value {
145130
self.const_uint(self.type_i1(), val as u64)
146131
}
147132

133+
fn const_i8(&self, i: i8) -> &'ll Value {
134+
self.const_int(self.type_i8(), i as i64)
135+
}
136+
148137
fn const_i16(&self, i: i16) -> &'ll Value {
149138
self.const_int(self.type_i16(), i as i64)
150139
}
@@ -153,8 +142,12 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
153142
self.const_int(self.type_i32(), i as i64)
154143
}
155144

156-
fn const_i8(&self, i: i8) -> &'ll Value {
157-
self.const_int(self.type_i8(), i as i64)
145+
fn const_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
146+
unsafe { llvm::LLVMConstInt(t, i as u64, True) }
147+
}
148+
149+
fn const_u8(&self, i: u8) -> &'ll Value {
150+
self.const_uint(self.type_i8(), i as u64)
158151
}
159152

160153
fn const_u32(&self, i: u32) -> &'ll Value {
@@ -179,8 +172,15 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
179172
self.const_uint(self.isize_ty, i)
180173
}
181174

182-
fn const_u8(&self, i: u8) -> &'ll Value {
183-
self.const_uint(self.type_i8(), i as u64)
175+
fn const_uint(&self, t: &'ll Type, i: u64) -> &'ll Value {
176+
unsafe { llvm::LLVMConstInt(t, i, False) }
177+
}
178+
179+
fn const_uint_big(&self, t: &'ll Type, u: u128) -> &'ll Value {
180+
unsafe {
181+
let words = [u as u64, (u >> 64) as u64];
182+
llvm::LLVMConstIntOfArbitraryPrecision(t, 2, words.as_ptr())
183+
}
184184
}
185185

186186
fn const_real(&self, t: &'ll Type, val: f64) -> &'ll Value {

‎compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ pub(crate) fn const_alloc_to_llvm<'ll>(
7373

7474
// Generating partially-uninit consts is limited to small numbers of chunks,
7575
// to avoid the cost of generating large complex const expressions.
76-
// For example, `[(u32, u8); 1024 * 1024]` contains uninit padding in each element,
77-
// and would result in `{ [5 x i8] zeroinitializer, [3 x i8] undef, ...repeat 1M times... }`.
76+
// For example, `[(u32, u8); 1024 * 1024]` contains uninit padding in each element, and
77+
// would result in `{ [5 x i8] zeroinitializer, [3 x i8] undef, ...repeat 1M times... }`.
7878
let max = cx.sess().opts.unstable_opts.uninit_const_chunk_threshold;
7979
let allow_uninit_chunks = chunks.clone().take(max.saturating_add(1)).count() <= max;
8080

@@ -249,8 +249,8 @@ impl<'ll> CodegenCx<'ll, '_> {
249249
trace!(?instance);
250250

251251
let DefKind::Static { nested, .. } = self.tcx.def_kind(def_id) else { bug!() };
252-
// Nested statics do not have a type, so pick a dummy type and let `codegen_static` figure out
253-
// the llvm type from the actual evaluated initializer.
252+
// Nested statics do not have a type, so pick a dummy type and let `codegen_static` figure
253+
// out the llvm type from the actual evaluated initializer.
254254
let llty = if nested {
255255
self.type_i8()
256256
} else {
@@ -262,7 +262,7 @@ impl<'ll> CodegenCx<'ll, '_> {
262262
}
263263

264264
#[instrument(level = "debug", skip(self, llty))]
265-
pub(crate) fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Value {
265+
fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Value {
266266
let instance = Instance::mono(self.tcx, def_id);
267267
if let Some(&g) = self.instances.borrow().get(&instance) {
268268
trace!("used cached value");
@@ -320,15 +320,16 @@ impl<'ll> CodegenCx<'ll, '_> {
320320
}
321321

322322
if !def_id.is_local() {
323-
let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
323+
let needs_dll_storage_attr = self.use_dll_storage_attrs
324+
&& !self.tcx.is_foreign_item(def_id)
324325
// Local definitions can never be imported, so we must not apply
325326
// the DLLImport annotation.
326-
!dso_local &&
327+
&& !dso_local
327328
// ThinLTO can't handle this workaround in all cases, so we don't
328329
// emit the attrs. Instead we make them unnecessary by disallowing
329330
// dynamic linking when linker plugin based LTO is enabled.
330-
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() &&
331-
self.tcx.sess.lto() != Lto::Thin;
331+
&& !self.tcx.sess.opts.cg.linker_plugin_lto.enabled()
332+
&& self.tcx.sess.lto() != Lto::Thin;
332333

333334
// If this assertion triggers, there's something wrong with commandline
334335
// argument validation.
@@ -551,8 +552,8 @@ impl<'ll> CodegenCx<'ll, '_> {
551552
// `#[used(compiler)]` is explicitly requested. This is to avoid similar breakage
552553
// on other targets, in particular MachO targets have *their* static constructor
553554
// lists broken if `llvm.compiler.used` is emitted rather than `llvm.used`. However,
554-
// that check happens when assigning the `CodegenFnAttrFlags` in `rustc_hir_analysis`,
555-
// so we don't need to take care of it here.
555+
// that check happens when assigning the `CodegenFnAttrFlags` in
556+
// `rustc_hir_analysis`, so we don't need to take care of it here.
556557
self.add_compiler_used_global(g);
557558
}
558559
if attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) {

‎compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use crate::type_::Type;
3535
use crate::value::Value;
3636
use crate::{attributes, coverageinfo, debuginfo, llvm, llvm_util};
3737

38-
/// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
39-
/// `llvm::Context` so that several compilation units may be optimized in parallel.
38+
/// There is one `CodegenCx` per codegen unit. Each one has its own LLVM
39+
/// `llvm::Context` so that several codegen units may be processed in parallel.
4040
/// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.
4141
pub(crate) struct CodegenCx<'ll, 'tcx> {
4242
pub tcx: TyCtxt<'tcx>,
@@ -231,7 +231,8 @@ pub(crate) unsafe fn create_module<'ll>(
231231
}
232232
}
233233

234-
// Enable LTO unit splitting if specified or if CFI is enabled. (See https://reviews.llvm.org/D53891.)
234+
// Enable LTO unit splitting if specified or if CFI is enabled. (See
235+
// https://reviews.llvm.org/D53891.)
235236
if sess.is_split_lto_unit_enabled() || sess.is_sanitizer_cfi_enabled() {
236237
let enable_split_lto_unit = c"EnableSplitLTOUnit".as_ptr();
237238
unsafe {

‎compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ mod mcdc {
121121
num_conditions: u16,
122122
}
123123

124-
// ConditionId in llvm is `unsigned int` at 18 while `int16_t` at [19](https://github.com/llvm/llvm-project/pull/81257)
124+
// ConditionId in llvm is `unsigned int` at 18 while `int16_t` at
125+
// [19](https://github.com/llvm/llvm-project/pull/81257).
125126
type LLVMConditionId = i16;
126127

127128
/// Must match the layout of `LLVMRustMCDCBranchParameters`.

‎compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ impl<'ll, 'tcx> CrateCoverageContext<'ll, 'tcx> {
4848
self.function_coverage_map.replace(FxIndexMap::default())
4949
}
5050

51-
/// LLVM use a temp value to record evaluated mcdc test vector of each decision, which is called condition bitmap.
52-
/// In order to handle nested decisions, several condition bitmaps can be
53-
/// allocated for a function body.
54-
/// These values are named `mcdc.addr.{i}` and are a 32-bit integers.
55-
/// They respectively hold the condition bitmaps for decisions with a depth of `i`.
51+
/// LLVM use a temp value to record evaluated mcdc test vector of each decision, which is
52+
/// called condition bitmap. In order to handle nested decisions, several condition bitmaps can
53+
/// be allocated for a function body. These values are named `mcdc.addr.{i}` and are a 32-bit
54+
/// integers. They respectively hold the condition bitmaps for decisions with a depth of `i`.
5655
fn try_get_mcdc_condition_bitmap(
5756
&self,
5857
instance: &Instance<'tcx>,
@@ -157,8 +156,8 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
157156
),
158157
CoverageKind::CounterIncrement { id } => {
159158
func_coverage.mark_counter_id_seen(id);
160-
// We need to explicitly drop the `RefMut` before calling into `instrprof_increment`,
161-
// as that needs an exclusive borrow.
159+
// We need to explicitly drop the `RefMut` before calling into
160+
// `instrprof_increment`, as that needs an exclusive borrow.
162161
drop(coverage_map);
163162

164163
// The number of counters passed to `llvm.instrprof.increment` might

‎compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
4444
// Add the pretty printers for the standard library first.
4545
section_contents.extend_from_slice(b"\x01gdb_load_rust_pretty_printers.py\0");
4646

47-
// Next, add the pretty printers that were specified via the `#[debugger_visualizer]` attribute.
47+
// Next, add the pretty printers that were specified via the `#[debugger_visualizer]`
48+
// attribute.
4849
let visualizers = collect_debugger_visualizers_transitive(
4950
cx.tcx,
5051
DebuggerVisualizerType::GdbPrettyPrinter,

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
216216
// need to make sure that we don't break existing debuginfo consumers
217217
// by doing that (at least not without a warning period).
218218
let layout_type = if ptr_type.is_box() {
219-
// The assertion at the start of this function ensures we have a ZST allocator.
220-
// We'll make debuginfo "skip" all ZST allocators, not just the default allocator.
219+
// The assertion at the start of this function ensures we have a ZST
220+
// allocator. We'll make debuginfo "skip" all ZST allocators, not just the
221+
// default allocator.
221222
Ty::new_mut_ptr(cx.tcx, pointee_type)
222223
} else {
223224
ptr_type
@@ -280,8 +281,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
280281
cx: &CodegenCx<'ll, 'tcx>,
281282
unique_type_id: UniqueTypeId<'tcx>,
282283
) -> DINodeCreationResult<'ll> {
283-
// It's possible to create a self-referential
284-
// type in Rust by using 'impl trait':
284+
// It's possible to create a self-referential type in Rust by using 'impl trait':
285285
//
286286
// fn foo() -> impl Copy { foo }
287287
//
@@ -573,14 +573,14 @@ pub(crate) fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFi
573573
{
574574
// If the compiler's working directory (which also is the DW_AT_comp_dir of
575575
// the compilation unit) is a prefix of the path we are about to emit, then
576-
// only emit the part relative to the working directory.
577-
// Because of path remapping we sometimes see strange things here: `abs_path`
578-
// might actually look like a relative path
579-
// (e.g. `<crate-name-and-version>/src/lib.rs`), so if we emit it without
580-
// taking the working directory into account, downstream tooling will
581-
// interpret it as `<working-directory>/<crate-name-and-version>/src/lib.rs`,
582-
// which makes no sense. Usually in such cases the working directory will also
583-
// be remapped to `<crate-name-and-version>` or some other prefix of the path
576+
// only emit the part relative to the working directory. Because of path
577+
// remapping we sometimes see strange things here: `abs_path` might
578+
// actually look like a relative path (e.g.
579+
// `<crate-name-and-version>/src/lib.rs`), so if we emit it without taking
580+
// the working directory into account, downstream tooling will interpret it
581+
// as `<working-directory>/<crate-name-and-version>/src/lib.rs`, which
582+
// makes no sense. Usually in such cases the working directory will also be
583+
// remapped to `<crate-name-and-version>` or some other prefix of the path
584584
// we are remapping, so we end up with
585585
// `<crate-name-and-version>/<crate-name-and-version>/src/lib.rs`.
586586
// By moving the working directory portion into the `directory` part of the

‎compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ pub(crate) fn mangled_name_of_instance<'a, 'tcx>(
1313
cx: &CodegenCx<'a, 'tcx>,
1414
instance: Instance<'tcx>,
1515
) -> ty::SymbolName<'tcx> {
16-
let tcx = cx.tcx;
17-
tcx.symbol_name(instance)
16+
cx.tcx.symbol_name(instance)
1817
}
1918

2019
pub(crate) fn item_namespace<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {

‎compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
404404
let llvm_name =
405405
&format!("llvm.fsh{}.i{}", if is_left { 'l' } else { 'r' }, width);
406406

407-
// llvm expects shift to be the same type as the values, but rust always uses `u32`
407+
// llvm expects shift to be the same type as the values, but rust
408+
// always uses `u32`.
408409
let raw_shift = self.intcast(raw_shift, self.val_ty(val), false);
409410

410411
self.call_intrinsic(llvm_name, &[val, val, raw_shift])
@@ -573,8 +574,8 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
573574
span,
574575
) {
575576
Ok(llval) => llval,
576-
// If there was an error, just skip this invocation... we'll abort compilation anyway,
577-
// but we can keep codegen'ing to find more errors.
577+
// If there was an error, just skip this invocation... we'll abort compilation
578+
// anyway, but we can keep codegen'ing to find more errors.
578579
Err(()) => return Ok(()),
579580
}
580581
}
@@ -1847,7 +1848,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
18471848
require!(
18481849
matches!(
18491850
*pointer_ty.kind(),
1850-
ty::RawPtr(p_ty, p_mutbl) if p_ty == values_elem && p_ty.kind() == values_elem.kind() && p_mutbl.is_mut()
1851+
ty::RawPtr(p_ty, p_mutbl)
1852+
if p_ty == values_elem && p_ty.kind() == values_elem.kind() && p_mutbl.is_mut()
18511853
),
18521854
InvalidMonomorphization::ExpectedElementType {
18531855
span,

‎compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 71 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,18 @@ pub enum IntPredicate {
220220

221221
impl IntPredicate {
222222
pub fn from_generic(intpre: rustc_codegen_ssa::common::IntPredicate) -> Self {
223+
use rustc_codegen_ssa::common::IntPredicate as Common;
223224
match intpre {
224-
rustc_codegen_ssa::common::IntPredicate::IntEQ => IntPredicate::IntEQ,
225-
rustc_codegen_ssa::common::IntPredicate::IntNE => IntPredicate::IntNE,
226-
rustc_codegen_ssa::common::IntPredicate::IntUGT => IntPredicate::IntUGT,
227-
rustc_codegen_ssa::common::IntPredicate::IntUGE => IntPredicate::IntUGE,
228-
rustc_codegen_ssa::common::IntPredicate::IntULT => IntPredicate::IntULT,
229-
rustc_codegen_ssa::common::IntPredicate::IntULE => IntPredicate::IntULE,
230-
rustc_codegen_ssa::common::IntPredicate::IntSGT => IntPredicate::IntSGT,
231-
rustc_codegen_ssa::common::IntPredicate::IntSGE => IntPredicate::IntSGE,
232-
rustc_codegen_ssa::common::IntPredicate::IntSLT => IntPredicate::IntSLT,
233-
rustc_codegen_ssa::common::IntPredicate::IntSLE => IntPredicate::IntSLE,
225+
Common::IntEQ => Self::IntEQ,
226+
Common::IntNE => Self::IntNE,
227+
Common::IntUGT => Self::IntUGT,
228+
Common::IntUGE => Self::IntUGE,
229+
Common::IntULT => Self::IntULT,
230+
Common::IntULE => Self::IntULE,
231+
Common::IntSGT => Self::IntSGT,
232+
Common::IntSGE => Self::IntSGE,
233+
Common::IntSLT => Self::IntSLT,
234+
Common::IntSLE => Self::IntSLE,
234235
}
235236
}
236237
}
@@ -259,27 +260,24 @@ pub enum RealPredicate {
259260

260261
impl RealPredicate {
261262
pub fn from_generic(realp: rustc_codegen_ssa::common::RealPredicate) -> Self {
263+
use rustc_codegen_ssa::common::RealPredicate as Common;
262264
match realp {
263-
rustc_codegen_ssa::common::RealPredicate::RealPredicateFalse => {
264-
RealPredicate::RealPredicateFalse
265-
}
266-
rustc_codegen_ssa::common::RealPredicate::RealOEQ => RealPredicate::RealOEQ,
267-
rustc_codegen_ssa::common::RealPredicate::RealOGT => RealPredicate::RealOGT,
268-
rustc_codegen_ssa::common::RealPredicate::RealOGE => RealPredicate::RealOGE,
269-
rustc_codegen_ssa::common::RealPredicate::RealOLT => RealPredicate::RealOLT,
270-
rustc_codegen_ssa::common::RealPredicate::RealOLE => RealPredicate::RealOLE,
271-
rustc_codegen_ssa::common::RealPredicate::RealONE => RealPredicate::RealONE,
272-
rustc_codegen_ssa::common::RealPredicate::RealORD => RealPredicate::RealORD,
273-
rustc_codegen_ssa::common::RealPredicate::RealUNO => RealPredicate::RealUNO,
274-
rustc_codegen_ssa::common::RealPredicate::RealUEQ => RealPredicate::RealUEQ,
275-
rustc_codegen_ssa::common::RealPredicate::RealUGT => RealPredicate::RealUGT,
276-
rustc_codegen_ssa::common::RealPredicate::RealUGE => RealPredicate::RealUGE,
277-
rustc_codegen_ssa::common::RealPredicate::RealULT => RealPredicate::RealULT,
278-
rustc_codegen_ssa::common::RealPredicate::RealULE => RealPredicate::RealULE,
279-
rustc_codegen_ssa::common::RealPredicate::RealUNE => RealPredicate::RealUNE,
280-
rustc_codegen_ssa::common::RealPredicate::RealPredicateTrue => {
281-
RealPredicate::RealPredicateTrue
282-
}
265+
Common::RealPredicateFalse => Self::RealPredicateFalse,
266+
Common::RealOEQ => Self::RealOEQ,
267+
Common::RealOGT => Self::RealOGT,
268+
Common::RealOGE => Self::RealOGE,
269+
Common::RealOLT => Self::RealOLT,
270+
Common::RealOLE => Self::RealOLE,
271+
Common::RealONE => Self::RealONE,
272+
Common::RealORD => Self::RealORD,
273+
Common::RealUNO => Self::RealUNO,
274+
Common::RealUEQ => Self::RealUEQ,
275+
Common::RealUGT => Self::RealUGT,
276+
Common::RealUGE => Self::RealUGE,
277+
Common::RealULT => Self::RealULT,
278+
Common::RealULE => Self::RealULE,
279+
Common::RealUNE => Self::RealUNE,
280+
Common::RealPredicateTrue => Self::RealPredicateTrue,
283281
}
284282
}
285283
}
@@ -311,26 +309,27 @@ pub enum TypeKind {
311309

312310
impl TypeKind {
313311
pub fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind {
312+
use rustc_codegen_ssa::common::TypeKind as Common;
314313
match self {
315-
TypeKind::Void => rustc_codegen_ssa::common::TypeKind::Void,
316-
TypeKind::Half => rustc_codegen_ssa::common::TypeKind::Half,
317-
TypeKind::Float => rustc_codegen_ssa::common::TypeKind::Float,
318-
TypeKind::Double => rustc_codegen_ssa::common::TypeKind::Double,
319-
TypeKind::X86_FP80 => rustc_codegen_ssa::common::TypeKind::X86_FP80,
320-
TypeKind::FP128 => rustc_codegen_ssa::common::TypeKind::FP128,
321-
TypeKind::PPC_FP128 => rustc_codegen_ssa::common::TypeKind::PPC_FP128,
322-
TypeKind::Label => rustc_codegen_ssa::common::TypeKind::Label,
323-
TypeKind::Integer => rustc_codegen_ssa::common::TypeKind::Integer,
324-
TypeKind::Function => rustc_codegen_ssa::common::TypeKind::Function,
325-
TypeKind::Struct => rustc_codegen_ssa::common::TypeKind::Struct,
326-
TypeKind::Array => rustc_codegen_ssa::common::TypeKind::Array,
327-
TypeKind::Pointer => rustc_codegen_ssa::common::TypeKind::Pointer,
328-
TypeKind::Vector => rustc_codegen_ssa::common::TypeKind::Vector,
329-
TypeKind::Metadata => rustc_codegen_ssa::common::TypeKind::Metadata,
330-
TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token,
331-
TypeKind::ScalableVector => rustc_codegen_ssa::common::TypeKind::ScalableVector,
332-
TypeKind::BFloat => rustc_codegen_ssa::common::TypeKind::BFloat,
333-
TypeKind::X86_AMX => rustc_codegen_ssa::common::TypeKind::X86_AMX,
314+
Self::Void => Common::Void,
315+
Self::Half => Common::Half,
316+
Self::Float => Common::Float,
317+
Self::Double => Common::Double,
318+
Self::X86_FP80 => Common::X86_FP80,
319+
Self::FP128 => Common::FP128,
320+
Self::PPC_FP128 => Common::PPC_FP128,
321+
Self::Label => Common::Label,
322+
Self::Integer => Common::Integer,
323+
Self::Function => Common::Function,
324+
Self::Struct => Common::Struct,
325+
Self::Array => Common::Array,
326+
Self::Pointer => Common::Pointer,
327+
Self::Vector => Common::Vector,
328+
Self::Metadata => Common::Metadata,
329+
Self::Token => Common::Token,
330+
Self::ScalableVector => Common::ScalableVector,
331+
Self::BFloat => Common::BFloat,
332+
Self::X86_AMX => Common::X86_AMX,
334333
}
335334
}
336335
}
@@ -354,18 +353,19 @@ pub enum AtomicRmwBinOp {
354353

355354
impl AtomicRmwBinOp {
356355
pub fn from_generic(op: rustc_codegen_ssa::common::AtomicRmwBinOp) -> Self {
356+
use rustc_codegen_ssa::common::AtomicRmwBinOp as Common;
357357
match op {
358-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg => AtomicRmwBinOp::AtomicXchg,
359-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAdd => AtomicRmwBinOp::AtomicAdd,
360-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicSub => AtomicRmwBinOp::AtomicSub,
361-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAnd => AtomicRmwBinOp::AtomicAnd,
362-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicNand => AtomicRmwBinOp::AtomicNand,
363-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicOr => AtomicRmwBinOp::AtomicOr,
364-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXor => AtomicRmwBinOp::AtomicXor,
365-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMax => AtomicRmwBinOp::AtomicMax,
366-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMin => AtomicRmwBinOp::AtomicMin,
367-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMax => AtomicRmwBinOp::AtomicUMax,
368-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMin => AtomicRmwBinOp::AtomicUMin,
358+
Common::AtomicXchg => Self::AtomicXchg,
359+
Common::AtomicAdd => Self::AtomicAdd,
360+
Common::AtomicSub => Self::AtomicSub,
361+
Common::AtomicAnd => Self::AtomicAnd,
362+
Common::AtomicNand => Self::AtomicNand,
363+
Common::AtomicOr => Self::AtomicOr,
364+
Common::AtomicXor => Self::AtomicXor,
365+
Common::AtomicMax => Self::AtomicMax,
366+
Common::AtomicMin => Self::AtomicMin,
367+
Common::AtomicUMax => Self::AtomicUMax,
368+
Common::AtomicUMin => Self::AtomicUMin,
369369
}
370370
}
371371
}
@@ -387,17 +387,14 @@ pub enum AtomicOrdering {
387387

388388
impl AtomicOrdering {
389389
pub fn from_generic(ao: rustc_codegen_ssa::common::AtomicOrdering) -> Self {
390+
use rustc_codegen_ssa::common::AtomicOrdering as Common;
390391
match ao {
391-
rustc_codegen_ssa::common::AtomicOrdering::Unordered => AtomicOrdering::Unordered,
392-
rustc_codegen_ssa::common::AtomicOrdering::Relaxed => AtomicOrdering::Monotonic,
393-
rustc_codegen_ssa::common::AtomicOrdering::Acquire => AtomicOrdering::Acquire,
394-
rustc_codegen_ssa::common::AtomicOrdering::Release => AtomicOrdering::Release,
395-
rustc_codegen_ssa::common::AtomicOrdering::AcquireRelease => {
396-
AtomicOrdering::AcquireRelease
397-
}
398-
rustc_codegen_ssa::common::AtomicOrdering::SequentiallyConsistent => {
399-
AtomicOrdering::SequentiallyConsistent
400-
}
392+
Common::Unordered => Self::Unordered,
393+
Common::Relaxed => Self::Monotonic,
394+
Common::Acquire => Self::Acquire,
395+
Common::Release => Self::Release,
396+
Common::AcquireRelease => Self::AcquireRelease,
397+
Common::SequentiallyConsistent => Self::SequentiallyConsistent,
401398
}
402399
}
403400
}
@@ -563,13 +560,11 @@ pub enum ArchiveKind {
563560
K_AIXBIG,
564561
}
565562

566-
// LLVMRustThinLTOData
567563
unsafe extern "C" {
564+
// LLVMRustThinLTOData
568565
pub type ThinLTOData;
569-
}
570566

571-
// LLVMRustThinLTOBuffer
572-
unsafe extern "C" {
567+
// LLVMRustThinLTOBuffer
573568
pub type ThinLTOBuffer;
574569
}
575570

@@ -633,26 +628,12 @@ struct InvariantOpaque<'a> {
633628
// Opaque pointer types
634629
unsafe extern "C" {
635630
pub type Module;
636-
}
637-
unsafe extern "C" {
638631
pub type Context;
639-
}
640-
unsafe extern "C" {
641632
pub type Type;
642-
}
643-
unsafe extern "C" {
644633
pub type Value;
645-
}
646-
unsafe extern "C" {
647634
pub type ConstantInt;
648-
}
649-
unsafe extern "C" {
650635
pub type Attribute;
651-
}
652-
unsafe extern "C" {
653636
pub type Metadata;
654-
}
655-
unsafe extern "C" {
656637
pub type BasicBlock;
657638
}
658639
#[repr(C)]
@@ -661,11 +642,7 @@ pub struct Builder<'a>(InvariantOpaque<'a>);
661642
pub struct PassManager<'a>(InvariantOpaque<'a>);
662643
unsafe extern "C" {
663644
pub type Pass;
664-
}
665-
unsafe extern "C" {
666645
pub type TargetMachine;
667-
}
668-
unsafe extern "C" {
669646
pub type Archive;
670647
}
671648
#[repr(C)]
@@ -674,11 +651,7 @@ pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
674651
pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
675652
unsafe extern "C" {
676653
pub type Twine;
677-
}
678-
unsafe extern "C" {
679654
pub type DiagnosticInfo;
680-
}
681-
unsafe extern "C" {
682655
pub type SMDiagnostic;
683656
}
684657
#[repr(C)]
@@ -2177,7 +2150,8 @@ unsafe extern "C" {
21772150

21782151
pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char;
21792152

2180-
// This function makes copies of pointed to data, so the data's lifetime may end after this function returns
2153+
// This function makes copies of pointed to data, so the data's lifetime may end after this
2154+
// function returns.
21812155
pub fn LLVMRustCreateTargetMachine(
21822156
Triple: *const c_char,
21832157
CPU: *const c_char,

‎compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ impl<'a> IntoIterator for LLVMFeature<'a> {
217217
// where `{ARCH}` is the architecture name. Look for instances of `SubtargetFeature`.
218218
//
219219
// Check the current rustc fork of LLVM in the repo at https://github.com/rust-lang/llvm-project/.
220-
// The commit in use can be found via the `llvm-project` submodule in https://github.com/rust-lang/rust/tree/master/src
221-
// Though note that Rust can also be build with an external precompiled version of LLVM
222-
// which might lead to failures if the oldest tested / supported LLVM version
223-
// doesn't yet support the relevant intrinsics
220+
// The commit in use can be found via the `llvm-project` submodule in
221+
// https://github.com/rust-lang/rust/tree/master/src Though note that Rust can also be build with
222+
// an external precompiled version of LLVM which might lead to failures if the oldest tested /
223+
// supported LLVM version doesn't yet support the relevant intrinsics.
224224
pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFeature<'a>> {
225225
let arch = if sess.target.arch == "x86_64" {
226226
"x86"
@@ -259,8 +259,8 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
259259
("aarch64", "fp16") => Some(LLVMFeature::new("fullfp16")),
260260
// Filter out features that are not supported by the current LLVM version
261261
("aarch64", "fpmr") if get_version().0 != 18 => None,
262-
// In LLVM 18, `unaligned-scalar-mem` was merged with `unaligned-vector-mem` into a single feature called
263-
// `fast-unaligned-access`. In LLVM 19, it was split back out.
262+
// In LLVM 18, `unaligned-scalar-mem` was merged with `unaligned-vector-mem` into a single
263+
// feature called `fast-unaligned-access`. In LLVM 19, it was split back out.
264264
("riscv32" | "riscv64", "unaligned-scalar-mem") if get_version().0 == 18 => {
265265
Some(LLVMFeature::new("fast-unaligned-access"))
266266
}
@@ -406,7 +406,8 @@ fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMach
406406
.supported_target_features()
407407
.iter()
408408
.filter_map(|(feature, _gate, _implied)| {
409-
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these strings.
409+
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these
410+
// strings.
410411
let llvm_feature = to_llvm_features(sess, *feature)?.llvm_feature_name;
411412
let desc =
412413
match llvm_target_features.binary_search_by_key(&llvm_feature, |(f, _d)| f).ok() {

‎compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
2424
) {
2525
let instance = Instance::mono(self.tcx, def_id);
2626
let DefKind::Static { nested, .. } = self.tcx.def_kind(def_id) else { bug!() };
27-
// Nested statics do not have a type, so pick a dummy type and let `codegen_static` figure out
28-
// the llvm type from the actual evaluated initializer.
27+
// Nested statics do not have a type, so pick a dummy type and let `codegen_static` figure
28+
// out the llvm type from the actual evaluated initializer.
2929
let ty = if nested {
3030
self.tcx.types.unit
3131
} else {

‎compiler/rustc_codegen_ssa/src/traits/consts.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ pub trait ConstCodegenMethods<'tcx>: BackendTypes {
1414
/// (including code that e.g. copies uninit memory with `MaybeUninit`) can never encounter a
1515
/// poison value.
1616
fn const_poison(&self, t: Self::Type) -> Self::Value;
17-
fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
18-
fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;
19-
fn const_uint_big(&self, t: Self::Type, u: u128) -> Self::Value;
17+
2018
fn const_bool(&self, val: bool) -> Self::Value;
19+
20+
fn const_i8(&self, i: i8) -> Self::Value;
2121
fn const_i16(&self, i: i16) -> Self::Value;
2222
fn const_i32(&self, i: i32) -> Self::Value;
23-
fn const_i8(&self, i: i8) -> Self::Value;
23+
fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
24+
fn const_u8(&self, i: u8) -> Self::Value;
2425
fn const_u32(&self, i: u32) -> Self::Value;
2526
fn const_u64(&self, i: u64) -> Self::Value;
2627
fn const_u128(&self, i: u128) -> Self::Value;
2728
fn const_usize(&self, i: u64) -> Self::Value;
28-
fn const_u8(&self, i: u8) -> Self::Value;
29+
fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;
30+
fn const_uint_big(&self, t: Self::Type, u: u128) -> Self::Value;
2931
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;
3032

3133
fn const_str(&self, s: &str) -> (Self::Value, Self::Value);

0 commit comments

Comments
 (0)
Please sign in to comment.