Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ pub(crate) unsafe fn create_module<'ll>(
llvm::LLVMRustSetModuleCodeModel(llmod, to_llvm_code_model(sess.code_model()));
}

let large_data_threshold = sess.opts.unstable_opts.large_data_threshold.unwrap_or(0);
if large_data_threshold != 0 {
Comment thread
jakos-sec marked this conversation as resolved.
Outdated
unsafe {
llvm::LLVMRustSetModuleLargeDataThreshold(llmod, large_data_threshold);
}
}

// If skipping the PLT is enabled, we need to add some module metadata
// to ensure intrinsic calls don't use it.
if !sess.needs_plt() {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,7 @@ unsafe extern "C" {
pub(crate) fn LLVMRustSetModulePICLevel(M: &Module);
pub(crate) fn LLVMRustSetModulePIELevel(M: &Module);
pub(crate) fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);
pub(crate) fn LLVMRustSetModuleLargeDataThreshold(M: &Module, Threshold: u64);
pub(crate) fn LLVMRustBufferPtr(p: &Buffer) -> *const u8;
pub(crate) fn LLVMRustBufferLen(p: &Buffer) -> usize;
pub(crate) fn LLVMRustBufferFree(p: &'static mut Buffer);
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,11 @@ extern "C" void LLVMRustSetModuleCodeModel(LLVMModuleRef M,
unwrap(M)->setCodeModel(*CM);
}

extern "C" void LLVMRustSetModuleLargeDataThreshold(LLVMModuleRef M,
uint64_t Threshold) {
unwrap(M)->setLargeDataThreshold(Threshold);
}

// Here you'll find an implementation of ThinLTO as used by the Rust compiler
// right now. This ThinLTO support is only enabled on "recent ish" versions of
// LLVM, and otherwise it's just blanket rejected from other compilers.
Expand Down
9 changes: 9 additions & 0 deletions tests/codegen-llvm/large_data_threshold.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ only-x86_64
//@ revisions: DEFAULT EXPLICIT
//@[DEFAULT] compile-flags: -C code-model=medium
//@[EXPLICIT] compile-flags: -C code-model=medium -Z large-data-threshold=1024

#![crate_type = "lib"]

// DEFAULT-NOT: !"Large Data Threshold"
// EXPLICIT: !{{[0-9]+}} = !{i32 1, !"Large Data Threshold", i64 1024}
Loading