31 #define DEBUG_TYPE "codegen-cp"
33 STATISTIC(NumDeletes,
"Number of dead copies deleted");
53 void SourceNoLongerAvailable(
unsigned Reg,
63 "Machine Copy Propagation Pass",
false,
false)
66 MachineCopyPropagation::SourceNoLongerAvailable(
unsigned Reg,
70 SourceMap::iterator
SI = SrcMap.find(*AI);
71 if (SI != SrcMap.end()) {
72 const DestList& Defs = SI->second;
73 for (DestList::const_iterator
I = Defs.begin(), E = Defs.end();
75 unsigned MappedDef = *
I;
77 AvailCopyMap.erase(MappedDef);
79 AvailCopyMap.erase(*SR);
95 while (I != E && I != E2) {
96 if (I->hasUnmodeledSideEffects() || I->isCall() ||
137 bool Changed =
false;
149 " register allocation!");
152 if (CI != AvailCopyMap.
end()) {
154 if (!MRI->isReserved(Def) &&
171 DEBUG(
dbgs() <<
"MCP: copy is a NOP, removing: "; MI->
dump());
176 I->clearRegisterKills(Def, TRI);
187 CI = CopyMap.
find(*AI);
188 if (CI != CopyMap.
end()) {
189 DEBUG(
dbgs() <<
"MCP: Copy is no longer dead: "; CI->second->dump());
190 MaybeDeadCopies.
remove(CI->second);
194 DEBUG(
dbgs() <<
"MCP: Copy is a deletion candidate: "; MI->
dump());
197 MaybeDeadCopies.
insert(MI);
206 SourceNoLongerAvailable(Def, SrcMap, AvailCopyMap);
212 AvailCopyMap.
erase(*AI);
217 AvailCopyMap[*SR] =
MI;
222 if (std::find(SrcMap[Src].
begin(), SrcMap[Src].
end(), Def) ==
224 SrcMap[Src].push_back(Def);
232 int RegMaskOpNum = -1;
245 " register allocation!");
256 if (CI != CopyMap.
end()) {
257 DEBUG(
dbgs() <<
"MCP: Copy is used - not dead: "; CI->second->dump());
258 MaybeDeadCopies.
remove(CI->second);
275 if (RegMaskOpNum >= 0) {
279 DI = MaybeDeadCopies.
begin(), DE = MaybeDeadCopies.
end();
281 unsigned Reg = (*DI)->getOperand(0).getReg();
284 DEBUG(
dbgs() <<
"MCP: Removing copy due to regmask clobbering: ";
286 (*DI)->eraseFromParent();
292 MaybeDeadCopies.
clear();
293 AvailCopyMap.
clear();
299 for (
unsigned i = 0, e = Defs.
size(); i != e; ++i) {
300 unsigned Reg = Defs[i];
305 AvailCopyMap.
erase(*AI);
310 SourceNoLongerAvailable(Reg, SrcMap, AvailCopyMap);
319 DI = MaybeDeadCopies.
begin(), DE = MaybeDeadCopies.
end();
321 if (!MRI->isReserved((*DI)->getOperand(0).getReg())) {
322 (*DI)->eraseFromParent();
332 bool MachineCopyPropagation::runOnMachineFunction(
MachineFunction &MF) {
336 bool Changed =
false;
343 Changed |= CopyPropagateBlock(*
I);
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
static bool NoInterveningSideEffect(const MachineInstr *CopyMI, const MachineInstr *MI)
static bool isNopCopy(MachineInstr *CopyMI, unsigned Def, unsigned Src, const TargetRegisterInfo *TRI)
isNopCopy - Return true if the specified copy is really a nop.
static bool isVirtualRegister(unsigned Reg)
isVirtualRegister - Return true if the specified register number is in the virtual register namespace...
const_iterator begin(StringRef path)
Get begin iterator over path.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
bool isSubRegister(unsigned RegA, unsigned RegB) const
Returns true if RegB is a sub-register of RegA.
iterator end()
Get an iterator to the end of the SetVector.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
unsigned getSubRegIndex(unsigned RegNo, unsigned SubRegNo) const
For a given register pair, return the sub-register index if the second register is a sub-register of ...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Reg
All possible values of the reg field in the ModR/M byte.
bool remove(const value_type &X)
Remove an item from the set vector.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
bool insert(const value_type &X)
Insert a new element into the SetVector.
iterator begin()
Get an iterator to the beginning of the SetVector.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
bool erase(const KeyT &Val)
const MachineOperand & getOperand(unsigned i) const
MCRegAliasIterator enumerates all registers aliasing Reg.
char & MachineCopyPropagationID
MachineCopyPropagation - This pass performs copy propagation on machine instructions.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSubRegIterator enumerates all sub-registers of Reg.
void initializeMachineCopyPropagationPass(PassRegistry &)
INITIALIZE_PASS(MachineCopyPropagation,"machine-cp","Machine Copy Propagation Pass", false, false) void MachineCopyPropagation
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
A SetVector that performs no allocations if smaller than a certain size.
MachineOperand class - Representation of each machine instruction operand.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool clobbersPhysReg(const uint32_t *RegMask, unsigned PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
void clear()
Completely clear the SetVector.
StringRef getName() const
getName - Return the name of the corresponding LLVM basic block, or "(null)".
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
iterator find(const KeyT &Val)
unsigned getReg() const
getReg - Returns the register number.
virtual const TargetInstrInfo * getInstrInfo() const
BasicBlockListType::iterator iterator
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.