mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Remove explicit EmitThinLTOSummary argument
In favor of passing a NULL ThinLTOSummaryBufferRef. And improve type improve type safety on the Rust side.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::ptr::NonNull;
|
||||
use std::sync::Arc;
|
||||
use std::{io, iter, slice};
|
||||
|
||||
@@ -660,17 +659,13 @@ pub(crate) fn run_pass_manager(
|
||||
debug!("lto done");
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub(crate) struct Buffer(&'static mut llvm::Buffer);
|
||||
|
||||
unsafe impl Send for Buffer {}
|
||||
unsafe impl Sync for Buffer {}
|
||||
|
||||
impl Buffer {
|
||||
pub(crate) unsafe fn from_raw_ptr(ptr: *mut llvm::Buffer) -> Buffer {
|
||||
let mut ptr = NonNull::new(ptr).unwrap();
|
||||
Buffer(unsafe { ptr.as_mut() })
|
||||
}
|
||||
|
||||
pub(crate) fn data(&self) -> &[u8] {
|
||||
unsafe {
|
||||
let ptr = llvm::LLVMRustBufferPtr(self.0);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::ptr::null_mut;
|
||||
use std::sync::Arc;
|
||||
use std::{fs, slice, str};
|
||||
|
||||
@@ -29,7 +28,7 @@
|
||||
};
|
||||
use tracing::{debug, trace};
|
||||
|
||||
use crate::back::lto::ModuleBuffer;
|
||||
use crate::back::lto::{Buffer, ModuleBuffer};
|
||||
use crate::back::owned_target_machine::OwnedTargetMachine;
|
||||
use crate::back::profiling::{
|
||||
LlvmSelfProfiler, selfprofile_after_pass_callback, selfprofile_before_pass_callback,
|
||||
@@ -563,8 +562,8 @@ pub(crate) unsafe fn llvm_optimize(
|
||||
prof: &SelfProfilerRef,
|
||||
dcx: DiagCtxtHandle<'_>,
|
||||
module: &ModuleCodegen<ModuleLlvm>,
|
||||
thin_lto_buffer: Option<&mut *mut llvm::Buffer>,
|
||||
thin_lto_summary_buffer: Option<&mut *mut llvm::Buffer>,
|
||||
thin_lto_buffer: Option<&mut Option<Buffer>>,
|
||||
thin_lto_summary_buffer: Option<&mut Option<Buffer>>,
|
||||
config: &ModuleConfig,
|
||||
opt_level: config::OptLevel,
|
||||
opt_stage: llvm::OptStage,
|
||||
@@ -788,7 +787,6 @@ fn handle_offload<'ll>(cx: &'ll SimpleCx<'_>, old_fn: &llvm::Value) {
|
||||
config.lint_llvm_ir,
|
||||
thin_lto_buffer,
|
||||
thin_lto_summary_buffer,
|
||||
config.emit_thin_lto_summary,
|
||||
merge_functions,
|
||||
unroll_loops,
|
||||
vectorize_slp,
|
||||
@@ -939,7 +937,7 @@ pub(crate) fn optimize(
|
||||
&& config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full))
|
||||
|| config.emit_thin_lto_summary
|
||||
{
|
||||
(Some(null_mut()), Some(null_mut()))
|
||||
(Some(None), config.emit_thin_lto_summary.then_some(None))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
@@ -958,19 +956,17 @@ pub(crate) fn optimize(
|
||||
)
|
||||
};
|
||||
if let Some(thin_lto_buffer) = thin_lto_buffer {
|
||||
let thin_lto_buffer =
|
||||
unsafe { crate::back::lto::Buffer::from_raw_ptr(thin_lto_buffer) };
|
||||
let thin_lto_summary_buffer =
|
||||
unsafe { crate::back::lto::Buffer::from_raw_ptr(thin_lto_summary_buffer.unwrap()) };
|
||||
let thin_lto_buffer = thin_lto_buffer.unwrap();
|
||||
module.thin_lto_buffer = Some(thin_lto_buffer.data().to_vec());
|
||||
let bc_summary_out = cgcx.output_filenames.temp_path_for_cgu(
|
||||
OutputType::ThinLinkBitcode,
|
||||
&module.name,
|
||||
cgcx.invocation_temp.as_deref(),
|
||||
);
|
||||
if config.emit_thin_lto_summary
|
||||
if let Some(thin_lto_summary_buffer) = thin_lto_summary_buffer
|
||||
&& let Some(thin_link_bitcode_filename) = bc_summary_out.file_name()
|
||||
{
|
||||
let thin_lto_summary_buffer = thin_lto_summary_buffer.unwrap();
|
||||
let summary_data = thin_lto_summary_buffer.data();
|
||||
prof.artifact_size(
|
||||
"llvm_bitcode_summary",
|
||||
|
||||
@@ -2372,9 +2372,8 @@ pub(crate) fn LLVMRustOptimize<'a>(
|
||||
NoPrepopulatePasses: bool,
|
||||
VerifyIR: bool,
|
||||
LintIR: bool,
|
||||
ThinLTOBuffer: Option<&mut *mut Buffer>,
|
||||
ThinLTOSummaryBuffer: Option<&mut *mut Buffer>,
|
||||
EmitThinLTOSummary: bool,
|
||||
ThinLTOBuffer: Option<&mut Option<crate::back::lto::Buffer>>,
|
||||
ThinLTOSummaryBuffer: Option<&mut Option<crate::back::lto::Buffer>>,
|
||||
MergeFunctions: bool,
|
||||
UnrollLoops: bool,
|
||||
SLPVectorize: bool,
|
||||
|
||||
@@ -554,9 +554,9 @@ extern "C" LLVMRustResult LLVMRustOptimize(
|
||||
LLVMRustPassBuilderOptLevel OptLevelRust, LLVMRustOptStage OptStage,
|
||||
bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR,
|
||||
bool LintIR, LLVMRustBuffer **ThinLTOBufferRef,
|
||||
LLVMRustBuffer **ThinLTOSummaryBufferRef, bool EmitThinLTOSummary,
|
||||
bool MergeFunctions, bool UnrollLoops, bool SLPVectorize,
|
||||
bool LoopVectorize, bool DisableSimplifyLibCalls, bool EmitLifetimeMarkers,
|
||||
LLVMRustBuffer **ThinLTOSummaryBufferRef, bool MergeFunctions,
|
||||
bool UnrollLoops, bool SLPVectorize, bool LoopVectorize,
|
||||
bool DisableSimplifyLibCalls, bool EmitLifetimeMarkers,
|
||||
registerEnzymeAndPassPipelineFn EnzymePtr, bool PrintBeforeEnzyme,
|
||||
bool PrintAfterEnzyme, bool PrintPasses,
|
||||
LLVMRustSanitizerOptions *SanitizerOptions, const char *PGOGenPath,
|
||||
@@ -825,9 +825,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
|
||||
// `ThinLTOPreLinkDefaultPipeline`.
|
||||
MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(OptLevel));
|
||||
MPM.addPass(ThinLTOBitcodeWriterPass(
|
||||
ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr));
|
||||
ThinLTODataOS,
|
||||
ThinLTOSummaryBufferRef ? &ThinLinkDataOS : nullptr));
|
||||
*ThinLTOBufferRef = ThinLTOBuffer.release();
|
||||
*ThinLTOSummaryBufferRef = ThinLTOSummaryBuffer.release();
|
||||
if (ThinLTOSummaryBufferRef) {
|
||||
*ThinLTOSummaryBufferRef = ThinLTOSummaryBuffer.release();
|
||||
}
|
||||
MPM.addPass(PB.buildModuleOptimizationPipeline(
|
||||
OptLevel, ThinOrFullLTOPhase::None));
|
||||
MPM.addPass(
|
||||
@@ -883,12 +886,14 @@ extern "C" LLVMRustResult LLVMRustOptimize(
|
||||
// lto is requested. See PR #136840 for background information.
|
||||
if (OptStage != LLVMRustOptStage::PreLinkFatLTO) {
|
||||
MPM.addPass(ThinLTOBitcodeWriterPass(
|
||||
ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr));
|
||||
ThinLTODataOS, ThinLTOSummaryBufferRef ? &ThinLinkDataOS : nullptr));
|
||||
} else {
|
||||
MPM.addPass(BitcodeWriterPass(ThinLTODataOS));
|
||||
}
|
||||
*ThinLTOBufferRef = ThinLTOBuffer.release();
|
||||
*ThinLTOSummaryBufferRef = ThinLTOSummaryBuffer.release();
|
||||
if (ThinLTOSummaryBufferRef) {
|
||||
*ThinLTOSummaryBufferRef = ThinLTOSummaryBuffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
// now load "-enzyme" pass:
|
||||
|
||||
Reference in New Issue
Block a user