60 raw_ostream &operator<< (raw_ostream &OS, const Print<Liveness::RefMap> &
P) {
62 for (
auto &
I :
P.Obj) {
63 OS <<
' ' <<
printReg(
I.first, &
P.G.getTRI()) <<
'{';
64 for (
auto J =
I.second.begin(),
E =
I.second.end(); J !=
E; ) {
125 auto SNA = DFG.addr<
RefNode*>(Start);
126 if (
NodeId RD = SNA.Addr->getReachingDef())
129 for (
auto S : DFG.getRelatedRefs(RefA.
Addr->
getOwner(DFG), RefA))
140 for (
unsigned i = 0; i < DefQ.
size(); ++i) {
146 if (!DFG.IsPreservingDef(
TA))
151 for (
auto S : DFG.getRelatedRefs(
TA.Addr->getOwner(DFG),
TA))
162 if (!IsPhi && !PRI.alias(RefRR,
TA.Addr->getRegRef(DFG)))
165 Owners.
insert(
TA.Addr->getOwner(DFG).Id);
184 return MDT.dominates(BB, BA);
196 return MDT.dominates(CB, CA);
207 std::vector<NodeId> Tmp(Owners.
begin(), Owners.
end());
246 if (FullChain || IsPhi || !RRs.
hasCoverOf(QR))
249 RDefs.
insert(RDefs.
end(), Ds.begin(), Ds.end());
253 uint16_t Flags = DA.Addr->getFlags();
256 RRs.
insert(DA.Addr->getRegRef(DFG));
268 std::pair<NodeSet,bool>
271 return getAllReachingDefsRecImpl(RefRR, RefA, Visited, Defs, 0,
MaxRecNest);
274 std::pair<NodeSet,bool>
276 NodeSet &Visited,
const NodeSet &Defs,
unsigned Nest,
unsigned MaxNest) {
283 const auto DA = DFG.addr<
const DefNode*>(
D);
285 DefRRs.
insert(DA.Addr->getRegRef(DFG));
288 NodeList RDs = getAllReachingDefs(RefRR, RefA,
false,
true, DefRRs);
290 return { Defs,
true };
295 TmpDefs.insert(R.Id);
300 Result.insert(DA.Id);
304 if (Visited.count(PA.
Id))
306 Visited.insert(PA.
Id);
309 const auto &
T = getAllReachingDefsRecImpl(RefRR, U, Visited, TmpDefs,
312 return {
T.first,
false };
313 Result.insert(
T.first.begin(),
T.first.end());
317 return { Result,
true };
330 return T.Id == FindId;
344 if (!PRI.alias(R.Addr->getRegRef(DFG), RefRR))
365 if ((
N =
N->getIDom()))
366 BA = DFG.findBlock(
N->getBlock());
393 auto UA = DFG.addr<
UseNode*>(U);
396 if (PRI.alias(RefRR, UR) && !DefRRs.
hasCoverOf(UR))
399 U = UA.Addr->getSibling();
409 if (DefRRs.
hasCoverOf(DR) || !PRI.alias(RefRR, DR))
412 if (DFG.IsPreservingDef(DA)) {
414 T = getAllReachedUses(RefRR, DA, DefRRs);
418 T = getAllReachedUses(RefRR, DA, NewDefRRs);
420 Uses.insert(T.begin(), T.end());
433 Phis.
insert(Phis.
end(), Ps.begin(), Ps.end());
437 std::map<NodeId,std::map<NodeId,RegisterAggr>> PhiUp;
438 std::vector<NodeId> PhiUQ;
439 std::map<NodeId,RegisterAggr> PhiDRs;
445 RefMap &RealUses = RealUseMap[PhiA.Id];
446 NodeList PhiRefs = PhiA.Addr->members(DFG);
456 DRs.
insert(R.Addr->getRegRef(DFG));
458 PhiDefs.insert(R.Id);
460 PhiDRs.insert(std::make_pair(PhiA.Id, DRs));
467 for (
unsigned i = 0; i < DefQ.
size(); ++i) {
488 for (
auto T : DFG.getRelatedRefs(A.
Addr->
getOwner(DFG), A)) {
511 for (
auto UI = RealUses.begin(), UE = RealUses.end(); UI != UE; ) {
518 for (std::pair<NodeId,LaneBitmask>
I : Uses) {
519 auto UA = DFG.addr<
UseNode*>(
I.first);
526 if (PhiDefs.count(DA.Id))
528 Covered.
insert(DA.Addr->getRegRef(DFG));
534 UI->second.insert({
I.first, S.
Mask});
537 UI = UI->second.empty() ? RealUses.erase(UI) : std::next(UI);
542 if (!RealUses.empty())
543 PhiUQ.push_back(PhiA.Id);
552 for (
auto I : PhiRefs) {
560 NodeList Ds = getAllReachingDefs(UR, PUA,
true,
false, NoRegs);
566 std::map<NodeId,RegisterAggr> &M = PhiUp[PUA.
Id];
569 M.insert(std::make_pair(RP, DefRRs));
571 F->second.insert(DefRRs);
573 DefRRs.
insert(
D.Addr->getRegRef(DFG));
582 dbgs() <<
"Phi-up-to-phi map with intervening defs:\n";
583 for (
auto I : PhiUp) {
585 for (
auto R :
I.second)
615 for (
unsigned i = 0; i < PhiUQ.size(); ++i) {
616 auto PA = DFG.addr<
PhiNode*>(PhiUQ[i]);
618 RefMap &RUM = RealUseMap[PA.Id];
621 std::map<NodeId,RegisterAggr> &PUM = PhiUp[UA.Id];
622 RegisterRef UR = PRI.normalize(UA.Addr->getRegRef(DFG));
623 for (
const std::pair<const NodeId, RegisterAggr> &
P : PUM) {
624 bool Changed =
false;
639 for (
const std::pair<const RegisterId, NodeRefSet> &
T : RUM) {
648 for (std::pair<NodeId,LaneBitmask> V :
T.second) {
654 Changed |= RS.insert({V.first,
SS.Mask}).
second;
660 PhiUQ.push_back(
P.first);
666 dbgs() <<
"Real use map:\n";
667 for (
auto I : RealUseMap) {
690 NBMap.
insert(std::make_pair(
RA.Id, BB));
691 NBMap.insert(std::make_pair(IA.Id, BB));
700 auto F1 = MDF.find(&
B);
704 for (
unsigned i = 0; i < IDFB.size(); ++i) {
705 auto F2 = MDF.find(IDFB[i]);
707 IDFB.
insert(F2->second.begin(), F2->second.end());
711 IDF[&
B].insert(IDFB.begin(), IDFB.end());
715 for (
auto S :
I.second)
716 IIDF[S].insert(
I.first);
728 for (
const RefMap::value_type &S : RealUseMap[
P.Id])
729 LON[S.first].
insert(S.second.begin(), S.second.end());
733 dbgs() <<
"Phi live-on-entry map:\n";
734 for (
auto &
I : PhiLON)
735 dbgs() <<
"block #" <<
I.first->getNumber() <<
" -> " 745 RefMap &RUs = RealUseMap[PA.Id];
750 for (
auto U : PA.Addr->members_if(DFG.IsRef<
NodeAttrs::Use>, DFG)) {
751 if (!SeenUses.insert(U.Id).second)
769 RefMap &LOX = PhiLOX[PrA.Addr->getCode()];
771 for (
const std::pair<const RegisterId, NodeRefSet> &RS : RUs) {
773 for (std::pair<NodeId,LaneBitmask>
P : RS.second) {
778 NodeList Ds = getAllReachingDefs(S, PUA,
true,
false, NoRegs);
784 LOX[S.
Reg].insert({
D.Id, TM});
790 SeenUses.insert(
T.Id);
796 dbgs() <<
"Phi live-on-exit map:\n";
797 for (
auto &
I : PhiLOX)
798 dbgs() <<
"block #" <<
I.first->getNumber() <<
" -> " 803 traverse(&MF.front(), LiveIn);
806 LiveMap[&MF.front()].insert(DFG.getLiveIns());
811 std::vector<RegisterRef> LV;
812 for (
auto I =
B.livein_begin(),
E =
B.livein_end();
I !=
E; ++
I)
826 dbgs() <<
"\tcomp = {";
836 for (
auto &
B : DFG.getMF()) {
838 std::vector<unsigned>
T;
839 for (
auto I =
B.livein_begin(),
E =
B.livein_end();
I !=
E; ++
I)
840 T.push_back(
I->PhysReg);
853 for (
auto &
B : DFG.getMF())
867 if ((M &
I.LaneMask).any())
875 CopyLiveIns(B, LiveIn);
877 CopyLiveIns(
SI, Live);
890 if (!
Op.isReg() || !
Op.isDef() ||
Op.isImplicit())
899 if (!
Op.isReg() || !
Op.isUse() ||
Op.isUndef())
922 auto F = NBMap.find(RN);
923 if (
F != NBMap.end())
960 LiveIn[S.first].insert(S.second.begin(), S.second.end());
965 <<
" after recursion into: {";
967 dbgs() <<
' ' <<
I->getBlock()->getNumber();
976 LiveIn[S.first].insert(S.second.begin(), S.second.end());
979 dbgs() <<
"after LOX\n";
991 RefMap LiveInCopy = LiveIn;
994 for (
const std::pair<const RegisterId, NodeRefSet> &
LE : LiveInCopy) {
1018 if (!DFG.IsPreservingDef(DA)) {
1024 if (RRs.
insert(DA.Addr->getRegRef(DFG)).hasCoverOf(LRef))
1045 NewDefs.insert({
TA.Id,T.
Mask});
1052 RRs.
insert(
TA.Addr->getRegRef(DFG));
1063 dbgs() <<
"after defs in block\n";
1069 for (
auto I : DFG.getFunc().Addr->findBlock(B, DFG).Addr->members(DFG)) {
1076 RegisterRef RR = PRI.normalize(UA.Addr->getRegRef(DFG));
1078 if (getBlockWithRef(
D.Id) !=
B)
1079 LiveIn[RR.
Reg].insert({D.Id,RR.Mask});
1084 dbgs() <<
"after uses in block\n";
1093 for (
auto &R : LON) {
1095 for (
auto P : R.second)
1101 dbgs() <<
"after phi uses in block\n";
1106 for (
auto C : IIDF[B]) {
1108 for (
const std::pair<const RegisterId, NodeRefSet> &S : LiveIn)
1109 for (
auto R : S.second)
1110 if (MDT.properlyDominates(getBlockWithRef(R.first),
C))
1115 void Liveness::emptify(
RefMap &M) {
1116 for (
auto I = M.begin(),
E = M.end();
I !=
E; )
1117 I =
I->second.empty() ? M.erase(
I) : std::next(
I);
bool hasCoverOf(RegisterRef RR) const
NodeId getReachedUse() const
A common definition of LaneBitmask for use in TableGen and CodeGen.
uint16_t getFlags() const
static cl::opt< unsigned > MaxRecNest("rdf-liveness-max-rec", cl::init(25), cl::Hidden, cl::desc("Maximum recursion level"))
This class represents lattice values for constants.
size_type size() const
Determine the number of elements in the SetVector.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
bool hasAliasOf(RegisterRef RR) const
std::pair< NodeSet, bool > getAllReachingDefsRec(RegisterRef RefRR, NodeAddr< RefNode *> RefA, NodeSet &Visited, const NodeSet &Defs)
unsigned const TargetRegisterInfo * TRI
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
iterator_range< mop_iterator > operands()
RegisterRef intersectWith(RegisterRef RR) const
rr_iterator rr_begin() const
iterator end()
Get an iterator to the end of the SetVector.
RegisterRef clearIn(RegisterRef RR) const
iterator_range< succ_iterator > successors()
SI optimize exec mask operations pre RA
void clearKillInfo()
Clears kill flags on all operands.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
A Use represents the edge between a Value definition and its users.
RegisterRef getRegRef(const DataFlowGraph &G) const
NodeAddr< RefNode * > getNearestAliasedRef(RegisterRef RefRR, NodeAddr< InstrNode *> IA)
Find the nearest ref node aliased to RefRR, going upwards in the data flow, starting from the instruc...
bool insert(const value_type &X)
Insert a new element into the SetVector.
unsigned getSubRegIndex() const
Returns sub-register index of the current sub-register.
iterator begin()
Get an iterator to the beginning of the SetVector.
Base class for the actual dominator tree node.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
reverse_iterator rbegin()
NodeAddr< NodeBase * > getOwner(const DataFlowGraph &G)
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
rr_iterator rr_end() const
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
MCRegAliasIterator enumerates all registers aliasing Reg.
RegisterRef makeRegRef() const
constexpr bool none() const
NodeId getPredecessor() const
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
NodeList members_if(Predicate P, const DataFlowGraph &G) const
MCSubRegIterator enumerates all sub-registers of Reg.
bool isDebugInstr() const
NodeList members(const DataFlowGraph &G) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void sort(IteratorTy Start, IteratorTy End)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
RegisterAggr & insert(RegisterRef RR)
bool isValid() const
Returns true if this iterator is not yet at the end.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode *> RefA, bool TopShadows, bool FullChain, const RegisterAggr &DefRRs)
std::pair< NodeId, LaneBitmask > NodeRef
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::map< RegisterId, NodeRefSet > RefMap
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
NodeId getReachedDef() const
iterator insert(iterator I, T &&Elt)
std::set< NodeId > NodeSet
Representation of each machine instruction.
NodeId getReachingDef() const
NodeAddr< NodeBase * > getOwner(const DataFlowGraph &G)
static ValueLatticeElement intersect(const ValueLatticeElement &A, const ValueLatticeElement &B)
Combine two sets of facts about the same value into a single set of facts.
LLVM_NODISCARD bool empty() const
std::set< NodeRef > NodeRefSet
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr< DefNode *> DefA, const RegisterAggr &DefRRs)
iterator_range< livein_iterator > liveins() const
reverse_iterator rbegin()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isCoverOf(RegisterRef RA, RegisterRef RB, const PhysicalRegisterInfo &PRI)
A vector that has set insertion semantics.
MachineBasicBlock * getCode() const
This class implements an extremely fast bulk output stream that can only output to a stream...
MCRegister getSubReg() const
Returns current sub-register.
NodeId getSibling() const
Wrapper class representing virtual and physical registers.