diff options
| author | bors <bors@rust-lang.org> | 2025-04-05 03:09:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-04-05 03:09:33 +0000 |
| commit | 1e008dd5d83e782ad37fc9cf6824733f824cc8cd (patch) | |
| tree | f41496f629002b9a8f91afa2b50206a7d485e72f /compiler/rustc_codegen_llvm/src/context.rs | |
| parent | bad13a970a136389187dd1cf2f2fc737a8bea5fc (diff) | |
| parent | e31ce50698b40f36056f1e13f7f320ebdb38a102 (diff) | |
| download | rust-1e008dd5d83e782ad37fc9cf6824733f824cc8cd.tar.gz rust-1e008dd5d83e782ad37fc9cf6824733f824cc8cd.zip | |
Auto merge of #139396 - Zalathar:rollup-lmoqvru, r=Zalathar
Rollup of 11 pull requests Successful merges: - #136457 (Expose algebraic floating point intrinsics) - #137880 (Autodiff batching) - #137897 (fix pthread-based tls on apple targets) - #138024 (Allow optimizing out `panic_bounds_check` in Unicode checks.) - #138546 (Add integer to string formatting tests) - #138826 (StableMIR: Add `associated_items`.) - #138950 (replace extra_filename with strict version hash in metrics file names) - #139274 (Rustdoc: typecheck settings.js) - #139285 (use lower case to match other error messages) - #139341 (Apply `Recovery::Forbidden` when reparsing pasted macro fragments.) - #139389 (make `Arguments::as_statically_known_str` doc(hidden)) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/context.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/context.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index f7b096ff976..3be8cd5f6ac 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -8,6 +8,7 @@ use std::str; use rustc_abi::{HasDataLayout, Size, TargetDataLayout, VariantIdx}; use rustc_codegen_ssa::back::versioned_llvm_target; use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh}; +use rustc_codegen_ssa::common::TypeKind; use rustc_codegen_ssa::errors as ssa_errors; use rustc_codegen_ssa::traits::*; use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN}; @@ -38,7 +39,7 @@ use crate::debuginfo::metadata::apply_vcall_visibility_metadata; use crate::llvm::Metadata; use crate::type_::Type; use crate::value::Value; -use crate::{attributes, coverageinfo, debuginfo, llvm, llvm_util}; +use crate::{attributes, common, coverageinfo, debuginfo, llvm, llvm_util}; /// `TyCtxt` (and related cache datastructures) can't be move between threads. /// However, there are various cx related functions which we want to be available to the builder and @@ -643,7 +644,18 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { llvm::set_section(g, c"llvm.metadata"); } } - +impl<'ll> SimpleCx<'ll> { + pub(crate) fn get_return_type(&self, ty: &'ll Type) -> &'ll Type { + assert_eq!(self.type_kind(ty), TypeKind::Function); + unsafe { llvm::LLVMGetReturnType(ty) } + } + pub(crate) fn get_type_of_global(&self, val: &'ll Value) -> &'ll Type { + unsafe { llvm::LLVMGlobalGetValueType(val) } + } + pub(crate) fn val_ty(&self, v: &'ll Value) -> &'ll Type { + common::val_ty(v) + } +} impl<'ll> SimpleCx<'ll> { pub(crate) fn new( llmod: &'ll llvm::Module, @@ -660,6 +672,13 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> { llvm::LLVMMetadataAsValue(self.llcx(), metadata) } + // FIXME(autodiff): We should split `ConstCodegenMethods` to pull the reusable parts + // onto a trait that is also implemented for GenericCx. + pub(crate) fn get_const_i64(&self, n: u64) -> &'ll Value { + let ty = unsafe { llvm::LLVMInt64TypeInContext(self.llcx()) }; + unsafe { llvm::LLVMConstInt(ty, n, llvm::False) } + } + pub(crate) fn get_function(&self, name: &str) -> Option<&'ll Value> { let name = SmallCStr::new(name); unsafe { llvm::LLVMGetNamedFunction((**self).borrow().llmod, name.as_ptr()) } |
