Skip to content

Commit e57f4e8

Browse files
committed
[RISCV][NFC] Make generated intrinsic records more human-readable (llvm#133710)
We add comment markers and print enum names instead of numbers. For required extensions, we print the feature list instead of raw bits. This recommits d0cf5cd which was reverted by 21ff45d.
1 parent 21ff45d commit e57f4e8

File tree

4 files changed

+105
-33
lines changed

4 files changed

+105
-33
lines changed

clang/include/clang/Support/RISCVVIntrinsicUtils.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/ADT/BitmaskEnum.h"
14+
#include "llvm/ADT/Bitset.h"
1415
#include "llvm/ADT/SmallVector.h"
1516
#include "llvm/ADT/StringRef.h"
1617
#include <cstdint>
@@ -376,6 +377,8 @@ enum PolicyScheme : uint8_t {
376377
HasPolicyOperand,
377378
};
378379

380+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum PolicyScheme PS);
381+
379382
// TODO refactor RVVIntrinsic class design after support all intrinsic
380383
// combination. This represents an instantiation of an intrinsic with a
381384
// particular type and prototype
@@ -507,6 +510,23 @@ enum RVVRequire {
507510
RVV_REQ_NUM,
508511
};
509512

513+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum RVVRequire Require);
514+
515+
struct RequiredExtensionBits {
516+
llvm::Bitset<RVV_REQ_NUM> Bits;
517+
RequiredExtensionBits() {}
518+
RequiredExtensionBits(std::initializer_list<RVVRequire> Init) {
519+
for (auto I : Init)
520+
Bits.set(I);
521+
}
522+
523+
void set(unsigned I) { Bits.set(I); }
524+
bool operator[](unsigned I) const { return Bits[I]; }
525+
};
526+
527+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
528+
const RequiredExtensionBits &Exts);
529+
510530
// Raw RVV intrinsic info, used to expand later.
511531
// This struct is highly compact for minimized code size.
512532
struct RVVIntrinsicRecord {
@@ -518,7 +538,7 @@ struct RVVIntrinsicRecord {
518538
const char *OverloadedName;
519539

520540
// Required target features for this intrinsic.
521-
uint32_t RequiredExtensions[(RVV_REQ_NUM + 31) / 32];
541+
RequiredExtensionBits RequiredExtensions;
522542

523543
// Prototype for this intrinsic, index of RVVSignatureTable.
524544
uint16_t PrototypeIndex;

clang/lib/Sema/SemaRISCV.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
232232
for (auto &Record : Recs) {
233233
// Check requirements.
234234
if (llvm::any_of(FeatureCheckList, [&](const auto &Item) {
235-
return ((Record.RequiredExtensions[Item.second / 32] &
236-
(1U << (Item.second % 32))) != 0) &&
235+
return Record.RequiredExtensions[Item.second] &&
237236
!TI.hasFeature(Item.first);
238237
}))
239238
continue;

clang/lib/Support/RISCVVIntrinsicUtils.cpp

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,36 +1196,91 @@ SmallVector<PrototypeDescriptor> parsePrototypes(StringRef Prototypes) {
11961196
return PrototypeDescriptors;
11971197
}
11981198

1199+
#define STRINGIFY(NAME) \
1200+
case NAME: \
1201+
OS << #NAME; \
1202+
break;
1203+
1204+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum PolicyScheme PS) {
1205+
switch (PS) {
1206+
STRINGIFY(SchemeNone)
1207+
STRINGIFY(HasPassthruOperand)
1208+
STRINGIFY(HasPolicyOperand)
1209+
}
1210+
return OS;
1211+
}
1212+
1213+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum RVVRequire Require) {
1214+
switch (Require) {
1215+
STRINGIFY(RVV_REQ_RV64)
1216+
STRINGIFY(RVV_REQ_Zvfhmin)
1217+
STRINGIFY(RVV_REQ_Xsfvcp)
1218+
STRINGIFY(RVV_REQ_Xsfvfnrclipxfqf)
1219+
STRINGIFY(RVV_REQ_Xsfvfwmaccqqq)
1220+
STRINGIFY(RVV_REQ_Xsfvqmaccdod)
1221+
STRINGIFY(RVV_REQ_Xsfvqmaccqoq)
1222+
STRINGIFY(RVV_REQ_Zvbb)
1223+
STRINGIFY(RVV_REQ_Zvbc)
1224+
STRINGIFY(RVV_REQ_Zvkb)
1225+
STRINGIFY(RVV_REQ_Zvkg)
1226+
STRINGIFY(RVV_REQ_Zvkned)
1227+
STRINGIFY(RVV_REQ_Zvknha)
1228+
STRINGIFY(RVV_REQ_Zvknhb)
1229+
STRINGIFY(RVV_REQ_Zvksed)
1230+
STRINGIFY(RVV_REQ_Zvksh)
1231+
STRINGIFY(RVV_REQ_Zvfbfwma)
1232+
STRINGIFY(RVV_REQ_Zvfbfmin)
1233+
STRINGIFY(RVV_REQ_Zvfh)
1234+
STRINGIFY(RVV_REQ_Experimental)
1235+
default:
1236+
llvm_unreachable("Unsupported RVVRequire!");
1237+
break;
1238+
}
1239+
return OS;
1240+
}
1241+
1242+
#undef STRINGIFY
1243+
1244+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1245+
const RequiredExtensionBits &Exts) {
1246+
OS << "{";
1247+
ListSeparator LS;
1248+
for (unsigned I = 0; I < RVV_REQ_NUM; I++)
1249+
if (Exts[I])
1250+
OS << LS << static_cast<RVVRequire>(I);
1251+
OS << "}";
1252+
return OS;
1253+
}
1254+
11991255
raw_ostream &operator<<(raw_ostream &OS, const RVVIntrinsicRecord &Record) {
12001256
OS << "{";
1201-
OS << "\"" << Record.Name << "\",";
1257+
OS << "/*Name=*/\"" << Record.Name << "\", ";
12021258
if (Record.OverloadedName == nullptr ||
12031259
StringRef(Record.OverloadedName).empty())
1204-
OS << "nullptr,";
1260+
OS << "/*OverloadedName=*/nullptr, ";
12051261
else
1206-
OS << "\"" << Record.OverloadedName << "\",";
1207-
OS << "{";
1208-
for (uint32_t Exts : Record.RequiredExtensions)
1209-
OS << Exts << ',';
1210-
OS << "},";
1211-
OS << Record.PrototypeIndex << ",";
1212-
OS << Record.SuffixIndex << ",";
1213-
OS << Record.OverloadedSuffixIndex << ",";
1214-
OS << (int)Record.PrototypeLength << ",";
1215-
OS << (int)Record.SuffixLength << ",";
1216-
OS << (int)Record.OverloadedSuffixSize << ",";
1217-
OS << (int)Record.TypeRangeMask << ",";
1218-
OS << (int)Record.Log2LMULMask << ",";
1219-
OS << (int)Record.NF << ",";
1220-
OS << (int)Record.HasMasked << ",";
1221-
OS << (int)Record.HasVL << ",";
1222-
OS << (int)Record.HasMaskedOffOperand << ",";
1223-
OS << (int)Record.HasTailPolicy << ",";
1224-
OS << (int)Record.HasMaskPolicy << ",";
1225-
OS << (int)Record.HasFRMRoundModeOp << ",";
1226-
OS << (int)Record.IsTuple << ",";
1227-
OS << (int)Record.UnMaskedPolicyScheme << ",";
1228-
OS << (int)Record.MaskedPolicyScheme << ",";
1262+
OS << "/*OverloadedName=*/\"" << Record.OverloadedName << "\", ";
1263+
OS << "/*RequiredExtensions=*/" << Record.RequiredExtensions << ", ";
1264+
OS << "/*PrototypeIndex=*/" << Record.PrototypeIndex << ", ";
1265+
OS << "/*SuffixIndex=*/" << Record.SuffixIndex << ", ";
1266+
OS << "/*OverloadedSuffixIndex=*/" << Record.OverloadedSuffixIndex << ", ";
1267+
OS << "/*PrototypeLength=*/" << (int)Record.PrototypeLength << ", ";
1268+
OS << "/*SuffixLength=*/" << (int)Record.SuffixLength << ", ";
1269+
OS << "/*OverloadedSuffixSize=*/" << (int)Record.OverloadedSuffixSize << ", ";
1270+
OS << "/*TypeRangeMask=*/" << (int)Record.TypeRangeMask << ", ";
1271+
OS << "/*Log2LMULMask=*/" << (int)Record.Log2LMULMask << ", ";
1272+
OS << "/*NF=*/" << (int)Record.NF << ", ";
1273+
OS << "/*HasMasked=*/" << (int)Record.HasMasked << ", ";
1274+
OS << "/*HasVL=*/" << (int)Record.HasVL << ", ";
1275+
OS << "/*HasMaskedOffOperand=*/" << (int)Record.HasMaskedOffOperand << ", ";
1276+
OS << "/*HasTailPolicy=*/" << (int)Record.HasTailPolicy << ", ";
1277+
OS << "/*HasMaskPolicy=*/" << (int)Record.HasMaskPolicy << ", ";
1278+
OS << "/*HasFRMRoundModeOp=*/" << (int)Record.HasFRMRoundModeOp << ", ";
1279+
OS << "/*IsTuple=*/" << (int)Record.IsTuple << ", ";
1280+
OS << "/*UnMaskedPolicyScheme=*/" << (PolicyScheme)Record.UnMaskedPolicyScheme
1281+
<< ", ";
1282+
OS << "/*MaskedPolicyScheme=*/" << (PolicyScheme)Record.MaskedPolicyScheme
1283+
<< ", ";
12291284
OS << "},\n";
12301285
return OS;
12311286
}

