From 79b3cddfa2eeb9ed7f93daf8e4f3c3d87779c3ab Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 1 Nov 2010 03:19:09 +0000 Subject: [PATCH] avoid needless throw/catch/rethrow, stringref'ize some simple stuff. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117892 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/AsmMatcherEmitter.cpp | 7 ++----- utils/TableGen/CodeGenInstruction.cpp | 6 +++--- utils/TableGen/CodeGenInstruction.h | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp index 37a8c8f79bb..3f4594c4e3e 100644 --- a/utils/TableGen/AsmMatcherEmitter.cpp +++ b/utils/TableGen/AsmMatcherEmitter.cpp @@ -945,7 +945,7 @@ void AsmMatcherInfo::BuildInfo() { Instructions.push_back(II.take()); } - + // Build info for the register classes. BuildRegisterClasses(SingletonRegisters); @@ -998,12 +998,9 @@ void AsmMatcherInfo::BuildInfo() { // Map this token to an operand. FIXME: Move elsewhere. unsigned Idx; - try { - Idx = II->Instr->getOperandNamed(OperandName); - } catch(...) { + if (!II->Instr->hasOperandNamed(OperandName, Idx)) throw std::string("error: unable to find operand: '" + OperandName.str() + "'"); - } // FIXME: This is annoying, the named operand may be tied (e.g., // XCHG8rm). What we want is the untied operand, which we now have to diff --git a/utils/TableGen/CodeGenInstruction.cpp b/utils/TableGen/CodeGenInstruction.cpp index 41a27cea3dd..259e7c36a4c 100644 --- a/utils/TableGen/CodeGenInstruction.cpp +++ b/utils/TableGen/CodeGenInstruction.cpp @@ -237,17 +237,17 @@ CodeGenInstruction::CodeGenInstruction(Record *R) : TheDef(R) { /// non-empty name. If the instruction does not have an operand with the /// specified name, throw an exception. /// -unsigned CodeGenInstruction::getOperandNamed(const std::string &Name) const { +unsigned CodeGenInstruction::getOperandNamed(StringRef Name) const { unsigned OpIdx; if (hasOperandNamed(Name, OpIdx)) return OpIdx; throw "Instruction '" + TheDef->getName() + - "' does not have an operand named '$" + Name + "'!"; + "' does not have an operand named '$" + Name.str() + "'!"; } /// hasOperandNamed - Query whether the instruction has an operand of the /// given name. If so, return true and set OpIdx to the index of the /// operand. Otherwise, return false. -bool CodeGenInstruction::hasOperandNamed(const std::string &Name, +bool CodeGenInstruction::hasOperandNamed(StringRef Name, unsigned &OpIdx) const { assert(!Name.empty() && "Cannot search for operand with no name!"); for (unsigned i = 0, e = OperandList.size(); i != e; ++i) diff --git a/utils/TableGen/CodeGenInstruction.h b/utils/TableGen/CodeGenInstruction.h index 33701ec0110..7f9d24925cc 100644 --- a/utils/TableGen/CodeGenInstruction.h +++ b/utils/TableGen/CodeGenInstruction.h @@ -190,12 +190,12 @@ namespace llvm { /// getOperandNamed - Return the index of the operand with the specified /// non-empty name. If the instruction does not have an operand with the /// specified name, throw an exception. - unsigned getOperandNamed(const std::string &Name) const; + unsigned getOperandNamed(StringRef Name) const; /// hasOperandNamed - Query whether the instruction has an operand of the /// given name. If so, return true and set OpIdx to the index of the /// operand. Otherwise, return false. - bool hasOperandNamed(const std::string &Name, unsigned &OpIdx) const; + bool hasOperandNamed(StringRef Name, unsigned &OpIdx) const; /// HasOneImplicitDefWithKnownVT - If the instruction has at least one /// implicit def and it has a known VT, return the VT, otherwise return