Skip to content

Commit dd2b195

Browse files
committed
Auto merge of rust-lang#109862 - klensy:llvm-dd, r=nikic
llvm: replace some deprecated functions, add fixmes Replace some deprecated llvm functions, add FIXME's (for simpler future work), replace some rust custom functions with llvm ones.
2 parents 4f87a63 + fdfca76 commit dd2b195

File tree

9 files changed

+65
-136
lines changed

9 files changed

+65
-136
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl<'tcx> AsmMethods<'tcx> for CodegenCx<'_, 'tcx> {
381381
}
382382

383383
unsafe {
384-
llvm::LLVMRustAppendModuleInlineAsm(
384+
llvm::LLVMAppendModuleInlineAsm(
385385
self.llmod,
386386
template_str.as_ptr().cast(),
387387
template_str.len(),

compiler/rustc_codegen_llvm/src/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,9 @@ unsafe fn embed_bitcode(
904904
// We need custom section flags, so emit module-level inline assembly.
905905
let section_flags = if cgcx.is_pe_coff { "n" } else { "e" };
906906
let asm = create_section_with_flags_asm(".llvmbc", section_flags, bitcode);
907-
llvm::LLVMRustAppendModuleInlineAsm(llmod, asm.as_ptr().cast(), asm.len());
907+
llvm::LLVMAppendModuleInlineAsm(llmod, asm.as_ptr().cast(), asm.len());
908908
let asm = create_section_with_flags_asm(".llvmcmd", section_flags, cmdline.as_bytes());
909-
llvm::LLVMRustAppendModuleInlineAsm(llmod, asm.as_ptr().cast(), asm.len());
909+
llvm::LLVMAppendModuleInlineAsm(llmod, asm.as_ptr().cast(), asm.len());
910910
}
911911
}
912912

compiler/rustc_codegen_llvm/src/builder.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::abi::FnAbiLlvmExt;
22
use crate::attributes;
33
use crate::common::Funclet;
44
use crate::context::CodegenCx;
5-
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock};
5+
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, True};
66
use crate::type_::Type;
77
use crate::type_of::LayoutLlvmExt;
88
use crate::value::Value;
@@ -841,7 +841,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
841841
}
842842

843843
fn intcast(&mut self, val: &'ll Value, dest_ty: &'ll Type, is_signed: bool) -> &'ll Value {
844-
unsafe { llvm::LLVMRustBuildIntCast(self.llbuilder, val, dest_ty, is_signed) }
844+
unsafe {
845+
llvm::LLVMBuildIntCast2(
846+
self.llbuilder,
847+
val,
848+
dest_ty,
849+
if is_signed { True } else { False },
850+
UNNAMED,
851+
)
852+
}
845853
}
846854

847855
fn pointercast(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
@@ -1001,11 +1009,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10011009
fn cleanup_pad(&mut self, parent: Option<&'ll Value>, args: &[&'ll Value]) -> Funclet<'ll> {
10021010
let name = cstr!("cleanuppad");
10031011
let ret = unsafe {
1004-
llvm::LLVMRustBuildCleanupPad(
1012+
llvm::LLVMBuildCleanupPad(
10051013
self.llbuilder,
10061014
parent,
1007-
args.len() as c_uint,
10081015
args.as_ptr(),
1016+
args.len() as c_uint,
10091017
name.as_ptr(),
10101018
)
10111019
};
@@ -1014,19 +1022,19 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10141022

10151023
fn cleanup_ret(&mut self, funclet: &Funclet<'ll>, unwind: Option<&'ll BasicBlock>) {
10161024
unsafe {
1017-
llvm::LLVMRustBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)
1025+
llvm::LLVMBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)
10181026
.expect("LLVM does not have support for cleanupret");
10191027
}
10201028
}
10211029

