Skip to content

Commit 6d99c36

Browse files
authored
Unrolled build for rust-lang#123237
Rollup merge of rust-lang#123237 - bjorn3:debuginfo_refactor, r=compiler-errors Various rustc_codegen_ssa cleanups
2 parents bf750f5 + 84f45bb commit 6d99c36

File tree

16 files changed

+138
-179
lines changed

16 files changed

+138
-179
lines changed

compiler/rustc_codegen_gcc/src/common.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2828
global
2929
// TODO(antoyo): set linkage.
3030
}
31+
32+
pub fn const_bitcast(&self, value: RValue<'gcc>, typ: Type<'gcc>) -> RValue<'gcc> {
33+
if value.get_type() == self.bool_type.make_pointer() {
34+
if let Some(pointee) = typ.get_pointee() {
35+
if pointee.dyncast_vector().is_some() {
36+
panic!()
37+
}
38+
}
39+
}
40+
// NOTE: since bitcast makes a value non-constant, don't bitcast if not necessary as some
41+
// SIMD builtins require a constant value.
42+
self.bitcast_if_needed(value, typ)
43+
}
3144
}
3245

3346
pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) -> RValue<'gcc> {
@@ -239,19 +252,6 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
239252
const_alloc_to_gcc(self, alloc)
240253
}
241254

242-
fn const_bitcast(&self, value: RValue<'gcc>, typ: Type<'gcc>) -> RValue<'gcc> {
243-
if value.get_type() == self.bool_type.make_pointer() {
244-
if let Some(pointee) = typ.get_pointee() {
245-
if pointee.dyncast_vector().is_some() {
246-
panic!()
247-
}
248-
}
249-
}
250-
// NOTE: since bitcast makes a value non-constant, don't bitcast if not necessary as some
251-
// SIMD builtins require a constant value.
252-
self.bitcast_if_needed(value, typ)
253-
}
254-
255255
fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
256256
self.context
257257
.new_array_access(None, base_addr, self.const_usize(offset.bytes()))

compiler/rustc_codegen_gcc/src/context.rs

-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::callee::get_fn;
2727
use crate::common::SignType;
2828

2929
pub struct CodegenCx<'gcc, 'tcx> {
30-
pub check_overflow: bool,
3130
pub codegen_unit: &'tcx CodegenUnit<'tcx>,
3231
pub context: &'gcc Context<'gcc>,
3332

@@ -134,8 +133,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
134133
tcx: TyCtxt<'tcx>,
135134
supports_128bit_integers: bool,
136135
) -> Self {
137-
let check_overflow = tcx.sess.overflow_checks();
138-
139136
let create_type = |ctype, rust_type| {
140137
let layout = tcx.layout_of(ParamEnv::reveal_all().and(rust_type)).unwrap();
141138
let align = layout.align.abi.bytes();
@@ -271,7 +268,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
271268
}
272269

273270
let mut cx = Self {
274-
check_overflow,
275271
codegen_unit,
276272
context,
277273
current_func: RefCell::new(None),
@@ -511,10 +507,6 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
511507
&self.tcx.sess
512508
}
513509

514-
fn check_overflow(&self) -> bool {
515-
self.check_overflow
516-
}
517-
518510
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
519511
self.codegen_unit
520512
}

compiler/rustc_codegen_gcc/src/type_.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,34 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
8989
ty::FloatTy::F128 => self.type_f128(),
9090
}
9191
}
92-
}
9392

94-
impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
95-
fn type_i1(&self) -> Type<'gcc> {
93+
pub fn type_i1(&self) -> Type<'gcc> {
9694
self.bool_type
9795
}
9896

