From 7e2f78923c47cf10639f706ea528b49142669a2d Mon Sep 17 00:00:00 2001 From: Pengcheng Wang Date: Sat, 28 Mar 2026 01:42:49 +0800 Subject: [PATCH] [RISCV][NFC] Use enum types to improve debuggability (#188418) So that we can see the enum values instead of integral values when dumping in debuggers. --- .../clang/Support/RISCVVIntrinsicUtils.h | 13 ++++---- clang/lib/Support/RISCVVIntrinsicUtils.cpp | 30 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h b/clang/include/clang/Support/RISCVVIntrinsicUtils.h index 4016cc2f77de..18738f2c3aa4 100644 --- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h +++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h @@ -173,14 +173,15 @@ struct PrototypeDescriptor { BaseTypeModifier PT, VectorTypeModifier VTM = VectorTypeModifier::NoModifier, TypeModifier TM = TypeModifier::NoModifier) - : PT(static_cast(PT)), VTM(static_cast(VTM)), - TM(static_cast(TM)) {} - constexpr PrototypeDescriptor(uint8_t PT, uint8_t VTM, uint8_t TM) : PT(PT), VTM(VTM), TM(TM) {} + constexpr PrototypeDescriptor(uint8_t PT, uint8_t VTM, uint8_t TM) + : PT(static_cast(PT)), + VTM(static_cast(VTM)), + TM(static_cast(TM)) {} - uint8_t PT = static_cast(BaseTypeModifier::Invalid); - uint8_t VTM = static_cast(VectorTypeModifier::NoModifier); - uint8_t TM = static_cast(TypeModifier::NoModifier); + BaseTypeModifier PT = BaseTypeModifier::Invalid; + VectorTypeModifier VTM = VectorTypeModifier::NoModifier; + TypeModifier TM = TypeModifier::NoModifier; bool operator!=(const PrototypeDescriptor &PD) const { return !(*this == PD); diff --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp b/clang/lib/Support/RISCVVIntrinsicUtils.cpp index a5430aee6b74..218d7b75ff7f 100644 --- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp +++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp @@ -481,7 +481,7 @@ PrototypeDescriptor::parsePrototypeDescriptor( default: llvm_unreachable("Illegal primitive type transformers!"); } - PD.PT = static_cast(PT); + PD.PT = PT; PrototypeDescriptorStr = PrototypeDescriptorStr.drop_back(); // Compute the vector type transformers, it can only appear one time. @@ -650,7 +650,7 @@ PrototypeDescriptor::parsePrototypeDescriptor( llvm_unreachable("Illegal complex type transformers!"); } } - PD.VTM = static_cast(VTM); + PD.VTM = VTM; // Compute the remain type transformers TypeModifier TM = TypeModifier::NoModifier; @@ -688,7 +688,7 @@ PrototypeDescriptor::parsePrototypeDescriptor( llvm_unreachable("Illegal non-primitive type transformer!"); } } - PD.TM = static_cast(TM); + PD.TM = TM; return PD; } @@ -972,9 +972,9 @@ static uint64_t computeRVVTypeHashValue(BasicType BT, int Log2LMUL, // | Log2LMUL + 3 | BT | Proto.PT | Proto.TM | Proto.VTM | assert(Log2LMUL >= -3 && Log2LMUL <= 3); return (Log2LMUL + 3) | (static_cast(BT) & 0xffff) << 8 | - ((uint64_t)(Proto.PT & 0xff) << 24) | - ((uint64_t)(Proto.TM & 0xff) << 32) | - ((uint64_t)(Proto.VTM & 0xff) << 40); + (static_cast(Proto.PT) << 24) | + (static_cast(Proto.TM) << 32) | + (static_cast(Proto.VTM) << 40); } std::optional RVVTypeCache::computeType(BasicType BT, int Log2LMUL, @@ -1086,10 +1086,9 @@ llvm::SmallVector RVVIntrinsic::computeBuiltinTypes( } else if (NF > 1) { if (IsTuple) { PrototypeDescriptor BasePtrOperand = Prototype[1]; - PrototypeDescriptor MaskoffType = PrototypeDescriptor( - static_cast(BaseTypeModifier::Vector), - static_cast(getTupleVTM(NF)), - BasePtrOperand.TM & ~static_cast(TypeModifier::Pointer)); + PrototypeDescriptor MaskoffType = + PrototypeDescriptor(BaseTypeModifier::Vector, getTupleVTM(NF), + BasePtrOperand.TM & ~TypeModifier::Pointer); NewPrototype.insert(NewPrototype.begin() + 1, MaskoffType); } else { // Convert @@ -1097,7 +1096,7 @@ llvm::SmallVector RVVIntrinsic::computeBuiltinTypes( // to // (void, op0 address, op1 address, ..., maskedoff0, maskedoff1, ...) PrototypeDescriptor MaskoffType = NewPrototype[1]; - MaskoffType.TM &= ~static_cast(TypeModifier::Pointer); + MaskoffType.TM &= ~TypeModifier::Pointer; NewPrototype.insert(NewPrototype.begin() + NF + 1, NF, MaskoffType); } } @@ -1125,10 +1124,9 @@ llvm::SmallVector RVVIntrinsic::computeBuiltinTypes( } else if (PolicyAttrs.isTUPolicy() && HasPassthruOp) { if (IsTuple) { PrototypeDescriptor BasePtrOperand = Prototype[0]; - PrototypeDescriptor MaskoffType = PrototypeDescriptor( - static_cast(BaseTypeModifier::Vector), - static_cast(getTupleVTM(NF)), - BasePtrOperand.TM & ~static_cast(TypeModifier::Pointer)); + PrototypeDescriptor MaskoffType = + PrototypeDescriptor(BaseTypeModifier::Vector, getTupleVTM(NF), + BasePtrOperand.TM & ~TypeModifier::Pointer); NewPrototype.insert(NewPrototype.begin(), MaskoffType); } else { // NF > 1 cases for segment load operations. @@ -1137,7 +1135,7 @@ llvm::SmallVector RVVIntrinsic::computeBuiltinTypes( // to // (void, op0 address, op1 address, maskedoff0, maskedoff1, ...) PrototypeDescriptor MaskoffType = Prototype[1]; - MaskoffType.TM &= ~static_cast(TypeModifier::Pointer); + MaskoffType.TM &= ~TypeModifier::Pointer; NewPrototype.insert(NewPrototype.begin() + NF + 1, NF, MaskoffType); } }