Skip to content

Commit 890caba

Browse files
committed
Stub out various legacy PM functions with LLVM 15
1 parent 7dc307f commit 890caba

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ pub(crate) fn run_pass_manager(
625625
if thin {
626626
llvm::LLVMRustPassManagerBuilderPopulateThinLTOPassManager(b, pm);
627627
} else {
628-
llvm::LLVMPassManagerBuilderPopulateLTOPassManager(
628+
llvm::LLVMRustPassManagerBuilderPopulateLTOPassManager(
629629
b, pm, /* Internalize = */ False, /* RunInliner = */ True,
630630
);
631631
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ extern "C" {
18421842
PMB: &PassManagerBuilder,
18431843
PM: &PassManager<'_>,
18441844
);
1845-
pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1845+
pub fn LLVMRustPassManagerBuilderPopulateLTOPassManager(
18461846
PMB: &PassManagerBuilder,
18471847
PM: &PassManager<'_>,
18481848
Internalize: Bool,

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static LLVMRustPassKind toRust(PassKind Kind) {
107107
}
108108

109109
extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
110+
#if LLVM_VERSION_LT(15, 0)
110111
StringRef SR(PassName);
111112
PassRegistry *PR = PassRegistry::getPassRegistry();
112113

@@ -115,36 +116,59 @@ extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
115116
return wrap(PI->createPass());
116117
}
117118
return nullptr;
119+
#else
120+
report_fatal_error("Legacy PM not supported with LLVM 15");
121+
#endif
118122
}
119123

120124
extern "C" LLVMPassRef LLVMRustCreateAddressSanitizerFunctionPass(bool Recover) {
125+
#if LLVM_VERSION_LT(15, 0)
121126
const bool CompileKernel = false;
122127
const bool UseAfterScope = true;
123128

124129
return wrap(createAddressSanitizerFunctionPass(CompileKernel, Recover, UseAfterScope));
130+
#else
131+
report_fatal_error("Legacy PM not supported with LLVM 15");
132+
#endif
125133
}
126134

127135
extern "C" LLVMPassRef LLVMRustCreateModuleAddressSanitizerPass(bool Recover) {
136+
#if LLVM_VERSION_LT(15, 0)
128137
const bool CompileKernel = false;
129138

130139
return wrap(createModuleAddressSanitizerLegacyPassPass(CompileKernel, Recover));
140+
#else
141+
report_fatal_error("Legacy PM not supported with LLVM 15");
142+
#endif
131143
}
132144

133145
extern "C" LLVMPassRef LLVMRustCreateMemorySanitizerPass(int TrackOrigins, bool Recover) {
146+
#if LLVM_VERSION_LT(15, 0)
134147
const bool CompileKernel = false;
135148

136149
return wrap(createMemorySanitizerLegacyPassPass(
137150
MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
151+
#else
152+
report_fatal_error("Legacy PM not supported with LLVM 15");
153+
#endif
138154
}
139155

140156
extern "C" LLVMPassRef LLVMRustCreateThreadSanitizerPass() {
157+
#if LLVM_VERSION_LT(15, 0)
141158
return wrap(createThreadSanitizerLegacyPassPass());
159+
#else
160+
report_fatal_error("Legacy PM not supported with LLVM 15");
161+
#endif
142162
}
143163

144164
extern "C" LLVMPassRef LLVMRustCreateHWAddressSanitizerPass(bool Recover) {
165+
#if LLVM_VERSION_LT(15, 0)
145166
const bool CompileKernel = false;
146167

147168
return wrap(createHWAddressSanitizerLegacyPassPass(CompileKernel, Recover));
169+
#else
170+
report_fatal_error("Legacy PM not supported with LLVM 15");
171+
#endif
148172
}
149173

150174
extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) {
@@ -154,23 +178,40 @@ extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) {
154178
}
155179

156180
extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
181+
#if LLVM_VERSION_LT(15, 0)
157182
assert(RustPass);
158183
Pass *Pass = unwrap(RustPass);
159184
PassManagerBase *PMB = unwrap(PMR);
160185
PMB->add(Pass);
186+
#else
187+
report_fatal_error("Legacy PM not supported with LLVM 15");
188+
#endif
189+
}
190+
extern "C" void LLVMRustPassManagerBuilderPopulateLTOPassManager(
191+
LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM, bool Internalize, bool RunInliner) {
192+
#if LLVM_VERSION_LT(15, 0)
193+
LLVMPassManagerBuilderPopulateLTOPassManager(PMB, PM, Internalize, RunInliner);
194+
#else
195+
report_fatal_error("Legacy PM not supported with LLVM 15");
196+
#endif
161197
}
162198

163199
extern "C"
164200
void LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
165201
LLVMPassManagerBuilderRef PMBR,
166202
LLVMPassManagerRef PMR
167203
) {
204+
#if LLVM_VERSION_LT(15, 0)
168205
unwrap(PMBR)->populateThinLTOPassManager(*unwrap(PMR));
206+
#else
207+
report_fatal_error("Legacy PM not supported with LLVM 15");
208+
#endif
169209
}
170210

171211
extern "C"
172212
void LLVMRustAddLastExtensionPasses(
173213
LLVMPassManagerBuilderRef PMBR, LLVMPassRef *Passes, size_t NumPasses) {
214+
#if LLVM_VERSION_LT(15, 0)
174215
auto AddExtensionPasses = [Passes, NumPasses](
175216
const PassManagerBuilder &Builder, PassManagerBase &PM) {
176217
for (size_t I = 0; I < NumPasses; I++) {
@@ -183,6 +224,9 @@ void LLVMRustAddLastExtensionPasses(
183224
AddExtensionPasses);
184225
unwrap(PMBR)->addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
185226
AddExtensionPasses);
227+
#else
228+
report_fatal_error("Legacy PM not supported with LLVM 15");
229+
#endif
186230
}
187231

188232
#ifdef LLVM_COMPONENT_X86

0 commit comments

Comments
 (0)