10221030
fn catch_pad(&mut self, parent: &'ll Value, args: &[&'ll Value]) -> Funclet<'ll> {
10231031
let name = cstr!("catchpad");
10241032
let ret = unsafe {
1025-
llvm::LLVMRustBuildCatchPad(
1033+
llvm::LLVMBuildCatchPad(
10261034
self.llbuilder,
10271035
parent,
1028-
args.len() as c_uint,
10291036
args.as_ptr(),
1037+
args.len() as c_uint,
10301038
name.as_ptr(),
10311039
)
10321040
};
@@ -1041,7 +1049,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10411049
) -> &'ll Value {
10421050
let name = cstr!("catchswitch");
10431051
let ret = unsafe {
1044-
llvm::LLVMRustBuildCatchSwitch(
1052+
llvm::LLVMBuildCatchSwitch(
10451053
self.llbuilder,
10461054
parent,
10471055
unwind,
@@ -1052,7 +1060,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10521060
let ret = ret.expect("LLVM does not have support for catchswitch");
10531061
for handler in handlers {
10541062
unsafe {
1055-
llvm::LLVMRustAddHandler(ret, handler);
1063+
llvm::LLVMAddHandler(ret, handler);
10561064
}
10571065
}
10581066
ret
@@ -1376,8 +1384,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
13761384
}
13771385

13781386
pub fn catch_ret(&mut self, funclet: &Funclet<'ll>, unwind: &'ll BasicBlock) -> &'ll Value {
1379-
let ret =
1380-
unsafe { llvm::LLVMRustBuildCatchRet(self.llbuilder, funclet.cleanuppad(), unwind) };
1387+
let ret = unsafe { llvm::LLVMBuildCatchRet(self.llbuilder, funclet.cleanuppad(), unwind) };
13811388
ret.expect("LLVM does not have support for catchret")
13821389
}
13831390

compiler/rustc_codegen_llvm/src/consts.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::type_::Type;
77
use crate::type_of::LayoutLlvmExt;
88
use crate::value::Value;
99
use cstr::cstr;
10-
use libc::c_uint;
1110
use rustc_codegen_ssa::traits::*;
1211
use rustc_hir::def_id::DefId;
1312
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
@@ -486,10 +485,10 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
486485
// go into custom sections of the wasm executable.
487486
if self.tcx.sess.target.is_like_wasm {
488487
if let Some(section) = attrs.link_section {
489-
let section = llvm::LLVMMDStringInContext(
488+
let section = llvm::LLVMMDStringInContext2(
490489
self.llcx,
491490
section.as_str().as_ptr().cast(),
492-
section.as_str().len() as c_uint,
491+
section.as_str().len(),
493492
);
494493
assert!(alloc.provenance().ptrs().is_empty());
495494

@@ -498,17 +497,15 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
498497
// as part of the interpreter execution).
499498
let bytes =
500499
alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len());
501-
let alloc = llvm::LLVMMDStringInContext(
502-
self.llcx,
503-
bytes.as_ptr().cast(),
504-
bytes.len() as c_uint,
505-
);
500+
let alloc =
501+
llvm::LLVMMDStringInContext2(self.llcx, bytes.as_ptr().cast(), bytes.len());
506502
let data = [section, alloc];
507-
let meta = llvm::LLVMMDNodeInContext(self.llcx, data.as_ptr(), 2);
503+
let meta = llvm::LLVMMDNodeInContext2(self.llcx, data.as_ptr(), data.len());
504+
let val = llvm::LLVMMetadataAsValue(self.llcx, meta);
508505
llvm::LLVMAddNamedMetadataOperand(
509506
self.llmod,
510507
"wasm.custom_sections\0".as_ptr().cast(),
511-
meta,
508+
val,
512509
);
513510
}
514511
} else {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -864,29 +864,24 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
864864
);
865865

866866
if tcx.sess.opts.unstable_opts.profile {
867-
let cu_desc_metadata =
868-
llvm::LLVMRustMetadataAsValue(debug_context.llcontext, unit_metadata);
869867
let default_gcda_path = &output_filenames.with_extension("gcda");
870868
let gcda_path =
871869
tcx.sess.opts.unstable_opts.profile_emit.as_ref().unwrap_or(default_gcda_path);
872870

873871
let gcov_cu_info = [
874872
path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")),
875873
path_to_mdstring(debug_context.llcontext, gcda_path),
876-
cu_desc_metadata,
874+
unit_metadata,
877875
];
878-
let gcov_metadata = llvm::LLVMMDNodeInContext(
876+
let gcov_metadata = llvm::LLVMMDNodeInContext2(
879877
debug_context.llcontext,
880878
gcov_cu_info.as_ptr(),
881-
gcov_cu_info.len() as c_uint,
879+
gcov_cu_info.len(),
882880
);
881+
let val = llvm::LLVMMetadataAsValue(debug_context.llcontext, gcov_metadata);
883882

884883
let llvm_gcov_ident = cstr!("llvm.gcov");
885-
llvm::LLVMAddNamedMetadataOperand(
886-
debug_context.llmod,
887-
llvm_gcov_ident.as_ptr(),
888-
gcov_metadata,
889-
);
884+
llvm::LLVMAddNamedMetadataOperand(debug_context.llmod, llvm_gcov_ident.as_ptr(), val);
890885
}
891886

892887
// Insert `llvm.ident` metadata on the wasm targets since that will
@@ -907,15 +902,9 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
907902
return unit_metadata;
908903
};
909904

910-
fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll Value {
905+
fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll llvm::Metadata {
911906
let path_str = path_to_c_string(path);
912-
unsafe {
913-
llvm::LLVMMDStringInContext(
914-
llcx,
915-
path_str.as_ptr(),
916-
path_str.as_bytes().len() as c_uint,
917-
)
918-
}
907+
unsafe { llvm::LLVMMDStringInContext2(llcx, path_str.as_ptr(), path_str.as_bytes().len()) }
919908
}
920909
}
921910

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
209209

210210
fn set_dbg_loc(&mut self, dbg_loc: &'ll DILocation) {
211211
unsafe {
212-
let dbg_loc_as_llval = llvm::LLVMRustMetadataAsValue(self.cx().llcx, dbg_loc);
213-
llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc_as_llval);
212+
llvm::LLVMSetCurrentDebugLocation2(self.llbuilder, dbg_loc);
214213
}
215214
}
216215

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+25-17
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ extern "C" {
10181018
pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
10191019

10201020
/// See Module::setModuleInlineAsm.
1021-
pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char, AsmLen: size_t);
1021+
pub fn LLVMAppendModuleInlineAsm(M: &Module, Asm: *const c_char, Len: size_t);
10221022

10231023
/// See llvm::LLVMTypeKind::getTypeID.
10241024
pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
@@ -1065,7 +1065,7 @@ extern "C" {
10651065

10661066
// Operations on other types
10671067
pub fn LLVMVoidTypeInContext(C: &Context) -> &Type;
1068-
pub fn LLVMRustMetadataTypeInContext(C: &Context) -> &Type;
1068+
pub fn LLVMMetadataTypeInContext(C: &Context) -> &Type;
10691069

10701070
// Operations on all values
10711071
pub fn LLVMTypeOf(Val: &Value) -> &Type;
@@ -1084,7 +1084,12 @@ extern "C" {
10841084
pub fn LLVMGetPoison(Ty: &Type) -> &Value;
10851085

10861086
// Operations on metadata
1087+
// FIXME: deprecated, replace with LLVMMDStringInContext2
10871088
pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
1089+
1090+
pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;
1091+
1092+
// FIXME: deprecated, replace with LLVMMDNodeInContext2
10881093
pub fn LLVMMDNodeInContext<'a>(
10891094
C: &'a Context,
10901095
Vals: *const &'a Value,
@@ -1123,6 +1128,8 @@ extern "C" {
11231128
Packed: Bool,
11241129
) -> &'a Value;
11251130

1131+
// FIXME: replace with LLVMConstArray2 when bumped minimal version to llvm-17
1132+
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
11261133
pub fn LLVMConstArray<'a>(
11271134
ElementTy: &'a Type,
11281135
ConstantVals: *const &'a Value,
@@ -1262,7 +1269,7 @@ extern "C" {
12621269
pub fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
12631270

12641271
// Metadata
1265-
pub fn LLVMSetCurrentDebugLocation<'a>(Builder: &Builder<'a>, L: &'a Value);
1272+
pub fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: &'a Metadata);
12661273

12671274
// Terminators
12681275
pub fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;
@@ -1302,38 +1309,38 @@ extern "C" {
13021309
pub fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
13031310
pub fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value;
13041311

1305-
pub fn LLVMRustBuildCleanupPad<'a>(
1312+
pub fn LLVMBuildCleanupPad<'a>(
13061313
B: &Builder<'a>,
13071314
ParentPad: Option<&'a Value>,
1308-
ArgCnt: c_uint,
13091315
Args: *const &'a Value,
1316+
NumArgs: c_uint,
13101317
Name: *const c_char,
13111318
) -> Option<&'a Value>;
1312-
pub fn LLVMRustBuildCleanupRet<'a>(
1319+
pub fn LLVMBuildCleanupRet<'a>(
13131320
B: &Builder<'a>,
13141321
CleanupPad: &'a Value,
1315-
UnwindBB: Option<&'a BasicBlock>,
1322+
BB: Option<&'a BasicBlock>,
13161323
) -> Option<&'a Value>;
1317-
pub fn LLVMRustBuildCatchPad<'a>(
1324+
pub fn LLVMBuildCatchPad<'a>(
13181325
B: &Builder<'a>,
13191326
ParentPad: &'a Value,
1320-
ArgCnt: c_uint,
13211327
Args: *const &'a Value,
1328+
NumArgs: c_uint,
13221329
Name: *const c_char,
13231330
) -> Option<&'a Value>;
1324-
pub fn LLVMRustBuildCatchRet<'a>(
1331+
pub fn LLVMBuildCatchRet<'a>(
13251332
B: &Builder<'a>,
1326-
Pad: &'a Value,
1333+
CatchPad: &'a Value,
13271334
BB: &'a BasicBlock,
13281335
) -> Option<&'a Value>;
1329-
pub fn LLVMRustBuildCatchSwitch<'a>(
1336+
pub fn LLVMBuildCatchSwitch<'a>(
13301337
Builder: &Builder<'a>,
13311338
ParentPad: Option<&'a Value>,
1332-
BB: Option<&'a BasicBlock>,
1339+
UnwindBB: Option<&'a BasicBlock>,
13331340
NumHandlers: c_uint,
13341341
Name: *const c_char,
13351342
) -> Option<&'a Value>;
1336-
pub fn LLVMRustAddHandler<'a>(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
1343+
pub fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock);
13371344
pub fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value);
13381345

