@@ -498,44 +498,75 @@ static void buildRuntimeModule() {
498
498
// ////////////////////////////////////////////////////////////////////////////
499
499
500
500
// Construct some attribute lists used below (possibly multiple times)
501
- AttrSet NoAttrs,
502
- Attr_NoUnwind (NoAttrs, LLAttributeList::FunctionIndex,
503
- llvm::Attribute::NoUnwind),
501
+ AttrSet NoAttrs, Attr_NoUnwind, Attr_ReadOnly, Attr_ReadOnly_NoUnwind, Attr_Cold, Attr_Cold_NoReturn, Attr_Cold_NoReturn_NoUnwind,
502
+ Attr_ReadOnly_1_NoCapture, Attr_ReadOnly_1_3_NoCapture, Attr_ReadOnly_NoUnwind_1_NoCapture,
503
+ Attr_ReadOnly_NoUnwind_1_2_NoCapture, Attr_1_NoCapture, Attr_1_2_NoCapture, Attr_1_3_NoCapture,
504
+ Attr_1_4_NoCapture;
505
+ // `nounwind`
506
+ {
507
+ auto addNoUnwind = [&](AttrSet& a) {
508
+ llvm::AttrBuilder ab (context);
509
+ ab.addAttribute (llvm::Attribute::NoUnwind);
510
+ a.addToFunction (ab);
511
+ };
512
+ addNoUnwind (Attr_NoUnwind);
513
+ addNoUnwind (Attr_Cold_NoReturn_NoUnwind);
514
+ addNoUnwind (Attr_ReadOnly_NoUnwind);
515
+ addNoUnwind (Attr_ReadOnly_NoUnwind_1_NoCapture);
516
+ addNoUnwind (Attr_ReadOnly_NoUnwind_1_2_NoCapture);
517
+ }
518
+ // `readonly`
519
+ {
520
+ auto addReadOnly = [&](AttrSet& a) {
504
521
#if LDC_LLVM_VER >= 1600
505
- Attr_ReadOnly (llvm::AttributeList ().addFnAttribute (
506
- context, llvm::Attribute::getWithMemoryEffects (
507
- context, llvm::MemoryEffects::readOnly ()))),
522
+ a = a.merge (AttrSet (llvm::AttributeList ().addFnAttribute (
523
+ context, llvm::Attribute::getWithMemoryEffects (
524
+ context, llvm::MemoryEffects::readOnly ()))));
525
+ #else
526
+ llvm::AttrBuilder ab (context);
527
+ ab.addAttribute (llvm::Attribute::ReadOnly);
528
+ a = a.addToFunction (ab);
529
+ #endif
530
+ };
531
+ addReadOnly (Attr_ReadOnly);
532
+ addReadOnly (Attr_ReadOnly_NoUnwind);
533
+ addReadOnly (Attr_ReadOnly_1_NoCapture);
534
+ addReadOnly (Attr_ReadOnly_1_3_NoCapture);
535
+ addReadOnly (Attr_ReadOnly_NoUnwind_1_NoCapture);
536
+ addReadOnly (Attr_ReadOnly_NoUnwind_1_2_NoCapture);
537
+ }
538
+ // `cold`
539
+ {
540
+ auto addCold = [&](AttrSet& a) {
541
+ llvm::AttrBuilder ab (context);
542
+ ab.addAttribute (llvm::Attribute::Cold);
543
+ };
544
+ addCold (Attr_Cold);
545
+ addCold (Attr_Cold_NoReturn);
546
+ addCold (Attr_Cold_NoReturn_NoUnwind);
547
+ }
548
+ // `nocapture`/ `captures(none)`
549
+ {
550
+ auto addCapturesNone = [&](int extra, AttrSet& a) {
551
+ llvm::AttrBuilder ab (context);
552
+ #if LDC_LLVM_VER >= 2100
553
+ ab.addCapturesAttr (llvm::CaptureInfo::none ());
508
554
#else
509
- Attr_ReadOnly (NoAttrs, LLAttributeList::FunctionIndex,
510
- llvm::Attribute::ReadOnly),
555
+ ab.addAttribute (llvm::Attribute::NoCapture);
511
556
#endif
512
- Attr_Cold (NoAttrs, LLAttributeList::FunctionIndex, llvm::Attribute::Cold),
513
- Attr_Cold_NoReturn (Attr_Cold, LLAttributeList::FunctionIndex,
514
- llvm::Attribute::NoReturn),
515
- Attr_Cold_NoReturn_NoUnwind (Attr_Cold_NoReturn,
516
- LLAttributeList::FunctionIndex,
517
- llvm::Attribute::NoUnwind),
518
- Attr_ReadOnly_NoUnwind (Attr_ReadOnly, LLAttributeList::FunctionIndex,
519
- llvm::Attribute::NoUnwind),
520
- Attr_ReadOnly_1_NoCapture (Attr_ReadOnly, LLAttributeList::FirstArgIndex,
521
- llvm::Attribute::NoCapture),
522
- Attr_ReadOnly_1_3_NoCapture (Attr_ReadOnly_1_NoCapture,
523
- LLAttributeList::FirstArgIndex + 2 ,
524
- llvm::Attribute::NoCapture),
525
- Attr_ReadOnly_NoUnwind_1_NoCapture (Attr_ReadOnly_1_NoCapture,
526
- LLAttributeList::FunctionIndex,
527
- llvm::Attribute::NoUnwind),
528
- Attr_ReadOnly_NoUnwind_1_2_NoCapture (Attr_ReadOnly_NoUnwind_1_NoCapture,
529
- LLAttributeList::FirstArgIndex + 1 ,
530
- llvm::Attribute::NoCapture),
531
- Attr_1_NoCapture (NoAttrs, LLAttributeList::FirstArgIndex,
532
- llvm::Attribute::NoCapture),
533
- Attr_1_2_NoCapture (Attr_1_NoCapture, LLAttributeList::FirstArgIndex + 1 ,
534
- llvm::Attribute::NoCapture),
535
- Attr_1_3_NoCapture (Attr_1_NoCapture, LLAttributeList::FirstArgIndex + 2 ,
536
- llvm::Attribute::NoCapture),
537
- Attr_1_4_NoCapture (Attr_1_NoCapture, LLAttributeList::FirstArgIndex + 3 ,
538
- llvm::Attribute::NoCapture);
557
+ a.addToParam (0 , ab);
558
+ if (extra)
559
+ a.addToParam (extra-1 , ab);
560
+ };
561
+ addCapturesNone (0 , Attr_ReadOnly_1_NoCapture);
562
+ addCapturesNone (3 , Attr_ReadOnly_1_3_NoCapture);
563
+ addCapturesNone (0 , Attr_ReadOnly_NoUnwind_1_NoCapture);
564
+ addCapturesNone (2 , Attr_ReadOnly_NoUnwind_1_2_NoCapture);
565
+ addCapturesNone (0 , Attr_1_NoCapture);
566
+ addCapturesNone (2 , Attr_1_2_NoCapture);
567
+ addCapturesNone (3 , Attr_1_3_NoCapture);
568
+ addCapturesNone (4 , Attr_1_4_NoCapture);
569
+ }
539
570
540
571
// ////////////////////////////////////////////////////////////////////////////
541
572
// ////////////////////////////////////////////////////////////////////////////
0 commit comments