@@ -74,8 +74,7 @@ static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
7474}
7575
7676template <typename FPGALoopAttrT>
77- static Attr *handleIntelFPGALoopAttr (Sema &S, Stmt *St, const ParsedAttr &A) {
78-
77+ static Attr *handleIntelFPGALoopAttr (Sema &S, const ParsedAttr &A) {
7978 if (S.LangOpts .SYCLIsHost )
8079 return nullptr ;
8180
@@ -93,39 +92,7 @@ static Attr *handleIntelFPGALoopAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
9392 }
9493 }
9594
96- unsigned SafeInterval = 0 ;
97-
98- if (NumArgs == 1 ) {
99- Expr *E = A.getArgAsExpr (0 );
100- llvm::APSInt ArgVal (32 );
101-
102- if (!E->isIntegerConstantExpr (ArgVal, S.Context )) {
103- S.Diag (A.getLoc (), diag::err_attribute_argument_type)
104- << A << AANT_ArgumentIntegerConstant << E->getSourceRange ();
105- return nullptr ;
106- }
107-
108- int Val = ArgVal.getSExtValue ();
109-
110- if (A.getKind () != ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency) {
111- if (Val <= 0 ) {
112- S.Diag (A.getRange ().getBegin (),
113- diag::warn_attribute_requires_positive_integer)
114- << A << /* positive */ 0 ;
115- return nullptr ;
116- }
117- } else {
118- if (Val < 0 ) {
119- S.Diag (A.getRange ().getBegin (),
120- diag::warn_attribute_requires_positive_integer)
121- << A << /* non-negative */ 1 ;
122- return nullptr ;
123- }
124- }
125- SafeInterval = Val;
126- }
127-
128- return FPGALoopAttrT::CreateImplicit (S.Context , SafeInterval);
95+ return S.BuildSYCLIntelFPGALoopAttr <FPGALoopAttrT>(A, A.getArgAsExpr (0 ));
12996}
13097
13198static bool checkSYCLIntelFPGAIVDepSafeLen (Sema &S, llvm::APSInt &Value,
@@ -207,6 +174,44 @@ Sema::BuildSYCLIntelFPGAIVDepAttr(const AttributeCommonInfo &CI, Expr *Expr1,
207174 SYCLIntelFPGAIVDepAttr (Context, CI, SafeLenExpr, ArrayExpr, SafelenValue);
208175}
209176
177+ template <typename FPGALoopAttrT>
178+ FPGALoopAttrT *Sema::BuildSYCLIntelFPGALoopAttr (const AttributeCommonInfo &A,
179+ Expr *E) {
180+ if (!E)
181+ return nullptr ;
182+
183+ if (!E->isInstantiationDependent ()) {
184+ llvm::APSInt ArgVal (32 );
185+
186+ if (!E->isIntegerConstantExpr (ArgVal, getASTContext ())) {
187+ Diag (E->getExprLoc (), diag::err_attribute_argument_type)
188+ << A.getAttrName () << AANT_ArgumentIntegerConstant
189+ << E->getSourceRange ();
190+ return nullptr ;
191+ }
192+
193+ int Val = ArgVal.getSExtValue ();
194+
195+ if (A.getParsedKind () == ParsedAttr::AT_SYCLIntelFPGAII) {
196+ if (Val <= 0 ) {
197+ Diag (E->getExprLoc (), diag::err_attribute_requires_positive_integer)
198+ << " 'ii'" << /* positive */ 0 ;
199+ return nullptr ;
200+ }
201+ } else if (A.getParsedKind () ==
202+ ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency) {
203+ if (Val < 0 ) {
204+ Diag (E->getExprLoc (), diag::err_attribute_requires_positive_integer)
205+ << " 'max_concurrency'" << /* non-negative */ 1 ;
206+ return nullptr ;
207+ }
208+ } else {
209+ llvm_unreachable (" unknown sycl fpga loop attr" );
210+ }
211+ }
212+
213+ return new (Context) FPGALoopAttrT (Context, A, E);
214+ }
210215// Filters out any attributes from the list that are either not the specified
211216// type, or whose function isDependent returns true.
212217template <typename T>
@@ -611,9 +616,9 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
611616 case ParsedAttr::AT_SYCLIntelFPGAIVDep:
612617 return handleIntelFPGAIVDepAttr (S, A);
613618 case ParsedAttr::AT_SYCLIntelFPGAII:
614- return handleIntelFPGALoopAttr<SYCLIntelFPGAIIAttr>(S, St, A);
619+ return handleIntelFPGALoopAttr<SYCLIntelFPGAIIAttr>(S, A);
615620 case ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency:
616- return handleIntelFPGALoopAttr<SYCLIntelFPGAMaxConcurrencyAttr>(S, St, A);
621+ return handleIntelFPGALoopAttr<SYCLIntelFPGAMaxConcurrencyAttr>(S, A);
617622 case ParsedAttr::AT_OpenCLUnrollHint:
618623 return handleLoopUnrollHint<OpenCLUnrollHintAttr>(S, St, A, Range);
619624 case ParsedAttr::AT_LoopUnrollHint:
0 commit comments