Skip to content

Commit 2378651

Browse files
authored
Rollup merge of #66858 - 0dvictor:capi, r=rkruppe
Use LLVMAddAnalysisPasses instead of Rust's wrapper LLVM exposes a C API `LLVMAddAnalysisPasses` and hence Rust's own wrapper `LLVMRustAddAnalysisPasses` is not needed anymore.
2 parents 9ae7fb3 + b41b1d3 commit 2378651

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

src/librustc_codegen_llvm/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ pub(crate) fn run_pass_manager(cgcx: &CodegenContext<LlvmCodegenBackend>,
541541
debug!("running the pass manager");
542542
unsafe {
543543
let pm = llvm::LLVMCreatePassManager();
544-
llvm::LLVMRustAddAnalysisPasses(module.module_llvm.tm, pm, module.module_llvm.llmod());
544+
llvm::LLVMAddAnalysisPasses(module.module_llvm.tm, pm);
545545

546546
if config.verify_llvm_ir {
547547
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr().cast());

src/librustc_codegen_llvm/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
384384
// we'll get errors in LLVM.
385385
let using_thin_buffers = config.bitcode_needed();
386386
if !config.no_prepopulate_passes {
387-
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
388-
llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);
387+
llvm::LLVMAddAnalysisPasses(tm, fpm);
388+
llvm::LLVMAddAnalysisPasses(tm, mpm);
389389
let opt_level = to_llvm_opt_settings(opt_level).0;
390390
let prepare_for_thin_lto = cgcx.lto == Lto::Thin || cgcx.lto == Lto::ThinLocal ||
391391
(cgcx.lto != Lto::Fat && cgcx.opts.cg.linker_plugin_lto.enabled());
@@ -509,7 +509,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
509509
where F: FnOnce(&'ll mut PassManager<'ll>) -> R,
510510
{
511511
let cpm = llvm::LLVMCreatePassManager();
512-
llvm::LLVMRustAddAnalysisPasses(tm, cpm, llmod);
512+
llvm::LLVMAddAnalysisPasses(tm, cpm);
513513
llvm::LLVMRustAddLibraryInfo(cpm, llmod, no_builtins);
514514
f(cpm)
515515
}

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,8 @@ extern "C" {
13411341

13421342
pub fn LLVMInitializePasses();
13431343

1344+
pub fn LLVMAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>);
1345+
13441346
pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
13451347
pub fn LLVMPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
13461348
pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: &PassManagerBuilder, Value: Bool);
@@ -1703,7 +1705,6 @@ extern "C" {
17031705
EmitStackSizeSection: bool)
17041706
-> Option<&'static mut TargetMachine>;
17051707
pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
1706-
pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);
17071708
pub fn LLVMRustAddBuilderLibraryInfo(PMB: &'a PassManagerBuilder,
17081709
M: &'a Module,
17091710
DisableSimplifyLibCalls: bool);

src/rustllvm/PassWrapper.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,6 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
445445
delete unwrap(TM);
446446
}
447447

448-
// Unfortunately, LLVM doesn't expose a C API to add the corresponding analysis
449-
// passes for a target to a pass manager. We export that functionality through
450-
// this function.
451-
extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
452-
LLVMPassManagerRef PMR,
453-
LLVMModuleRef M) {
454-
PassManagerBase *PM = unwrap(PMR);
455-
PM->add(
456-
createTargetTransformInfoWrapperPass(unwrap(TM)->getTargetIRAnalysis()));
457-
}
458-
459448
extern "C" void LLVMRustConfigurePassManagerBuilder(
460449
LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel,
461450
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize, bool PrepareForThinLTO,

0 commit comments

Comments
 (0)