Skip to content

Commit 1752d52

Browse files
authored
[RISCV] Make RequiredExtensions for intrinsics scalable to more than 32 extensions. NFC (#132895)
We have more than 32 extensions in our downstream and had to change this type from uint32_t to uint64_t. To simplify our downstream and make the code more flexible, I propose to make it an array of uint32_t that we can size based on the number of extensions. I really wanted to use std::bitset, but we have to print the bits to a .inc file which can't easily be done with std::bitset.
1 parent 6927483 commit 1752d52

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed

clang/include/clang/Support/RISCVVIntrinsicUtils.h

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -483,30 +483,28 @@ class RVVIntrinsic {
483483

484484
// RVVRequire should be sync'ed with target features, but only
485485
// required features used in riscv_vector.td.
486-
enum RVVRequire : uint32_t {
487-
RVV_REQ_None = 0,
488-
RVV_REQ_RV64 = 1 << 0,
489-
RVV_REQ_Zvfhmin = 1 << 1,
490-
RVV_REQ_Xsfvcp = 1 << 2,
491-
RVV_REQ_Xsfvfnrclipxfqf = 1 << 3,
492-
RVV_REQ_Xsfvfwmaccqqq = 1 << 4,
493-
RVV_REQ_Xsfvqmaccdod = 1 << 5,
494-
RVV_REQ_Xsfvqmaccqoq = 1 << 6,
495-
RVV_REQ_Zvbb = 1 << 7,
496-
RVV_REQ_Zvbc = 1 << 8,
497-
RVV_REQ_Zvkb = 1 << 9,
498-
RVV_REQ_Zvkg = 1 << 10,
499-
RVV_REQ_Zvkned = 1 << 11,
500-
RVV_REQ_Zvknha = 1 << 12,
501-
RVV_REQ_Zvknhb = 1 << 13,
502-
RVV_REQ_Zvksed = 1 << 14,
503-
RVV_REQ_Zvksh = 1 << 15,
504-
RVV_REQ_Zvfbfwma = 1 << 16,
505-
RVV_REQ_Zvfbfmin = 1 << 17,
506-
RVV_REQ_Zvfh = 1 << 18,
507-
RVV_REQ_Experimental = 1 << 19,
508-
509-
LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Experimental)
486+
enum RVVRequire {
487+
RVV_REQ_RV64,
488+
RVV_REQ_Zvfhmin,
489+
RVV_REQ_Xsfvcp,
490+
RVV_REQ_Xsfvfnrclipxfqf,
491+
RVV_REQ_Xsfvfwmaccqqq,
492+
RVV_REQ_Xsfvqmaccdod,
493+
RVV_REQ_Xsfvqmaccqoq,
494+
RVV_REQ_Zvbb,
495+
RVV_REQ_Zvbc,
496+
RVV_REQ_Zvkb,
497+
RVV_REQ_Zvkg,
498+
RVV_REQ_Zvkned,
499+
RVV_REQ_Zvknha,
500+
RVV_REQ_Zvknhb,
501+
RVV_REQ_Zvksed,
502+
RVV_REQ_Zvksh,
503+
RVV_REQ_Zvfbfwma,
504+
RVV_REQ_Zvfbfmin,
505+
RVV_REQ_Zvfh,
506+
RVV_REQ_Experimental,
507+
RVV_REQ_NUM,
510508
};
511509

512510
// Raw RVV intrinsic info, used to expand later.
@@ -519,6 +517,9 @@ struct RVVIntrinsicRecord {
519517
// e.g. vadd
520518
const char *OverloadedName;
521519

520+
// Required target features for this intrinsic.
521+
uint32_t RequiredExtensions[(RVV_REQ_NUM + 31) / 32];
522+
522523
// Prototype for this intrinsic, index of RVVSignatureTable.
523524
uint16_t PrototypeIndex;
524525

@@ -537,9 +538,6 @@ struct RVVIntrinsicRecord {
537538
// Length of overloaded intrinsic suffix.
538539
uint8_t OverloadedSuffixSize;
539540

540-
// Required target features for this intrinsic.
541-
uint32_t RequiredExtensions;
542-
543541
// Supported type, mask of BasicType.
544542
uint8_t TypeRangeMask;
545543

clang/lib/Sema/SemaRISCV.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class RISCVIntrinsicManagerImpl : public sema::RISCVIntrinsicManager {
206206
void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
207207
ArrayRef<RVVIntrinsicRecord> Recs, IntrinsicKind K) {
208208
const TargetInfo &TI = Context.getTargetInfo();
209-
static const std::pair<const char *, RVVRequire> FeatureCheckList[] = {
209+
static const std::pair<const char *, unsigned> FeatureCheckList[] = {
210210
{"64bit", RVV_REQ_RV64},
211211
{"xsfvcp", RVV_REQ_Xsfvcp},
212212
{"xsfvfnrclipxfqf", RVV_REQ_Xsfvfnrclipxfqf},
@@ -232,7 +232,8 @@ 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) == Item.second &&
235+
return ((Record.RequiredExtensions[Item.second / 32] &
236+
(1U << (Item.second % 32))) != 0) &&
236237
!TI.hasFeature(Item.first);
237238
}))
238239
continue;

clang/lib/Support/RISCVVIntrinsicUtils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,13 +1204,16 @@ raw_ostream &operator<<(raw_ostream &OS, const RVVIntrinsicRecord &Record) {
12041204
OS << "nullptr,";
12051205
else
12061206
OS << "\"" << Record.OverloadedName << "\",";
1207+
OS << "{";
1208+
for (uint32_t Exts : Record.RequiredExtensions)
1209+
OS << Exts << ',';
1210+
OS << "},";
12071211
OS << Record.PrototypeIndex << ",";
12081212
OS << Record.SuffixIndex << ",";
12091213
OS << Record.OverloadedSuffixIndex << ",";
12101214
OS << (int)Record.PrototypeLength << ",";
12111215
OS << (int)Record.SuffixLength << ",";
12121216
OS << (int)Record.OverloadedSuffixSize << ",";
1213-
OS << Record.RequiredExtensions << ",";
12141217
OS << (int)Record.TypeRangeMask << ",";
12151218
OS << (int)Record.Log2LMULMask << ",";
12161219
OS << (int)Record.NF << ",";

clang/utils/TableGen/RISCVVEmitter.cpp

Lines changed: 7 additions & 8 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;
48+
uint32_t RequiredExtensions[(RVV_REQ_NUM + 31) / 32];
4949

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

770770
SR.Log2LMULMask = Log2LMULMask;
771771

772-
SR.RequiredExtensions = 0;
772+
memset(SR.RequiredExtensions, 0, sizeof(SR.RequiredExtensions));
773773
for (auto RequiredFeature : RequiredFeatures) {
774-
RVVRequire RequireExt =
774+
unsigned RequireExt =
775775
StringSwitch<RVVRequire>(RequiredFeature)
776776
.Case("RV64", RVV_REQ_RV64)
777777
.Case("Zvfhmin", RVV_REQ_Zvfhmin)
@@ -792,10 +792,8 @@ void RVVEmitter::createRVVIntrinsics(
792792
.Case("Zvfbfwma", RVV_REQ_Zvfbfwma)
793793
.Case("Zvfbfmin", RVV_REQ_Zvfbfmin)
794794
.Case("Zvfh", RVV_REQ_Zvfh)
795-
.Case("Experimental", RVV_REQ_Experimental)
796-
.Default(RVV_REQ_None);
797-
assert(RequireExt != RVV_REQ_None && "Unrecognized required feature?");
798-
SR.RequiredExtensions |= RequireExt;
795+
.Case("Experimental", RVV_REQ_Experimental);
796+
SR.RequiredExtensions[RequireExt / 32] |= 1U << (RequireExt % 32);
799797
}
800798

801799
SR.NF = NF;
@@ -839,7 +837,8 @@ void RVVEmitter::createRVVIntrinsicRecords(std::vector<RVVIntrinsicRecord> &Out,
839837
R.PrototypeLength = SR.Prototype.size();
840838
R.SuffixLength = SR.Suffix.size();
841839
R.OverloadedSuffixSize = SR.OverloadedSuffix.size();
842-
R.RequiredExtensions = SR.RequiredExtensions;
840+
memcpy(R.RequiredExtensions, SR.RequiredExtensions,
841+
sizeof(R.RequiredExtensions));
843842
R.TypeRangeMask = SR.TypeRangeMask;
844843
R.Log2LMULMask = SR.Log2LMULMask;
845844
R.NF = SR.NF;

0 commit comments

Comments
 (0)