From 16bdd01e87f040d26c6df7de7901574d888a8053 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 29 Feb 2012 23:46:50 +0000 Subject: [PATCH] Implement getSubRegIndex as a linear search on the SubRegTable instead of using a big switch. - The search bounds are constant, in the worst case (ARM target) it will scan over 30 uint16_ts. - This method isn't very hot, I had problems finding a testcase where it's called more than a dozen of times (no perf impact). llvm-svn: 151773 --- utils/TableGen/RegisterInfoEmitter.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp index 899f5523e21..5528777a232 100644 --- a/utils/TableGen/RegisterInfoEmitter.cpp +++ b/utils/TableGen/RegisterInfoEmitter.cpp @@ -774,21 +774,13 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target, OS << " return 0;\n}\n\n"; OS << "unsigned " << ClassName - << "::getSubRegIndex(unsigned RegNo, unsigned SubRegNo) const {\n" - << " switch (RegNo) {\n" - << " default:\n return 0;\n"; - for (unsigned i = 0, e = Regs.size(); i != e; ++i) { - const CodeGenRegister::SubRegMap &SRM = Regs[i]->getSubRegs(); - if (SRM.empty()) - continue; - OS << " case " << getQualifiedName(Regs[i]->TheDef) << ":\n"; - for (CodeGenRegister::SubRegMap::const_iterator ii = SRM.begin(), - ie = SRM.end(); ii != ie; ++ii) - OS << " if (SubRegNo == " << getQualifiedName(ii->second->TheDef) - << ") return " << ii->first->getQualifiedName() << ";\n"; - OS << " return 0;\n"; + << "::getSubRegIndex(unsigned RegNo, unsigned SubRegNo) const {\n"; + if (SubRegIndices.size()) { + OS << " for (unsigned I = 0; I != array_lengthof(" + << TargetName << "SubRegTable[0]); ++I)\n" + << " if (" << TargetName << "SubRegTable[RegNo - 1][I] == SubRegNo)\n" + << " return I + 1;\n"; } - OS << " };\n"; OS << " return 0;\n"; OS << "}\n\n";