summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_cranelift/src/common.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_codegen_cranelift/src/common.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src/common.rs')
-rw-r--r--compiler/rustc_codegen_cranelift/src/common.rs77
1 files changed, 30 insertions, 47 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs
index 359b430b4..63562d335 100644
--- a/compiler/rustc_codegen_cranelift/src/common.rs
+++ b/compiler/rustc_codegen_cranelift/src/common.rs
@@ -1,6 +1,5 @@
use cranelift_codegen::isa::TargetFrontendConfig;
use gimli::write::FileId;
-
use rustc_data_structures::sync::Lrc;
use rustc_index::IndexVec;
use rustc_middle::ty::layout::{
@@ -204,9 +203,9 @@ pub(crate) fn type_min_max_value(
(types::I8, false) | (types::I16, false) | (types::I32, false) | (types::I64, false) => {
0i64
}
- (types::I8, true) => i64::from(i8::MIN),
- (types::I16, true) => i64::from(i16::MIN),
- (types::I32, true) => i64::from(i32::MIN),
+ (types::I8, true) => i64::from(i8::MIN as u8),
+ (types::I16, true) => i64::from(i16::MIN as u16),
+ (types::I32, true) => i64::from(i32::MIN as u32),
(types::I64, true) => i64::MIN,
_ => unreachable!(),
};
@@ -216,9 +215,9 @@ pub(crate) fn type_min_max_value(
(types::I16, false) => i64::from(u16::MAX),
(types::I32, false) => i64::from(u32::MAX),
(types::I64, false) => u64::MAX as i64,
- (types::I8, true) => i64::from(i8::MAX),
- (types::I16, true) => i64::from(i16::MAX),
- (types::I32, true) => i64::from(i32::MAX),
+ (types::I8, true) => i64::from(i8::MAX as u8),
+ (types::I16, true) => i64::from(i16::MAX as u16),
+ (types::I32, true) => i64::from(i32::MAX as u32),
(types::I64, true) => i64::MAX,
_ => unreachable!(),
};
@@ -384,6 +383,25 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
})
}
+ pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer {
+ if align <= 16 {
+ let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData {
+ kind: StackSlotKind::ExplicitSlot,
+ // FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to
+ // specify stack slot alignment.
+ size: (size + 15) / 16 * 16,
+ });
+ Pointer::stack_slot(stack_slot)
+ } else {
+ // Alignment is too big to handle using the above hack. Dynamically realign a stack slot
+ // instead. This wastes some space for the realignment.
+ let base_ptr = self.create_stack_slot(size + align, 16).get_addr(self);
+ let misalign_offset = self.bcx.ins().urem_imm(base_ptr, i64::from(align));
+ let realign_offset = self.bcx.ins().irsub_imm(misalign_offset, i64::from(align));
+ Pointer::new(self.bcx.ins().iadd(base_ptr, realign_offset))
+ }
+ }
+
pub(crate) fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
if let Some(debug_context) = &mut self.cx.debug_context {
let (file, line, column) =
@@ -412,46 +430,11 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
}
}
- // Note: must be kept in sync with get_caller_location from cg_ssa
- pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> {
- let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| {
- let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
- let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
- let const_loc = fx.tcx.const_caller_location((
- rustc_span::symbol::Symbol::intern(
- &caller.file.name.prefer_remapped().to_string_lossy(),
- ),
- caller.line as u32,
- caller.col_display as u32 + 1,
- ));
- crate::constant::codegen_const_value(fx, const_loc, fx.tcx.caller_location_ty())
- };
-
- // Walk up the `SourceScope`s, in case some of them are from MIR inlining.
- // If so, the starting `source_info.span` is in the innermost inlined
- // function, and will be replaced with outer callsite spans as long
- // as the inlined functions were `#[track_caller]`.
- loop {
- let scope_data = &self.mir.source_scopes[source_info.scope];
-
- if let Some((callee, callsite_span)) = scope_data.inlined {
- // Stop inside the most nested non-`#[track_caller]` function,
- // before ever reaching its caller (which is irrelevant).
- if !callee.def.requires_caller_location(self.tcx) {
- return span_to_caller_location(self, source_info.span);
- }
- source_info.span = callsite_span;
- }
-
- // Skip past all of the parents with `inlined: None`.
- match scope_data.inlined_parent_scope {
- Some(parent) => source_info.scope = parent,
- None => break,
- }
- }
-
- // No inlined `SourceScope`s, or all of them were `#[track_caller]`.
- self.caller_location.unwrap_or_else(|| span_to_caller_location(self, source_info.span))
+ pub(crate) fn get_caller_location(&mut self, source_info: mir::SourceInfo) -> CValue<'tcx> {
+ self.mir.caller_location_span(source_info, self.caller_location, self.tcx, |span| {
+ let const_loc = self.tcx.span_as_caller_location(span);
+ crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty())
+ })
}
pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value {