24#define DEBUG_TYPE "CopyHoist"
59 void collectCopyInst();
68 std::vector<DenseMap<std::pair<Register, Register>,
MachineInstr *>>
74char HexagonCopyHoisting::ID = 0;
101 if (BB->pred_size() != 1)
103 auto &BBCopyInst = CopyMIList[BB->getNumber()];
104 if (BBCopyInst.size() > 0)
105 Changed |= analyzeCopy(*BB->pred_begin());
110 LiveIntervals &LIS = getAnalysis<LiveIntervalsWrapperPass>().getLIS();
121void HexagonCopyHoisting::collectCopyInst() {
124 auto &BBCopyInst = CopyMIList[BB.getNumber()];
129 if (
MI.getOpcode() == TargetOpcode::COPY)
130 addMItoCopyList(&
MI);
132 LLVM_DEBUG(
dbgs() <<
"\tNumber of copies: " << BBCopyInst.size() <<
"\n");
137 unsigned BBNum =
MI->getParent()->getNumber();
138 auto &BBCopyInst = CopyMIList[BBNum];
144 MRI->getRegClass(DstReg) != &Hexagon::IntRegsRegClass ||
145 MRI->getRegClass(SrcReg) != &Hexagon::IntRegsRegClass)
148 BBCopyInst.insert(std::pair(std::pair(SrcReg, DstReg),
MI));
151 for (
auto II : BBCopyInst) {
165 bool Changed =
false;
170 if (SB->pred_size() != 1 || SB->isEHPad() || SB->hasAddressTaken())
175 auto &BBCopyInst1 = CopyMIList[SBB1->
getNumber()];
177 for (
auto II : BBCopyInst1) {
178 std::pair<Register, Register>
Key =
II.getFirst();
180 bool IsSafetoMove =
true;
182 auto &SuccBBCopyInst = CopyMIList[SuccBB->getNumber()];
183 if (!SuccBBCopyInst.count(Key)) {
185 IsSafetoMove =
false;
191 if (!isSafetoMove(SuccMI)) {
192 IsSafetoMove =
false;
201 moveCopyInstr(BB, Key,
MI);
208 auto &BBCopyInst = CopyMIList[BB->
getNumber()];
209 for (
auto II : BBCopyInst) {
217bool HexagonCopyHoisting::isSafetoMove(
MachineInstr *CandMI) {
227 for (MII = BB->
begin(), MIE = CandMI; MII != MIE; ++MII) {
230 if (Mo.isReg() && Mo.getReg() == DefR)
234 for (MII = BB->
begin(), MIE = CandMI; MII != MIE; ++MII) {
237 if (Mo.isReg() && Mo.isDef() && Mo.getReg() == UseR)
244 std::pair<Register, Register> Key,
253 auto &BBCopyInst = CopyMIList[SuccBB->getNumber()];
256 BBCopyInst.erase(Key);
265 "Hexagon move phi copy",
false,
false)
268 return new HexagonCopyHoisting();
unsigned const MachineRegisterInfo * MRI
This file defines the DenseMap class.
static cl::opt< std::string > CPHoistFn("cphoistfn", cl::Hidden, cl::desc(""), cl::init(""))
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
FunctionPass class - This class is used to implement most global optimizations.
SlotIndexes * getSlotIndexes() const
void reanalyze(MachineFunction &MF)
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
succ_iterator succ_begin()
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
unsigned succ_size() const
iterator_range< succ_iterator > successors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
Analysis pass which computes a MachineDominatorTree.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
iterator_range< mop_iterator > operands()
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
static constexpr bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
A global registry used in conjunction with static constructors to make pluggable components (like tar...
StringRef - Represent a constant reference to a string, i.e.
StringRef getName() const
Return a constant reference to the value's name.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
FunctionPass * createHexagonCopyHoisting()
iterator_range< po_iterator< T > > post_order(const T &G)
void initializeHexagonCopyHoistingPass(PassRegistry &Registry)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
char & HexagonCopyHoistingID