mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Drop Layout::alignment_bytes_for_llvm
This commit is contained in:
parent
f95cef8086
commit
5b0d47c9eb
3 changed files with 0 additions and 126 deletions
|
@ -54,22 +54,6 @@ impl FloatWidth {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn alignment_bytes_for_llvm(&self, target_info: TargetInfo) -> u32 {
|
||||
use roc_target::Architecture::*;
|
||||
use FloatWidth::*;
|
||||
|
||||
// NOTE: this must never use mem::align_of, because that returns the alignment
|
||||
// for the target of *the compiler itself* (e.g. this Rust code), not what
|
||||
// the compiler is targeting (e.g. what the Roc code will be compiled to).
|
||||
match self {
|
||||
F32 => 4,
|
||||
F64 => match target_info.architecture {
|
||||
X86_64 | Aarch64 | Wasm32 => 8,
|
||||
X86_32 | Aarch32 => 4,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn try_from_symbol(symbol: Symbol) -> Option<Self> {
|
||||
match symbol {
|
||||
Symbol::NUM_F64 | Symbol::NUM_BINARY64 => Some(FloatWidth::F64),
|
||||
|
@ -142,28 +126,6 @@ impl IntWidth {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn alignment_bytes_for_llvm(&self, target_info: TargetInfo) -> u32 {
|
||||
use roc_target::Architecture;
|
||||
use IntWidth::*;
|
||||
|
||||
// NOTE: this must never use mem::align_of, because that returns the alignment
|
||||
// for the target of *the compiler itself* (e.g. this Rust code), not what
|
||||
// the compiler is targeting (e.g. what the Roc code will be compiled to).
|
||||
match self {
|
||||
U8 | I8 => 1,
|
||||
U16 | I16 => 2,
|
||||
U32 | I32 => 4,
|
||||
U64 | I64 => match target_info.architecture {
|
||||
Architecture::X86_64
|
||||
| Architecture::Aarch64
|
||||
| Architecture::Aarch32
|
||||
| Architecture::Wasm32 => 8,
|
||||
Architecture::X86_32 => 4,
|
||||
},
|
||||
U128 | I128 => 8,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn try_from_symbol(symbol: Symbol) -> Option<Self> {
|
||||
match symbol {
|
||||
Symbol::NUM_I128 | Symbol::NUM_SIGNED128 => Some(IntWidth::I128),
|
||||
|
|
|
@ -2734,65 +2734,6 @@ impl<'a> LayoutRepr<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn alignment_bytes_for_llvm<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use LayoutRepr::*;
|
||||
match self {
|
||||
Struct(field_layouts) => field_layouts
|
||||
.iter()
|
||||
.map(|x| {
|
||||
interner
|
||||
.get_repr(*x)
|
||||
.alignment_bytes_for_llvm(interner, target_info)
|
||||
})
|
||||
.max()
|
||||
.unwrap_or(0),
|
||||
|
||||
Union(variant) => {
|
||||
use UnionLayout::*;
|
||||
|
||||
match variant {
|
||||
NonRecursive(tags) => {
|
||||
let max_alignment = tags
|
||||
.iter()
|
||||
.flat_map(|layouts| {
|
||||
layouts.iter().map(|layout| {
|
||||
interner
|
||||
.get_repr(*layout)
|
||||
.alignment_bytes_for_llvm(interner, target_info)
|
||||
})
|
||||
})
|
||||
.max();
|
||||
|
||||
let discriminant = variant.discriminant();
|
||||
match max_alignment {
|
||||
Some(align) => round_up_to_alignment(
|
||||
align.max(discriminant.alignment_bytes()),
|
||||
discriminant.alignment_bytes(),
|
||||
),
|
||||
None => {
|
||||
// none of the tags had any payload, but the tag id still contains information
|
||||
discriminant.alignment_bytes()
|
||||
}
|
||||
}
|
||||
}
|
||||
Recursive(_)
|
||||
| NullableWrapped { .. }
|
||||
| NullableUnwrapped { .. }
|
||||
| NonNullableUnwrapped(_) => target_info.ptr_width() as u32,
|
||||
}
|
||||
}
|
||||
LambdaSet(lambda_set) => interner
|
||||
.get_repr(lambda_set.runtime_representation())
|
||||
.alignment_bytes_for_llvm(interner, target_info),
|
||||
Builtin(builtin) => builtin.alignment_bytes_for_llvm(target_info),
|
||||
RecursivePointer(_) => target_info.ptr_width() as u32,
|
||||
Boxed(_) => target_info.ptr_width() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allocation_alignment_bytes<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: LayoutInterner<'a>,
|
||||
|
@ -3056,30 +2997,6 @@ impl<'a> Builtin<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn alignment_bytes_for_llvm(&self, target_info: TargetInfo) -> u32 {
|
||||
use std::mem::align_of;
|
||||
use Builtin::*;
|
||||
|
||||
let ptr_width = target_info.ptr_width() as u32;
|
||||
|
||||
// for our data structures, what counts is the alignment of the `( ptr, len )` tuple, and
|
||||
// since both of those are one pointer size, the alignment of that structure is a pointer
|
||||
// size
|
||||
match self {
|
||||
Int(int_width) => int_width.alignment_bytes_for_llvm(target_info),
|
||||
Float(float_width) => float_width.alignment_bytes_for_llvm(target_info),
|
||||
Bool => align_of::<bool>() as u32,
|
||||
Decimal => IntWidth::I128.alignment_bytes_for_llvm(target_info),
|
||||
// we often treat these as i128 (64-bit systems)
|
||||
// or i64 (32-bit systems).
|
||||
//
|
||||
// In webassembly, For that to be safe
|
||||
// they must be aligned to allow such access
|
||||
List(_) => ptr_width,
|
||||
Str => ptr_width,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn safe_to_memcpy(&self) -> bool {
|
||||
use Builtin::*;
|
||||
|
||||
|
|
|
@ -207,11 +207,6 @@ pub trait LayoutInterner<'a>: Sized {
|
|||
.alignment_bytes(self, self.target_info())
|
||||
}
|
||||
|
||||
fn alignment_bytes_for_llvm(&self, layout: InLayout<'a>) -> u32 {
|
||||
self.get_repr(layout)
|
||||
.alignment_bytes_for_llvm(self, self.target_info())
|
||||
}
|
||||
|
||||
fn allocation_alignment_bytes(&self, layout: InLayout<'a>) -> u32 {
|
||||
self.get_repr(layout)
|
||||
.allocation_alignment_bytes(self, self.target_info())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue