[llvm-commits] [llvm] r151773 - /llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp
Benjamin Kramer
benny.kra at googlemail.com
Wed Feb 29 15:46:50 PST 2012
Author: d0k
Date: Wed Feb 29 17:46:50 2012
New Revision: 151773
URL: http://llvm.org/viewvc/llvm-project?rev=151773&view=rev
Log:
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).
Modified:
llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp
Modified: llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp?rev=151773&r1=151772&r2=151773&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp Wed Feb 29 17:46:50 2012
@@ -774,21 +774,13 @@
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";
More information about the llvm-commits
mailing list