@@ -532,7 +532,6 @@ MDNode *LoopInfo::createMetadata(
532
532
533
533
// Setting ii attribute with an initiation interval
534
534
if (Attrs.SYCLIInterval > 0 ) {
535
- LLVMContext &Ctx = Header->getContext ();
536
535
Metadata *Vals[] = {MDString::get (Ctx, " llvm.loop.ii.count" ),
537
536
ConstantAsMetadata::get (ConstantInt::get (
538
537
llvm::Type::getInt32Ty (Ctx), Attrs.SYCLIInterval ))};
@@ -541,14 +540,52 @@ MDNode *LoopInfo::createMetadata(
541
540
542
541
// Setting max_concurrency attribute with number of threads
543
542
if (Attrs.SYCLMaxConcurrencyEnable ) {
544
- LLVMContext &Ctx = Header->getContext ();
545
543
Metadata *Vals[] = {MDString::get (Ctx, " llvm.loop.max_concurrency.count" ),
546
544
ConstantAsMetadata::get (ConstantInt::get (
547
545
llvm::Type::getInt32Ty (Ctx),
548
546
Attrs.SYCLMaxConcurrencyNThreads ))};
549
547
LoopProperties.push_back (MDNode::get (Ctx, Vals));
550
548
}
551
549
550
+ if (Attrs.SYCLLoopCoalesceEnable ) {
551
+ Metadata *Vals[] = {MDString::get (Ctx, " llvm.loop.coalesce.enable" )};
552
+ LoopProperties.push_back (MDNode::get (Ctx, Vals));
553
+ }
554
+
555
+ if (Attrs.SYCLLoopCoalesceNLevels > 0 ) {
556
+ Metadata *Vals[] = {
557
+ MDString::get (Ctx, " llvm.loop.coalesce.count" ),
558
+ ConstantAsMetadata::get (ConstantInt::get (
559
+ llvm::Type::getInt32Ty (Ctx), Attrs.SYCLLoopCoalesceNLevels ))};
560
+ LoopProperties.push_back (MDNode::get (Ctx, Vals));
561
+ }
562
+
563
+ // disable_loop_pipelining attribute corresponds to
564
+ // 'llvm.loop.intel.pipelining.enable, i32 0' metadata
565
+ if (Attrs.SYCLLoopPipeliningDisable ) {
566
+ Metadata *Vals[] = {MDString::get (Ctx, " llvm.loop.intel.pipelining.enable" ),
567
+ ConstantAsMetadata::get (
568
+ ConstantInt::get (llvm::Type::getInt32Ty (Ctx), 0 ))};
569
+ LoopProperties.push_back (MDNode::get (Ctx, Vals));
570
+ }
571
+
572
+ if (Attrs.SYCLMaxInterleavingEnable ) {
573
+ Metadata *Vals[] = {MDString::get (Ctx, " llvm.loop.max_interleaving.count" ),
574
+ ConstantAsMetadata::get (ConstantInt::get (
575
+ llvm::Type::getInt32Ty (Ctx),
576
+ Attrs.SYCLMaxInterleavingNInvocations ))};
577
+ LoopProperties.push_back (MDNode::get (Ctx, Vals));
578
+ }
579
+
580
+ if (Attrs.SYCLSpeculatedIterationsEnable ) {
581
+ Metadata *Vals[] = {
582
+ MDString::get (Ctx, " llvm.loop.intel.speculated.iterations.count" ),
583
+ ConstantAsMetadata::get (
584
+ ConstantInt::get (llvm::Type::getInt32Ty (Ctx),
585
+ Attrs.SYCLSpeculatedIterationsNIterations ))};
586
+ LoopProperties.push_back (MDNode::get (Ctx, Vals));
587
+ }
588
+
552
589
LoopProperties.insert (LoopProperties.end (), AdditionalLoopProperties.begin (),
553
590
AdditionalLoopProperties.end ());
554
591
return createFullUnrollMetadata (Attrs, LoopProperties, HasUserTransforms);
@@ -560,9 +597,13 @@ LoopAttributes::LoopAttributes(bool IsParallel)
560
597
UnrollAndJamEnable(LoopAttributes::Unspecified),
561
598
VectorizePredicateEnable(LoopAttributes::Unspecified), VectorizeWidth(0 ),
562
599
InterleaveCount(0 ), SYCLIInterval(0 ), SYCLMaxConcurrencyEnable(false ),
563
- SYCLMaxConcurrencyNThreads(0 ), UnrollCount(0 ), UnrollAndJamCount(0 ),
564
- DistributeEnable(LoopAttributes::Unspecified), PipelineDisabled(false ),
565
- PipelineInitiationInterval(0 ) {}
600
+ SYCLMaxConcurrencyNThreads(0 ), SYCLLoopCoalesceEnable(false ),
601
+ SYCLLoopCoalesceNLevels(0 ), SYCLLoopPipeliningDisable(false ),
602
+ SYCLMaxInterleavingEnable(false ), SYCLMaxInterleavingNInvocations(0 ),
603
+ SYCLSpeculatedIterationsEnable(false ),
604
+ SYCLSpeculatedIterationsNIterations(0 ), UnrollCount(0 ),
605
+ UnrollAndJamCount(0 ), DistributeEnable(LoopAttributes::Unspecified),
606
+ PipelineDisabled(false ), PipelineInitiationInterval(0 ) {}
566
607
567
608
void LoopAttributes::clear () {
568
609
IsParallel = false ;
@@ -572,6 +613,13 @@ void LoopAttributes::clear() {
572
613
SYCLIInterval = 0 ;
573
614
SYCLMaxConcurrencyEnable = false ;
574
615
SYCLMaxConcurrencyNThreads = 0 ;
616
+ SYCLLoopCoalesceEnable = false ;
617
+ SYCLLoopCoalesceNLevels = 0 ;
618
+ SYCLLoopPipeliningDisable = false ;
619
+ SYCLMaxInterleavingEnable = false ;
620
+ SYCLMaxInterleavingNInvocations = 0 ;
621
+ SYCLSpeculatedIterationsEnable = false ;
622
+ SYCLSpeculatedIterationsNIterations = 0 ;
575
623
InterleaveCount = 0 ;
576
624
UnrollCount = 0 ;
577
625
UnrollAndJamCount = 0 ;
@@ -599,9 +647,16 @@ LoopInfo::LoopInfo(BasicBlock *Header, const LoopAttributes &Attrs,
599
647
if (!Attrs.IsParallel && Attrs.VectorizeWidth == 0 &&
600
648
Attrs.InterleaveCount == 0 && !Attrs.GlobalSYCLIVDepInfo .hasValue () &&
601
649
Attrs.ArraySYCLIVDepInfo .empty () && Attrs.SYCLIInterval == 0 &&
602
- Attrs.SYCLMaxConcurrencyEnable == false && Attrs.UnrollCount == 0 &&
603
- Attrs.UnrollAndJamCount == 0 && !Attrs.PipelineDisabled &&
604
- Attrs.PipelineInitiationInterval == 0 &&
650
+ Attrs.SYCLMaxConcurrencyEnable == false &&
651
+ Attrs.SYCLLoopCoalesceEnable == false &&
652
+ Attrs.SYCLLoopCoalesceNLevels == 0 &&
653
+ Attrs.SYCLLoopPipeliningDisable == false &&
654
+ Attrs.SYCLMaxInterleavingEnable == false &&
655
+ Attrs.SYCLMaxInterleavingNInvocations == 0 &&
656
+ Attrs.SYCLSpeculatedIterationsEnable == false &&
657
+ Attrs.SYCLSpeculatedIterationsNIterations == 0 &&
658
+ Attrs.UnrollCount == 0 && Attrs.UnrollAndJamCount == 0 &&
659
+ !Attrs.PipelineDisabled && Attrs.PipelineInitiationInterval == 0 &&
605
660
Attrs.VectorizePredicateEnable == LoopAttributes::Unspecified &&
606
661
Attrs.VectorizeEnable == LoopAttributes::Unspecified &&
607
662
Attrs.UnrollEnable == LoopAttributes::Unspecified &&
@@ -903,15 +958,36 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
903
958
// n - 'llvm.loop.ii.count, i32 n' metadata will be emitted
904
959
// For attribute max_concurrency:
905
960
// n - 'llvm.loop.max_concurrency.count, i32 n' metadata will be emitted
961
+ // For attribute loop_coalesce:
962
+ // without parameter - 'lvm.loop.coalesce.enable' metadata will be emitted
963
+ // n - 'llvm.loop.coalesce.count, i32 n' metadata will be emitted
964
+ // For attribute disable_loop_pipelining:
965
+ // 'llvm.loop.intel.pipelining.enable, i32 0' metadata will be emitted
966
+ // For attribute max_interleaving:
967
+ // n - 'llvm.loop.max_interleaving.count, i32 n' metadata will be emitted
968
+ // For attribute speculated_iterations:
969
+ // n - 'llvm.loop.intel.speculated.iterations.count, i32 n' metadata will be
970
+ // emitted
906
971
for (const auto *Attr : Attrs) {
907
972
const SYCLIntelFPGAIVDepAttr *IntelFPGAIVDep =
908
973
dyn_cast<SYCLIntelFPGAIVDepAttr>(Attr);
909
974
const SYCLIntelFPGAIIAttr *IntelFPGAII =
910
975
dyn_cast<SYCLIntelFPGAIIAttr>(Attr);
911
976
const SYCLIntelFPGAMaxConcurrencyAttr *IntelFPGAMaxConcurrency =
912
977
dyn_cast<SYCLIntelFPGAMaxConcurrencyAttr>(Attr);
913
-
914
- if (!IntelFPGAIVDep && !IntelFPGAII && !IntelFPGAMaxConcurrency)
978
+ const SYCLIntelFPGALoopCoalesceAttr *IntelFPGALoopCoalesce =
979
+ dyn_cast<SYCLIntelFPGALoopCoalesceAttr>(Attr);
980
+ const SYCLIntelFPGADisableLoopPipeliningAttr
981
+ *IntelFPGADisableLoopPipelining =
982
+ dyn_cast<SYCLIntelFPGADisableLoopPipeliningAttr>(Attr);
983
+ const SYCLIntelFPGAMaxInterleavingAttr *IntelFPGAMaxInterleaving =
984
+ dyn_cast<SYCLIntelFPGAMaxInterleavingAttr>(Attr);
985
+ const SYCLIntelFPGASpeculatedIterationsAttr *IntelFPGASpeculatedIterations =
986
+ dyn_cast<SYCLIntelFPGASpeculatedIterationsAttr>(Attr);
987
+
988
+ if (!IntelFPGAIVDep && !IntelFPGAII && !IntelFPGAMaxConcurrency &&
989
+ !IntelFPGALoopCoalesce && !IntelFPGADisableLoopPipelining &&
990
+ !IntelFPGAMaxInterleaving && !IntelFPGASpeculatedIterations)
915
991
continue ;
916
992
917
993
if (IntelFPGAIVDep) {
@@ -944,6 +1020,44 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
944
1020
setSYCLMaxConcurrencyEnable ();
945
1021
setSYCLMaxConcurrencyNThreads (ArgVal.getSExtValue ());
946
1022
}
1023
+
1024
+ if (IntelFPGALoopCoalesce) {
1025
+ llvm::APSInt ArgVal (32 );
1026
+ if (auto *LCE = IntelFPGALoopCoalesce->getNExpr ()) {
1027
+ bool IsValid = LCE->isIntegerConstantExpr (ArgVal, Ctx);
1028
+ assert (IsValid && " Not an integer constant expression" );
1029
+ (void )IsValid;
1030
+ setSYCLLoopCoalesceNLevels (ArgVal.getSExtValue ());
1031
+ } else {
1032
+ setSYCLLoopCoalesceEnable ();
1033
+ }
1034
+ }
1035
+
1036
+ if (IntelFPGADisableLoopPipelining) {
1037
+ setSYCLLoopPipeliningDisable ();
1038
+ }
1039
+
1040
+ if (IntelFPGAMaxInterleaving) {
1041
+ llvm::APSInt ArgVal (32 );
1042
+ bool IsValid =
1043
+ IntelFPGAMaxInterleaving->getNExpr ()->isIntegerConstantExpr (ArgVal,
1044
+ Ctx);
1045
+ assert (IsValid && " Not an integer constant expression" );
1046
+ (void )IsValid;
1047
+ setSYCLMaxInterleavingEnable ();
1048
+ setSYCLMaxInterleavingNInvocations (ArgVal.getSExtValue ());
1049
+ }
1050
+
1051
+ if (IntelFPGASpeculatedIterations) {
1052
+ llvm::APSInt ArgVal (32 );
1053
+ bool IsValid =
1054
+ IntelFPGASpeculatedIterations->getNExpr ()->isIntegerConstantExpr (
1055
+ ArgVal, Ctx);
1056
+ assert (IsValid && " Not an integer constant expression" );
1057
+ (void )IsValid;
1058
+ setSYCLSpeculatedIterationsEnable ();
1059
+ setSYCLSpeculatedIterationsNIterations (ArgVal.getSExtValue ());
1060
+ }
947
1061
}
948
1062
949
1063
// / Stage the attributes.
0 commit comments