[llvm] [RISCV] Add groupid/bitmask for RISC-V extension (PR #94440)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 21:40:22 PDT 2024
================
@@ -210,10 +211,58 @@ static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
OS << "\n#undef TUNE_PROC\n";
}
+static inline uint64_t getValueFromBitsInit(const BitsInit *B,
+ const Record &R) {
+ assert(B->getNumBits() <= sizeof(uint64_t) * 8 && "BitInits' too long!");
+
+ uint64_t Value = 0;
+ for (unsigned i = 0, e = B->getNumBits(); i != e; ++i) {
+ const auto *Bit = dyn_cast<BitInit>(B->getBit(i));
+ if (Bit)
+ Value |= uint64_t(Bit->getValue()) << i;
+ }
+ return Value;
+}
+
+static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
+
+ std::vector<Record *> Extensions =
+ RK.getAllDerivedDefinitionsIfDefined("RISCVExtensionBitmask");
+ llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
+ return getExtensionName(Rec1) < getExtensionName(Rec2);
+ });
+
+ llvm::DenseSet<std::pair<uint64_t, uint64_t>> Seen;
+
+ OS << "#ifdef GET_RISCVExtensionBitmaskTable_IMPL\n";
+ OS << "static const RISCVExtensionBitmask ExtensionBitmask[]={\n";
+ for (const Record *Rec : Extensions) {
+ BitsInit *GroupIDBits = Rec->getValueAsBitsInit("GroupID");
+ BitsInit *BitmaskBits = Rec->getValueAsBitsInit("Bitmask");
+
+ StringRef ExtName = Rec->getValueAsString("Name");
+ ExtName.consume_front("experimental-");
+ uint64_t GroupIDVal = getValueFromBitsInit(GroupIDBits, *Rec);
+ uint64_t BitmaskVal = getValueFromBitsInit(BitmaskBits, *Rec);
+
+ assert(!Seen.contains(std::make_pair(GroupIDVal, BitmaskVal)) &&
+ "duplicated bitmask");
+ Seen.insert(std::make_pair(GroupIDVal, BitmaskVal));
----------------
topperc wrote:
Use the return value from insert for the assert?
https://github.com/llvm/llvm-project/pull/94440
More information about the llvm-commits
mailing list