Skip to content

Commit 5dd5db9

Browse files
committed
Coding style fixes and remove invalid assert
1 parent 2ff6f95 commit 5dd5db9

File tree

9 files changed

+48
-67
lines changed

9 files changed

+48
-67
lines changed

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,11 @@ class ASTNodeTraverser
455455
using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
456456

457457
switch (Operand.getKind()) {
458-
case SpirvOperandKind::kConstantId:
459-
case SpirvOperandKind::kLiteral:
458+
case SpirvOperandKind::ConstantId:
459+
case SpirvOperandKind::Literal:
460460
break;
461461

462-
case SpirvOperandKind::kTypeId:
462+
case SpirvOperandKind::TypeId:
463463
Visit(Operand.getResultType());
464464
break;
465465

clang/include/clang/AST/Type.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6366,23 +6366,23 @@ class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode {
63666366
class SpirvOperand {
63676367
public:
63686368
enum SpirvOperandKind : unsigned char {
6369-
kInvalid, ///< Uninitialized.
6370-
kConstantId, ///< Integral value to represent as a SPIR-V OpConstant
6371-
///< instruction ID.
6372-
kLiteral, ///< Integral value to represent as an immediate literal.
6373-
kTypeId, ///< Type to represent as a SPIR-V type ID.
6369+
Invalid, ///< Uninitialized.
6370+
ConstantId, ///< Integral value to represent as a SPIR-V OpConstant
6371+
///< instruction ID.
6372+
Literal, ///< Integral value to represent as an immediate literal.
6373+
TypeId, ///< Type to represent as a SPIR-V type ID.
63746374

6375-
kMax,
6375+
Max,
63766376
};
63776377

63786378
private:
6379-
SpirvOperandKind Kind = kInvalid;
6379+
SpirvOperandKind Kind = Invalid;
63806380

63816381
QualType ResultType;
63826382
llvm::APInt Value; // Signedness of constants is represented by ResultType.
63836383

63846384
public:
6385-
SpirvOperand() : Kind(kInvalid), ResultType() {}
6385+
SpirvOperand() : Kind(Invalid), ResultType() {}
63866386

63876387
SpirvOperand(SpirvOperandKind Kind, QualType ResultType, llvm::APInt Value)
63886388
: Kind(Kind), ResultType(ResultType), Value(Value) {}
@@ -6406,10 +6406,10 @@ class SpirvOperand {
64066406

64076407
SpirvOperandKind getKind() const { return Kind; }
64086408

6409-
bool isValid() const { return Kind != kInvalid && Kind < kMax; }
6410-
bool isConstant() const { return Kind == kConstantId; }
6411-
bool isLiteral() const { return Kind == kLiteral; }
6412-
bool isType() const { return Kind == kTypeId; }
6409+
bool isValid() const { return Kind != Invalid && Kind < Max; }
6410+
bool isConstant() const { return Kind == ConstantId; }
6411+
bool isLiteral() const { return Kind == Literal; }
6412+
bool isType() const { return Kind == TypeId; }
64136413

64146414
llvm::APInt getValue() const {
64156415
assert((isConstant() || isLiteral()) &&
@@ -6424,15 +6424,15 @@ class SpirvOperand {
64246424
}
64256425

64266426
static SpirvOperand createConstant(QualType ResultType, llvm::APInt Val) {
6427-
return SpirvOperand(kConstantId, ResultType, Val);
6427+
return SpirvOperand(ConstantId, ResultType, Val);
64286428
}
64296429

64306430
static SpirvOperand createLiteral(llvm::APInt Val) {
6431-
return SpirvOperand(kLiteral, QualType(), Val);
6431+
return SpirvOperand(Literal, QualType(), Val);
64326432
}
64336433

64346434
static SpirvOperand createType(QualType T) {
6435-
return SpirvOperand(kTypeId, T, llvm::APSInt());
6435+
return SpirvOperand(TypeId, T, llvm::APSInt());
64366436
}
64376437

64386438
void Profile(llvm::FoldingSetNodeID &ID) const {
@@ -6460,9 +6460,8 @@ class HLSLInlineSpirvType final
64606460
ArrayRef<SpirvOperand> Operands)
64616461
: Type(HLSLInlineSpirv, QualType(), TypeDependence::None), Opcode(Opcode),
64626462
Size(Size), Alignment(Alignment), NumOperands(Operands.size()) {
6463-
for (size_t I = 0; I < NumOperands; I++) {
6463+
for (size_t I = 0; I < NumOperands; I++)
64646464
getTrailingObjects<SpirvOperand>()[I] = Operands[I];
6465-
}
64666465
}
64676466

64686467
public:
@@ -6486,9 +6485,8 @@ class HLSLInlineSpirvType final
64866485
ID.AddInteger(Opcode);
64876486
ID.AddInteger(Size);
64886487
ID.AddInteger(Alignment);
6489-
for (auto &Operand : Operands) {
6488+
for (auto &Operand : Operands)
64906489
Operand.Profile(ID);
6491-
}
64926490
}
64936491

64946492
static bool classof(const Type *T) {

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5496,9 +5496,9 @@ QualType ASTContext::getHLSLInlineSpirvType(uint32_t Opcode, uint32_t Size,
54965496

54975497
unsigned size = sizeof(HLSLInlineSpirvType);
54985498
size += Operands.size() * sizeof(SpirvOperand);
5499-
void *mem = Allocate(size, alignof(HLSLInlineSpirvType));
5499+
void *Mem = Allocate(size, alignof(HLSLInlineSpirvType));
55005500

5501-
Ty = new (mem) HLSLInlineSpirvType(Opcode, Size, Alignment, Operands);
5501+
Ty = new (Mem) HLSLInlineSpirvType(Opcode, Size, Alignment, Operands);
55025502

55035503
Types.push_back(Ty);
55045504
HLSLInlineSpirvTypes.InsertNode(Ty, InsertPos);
@@ -11864,11 +11864,9 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, bool OfBlockPointer,
1186411864
if (LHSTy->getOpcode() == RHSTy->getOpcode() &&
1186511865
LHSTy->getSize() == RHSTy->getSize() &&
1186611866
LHSTy->getAlignment() == RHSTy->getAlignment()) {
11867-
for (size_t I = 0; I < LHSTy->getOperands().size(); I++) {
11868-
if (LHSTy->getOperands()[I] != RHSTy->getOperands()[I]) {
11867+
for (size_t I = 0; I < LHSTy->getOperands().size(); I++)
11868+
if (LHSTy->getOperands()[I] != RHSTy->getOperands()[I])
1186911869
return {};
11870-
}
11871-
}
1187211870

1187311871
return LHS;
1187411872
}

clang/lib/AST/ASTImporter.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,19 +1837,18 @@ ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
18371837

18381838
llvm::SmallVector<SpirvOperand> ToOperands;
18391839

1840-
size_t I = 0;
18411840
for (auto &Operand : T->getOperands()) {
18421841
using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
18431842

18441843
switch (Operand.getKind()) {
1845-
case SpirvOperandKind::kConstantId:
1844+
case SpirvOperandKind::ConstantId:
18461845
ToOperands.push_back(SpirvOperand::createConstant(
18471846
importChecked(Err, Operand.getResultType()), Operand.getValue()));
18481847
break;
1849-
case SpirvOperandKind::kLiteral:
1848+
case SpirvOperandKind::Literal:
18501849
ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
18511850
break;
1852-
case SpirvOperandKind::kTypeId:
1851+
case SpirvOperandKind::TypeId:
18531852
ToOperands.push_back(SpirvOperand::createType(
18541853
importChecked(Err, Operand.getResultType())));
18551854
break;
@@ -1861,8 +1860,6 @@ ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
18611860
return std::move(Err);
18621861
}
18631862

1864-
assert(I == NumOperands);
1865-
18661863
return Importer.getToContext().getHLSLInlineSpirvType(
18671864
ToOpcode, ToSize, ToAlignment, ToOperands);
18681865
}

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4709,17 +4709,17 @@ void CXXNameMangler::mangleType(const HLSLInlineSpirvType *T) {
47094709
using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
47104710

47114711
switch (Operand.getKind()) {
4712-
case SpirvOperandKind::kConstantId:
4712+
case SpirvOperandKind::ConstantId:
47134713
mangleVendorQualifier("_Const");
47144714
mangleIntegerLiteral(Operand.getResultType(),
47154715
llvm::APSInt(Operand.getValue()));
47164716
break;
4717-
case SpirvOperandKind::kLiteral:
4717+
case SpirvOperandKind::Literal:
47184718
mangleVendorQualifier("_Lit");
47194719
mangleIntegerLiteral(Context.getASTContext().IntTy,
47204720
llvm::APSInt(Operand.getValue()));
47214721
break;
4722-
case SpirvOperandKind::kTypeId:
4722+
case SpirvOperandKind::TypeId:
47234723
mangleVendorQualifier("_Type");
47244724
mangleType(Operand.getResultType());
47254725
break;

clang/lib/AST/TypePrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ void TypePrinter::printHLSLInlineSpirvBefore(const HLSLInlineSpirvType *T,
21522152

21532153
OS << ", ";
21542154
switch (Operand.getKind()) {
2155-
case SpirvOperandKind::kConstantId: {
2155+
case SpirvOperandKind::ConstantId: {
21562156
QualType ConstantType = Operand.getResultType();
21572157
OS << "vk::integral_constant<";
21582158
printBefore(ConstantType, OS);
@@ -2162,12 +2162,12 @@ void TypePrinter::printHLSLInlineSpirvBefore(const HLSLInlineSpirvType *T,
21622162
OS << ">";
21632163
break;
21642164
}
2165-
case SpirvOperandKind::kLiteral:
2165+
case SpirvOperandKind::Literal:
21662166
OS << "vk::Literal<vk::integral_constant<uint, ";
21672167
OS << Operand.getValue();
21682168
OS << ">>";
21692169
break;
2170-
case SpirvOperandKind::kTypeId: {
2170+
case SpirvOperandKind::TypeId: {
21712171
QualType Type = Operand.getResultType();
21722172
printBefore(Type, OS);
21732173
printAfter(Type, OS);

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,8 @@ bool CodeGenTypes::isZeroInitializable(QualType T) {
882882
return getCXXABI().isZeroInitializable(MPT);
883883

884884
// HLSL Inline SPIR-V types are non-zero-initializable.
885-
if (T->getAs<HLSLInlineSpirvType>()) {
885+
if (T->getAs<HLSLInlineSpirvType>())
886886
return false;
887-
}
888887

889888
// Everything else is okay.
890889
return true;

clang/lib/CodeGen/Targets/SPIR.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,10 @@ static llvm::Type *getInlineSpirvConstant(CodeGenModule &CGM,
396396
if (Words.size() == 0)
397397
Words.push_back(0);
398398

399-
if (IntegralType) {
399+
if (IntegralType)
400400
return llvm::TargetExtType::get(Ctx, "spirv.IntegralConstant",
401401
{IntegralType}, Words);
402-
} else {
403-
return llvm::TargetExtType::get(Ctx, "spirv.Literal", {}, Words);
404-
}
402+
return llvm::TargetExtType::get(Ctx, "spirv.Literal", {}, Words);
405403
}
406404

407405
static llvm::Type *getInlineSpirvType(CodeGenModule &CGM,
@@ -415,20 +413,20 @@ static llvm::Type *getInlineSpirvType(CodeGenModule &CGM,
415413

416414
llvm::Type *Result = nullptr;
417415
switch (Operand.getKind()) {
418-
case SpirvOperandKind::kConstantId: {
416+
case SpirvOperandKind::ConstantId: {
419417
llvm::Type *IntegralType =
420418
CGM.getTypes().ConvertType(Operand.getResultType());
421419
llvm::APInt Value = Operand.getValue();
422420

423421
Result = getInlineSpirvConstant(CGM, IntegralType, Value);
424422
break;
425423
}
426-
case SpirvOperandKind::kLiteral: {
424+
case SpirvOperandKind::Literal: {
427425
llvm::APInt Value = Operand.getValue();
428426
Result = getInlineSpirvConstant(CGM, nullptr, Value);
429427
break;
430428
}
431-
case SpirvOperandKind::kTypeId: {
429+
case SpirvOperandKind::TypeId: {
432430
QualType TypeOperand = Operand.getResultType();
433431
if (auto *RT = TypeOperand->getAs<RecordType>()) {
434432
auto *RD = RT->getDecl();
@@ -465,9 +463,8 @@ llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(
465463
const SmallVector<int32_t> *Packoffsets) const {
466464
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
467465

468-
if (auto *SpirvType = dyn_cast<HLSLInlineSpirvType>(Ty)) {
466+
if (auto *SpirvType = dyn_cast<HLSLInlineSpirvType>(Ty))
469467
return getInlineSpirvType(CGM, SpirvType);
470-
}
471468

472469
auto *ResType = dyn_cast<HLSLAttributedResourceType>(Ty);
473470
if (!ResType)

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,20 +3269,17 @@ static SpirvOperand checkHLSLSpirvTypeOperand(Sema &SemaRef,
32693269
QualType ConstantType = ConstantArgs[0].getAsType();
32703270
llvm::APInt Value = ConstantArgs[1].getAsIntegral();
32713271

3272-
if (Literal) {
3272+
if (Literal)
32733273
return SpirvOperand::createLiteral(Value);
3274-
} else {
3275-
return SpirvOperand::createConstant(ConstantType, Value);
3276-
}
3274+
return SpirvOperand::createConstant(ConstantType, Value);
32773275
} else if (Literal) {
32783276
SemaRef.Diag(LiteralLoc, diag::err_hlsl_vk_literal_must_contain_constant);
32793277
return SpirvOperand();
32803278
}
32813279
}
32823280
if (SemaRef.RequireCompleteType(Loc, OperandArg,
3283-
diag::err_call_incomplete_argument)) {
3281+
diag::err_call_incomplete_argument))
32843282
return SpirvOperand();
3285-
}
32863283
return SpirvOperand::createType(OperandArg);
32873284
}
32883285

@@ -3391,8 +3388,7 @@ checkBuiltinTemplateIdType(Sema &SemaRef, BuiltinTemplateDecl *BTD,
33913388
assert(Converted.size() == 4);
33923389

33933390
if (!Context.getTargetInfo().getTriple().isSPIRV()) {
3394-
SemaRef.Diag(TemplateLoc, diag::err_hlsl_spirv_only)
3395-
<< "__hlsl_spirv_type";
3391+
SemaRef.Diag(TemplateLoc, diag::err_hlsl_spirv_only) << BTD;
33963392
}
33973393

33983394
if (llvm::any_of(Converted, [](auto &C) { return C.isDependent(); }))
@@ -3410,9 +3406,8 @@ checkBuiltinTemplateIdType(Sema &SemaRef, BuiltinTemplateDecl *BTD,
34103406
QualType OperandArg = OperandTA.getAsType();
34113407
auto Operand = checkHLSLSpirvTypeOperand(SemaRef, OperandArg,
34123408
TemplateArgs[3].getLocation());
3413-
if (!Operand.isValid()) {
3409+
if (!Operand.isValid())
34143410
return QualType();
3415-
}
34163411
Operands.push_back(Operand);
34173412
}
34183413

@@ -6250,13 +6245,10 @@ bool UnnamedLocalNoLinkageFinder::VisitHLSLAttributedResourceType(
62506245

62516246
bool UnnamedLocalNoLinkageFinder::VisitHLSLInlineSpirvType(
62526247
const HLSLInlineSpirvType *T) {
6253-
for (auto &Operand : T->getOperands()) {
6254-
if (Operand.isConstant() && Operand.isLiteral()) {
6255-
if (Visit(Operand.getResultType())) {
6248+
for (auto &Operand : T->getOperands())
6249+
if (Operand.isConstant() && Operand.isLiteral())
6250+
if (Visit(Operand.getResultType()))
62566251
return true;
6257-
}
6258-
}
6259-
}
62606252
return false;
62616253
}
62626254

0 commit comments

Comments
 (0)