Skip to content

Commit 3fffc88

Browse files
committed
Merge ref 'df8102fe5f24:/library/compiler-builtins' from https://github.com/rust-lang/rust
Pull recent changes from rust-lang/rust via Josh. Upstream ref: df8102fe5f24f28a918660b0cd918d7331c3896e Filtered ref: 3c30d8cb1ec24e0b8a88a5cedcf6b9bece0117d7
2 parents 357baca + aa88602 commit 3fffc88

13 files changed

Lines changed: 132 additions & 200 deletions

File tree

src/abi.rs

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "master")]
22
use gccjit::FnAttribute;
33
use gccjit::{ToLValue, ToRValue, Type};
4-
use rustc_abi::{Reg, RegKind};
4+
use rustc_abi::{ArmCall, CanonAbi, InterruptKind, Reg, RegKind, X86Call};
55
use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeCodegenMethods};
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_middle::bug;
@@ -10,12 +10,9 @@ use rustc_middle::ty::layout::LayoutOf;
1010
#[cfg(feature = "master")]
1111
use rustc_session::config;
1212
use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode};
13-
#[cfg(feature = "master")]
14-
use rustc_target::callconv::{Conv, RiscvInterruptKind};
1513

1614
use crate::builder::Builder;
1715
use crate::context::CodegenCx;
18-
use crate::intrinsic::ArgAbiExt;
1916
use crate::type_of::LayoutGccExt;
2017

2118
impl AbiBuilderMethods for Builder<'_, '_, '_> {
@@ -125,7 +122,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
125122
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_gcc_type(cx),
126123
PassMode::Cast { ref cast, .. } => cast.gcc_type(cx),
127124
PassMode::Indirect { .. } => {
128-
argument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
125+
argument_tys.push(cx.type_ptr_to(self.ret.layout.gcc_type(cx)));
129126
cx.type_void()
130127
}
131128
};
@@ -176,13 +173,13 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
176173
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: true } => {
177174
// This is a "byval" argument, so we don't apply the `restrict` attribute on it.
178175
on_stack_param_indices.insert(argument_tys.len());
179-
arg.memory_ty(cx)
176+
arg.layout.gcc_type(cx)
180177
}
181178
PassMode::Direct(attrs) => {
182179
apply_attrs(arg.layout.immediate_gcc_type(cx), &attrs, argument_tys.len())
183180
}
184181
PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => {
185-
apply_attrs(cx.type_ptr_to(arg.memory_ty(cx)), &attrs, argument_tys.len())
182+
apply_attrs(cx.type_ptr_to(arg.layout.gcc_type(cx)), &attrs, argument_tys.len())
186183
}
187184
PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => {
188185
assert!(!on_stack);
@@ -239,29 +236,16 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
239236
}
240237

