39 unsigned Opc =
MI->getOpcode();
41 case TargetOpcode::COPY: {
44 RegisterRef DstR = DFG.makeRegRef(Dst.getReg(), Dst.getSubReg());
45 RegisterRef SrcR = DFG.makeRegRef(Src.getReg(), Src.getSubReg());
49 if (
TRI.getMinimalPhysRegClass(DstR.
Reg) !=
50 TRI.getMinimalPhysRegClass(SrcR.
Reg))
52 if (!DFG.isTracked(SrcR) || !DFG.isTracked(DstR))
54 EM.insert(std::make_pair(DstR, SrcR));
57 case TargetOpcode::REG_SEQUENCE:
64 CopyMap.insert(std::make_pair(SA.
Id, EM));
68 auto FS = DefM.find(
I.second.Reg);
69 if (FS == DefM.end() || FS->second.empty())
71 RDefMap[
I.second][SA.
Id] = FS->second.top()->Id;
79 RegisterSet RRs(DFG.getPRI());
81 RRs.insert(
RA.Addr->getRegRef(DFG));
83 for (
auto &R : RDefMap) {
84 if (!RRs.count(R.first))
92 for (
auto &R : RDefMap) {
93 if (!RRs.count(
R.first))
95 auto F = DefM.find(
R.first.Reg);
96 if (
F == DefM.end() ||
F->second.empty())
98 R.second[
IA.Id] =
F->second.top()->Id;
102bool CopyPropagation::scanBlock(MachineBasicBlock *
B) {
104 NodeAddr<BlockNode*> BA = DFG.findBlock(
B);
105 DFG.markBlock(BA.
Id, DefM);
107 for (NodeAddr<InstrNode*> IA : BA.
Addr->members(DFG)) {
109 NodeAddr<StmtNode*> SA =
IA;
110 EqualityMap EM(RegisterRefLess(DFG.getPRI()));
111 if (interpretAsCopy(SA.
Addr->getCode(), EM))
116 DFG.pushAllDefs(IA, DefM);
121 Changed |= scanBlock(
I->getBlock());
123 DFG.releaseBlock(BA.
Id, DefM);
128 scanBlock(&DFG.getMF().front());
131 dbgs() <<
"Copies:\n";
135 if (
auto It = CopyMap.find(
I); It != CopyMap.end()) {
136 for (
auto J : It->second)
142 dbgs() <<
"\nRDef map:\n";
143 for (
auto R : RDefMap) {
145 for (
auto &M : R.second)
154 bool HasLimit =
CpLimit.getNumOccurrences() > 0;
157 auto MinPhysReg = [
this] (
RegisterRef RR) ->
unsigned {
163 if (RR.Mask ==
TRI.getSubRegIndexLaneMask(S.getSubRegIndex()))
164 return S.getSubReg();
177 auto FS = CopyMap.find(SA.
Id);
178 if (FS == CopyMap.end())
184 auto FR = EM.find(DR);
191 auto &RDefSR = RDefMap[SR];
194 for (
NodeId N = DA.Addr->getReachedUse(), NextN;
N;
N = NextN) {
200 if (!PRI.
equal_to(UA.Addr->getRegRef(DFG), DR))
205 if (RDefSR[IA.Id] != RDefSR_SA)
217 unsigned NewReg = MinPhysReg(SR);
220 DFG.unlinkUse(UA,
false);
221 if (RDefSR_SA != 0) {
222 UA.Addr->linkToDef(UA.Id, DFG.addr<
DefNode*>(RDefSR_SA));
224 UA.Addr->setReachingDef(0);
225 UA.Addr->setSibling(0);
235 auto FC = CopyMap.find(IA.Id);
236 if (FC != CopyMap.end()) {
238 auto &M = FC->second;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Register const TargetRegisterInfo * TRI
static cl::opt< unsigned > CpLimit("rdf-cp-limit", cl::init(0), cl::Hidden)
SI optimize exec mask operations pre RA
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices.
bool isValid() const
Returns true if this iterator is not yet at the end.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
const LaneBitmask LaneMask
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
Print(const T &, const DataFlowGraph &) -> Print< T >
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
DWARFExpression::Operation Op
std::map< RegisterRef, RegisterRef, RegisterRefLess > EqualityMap
virtual bool interpretAsCopy(const MachineInstr *MI, EqualityMap &EM)
bool equal_to(RegisterRef A, RegisterRef B) const
NodeId getSibling() const
MachineInstr * getCode() const