Skip to content

Commit eaab97a

Browse files
authored
[NFC] Rename hlsl semantics to hlsl annotations (llvm#89309)
The attribute name "HLSLSemantics" is confusing, because semantics aren't always the annotation that are applied to specific variables. The name for this attribute needs to be less specific. This PR changes the attribute name from HLSLSemantic to HLSLAnnotation, and changes the associated function and variable names to support this conceptual change. The HLSLAnnotation attribute will never be output in ast-dump due to it being parsed for the attribute that it represents. There is no functional change, so there are no accompanying tests.
1 parent 87a2159 commit eaab97a

File tree

6 files changed

+53
-53
lines changed

6 files changed

+53
-53
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ class Clang<string name, bit allowInC = 1, int version = 1>
368368
bit AllowInC = allowInC;
369369
}
370370

371-
// HLSL Semantic spellings
372-
class HLSLSemantic<string name> : Spelling<name, "HLSLSemantic">;
371+
// HLSL Annotation spellings
372+
class HLSLAnnotation<string name> : Spelling<name, "HLSLAnnotation">;
373373

374374
class Accessor<string name, list<Spelling> spellings> {
375375
string Name = name;
@@ -4358,22 +4358,22 @@ def HLSLNumThreads: InheritableAttr {
43584358
}
43594359

43604360
def HLSLSV_GroupIndex: HLSLAnnotationAttr {
4361-
let Spellings = [HLSLSemantic<"SV_GroupIndex">];
4361+
let Spellings = [HLSLAnnotation<"SV_GroupIndex">];
43624362
let Subjects = SubjectList<[ParmVar, GlobalVar]>;
43634363
let LangOpts = [HLSL];
43644364
let Documentation = [HLSLSV_GroupIndexDocs];
43654365
}
43664366

43674367
def HLSLResourceBinding: InheritableAttr {
4368-
let Spellings = [HLSLSemantic<"register">];
4368+
let Spellings = [HLSLAnnotation<"register">];
43694369
let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
43704370
let LangOpts = [HLSL];
43714371
let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
43724372
let Documentation = [HLSLResourceBindingDocs];
43734373
}
43744374

43754375
def HLSLSV_DispatchThreadID: HLSLAnnotationAttr {
4376-
let Spellings = [HLSLSemantic<"SV_DispatchThreadID">];
4376+
let Spellings = [HLSLAnnotation<"SV_DispatchThreadID">];
43774377
let Subjects = SubjectList<[ParmVar, Field]>;
43784378
let LangOpts = [HLSL];
43794379
let Documentation = [HLSLSV_DispatchThreadIDDocs];

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class AttributeCommonInfo {
5252
/// Context-sensitive version of a keyword attribute.
5353
AS_ContextSensitiveKeyword,
5454

55-
/// <vardecl> : <semantic>
56-
AS_HLSLSemantic,
55+
/// <vardecl> : <annotation>
56+
AS_HLSLAnnotation,
5757

5858
/// The attibute has no source code manifestation and is only created
5959
/// implicitly.
@@ -120,7 +120,7 @@ class AttributeCommonInfo {
120120
}
121121
static Form Pragma() { return AS_Pragma; }
122122
static Form ContextSensitiveKeyword() { return AS_ContextSensitiveKeyword; }
123-
static Form HLSLSemantic() { return AS_HLSLSemantic; }
123+
static Form HLSLAnnotation() { return AS_HLSLAnnotation; }
124124
static Form Implicit() { return AS_Implicit; }
125125

126126
private:

clang/include/clang/Parse/Parser.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,25 +2967,25 @@ class Parser : public CodeCompletionHandler {
29672967
Sema::AttributeCompletion Completion = Sema::AttributeCompletion::None,
29682968
const IdentifierInfo *EnclosingScope = nullptr);
29692969

2970-
void MaybeParseHLSLSemantics(Declarator &D,
2971-
SourceLocation *EndLoc = nullptr) {
2972-
assert(getLangOpts().HLSL && "MaybeParseHLSLSemantics is for HLSL only");
2970+
void MaybeParseHLSLAnnotations(Declarator &D,
2971+
SourceLocation *EndLoc = nullptr) {
2972+
assert(getLangOpts().HLSL && "MaybeParseHLSLAnnotations is for HLSL only");
29732973
if (Tok.is(tok::colon)) {
29742974
ParsedAttributes Attrs(AttrFactory);
2975-
ParseHLSLSemantics(Attrs, EndLoc);
2975+
ParseHLSLAnnotations(Attrs, EndLoc);
29762976
D.takeAttributes(Attrs);
29772977
}
29782978
}
29792979

2980-
void MaybeParseHLSLSemantics(ParsedAttributes &Attrs,
2981-
SourceLocation *EndLoc = nullptr) {
2982-
assert(getLangOpts().HLSL && "MaybeParseHLSLSemantics is for HLSL only");
2980+
void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
2981+
SourceLocation *EndLoc = nullptr) {
2982+
assert(getLangOpts().HLSL && "MaybeParseHLSLAnnotations is for HLSL only");
29832983
if (getLangOpts().HLSL && Tok.is(tok::colon))
2984-
ParseHLSLSemantics(Attrs, EndLoc);
2984+
ParseHLSLAnnotations(Attrs, EndLoc);
29852985
}
29862986

2987-
void ParseHLSLSemantics(ParsedAttributes &Attrs,
2988-
SourceLocation *EndLoc = nullptr);
2987+
void ParseHLSLAnnotations(ParsedAttributes &Attrs,
2988+
SourceLocation *EndLoc = nullptr);
29892989
Decl *ParseHLSLBuffer(SourceLocation &DeclEnd);
29902990

29912991
void MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {

clang/lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
22222222
}
22232223

22242224
if (getLangOpts().HLSL)
2225-
MaybeParseHLSLSemantics(D);
2225+
MaybeParseHLSLAnnotations(D);
22262226

22272227
if (Tok.is(tok::kw_requires))
22282228
ParseTrailingRequiresClause(D);
@@ -2469,7 +2469,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
24692469
ParseDeclarator(D);
24702470

24712471
if (getLangOpts().HLSL)
2472-
MaybeParseHLSLSemantics(D);
2472+
MaybeParseHLSLAnnotations(D);
24732473

24742474
if (!D.isInvalidType()) {
24752475
// C++2a [dcl.decl]p1
@@ -7699,7 +7699,7 @@ void Parser::ParseParameterDeclarationClause(
76997699
// Parse GNU attributes, if present.
77007700
MaybeParseGNUAttributes(ParmDeclarator);
77017701
if (getLangOpts().HLSL)
7702-
MaybeParseHLSLSemantics(DS.getAttributes());
7702+
MaybeParseHLSLAnnotations(DS.getAttributes());
77037703

77047704
if (Tok.is(tok::kw_requires)) {
77057705
// User tried to define a requires clause in a parameter declaration,

clang/lib/Parse/ParseHLSL.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Decl *Parser::ParseHLSLBuffer(SourceLocation &DeclEnd) {
6363
SourceLocation IdentifierLoc = ConsumeToken();
6464

6565
ParsedAttributes Attrs(AttrFactory);
66-
MaybeParseHLSLSemantics(Attrs, nullptr);
66+
MaybeParseHLSLAnnotations(Attrs, nullptr);
6767

6868
ParseScope BufferScope(this, Scope::DeclScope);
6969
BalancedDelimiterTracker T(*this, tok::l_brace);
@@ -118,12 +118,10 @@ static void fixSeparateAttrArgAndNumber(StringRef ArgStr, SourceLocation ArgLoc,
118118
Slot = IdentifierLoc::create(Ctx, ArgLoc, PP.getIdentifierInfo(FixedArg));
119119
}
120120

121-
void Parser::ParseHLSLSemantics(ParsedAttributes &Attrs,
122-
SourceLocation *EndLoc) {
123-
// FIXME: HLSLSemantic is shared for Semantic and resource binding which is
124-
// confusing. Need a better name to avoid misunderstanding. Issue
125-
// https://github.com/llvm/llvm-project/issues/57882
126-
assert(Tok.is(tok::colon) && "Not a HLSL Semantic");
121+
void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs,
122+
SourceLocation *EndLoc) {
123+
124+
assert(Tok.is(tok::colon) && "Not a HLSL Annotation");
127125
ConsumeToken();
128126

129127
IdentifierInfo *II = nullptr;
@@ -141,7 +139,7 @@ void Parser::ParseHLSLSemantics(ParsedAttributes &Attrs,
141139
if (EndLoc)
142140
*EndLoc = Tok.getLocation();
143141
ParsedAttr::Kind AttrKind =
144-
ParsedAttr::getParsedKind(II, nullptr, ParsedAttr::AS_HLSLSemantic);
142+
ParsedAttr::getParsedKind(II, nullptr, ParsedAttr::AS_HLSLAnnotation);
145143

146144
ArgsVector ArgExprs;
147145
switch (AttrKind) {
@@ -192,10 +190,10 @@ void Parser::ParseHLSLSemantics(ParsedAttributes &Attrs,
192190
case ParsedAttr::AT_HLSLSV_DispatchThreadID:
193191
break;
194192
default:
195-
llvm_unreachable("invalid HLSL Semantic");
193+
llvm_unreachable("invalid HLSL Annotation");
196194
break;
197195
}
198196

199197
Attrs.addNew(II, Loc, nullptr, SourceLocation(), ArgExprs.data(),
200-
ArgExprs.size(), ParsedAttr::Form::HLSLSemantic());
198+
ArgExprs.size(), ParsedAttr::Form::HLSLAnnotation());
201199
}

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ writePrettyPrintFunction(const Record &R,
16181618
Spelling += Namespace;
16191619
Spelling += " ";
16201620
}
1621-
} else if (Variety == "HLSLSemantic") {
1621+
} else if (Variety == "HLSLAnnotation") {
16221622
Prefix = ":";
16231623
Suffix = "";
16241624
} else {
@@ -3608,7 +3608,7 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
36083608
// and declspecs. Then generate a big switch statement for each of them.
36093609
std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
36103610
std::vector<std::pair<const Record *, FlattenedSpelling>> Declspec, Microsoft,
3611-
GNU, Pragma, HLSLSemantic;
3611+
GNU, Pragma, HLSLAnnotation;
36123612
std::map<std::string,
36133613
std::vector<std::pair<const Record *, FlattenedSpelling>>>
36143614
CXX, C23;
@@ -3631,8 +3631,8 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
36313631
C23[SI.nameSpace()].emplace_back(R, SI);
36323632
else if (Variety == "Pragma")
36333633
Pragma.emplace_back(R, SI);
3634-
else if (Variety == "HLSLSemantic")
3635-
HLSLSemantic.emplace_back(R, SI);
3634+
else if (Variety == "HLSLAnnotation")
3635+
HLSLAnnotation.emplace_back(R, SI);
36363636
}
36373637
}
36383638

@@ -3650,9 +3650,9 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
36503650
OS << "case AttributeCommonInfo::Syntax::AS_Pragma:\n";
36513651
OS << " return llvm::StringSwitch<int>(Name)\n";
36523652
GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
3653-
OS << "case AttributeCommonInfo::Syntax::AS_HLSLSemantic:\n";
3653+
OS << "case AttributeCommonInfo::Syntax::AS_HLSLAnnotation:\n";
36543654
OS << " return llvm::StringSwitch<int>(Name)\n";
3655-
GenerateHasAttrSpellingStringSwitch(HLSLSemantic, OS, "HLSLSemantic");
3655+
GenerateHasAttrSpellingStringSwitch(HLSLAnnotation, OS, "HLSLAnnotation");
36563656
auto fn = [&OS](const char *Spelling,
36573657
const std::map<
36583658
std::string,
@@ -4669,7 +4669,7 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) {
46694669

46704670
std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
46714671
std::vector<StringMatcher::StringPair> GNU, Declspec, Microsoft, CXX11,
4672-
Keywords, Pragma, C23, HLSLSemantic;
4672+
Keywords, Pragma, C23, HLSLAnnotation;
46734673
std::set<std::string> Seen;
46744674
for (const auto *A : Attrs) {
46754675
const Record &Attr = *A;
@@ -4720,8 +4720,8 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) {
47204720
Matches = &Keywords;
47214721
else if (Variety == "Pragma")
47224722
Matches = &Pragma;
4723-
else if (Variety == "HLSLSemantic")
4724-
Matches = &HLSLSemantic;
4723+
else if (Variety == "HLSLAnnotation")
4724+
Matches = &HLSLAnnotation;
47254725

47264726
assert(Matches && "Unsupported spelling variety found");
47274727

@@ -4757,8 +4757,8 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) {
47574757
StringMatcher("Name", Keywords, OS).Emit();
47584758
OS << " } else if (AttributeCommonInfo::AS_Pragma == Syntax) {\n";
47594759
StringMatcher("Name", Pragma, OS).Emit();
4760-
OS << " } else if (AttributeCommonInfo::AS_HLSLSemantic == Syntax) {\n";
4761-
StringMatcher("Name", HLSLSemantic, OS).Emit();
4760+
OS << " } else if (AttributeCommonInfo::AS_HLSLAnnotation == Syntax) {\n";
4761+
StringMatcher("Name", HLSLAnnotation, OS).Emit();
47624762
OS << " }\n";
47634763
OS << " return AttributeCommonInfo::UnknownAttribute;\n"
47644764
<< "}\n";
@@ -4876,7 +4876,7 @@ enum class SpellingKind : size_t {
48764876
Microsoft,
48774877
Keyword,
48784878
Pragma,
4879-
HLSLSemantic,
4879+
HLSLAnnotation,
48804880
NumSpellingKinds
48814881
};
48824882
static const size_t NumSpellingKinds = (size_t)SpellingKind::NumSpellingKinds;
@@ -4890,15 +4890,16 @@ class SpellingList {
48904890
}
48914891

48924892
void add(const Record &Attr, FlattenedSpelling Spelling) {
4893-
SpellingKind Kind = StringSwitch<SpellingKind>(Spelling.variety())
4894-
.Case("GNU", SpellingKind::GNU)
4895-
.Case("CXX11", SpellingKind::CXX11)
4896-
.Case("C23", SpellingKind::C23)
4897-
.Case("Declspec", SpellingKind::Declspec)
4898-
.Case("Microsoft", SpellingKind::Microsoft)
4899-
.Case("Keyword", SpellingKind::Keyword)
4900-
.Case("Pragma", SpellingKind::Pragma)
4901-
.Case("HLSLSemantic", SpellingKind::HLSLSemantic);
4893+
SpellingKind Kind =
4894+
StringSwitch<SpellingKind>(Spelling.variety())
4895+
.Case("GNU", SpellingKind::GNU)
4896+
.Case("CXX11", SpellingKind::CXX11)
4897+
.Case("C23", SpellingKind::C23)
4898+
.Case("Declspec", SpellingKind::Declspec)
4899+
.Case("Microsoft", SpellingKind::Microsoft)
4900+
.Case("Keyword", SpellingKind::Keyword)
4901+
.Case("Pragma", SpellingKind::Pragma)
4902+
.Case("HLSLAnnotation", SpellingKind::HLSLAnnotation);
49024903
std::string Name;
49034904
if (!Spelling.nameSpace().empty()) {
49044905
switch (Kind) {
@@ -5007,7 +5008,8 @@ static void WriteDocumentation(RecordKeeper &Records,
50075008
// so it must be last.
50085009
OS << ".. csv-table:: Supported Syntaxes\n";
50095010
OS << " :header: \"GNU\", \"C++11\", \"C23\", \"``__declspec``\",";
5010-
OS << " \"Keyword\", \"``#pragma``\", \"HLSL Semantic\", \"``#pragma clang ";
5011+
OS << " \"Keyword\", \"``#pragma``\", \"HLSL Annotation\", \"``#pragma "
5012+
"clang ";
50115013
OS << "attribute``\"\n\n \"";
50125014
for (size_t Kind = 0; Kind != NumSpellingKinds; ++Kind) {
50135015
SpellingKind K = (SpellingKind)Kind;

0 commit comments

Comments
 (0)