diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index d64c8de6ed7aa..1059de3c0aec0 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -1234,7 +1234,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// Helper method for the sequence of calls: /// - `LLVMMDNodeInContext2` (to create an `llvm::MDNode` from a list of metadata) - /// - `LLVMRustGlobalAddMetadata` (to set that node as metadata of `kind_id` for `global`) + /// - `LLVMGlobalAddMetadata` (to set that node as metadata of `kind_id` for `global`) pub(crate) fn global_add_metadata_node( &self, global: &'ll Value, @@ -1242,7 +1242,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { md_list: &[&'ll Metadata], ) { let md = self.md_node_in_context(md_list); - unsafe { llvm::LLVMRustGlobalAddMetadata(global, kind_id, md) }; + unsafe { llvm::LLVMGlobalAddMetadata(global, kind_id, md) }; } /// Helper method for the sequence of calls: diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index 3511056f79306..95f8f9e50a516 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -43,9 +43,7 @@ pub(crate) fn declare_simple_fn<'ll>( ty: &'ll Type, ) -> &'ll Value { debug!("declare_simple_fn(name={:?}, ty={:?})", name, ty); - let llfn = unsafe { - llvm::LLVMRustGetOrInsertFunction(cx.llmod, name.as_c_char_ptr(), name.len(), ty) - }; + let llfn = unsafe { llvm::LLVMGetOrInsertFunction(cx.llmod, name.as_ptr(), name.len(), ty) }; llvm::SetFunctionCallConv(llfn, callconv); llvm::set_unnamed_address(llfn, unnamed); diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index eca5fe429f541..345584cfdbdfc 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -993,6 +993,11 @@ unsafe extern "C" { KindID: MetadataKindId, Metadata: &'a Metadata, ); + pub(crate) fn LLVMGlobalAddMetadata<'ll>( + Global: &'ll Value, + Kind: MetadataKindId, + MD: &'ll Metadata, + ); pub(crate) safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata; // Operations on constants of any type @@ -1124,6 +1129,12 @@ unsafe extern "C" { Name: *const c_char, FunctionTy: &'a Type, ) -> &'a Value; + pub(crate) fn LLVMGetOrInsertFunction<'ll>( + M: &'ll Module, + Name: *const c_uchar, // See "PTR_LEN_STR". + NameLen: size_t, + FunctionTy: &'ll Type, + ) -> &'ll Value; pub(crate) fn LLVMDeleteFunction(Fn: &Value); // Operations about llvm intrinsics @@ -1962,12 +1973,6 @@ unsafe extern "C" { pub(crate) fn LLVMRustDisableSystemDialogsOnCrash(); // Operations on all values - /// FIXME: After dropping LLVM 21, migrate to LLVM-C's `LLVMGlobalAddMetadata`. - pub(crate) fn LLVMRustGlobalAddMetadata<'a>( - Val: &'a Value, - KindID: MetadataKindId, - Metadata: &'a Metadata, - ); pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool; pub(crate) fn LLVMRustStripPointerCasts<'a>(Val: &'a Value) -> &'a Value; @@ -2033,13 +2038,6 @@ unsafe extern "C" { ) -> &Attribute; // Operations on functions - /// FIXME: After dropping LLVM 21, migrate to LLVM-C's `LLVMGetOrInsertFunction`. - pub(crate) fn LLVMRustGetOrInsertFunction<'a>( - M: &'a Module, - Name: *const c_char, - NameLen: size_t, - FunctionTy: &'a Type, - ) -> &'a Value; pub(crate) fn LLVMRustAddFunctionAttributes<'a>( Fn: &'a Value, index: c_uint, diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 16c7daf66f095..62aa8c5c57aae 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -195,16 +195,6 @@ LLVMRustVerifyFunction(LLVMValueRef Fn, LLVMRustVerifierFailureAction Action) { return LLVMVerifyFunction(Fn, fromRust(Action)); } -extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M, - const char *Name, - size_t NameLen, - LLVMTypeRef FunctionTy) { - return wrap(unwrap(M) - ->getOrInsertFunction(StringRef(Name, NameLen), - unwrap(FunctionTy)) - .getCallee()); -} - // Get the global variable with the given name if it exists or create a new // external global. extern "C" LLVMValueRef @@ -1012,11 +1002,6 @@ extern "C" void LLVMRustRemoveFnAttribute(LLVMValueRef Fn, const char *Name, } } -extern "C" void LLVMRustGlobalAddMetadata(LLVMValueRef Global, unsigned Kind, - LLVMMetadataRef MD) { - unwrap(Global)->addMetadata(Kind, *unwrap(MD)); -} - extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit( LLVMDIBuilderRef Builder, unsigned Lang, LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, bool isOptimized,