From ccd682c69543bfdb0db692daf54cdd2cb14aa487 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 11 Sep 2012 23:32:17 +0000 Subject: [PATCH] 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. llvm-svn: 163659 --- llvm/utils/TableGen/CodeGenRegisters.cpp | 6 ++++++ llvm/utils/TableGen/CodeGenRegisters.h | 4 ++++ llvm/utils/TableGen/CodeGenTarget.cpp | 11 +++++------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp index 931807ae44ba..f195b4e3fa98 100644 --- a/llvm/utils/TableGen/CodeGenRegisters.cpp +++ b/llvm/utils/TableGen/CodeGenRegisters.cpp @@ -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) diff --git a/llvm/utils/TableGen/CodeGenRegisters.h b/llvm/utils/TableGen/CodeGenRegisters.h index bd748ca62e12..e41107415612 100644 --- a/llvm/utils/TableGen/CodeGenRegisters.h +++ b/llvm/utils/TableGen/CodeGenRegisters.h @@ -440,6 +440,7 @@ namespace llvm { // Registers. std::vector Registers; + StringMap RegistersByName; DenseMap Def2Reg; unsigned NumNativeRegUnits; @@ -522,6 +523,9 @@ namespace llvm { } const std::vector &getRegisters() { return Registers; } + const StringMap &getRegistersByName() { + return RegistersByName; + } // Find a register from its Record def. CodeGenRegister *getReg(Record*); diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp index fa31c9fb1ba0..6335cc5c4c5f 100644 --- a/llvm/utils/TableGen/CodeGenTarget.cpp +++ b/llvm/utils/TableGen/CodeGenTarget.cpp @@ -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 &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 &Regs = getRegBank().getRegistersByName(); + StringMap::const_iterator I = Regs.find(Name); + if (I == Regs.end()) + return 0; + return I->second; } std::vector CodeGenTarget::