Skip to content

Commit 6dc0bcc

Browse files
committed
Stub out more PassManagerBuilder functions
1 parent 3cf0809 commit 6dc0bcc

File tree

3 files changed

+68
-23
lines changed

3 files changed

+68
-23
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ pub(crate) unsafe fn optimize(
634634
extra_passes.as_ptr(),
635635
extra_passes.len() as size_t,
636636
);
637-
llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(b, fpm);
638-
llvm::LLVMPassManagerBuilderPopulateModulePassManager(b, mpm);
637+
llvm::LLVMRustPassManagerBuilderPopulateFunctionPassManager(b, fpm);
638+
llvm::LLVMRustPassManagerBuilderPopulateModulePassManager(b, mpm);
639639
});
640640

641641
have_name_anon_globals_pass = have_name_anon_globals_pass || prepare_for_thin_lto;
@@ -1091,7 +1091,7 @@ pub unsafe fn with_llvm_pmb(
10911091
// Create the PassManagerBuilder for LLVM. We configure it with
10921092
// reasonable defaults and prepare it to actually populate the pass
10931093
// manager.
1094-
let builder = llvm::LLVMPassManagerBuilderCreate();
1094+
let builder = llvm::LLVMRustPassManagerBuilderCreate();
10951095
let opt_size = config.opt_size.map_or(llvm::CodeGenOptSizeNone, |x| to_llvm_opt_settings(x).1);
10961096
let inline_threshold = config.inline_threshold;
10971097
let pgo_gen_path = get_pgo_gen_path(config);
@@ -1108,14 +1108,9 @@ pub unsafe fn with_llvm_pmb(
11081108
pgo_gen_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
11091109
pgo_use_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
11101110
pgo_sample_use_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
1111+
opt_size as c_int,
11111112
);
11121113

1113-
llvm::LLVMPassManagerBuilderSetSizeLevel(builder, opt_size as u32);
1114-
1115-
if opt_size != llvm::CodeGenOptSizeNone {
1116-
llvm::LLVMPassManagerBuilderSetDisableUnrollLoops(builder, 1);
1117-
}
1118-
11191114
llvm::LLVMRustAddBuilderLibraryInfo(builder, llmod, config.no_builtins);
11201115

11211116
// Here we match what clang does (kinda). For O0 we only inline
@@ -1124,16 +1119,16 @@ pub unsafe fn with_llvm_pmb(
11241119
// thresholds copied from clang.
11251120
match (opt_level, opt_size, inline_threshold) {
11261121
(.., Some(t)) => {
1127-
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, t);
1122+
llvm::LLVMRustPassManagerBuilderUseInlinerWithThreshold(builder, t);
11281123
}
11291124
(llvm::CodeGenOptLevel::Aggressive, ..) => {
1130-
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 275);
1125+
llvm::LLVMRustPassManagerBuilderUseInlinerWithThreshold(builder, 275);
11311126
}
11321127
(_, llvm::CodeGenOptSizeDefault, _) => {
1133-
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 75);
1128+
llvm::LLVMRustPassManagerBuilderUseInlinerWithThreshold(builder, 75);
11341129
}
11351130
(_, llvm::CodeGenOptSizeAggressive, _) => {
1136-
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 25);
1131+
llvm::LLVMRustPassManagerBuilderUseInlinerWithThreshold(builder, 25);
11371132
}
11381133
(llvm::CodeGenOptLevel::None, ..) => {
11391134
llvm::LLVMRustAddAlwaysInlinePass(builder, config.emit_lifetime_markers);
@@ -1142,12 +1137,12 @@ pub unsafe fn with_llvm_pmb(
11421137
llvm::LLVMRustAddAlwaysInlinePass(builder, config.emit_lifetime_markers);
11431138
}
11441139
(llvm::CodeGenOptLevel::Default, ..) => {
1145-
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 225);
1140+
llvm::LLVMRustPassManagerBuilderUseInlinerWithThreshold(builder, 225);
11461141
}
11471142
}
11481143

11491144
f(builder);
1150-
llvm::LLVMPassManagerBuilderDispose(builder);
1145+
llvm::LLVMRustPassManagerBuilderDispose(builder);
11511146
}
11521147

11531148
// Create a `__imp_<symbol> = &symbol` global for every public static `symbol`.

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1825,20 +1825,18 @@ extern "C" {
18251825

18261826
pub fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
18271827

1828-
pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
1829-
pub fn LLVMPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
1830-
pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: &PassManagerBuilder, Value: Bool);
1831-
pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: &PassManagerBuilder, Value: Bool);
1832-
pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1828+
pub fn LLVMRustPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
1829+
pub fn LLVMRustPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
1830+
pub fn LLVMRustPassManagerBuilderUseInlinerWithThreshold(
18331831
PMB: &PassManagerBuilder,
18341832
threshold: c_uint,
18351833
);
1836-
pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1834+
pub fn LLVMRustPassManagerBuilderPopulateModulePassManager(
18371835
PMB: &PassManagerBuilder,
18381836
PM: &PassManager<'_>,
18391837
);
18401838

