Skip to content

[SYCL] Move the lambda attribute hack logic into tablegen; NFC #3381

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

Merged
merged 1 commit into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
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
25 changes: 22 additions & 3 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,14 @@ class Attr {
// attribute may be documented under multiple categories, more than one
// Documentation entry may be listed.
list<Documentation> Documentation;
// The SYCL specification allows attributes on lambdas as a nonconforming
// extension to C++. The attributes are written in the type position but will
// be applied to the generated function declaration rather than type. Setting
// this bit to 1 opts an attribute into this nonconforming extension. New
// attributes should not set this bit unless the attribute is required by the
// SYCL specification. This bit only applies to the [[]] spelling of an
// attribute and has no effect on any other spellings.
bit SupportsNonconformingLambdaSyntax = 0;
}

/// A type attribute is not processed on a declaration or a statement.
Expand Down Expand Up @@ -1186,6 +1194,7 @@ def SYCLSimd : InheritableAttr {
let Subjects = SubjectList<[Function]>;
let LangOpts = [SYCLExplicitSIMD];
let Documentation = [SYCLSimdDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

// Available in SYCL explicit SIMD extension. Binds a file scope private
Expand Down Expand Up @@ -1258,11 +1267,12 @@ def SYCLRequiresDecomposition : InheritableAttr {
}

def SYCLIntelKernelArgsRestrict : InheritableAttr {
let Spellings = [ CXX11<"intel", "kernel_args_restrict"> ];
let Spellings = [CXX11<"intel", "kernel_args_restrict">];
let Subjects = SubjectList<[Function], ErrorDiag>;
let LangOpts = [ SYCLIsDevice, SYCLIsHost ];
let Documentation = [ SYCLIntelKernelArgsRestrictDocs ];
let LangOpts = [SYCLIsDevice, SYCLIsHost];
let Documentation = [SYCLIntelKernelArgsRestrictDocs];
let SimpleHandler = 1;
let SupportsNonconformingLambdaSyntax = 1;
}

def SYCLIntelNumSimdWorkItems : InheritableAttr {
Expand All @@ -1272,13 +1282,15 @@ def SYCLIntelNumSimdWorkItems : InheritableAttr {
let LangOpts = [SYCLIsDevice, SYCLIsHost];
let Subjects = SubjectList<[Function], ErrorDiag>;
let Documentation = [SYCLIntelNumSimdWorkItemsAttrDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

def SYCLIntelUseStallEnableClusters : InheritableAttr {
let Spellings = [CXX11<"intel","use_stall_enable_clusters">];
let LangOpts = [SYCLIsHost, SYCLIsDevice];
let Subjects = SubjectList<[Function], ErrorDiag>;
let Documentation = [SYCLIntelUseStallEnableClustersAttrDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

def SYCLIntelSchedulerTargetFmaxMhz : InheritableAttr {
Expand All @@ -1288,6 +1300,7 @@ def SYCLIntelSchedulerTargetFmaxMhz : InheritableAttr {
let LangOpts = [SYCLIsDevice, SYCLIsHost];
let Subjects = SubjectList<[Function], ErrorDiag>;
let Documentation = [SYCLIntelSchedulerTargetFmaxMhzAttrDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

def SYCLIntelMaxWorkGroupSize : InheritableAttr {
Expand All @@ -1313,6 +1326,7 @@ def SYCLIntelMaxWorkGroupSize : InheritableAttr {
}
}];
let Documentation = [SYCLIntelMaxWorkGroupSizeAttrDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

def SYCLIntelMaxGlobalWorkDim : InheritableAttr {
Expand All @@ -1322,6 +1336,7 @@ def SYCLIntelMaxGlobalWorkDim : InheritableAttr {
let LangOpts = [SYCLIsDevice, SYCLIsHost];
let Subjects = SubjectList<[Function], ErrorDiag>;
let Documentation = [SYCLIntelMaxGlobalWorkDimAttrDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

def SYCLIntelNoGlobalWorkOffset : InheritableAttr {
Expand All @@ -1331,6 +1346,7 @@ def SYCLIntelNoGlobalWorkOffset : InheritableAttr {
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let Subjects = SubjectList<[Function], ErrorDiag>;
let Documentation = [SYCLIntelNoGlobalWorkOffsetAttrDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

def SYCLIntelLoopFuse : InheritableAttr {
Expand All @@ -1342,6 +1358,7 @@ def SYCLIntelLoopFuse : InheritableAttr {
let Accessors = [Accessor<"isIndependent",
[CXX11<"intel", "loop_fuse_independent">]>];
let Documentation = [SYCLIntelLoopFuseDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

def C11NoReturn : InheritableAttr {
Expand Down Expand Up @@ -1404,6 +1421,7 @@ def IntelReqdSubGroupSize: InheritableAttr {
let Subjects = SubjectList<[Function], ErrorDiag>;
let Documentation = [IntelReqdSubGroupSizeDocs];
let LangOpts = [OpenCL, SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let SupportsNonconformingLambdaSyntax = 1;
}

// This attribute is both a type attribute, and a declaration attribute (for
Expand Down Expand Up @@ -2808,6 +2826,7 @@ def ReqdWorkGroupSize : InheritableAttr {
}
}];
let Documentation = [ReqdWorkGroupSizeAttrDocs];
let SupportsNonconformingLambdaSyntax = 1;
}

def WorkGroupSizeHint : InheritableAttr {
Expand Down
20 changes: 0 additions & 20 deletions clang/include/clang/Basic/AttributeCommonInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,6 @@ class AttributeCommonInfo {
return SyntaxUsed == AS_CXX11 || isAlignasAttribute();
}

bool isAllowedOnLambdas() const {
// FIXME: Eventually we want to do a list here populated via tablegen. But
// we want C++ attributes to be permissible on Lambdas, and get propagated
// to the call operator declaration.
auto ParsedAttr = getParsedKind();
if (ParsedAttr == AT_SYCLIntelKernelArgsRestrict ||
(ParsedAttr == AT_ReqdWorkGroupSize && isCXX11Attribute()) ||
(ParsedAttr == AT_IntelReqdSubGroupSize && isCXX11Attribute()) ||
ParsedAttr == AT_SYCLIntelNumSimdWorkItems ||
ParsedAttr == AT_SYCLIntelSchedulerTargetFmaxMhz ||
ParsedAttr == AT_SYCLIntelMaxWorkGroupSize ||
ParsedAttr == AT_SYCLIntelMaxGlobalWorkDim ||
ParsedAttr == AT_SYCLIntelNoGlobalWorkOffset ||
ParsedAttr == AT_SYCLIntelUseStallEnableClusters ||
ParsedAttr == AT_SYCLIntelLoopFuse || ParsedAttr == AT_SYCLSimd)
return true;

return false;
}

bool isC2xAttribute() const { return SyntaxUsed == AS_C2x; }

bool isKeywordAttribute() const {
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Sema/ParsedAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ struct ParsedAttrInfo {
unsigned IsKnownToGCC : 1;
/// True if this attribute is supported by #pragma clang attribute.
unsigned IsSupportedByPragmaAttribute : 1;
/// True if this attribute supports a nonconforming behavior when applied to
/// a lambda in the type position.
unsigned SupportsNonconformingLambdaSyntax : 1;
/// The syntaxes supported by this attribute and how they're spelled.
struct Spelling {
AttributeCommonInfo::Syntax Syntax;
Expand Down Expand Up @@ -590,6 +593,7 @@ class ParsedAttr final
bool existsInTarget(const TargetInfo &Target) const;
bool isKnownToGCC() const;
bool isSupportedByPragmaAttribute() const;
bool supportsNonconformingLambdaSyntax() const;

/// If the parsed attribute has a semantic equivalent, and it would
/// have a semantic Spelling enumeration (due to having semantically-distinct
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/ParsedAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ bool ParsedAttr::isSupportedByPragmaAttribute() const {
return getInfo().IsSupportedByPragmaAttribute;
}

bool ParsedAttr::supportsNonconformingLambdaSyntax() const {
return getInfo().SupportsNonconformingLambdaSyntax && isCXX11Attribute();
}

unsigned ParsedAttr::getSemanticSpelling() const {
return getInfo().spellingIndexToSemanticSpelling(*this);
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8859,7 +8859,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
// Ignore C++11 attributes on declarator chunks: they appertain to the type
// instead.
if (AL.isCXX11Attribute() && !IncludeCXX11Attributes &&
(!IsDeclLambdaCallOperator(D) || !AL.isAllowedOnLambdas()))
(!IsDeclLambdaCallOperator(D) || !AL.supportsNonconformingLambdaSyntax()))
return;

// Unknown attributes are automatically warned on. Target-specific attributes
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8123,7 +8123,8 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
default:
// A C++11 attribute on a declarator chunk must appertain to a type.
if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk &&
(!state.isProcessingLambdaExpr() || !attr.isAllowedOnLambdas())) {
(!state.isProcessingLambdaExpr() ||
!attr.supportsNonconformingLambdaSyntax())) {
state.getSema().Diag(attr.getLoc(), diag::err_attribute_not_type_attr)
<< attr;
attr.setUsedAsTypeAttr();
Expand Down
2 changes: 2 additions & 0 deletions clang/utils/TableGen/ClangAttrEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3796,6 +3796,8 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
OS << IsKnownToGCC(Attr) << ";\n";
OS << " IsSupportedByPragmaAttribute = ";
OS << PragmaAttributeSupport.isAttributedSupported(*I->second) << ";\n";
OS << " SupportsNonconformingLambdaSyntax = ";
OS << Attr.getValueAsBit("SupportsNonconformingLambdaSyntax") << ";\n";
if (!Spellings.empty())
OS << " Spellings = " << I->first << "Spellings;\n";
OS << " }\n";
Expand Down