9
9
// except according to those terms.
10
10
11
11
#include " rustllvm.h"
12
+ #include " llvm/IR/CallSite.h"
12
13
#include " llvm/IR/DebugInfoMetadata.h"
13
14
#include " llvm/IR/DiagnosticInfo.h"
14
15
#include " llvm/IR/DiagnosticPrinter.h"
18
19
#include " llvm/Object/ObjectFile.h"
19
20
#include " llvm/Bitcode/BitcodeWriterPass.h"
20
21
#include " llvm/Support/Signals.h"
21
-
22
- #include " llvm/IR/CallSite.h"
23
-
24
- #if LLVM_VERSION_GE(5, 0)
25
22
#include " llvm/ADT/Optional.h"
26
- #else
27
- #include < cstdlib>
28
- #endif
29
23
30
24
#include < iostream>
31
25
@@ -212,14 +206,7 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
212
206
LLVMRustAttribute RustAttr) {
213
207
CallSite Call = CallSite (unwrap<Instruction>(Instr));
214
208
Attribute Attr = Attribute::get (Call->getContext (), fromRust (RustAttr));
215
- #if LLVM_VERSION_GE(5, 0)
216
209
Call.addAttribute (Index, Attr);
217
- #else
218
- AttrBuilder B (Attr);
219
- Call.setAttributes (Call.getAttributes ().addAttributes (
220
- Call->getContext (), Index,
221
- AttributeSet::get (Call->getContext (), Index, B)));
222
- #endif
223
210
}
224
211
225
212
extern " C" void LLVMRustAddAlignmentCallSiteAttr (LLVMValueRef Instr,
@@ -228,14 +215,8 @@ extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr,
228
215
CallSite Call = CallSite (unwrap<Instruction>(Instr));
229
216
AttrBuilder B;
230
217
B.addAlignmentAttr (Bytes);
231
- #if LLVM_VERSION_GE(5, 0)
232
218
Call.setAttributes (Call.getAttributes ().addAttributes (
233
219
Call->getContext (), Index, B));
234
- #else
235
- Call.setAttributes (Call.getAttributes ().addAttributes (
236
- Call->getContext (), Index,
237
- AttributeSet::get (Call->getContext (), Index, B)));
238
- #endif
239
220
}
240
221
241
222
extern " C" void LLVMRustAddDereferenceableCallSiteAttr (LLVMValueRef Instr,
@@ -244,14 +225,8 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
244
225
CallSite Call = CallSite (unwrap<Instruction>(Instr));
245
226
AttrBuilder B;
246
227
B.addDereferenceableAttr (Bytes);
247
- #if LLVM_VERSION_GE(5, 0)
248
228
Call.setAttributes (Call.getAttributes ().addAttributes (
249
229
Call->getContext (), Index, B));
250
- #else
251
- Call.setAttributes (Call.getAttributes ().addAttributes (
252
- Call->getContext (), Index,
253
- AttributeSet::get (Call->getContext (), Index, B)));
254
- #endif
255
230
}
256
231
257
232
extern " C" void LLVMRustAddDereferenceableOrNullCallSiteAttr (LLVMValueRef Instr,
@@ -260,26 +235,16 @@ extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr,
260
235
CallSite Call = CallSite (unwrap<Instruction>(Instr));
261
236
AttrBuilder B;
262
237
B.addDereferenceableOrNullAttr (Bytes);
263
- #if LLVM_VERSION_GE(5, 0)
264
238
Call.setAttributes (Call.getAttributes ().addAttributes (
265
239
Call->getContext (), Index, B));
266
- #else
267
- Call.setAttributes (Call.getAttributes ().addAttributes (
268
- Call->getContext (), Index,
269
- AttributeSet::get (Call->getContext (), Index, B)));
270
- #endif
271
240
}
272
241
273
242
extern " C" void LLVMRustAddFunctionAttribute (LLVMValueRef Fn, unsigned Index,
274
243
LLVMRustAttribute RustAttr) {
275
244
Function *A = unwrap<Function>(Fn);
276
245
Attribute Attr = Attribute::get (A->getContext (), fromRust (RustAttr));
277
246
AttrBuilder B (Attr);
278
- #if LLVM_VERSION_GE(5, 0)
279
247
A->addAttributes (Index, B);
280
- #else
281
- A->addAttributes (Index, AttributeSet::get (A->getContext (), Index, B));
282
- #endif
283
248
}
284
249
285
250
extern " C" void LLVMRustAddAlignmentAttr (LLVMValueRef Fn,
@@ -288,23 +253,15 @@ extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn,
288
253
Function *A = unwrap<Function>(Fn);
289
254
AttrBuilder B;
290
255
B.addAlignmentAttr (Bytes);
291
- #if LLVM_VERSION_GE(5, 0)
292
256
A->addAttributes (Index, B);
293
- #else
294
- A->addAttributes (Index, AttributeSet::get (A->getContext (), Index, B));
295
- #endif
296
257
}
297
258
298
259
extern " C" void LLVMRustAddDereferenceableAttr (LLVMValueRef Fn, unsigned Index,
299
260
uint64_t Bytes) {
300
261
Function *A = unwrap<Function>(Fn);
301
262
AttrBuilder B;
302
263
B.addDereferenceableAttr (Bytes);
303
- #if LLVM_VERSION_GE(5, 0)
304
264
A->addAttributes (Index, B);
305
- #else
306
- A->addAttributes (Index, AttributeSet::get (A->getContext (), Index, B));
307
- #endif
308
265
}
309
266
310
267
extern " C" void LLVMRustAddDereferenceableOrNullAttr (LLVMValueRef Fn,
@@ -313,11 +270,7 @@ extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
313
270
Function *A = unwrap<Function>(Fn);
314
271
AttrBuilder B;
315
272
B.addDereferenceableOrNullAttr (Bytes);
316
- #if LLVM_VERSION_GE(5, 0)
317
273
A->addAttributes (Index, B);
318
- #else
319
- A->addAttributes (Index, AttributeSet::get (A->getContext (), Index, B));
320
- #endif
321
274
}
322
275
323
276
extern " C" void LLVMRustAddFunctionAttrStringValue (LLVMValueRef Fn,
@@ -327,11 +280,7 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
327
280
Function *F = unwrap<Function>(Fn);
328
281
AttrBuilder B;
329
282
B.addAttribute (Name, Value);
330
- #if LLVM_VERSION_GE(5, 0)
331
283
F->addAttributes (Index, B);
332
- #else
333
- F->addAttributes (Index, AttributeSet::get (F->getContext (), Index, B));
334
- #endif
335
284
}
336
285
337
286
extern " C" void LLVMRustRemoveFunctionAttributes (LLVMValueRef Fn,
@@ -341,12 +290,7 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
341
290
Attribute Attr = Attribute::get (F->getContext (), fromRust (RustAttr));
342
291
AttrBuilder B (Attr);
343
292
auto PAL = F->getAttributes ();
344
- #if LLVM_VERSION_GE(5, 0)
345
293
auto PALNew = PAL.removeAttributes (F->getContext (), Index, B);
346
- #else
347
- const AttributeSet PALNew = PAL.removeAttributes (
348
- F->getContext (), Index, AttributeSet::get (F->getContext (), Index, B));
349
- #endif
350
294
F->setAttributes (PALNew);
351
295
}
352
296
@@ -396,7 +340,6 @@ enum class LLVMRustSynchronizationScope {
396
340
CrossThread,
397
341
};
398
342
399
- #if LLVM_VERSION_GE(5, 0)
400
343
static SyncScope::ID fromRust (LLVMRustSynchronizationScope Scope) {
401
344
switch (Scope) {
402
345
case LLVMRustSynchronizationScope::SingleThread:
@@ -407,18 +350,6 @@ static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) {
407
350
report_fatal_error (" bad SynchronizationScope." );
408
351
}
409
352
}
410
- #else
411
- static SynchronizationScope fromRust (LLVMRustSynchronizationScope Scope) {
412
- switch (Scope) {
413
- case LLVMRustSynchronizationScope::SingleThread:
414
- return SingleThread;
415
- case LLVMRustSynchronizationScope::CrossThread:
416
- return CrossThread;
417
- default :
418
- report_fatal_error (" bad SynchronizationScope." );
419
- }
420
- }
421
- #endif
422
353
423
354
extern " C" LLVMValueRef
424
355
LLVMRustBuildAtomicFence (LLVMBuilderRef B, LLVMAtomicOrdering Order,
@@ -463,18 +394,6 @@ extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm)
463
394
464
395
typedef DIBuilder *LLVMRustDIBuilderRef;
465
396
466
- #if LLVM_VERSION_LT(5, 0)
467
- typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
468
-
469
- namespace llvm {
470
- DEFINE_ISA_CONVERSION_FUNCTIONS (Metadata, LLVMMetadataRef)
471
-
472
- inline Metadata **unwrap (LLVMMetadataRef *Vals) {
473
- return reinterpret_cast <Metadata **>(Vals);
474
- }
475
- }
476
- #endif
477
-
478
397
template <typename DIT> DIT *unwrapDIPtr (LLVMMetadataRef Ref) {
479
398
return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr );
480
399
}
@@ -590,11 +509,6 @@ static DINode::DIFlags fromRust(LLVMRustDIFlags Flags) {
590
509
if (isSet (Flags & LLVMRustDIFlags::FlagRValueReference)) {
591
510
Result |= DINode::DIFlags::FlagRValueReference;
592
511
}
593
- #if LLVM_VERSION_LE(4, 0)
594
- if (isSet (Flags & LLVMRustDIFlags::FlagExternalTypeRef)) {
595
- Result |= DINode::DIFlags::FlagExternalTypeRef;
596
- }
597
- #endif
598
512
if (isSet (Flags & LLVMRustDIFlags::FlagIntroducedVirtual)) {
599
513
Result |= DINode::DIFlags::FlagIntroducedVirtual;
600
514
}
@@ -693,9 +607,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
693
607
uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) {
694
608
return wrap (Builder->createPointerType (unwrapDI<DIType>(PointeeTy),
695
609
SizeInBits, AlignInBits,
696
- #if LLVM_VERSION_GE(5, 0)
697
610
/* DWARFAddressSpace */ None,
698
- #endif
699
611
Name));
700
612
}
701
613
@@ -902,12 +814,7 @@ LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder,
902
814
LLVMMetadataRef Scope, const char *Name,
903
815
LLVMMetadataRef File, unsigned LineNo) {
904
816
return wrap (Builder->createNameSpace (
905
- unwrapDI<DIDescriptor>(Scope), Name
906
- #if LLVM_VERSION_LT(5, 0)
907
- ,
908
- unwrapDI<DIFile>(File), LineNo
909
- #endif
910
- ,
817
+ unwrapDI<DIDescriptor>(Scope), Name,
911
818
false // ExportSymbols (only relevant for C++ anonymous namespaces)
912
819
));
913
820
}
@@ -937,12 +844,7 @@ extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() {
937
844
}
938
845
939
846
extern " C" int64_t LLVMRustDIBuilderCreateOpPlusUconst () {
940
- #if LLVM_VERSION_GE(5, 0)
941
847
return dwarf::DW_OP_plus_uconst;
942
- #else
943
- // older LLVM used `plus` to behave like `plus_uconst`.
944
- return dwarf::DW_OP_plus;
945
- #endif
946
848
}
947
849
948
850
extern " C" void LLVMRustWriteTypeToString (LLVMTypeRef Ty, RustStringRef Str) {
@@ -1014,21 +916,12 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic(
1014
916
*FunctionOut = wrap (&Opt->getFunction ());
1015
917
1016
918
RawRustStringOstream FilenameOS (FilenameOut);
1017
- #if LLVM_VERSION_GE(5,0)
1018
919
DiagnosticLocation loc = Opt->getLocation ();
1019
920
if (loc.isValid ()) {
1020
921
*Line = loc.getLine ();
1021
922
*Column = loc.getColumn ();
1022
923
FilenameOS << loc.getFilename ();
1023
924
}
1024
- #else
1025
- const DebugLoc &loc = Opt->getDebugLoc ();
1026
- if (loc) {
1027
- *Line = loc.getLine ();
1028
- *Column = loc.getCol ();
1029
- FilenameOS << cast<DIScope>(loc.getScope ())->getFilename ();
1030
- }
1031
- #endif
1032
925
1033
926
RawRustStringOstream MessageOS (MessageOut);
1034
927
MessageOS << Opt->getMsg ();
@@ -1451,7 +1344,6 @@ LLVMRustModuleCost(LLVMModuleRef M) {
1451
1344
}
1452
1345
1453
1346
// Vector reductions:
1454
- #if LLVM_VERSION_GE(5, 0)
1455
1347
extern " C" LLVMValueRef
1456
1348
LLVMRustBuildVectorReduceFAdd (LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Src) {
1457
1349
return wrap (unwrap (B)->CreateFAddReduce (unwrap (Acc),unwrap (Src)));
@@ -1497,54 +1389,6 @@ LLVMRustBuildVectorReduceFMax(LLVMBuilderRef B, LLVMValueRef Src, bool NoNaN) {
1497
1389
return wrap (unwrap (B)->CreateFPMaxReduce (unwrap (Src), NoNaN));
1498
1390
}
1499
1391
1500
- #else
1501
-
1502
- extern " C" LLVMValueRef
1503
- LLVMRustBuildVectorReduceFAdd (LLVMBuilderRef, LLVMValueRef, LLVMValueRef) {
1504
- return nullptr ;
1505
- }
1506
- extern " C" LLVMValueRef
1507
- LLVMRustBuildVectorReduceFMul (LLVMBuilderRef, LLVMValueRef, LLVMValueRef) {
1508
- return nullptr ;
1509
- }
1510
- extern " C" LLVMValueRef
1511
- LLVMRustBuildVectorReduceAdd (LLVMBuilderRef, LLVMValueRef) {
1512
- return nullptr ;
1513
- }
1514
- extern " C" LLVMValueRef
1515
- LLVMRustBuildVectorReduceMul (LLVMBuilderRef, LLVMValueRef) {
1516
- return nullptr ;
1517
- }
1518
- extern " C" LLVMValueRef
1519
- LLVMRustBuildVectorReduceAnd (LLVMBuilderRef, LLVMValueRef) {
1520
- return nullptr ;
1521
- }
1522
- extern " C" LLVMValueRef
1523
- LLVMRustBuildVectorReduceOr (LLVMBuilderRef, LLVMValueRef) {
1524
- return nullptr ;
1525
- }
1526
- extern " C" LLVMValueRef
1527
- LLVMRustBuildVectorReduceXor (LLVMBuilderRef, LLVMValueRef) {
1528
- return nullptr ;
1529
- }
1530
- extern " C" LLVMValueRef
1531
- LLVMRustBuildVectorReduceMin (LLVMBuilderRef, LLVMValueRef, bool ) {
1532
- return nullptr ;
1533
- }
1534
- extern " C" LLVMValueRef
1535
- LLVMRustBuildVectorReduceMax (LLVMBuilderRef, LLVMValueRef, bool ) {
1536
- return nullptr ;
1537
- }
1538
- extern " C" LLVMValueRef
1539
- LLVMRustBuildVectorReduceFMin (LLVMBuilderRef, LLVMValueRef, bool ) {
1540
- return nullptr ;
1541
- }
1542
- extern " C" LLVMValueRef
1543
- LLVMRustBuildVectorReduceFMax (LLVMBuilderRef, LLVMValueRef, bool ) {
1544
- return nullptr ;
1545
- }
1546
- #endif
1547
-
1548
1392
#if LLVM_VERSION_GE(6, 0)
1549
1393
extern " C" LLVMValueRef
1550
1394
LLVMRustBuildMinNum (LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) {
0 commit comments