Deleted Added
full compact
TailDuplication.cpp (208954) TailDuplication.cpp (210299)
1//===-- TailDuplication.cpp - Duplicate blocks into predecessors' tails ---===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass duplicates basic blocks ending in unconditional branches into
11// the tails of their predecessors.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "tailduplication"
16#include "llvm/Function.h"
17#include "llvm/CodeGen/Passes.h"
18#include "llvm/CodeGen/MachineModuleInfo.h"
19#include "llvm/CodeGen/MachineFunctionPass.h"
1//===-- TailDuplication.cpp - Duplicate blocks into predecessors' tails ---===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass duplicates basic blocks ending in unconditional branches into
11// the tails of their predecessors.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "tailduplication"
16#include "llvm/Function.h"
17#include "llvm/CodeGen/Passes.h"
18#include "llvm/CodeGen/MachineModuleInfo.h"
19#include "llvm/CodeGen/MachineFunctionPass.h"
20#include "llvm/CodeGen/MachineInstrBuilder.h"
20#include "llvm/CodeGen/MachineRegisterInfo.h"
21#include "llvm/CodeGen/MachineSSAUpdater.h"
22#include "llvm/Target/TargetInstrInfo.h"
23#include "llvm/Support/CommandLine.h"
24#include "llvm/Support/Debug.h"
25#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/raw_ostream.h"
27#include "llvm/ADT/SmallSet.h"

--- 526 unchanged lines hidden (view full) ---

554 } else {
555 // Replace def of virtual registers with new registers, and update
556 // uses with PHI source register or the new registers.
557 DuplicateInstruction(MI, TailBB, PredBB, MF, LocalVRMap);
558 }
559 }
560 MachineBasicBlock::iterator Loc = PredBB->getFirstTerminator();
561 for (unsigned i = 0, e = CopyInfos.size(); i != e; ++i) {
21#include "llvm/CodeGen/MachineRegisterInfo.h"
22#include "llvm/CodeGen/MachineSSAUpdater.h"
23#include "llvm/Target/TargetInstrInfo.h"
24#include "llvm/Support/CommandLine.h"
25#include "llvm/Support/Debug.h"
26#include "llvm/Support/ErrorHandling.h"
27#include "llvm/Support/raw_ostream.h"
28#include "llvm/ADT/SmallSet.h"

--- 526 unchanged lines hidden (view full) ---

555 } else {
556 // Replace def of virtual registers with new registers, and update
557 // uses with PHI source register or the new registers.
558 DuplicateInstruction(MI, TailBB, PredBB, MF, LocalVRMap);
559 }
560 }
561 MachineBasicBlock::iterator Loc = PredBB->getFirstTerminator();
562 for (unsigned i = 0, e = CopyInfos.size(); i != e; ++i) {
562 const TargetRegisterClass *RC = MRI->getRegClass(CopyInfos[i].first);
563 TII->copyRegToReg(*PredBB, Loc, CopyInfos[i].first,
564 CopyInfos[i].second, RC,RC, DebugLoc());
565 MachineInstr *CopyMI = prior(Loc);
566 Copies.push_back(CopyMI);
563 Copies.push_back(BuildMI(*PredBB, Loc, DebugLoc(),
564 TII->get(TargetOpcode::COPY),
565 CopyInfos[i].first).addReg(CopyInfos[i].second));
567 }
568 NumInstrDups += TailBB->size() - 1; // subtract one for removed branch
569
570 // Update the CFG.
571 PredBB->removeSuccessor(PredBB->succ_begin());
572 assert(PredBB->succ_empty() &&
573 "TailDuplicate called on block with multiple successors!");
574 for (MachineBasicBlock::succ_iterator I = TailBB->succ_begin(),

--- 38 unchanged lines hidden (view full) ---

613 // Replace def of virtual registers with new registers, and update
614 // uses with PHI source register or the new registers.
615 MachineInstr *MI = &*I++;
616 DuplicateInstruction(MI, TailBB, PrevBB, MF, LocalVRMap);
617 MI->eraseFromParent();
618 }
619 MachineBasicBlock::iterator Loc = PrevBB->getFirstTerminator();
620 for (unsigned i = 0, e = CopyInfos.size(); i != e; ++i) {
566 }
567 NumInstrDups += TailBB->size() - 1; // subtract one for removed branch
568
569 // Update the CFG.
570 PredBB->removeSuccessor(PredBB->succ_begin());
571 assert(PredBB->succ_empty() &&
572 "TailDuplicate called on block with multiple successors!");
573 for (MachineBasicBlock::succ_iterator I = TailBB->succ_begin(),

--- 38 unchanged lines hidden (view full) ---

612 // Replace def of virtual registers with new registers, and update
613 // uses with PHI source register or the new registers.
614 MachineInstr *MI = &*I++;
615 DuplicateInstruction(MI, TailBB, PrevBB, MF, LocalVRMap);
616 MI->eraseFromParent();
617 }
618 MachineBasicBlock::iterator Loc = PrevBB->getFirstTerminator();
619 for (unsigned i = 0, e = CopyInfos.size(); i != e; ++i) {
621 const TargetRegisterClass *RC = MRI->getRegClass(CopyInfos[i].first);
622 TII->copyRegToReg(*PrevBB, Loc, CopyInfos[i].first,
623 CopyInfos[i].second, RC, RC, DebugLoc());
624 MachineInstr *CopyMI = prior(Loc);
625 Copies.push_back(CopyMI);
620 Copies.push_back(BuildMI(*PrevBB, Loc, DebugLoc(),
621 TII->get(TargetOpcode::COPY),
622 CopyInfos[i].first)
623 .addReg(CopyInfos[i].second));
626 }
627 } else {
628 // No PHIs to worry about, just splice the instructions over.
629 PrevBB->splice(PrevBB->end(), TailBB, TailBB->begin(), TailBB->end());
630 }
631 PrevBB->removeSuccessor(PrevBB->succ_begin());
632 assert(PrevBB->succ_empty());
633 PrevBB->transferSuccessors(TailBB);

--- 21 unchanged lines hidden ---
624 }
625 } else {
626 // No PHIs to worry about, just splice the instructions over.
627 PrevBB->splice(PrevBB->end(), TailBB, TailBB->begin(), TailBB->end());
628 }
629 PrevBB->removeSuccessor(PrevBB->succ_begin());
630 assert(PrevBB->succ_empty());
631 PrevBB->transferSuccessors(TailBB);

--- 21 unchanged lines hidden ---