llvm.org GIT mirror llvm / 52ce29d
Merge 98977 from mainline. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_27@99292 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 10 years ago
3 changed file(s) with 6 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
8282 ///
8383 unsigned createJumpTableIndex(const std::vector &DestBBs);
8484
85 /// getJumpTableIndex - Return the index for an existing jump table.
86 ///
87 unsigned getJumpTableIndex(const std::vector &DestBBs);
88
8985 /// isEmpty - Return true if there are no jump tables.
9086 ///
9187 bool isEmpty() const { return JumpTables.empty(); }
202202 MadeChange |= MadeChangeThisIteration;
203203 }
204204
205 // See if any jump tables have become mergable or dead as the code generator
205 // See if any jump tables have become dead as the code generator
206206 // did its thing.
207207 MachineJumpTableInfo *JTI = MF.getJumpTableInfo();
208208 if (JTI == 0) {
210210 return MadeChange;
211211 }
212212
213 const std::vector &JTs = JTI->getJumpTables();
214 // Figure out how these jump tables should be merged.
215 std::vector JTMapping;
216 JTMapping.reserve(JTs.size());
217
218 // We always keep the 0th jump table.
219 JTMapping.push_back(0);
220
221 // Scan the jump tables, seeing if there are any duplicates. Note that this
222 // is N^2, which should be fixed someday.
223 for (unsigned i = 1, e = JTs.size(); i != e; ++i) {
224 if (JTs[i].MBBs.empty())
225 JTMapping.push_back(i);
226 else
227 JTMapping.push_back(JTI->getJumpTableIndex(JTs[i].MBBs));
228 }
229
230 // If a jump table was merge with another one, walk the function rewriting
231 // references to jump tables to reference the new JT ID's. Keep track of
232 // whether we see a jump table idx, if not, we can delete the JT.
233 BitVector JTIsLive(JTs.size());
213 // Walk the function to find jump tables that are live.
214 BitVector JTIsLive(JTI->getJumpTables().size());
234215 for (MachineFunction::iterator BB = MF.begin(), E = MF.end();
235216 BB != E; ++BB) {
236217 for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end();
238219 for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op) {
239220 MachineOperand &Op = I->getOperand(op);
240221 if (!Op.isJTI()) continue;
241 unsigned NewIdx = JTMapping[Op.getIndex()];
242 Op.setIndex(NewIdx);
243222
244223 // Remember that this JT is live.
245 JTIsLive.set(NewIdx);
224 JTIsLive.set(Op.getIndex());
246225 }
247226 }
248227
249 // Finally, remove dead jump tables. This happens either because the
250 // indirect jump was unreachable (and thus deleted) or because the jump
251 // table was merged with some other one.
228 // Finally, remove dead jump tables. This happens when the
229 // indirect jump was unreachable (and thus deleted).
252230 for (unsigned i = 0, e = JTIsLive.size(); i != e; ++i)
253231 if (!JTIsLive.test(i)) {
254232 JTI->RemoveJumpTable(i);
602602 return JumpTables.size()-1;
603603 }
604604
605 /// getJumpTableIndex - Return the index for an existing jump table entry in
606 /// the jump table info.
607 unsigned MachineJumpTableInfo::getJumpTableIndex(
608 const std::vector &DestBBs) {
609 for (unsigned i = 0, e = JumpTables.size(); i != e; ++i)
610 if (JumpTables[i].MBBs == DestBBs)
611 return i;
612 assert(false && "getJumpTableIndex failed to find matching table");
613 return ~0;
614 }
615
616605 /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
617606 /// the jump tables to branch to New instead.
618607 bool MachineJumpTableInfo::ReplaceMBBInJumpTables(MachineBasicBlock *Old,