File indexing completed on 2026-05-10 08:43:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef LLVM_CODEGEN_RDFLIVENESS_H
0013 #define LLVM_CODEGEN_RDFLIVENESS_H
0014
0015 #include "RDFGraph.h"
0016 #include "RDFRegisters.h"
0017 #include "llvm/ADT/DenseMap.h"
0018 #include "llvm/MC/LaneBitmask.h"
0019 #include <map>
0020 #include <set>
0021 #include <unordered_map>
0022 #include <unordered_set>
0023 #include <utility>
0024
0025 namespace llvm {
0026
0027 class MachineBasicBlock;
0028 class MachineDominanceFrontier;
0029 class MachineDominatorTree;
0030 class MachineRegisterInfo;
0031 class TargetRegisterInfo;
0032
0033 namespace rdf {
0034 namespace detail {
0035
0036 using NodeRef = std::pair<NodeId, LaneBitmask>;
0037
0038 }
0039 }
0040 }
0041
0042 namespace std {
0043
0044 template <> struct hash<llvm::rdf::detail::NodeRef> {
0045 std::size_t operator()(llvm::rdf::detail::NodeRef R) const {
0046 return std::hash<llvm::rdf::NodeId>{}(R.first) ^
0047 std::hash<llvm::LaneBitmask::Type>{}(R.second.getAsInteger());
0048 }
0049 };
0050
0051 }
0052
0053 namespace llvm::rdf {
0054
0055 struct Liveness {
0056 public:
0057 using LiveMapType = RegisterAggrMap<MachineBasicBlock *>;
0058 using NodeRef = detail::NodeRef;
0059 using NodeRefSet = std::unordered_set<NodeRef>;
0060 using RefMap = std::unordered_map<RegisterId, NodeRefSet>;
0061
0062 Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
0063 : DFG(g), TRI(g.getTRI()), PRI(g.getPRI()), MDT(g.getDT()),
0064 MDF(g.getDF()), LiveMap(g.getPRI()), Empty(), NoRegs(g.getPRI()) {}
0065
0066 NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr<RefNode *> RefA,
0067 bool TopShadows, bool FullChain,
0068 const RegisterAggr &DefRRs);
0069
0070 NodeList getAllReachingDefs(NodeAddr<RefNode *> RefA) {
0071 return getAllReachingDefs(RefA.Addr->getRegRef(DFG), RefA, false, false,
0072 NoRegs);
0073 }
0074
0075 NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr<RefNode *> RefA) {
0076 return getAllReachingDefs(RefRR, RefA, false, false, NoRegs);
0077 }
0078
0079 NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr<DefNode *> DefA,
0080 const RegisterAggr &DefRRs);
0081
0082 NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr<DefNode *> DefA) {
0083 return getAllReachedUses(RefRR, DefA, NoRegs);
0084 }
0085
0086 std::pair<NodeSet, bool> getAllReachingDefsRec(RegisterRef RefRR,
0087 NodeAddr<RefNode *> RefA,
0088 NodeSet &Visited,
0089 const NodeSet &Defs);
0090
0091 NodeAddr<RefNode *> getNearestAliasedRef(RegisterRef RefRR,
0092 NodeAddr<InstrNode *> IA);
0093
0094 LiveMapType &getLiveMap() { return LiveMap; }
0095 const LiveMapType &getLiveMap() const { return LiveMap; }
0096
0097 const RefMap &getRealUses(NodeId P) const {
0098 auto F = RealUseMap.find(P);
0099 return F == RealUseMap.end() ? Empty : F->second;
0100 }
0101
0102 void computePhiInfo();
0103 void computeLiveIns();
0104 void resetLiveIns();
0105 void resetKills();
0106 void resetKills(MachineBasicBlock *B);
0107
0108 void trace(bool T) { Trace = T; }
0109
0110 private:
0111 const DataFlowGraph &DFG;
0112 const TargetRegisterInfo &TRI;
0113 const PhysicalRegisterInfo &PRI;
0114 const MachineDominatorTree &MDT;
0115 const MachineDominanceFrontier &MDF;
0116 LiveMapType LiveMap;
0117 const RefMap Empty;
0118 const RegisterAggr NoRegs;
0119 bool Trace = false;
0120
0121
0122
0123
0124 DenseMap<NodeId, MachineBasicBlock *> NBMap;
0125
0126
0127
0128
0129
0130
0131 DenseMap<NodeId, RefMap> RealUseMap;
0132
0133
0134 std::map<MachineBasicBlock *, std::set<MachineBasicBlock *>> IIDF;
0135
0136
0137 std::map<MachineBasicBlock *, RefMap> PhiLON;
0138
0139
0140
0141
0142
0143
0144 std::map<MachineBasicBlock *, RefMap> PhiLOX;
0145
0146 MachineBasicBlock *getBlockWithRef(NodeId RN) const;
0147 void traverse(MachineBasicBlock *B, RefMap &LiveIn);
0148 void emptify(RefMap &M);
0149
0150 std::pair<NodeSet, bool>
0151 getAllReachingDefsRecImpl(RegisterRef RefRR, NodeAddr<RefNode *> RefA,
0152 NodeSet &Visited, const NodeSet &Defs,
0153 unsigned Nest, unsigned MaxNest);
0154 };
0155
0156 raw_ostream &operator<<(raw_ostream &OS, const Print<Liveness::RefMap> &P);
0157
0158 }
0159
0160 #endif