97+
pub fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
98+
let types = fields.to_vec();
99+
if let Some(typ) = self.struct_types.borrow().get(fields) {
100+
return *typ;
101+
}
102+
let fields: Vec<_> = fields
103+
.iter()
104+
.enumerate()
105+
.map(|(index, field)| {
106+
self.context.new_field(None, *field, format!("field{}_TODO", index))
107+
})
108+
.collect();
109+
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
110+
if packed {
111+
#[cfg(feature = "master")]
112+
typ.set_packed();
113+
}
114+
self.struct_types.borrow_mut().insert(types, typ);
115+
typ
116+
}
117+
}
118+
119+
impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
99120
fn type_i8(&self) -> Type<'gcc> {
100121
self.i8_type
101122
}
@@ -131,7 +152,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
131152
fn type_f64(&self) -> Type<'gcc> {
132153
self.double_type
133154
}
134-
155+
135156
fn type_f128(&self) -> Type<'gcc> {
136157
unimplemented!("f16_f128")
137158
}
@@ -140,27 +161,6 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
140161
self.context.new_function_pointer_type(None, return_type, params, false)
141162
}
142163

143-
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
144-
let types = fields.to_vec();
145-
if let Some(typ) = self.struct_types.borrow().get(fields) {
146-
return *typ;
147-
}
148-
let fields: Vec<_> = fields
149-
.iter()
150-
.enumerate()
151-
.map(|(index, field)| {
152-
self.context.new_field(None, *field, format!("field{}_TODO", index))
153-
})
154-
.collect();
155-
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
156-
if packed {
157-
#[cfg(feature = "master")]
158-
typ.set_packed();
159-
}
160-
self.struct_types.borrow_mut().insert(types, typ);
161-
typ
162-
}
163-
164164
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
165165
if self.is_int_type_or_bool(typ) {
166166
TypeKind::Integer

compiler/rustc_codegen_llvm/src/common.rs

-4
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,6 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
329329
const_alloc_to_llvm(self, alloc, /*static*/ false)
330330
}
331331

332-
fn const_bitcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {
333-
self.const_bitcast(val, ty)
334-
}
335-
336332
fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
337333
unsafe {
338334
llvm::LLVMConstInBoundsGEP2(

compiler/rustc_codegen_llvm/src/context.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::back::write::to_llvm_code_model;
33
use crate::callee::get_fn;
44
use crate::coverageinfo;
55
use crate::debuginfo;
6+
use crate::debuginfo::metadata::apply_vcall_visibility_metadata;
67
use crate::llvm;
78
use crate::llvm_util;
89
use crate::type_::Type;
@@ -43,7 +44,6 @@ use std::str;
4344
/// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.
4445
pub struct CodegenCx<'ll, 'tcx> {
4546
pub tcx: TyCtxt<'tcx>,
46-
pub check_overflow: bool,
4747
pub use_dll_storage_attrs: bool,
4848
pub tls_model: llvm::ThreadLocalMode,
4949

@@ -441,8 +441,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
441441
// start) and then strongly recommending static linkage on Windows!
442442
let use_dll_storage_attrs = tcx.sess.target.is_like_windows;
443443

444-
let check_overflow = tcx.sess.overflow_checks();
445-
446444
let tls_model = to_llvm_tls_model(tcx.sess.tls_model());
447445

448446
let (llcx, llmod) = (&*llvm_module.llcx, llvm_module.llmod());
@@ -466,7 +464,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
466464

467465
CodegenCx {
468466
tcx,
469-
check_overflow,
470467
use_dll_storage_attrs,
471468
tls_model,
472469
llmod,
@@ -522,6 +519,15 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
522519
&self.vtables
523520
}
524521

522+
fn apply_vcall_visibility_metadata(
523+
&self,
524+
ty: Ty<'tcx>,
525+
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
526+
vtable: &'ll Value,
527+
) {
528+
apply_vcall_visibility_metadata(self, ty, poly_trait_ref, vtable);
529+
}
530+
525531
fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
526532
get_fn(self, instance)
527533
}
@@ -596,10 +602,6 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
596602
self.tcx.sess
597603
}
598604

599-
fn check_overflow(&self) -> bool {
600-
self.check_overflow
601-
}
602-
603605
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
604606
self.codegen_unit
605607
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1449,12 +1449,18 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
14491449
.di_node
14501450
}
14511451

