Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/llvm_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ unsafe fn wrap_llcx<'ll>(llcx_raw: ptr::NonNull<llvm::ContextRaw>) -> llvm::Cont
llvm::Context { llcx_raw, _invariant_ll: PhantomData }
}

/// Shared helper to call [`llvm::LLVMContextCreate`] and then configure
/// Shared helper to call [`llvm::LLVMRustContextCreate`] and then configure
/// [`llvm::LLVMContextSetDiscardValueNames`].
fn create_context_and_set_fewer_names(fewer_names: bool) -> ptr::NonNull<llvm::ContextRaw> {
unsafe {
let llcx_raw = llvm::LLVMContextCreate();
let llcx_raw = llvm::LLVMRustContextCreate();
llvm::LLVMContextSetDiscardValueNames(wrap_llcx(llcx_raw), fewer_names.to_llvm_bool());
llcx_raw
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ pub(crate) type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) ->

unsafe extern "C" {
// Create and destroy contexts.
pub(crate) fn LLVMContextCreate() -> ptr::NonNull<ContextRaw>;
pub(crate) fn LLVMRustContextCreate() -> ptr::NonNull<ContextRaw>;
pub(crate) fn LLVMContextDispose(C: ptr::NonNull<ContextRaw>);
pub(crate) fn LLVMContextSetDiscardValueNames<'ll>(C: Context<'ll>, Discard: Bool);
pub(crate) fn LLVMGetMDKindIDInContext<'ll>(
Expand Down
22 changes: 22 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "llvm/Plugins/PassPlugin.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/FileSystem.h"
#if LLVM_VERSION_GE(24, 0)
#include "llvm/Support/LibraryOptionsContext.h"
#endif
#include "llvm/Support/Program.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/VirtualFileSystem.h"
Expand Down Expand Up @@ -344,6 +347,10 @@ extern "C" const char *LLVMRustGetHostCPUName(size_t *OutLen) {
return Name.data();
}

#if LLVM_VERSION_GE(24, 0)
static cl::LibraryOptionsContext OptionsContext;
#endif

extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
const char *TripleStr, const char *CPU, const char *Feature,
const char *ABIStr, LLVMRustCodeModel RustCM, LLVMRustRelocModel RustReloc,
Expand All @@ -369,6 +376,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
}

TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip);
#if LLVM_VERSION_GE(24, 0)
Options.MCOptions.LibraryOptions = &OptionsContext;
#endif

#if LLVM_VERSION_LT(24, 0)
Options.FloatABIType = FloatABIType;
Expand Down Expand Up @@ -437,6 +447,14 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
return wrap(TM);
}

extern "C" LLVMContextRef LLVMRustContextCreate() {
LLVMContextRef Ctx = LLVMContextCreate();
#if LLVM_VERSION_GE(24, 0)
unwrap(Ctx)->getLibraryOptions().assign(OptionsContext);
#endif
return Ctx;
}

extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) {
// Initializing the command-line options more than once is not allowed. So,
// check if they've already been initialized. (This could happen if we're
Expand All @@ -446,7 +464,11 @@ extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) {
if (Initialized)
return;
Initialized = true;
#if LLVM_VERSION_LT(24, 0)
cl::ParseCommandLineOptions(Argc, Argv);
#else
cl::parseCommandLineOptions(OptionsContext, ArrayRef(Argv, Argc));
#endif
}

enum class LLVMRustFileType {
Expand Down
Loading