241238
#[cfg(feature = "master")]
242-
pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<'gcc>> {
239+
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &str) -> Option<FnAttribute<'gcc>> {
243240
let attribute = match conv {
244-
Conv::C | Conv::Rust => return None,
245-
Conv::CCmseNonSecureCall => {
246-
if arch == "arm" {
247-
FnAttribute::ArmCmseNonsecureCall
248-
} else {
249-
return None;
250-
}
251-
}
252-
Conv::CCmseNonSecureEntry => {
253-
if arch == "arm" {
254-
FnAttribute::ArmCmseNonsecureEntry
255-
} else {
256-
return None;
257-
}
258-
}
259-
Conv::Cold => FnAttribute::Cold,
260-
// NOTE: the preserve attributes are not yet implemented in GCC:
261-
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110899
262-
Conv::PreserveMost => return None,
263-
Conv::PreserveAll => return None,
264-
Conv::GpuKernel => {
241+
CanonAbi::C | CanonAbi::Rust => return None,
242+
CanonAbi::Arm(arm_call) => match arm_call {
243+
ArmCall::CCmseNonSecureCall => FnAttribute::ArmCmseNonsecureCall,
244+
ArmCall::CCmseNonSecureEntry => FnAttribute::ArmCmseNonsecureEntry,
245+
ArmCall::Aapcs => FnAttribute::ArmPcs("aapcs"),
246+
},
247+
CanonAbi::RustCold => FnAttribute::Cold,
248+
CanonAbi::GpuKernel => {
265249
if arch == "amdgpu" {
266250
FnAttribute::GcnAmdGpuHsaKernel
267251
} else if arch == "nvptx64" {
@@ -271,26 +255,24 @@ pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<
271255
}
272256
}
273257
// TODO(antoyo): check if those AVR attributes are mapped correctly.
274-
Conv::AvrInterrupt => FnAttribute::AvrSignal,
275-
Conv::AvrNonBlockingInterrupt => FnAttribute::AvrInterrupt,
276-
Conv::ArmAapcs => FnAttribute::ArmPcs("aapcs"),
277-
Conv::Msp430Intr => FnAttribute::Msp430Interrupt,
278-
Conv::RiscvInterrupt { kind } => {
279-
let kind = match kind {
280-
RiscvInterruptKind::Machine => "machine",
281-
RiscvInterruptKind::Supervisor => "supervisor",
282-
};
283-
FnAttribute::RiscvInterrupt(kind)
284-
}
285-
Conv::X86Fastcall => FnAttribute::X86FastCall,
286-
Conv::X86Intr => FnAttribute::X86Interrupt,
287-
Conv::X86Stdcall => FnAttribute::X86Stdcall,
288-
Conv::X86ThisCall => FnAttribute::X86ThisCall,
289-
// NOTE: the vectorcall calling convention is not yet implemented in GCC:
290-
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
291-
Conv::X86VectorCall => return None,
292-
Conv::X86_64SysV => FnAttribute::X86SysvAbi,
293-
Conv::X86_64Win64 => FnAttribute::X86MsAbi,
258+
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
259+
InterruptKind::Avr => FnAttribute::AvrSignal,
260+
InterruptKind::AvrNonBlocking => FnAttribute::AvrInterrupt,
261+
InterruptKind::Msp430 => FnAttribute::Msp430Interrupt,
262+
InterruptKind::RiscvMachine => FnAttribute::RiscvInterrupt("machine"),
263+
InterruptKind::RiscvSupervisor => FnAttribute::RiscvInterrupt("supervisor"),
264+
InterruptKind::X86 => FnAttribute::X86Interrupt,
265+
},
266+
CanonAbi::X86(x86_call) => match x86_call {
267+
X86Call::Fastcall => FnAttribute::X86FastCall,
268+
X86Call::Stdcall => FnAttribute::X86Stdcall,
269+
X86Call::Thiscall => FnAttribute::X86ThisCall,
270+
// // NOTE: the vectorcall calling convention is not yet implemented in GCC:
271+
// // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
272+
X86Call::Vectorcall => return None,
273+
X86Call::SysV64 => FnAttribute::X86SysvAbi,
274+
X86Call::Win64 => FnAttribute::X86MsAbi,
275+
},
294276
};
295277
Some(attribute)
296278
}

src/attributes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
use gccjit::FnAttribute;
33
use gccjit::Function;
44
#[cfg(feature = "master")]
5-
use rustc_attr_parsing::InlineAttr;
6-
use rustc_attr_parsing::InstructionSetAttr;
5+
use rustc_attr_data_structures::InlineAttr;
6+
use rustc_attr_data_structures::InstructionSetAttr;
77
#[cfg(feature = "master")]
88
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
99
#[cfg(feature = "master")]

src/base.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,22 @@ pub fn compile_codegen_unit(
219219

220220
let mono_items = cgu.items_in_deterministic_order(tcx);
221221
for &(mono_item, data) in &mono_items {
222-
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, data.linkage, data.visibility);
222+
mono_item.predefine::<Builder<'_, '_, '_>>(
223+
&mut cx,
224+
cgu_name.as_str(),
225+
data.linkage,
226+
data.visibility,
227+
);
223228
}
224229

225230
// ... and now that we have everything pre-defined, fill out those definitions.
226231
for &(mono_item, item_data) in &mono_items {
227-
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, item_data);
232+
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, cgu_name.as_str(), item_data);
228233
}
229234

230235
// If this codegen unit contains the main function, also create the
231236
// wrapper here
232-
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx);
237+
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx, cx.codegen_unit);
233238

234239
// Finalize debuginfo
235240
if cx.sess().opts.debuginfo != DebugInfo::None {

src/builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout, WrappingRange};
1212
use rustc_apfloat::{Float, Round, Status, ieee};
1313
use rustc_codegen_ssa::MemFlags;
1414
use rustc_codegen_ssa::common::{
15-
AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
15+
AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
1616
};
1717
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1818
use rustc_codegen_ssa::mir::place::PlaceRef;
@@ -26,7 +26,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2626
use rustc_middle::ty::layout::{
2727
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
2828
};
29-
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
29+
use rustc_middle::ty::{self, AtomicOrdering, Instance, Ty, TyCtxt};
3030
use rustc_span::Span;
3131
use rustc_span::def_id::DefId;
3232
use rustc_target::callconv::FnAbi;
@@ -75,7 +75,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
7575

