Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 22 additions & 59 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,48 +498,21 @@ static void instantiateDependentAMDGPUWavesPerEUAttr(
S.addAMDGPUWavesPerEUAttr(New, Attr, MinExpr, MaxExpr);
}

static void instantiateIntelFPGABankWidthAttr(
template <typename AttrName>
static void instantiateIntelFPGAMemoryAttr(
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
const IntelFPGABankWidthAttr *Attr, Decl *New) {
const AttrName *Attr, Decl *New) {
EnterExpressionEvaluationContext Unevaluated(
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
ExprResult Result = S.SubstExpr(Attr->getValue(), TemplateArgs);
if (!Result.isInvalid())
return S.AddOneConstantPowerTwoValueAttr<IntelFPGABankWidthAttr>(
New, *Attr, Result.getAs<Expr>());
}

static void instantiateIntelFPGANumBanksAttr(
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
const IntelFPGANumBanksAttr *Attr, Decl *New) {
EnterExpressionEvaluationContext Unevaluated(
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
ExprResult Result = S.SubstExpr(Attr->getValue(), TemplateArgs);
if (!Result.isInvalid())
return S.AddOneConstantPowerTwoValueAttr<IntelFPGANumBanksAttr>(
New, *Attr, Result.getAs<Expr>());
}

static void instantiateIntelFPGAPrivateCopiesAttr(
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
const IntelFPGAPrivateCopiesAttr *Attr, Decl *New) {
EnterExpressionEvaluationContext Unevaluated(
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
ExprResult Result = S.SubstExpr(Attr->getValue(), TemplateArgs);
if (!Result.isInvalid())
return S.AddOneConstantValueAttr<IntelFPGAPrivateCopiesAttr>(
New, *Attr, Result.getAs<Expr>());
}

static void instantiateIntelFPGAMaxReplicatesAttr(
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
const IntelFPGAMaxReplicatesAttr *Attr, Decl *New) {
EnterExpressionEvaluationContext Unevaluated(
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
ExprResult Result = S.SubstExpr(Attr->getValue(), TemplateArgs);
if (!Result.isInvalid())
return S.AddOneConstantValueAttr<IntelFPGAMaxReplicatesAttr>(
New, *Attr, Result.getAs<Expr>());
if (!Result.isInvalid()) {
if (std::is_same<AttrName, IntelFPGABankWidthAttr>::value ||
std::is_same<AttrName, IntelFPGANumBanksAttr>::value)
return S.AddOneConstantPowerTwoValueAttr<AttrName>(New, *Attr,
Result.getAs<Expr>());
return S.AddOneConstantValueAttr<AttrName>(New, *Attr,
Result.getAs<Expr>());
}
}

static void instantiateIntelFPGABankBitsAttr(
Expand All @@ -557,17 +530,6 @@ static void instantiateIntelFPGABankBitsAttr(
S.AddIntelFPGABankBitsAttr(New, *Attr, Args.data(), Args.size());
}

static void instantiateIntelFPGAForcePow2DepthAttr(
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
const IntelFPGAForcePow2DepthAttr *Attr, Decl *New) {
EnterExpressionEvaluationContext Unevaluated(
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
ExprResult Result = S.SubstExpr(Attr->getValue(), TemplateArgs);
if (!Result.isInvalid())
S.AddOneConstantValueAttr<IntelFPGAForcePow2DepthAttr>(
New, *Attr, Result.getAs<Expr>());
}

static void instantiateSYCLIntelPipeIOAttr(
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
const SYCLIntelPipeIOAttr *Attr, Decl *New) {
Expand Down Expand Up @@ -700,23 +662,24 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,

if (const auto *IntelFPGABankWidth =
dyn_cast<IntelFPGABankWidthAttr>(TmplAttr)) {
instantiateIntelFPGABankWidthAttr(*this, TemplateArgs, IntelFPGABankWidth,
New);
instantiateIntelFPGAMemoryAttr<IntelFPGABankWidthAttr>(
*this, TemplateArgs, IntelFPGABankWidth, New);
}

if (const auto *IntelFPGANumBanks =
dyn_cast<IntelFPGANumBanksAttr>(TmplAttr)) {
instantiateIntelFPGANumBanksAttr(*this, TemplateArgs, IntelFPGANumBanks,
New);
instantiateIntelFPGAMemoryAttr<IntelFPGANumBanksAttr>(
*this, TemplateArgs, IntelFPGANumBanks, New);
}
if (const auto *IntelFPGAPrivateCopies =
dyn_cast<IntelFPGAPrivateCopiesAttr>(TmplAttr)) {
instantiateIntelFPGAPrivateCopiesAttr(*this, TemplateArgs,
IntelFPGAPrivateCopies, New);
instantiateIntelFPGAMemoryAttr<IntelFPGAPrivateCopiesAttr>(
*this, TemplateArgs, IntelFPGAPrivateCopies, New);
}
if (const auto *IntelFPGAMaxReplicates =
dyn_cast<IntelFPGAMaxReplicatesAttr>(TmplAttr)) {
instantiateIntelFPGAMaxReplicatesAttr(*this, TemplateArgs,
IntelFPGAMaxReplicates, New);
instantiateIntelFPGAMemoryAttr<IntelFPGAMaxReplicatesAttr>(
*this, TemplateArgs, IntelFPGAMaxReplicates, New);
}
if (const auto *IntelFPGABankBits =
dyn_cast<IntelFPGABankBitsAttr>(TmplAttr)) {
Expand All @@ -725,8 +688,8 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
}
if (const auto *IntelFPGAForcePow2Depth =
dyn_cast<IntelFPGAForcePow2DepthAttr>(TmplAttr)) {
instantiateIntelFPGAForcePow2DepthAttr(*this, TemplateArgs,
IntelFPGAForcePow2Depth, New);
instantiateIntelFPGAMemoryAttr<IntelFPGAForcePow2DepthAttr>(
*this, TemplateArgs, IntelFPGAForcePow2Depth, New);
}
if (const auto *SYCLIntelPipeIO = dyn_cast<SYCLIntelPipeIOAttr>(TmplAttr)) {
instantiateSYCLIntelPipeIOAttr(*this, TemplateArgs, SYCLIntelPipeIO, New);
Expand Down