[llvm] [GISel][TableGen] Generate getRegBankFromRegClass (PR #99896)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 08:09:07 PDT 2024
================
@@ -287,8 +291,94 @@ void RegisterBankEmitter::emitBaseClassImplementation(
<< " for (auto RB : enumerate(RegBanks))\n"
<< " assert(RB.index() == RB.value()->getID() && \"Index != ID\");\n"
<< "#endif // NDEBUG\n"
- << "}\n"
- << "} // end namespace llvm\n";
+ << "}\n";
+
+ uint32_t NumRegBanks = Banks.size();
+ uint32_t BitSize = NextPowerOf2(Log2_32(NumRegBanks));
+ uint32_t ElemsPerWord = 32 / BitSize;
+ uint32_t BitMask = (1 << BitSize) - 1;
+ bool HasAmbigousOrMissingEntry = false;
+ struct Entry {
+ std::string RCIdName;
+ std::string RBIdName;
+ };
+ SmallVector<Entry, 0> Entries;
+ for (const auto &Bank : Banks) {
+ for (const auto *RC : Bank.register_classes()) {
+ if (RC->EnumValue >= Entries.size())
+ Entries.resize(RC->EnumValue + 1);
+ Entry &E = Entries[RC->EnumValue];
+ E.RCIdName = RC->getIdName();
+ if (!E.RBIdName.empty()) {
+ HasAmbigousOrMissingEntry = true;
+ E.RBIdName = "InvalidRegBankID";
+ } else {
+ E.RBIdName = (TargetName + "::" + Bank.getEnumeratorName()).str();
+ }
+ }
+ }
+ for (auto &E : Entries) {
+ if (E.RBIdName.empty()) {
+ HasAmbigousOrMissingEntry = true;
+ E.RBIdName = "InvalidRegBankID";
+ }
+ }
+ OS << "const RegisterBank &\n"
+ << TargetName
+ << "GenRegisterBankInfo::getRegBankFromRegClass"
+ "(const TargetRegisterClass &RC, LLT) const {\n";
+ if (HasAmbigousOrMissingEntry) {
+ OS << " constexpr uint32_t InvalidRegBankID = uint32_t("
+ << TargetName + "::InvalidRegBankID) & " << BitMask << ";\n";
+ }
+ unsigned TableSize =
+ Entries.size() / ElemsPerWord + ((Entries.size() % ElemsPerWord) > 0);
----------------
topperc wrote:
use divideCeil?
https://github.com/llvm/llvm-project/pull/99896
More information about the llvm-commits
mailing list