Skip to content

Commit

Permalink
Remove LLVMMDNodeInContext.
Browse files Browse the repository at this point in the history
Because it's deprecated in LLVM. Use `LLVMMDNodeInContext2` instead.
  • Loading branch information
nnethercote committed Sep 18, 2024
1 parent 5da0745 commit 3a78ab4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 36 deletions.
18 changes: 14 additions & 4 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,21 @@ pub(crate) fn inline_asm_call<'ll>(
// due to the asm template string coming from a macro. LLVM will
// default to the first srcloc for lines that don't have an
// associated srcloc.
srcloc.push(bx.const_i32(0));
srcloc.push(llvm::LLVMValueAsMetadata(bx.const_i32(0)));
}
srcloc.extend(line_spans.iter().map(|span| bx.const_i32(span.lo().to_u32() as i32)));
let md = llvm::LLVMMDNodeInContext(bx.llcx, srcloc.as_ptr(), srcloc.len() as u32);
llvm::LLVMSetMetadata(call, kind, md);
srcloc.extend(
line_spans
.iter()
.map(|span| llvm::LLVMValueAsMetadata(bx.const_i32(span.lo().to_u32() as i32))),
);
llvm::LLVMSetMetadata(
call,
kind,
llvm::LLVMMetadataAsValue(
bx.llcx,
llvm::LLVMMDNodeInContext2(bx.llcx, srcloc.as_ptr(), srcloc.len()),
),
);

Some(call)
} else {
Expand Down
53 changes: 40 additions & 13 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,15 +683,18 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {

unsafe {
let llty = self.cx.val_ty(load);
let v = [
self.cx.const_uint_big(llty, range.start),
self.cx.const_uint_big(llty, range.end.wrapping_add(1)),
let md = [
llvm::LLVMValueAsMetadata(self.cx.const_uint_big(llty, range.start)),
llvm::LLVMValueAsMetadata(self.cx.const_uint_big(llty, range.end.wrapping_add(1))),
];

llvm::LLVMSetMetadata(
load,
llvm::MD_range as c_uint,
llvm::LLVMMDNodeInContext(self.cx.llcx, v.as_ptr(), v.len() as c_uint),
llvm::LLVMMetadataAsValue(
self.cx.llcx,
llvm::LLVMMDNodeInContext2(self.cx.llcx, md.as_ptr(), md.len()),
),
);
}
}
Expand All @@ -701,7 +704,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
llvm::LLVMSetMetadata(
load,
llvm::MD_nonnull as c_uint,
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
llvm::LLVMMetadataAsValue(
self.cx.llcx,
llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0),
),
);
}
}
Expand Down Expand Up @@ -750,9 +756,18 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
// *always* point to a metadata value of the integer 1.
//
// [1]: https://llvm.org/docs/LangRef.html#store-instruction
let one = self.cx.const_i32(1);
let node = llvm::LLVMMDNodeInContext(self.cx.llcx, &one, 1);
llvm::LLVMSetMetadata(store, llvm::MD_nontemporal as c_uint, node);
llvm::LLVMSetMetadata(
store,
llvm::MD_nontemporal as c_uint,
llvm::LLVMMetadataAsValue(
self.cx.llcx,
llvm::LLVMMDNodeInContext2(
self.cx.llcx,
&llvm::LLVMValueAsMetadata(self.cx.const_i32(1)),
1,
),
),
);
}
}
store
Expand Down Expand Up @@ -1219,7 +1234,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
llvm::LLVMSetMetadata(
load,
llvm::MD_invariant_load as c_uint,
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
llvm::LLVMMetadataAsValue(
self.cx.llcx,
llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0),
),
);
}
}
Expand Down Expand Up @@ -1355,12 +1373,15 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {

fn align_metadata(&mut self, load: &'ll Value, align: Align) {
unsafe {
let v = [self.cx.const_u64(align.bytes())];
let md = [llvm::LLVMValueAsMetadata(self.cx.const_u64(align.bytes()))];

llvm::LLVMSetMetadata(
load,
llvm::MD_align as c_uint,
llvm::LLVMMDNodeInContext(self.cx.llcx, v.as_ptr(), v.len() as c_uint),
llvm::LLVMMetadataAsValue(
self.cx.llcx,
llvm::LLVMMDNodeInContext2(self.cx.llcx, md.as_ptr(), md.len()),
),
);
}
}
Expand All @@ -1370,7 +1391,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
llvm::LLVMSetMetadata(
load,
llvm::MD_noundef as c_uint,
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
llvm::LLVMMetadataAsValue(
self.cx.llcx,
llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0),
),
);
}
}
Expand All @@ -1380,7 +1404,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
llvm::LLVMSetMetadata(
inst,
llvm::MD_unpredictable as c_uint,
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
llvm::LLVMMetadataAsValue(
self.cx.llcx,
llvm::LLVMMDNodeInContext2(self.cx.llcx, ptr::null(), 0),
),
);
}
}
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,13 +913,6 @@ unsafe extern "C" {

// Operations on metadata
pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;

// FIXME: deprecated, replace with LLVMMDNodeInContext2
pub fn LLVMMDNodeInContext<'a>(
C: &'a Context,
Vals: *const &'a Value,
Count: c_uint,
) -> &'a Value;
pub fn LLVMMDNodeInContext2<'a>(
C: &'a Context,
Vals: *const &'a Metadata,
Expand Down
22 changes: 10 additions & 12 deletions compiler/rustc_codegen_llvm/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,32 +283,30 @@ impl<'ll, 'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
impl<'ll, 'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'ll, 'tcx> {
fn add_type_metadata(&self, function: &'ll Value, typeid: String) {
let typeid_metadata = self.typeid_metadata(typeid).unwrap();
let v = [self.const_usize(0), typeid_metadata];
unsafe {
let meta = [
llvm::LLVMValueAsMetadata(self.const_usize(0)),
llvm::LLVMValueAsMetadata(typeid_metadata),
];
llvm::LLVMRustGlobalAddMetadata(
function,
llvm::MD_type as c_uint,
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
self.llcx,
v.as_ptr(),
v.len() as c_uint,
)),
llvm::LLVMMDNodeInContext2(self.llcx, meta.as_ptr(), meta.len()),
)
}
}

fn set_type_metadata(&self, function: &'ll Value, typeid: String) {
let typeid_metadata = self.typeid_metadata(typeid).unwrap();
let v = [self.const_usize(0), typeid_metadata];
unsafe {
let meta = [
llvm::LLVMValueAsMetadata(self.const_usize(0)),
llvm::LLVMValueAsMetadata(typeid_metadata),
];
llvm::LLVMGlobalSetMetadata(
function,
llvm::MD_type as c_uint,
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
self.llcx,
v.as_ptr(),
v.len() as c_uint,
)),
llvm::LLVMMDNodeInContext2(self.llcx, meta.as_ptr(), meta.len()),
)
}
}
Expand Down

0 comments on commit 3a78ab4

Please sign in to comment.