clang/utils/TableGen/RISCVVEmitter.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct SemaRecord {
4545
unsigned Log2LMULMask;
4646

4747
// Required extensions for this intrinsic.
48-
uint32_t RequiredExtensions[(RVV_REQ_NUM + 31) / 32];
48+
RequiredExtensionBits RequiredExtensions;
4949

5050
// Prototype for this intrinsic.
5151
SmallVector<PrototypeDescriptor> Prototype;
@@ -769,7 +769,6 @@ void RVVEmitter::createRVVIntrinsics(
769769

770770
SR.Log2LMULMask = Log2LMULMask;
771771

772-
memset(SR.RequiredExtensions, 0, sizeof(SR.RequiredExtensions));
773772
for (auto RequiredFeature : RequiredFeatures) {
774773
unsigned RequireExt =
775774
StringSwitch<RVVRequire>(RequiredFeature)
@@ -793,7 +792,7 @@ void RVVEmitter::createRVVIntrinsics(
793792
.Case("Zvfbfmin", RVV_REQ_Zvfbfmin)
794793
.Case("Zvfh", RVV_REQ_Zvfh)
795794
.Case("Experimental", RVV_REQ_Experimental);
796-
SR.RequiredExtensions[RequireExt / 32] |= 1U << (RequireExt % 32);
795+
SR.RequiredExtensions.set(RequireExt);
797796
}
798797

799798
SR.NF = NF;
@@ -837,8 +836,7 @@ void RVVEmitter::createRVVIntrinsicRecords(std::vector<RVVIntrinsicRecord> &Out,
837836
R.PrototypeLength = SR.Prototype.size();
838837
R.SuffixLength = SR.Suffix.size();
839838
R.OverloadedSuffixSize = SR.OverloadedSuffix.size();
840-
memcpy(R.RequiredExtensions, SR.RequiredExtensions,
841-
sizeof(R.RequiredExtensions));
839+
R.RequiredExtensions = SR.RequiredExtensions;
842840
R.TypeRangeMask = SR.TypeRangeMask;
843841
R.Log2LMULMask = SR.Log2LMULMask;
844842
R.NF = SR.NF;

0 commit comments

Comments
 (0)