Skip to content

Commit 2354f87

Browse files
committed
Addresses reviewer comments.
1 parent c0d7562 commit 2354f87

13 files changed

Lines changed: 265 additions & 244 deletions

tools/clang/include/clang/AST/OperationKinds.h

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <limits> // HLSL Change
2222

2323
namespace clang {
24-
24+
2525
/// CastKind - The kind of operation required for a conversion.
2626
enum CastKind {
2727
/// CK_Dependent - A conversion which cannot yet be analyzed because
@@ -340,55 +340,35 @@ static_assert(
340340
enum BinaryOperatorKind {
341341
// Operators listed in order of precedence.
342342
// Note that additions to this should also update the StmtVisitor class.
343-
BO_PtrMemD,
344-
BO_PtrMemI, // [C++ 5.5] Pointer-to-member operators.
345-
BO_Mul,
346-
BO_Div,
347-
BO_Rem, // [C99 6.5.5] Multiplicative operators.
348-
BO_Add,
349-
BO_Sub, // [C99 6.5.6] Additive operators.
350-
BO_Shl,
351-
BO_Shr, // [C99 6.5.7] Bitwise shift operators.
352-
BO_LT,
353-
BO_GT,
354-
BO_LE,
355-
BO_GE, // [C99 6.5.8] Relational operators.
356-
BO_EQ,
357-
BO_NE, // [C99 6.5.9] Equality operators.
358-
BO_And, // [C99 6.5.10] Bitwise AND operator.
359-
BO_Xor, // [C99 6.5.11] Bitwise XOR operator.
360-
BO_Or, // [C99 6.5.12] Bitwise OR operator.
361-
BO_LAnd, // [C99 6.5.13] Logical AND operator.
362-
BO_LOr, // [C99 6.5.14] Logical OR operator.
363-
BO_Assign,
364-
BO_MulAssign, // [C99 6.5.16] Assignment operators.
365-
BO_DivAssign,
366-
BO_RemAssign,
367-
BO_AddAssign,
368-
BO_SubAssign,
369-
BO_ShlAssign,
370-
BO_ShrAssign,
371-
BO_AndAssign,
372-
BO_XorAssign,
343+
BO_PtrMemD, BO_PtrMemI, // [C++ 5.5] Pointer-to-member operators.
344+
BO_Mul, BO_Div, BO_Rem, // [C99 6.5.5] Multiplicative operators.
345+
BO_Add, BO_Sub, // [C99 6.5.6] Additive operators.
346+
BO_Shl, BO_Shr, // [C99 6.5.7] Bitwise shift operators.
347+
BO_LT, BO_GT, BO_LE, BO_GE, // [C99 6.5.8] Relational operators.
348+
BO_EQ, BO_NE, // [C99 6.5.9] Equality operators.
349+
BO_And, // [C99 6.5.10] Bitwise AND operator.
350+
BO_Xor, // [C99 6.5.11] Bitwise XOR operator.
351+
BO_Or, // [C99 6.5.12] Bitwise OR operator.
352+
BO_LAnd, // [C99 6.5.13] Logical AND operator.
353+
BO_LOr, // [C99 6.5.14] Logical OR operator.
354+
BO_Assign, BO_MulAssign, // [C99 6.5.16] Assignment operators.
355+
BO_DivAssign, BO_RemAssign,
356+
BO_AddAssign, BO_SubAssign,
357+
BO_ShlAssign, BO_ShrAssign,
358+
BO_AndAssign, BO_XorAssign,
373359
BO_OrAssign,
374-
BO_Comma // [C99 6.5.17] Comma operator.
360+
BO_Comma // [C99 6.5.17] Comma operator.
375361
};
376362

377363
enum UnaryOperatorKind {
378364
// Note that additions to this should also update the StmtVisitor class.
379-
UO_PostInc,
380-
UO_PostDec, // [C99 6.5.2.4] Postfix increment and decrement
381-
UO_PreInc,
382-
UO_PreDec, // [C99 6.5.3.1] Prefix increment and decrement
383-
UO_AddrOf,
384-
UO_Deref, // [C99 6.5.3.2] Address and indirection
385-
UO_Plus,
386-
UO_Minus, // [C99 6.5.3.3] Unary arithmetic
387-
UO_Not,
388-
UO_LNot, // [C99 6.5.3.3] Unary arithmetic
389-
UO_Real,
390-
UO_Imag, // "__real expr"/"__imag expr" Extension.
391-
UO_Extension // __extension__ marker.
365+
UO_PostInc, UO_PostDec, // [C99 6.5.2.4] Postfix increment and decrement
366+
UO_PreInc, UO_PreDec, // [C99 6.5.3.1] Prefix increment and decrement
367+
UO_AddrOf, UO_Deref, // [C99 6.5.3.2] Address and indirection
368+
UO_Plus, UO_Minus, // [C99 6.5.3.3] Unary arithmetic
369+
UO_Not, UO_LNot, // [C99 6.5.3.3] Unary arithmetic
370+
UO_Real, UO_Imag, // "__real expr"/"__imag expr" Extension.
371+
UO_Extension // __extension__ marker.
392372
};
393373

394374
/// \brief The kind of bridging performed by the Objective-C bridge cast.
@@ -404,6 +384,6 @@ enum ObjCBridgeCastKind {
404384
OBC_BridgeRetained
405385
};
406386

407-
} // namespace clang
387+
}
408388

409389
#endif

tools/clang/lib/AST/HlslTypes.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -910,46 +910,46 @@ bool IsHLSLRayQueryType(clang::QualType type) {
910910
}
911911

912912
#ifdef ENABLE_SPIRV_CODEGEN
913+
static llvm::Optional<std::pair<clang::QualType, unsigned>>
914+
MaybeGetVKBufferPointerParams(clang::QualType type) {
915+
const RecordType *RT = dyn_cast<RecordType>(type.getCanonicalType());
916+
if (!RT)
917+
return llvm::None;
918+
919+
const ClassTemplateSpecializationDecl *templateDecl =
920+
dyn_cast<ClassTemplateSpecializationDecl>(RT->getAsCXXRecordDecl());
921+
if (!templateDecl || !templateDecl->getName().equals("BufferPointer"))
922+
return llvm::None;
923+
924+
auto *namespaceDecl =
925+
dyn_cast_or_null<NamespaceDecl>(templateDecl->getDeclContext());
926+
if (!namespaceDecl || !namespaceDecl->getName().equals("vk"))
927+
return llvm::None;
928+
929+
const TemplateArgumentList &argList = templateDecl->getTemplateArgs();
930+
QualType bufferType = argList[0].getAsType();
931+
unsigned align =
932+
argList.size() > 1 ? argList[1].getAsIntegral().getLimitedValue() : 0;
933+
return std::make_pair(bufferType, align);
934+
}
935+
913936
bool IsVKBufferPointerType(clang::QualType type) {
914-
type = type.getCanonicalType();
915-
if (const RecordType *RT = dyn_cast<RecordType>(type)) {
916-
if (const ClassTemplateSpecializationDecl *templateDecl =
917-
dyn_cast<ClassTemplateSpecializationDecl>(
918-
RT->getAsCXXRecordDecl())) {
919-
if (auto *namespaceDecl =
920-
dyn_cast_or_null<NamespaceDecl>(templateDecl->getDeclContext())) {
921-
if (namespaceDecl->getName().equals("vk") &&
922-
templateDecl->getName().equals("BufferPointer")) {
923-
return true;
924-
}
925-
}
926-
}
927-
}
928-
return false;
937+
return MaybeGetVKBufferPointerParams(type).hasValue();
929938
}
930939

931940
QualType GetVKBufferPointerBufferType(clang::QualType type) {
932-
return GetHLSLResourceTemplateParamType(type);
941+
auto bpParams = MaybeGetVKBufferPointerParams(type);
942+
assert(bpParams.hasValue() &&
943+
"cannot get pointer type for type that is not a vk::BufferPointer");
944+
return bpParams.getValue().first;
933945
}
934946

935947
unsigned GetVKBufferPointerAlignment(clang::QualType type) {
936-
type = type.getCanonicalType();
937-
if (const RecordType *RT = dyn_cast<RecordType>(type)) {
938-
if (const ClassTemplateSpecializationDecl *templateDecl =
939-
dyn_cast<ClassTemplateSpecializationDecl>(
940-
RT->getAsCXXRecordDecl())) {
941-
if (auto *namespaceDecl =
942-
dyn_cast_or_null<NamespaceDecl>(templateDecl->getDeclContext())) {
943-
if (namespaceDecl->getName().equals("vk") &&
944-
templateDecl->getName().equals("BufferPointer")) {
945-
const TemplateArgumentList &argList = templateDecl->getTemplateArgs();
946-
return (unsigned)argList[1].getAsIntegral().getLimitedValue();
947-
}
948-
}
949-
}
950-
}
951-
952-
return 0; // TODO: error
948+
auto bpParams = MaybeGetVKBufferPointerParams(type);
949+
assert(
950+
bpParams.hasValue() &&
951+
"cannot get pointer alignment for type that is not a vk::BufferPointer");
952+
return bpParams.getValue().second;
953953
}
954954
#endif
955955

0 commit comments

Comments
 (0)