@@ -498,44 +498,73 @@ 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
+ a = a.addToFunction (llvm::Attribute::ReadOnly);
527
+ #endif
528
+ };
529
+ addReadOnly (Attr_ReadOnly);
530
+ addReadOnly (Attr_ReadOnly_NoUnwind);
531
+ addReadOnly (Attr_ReadOnly_1_NoCapture);
532
+ addReadOnly (Attr_ReadOnly_1_3_NoCapture);
533
+ addReadOnly (Attr_ReadOnly_NoUnwind_1_NoCapture);
534
+ addReadOnly (Attr_ReadOnly_NoUnwind_1_2_NoCapture);
535
+ }
536
+ // `cold`
537
+ {
538
+ auto addCold = [&](AttrSet& a) {
539
+ llvm::AttrBuilder ab (context);
540
+ ab.addAttribute (llvm::Attribute::Cold);
541
+ };
542
+ addCold (Attr_Cold);
543
+ addCold (Attr_Cold_NoReturn);
544
+ addCold (Attr_Cold_NoReturn_NoUnwind);
545
+ }
546
+ // `nocapture`/ `captures(none)`
547
+ {
548
+ auto addCapturesNone = [&](int extra, AttrSet& a) {
549
+ llvm::AttrBuilder ab (context);
550
+ #if LDC_LLVM_VER >= 2100
551
+ ab.addCapturesAttr (llvm::CaptureInfo::none ());
508
552
#else
509
- Attr_ReadOnly (NoAttrs, LLAttributeList::FunctionIndex,
510
- llvm::Attribute::ReadOnly),
553
+ ab.addAttribute (llvm::Attribute::NoCapture);
511
554
#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);
555
+ a.addToParam (0 , ab);
556
+ if (extra)
557
+ a.addToParam (extra-1 , ab);
558
+ };
559
+ addCapturesNone (0 , Attr_ReadOnly_1_NoCapture);
560
+ addCapturesNone (3 , Attr_ReadOnly_1_3_NoCapture);
561
+ addCapturesNone (0 , Attr_ReadOnly_NoUnwind_1_NoCapture);
562
+ addCapturesNone (2 , Attr_ReadOnly_NoUnwind_1_2_NoCapture);
563
+ addCapturesNone (0 , Attr_1_NoCapture);
564
+ addCapturesNone (2 , Attr_1_2_NoCapture);
565
+ addCapturesNone (3 , Attr_1_3_NoCapture);
566
+ addCapturesNone (4 , Attr_1_4_NoCapture);
567
+ }
539
568
540
569
// ////////////////////////////////////////////////////////////////////////////
541
570
// ////////////////////////////////////////////////////////////////////////////
0 commit comments