-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL][FPGA] Add Intel FPGA bank_bits attribute #876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3761,6 +3761,15 @@ void Sema::AddOneConstantPowerTwoValueAttr(Decl *D, | |
<< &TmpAttr; | ||
return; | ||
} | ||
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) { | ||
if (auto *BBA = D->getAttr<IntelFPGABankBitsAttr>()) { | ||
unsigned NumBankBits = BBA->args_size(); | ||
if (NumBankBits != Value.ceilLogBase2()) { | ||
Diag(TmpAttr.getLocation(), diag::err_bankbits_numbanks_conflicting); | ||
return; | ||
} | ||
} | ||
} | ||
E = ICE.get(); | ||
} | ||
|
||
|
@@ -5105,6 +5114,8 @@ static bool checkIntelFPGARegisterAttrCompatibility(Sema &S, Decl *D, | |
InCompat = true; | ||
if (checkAttrMutualExclusion<IntelFPGAMergeAttr>(S, D, Attr)) | ||
InCompat = true; | ||
if (checkAttrMutualExclusion<IntelFPGABankBitsAttr>(S, D, Attr)) | ||
InCompat = true; | ||
|
||
return InCompat; | ||
} | ||
|
@@ -5209,6 +5220,92 @@ static void handleIntelFPGAMergeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |
IntelFPGAMergeAttr(S.Context, AL, Results[0], Results[1])); | ||
} | ||
|
||
/// Handle the bank_bits attribute. | ||
/// This attribute accepts a list of values greater than zero. | ||
/// This is incompatible with the register attribute. | ||
/// The numbanks and bank_bits attributes are related. If numbanks exists | ||
/// when handling bank_bits they are checked for consistency. If numbanks | ||
/// hasn't been added yet an implicit one is added with the correct value. | ||
MrSidims marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// If the user later adds a numbanks attribute the implicit one is removed. | ||
/// The values must be consecutive values (i.e. 3,4,5 or 2,1). | ||
static void handleIntelFPGABankBitsAttr(Sema &S, Decl *D, | ||
const ParsedAttr &Attr) { | ||
checkForDuplicateAttribute<IntelFPGABankBitsAttr>(S, D, Attr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add D decl validity check: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure we need this check? It seems that other attributes handling has no such check. I think that it is handled higher in the call stack. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends on a contract we have with clang code:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have here a strong evidences to push anyone to follow my own preferences, but as far as I'm a pedantic person - I'd prefer to add this check at least in a code what I write. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quickly looking into the code I did not find such checks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean declaration invalidation checks before attribute handling earlier in the code. |
||
|
||
if (!checkAttributeAtLeastNumArgs(S, Attr, 1)) | ||
return; | ||
|
||
if (checkAttrMutualExclusion<IntelFPGARegisterAttr>(S, D, Attr)) | ||
return; | ||
|
||
SmallVector<Expr *, 8> Args; | ||
for (unsigned I = 0; I < Attr.getNumArgs(); ++I) { | ||
MrSidims marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Args.push_back(Attr.getArgAsExpr(I)); | ||
} | ||
|
||
S.AddIntelFPGABankBitsAttr(D, Attr, Args.data(), Args.size()); | ||
} | ||
|
||
void Sema::AddIntelFPGABankBitsAttr(Decl *D, const AttributeCommonInfo &CI, | ||
Expr **Exprs, unsigned Size) { | ||
IntelFPGABankBitsAttr TmpAttr(Context, CI, Exprs, Size); | ||
SmallVector<Expr *, 8> Args; | ||
SmallVector<int64_t, 8> Values; | ||
bool ListIsValueDep = false; | ||
for (auto *E : TmpAttr.args()) { | ||
llvm::APSInt Value(32, /*IsUnsigned=*/false); | ||
Expr::EvalResult Result; | ||
ListIsValueDep = ListIsValueDep || E->isValueDependent(); | ||
if (!E->isValueDependent()) { | ||
ExprResult ICE; | ||
if (checkRangedIntegralArgument<IntelFPGABankBitsAttr>(E, &TmpAttr, ICE)) | ||
return; | ||
if (E->EvaluateAsInt(Result, Context)) | ||
Value = Result.Val.getInt(); | ||
E = ICE.get(); | ||
} | ||
Args.push_back(E); | ||
Values.push_back(Value.getExtValue()); | ||
} | ||
|
||
// Check that the list is consecutive. | ||
if (!ListIsValueDep && Values.size() > 1) { | ||
bool ListIsAscending = Values[0] < Values[1]; | ||
mlychkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (int I = 0, E = Values.size() - 1; I < E; ++I) { | ||
if (Values[I + 1] != Values[I] + (ListIsAscending ? 1 : -1)) { | ||
MrSidims marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Diag(CI.getLoc(), diag::err_bankbits_non_consecutive) << &TmpAttr; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
// Check or add the related numbanks attribute. | ||
if (auto *NBA = D->getAttr<IntelFPGANumBanksAttr>()) { | ||
Expr *E = NBA->getValue(); | ||
if (!E->isValueDependent()) { | ||
Expr::EvalResult Result; | ||
E->EvaluateAsInt(Result, Context); | ||
llvm::APSInt Value = Result.Val.getInt(); | ||
if (Args.size() != Value.ceilLogBase2()) { | ||
Diag(TmpAttr.getLoc(), diag::err_bankbits_numbanks_conflicting); | ||
return; | ||
} | ||
} | ||
} else { | ||
llvm::APInt Num(32, (unsigned)(1 << Args.size())); | ||
Expr *NBE = | ||
IntegerLiteral::Create(Context, Num, Context.IntTy, SourceLocation()); | ||
D->addAttr(IntelFPGANumBanksAttr::CreateImplicit(Context, NBE)); | ||
MrSidims marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (!D->hasAttr<IntelFPGAMemoryAttr>()) | ||
MrSidims marked this conversation as resolved.
Show resolved
Hide resolved
|
||
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit( | ||
Context, IntelFPGAMemoryAttr::Default)); | ||
|
||
D->addAttr(::new (Context) | ||
IntelFPGABankBitsAttr(Context, CI, Args.data(), Args.size())); | ||
} | ||
|
||
static void handleIntelFPGAMaxPrivateCopiesAttr(Sema &S, Decl *D, | ||
const ParsedAttr &Attr) { | ||
|
||
|
@@ -7635,6 +7732,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, | |
case ParsedAttr::AT_IntelFPGAMerge: | ||
handleIntelFPGAMergeAttr(S, D, AL); | ||
break; | ||
case ParsedAttr::AT_IntelFPGABankBits: | ||
handleIntelFPGABankBitsAttr(S, D, AL); | ||
break; | ||
|
||
case ParsedAttr::AT_AnyX86NoCallerSavedRegisters: | ||
handleSimpleAttribute<AnyX86NoCallerSavedRegistersAttr>(S, D, AL); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this limit should be documented. The current documentation doesn't imply this value, or, for that matter, any particular number of bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see, the limits for another attributes were not documented, so I just followed the common documenting style :)