46 raw_ostream &operator<< (raw_ostream &OS, const Print<Liveness::RefMap> &
P) {
48 for (
auto &
I :
P.Obj) {
49 OS <<
' ' <<
PrintReg(
I.first, &
P.G.getTRI()) <<
'{';
50 for (
auto J =
I.second.begin(),
E =
I.second.end(); J !=
E; ) {
111 if (
NodeId RD = SNA.Addr->getReachingDef())
125 for (
unsigned i = 0; i < DefQ.
size(); ++i) {
147 if (!IsPhi && !PRI.
alias(RefRR,
TA.Addr->getRegRef(DFG)))
150 Owners.
insert(
TA.Addr->getOwner(DFG).Id);
192 std::vector<NodeId> Tmp(Owners.
begin(), Owners.
end());
216 if (!FullChain && RRs.hasCoverOf(RefRR))
231 if (FullChain || IsPhi || !RRs.hasCoverOf(QR))
234 RDefs.
insert(RDefs.
end(), Ds.begin(), Ds.end());
238 uint16_t
Flags = DA.Addr->getFlags();
241 RRs.insert(DA.Addr->getRegRef(DFG));
254 std::pair<NodeSet,bool>
257 return getAllReachingDefsRecImpl(RefRR, RefA, Visited, Defs, 0,
MaxRecNest);
261 std::pair<NodeSet,bool>
263 NodeSet &Visited,
const NodeSet &Defs,
unsigned Nest,
unsigned MaxNest) {
272 DefRRs.insert(DA.Addr->getRegRef(DFG));
277 return { Defs,
true };
282 TmpDefs.insert(R.Id);
287 Result.insert(DA.Id);
291 if (Visited.count(PA.
Id))
293 Visited.insert(PA.
Id);
296 const auto &
T = getAllReachingDefsRecImpl(RefRR, U, Visited, TmpDefs,
299 return {
T.first,
false };
300 Result.insert(
T.first.begin(),
T.first.end());
304 return { Result,
true };
317 return T.Id == FindId;
331 if (!PRI.
alias(R.Addr->getRegRef(DFG), RefRR))
352 if ((
N =
N->getIDom()))
387 U = UA.Addr->getSibling();
408 Uses.insert(T.begin(), T.end());
422 Phis.
insert(Phis.
end(), Ps.begin(), Ps.end());
426 std::map<NodeId,std::map<NodeId,RegisterAggr>> PhiUp;
427 std::vector<NodeId> PhiUQ;
428 std::map<NodeId,RegisterAggr> PhiDRs;
434 RefMap &RealUses = RealUseMap[PhiA.Id];
435 NodeList PhiRefs = PhiA.Addr->members(DFG);
445 DRs.
insert(R.Addr->getRegRef(DFG));
447 PhiDefs.insert(R.Id);
449 PhiDRs.insert(std::make_pair(PhiA.Id, DRs));
456 for (
unsigned i = 0; i < DefQ.
size(); ++i) {
500 for (
auto UI = RealUses.begin(), UE = RealUses.end(); UI != UE; ) {
507 for (std::pair<NodeId,LaneBitmask>
I : Uses) {
515 if (PhiDefs.count(DA.Id))
517 Covered.
insert(DA.Addr->getRegRef(DFG));
523 UI->second.insert({
I.first, S.
Mask});
526 UI = UI->second.empty() ? RealUses.erase(UI) : std::next(UI);
531 if (!RealUses.empty())
532 PhiUQ.push_back(PhiA.Id);
541 for (
auto I : PhiRefs) {
555 std::map<NodeId,RegisterAggr> &M = PhiUp[PUA.
Id];
558 M.insert(std::make_pair(RP, DefRRs));
560 F->second.insert(DefRRs);
562 DefRRs.
insert(
D.Addr->getRegRef(DFG));
571 dbgs() <<
"Phi-up-to-phi map with intervening defs:\n";
572 for (
auto I : PhiUp) {
574 for (
auto R :
I.second)
604 for (
unsigned i = 0; i < PhiUQ.size(); ++i) {
610 std::map<NodeId,RegisterAggr> &PUM = PhiUp[UA.Id];
612 for (
const std::pair<NodeId,RegisterAggr> &
P : PUM) {
613 bool Changed =
false;
628 for (
const std::pair<RegisterId,NodeRefSet> &
T : RUM) {
637 for (std::pair<NodeId,LaneBitmask> V :
T.second) {
643 Changed |= RS.insert({V.first,SS.Mask}).
second;
649 PhiUQ.push_back(
P.first);
655 dbgs() <<
"Real use map:\n";
656 for (
auto I : RealUseMap) {
680 NBMap.
insert(std::make_pair(RA.Id, BB));
681 NBMap.
insert(std::make_pair(IA.Id, BB));
690 auto F1 = MDF.
find(&
B);
694 for (
unsigned i = 0; i < IDFB.size(); ++i) {
695 auto F2 = MDF.
find(IDFB[i]);
697 IDFB.insert(F2->second.begin(), F2->second.end());
701 IDF[&
B].insert(IDFB.begin(), IDFB.end());
705 for (
auto S :
I.second)
706 IIDF[S].insert(
I.first);
718 for (
const RefMap::value_type &S : RealUseMap[
P.Id])
719 LON[S.first].insert(S.second.begin(), S.second.end());
723 dbgs() <<
"Phi live-on-entry map:\n";
724 for (
auto &
I : PhiLON)
725 dbgs() <<
"block #" <<
I.first->getNumber() <<
" -> "
741 if (!SeenUses.insert(U.Id).second)
759 RefMap &LOX = PhiLOX[PrA.Addr->getCode()];
761 for (
const std::pair<RegisterId,NodeRefSet> &RS : RUs) {
763 for (std::pair<NodeId,LaneBitmask>
P : RS.second) {
774 LOX[S.
Reg].insert({
D.Id, TM});
780 SeenUses.insert(
T.Id);
786 dbgs() <<
"Phi live-on-exit map:\n";
787 for (
auto &
I : PhiLOX)
788 dbgs() <<
"block #" <<
I.first->getNumber() <<
" -> "
793 traverse(&MF.front(), LiveIn);
796 LiveMap[&MF.front()].insert(DFG.
getLiveIns());
801 std::vector<RegisterRef> LV;
802 for (
auto I =
B.livein_begin(),
E =
B.livein_end();
I !=
E; ++
I)
805 dbgs() <<
"BB#" <<
B.getNumber() <<
"\t rec = {";
816 dbgs() <<
"\tcomp = {";
827 for (
auto &
B : DFG.
getMF()) {
829 std::vector<unsigned>
T;
830 for (
auto I =
B.livein_begin(),
E =
B.livein_end();
I !=
E; ++
I)
831 T.push_back(
I->PhysReg);
845 for (
auto &
B : DFG.
getMF())
860 if ((M &
I.LaneMask).any())
868 CopyLiveIns(B, LiveIn);
870 CopyLiveIns(
SI, Live);
883 if (!
Op.isReg() || !
Op.isDef() ||
Op.isImplicit())
885 unsigned R =
Op.getReg();
892 if (!
Op.isReg() || !
Op.isUse() ||
Op.isUndef())
894 unsigned R =
Op.getReg();
916 auto F = NBMap.
find(RN);
917 if (
F != NBMap.
end())
955 LiveIn[S.first].insert(S.second.begin(), S.second.end());
960 <<
" after recursion into: {";
962 dbgs() <<
' ' <<
I->getBlock()->getNumber();
971 LiveIn[S.first].insert(S.second.begin(), S.second.end());
974 dbgs() <<
"after LOX\n";
986 RefMap LiveInCopy = LiveIn;
989 for (
const std::pair<RegisterId,NodeRefSet> &
LE : LiveInCopy) {
1011 LRef.Mask =
OR.second;
1019 if (RRs.insert(DA.Addr->getRegRef(DFG)).hasCoverOf(LRef))
1040 NewDefs.insert({
TA.Id,T.
Mask});
1047 RRs.insert(
TA.Addr->getRegRef(DFG));
1049 if (RRs.hasCoverOf(LRef))
1058 dbgs() <<
"after defs in block\n";
1064 for (
auto I : DFG.
getFunc().Addr->findBlock(B, DFG).Addr->members(DFG)) {
1073 if (getBlockWithRef(
D.Id) !=
B)
1074 LiveIn[RR.
Reg].insert({
D.Id,RR.
Mask});
1079 dbgs() <<
"after uses in block\n";
1087 RefMap &LON = PhiLON[
B];
1088 for (
auto &R : LON) {
1090 for (
auto P : R.second)
1096 dbgs() <<
"after phi uses in block\n";
1101 for (
auto C : IIDF[B]) {
1103 for (
const std::pair<RegisterId,NodeRefSet> &S : LiveIn)
1104 for (
auto R : S.second)
1105 if (MDT.properlyDominates(getBlockWithRef(R.first),
C))
1111 void Liveness::emptify(RefMap &M) {
1112 for (
auto I = M.begin(),
E = M.end();
I !=
E; )
1113 I =
I->second.empty() ? M.erase(
I) : std::next(
I);
NodeList members(const DataFlowGraph &G) const
MachineFunction & getMF() const
iterator_range< livein_iterator > liveins() const
static cl::opt< unsigned > MaxRecNest("rdf-liveness-max-rec", cl::init(25), cl::Hidden, cl::desc("Maximum recursion level"))
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
NodeId getReachedDef() const
uint16_t getFlags() const
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA, bool TopShadows, bool FullChain, const RegisterAggr &DefRRs)
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
rr_iterator rr_end() const
std::set< NodeRef > NodeRefSet
static bool IsPreservingDef(const NodeAddr< DefNode * > DA)
bool isValid() const
Returns true if this iterator is not yet at the end.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
iterator_range< mop_iterator > operands()
iterator end()
Get an iterator to the end of the SetVector.
size_type size() const
Determine the number of elements in the SetVector.
iterator_range< succ_iterator > successors()
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void clearKillInfo()
Clears kill flags on all operands.
NodeList getRelatedRefs(NodeAddr< InstrNode * > IA, NodeAddr< RefNode * > RA) const
A Use represents the edge between a Value definition and its users.
NodeId getReachedUse() const
static LVILatticeVal intersect(const LVILatticeVal &A, const LVILatticeVal &B)
Combine two sets of facts about the same value into a single set of facts.
RegisterRef mapTo(RegisterRef RR, unsigned R) const
LLVM_NODISCARD bool empty() const
MachineDomTreeNode * getNode(MachineBasicBlock *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
bool insert(const value_type &X)
Insert a new element into the SetVector.
static bool IsDef(const NodeAddr< NodeBase * > BA)
RegisterRef makeRegRef() const
std::map< RegisterId, NodeRefSet > RefMap
iterator begin()
Get an iterator to the beginning of the SetVector.
Base class for the actual dominator tree node.
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...
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
reverse_iterator rbegin()
NodeAddr< NodeBase * > getOwner(const DataFlowGraph &G)
NodeList members_if(Predicate P, const DataFlowGraph &G) const
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
iterator find(const_arg_type_t< KeyT > Val)
bool isDebugValue() const
INITIALIZE_PASS(HexagonEarlyIfConversion,"hexagon-eif","Hexagon early if conversion", false, false) bool HexagonEarlyIfConversion MachineBasicBlock * SB
initializer< Ty > init(const Ty &Val)
static bool IsRef(const NodeAddr< NodeBase * > BA)
bool hasCoverOf(RegisterRef RR) const
constexpr bool none() const
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static ManagedStatic< OptionRegistry > OR
MCRegAliasIterator enumerates all registers aliasing Reg.
static bool IsCode(const NodeAddr< NodeBase * > BA)
MCSubRegIterator enumerates all sub-registers of Reg.
RegisterRef intersectWith(RegisterRef RR) const
NodeId getPredecessor() const
iterator find(MachineBasicBlock *B)
std::pair< NodeId, LaneBitmask > NodeRef
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr< DefNode * > DefA, const RegisterAggr &DefRRs)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
unsigned getSubReg() const
Returns current sub-register.
RegisterAggr & insert(RegisterRef RR)
RegisterRef normalize(RegisterRef RR) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
NodeId getSibling() const
bool alias(RegisterRef RA, RegisterRef RB) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::set< NodeId > NodeSet
NodeAddr< FuncNode * > getFunc() const
RegisterRef getRegRef(const DataFlowGraph &G) const
static bool IsUse(const NodeAddr< NodeBase * > BA)
iterator insert(iterator I, T &&Elt)
unsigned getSubRegIndex() const
Returns sub-register index of the current sub-register.
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
Representation of each machine instruction.
NodeAddr< NodeBase * > getOwner(const DataFlowGraph &G)
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
RegisterRef clearIn(RegisterRef RR) const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
MachineBasicBlock * getCode() const
reverse_iterator rbegin()
rr_iterator rr_begin() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isCoverOf(RegisterRef RA, RegisterRef RB, const PhysicalRegisterInfo &PRI)
const RegisterAggr & getLiveIns() const
A vector that has set insertion semantics.
NodeAddr< T > addr(NodeId N) const
NodeId getReachingDef() const
This class implements an extremely fast bulk output stream that can only output to a stream...
bool hasAliasOf(RegisterRef RR) const
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
NodeAddr< BlockNode * > findBlock(MachineBasicBlock *BB) const
std::pair< NodeSet, bool > getAllReachingDefsRec(RegisterRef RefRR, NodeAddr< RefNode * > RefA, NodeSet &Visited, const NodeSet &Defs)