Skip to content

Commit dcbdcfd

Browse files
authored
[SYCL] Define templates used in multiple Sema TUs in a common .h file (#1164)
Signed-off-by: Premanand M Rao <premanand.m.rao@intel.com>
1 parent a540d01 commit dcbdcfd

File tree

2 files changed

+67
-66
lines changed

2 files changed

+67
-66
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include "clang/AST/DeclTemplate.h"
2323
#include "clang/AST/DeclarationName.h"
2424
#include "clang/AST/Expr.h"
25-
#include "clang/AST/ExprConcepts.h"
2625
#include "clang/AST/ExprCXX.h"
26+
#include "clang/AST/ExprConcepts.h"
2727
#include "clang/AST/ExprObjC.h"
2828
#include "clang/AST/ExternalASTSource.h"
2929
#include "clang/AST/LocInfoType.h"
@@ -34,6 +34,7 @@
3434
#include "clang/AST/TypeLoc.h"
3535
#include "clang/AST/TypeOrdering.h"
3636
#include "clang/Basic/BitmaskEnum.h"
37+
#include "clang/Basic/DiagnosticSema.h"
3738
#include "clang/Basic/ExpressionTraits.h"
3839
#include "clang/Basic/Module.h"
3940
#include "clang/Basic/OpenMPKinds.h"
@@ -12326,6 +12327,71 @@ class Sema final {
1232612327
void checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);
1232712328
};
1232812329

12330+
template <typename AttrType>
12331+
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
12332+
Expr *E) {
12333+
AttrType TmpAttr(Context, CI, E);
12334+
12335+
if (!E->isValueDependent()) {
12336+
ExprResult ICE;
12337+
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
12338+
return;
12339+
E = ICE.get();
12340+
}
12341+
12342+
if (IntelFPGAPrivateCopiesAttr::classof(&TmpAttr)) {
12343+
if (!D->hasAttr<IntelFPGAMemoryAttr>())
12344+
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
12345+
Context, IntelFPGAMemoryAttr::Default));
12346+
}
12347+
12348+
D->addAttr(::new (Context) AttrType(Context, CI, E));
12349+
}
12350+
12351+
template <typename AttrType>
12352+
void Sema::AddOneConstantPowerTwoValueAttr(Decl *D,
12353+
const AttributeCommonInfo &CI,
12354+
Expr *E) {
12355+
AttrType TmpAttr(Context, CI, E);
12356+
12357+
if (!E->isValueDependent()) {
12358+
ExprResult ICE;
12359+
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
12360+
return;
12361+
Expr::EvalResult Result;
12362+
E->EvaluateAsInt(Result, Context);
12363+
llvm::APSInt Value = Result.Val.getInt();
12364+
if (!Value.isPowerOf2()) {
12365+
Diag(CI.getLoc(), diag::err_attribute_argument_not_power_of_two)
12366+
<< &TmpAttr;
12367+
return;
12368+
}
12369+
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
12370+
if (auto *BBA = D->getAttr<IntelFPGABankBitsAttr>()) {
12371+
unsigned NumBankBits = BBA->args_size();
12372+
if (NumBankBits != Value.ceilLogBase2()) {
12373+
Diag(TmpAttr.getLocation(), diag::err_bankbits_numbanks_conflicting);
12374+
return;
12375+
}
12376+
}
12377+
}
12378+
E = ICE.get();
12379+
}
12380+
12381+
if (!D->hasAttr<IntelFPGAMemoryAttr>())
12382+
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
12383+
Context, IntelFPGAMemoryAttr::Default));
12384+
12385+
// We are adding a user NumBanks, drop any implicit default.
12386+
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
12387+
if (auto *NBA = D->getAttr<IntelFPGANumBanksAttr>())
12388+
if (NBA->isImplicit())
12389+
D->dropAttr<IntelFPGANumBanksAttr>();
12390+
}
12391+
12392+
D->addAttr(::new (Context) AttrType(Context, CI, E));
12393+
}
12394+
1232912395
/// RAII object that enters a new expression evaluation context.
1233012396
class EnterExpressionEvaluationContext {
1233112397
Sema &Actions;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,71 +3869,6 @@ bool Sema::checkRangedIntegralArgument(Expr *E, const AttrType *TmpAttr,
38693869
return false;
38703870
}
38713871

3872-
template <typename AttrType>
3873-
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
3874-
Expr *E) {
3875-
AttrType TmpAttr(Context, CI, E);
3876-
3877-
if (!E->isValueDependent()) {
3878-
ExprResult ICE;
3879-
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
3880-
return;
3881-
E = ICE.get();
3882-
}
3883-
3884-
if (IntelFPGAPrivateCopiesAttr::classof(&TmpAttr)) {
3885-
if (!D->hasAttr<IntelFPGAMemoryAttr>())
3886-
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
3887-
Context, IntelFPGAMemoryAttr::Default));
3888-
}
3889-
3890-
D->addAttr(::new (Context) AttrType(Context, CI, E));
3891-
}
3892-
3893-
template <typename AttrType>
3894-
void Sema::AddOneConstantPowerTwoValueAttr(Decl *D,
3895-
const AttributeCommonInfo &CI,
3896-
Expr *E) {
3897-
AttrType TmpAttr(Context, CI, E);
3898-
3899-
if (!E->isValueDependent()) {
3900-
ExprResult ICE;
3901-
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
3902-
return;
3903-
Expr::EvalResult Result;
3904-
E->EvaluateAsInt(Result, Context);
3905-
llvm::APSInt Value = Result.Val.getInt();
3906-
if (!Value.isPowerOf2()) {
3907-
Diag(CI.getLoc(), diag::err_attribute_argument_not_power_of_two)
3908-
<< &TmpAttr;
3909-
return;
3910-
}
3911-
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
3912-
if (auto *BBA = D->getAttr<IntelFPGABankBitsAttr>()) {
3913-
unsigned NumBankBits = BBA->args_size();
3914-
if (NumBankBits != Value.ceilLogBase2()) {
3915-
Diag(TmpAttr.getLocation(), diag::err_bankbits_numbanks_conflicting);
3916-
return;
3917-
}
3918-
}
3919-
}
3920-
E = ICE.get();
3921-
}
3922-
3923-
if (!D->hasAttr<IntelFPGAMemoryAttr>())
3924-
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
3925-
Context, IntelFPGAMemoryAttr::Default));
3926-
3927-
// We are adding a user NumBanks, drop any implicit default.
3928-
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
3929-
if (auto *NBA = D->getAttr<IntelFPGANumBanksAttr>())
3930-
if (NBA->isImplicit())
3931-
D->dropAttr<IntelFPGANumBanksAttr>();
3932-
}
3933-
3934-
D->addAttr(::new (Context) AttrType(Context, CI, E));
3935-
}
3936-
39373872
void Sema::AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
39383873
bool IsPackExpansion) {
39393874
AlignedAttr TmpAttr(Context, CI, true, E);

0 commit comments

Comments
 (0)