Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,15 +1234,15 @@ impl<'ll, CX: Borrow<SCx<'ll>>> 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,
kind_id: MetadataKindId,
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:
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_llvm/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 11 additions & 13 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 0 additions & 15 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionType>(FunctionTy))
.getCallee());
}

// Get the global variable with the given name if it exists or create a new
// external global.
extern "C" LLVMValueRef
Expand Down Expand Up @@ -1012,11 +1002,6 @@ extern "C" void LLVMRustRemoveFnAttribute(LLVMValueRef Fn, const char *Name,
}
}

extern "C" void LLVMRustGlobalAddMetadata(LLVMValueRef Global, unsigned Kind,
LLVMMetadataRef MD) {
unwrap<GlobalObject>(Global)->addMetadata(Kind, *unwrap<MDNode>(MD));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit(
LLVMDIBuilderRef Builder, unsigned Lang, LLVMMetadataRef FileRef,
const char *Producer, size_t ProducerLen, bool isOptimized,
Expand Down
Loading