1452-
fn vcall_visibility_metadata<'ll, 'tcx>(
1452+
pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
14531453
cx: &CodegenCx<'ll, 'tcx>,
14541454
ty: Ty<'tcx>,
14551455
trait_ref: Option<PolyExistentialTraitRef<'tcx>>,
14561456
vtable: &'ll Value,
14571457
) {
1458+
// FIXME(flip1995): The virtual function elimination optimization only works with full LTO in
1459+
// LLVM at the moment.
1460+
if !cx.sess().opts.unstable_opts.virtual_function_elimination || cx.sess().lto() != Lto::Fat {
1461+
return;
1462+
}
1463+
14581464
enum VCallVisibility {
14591465
Public = 0,
14601466
LinkageUnit = 1,
@@ -1531,12 +1537,6 @@ pub fn create_vtable_di_node<'ll, 'tcx>(
15311537
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
15321538
vtable: &'ll Value,
15331539
) {
1534-
// FIXME(flip1995): The virtual function elimination optimization only works with full LTO in
1535-
// LLVM at the moment.
1536-
if cx.sess().opts.unstable_opts.virtual_function_elimination && cx.sess().lto() == Lto::Fat {
1537-
vcall_visibility_metadata(cx, ty, poly_trait_ref, vtable);
1538-
}
1539-
15401540
if cx.dbg_cx.is_none() {
15411541
return;
15421542
}

compiler/rustc_codegen_llvm/src/lib.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,11 @@ impl CodegenBackend for LlvmCodegenBackend {
274274
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true)
275275
}
276276

277-
fn print(&self, req: &PrintRequest, out: &mut dyn PrintBackendInfo, sess: &Session) {
277+
fn print(&self, req: &PrintRequest, out: &mut String, sess: &Session) {
278+
use std::fmt::Write;
278279
match req.kind {
279280
PrintKind::RelocationModels => {
280-
writeln!(out, "Available relocation models:");
281+
writeln!(out, "Available relocation models:").unwrap();
281282
for name in &[
282283
"static",
283284
"pic",
@@ -288,25 +289,25 @@ impl CodegenBackend for LlvmCodegenBackend {
288289
"ropi-rwpi",
289290
"default",
290291
] {
291-
writeln!(out, " {name}");
292+
writeln!(out, " {name}").unwrap();
292293
}
293-
writeln!(out);
294+
writeln!(out).unwrap();
294295
}
295296
PrintKind::CodeModels => {
296-
writeln!(out, "Available code models:");
297+
writeln!(out, "Available code models:").unwrap();
297298
for name in &["tiny", "small", "kernel", "medium", "large"] {
298-
writeln!(out, " {name}");
299+
writeln!(out, " {name}").unwrap();
299300
}
300-
writeln!(out);
301+
writeln!(out).unwrap();
301302
}
302303
PrintKind::TlsModels => {
303-
writeln!(out, "Available TLS models:");
304+
writeln!(out, "Available TLS models:").unwrap();
304305
for name in
305306
&["global-dynamic", "local-dynamic", "initial-exec", "local-exec", "emulated"]
306307
{
307-
writeln!(out, " {name}");
308+
writeln!(out, " {name}").unwrap();
308309
}
309-
writeln!(out);
310+
writeln!(out).unwrap();
310311
}
311312
PrintKind::StackProtectorStrategies => {
312313
writeln!(
@@ -332,7 +333,8 @@ impl CodegenBackend for LlvmCodegenBackend {
332333
none
333334
Do not generate stack canaries.
334335
"#
335-
);
336+
)
337+
.unwrap();
336338
}
337339
_other => llvm_util::print(req, out, sess),
338340
}

compiler/rustc_codegen_llvm/src/llvm_util.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::errors::{
66
use crate::llvm;
77
use libc::c_int;
88
use rustc_codegen_ssa::base::wants_wasm_eh;
9-
use rustc_codegen_ssa::traits::PrintBackendInfo;
109
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1110
use rustc_data_structures::small_c_str::SmallCStr;
1211
use rustc_fs_util::path_to_c_string;
@@ -18,6 +17,7 @@ use rustc_target::spec::{MergeFunctions, PanicStrategy};
1817
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;
1918

2019
use std::ffi::{c_char, c_void, CStr, CString};
20+
use std::fmt::Write;
2121
use std::path::Path;
2222
use std::ptr;
2323
use std::slice;
@@ -372,7 +372,7 @@ fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> {
372372
ret
373373
}
374374

375-
fn print_target_features(out: &mut dyn PrintBackendInfo, sess: &Session, tm: &llvm::TargetMachine) {
375+
fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMachine) {
376376
let mut llvm_target_features = llvm_target_features(tm);
377377
let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
378378
let mut rustc_target_features = sess
@@ -412,24 +412,26 @@ fn print_target_features(out: &mut dyn PrintBackendInfo, sess: &Session, tm: &ll
412412
.max()
413413
.unwrap_or(0);
414414

415-
writeln!(out, "Features supported by rustc for this target:");
415+
writeln!(out, "Features supported by rustc for this target:").unwrap();
416416
for (feature, desc) in &rustc_target_features {
417-
writeln!(out, " {feature:max_feature_len$} - {desc}.");
417+
writeln!(out, " {feature:max_feature_len$} - {desc}.").unwrap();
418418
}
419-
writeln!(out, "\nCode-generation features supported by LLVM for this target:");
419+
writeln!(out, "\nCode-generation features supported by LLVM for this target:").unwrap();
420420
for (feature, desc) in &llvm_target_features {
421-
writeln!(out, " {feature:max_feature_len$} - {desc}.");
421+
writeln!(out, " {feature:max_feature_len$} - {desc}.").unwrap();
422422
}
423423
if llvm_target_features.is_empty() {
424-
writeln!(out, " Target features listing is not supported by this LLVM version.");
424+
writeln!(out, " Target features listing is not supported by this LLVM version.")
425+
.unwrap();
425426
}
426-
writeln!(out, "\nUse +feature to enable a feature, or -feature to disable it.");
427-
writeln!(out, "For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2\n");
428-
writeln!(out, "Code-generation features cannot be used in cfg or #[target_feature],");
429-
writeln!(out, "and may be renamed or removed in a future version of LLVM or rustc.\n");
427+
writeln!(out, "\nUse +feature to enable a feature, or -feature to disable it.").unwrap();
428+
writeln!(out, "For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2\n")
429+
.unwrap();
430+
writeln!(out, "Code-generation features cannot be used in cfg or #[target_feature],").unwrap();
431+
writeln!(out, "and may be renamed or removed in a future version of LLVM or rustc.\n").unwrap();
430432
}
431433

432-
pub(crate) fn print(req: &PrintRequest, mut out: &mut dyn PrintBackendInfo, sess: &Session) {
434+
pub(crate) fn print(req: &PrintRequest, mut out: &mut String, sess: &Session) {
433435
require_inited();
434436
let tm = create_informational_target_machine(sess);
435437
match req.kind {
@@ -440,9 +442,9 @@ pub(crate) fn print(req: &PrintRequest, mut out: &mut dyn PrintBackendInfo, sess
440442
let cpu_cstring = CString::new(handle_native(sess.target.cpu.as_ref()))
441443
.unwrap_or_else(|e| bug!("failed to convert to cstring: {}", e));
442444
unsafe extern "C" fn callback(out: *mut c_void, string: *const c_char, len: usize) {
443-
let out = &mut *(out as *mut &mut dyn PrintBackendInfo);
445+
let out = &mut *(out as *mut &mut String);
444446
let bytes = slice::from_raw_parts(string as *const u8, len);
445-
write!(out, "{}", String::from_utf8_lossy(bytes));
447+
write!(out, "{}", String::from_utf8_lossy(bytes)).unwrap();
446448
}
447449
unsafe {
448450
llvm::LLVMRustPrintTargetCPUs(

0 commit comments

Comments
 (0)