7676
let load_ordering = match order {
7777
// TODO(antoyo): does this make sense?
78-
AtomicOrdering::AcquireRelease | AtomicOrdering::Release => AtomicOrdering::Acquire,
78+
AtomicOrdering::AcqRel | AtomicOrdering::Release => AtomicOrdering::Acquire,
7979
_ => order,
8080
};
8181
let previous_value =
@@ -2474,8 +2474,8 @@ impl ToGccOrdering for AtomicOrdering {
24742474
AtomicOrdering::Relaxed => __ATOMIC_RELAXED, // TODO(antoyo): check if that's the same.
24752475
AtomicOrdering::Acquire => __ATOMIC_ACQUIRE,
24762476
AtomicOrdering::Release => __ATOMIC_RELEASE,
2477-
AtomicOrdering::AcquireRelease => __ATOMIC_ACQ_REL,
2478-
AtomicOrdering::SequentiallyConsistent => __ATOMIC_SEQ_CST,
2477+
AtomicOrdering::AcqRel => __ATOMIC_ACQ_REL,
2478+
AtomicOrdering::SeqCst => __ATOMIC_SEQ_CST,
24792479
};
24802480
ordering as i32
24812481
}

src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
106106
// This is a monomorphization of a generic function.
107107
if !(cx.tcx.sess.opts.share_generics()
108108
|| tcx.codegen_fn_attrs(instance_def_id).inline
109-
== rustc_attr_parsing::InlineAttr::Never)
109+
== rustc_attr_data_structures::InlineAttr::Never)
110110
{
111111
// When not sharing generics, all instances are in the same
112112
// crate and have hidden visibility.

src/consts.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
6767
}
6868

6969
#[cfg_attr(not(feature = "master"), allow(unused_mut))]
70-
fn codegen_static(&self, def_id: DefId) {
70+
fn codegen_static(&mut self, def_id: DefId) {
7171
let attrs = self.tcx.codegen_fn_attrs(def_id);
7272

7373
let Ok((value, alloc)) = codegen_static_initializer(self, def_id) else {
@@ -154,25 +154,20 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
154154
// TODO(antoyo): set link section.
155155
}
156156

157-
if attrs.flags.contains(CodegenFnAttrFlags::USED)
157+
if attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
158158
|| attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
159159
{
160160
self.add_used_global(global.to_rvalue());
161161
}
162162
}
163+
}
163164

165+
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
164166
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of i8*.
165-
fn add_used_global(&self, _global: RValue<'gcc>) {
167+
pub fn add_used_global(&mut self, _global: RValue<'gcc>) {
166168
// TODO(antoyo)
167169
}
168170

169-
fn add_compiler_used_global(&self, global: RValue<'gcc>) {
170-
// NOTE: seems like GCC does not make the distinction between compiler.used and used.
171-
self.add_used_global(global);
172-
}
173-
}
174-
175-
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
176171
#[cfg_attr(not(feature = "master"), allow(unused_variables))]
177172
pub fn add_used_function(&self, function: Function<'gcc>) {
178173
#[cfg(feature = "master")]

src/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,6 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
470470
self.tcx.sess
471471
}
472472

473-
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
474-
self.codegen_unit
475-
}
476-
477473
fn set_frame_pointer_type(&self, _llfn: RValue<'gcc>) {
478474
// TODO(antoyo)
479475
}

src/debuginfo.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
5252
fn clear_dbg_loc(&mut self) {
5353
self.location = None;
5454
}
55-
56-
fn get_dbg_loc(&self) -> Option<Self::DILocation> {
57-
self.location
58-
}
5955
}
6056

6157
/// Generate the `debug_context` in an MIR Body.

src/int.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
//! 128-bit integers on 32-bit platforms and thus require to be handled manually.
44
55
use gccjit::{BinaryOp, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp};
6-
use rustc_abi::{Endian, ExternAbi};
6+
use rustc_abi::{CanonAbi, Endian, ExternAbi};
77
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
88
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, BuilderMethods, OverflowOp};
99
use rustc_middle::ty::{self, Ty};
10-
use rustc_target::callconv::{ArgAbi, ArgAttributes, Conv, FnAbi, PassMode};
10+
use rustc_target::callconv::{ArgAbi, ArgAttributes, FnAbi, PassMode};
1111

1212
use crate::builder::{Builder, ToGccComp};
1313
use crate::common::{SignType, TypeReflection};
@@ -397,7 +397,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
397397
ret: arg_abi,
398398
c_variadic: false,
399399
fixed_count: 3,
400-
conv: Conv::C,
400+
conv: CanonAbi::C,
401401
can_unwind: false,
402402
};
403403
fn_abi.adjust_for_foreign_abi(self.cx, ExternAbi::C { unwind: false });

0 commit comments

Comments
 (0)