@@ -107,6 +107,7 @@ static LLVMRustPassKind toRust(PassKind Kind) {
107
107
}
108
108
109
109
extern " C" LLVMPassRef LLVMRustFindAndCreatePass (const char *PassName) {
110
+ #if LLVM_VERSION_LT(15, 0)
110
111
StringRef SR (PassName);
111
112
PassRegistry *PR = PassRegistry::getPassRegistry ();
112
113
@@ -115,36 +116,59 @@ extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
115
116
return wrap (PI->createPass ());
116
117
}
117
118
return nullptr ;
119
+ #else
120
+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
121
+ #endif
118
122
}
119
123
120
124
extern " C" LLVMPassRef LLVMRustCreateAddressSanitizerFunctionPass (bool Recover) {
125
+ #if LLVM_VERSION_LT(15, 0)
121
126
const bool CompileKernel = false ;
122
127
const bool UseAfterScope = true ;
123
128
124
129
return wrap (createAddressSanitizerFunctionPass (CompileKernel, Recover, UseAfterScope));
130
+ #else
131
+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
132
+ #endif
125
133
}
126
134
127
135
extern " C" LLVMPassRef LLVMRustCreateModuleAddressSanitizerPass (bool Recover) {
136
+ #if LLVM_VERSION_LT(15, 0)
128
137
const bool CompileKernel = false ;
129
138
130
139
return wrap (createModuleAddressSanitizerLegacyPassPass (CompileKernel, Recover));
140
+ #else
141
+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
142
+ #endif
131
143
}
132
144
133
145
extern " C" LLVMPassRef LLVMRustCreateMemorySanitizerPass (int TrackOrigins, bool Recover) {
146
+ #if LLVM_VERSION_LT(15, 0)
134
147
const bool CompileKernel = false ;
135
148
136
149
return wrap (createMemorySanitizerLegacyPassPass (
137
150
MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
151
+ #else
152
+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
153
+ #endif
138
154
}
139
155
140
156
extern " C" LLVMPassRef LLVMRustCreateThreadSanitizerPass () {
157
+ #if LLVM_VERSION_LT(15, 0)
141
158
return wrap (createThreadSanitizerLegacyPassPass ());
159
+ #else
160
+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
161
+ #endif
142
162
}
143
163
144
164
extern " C" LLVMPassRef LLVMRustCreateHWAddressSanitizerPass (bool Recover) {
165
+ #if LLVM_VERSION_LT(15, 0)
145
166
const bool CompileKernel = false ;
146
167
147
168
return wrap (createHWAddressSanitizerLegacyPassPass (CompileKernel, Recover));
169
+ #else
170
+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
171
+ #endif
148
172
}
149
173
150
174
extern " C" LLVMRustPassKind LLVMRustPassKind (LLVMPassRef RustPass) {
@@ -154,23 +178,84 @@ extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) {
154
178
}
155
179
156
180
extern " C" void LLVMRustAddPass (LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
181
+ #if LLVM_VERSION_LT(15, 0)
157
182
assert (RustPass);
158
183
Pass *Pass = unwrap (RustPass);
159
184
PassManagerBase *PMB = unwrap (PMR);
160
185
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
161
232
}
162
233
163
234
extern " C"
164
235
void LLVMRustPassManagerBuilderPopulateThinLTOPassManager (
165
236
LLVMPassManagerBuilderRef PMBR,
166
237
LLVMPassManagerRef PMR
167
238
) {
239
+ #if LLVM_VERSION_LT(15, 0)
168
240
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
169
253
}
170
254
171
255
extern " C"
172
256
void LLVMRustAddLastExtensionPasses (
173
257
LLVMPassManagerBuilderRef PMBR, LLVMPassRef *Passes, size_t NumPasses) {
258
+ #if LLVM_VERSION_LT(15, 0)
174
259
auto AddExtensionPasses = [Passes, NumPasses](
175
260
const PassManagerBuilder &Builder, PassManagerBase &PM) {
176
261
for (size_t I = 0 ; I < NumPasses; I++) {
@@ -183,6 +268,9 @@ void LLVMRustAddLastExtensionPasses(
183
268
AddExtensionPasses);
184
269
unwrap (PMBR)->addExtension (PassManagerBuilder::EP_EnabledOnOptLevel0,
185
270
AddExtensionPasses);
271
+ #else
272
+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
273
+ #endif
186
274
}
187
275
188
276
#ifdef LLVM_COMPONENT_X86
@@ -533,12 +621,16 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
533
621
extern " C" void LLVMRustConfigurePassManagerBuilder (
534
622
LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel,
535
623
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)
537
627
unwrap (PMBR)->MergeFunctions = MergeFunctions;
538
628
unwrap (PMBR)->SLPVectorize = SLPVectorize;
539
629
unwrap (PMBR)->OptLevel = fromRust (OptLevel);
540
630
unwrap (PMBR)->LoopVectorize = LoopVectorize;
541
631
unwrap (PMBR)->PrepareForThinLTO = PrepareForThinLTO;
632
+ unwrap (PMBR)->SizeLevel = SizeLevel;
633
+ unwrap (PMBR)->DisableUnrollLoops = SizeLevel != 0 ;
542
634
543
635
if (PGOGenPath) {
544
636
assert (!PGOUsePath && !PGOSampleUsePath);
@@ -550,6 +642,9 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
550
642
} else if (PGOSampleUsePath) {
551
643
unwrap (PMBR)->PGOSampleUse = PGOSampleUsePath;
552
644
}
645
+ #else
646
+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
647
+ #endif
553
648
}
554
649
555
650
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
0 commit comments