Compute a map from register names to registers, rather than scanning the list of registers every time we want to look up a register by name.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163659 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2012-09-11 23:32:17 +00:00
parent 2a3fcb382e
commit d2c699706c
3 changed files with 15 additions and 6 deletions

View File

@ -993,6 +993,12 @@ CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) {
for (unsigned i = 0, e = Registers.size(); i != e; ++i)
Registers[i]->buildObjectGraph(*this);
// Compute register name map.
for (unsigned i = 0, e = Registers.size(); i != e; ++i)
RegistersByName.GetOrCreateValue(
Registers[i]->TheDef->getValueAsString("AsmName"),
Registers[i]);
// Precompute all sub-register maps.
// This will create Composite entries for all inferred sub-register indices.
for (unsigned i = 0, e = Registers.size(); i != e; ++i)

View File

@ -440,6 +440,7 @@ namespace llvm {
// Registers.
std::vector<CodeGenRegister*> Registers;
StringMap<CodeGenRegister*> RegistersByName;
DenseMap<Record*, CodeGenRegister*> Def2Reg;
unsigned NumNativeRegUnits;
@ -522,6 +523,9 @@ namespace llvm {
}
const std::vector<CodeGenRegister*> &getRegisters() { return Registers; }
const StringMap<CodeGenRegister*> &getRegistersByName() {
return RegistersByName;
}
// Find a register from its Record def.
CodeGenRegister *getReg(Record*);

View File

@ -199,12 +199,11 @@ void CodeGenTarget::ReadRegAltNameIndices() const {
/// getRegisterByName - If there is a register with the specific AsmName,
/// return it.
const CodeGenRegister *CodeGenTarget::getRegisterByName(StringRef Name) const {
const std::vector<CodeGenRegister*> &Regs = getRegBank().getRegisters();
for (unsigned i = 0, e = Regs.size(); i != e; ++i)
if (Regs[i]->TheDef->getValueAsString("AsmName") == Name)
return Regs[i];
return 0;
const StringMap<CodeGenRegister*> &Regs = getRegBank().getRegistersByName();
StringMap<CodeGenRegister*>::const_iterator I = Regs.find(Name);
if (I == Regs.end())
return 0;
return I->second;
}
std::vector<MVT::SimpleValueType> CodeGenTarget::