@@ -107,6 +107,7 @@ static LLVMRustPassKind toRust(PassKind Kind) {
107107}
108108
109109extern " 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
120124extern " 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
127135extern " 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
133145extern " 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
140156extern " 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
144164extern " 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
150174extern " C" LLVMRustPassKind LLVMRustPassKind (LLVMPassRef RustPass) {
@@ -154,23 +178,84 @@ extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) {
154178}
155179
156180extern " 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+
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+
225+ extern " C" void LLVMRustPassManagerBuilderPopulateLTOPassManager (
226+ LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM, bool Internalize, bool RunInliner) {
227+ #if LLVM_VERSION_LT(15, 0)
228+ LLVMPassManagerBuilderPopulateLTOPassManager (PMB, PM, Internalize, RunInliner);
229+ #else
230+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
231+ #endif
161232}
162233
163234extern " C"
164235void LLVMRustPassManagerBuilderPopulateThinLTOPassManager (
165236 LLVMPassManagerBuilderRef PMBR,
166237 LLVMPassManagerRef PMR
167238) {
239+ #if LLVM_VERSION_LT(15, 0)
168240 unwrap (PMBR)->populateThinLTOPassManager (*unwrap (PMR));
241+ #else
242+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
243+ #endif
244+ }
245+
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
169253}
170254
171255extern " C"
172256void LLVMRustAddLastExtensionPasses (
173257 LLVMPassManagerBuilderRef PMBR, LLVMPassRef *Passes, size_t NumPasses) {
258+ #if LLVM_VERSION_LT(15, 0)
174259 auto AddExtensionPasses = [Passes, NumPasses](
175260 const PassManagerBuilder &Builder, PassManagerBase &PM) {
176261 for (size_t I = 0 ; I < NumPasses; I++) {
@@ -183,6 +268,9 @@ void LLVMRustAddLastExtensionPasses(
183268 AddExtensionPasses);
184269 unwrap (PMBR)->addExtension (PassManagerBuilder::EP_EnabledOnOptLevel0,
185270 AddExtensionPasses);
271+ #else
272+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
273+ #endif
186274}
187275
188276#ifdef LLVM_COMPONENT_X86
@@ -533,12 +621,16 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
533621extern " C" void LLVMRustConfigurePassManagerBuilder (
534622 LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel,
535623 bool MergeFunctions, bool SLPVectorize, bool LoopVectorize, bool PrepareForThinLTO,
536- 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)
537627 unwrap (PMBR)->MergeFunctions = MergeFunctions;
538628 unwrap (PMBR)->SLPVectorize = SLPVectorize;
539629 unwrap (PMBR)->OptLevel = fromRust (OptLevel);
540630 unwrap (PMBR)->LoopVectorize = LoopVectorize;
541631 unwrap (PMBR)->PrepareForThinLTO = PrepareForThinLTO;
632+ unwrap (PMBR)->SizeLevel = SizeLevel;
633+ unwrap (PMBR)->DisableUnrollLoops = SizeLevel != 0 ;
542634
543635 if (PGOGenPath) {
544636 assert (!PGOUsePath && !PGOSampleUsePath);
@@ -550,6 +642,9 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
550642 } else if (PGOSampleUsePath) {
551643 unwrap (PMBR)->PGOSampleUse = PGOSampleUsePath;
552644 }
645+ #else
646+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
647+ #endif
553648}
554649
555650// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
0 commit comments