aboutsummaryrefslogtreecommitdiff
path: root/clang/utils
diff options
context:
space:
mode:
authorChris Bieneman <chris.bieneman@me.com>2022-03-30 14:20:15 -0500
committerChris Bieneman <chris.bieneman@me.com>2022-04-14 10:21:58 -0500
commit1fdf952deeb9a02aa34794af3c1a7d13a30e068e (patch)
treeaf3a219c2a4c0a2d369c567cce93158014f9c754 /clang/utils
parent4f1065156b828f447b8b1a6848c3264184b5c860 (diff)
downloadllvm-1fdf952deeb9a02aa34794af3c1a7d13a30e068e.zip
llvm-1fdf952deeb9a02aa34794af3c1a7d13a30e068e.tar.gz
llvm-1fdf952deeb9a02aa34794af3c1a7d13a30e068e.tar.bz2
[HLSL] Add Semantic syntax, and SV_GroupIndex
HLSL has a language feature called Semantics which get attached to declarations like attributes and are used in a variety of ways. One example of semantic use is here with the `SV_GroupIndex` semantic which, when applied to an input for a compute shader is pre-populated by the driver with a flattened thread index. Differential Revision: https://reviews.llvm.org/D122699 # Conflicts: # clang/include/clang/Basic/Attr.td # clang/include/clang/Basic/AttrDocs.td
Diffstat (limited to 'clang/utils')
-rw-r--r--clang/utils/TableGen/ClangAttrEmitter.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index b77554c..2c0d46e 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1493,6 +1493,9 @@ writePrettyPrintFunction(const Record &R,
Spelling += Namespace;
Spelling += " ";
}
+ } else if (Variety == "HLSLSemantic") {
+ Prefix = ":";
+ Suffix = "";
} else {
llvm_unreachable("Unknown attribute syntax variety!");
}
@@ -3300,7 +3303,7 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
// Separate all of the attributes out into four group: generic, C++11, GNU,
// and declspecs. Then generate a big switch statement for each of them.
std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
- std::vector<Record *> Declspec, Microsoft, GNU, Pragma;
+ std::vector<Record *> Declspec, Microsoft, GNU, Pragma, HLSLSemantic;
std::map<std::string, std::vector<Record *>> CXX, C2x;
// Walk over the list of all attributes, and split them out based on the
@@ -3321,6 +3324,8 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
C2x[SI.nameSpace()].push_back(R);
else if (Variety == "Pragma")
Pragma.push_back(R);
+ else if (Variety == "HLSLSemantic")
+ HLSLSemantic.push_back(R);
}
}
@@ -3338,6 +3343,9 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
OS << "case AttrSyntax::Pragma:\n";
OS << " return llvm::StringSwitch<int>(Name)\n";
GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
+ OS << "case AttrSyntax::HLSLSemantic:\n";
+ OS << " return llvm::StringSwitch<int>(Name)\n";
+ GenerateHasAttrSpellingStringSwitch(HLSLSemantic, OS, "HLSLSemantic");
auto fn = [&OS](const char *Spelling, const char *Variety,
const std::map<std::string, std::vector<Record *>> &List) {
OS << "case AttrSyntax::" << Variety << ": {\n";
@@ -4286,7 +4294,7 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) {
std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
std::vector<StringMatcher::StringPair> GNU, Declspec, Microsoft, CXX11,
- Keywords, Pragma, C2x;
+ Keywords, Pragma, C2x, HLSLSemantic;
std::set<std::string> Seen;
for (const auto *A : Attrs) {
const Record &Attr = *A;
@@ -4338,6 +4346,8 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) {
Matches = &Keywords;
else if (Variety == "Pragma")
Matches = &Pragma;
+ else if (Variety == "HLSLSemantic")
+ Matches = &HLSLSemantic;
assert(Matches && "Unsupported spelling variety found");
@@ -4373,6 +4383,8 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) {
StringMatcher("Name", Keywords, OS).Emit();
OS << " } else if (AttributeCommonInfo::AS_Pragma == Syntax) {\n";
StringMatcher("Name", Pragma, OS).Emit();
+ OS << " } else if (AttributeCommonInfo::AS_HLSLSemantic == Syntax) {\n";
+ StringMatcher("Name", HLSLSemantic, OS).Emit();
OS << " }\n";
OS << " return AttributeCommonInfo::UnknownAttribute;\n"
<< "}\n";
@@ -4482,7 +4494,7 @@ void EmitClangAttrDocTable(RecordKeeper &Records, raw_ostream &OS) {
}
}
-enum class SpellingKind {
+enum class SpellingKind : size_t {
GNU,
CXX11,
C2x,
@@ -4490,8 +4502,10 @@ enum class SpellingKind {
Microsoft,
Keyword,
Pragma,
+ HLSLSemantic,
+ NumSpellingKinds
};
-static const size_t NumSpellingKinds = (size_t)SpellingKind::Pragma + 1;
+static const size_t NumSpellingKinds = (size_t)SpellingKind::NumSpellingKinds;
class SpellingList {
std::vector<std::string> Spellings[NumSpellingKinds];
@@ -4509,7 +4523,8 @@ public:
.Case("Declspec", SpellingKind::Declspec)
.Case("Microsoft", SpellingKind::Microsoft)
.Case("Keyword", SpellingKind::Keyword)
- .Case("Pragma", SpellingKind::Pragma);
+ .Case("Pragma", SpellingKind::Pragma)
+ .Case("HLSLSemantic", SpellingKind::HLSLSemantic);
std::string Name;
if (!Spelling.nameSpace().empty()) {
switch (Kind) {
@@ -4610,8 +4625,8 @@ static void WriteDocumentation(RecordKeeper &Records,
// List what spelling syntaxes the attribute supports.
OS << ".. csv-table:: Supported Syntaxes\n";
OS << " :header: \"GNU\", \"C++11\", \"C2x\", \"``__declspec``\",";
- OS << " \"Keyword\", \"``#pragma``\", \"``#pragma clang attribute``\"\n\n";
- OS << " \"";
+ OS << " \"Keyword\", \"``#pragma``\", \"``#pragma clang attribute``\",";
+ OS << " \"HLSL Semantic\"\n\n \"";
for (size_t Kind = 0; Kind != NumSpellingKinds; ++Kind) {
SpellingKind K = (SpellingKind)Kind;
// TODO: List Microsoft (IDL-style attribute) spellings once we fully