Skip to content

Commit 302652f

Browse files
authored
merge main into amd-staging (llvm#1833)
2 parents c5c0d30 + 53e5037 commit 302652f

File tree

107 files changed

+5047
-1293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+5047
-1293
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ class RootSignatureParser {
7171
// expected, or, there is a lexing error
7272

7373
/// Root Element parse methods:
74-
bool parseDescriptorTable();
75-
bool parseDescriptorTableClause();
74+
std::optional<llvm::hlsl::rootsig::DescriptorTable> parseDescriptorTable();
75+
std::optional<llvm::hlsl::rootsig::DescriptorTableClause>
76+
parseDescriptorTableClause();
7677

7778
/// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
7879
/// order and only exactly once. `ParsedClauseParams` denotes the current
@@ -84,9 +85,13 @@ class RootSignatureParser {
8485
std::optional<ParsedClauseParams>
8586
parseDescriptorTableClauseParams(RootSignatureToken::Kind RegType);
8687

88+
// Common parsing methods
8789
std::optional<uint32_t> parseUIntParam();
8890
std::optional<llvm::hlsl::rootsig::Register> parseRegister();
8991

92+
/// Parsing methods of various enums
93+
std::optional<llvm::hlsl::rootsig::ShaderVisibility> parseShaderVisibility();
94+
9095
/// Use NumericLiteralParser to convert CurToken.NumSpelling into a unsigned
9196
/// 32-bit integer
9297
std::optional<uint32_t> handleUIntLiteral();

clang/lib/AST/ExprConstant.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9202,7 +9202,10 @@ bool LValueExprEvaluator::VisitExtVectorElementExpr(
92029202

92039203
if (Success) {
92049204
Result.setFrom(Info.Ctx, Val);
9205-
const auto *VT = E->getBase()->getType()->castAs<VectorType>();
9205+
QualType BaseType = E->getBase()->getType();
9206+
if (E->isArrow())
9207+
BaseType = BaseType->getPointeeType();
9208+
const auto *VT = BaseType->castAs<VectorType>();
92069209
HandleLValueVectorElement(Info, E, Result, VT->getElementType(),
92079210
VT->getNumElements(), Indices[0]);
92089211
}

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,11 +1240,15 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
12401240
Instance.createSourceManager(Instance.getFileManager());
12411241
SourceManager &SourceMgr = Instance.getSourceManager();
12421242

1243-
// Note that this module is part of the module build stack, so that we
1244-
// can detect cycles in the module graph.
1245-
SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());
1246-
SourceMgr.pushModuleBuildStack(ModuleName,
1247-
FullSourceLoc(ImportLoc, getSourceManager()));
1243+
if (ThreadSafeConfig) {
1244+
// Detecting cycles in the module graph is responsibility of the client.
1245+
} else {
1246+
// Note that this module is part of the module build stack, so that we
1247+
// can detect cycles in the module graph.
1248+
SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());
1249+
SourceMgr.pushModuleBuildStack(
1250+
ModuleName, FullSourceLoc(ImportLoc, getSourceManager()));
1251+
}
12481252

12491253
// Make a copy for the new instance.
12501254
Instance.FailedModules = FailedModules;

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,14 @@ RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
2626

2727
bool RootSignatureParser::parse() {
2828
// Iterate as many RootElements as possible
29-
while (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
30-
// Dispatch onto parser method.
31-
// We guard against the unreachable here as we just ensured that CurToken
32-
// will be one of the kinds in the while condition
33-
switch (CurToken.TokKind) {
34-
case TokenKind::kw_DescriptorTable:
35-
if (parseDescriptorTable())
29+
do {
30+
if (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
31+
auto Table = parseDescriptorTable();
32+
if (!Table.has_value())
3633
return true;
37-
break;
38-
default:
39-
llvm_unreachable("Switch for consumed token was not provided");
34+
Elements.push_back(*Table);
4035
}
41-
42-
if (!tryConsumeExpectedToken(TokenKind::pu_comma))
43-
break;
44-
}
36+
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
4537

4638
if (consumeExpectedToken(TokenKind::end_of_stream,
4739
diag::err_hlsl_unexpected_end_of_params,
@@ -51,38 +43,58 @@ bool RootSignatureParser::parse() {
5143
return false;
5244
}
5345

54-
bool RootSignatureParser::parseDescriptorTable() {
46+
std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
5547
assert(CurToken.TokKind == TokenKind::kw_DescriptorTable &&
5648
"Expects to only be invoked starting at given keyword");
5749

58-
DescriptorTable Table;
59-
6050
if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
6151
CurToken.TokKind))
62-
return true;
52+
return std::nullopt;
53+
54+
DescriptorTable Table;
55+
std::optional<ShaderVisibility> Visibility;
6356

6457
// Iterate as many Clauses as possible
65-
while (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
66-
TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
67-
if (parseDescriptorTableClause())
68-
return true;
58+
do {
59+
if (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
60+
TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
61+
auto Clause = parseDescriptorTableClause();
62+
if (!Clause.has_value())
63+
return std::nullopt;
64+
Elements.push_back(*Clause);
65+
Table.NumClauses++;
66+
}
6967

70-
Table.NumClauses++;
68+
if (tryConsumeExpectedToken(TokenKind::kw_visibility)) {
69+
if (Visibility.has_value()) {
70+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
71+
<< CurToken.TokKind;
72+
return std::nullopt;
73+
}
7174

72-
if (!tryConsumeExpectedToken(TokenKind::pu_comma))
73-
break;
74-
}
75+
if (consumeExpectedToken(TokenKind::pu_equal))
76+
return std::nullopt;
77+
78+
Visibility = parseShaderVisibility();
79+
if (!Visibility.has_value())
80+
return std::nullopt;
81+
}
82+
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
83+
84+
// Fill in optional visibility
85+
if (Visibility.has_value())
86+
Table.Visibility = Visibility.value();
7587

7688
if (consumeExpectedToken(TokenKind::pu_r_paren,
7789
diag::err_hlsl_unexpected_end_of_params,
7890
/*param of=*/TokenKind::kw_DescriptorTable))
79-
return true;
91+
return std::nullopt;
8092

81-
Elements.push_back(Table);
82-
return false;
93+
return Table;
8394
}
8495

85-
bool RootSignatureParser::parseDescriptorTableClause() {
96+
std::optional<DescriptorTableClause>
97+
RootSignatureParser::parseDescriptorTableClause() {
8698
assert((CurToken.TokKind == TokenKind::kw_CBV ||
8799
CurToken.TokKind == TokenKind::kw_SRV ||
88100
CurToken.TokKind == TokenKind::kw_UAV ||
@@ -93,7 +105,7 @@ bool RootSignatureParser::parseDescriptorTableClause() {
93105

94106
if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
95107
CurToken.TokKind))
96-
return true;
108+
return std::nullopt;
97109

98110
DescriptorTableClause Clause;
99111
TokenKind ExpectedReg;
@@ -120,13 +132,13 @@ bool RootSignatureParser::parseDescriptorTableClause() {
120132

121133
auto Params = parseDescriptorTableClauseParams(ExpectedReg);
122134
if (!Params.has_value())
123-
return true;
135+
return std::nullopt;
124136

125137
// Check mandatory parameters were provided
126138
if (!Params->Reg.has_value()) {
127139
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
128140
<< ExpectedReg;
129-
return true;
141+
return std::nullopt;
130142
}
131143

132144
Clause.Reg = Params->Reg.value();
@@ -138,10 +150,9 @@ bool RootSignatureParser::parseDescriptorTableClause() {
138150
if (consumeExpectedToken(TokenKind::pu_r_paren,
139151
diag::err_hlsl_unexpected_end_of_params,
140152
/*param of=*/ParamKind))
141-
return true;
153+
return std::nullopt;
142154

143-
Elements.push_back(Clause);
144-
return false;
155+
return Clause;
145156
}
146157

147158
std::optional<RootSignatureParser::ParsedClauseParams>
@@ -231,6 +242,32 @@ std::optional<Register> RootSignatureParser::parseRegister() {
231242
return Reg;
232243
}
233244

245+
std::optional<llvm::hlsl::rootsig::ShaderVisibility>
246+
RootSignatureParser::parseShaderVisibility() {
247+
assert(CurToken.TokKind == TokenKind::pu_equal &&
248+
"Expects to only be invoked starting at given keyword");
249+
250+
TokenKind Expected[] = {
251+
#define SHADER_VISIBILITY_ENUM(NAME, LIT) TokenKind::en_##NAME,
252+
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
253+
};
254+
255+
if (!tryConsumeExpectedToken(Expected))
256+
return std::nullopt;
257+
258+
switch (CurToken.TokKind) {
259+
#define SHADER_VISIBILITY_ENUM(NAME, LIT) \
260+
case TokenKind::en_##NAME: \
261+
return ShaderVisibility::NAME; \
262+
break;
263+
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
264+
default:
265+
llvm_unreachable("Switch for consumed enum token was not provided");
266+
}
267+
268+
return std::nullopt;
269+
}
270+
234271
std::optional<uint32_t> RootSignatureParser::handleUIntLiteral() {
235272
// Parse the numeric value and do semantic checks on its specification
236273
clang::NumericLiteralParser Literal(CurToken.NumSpelling, CurToken.TokLoc,

0 commit comments

Comments
 (0)