summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_llvm/src/common.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_codegen_llvm/src/common.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/common.rs')
-rw-r--r--compiler/rustc_codegen_llvm/src/common.rs53
1 files changed, 21 insertions, 32 deletions
diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs
index 9127fba38..a2db59bd6 100644
--- a/compiler/rustc_codegen_llvm/src/common.rs
+++ b/compiler/rustc_codegen_llvm/src/common.rs
@@ -8,16 +8,15 @@ use crate::type_of::LayoutLlvmExt;
use crate::value::Value;
use rustc_ast::Mutability;
-use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::*;
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
use rustc_hir::def_id::DefId;
use rustc_middle::bug;
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
-use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
+use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::TyCtxt;
use rustc_session::cstore::{DllCallingConvention, DllImport, PeImportNameType};
-use rustc_target::abi::{self, AddressSpace, HasDataLayout, Pointer, Size};
+use rustc_target::abi::{self, AddressSpace, HasDataLayout, Pointer};
use rustc_target::spec::Target;
use libc::{c_char, c_uint};
@@ -169,6 +168,10 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
self.const_uint(self.type_i64(), i)
}
+ fn const_u128(&self, i: u128) -> &'ll Value {
+ self.const_uint_big(self.type_i128(), i)
+ }
+
fn const_usize(&self, i: u64) -> &'ll Value {
let bit_size = self.data_layout().pointer_size.bits();
if bit_size < 64 {
@@ -307,38 +310,24 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
const_alloc_to_llvm(self, alloc)
}
- fn from_const_alloc(
- &self,
- layout: TyAndLayout<'tcx>,
- alloc: ConstAllocation<'tcx>,
- offset: Size,
- ) -> PlaceRef<'tcx, &'ll Value> {
- let alloc_align = alloc.inner().align;
- assert_eq!(alloc_align, layout.align.abi);
- let llty = self.type_ptr_to(layout.llvm_type(self));
- let llval = if layout.size == Size::ZERO {
- let llval = self.const_usize(alloc_align.bytes());
- unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
- } else {
- let init = const_alloc_to_llvm(self, alloc);
- let base_addr = self.static_addr_of(init, alloc_align, None);
-
- let llval = unsafe {
- llvm::LLVMRustConstInBoundsGEP2(
- self.type_i8(),
- self.const_bitcast(base_addr, self.type_i8p()),
- &self.const_usize(offset.bytes()),
- 1,
- )
- };
- self.const_bitcast(llval, llty)
- };
- PlaceRef::new_sized(llval, layout)
- }
-
fn const_ptrcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {
consts::ptrcast(val, ty)
}
+
+ fn const_bitcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {
+ self.const_bitcast(val, ty)
+ }
+
+ fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
+ unsafe {
+ llvm::LLVMRustConstInBoundsGEP2(
+ self.type_i8(),
+ self.const_bitcast(base_addr, self.type_i8p()),
+ &self.const_usize(offset.bytes()),
+ 1,
+ )
+ }
+ }
}
/// Get the [LLVM type][Type] of a [`Value`].