diff options
author | Chris Lattner <sabre@nondot.org> | 2004-02-24 06:26:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-02-24 06:26:00 +0000 |
commit | b4a482a098ddb1923b69147b611e95146328ac71 (patch) | |
tree | 0274e8150e92ed9b1950041b970ef64972eb24bd /include/llvm | |
parent | e14ea0804afba2ac5824507571a220d05b0aa21d (diff) | |
download | external_llvm-b4a482a098ddb1923b69147b611e95146328ac71.zip external_llvm-b4a482a098ddb1923b69147b611e95146328ac71.tar.gz external_llvm-b4a482a098ddb1923b69147b611e95146328ac71.tar.bz2 |
Add some helpful methods for dealing with switch instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11794 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/iTerminators.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/llvm/iTerminators.h b/include/llvm/iTerminators.h index b0457f3..3c681a5 100644 --- a/include/llvm/iTerminators.h +++ b/include/llvm/iTerminators.h @@ -178,6 +178,36 @@ public: return cast<BasicBlock>(Operands[1].get()); } + /// getNumCases - return the number of 'cases' in this switch instruction. + /// Note that case #0 is always the default case. + unsigned getNumCases() const { + return Operands.size()/2; + } + + /// getCaseValue - Return the specified case value. Note that case #0, the + /// default destination, does not have a case value. + Constant *getCaseValue(unsigned i) { + assert(i && i < getNumCases() && "Illegal case value to get!"); + return getSuccessorValue(i); + } + + /// getCaseValue - Return the specified case value. Note that case #0, the + /// default destination, does not have a case value. + const Constant *getCaseValue(unsigned i) const { + assert(i && i < getNumCases() && "Illegal case value to get!"); + return getSuccessorValue(i); + } + + /// findCaseValue - Search all of the case values for the specified constant. + /// If it is explicitly handled, return the case number of it, otherwise + /// return 0 to indicate that it is handled by the default handler. + unsigned findCaseValue(const Constant *C) const { + for (unsigned i = 1, e = getNumCases(); i != e; ++i) + if (getCaseValue(i) == C) + return i; + return 0; + } + /// addCase - Add an entry to the switch instruction... /// void addCase(Constant *OnVal, BasicBlock *Dest); |