Skip to content

Commit cc6329a

Browse files
committed
Replace MetadataType with the MetadataKindId constants
1 parent 906bf49 commit cc6329a

File tree

6 files changed

+17
-49
lines changed

6 files changed

+17
-49
lines changed

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use smallvec::SmallVec;
3434
use crate::back::write::to_llvm_code_model;
3535
use crate::callee::get_fn;
3636
use crate::debuginfo::metadata::apply_vcall_visibility_metadata;
37-
use crate::llvm::Metadata;
37+
use crate::llvm::{Metadata, MetadataKindId};
3838
use crate::type_::Type;
3939
use crate::value::Value;
4040
use crate::{attributes, common, coverageinfo, debuginfo, llvm, llvm_util};
@@ -1006,11 +1006,11 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
10061006
pub(crate) fn set_metadata<'a>(
10071007
&self,
10081008
val: &'a Value,
1009-
kind_id: impl Into<llvm::MetadataKindId>,
1009+
kind_id: MetadataKindId,
10101010
md: &'ll Metadata,
10111011
) {
10121012
let node = self.get_metadata_value(md);
1013-
llvm::LLVMSetMetadata(val, kind_id.into(), node);
1013+
llvm::LLVMSetMetadata(val, kind_id, node);
10141014
}
10151015
}
10161016

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,16 +1611,12 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
16111611
let v = [llvm::LLVMValueAsMetadata(cx.const_usize(0)), typeid];
16121612
llvm::LLVMRustGlobalAddMetadata(
16131613
vtable,
1614-
llvm::MD_type as c_uint,
1614+
llvm::MD_type,
16151615
llvm::LLVMMDNodeInContext2(cx.llcx, v.as_ptr(), v.len()),
16161616
);
16171617
let vcall_visibility = llvm::LLVMValueAsMetadata(cx.const_u64(vcall_visibility as u64));
16181618
let vcall_visibility_metadata = llvm::LLVMMDNodeInContext2(cx.llcx, &vcall_visibility, 1);
1619-
llvm::LLVMGlobalSetMetadata(
1620-
vtable,
1621-
llvm::MetadataType::MD_vcall_visibility as c_uint,
1622-
vcall_visibility_metadata,
1623-
);
1619+
llvm::LLVMGlobalSetMetadata(vtable, llvm::MD_vcall_visibility, vcall_visibility_metadata);
16241620
}
16251621
}
16261622

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -514,31 +514,6 @@ pub(crate) enum FileType {
514514
ObjectFile,
515515
}
516516

517-
/// LLVMMetadataType
518-
#[derive(Copy, Clone)]
519-
#[repr(C)]
520-
#[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")]
521-
pub(crate) enum MetadataType {
522-
MD_dbg = 0,
523-
MD_tbaa = 1,
524-
MD_prof = 2,
525-
MD_fpmath = 3,
526-
MD_range = 4,
527-
MD_tbaa_struct = 5,
528-
MD_invariant_load = 6,
529-
MD_alias_scope = 7,
530-
MD_noalias = 8,
531-
MD_nontemporal = 9,
532-
MD_mem_parallel_loop_access = 10,
533-
MD_nonnull = 11,
534-
MD_unpredictable = 15,
535-
MD_align = 17,
536-
MD_type = 19,
537-
MD_vcall_visibility = 28,
538-
MD_noundef = 29,
539-
MD_kcfi_type = 36,
540-
}
541-
542517
/// Must match the layout of `LLVMInlineAsmDialect`.
543518
#[derive(Copy, Clone, PartialEq)]
544519
#[repr(C)]
@@ -1130,7 +1105,11 @@ unsafe extern "C" {
11301105
pub(crate) fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t);
11311106
pub(crate) fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value);
11321107
pub(crate) safe fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: MetadataKindId, Node: &'a Value);
1133-
pub(crate) fn LLVMGlobalSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
1108+
pub(crate) fn LLVMGlobalSetMetadata<'a>(
1109+
Val: &'a Value,
1110+
KindID: MetadataKindId,
1111+
Metadata: &'a Metadata,
1112+
);
11341113
pub(crate) safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata;
11351114

11361115
// Operations on constants of any type
@@ -2050,7 +2029,7 @@ unsafe extern "C" {
20502029
// Operations on all values
20512030
pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
20522031
Val: &'a Value,
2053-
KindID: c_uint,
2032+
KindID: MetadataKindId,
20542033
Metadata: &'a Metadata,
20552034
);
20562035
pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool;

compiler/rustc_codegen_llvm/src/llvm/metadata_kind.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
use libc::c_uint;
22

3-
use crate::llvm::MetadataType;
3+
pub(crate) use self::fixed_kinds::*;
44

55
#[derive(Copy, Clone)]
66
#[repr(transparent)]
77
pub(crate) struct MetadataKindId(c_uint);
88

9-
impl From<MetadataType> for MetadataKindId {
10-
fn from(value: MetadataType) -> Self {
11-
Self(value as c_uint)
12-
}
13-
}
14-
159
macro_rules! declare_fixed_metadata_kinds {
1610
(
1711
$(

compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use rustc_llvm::RustString;
1111

1212
pub(crate) use self::CallConv::*;
1313
pub(crate) use self::CodeGenOptSize::*;
14-
pub(crate) use self::MetadataType::*;
1514
pub(crate) use self::ffi::*;
16-
pub(crate) use self::metadata_kind::MetadataKindId;
15+
pub(crate) use self::metadata_kind::*;
1716
use crate::common::AsCCharPtr;
1817

1918
pub(crate) mod diagnostic;

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
306306
let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata];
307307
llvm::LLVMRustGlobalAddMetadata(
308308
function,
309-
llvm::MD_type as c_uint,
309+
llvm::MD_type,
310310
llvm::LLVMMDNodeInContext2(self.llcx, v.as_ptr(), v.len()),
311311
)
312312
}
@@ -318,7 +318,7 @@ impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
318318
let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata];
319319
llvm::LLVMGlobalSetMetadata(
320320
function,
321-
llvm::MD_type as c_uint,
321+
llvm::MD_type,
322322
llvm::LLVMMDNodeInContext2(self.llcx, v.as_ptr(), v.len()),
323323
)
324324
}
@@ -333,7 +333,7 @@ impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
333333
unsafe {
334334
llvm::LLVMRustGlobalAddMetadata(
335335
function,
336-
llvm::MD_kcfi_type as c_uint,
336+
llvm::MD_kcfi_type,
337337
llvm::LLVMMDNodeInContext2(
338338
self.llcx,
339339
&llvm::LLVMValueAsMetadata(kcfi_type_metadata),
@@ -348,7 +348,7 @@ impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
348348
unsafe {
349349
llvm::LLVMGlobalSetMetadata(
350350
function,
351-
llvm::MD_kcfi_type as c_uint,
351+
llvm::MD_kcfi_type,
352352
llvm::LLVMMDNodeInContext2(
353353
self.llcx,
354354
&llvm::LLVMValueAsMetadata(kcfi_type_metadata),

0 commit comments

Comments
 (0)