Skip to content

Commit 0abecda

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 0abecda

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4848
use rustc_span::Symbol;
4949
use rustc_target::spec::{RelocModel, TlsModel};
5050

51+
use crate::llvm::ToLlvmBool;
52+
5153
mod abi;
5254
mod allocator;
5355
mod asm;
@@ -384,7 +386,8 @@ unsafe impl Sync for ModuleLlvm {}
384386
impl ModuleLlvm {
385387
fn new(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
386388
unsafe {
387-
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
389+
let llcx = llvm::LLVMContextCreate();
390+
llvm::LLVMContextSetDiscardValueNames(llcx, tcx.sess.fewer_names().to_llvm_bool());
388391
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
389392
ModuleLlvm {
390393
llmod_raw,
@@ -396,7 +399,8 @@ impl ModuleLlvm {
396399

397400
fn new_metadata(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
398401
unsafe {
399-
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
402+
let llcx = llvm::LLVMContextCreate();
403+
llvm::LLVMContextSetDiscardValueNames(llcx, tcx.sess.fewer_names().to_llvm_bool());
400404
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
401405
ModuleLlvm {
402406
llmod_raw,
@@ -427,7 +431,8 @@ impl ModuleLlvm {
427431
dcx: DiagCtxtHandle<'_>,
428432
) -> Self {
429433
unsafe {
430-
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
434+
let llcx = llvm::LLVMContextCreate();
435+
llvm::LLVMContextSetDiscardValueNames(llcx, cgcx.fewer_names.to_llvm_bool());
431436
let llmod_raw = back::lto::parse_module(llcx, name, buffer, dcx);
432437
let tm = ModuleLlvm::tm_from_cgcx(cgcx, name.to_str().unwrap(), dcx);
433438

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)