diff options
| author | Manuel Drehwald <git@manuel.drehwald.info> | 2025-01-01 21:42:45 +0100 |
|---|---|---|
| committer | Manuel Drehwald <git@manuel.drehwald.info> | 2025-01-01 21:42:45 +0100 |
| commit | d753cbf7793f20229ed7a151d060456a9e1396e9 (patch) | |
| tree | 2a885dd222de7440293c7159de4d4c5f9e82bd45 /compiler/rustc_codegen_llvm/src/context.rs | |
| parent | 372442fe5ff1a2d06f4119f2b2e7d1e42388a0d3 (diff) | |
| download | rust-d753cbf7793f20229ed7a151d060456a9e1396e9.tar.gz rust-d753cbf7793f20229ed7a151d060456a9e1396e9.zip | |
upstream rustc_codegen_llvm changes for enzyme/autodiff
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/context.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/context.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index c602d99ff9d..d8fbe51b975 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -1,6 +1,6 @@ use std::borrow::Borrow; use std::cell::{Cell, RefCell}; -use std::ffi::{CStr, c_uint}; +use std::ffi::{CStr, c_char, c_uint}; use std::str; use rustc_abi::{HasDataLayout, TargetDataLayout, VariantIdx}; @@ -600,6 +600,31 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { llvm::set_section(g, c"llvm.metadata"); } } + + pub(crate) fn get_metadata_value(&self, metadata: &'ll Metadata) -> &'ll Value { + unsafe { llvm::LLVMMetadataAsValue(self.llcx, metadata) } + } + + pub(crate) fn get_function(&self, name: &str) -> Option<&'ll Value> { + let name = SmallCStr::new(name); + unsafe { llvm::LLVMGetNamedFunction(self.llmod, name.as_ptr()) } + } + + pub(crate) fn get_md_kind_id(&self, name: &str) -> u32 { + unsafe { + llvm::LLVMGetMDKindIDInContext( + self.llcx, + name.as_ptr() as *const c_char, + name.len() as c_uint, + ) + } + } + + pub(crate) fn create_metadata(&self, name: String) -> Option<&'ll Metadata> { + Some(unsafe { + llvm::LLVMMDStringInContext2(self.llcx, name.as_ptr() as *const c_char, name.len()) + }) + } } impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { |
