Skip to content

Commit 5f8c98b

Browse files
committed
Replace LLVMRustContextCreate with normal LLVM-C API calls
Since `LLVMRustContextCreate` can easily be replaced with a call to `LLVMContextCreate` and `LLVMContextSetDiscardValueNames`.
1 parent 9725c4b commit 5f8c98b

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ pub fn optimize_thin_module(
531531
// into that context. One day, however, we may do this for upstream
532532
// crates but for locally codegened modules we may be able to reuse
533533
// that LLVM Context and Module.
534-
//let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
534+
//let llcx = llvm::LLVMContextCreate();
535+
//llvm::LLVMContextSetDiscardValueNames(llcx, llvm::Bool::from_bool(cgcx.fewer_names));
535536
//let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &dcx)? as *const _;
536537
let mut should_combine_object_files = false;
537538
let context = match thin_module.shared.thin_buffers.get(thin_module.idx) {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,11 @@ unsafe impl Sync for ModuleLlvm {}
384384
impl ModuleLlvm {
385385
fn new(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
386386
unsafe {
387-
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
387+
let llcx = llvm::LLVMContextCreate();
388+
llvm::LLVMContextSetDiscardValueNames(
389+
llcx,
390+
llvm::Bool::from_bool(tcx.sess.fewer_names()),
391+
);
388392
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
389393
ModuleLlvm {
390394
llmod_raw,
@@ -396,7 +400,11 @@ impl ModuleLlvm {
396400

397401
fn new_metadata(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
398402
unsafe {
399-
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
403+
let llcx = llvm::LLVMContextCreate();
404+
llvm::LLVMContextSetDiscardValueNames(
405+
llcx,
406+
llvm::Bool::from_bool(tcx.sess.fewer_names()),
407+
);
400408
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
401409
ModuleLlvm {
402410
llmod_raw,
@@ -427,7 +435,8 @@ impl ModuleLlvm {
427435
dcx: DiagCtxtHandle<'_>,
428436
) -> Self {
429437
unsafe {
430-
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
438+
let llcx = llvm::LLVMContextCreate();
439+
llvm::LLVMContextSetDiscardValueNames(llcx, llvm::Bool::from_bool(cgcx.fewer_names));
431440
let llmod_raw = back::lto::parse_module(llcx, name, buffer, dcx);
432441
let tm = ModuleLlvm::tm_from_cgcx(cgcx, name.to_str().unwrap(), dcx);
433442

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,9 @@ pub(crate) type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) ->
905905

906906
unsafe extern "C" {
907907
// Create and destroy contexts.
908+
pub(crate) fn LLVMContextCreate() -> &'static mut Context;
908909
pub(crate) fn LLVMContextDispose(C: &'static mut Context);
910+
pub(crate) fn LLVMContextSetDiscardValueNames(C: &Context, Discard: Bool);
909911
pub(crate) fn LLVMGetMDKindIDInContext(
910912
C: &Context,
911913
Name: *const c_char,
@@ -1925,9 +1927,6 @@ unsafe extern "C" {
19251927
pub(crate) fn LLVMRustInstallErrorHandlers();
19261928
pub(crate) fn LLVMRustDisableSystemDialogsOnCrash();
19271929

1928-
// Create and destroy contexts.
1929-
pub(crate) fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
1930-
19311930
// Operations on all values
19321931
pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
19331932
Val: &'a Value,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ extern "C" void LLVMRustSetLastError(const char *Err) {
123123
LastError = strdup(Err);
124124
}
125125

126-
extern "C" LLVMContextRef LLVMRustContextCreate(bool shouldDiscardNames) {
127-
auto ctx = new LLVMContext();
128-
ctx->setDiscardValueNames(shouldDiscardNames);
129-
return wrap(ctx);
130-
}
131-
132126
extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
133127
const char *Target) {
134128
#if LLVM_VERSION_GE(21, 0)

0 commit comments

Comments
 (0)