15
15
#include " llvm/Support/CBindingWrapping.h"
16
16
#include " llvm/Support/FileSystem.h"
17
17
#include " llvm/Support/Host.h"
18
- #if LLVM_VERSION_MINOR >= 7
19
18
#include " llvm/Analysis/TargetLibraryInfo.h"
20
19
#include " llvm/Analysis/TargetTransformInfo.h"
21
- #else
22
- #include " llvm/Target/TargetLibraryInfo.h"
23
- #endif
24
20
#include " llvm/Target/TargetMachine.h"
25
21
#include " llvm/Target/TargetSubtargetInfo.h"
26
22
#include " llvm/Transforms/IPO/PassManagerBuilder.h"
@@ -49,7 +45,7 @@ LLVMInitializePasses() {
49
45
initializeVectorization (Registry);
50
46
initializeIPO (Registry);
51
47
initializeAnalysis (Registry);
52
- #if LLVM_VERSION_MINOR < = 7
48
+ #if LLVM_VERSION_MINOR = = 7
53
49
initializeIPA (Registry);
54
50
#endif
55
51
initializeTransformUtils (Registry);
@@ -223,17 +219,8 @@ LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
223
219
LLVMPassManagerRef PMR,
224
220
LLVMModuleRef M) {
225
221
PassManagerBase *PM = unwrap (PMR);
226
- #if LLVM_VERSION_MINOR >= 7
227
222
PM->add (createTargetTransformInfoWrapperPass (
228
223
unwrap (TM)->getTargetIRAnalysis ()));
229
- #else
230
- #if LLVM_VERSION_MINOR == 6
231
- PM->add (new DataLayoutPass ());
232
- #else
233
- PM->add (new DataLayoutPass (unwrap (M)));
234
- #endif
235
- unwrap (TM)->addAnalysisPasses (*PM);
236
- #endif
237
224
}
238
225
239
226
extern " C" void
@@ -242,10 +229,8 @@ LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
242
229
bool MergeFunctions,
243
230
bool SLPVectorize,
244
231
bool LoopVectorize) {
245
- #if LLVM_VERSION_MINOR >= 6
246
232
// Ignore mergefunc for now as enabling it causes crashes.
247
233
// unwrap(PMB)->MergeFunctions = MergeFunctions;
248
- #endif
249
234
unwrap (PMB)->SLPVectorize = SLPVectorize;
250
235
unwrap (PMB)->OptLevel = OptLevel;
251
236
unwrap (PMB)->LoopVectorize = LoopVectorize;
@@ -258,11 +243,7 @@ LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
258
243
LLVMModuleRef M,
259
244
bool DisableSimplifyLibCalls) {
260
245
Triple TargetTriple (unwrap (M)->getTargetTriple ());
261
- #if LLVM_VERSION_MINOR >= 7
262
246
TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl (TargetTriple);
263
- #else
264
- TargetLibraryInfo *TLI = new TargetLibraryInfo (TargetTriple);
265
- #endif
266
247
if (DisableSimplifyLibCalls)
267
248
TLI->disableAllFunctions ();
268
249
unwrap (PMB)->LibraryInfo = TLI;
@@ -275,17 +256,10 @@ LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
275
256
LLVMModuleRef M,
276
257
bool DisableSimplifyLibCalls) {
277
258
Triple TargetTriple (unwrap (M)->getTargetTriple ());
278
- #if LLVM_VERSION_MINOR >= 7
279
259
TargetLibraryInfoImpl TLII (TargetTriple);
280
260
if (DisableSimplifyLibCalls)
281
261
TLII.disableAllFunctions ();
282
262
unwrap (PMB)->add (new TargetLibraryInfoWrapperPass (TLII));
283
- #else
284
- TargetLibraryInfo *TLI = new TargetLibraryInfo (TargetTriple);
285
- if (DisableSimplifyLibCalls)
286
- TLI->disableAllFunctions ();
287
- unwrap (PMB)->add (TLI);
288
- #endif
289
263
}
290
264
291
265
// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
@@ -323,25 +297,16 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
323
297
PassManager *PM = unwrap<PassManager>(PMR);
324
298
325
299
std::string ErrorInfo;
326
- #if LLVM_VERSION_MINOR >= 6
327
300
std::error_code EC;
328
301
raw_fd_ostream OS (path, EC, sys::fs::F_None);
329
302
if (EC)
330
303
ErrorInfo = EC.message ();
331
- #else
332
- raw_fd_ostream OS (path, ErrorInfo, sys::fs::F_None);
333
- #endif
334
304
if (ErrorInfo != " " ) {
335
305
LLVMRustSetLastError (ErrorInfo.c_str ());
336
306
return false ;
337
307
}
338
308
339
- #if LLVM_VERSION_MINOR >= 7
340
309
unwrap (Target)->addPassesToEmitFile (*PM, OS, FileType, false );
341
- #else
342
- formatted_raw_ostream FOS (OS);
343
- unwrap (Target)->addPassesToEmitFile (*PM, FOS, FileType, false );
344
- #endif
345
310
PM->run (*unwrap (M));
346
311
347
312
// Apparently `addPassesToEmitFile` adds a pointer to our on-the-stack output
@@ -358,14 +323,10 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
358
323
PassManager *PM = unwrap<PassManager>(PMR);
359
324
std::string ErrorInfo;
360
325
361
- #if LLVM_VERSION_MINOR >= 6
362
326
std::error_code EC;
363
327
raw_fd_ostream OS (path, EC, sys::fs::F_None);
364
328
if (EC)
365
329
ErrorInfo = EC.message ();
366
- #else
367
- raw_fd_ostream OS (path, ErrorInfo, sys::fs::F_None);
368
- #endif
369
330
370
331
formatted_raw_ostream FOS (OS);
371
332
@@ -428,22 +389,10 @@ extern "C" void
428
389
LLVMRustSetDataLayoutFromTargetMachine (LLVMModuleRef Module,
429
390
LLVMTargetMachineRef TMR) {
430
391
TargetMachine *Target = unwrap (TMR);
431
- #if LLVM_VERSION_MINOR >= 7
432
392
unwrap (Module)->setDataLayout (Target->createDataLayout ());
433
- #elif LLVM_VERSION_MINOR >= 6
434
- if (const DataLayout *DL = Target->getSubtargetImpl ()->getDataLayout ())
435
- unwrap (Module)->setDataLayout (DL);
436
- #else
437
- if (const DataLayout *DL = Target->getDataLayout ())
438
- unwrap (Module)->setDataLayout (DL);
439
- #endif
440
393
}
441
394
442
395
extern " C" LLVMTargetDataRef
443
396
LLVMRustGetModuleDataLayout (LLVMModuleRef M) {
444
- #if LLVM_VERSION_MINOR >= 7
445
397
return wrap (&unwrap (M)->getDataLayout ());
446
- #else
447
- return wrap (unwrap (M)->getDataLayout ());
448
- #endif
449
398
}
0 commit comments