diff --git a/include/llvm/CodeGen/MachineJumpTableInfo.h b/include/llvm/CodeGen/MachineJumpTableInfo.h index b8d04bf2132..85d38ba01c5 100644 --- a/include/llvm/CodeGen/MachineJumpTableInfo.h +++ b/include/llvm/CodeGen/MachineJumpTableInfo.h @@ -83,7 +83,11 @@ public: /// getEntryAlignment - Return the alignment of each entry in the jump table. unsigned getEntryAlignment(const TargetData &TD) const; - /// getJumpTableIndex - Create a new jump table or return an existing one. + /// createJumpTableIndex - Create a new jump table. + /// + unsigned createJumpTableIndex(const std::vector &DestBBs); + + /// getJumpTableIndex - Return the index for an existing jump table. /// unsigned getJumpTableIndex(const std::vector &DestBBs); diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 37f3d22630d..254b5e7c7be 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -600,16 +600,25 @@ unsigned MachineJumpTableInfo::getEntryAlignment(const TargetData &TD) const { return ~0; } -/// getJumpTableIndex - Create a new jump table entry in the jump table info -/// or return an existing one. +/// createJumpTableIndex - Create a new jump table entry in the jump table info. /// -unsigned MachineJumpTableInfo::getJumpTableIndex( +unsigned MachineJumpTableInfo::createJumpTableIndex( const std::vector &DestBBs) { assert(!DestBBs.empty() && "Cannot create an empty jump table!"); JumpTables.push_back(MachineJumpTableEntry(DestBBs)); return JumpTables.size()-1; } +/// getJumpTableIndex - Return the index for an existing jump table entry in +/// the jump table info. +unsigned MachineJumpTableInfo::getJumpTableIndex( + const std::vector &DestBBs) { + for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) + if (JumpTables[i].MBBs == DestBBs) + return i; + assert(false && "getJumpTableIndex failed to find matching table"); + return ~0; +} /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update /// the jump tables to branch to New instead. diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 4c2cd72d213..12096b9a68b 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1675,11 +1675,10 @@ bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec& CR, } } - // Create a jump table index for this jump table, or return an existing - // one. + // Create a jump table index for this jump table. unsigned JTEncoding = TLI.getJumpTableEncoding(); unsigned JTI = CurMF->getOrCreateJumpTableInfo(JTEncoding) - ->getJumpTableIndex(DestBBs); + ->createJumpTableIndex(DestBBs); // Set the jump table information so that we can codegen it as a second // MachineBasicBlock