llvm.org GIT mirror llvm / 6a64c0b
Merge 64124 frm mainline. Turns out AnalyzeBranch can modify the mbb being analyzed. This is a nasty suprise to some callers, e.g. register coalescer. For now, add an parameter that tells AnalyzeBranch whether it's safe to modify the mbb. A better solution is out there, but I don't have time to deal with it right now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_25@64518 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 10 years ago
16 changed file(s) with 60 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
194194 /// Note that RemoveBranch and InsertBranch must be implemented to support
195195 /// cases where this method returns success.
196196 ///
197 /// If AllowModify is true, then this routine is allowed to modify the basic
198 /// block (e.g. delete instructions after the unconditional branch).
199 ///
197200 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
198201 MachineBasicBlock *&FBB,
199 SmallVectorImpl &Cond) const {
202 SmallVectorImpl &Cond,
203 bool AllowModify = false) const {
200204 return true;
201205 }
202206
190190 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; I++) {
191191 MachineBasicBlock *MBB = I, *TBB = 0, *FBB = 0;
192192 SmallVector Cond;
193 if (!TII->AnalyzeBranch(*MBB, TBB, FBB, Cond))
193 if (!TII->AnalyzeBranch(*MBB, TBB, FBB, Cond, true))
194194 EverMadeChange |= MBB->CorrectExtraCFGEdges(TBB, FBB, !Cond.empty());
195195 EverMadeChange |= OptimizeImpDefsBlock(MBB);
196196 }
433433 MachineBasicBlock *TBB = 0, *FBB = 0;
434434 SmallVector Cond;
435435 if (I != MF->end() &&
436 !TII->AnalyzeBranch(*CurMBB, TBB, FBB, Cond)) {
436 !TII->AnalyzeBranch(*CurMBB, TBB, FBB, Cond, true)) {
437437 MachineBasicBlock *NextBB = I;
438438 if (TBB == NextBB && !Cond.empty() && !FBB) {
439439 if (!TII->ReverseBranchCondition(Cond)) {
710710 continue;
711711 MachineBasicBlock *TBB = 0, *FBB = 0;
712712 SmallVector Cond;
713 if (!TII->AnalyzeBranch(*PBB, TBB, FBB, Cond)) {
713 if (!TII->AnalyzeBranch(*PBB, TBB, FBB, Cond, true)) {
714714 // Failing case: IBB is the target of a cbr, and
715715 // we cannot reverse the branch.
716716 SmallVector NewCond(Cond);
844844 bool BranchFolder::CanFallThrough(MachineBasicBlock *CurBB) {
845845 MachineBasicBlock *TBB = 0, *FBB = 0;
846846 SmallVector Cond;
847 bool CurUnAnalyzable = TII->AnalyzeBranch(*CurBB, TBB, FBB, Cond);
847 bool CurUnAnalyzable = TII->AnalyzeBranch(*CurBB, TBB, FBB, Cond, true);
848848 return CanFallThrough(CurBB, CurUnAnalyzable, TBB, FBB, Cond);
849849 }
850850
909909 MachineBasicBlock *PriorTBB = 0, *PriorFBB = 0;
910910 SmallVector PriorCond;
911911 bool PriorUnAnalyzable =
912 TII->AnalyzeBranch(PrevBB, PriorTBB, PriorFBB, PriorCond);
912 TII->AnalyzeBranch(PrevBB, PriorTBB, PriorFBB, PriorCond, true);
913913 if (!PriorUnAnalyzable) {
914914 // If the CFG for the prior block has extra edges, remove them.
915915 MadeChange |= PrevBB.CorrectExtraCFGEdges(PriorTBB, PriorFBB,
10221022 // Analyze the branch in the current block.
10231023 MachineBasicBlock *CurTBB = 0, *CurFBB = 0;
10241024 SmallVector CurCond;
1025 bool CurUnAnalyzable = TII->AnalyzeBranch(*MBB, CurTBB, CurFBB, CurCond);
1025 bool CurUnAnalyzable= TII->AnalyzeBranch(*MBB, CurTBB, CurFBB, CurCond, true);
10261026 if (!CurUnAnalyzable) {
10271027 // If the CFG for the prior block has extra edges, remove them.
10281028 MadeChange |= MBB->CorrectExtraCFGEdges(CurTBB, CurFBB, !CurCond.empty());
337337 // Branch analysis.
338338 bool ARMInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
339339 MachineBasicBlock *&FBB,
340 SmallVectorImpl &Cond) const {
340 SmallVectorImpl &Cond,
341 bool AllowModify) const {
341342 // If the block has no terminators, it just falls into the block after it.
342343 MachineBasicBlock::iterator I = MBB.end();
343344 if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
387388 (LastOpc == ARM::B || LastOpc == ARM::tB)) {
388389 TBB = SecondLastInst->getOperand(0).getMBB();
389390 I = LastInst;
390 I->eraseFromParent();
391 if (AllowModify)
392 I->eraseFromParent();
391393 return false;
392394 }
393395
398400 SecondLastOpc == ARM::BR_JTadd || SecondLastOpc==ARM::tBR_JTr) &&
399401 (LastOpc == ARM::B || LastOpc == ARM::tB)) {
400402 I = LastInst;
401 I->eraseFromParent();
403 if (AllowModify)
404 I->eraseFromParent();
402405 return true;
403406 }
404407
175175 // Branch analysis.
176176 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
177177 MachineBasicBlock *&FBB,
178 SmallVectorImpl &Cond) const;
178 SmallVectorImpl &Cond,
179 bool AllowModify) const;
179180 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
180181 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
181182 MachineBasicBlock *FBB,
320320
321321 // Branch analysis.
322322 bool AlphaInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
323 MachineBasicBlock *&FBB,
324 SmallVectorImpl &Cond) const {
323 MachineBasicBlock *&FBB,
324 SmallVectorImpl &Cond,
325 bool AllowModify) const {
325326 // If the block has no terminators, it just falls into the block after it.
326327 MachineBasicBlock::iterator I = MBB.end();
327328 if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
372373 LastInst->getOpcode() == Alpha::BR) {
373374 TBB = SecondLastInst->getOperand(0).getMBB();
374375 I = LastInst;
375 I->eraseFromParent();
376 if (AllowModify)
377 I->eraseFromParent();
376378 return false;
377379 }
378380
8282
8383 bool AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
8484 MachineBasicBlock *&FBB,
85 SmallVectorImpl &Cond) const;
85 SmallVectorImpl &Cond,
86 bool AllowModify) const;
8687 unsigned RemoveBranch(MachineBasicBlock &MBB) const;
8788 void insertNoop(MachineBasicBlock &MBB,
8889 MachineBasicBlock::iterator MI) const;
531531 bool
532532 SPUInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
533533 MachineBasicBlock *&FBB,
534 SmallVectorImpl &Cond) const {
534 SmallVectorImpl &Cond,
535 bool AllowModify) const {
535536 // If the block has no terminators, it just falls into the block after it.
536537 MachineBasicBlock::iterator I = MBB.end();
537538 if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
582583 if (isUncondBranch(SecondLastInst) && isUncondBranch(LastInst)) {
583584 TBB = SecondLastInst->getOperand(0).getMBB();
584585 I = LastInst;
585 I->eraseFromParent();
586 if (AllowModify)
587 I->eraseFromParent();
586588 return false;
587589 }
588590
103103
104104 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
105105 MachineBasicBlock *&FBB,
106 SmallVectorImpl &Cond) const;
106 SmallVectorImpl &Cond,
107 bool AllowModify) const;
107108
108109 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
109110
452452 bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
453453 MachineBasicBlock *&TBB,
454454 MachineBasicBlock *&FBB,
455 SmallVectorImpl &Cond) const
455 SmallVectorImpl &Cond,
456 bool AllowModify) const
456457 {
457458 // If the block has no terminators, it just falls into the block after it.
458459 MachineBasicBlock::iterator I = MBB.end();
524525 if ((SecondLastOpc == Mips::J) && (LastOpc == Mips::J)) {
525526 TBB = SecondLastInst->getOperand(0).getMBB();
526527 I = LastInst;
527 I->eraseFromParent();
528 if (AllowModify)
529 I->eraseFromParent();
528530 return false;
529531 }
530532
165165 /// Branch Analysis
166166 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
167167 MachineBasicBlock *&FBB,
168 SmallVectorImpl &Cond) const;
168 SmallVectorImpl &Cond,
169 bool AllowModify) const;
169170 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
170171 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
171172 MachineBasicBlock *FBB,
213213 // Branch analysis.
214214 bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
215215 MachineBasicBlock *&FBB,
216 SmallVectorImpl &Cond) const {
216 SmallVectorImpl &Cond,
217 bool AllowModify) const {
217218 // If the block has no terminators, it just falls into the block after it.
218219 MachineBasicBlock::iterator I = MBB.end();
219220 if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
262263 LastInst->getOpcode() == PPC::B) {
263264 TBB = SecondLastInst->getOperand(0).getMBB();
264265 I = LastInst;
265 I->eraseFromParent();
266 if (AllowModify)
267 I->eraseFromParent();
266268 return false;
267269 }
268270
107107 // Branch analysis.
108108 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
109109 MachineBasicBlock *&FBB,
110 SmallVectorImpl &Cond) const;
110 SmallVectorImpl &Cond,
111 bool AllowModify) const;
111112 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
112113 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
113114 MachineBasicBlock *FBB,
14871487 bool X86InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
14881488 MachineBasicBlock *&TBB,
14891489 MachineBasicBlock *&FBB,
1490 SmallVectorImpl &Cond) const {
1490 SmallVectorImpl &Cond,
1491 bool AllowModify) const {
14911492 // Start from the bottom of the block and work up, examining the
14921493 // terminator instructions.
14931494 MachineBasicBlock::iterator I = MBB.end();
15031504 return true;
15041505 // Handle unconditional branches.
15051506 if (I->getOpcode() == X86::JMP) {
1507 if (!AllowModify) {
1508 TBB = I->getOperand(0).getMBB();
1509 return false;
1510 }
1511
15061512 // If the block has any instructions after a JMP, delete them.
15071513 while (next(I) != MBB.end())
15081514 next(I)->eraseFromParent();
322322 virtual bool isUnpredicatedTerminator(const MachineInstr* MI) const;
323323 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
324324 MachineBasicBlock *&FBB,
325 SmallVectorImpl &Cond) const;
325 SmallVectorImpl &Cond,
326 bool AllowModify) const;
326327 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
327328 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
328329 MachineBasicBlock *FBB,
227227 ///
228228 bool
229229 XCoreInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
230 MachineBasicBlock *&FBB,
231 SmallVectorImpl &Cond) const {
230 MachineBasicBlock *&FBB,
231 SmallVectorImpl &Cond,
232 bool AllowModify) const {
232233 // If the block has no terminators, it just falls into the block after it.
233234 MachineBasicBlock::iterator I = MBB.end();
234235 if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
287288 IsBRU(LastInst->getOpcode())) {
288289 TBB = SecondLastInst->getOperand(0).getMBB();
289290 I = LastInst;
290 I->eraseFromParent();
291 if (AllowModify)
292 I->eraseFromParent();
291293 return false;
292294 }
293295
5555
5656 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
5757 MachineBasicBlock *&FBB,
58 SmallVectorImpl &Cond) const;
58 SmallVectorImpl &Cond,
59 bool AllowModify) const;
5960
6061 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
6162 MachineBasicBlock *FBB,