1841-
pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1839+
pub fn LLVMRustPassManagerBuilderPopulateFunctionPassManager(
18421840
PMB: &PassManagerBuilder,
18431841
PM: &PassManager<'_>,
18441842
);
@@ -2308,6 +2306,7 @@ extern "C" {
23082306
PGOGenPath: *const c_char,
23092307
PGOUsePath: *const c_char,
23102308
PGOSampleUsePath: *const c_char,
2309+
SizeLevel: c_int,
23112310
);
23122311
pub fn LLVMRustAddLibraryInfo<'a>(
23132312
PM: &PassManager<'a>,

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+52-1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,41 @@ extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
187187
report_fatal_error("Legacy PM not supported with LLVM 15");
188188
#endif
189189
}
190+
191+
extern "C" LLVMPassManagerBuilderRef LLVMRustPassManagerBuilderCreate() {
192+
#if LLVM_VERSION_LT(15, 0)
193+
return LLVMPassManagerBuilderCreate();
194+
#else
195+
report_fatal_error("Legacy PM not supported with LLVM 15");
196+
#endif
197+
}
198+
199+
extern "C" void LLVMRustPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
200+
#if LLVM_VERSION_LT(15, 0)
201+
LLVMPassManagerBuilderDispose(PMB);
202+
#else
203+
report_fatal_error("Legacy PM not supported with LLVM 15");
204+
#endif
205+
}
206+
207+
extern "C" void LLVMRustPassManagerBuilderPopulateFunctionPassManager(
208+
LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM) {
209+
#if LLVM_VERSION_LT(15, 0)
210+
LLVMPassManagerBuilderPopulateFunctionPassManager(PMB, PM);
211+
#else
212+
report_fatal_error("Legacy PM not supported with LLVM 15");
213+
#endif
214+
}
215+
216+
extern "C" void LLVMRustPassManagerBuilderPopulateModulePassManager(
217+
LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM) {
218+
#if LLVM_VERSION_LT(15, 0)
219+
LLVMPassManagerBuilderPopulateModulePassManager(PMB, PM);
220+
#else
221+
report_fatal_error("Legacy PM not supported with LLVM 15");
222+
#endif
223+
}
224+
190225
extern "C" void LLVMRustPassManagerBuilderPopulateLTOPassManager(
191226
LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM, bool Internalize, bool RunInliner) {
192227
#if LLVM_VERSION_LT(15, 0)
@@ -208,6 +243,15 @@ void LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
208243
#endif
209244
}
210245

246+
extern "C" void LLVMRustPassManagerBuilderUseInlinerWithThreshold(
247+
LLVMPassManagerBuilderRef PMB, unsigned Threshold) {
248+
#if LLVM_VERSION_LT(15, 0)
249+
LLVMPassManagerBuilderUseInlinerWithThreshold(PMB, Threshold);
250+
#else
251+
report_fatal_error("Legacy PM not supported with LLVM 15");
252+
#endif
253+
}
254+
211255
extern "C"
212256
void LLVMRustAddLastExtensionPasses(
213257
LLVMPassManagerBuilderRef PMBR, LLVMPassRef *Passes, size_t NumPasses) {
@@ -577,12 +621,16 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
577621
extern "C" void LLVMRustConfigurePassManagerBuilder(
578622
LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel,
579623
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize, bool PrepareForThinLTO,
580-
const char* PGOGenPath, const char* PGOUsePath, const char* PGOSampleUsePath) {
624+
const char* PGOGenPath, const char* PGOUsePath, const char* PGOSampleUsePath,
625+
int SizeLevel) {
626+
#if LLVM_VERSION_LT(15, 0)
581627
unwrap(PMBR)->MergeFunctions = MergeFunctions;
582628
unwrap(PMBR)->SLPVectorize = SLPVectorize;
583629
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
584630
unwrap(PMBR)->LoopVectorize = LoopVectorize;
585631
unwrap(PMBR)->PrepareForThinLTO = PrepareForThinLTO;
632+
unwrap(PMBR)->SizeLevel = SizeLevel;
633+
unwrap(PMBR)->DisableUnrollLoops = SizeLevel != 0;
586634

587635
if (PGOGenPath) {
588636
assert(!PGOUsePath && !PGOSampleUsePath);
@@ -594,6 +642,9 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
594642
} else if (PGOSampleUsePath) {
595643
unwrap(PMBR)->PGOSampleUse = PGOSampleUsePath;
596644
}
645+
#else
646+
report_fatal_error("Legacy PM not supported with LLVM 15");
647+
#endif
597648
}
598649

599650
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`

0 commit comments

Comments
 (0)