13391346
// Add a case to the switch instruction
@@ -1627,11 +1634,12 @@ extern "C" {
16271634
DestTy: &'a Type,
16281635
Name: *const c_char,
16291636
) -> &'a Value;
1630-
pub fn LLVMRustBuildIntCast<'a>(
1637+
pub fn LLVMBuildIntCast2<'a>(
16311638
B: &Builder<'a>,
16321639
Val: &'a Value,
16331640
DestTy: &'a Type,
1634-
IsSigned: bool,
1641+
IsSigned: Bool,
1642+
Name: *const c_char,
16351643
) -> &'a Value;
16361644

16371645
// Comparisons
@@ -1920,7 +1928,7 @@ extern "C" {
19201928
);
19211929
pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool;
19221930

1923-
pub fn LLVMRustMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1931+
pub fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
19241932

19251933
pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>;
19261934

compiler/rustc_codegen_llvm/src/type_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'ll> CodegenCx<'ll, '_> {
5353
}
5454

5555
pub(crate) fn type_metadata(&self) -> &'ll Type {
56-
unsafe { llvm::LLVMRustMetadataTypeInContext(self.llcx) }
56+
unsafe { llvm::LLVMMetadataTypeInContext(self.llcx) }
5757
}
5858

5959
///x Creates an integer type with the given number of bits, e.g., i24

0 commit comments

Comments
 (0)