xref: /aosp_15_r20/external/llvm/lib/Target/Hexagon/RDFLiveness.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===--- RDFLiveness.h ----------------------------------------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // Recalculate the liveness information given a data flow graph.
11*9880d681SAndroid Build Coastguard Worker // This includes block live-ins and kill flags.
12*9880d681SAndroid Build Coastguard Worker 
13*9880d681SAndroid Build Coastguard Worker #ifndef RDF_LIVENESS_H
14*9880d681SAndroid Build Coastguard Worker #define RDF_LIVENESS_H
15*9880d681SAndroid Build Coastguard Worker 
16*9880d681SAndroid Build Coastguard Worker #include "RDFGraph.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h"
18*9880d681SAndroid Build Coastguard Worker #include <map>
19*9880d681SAndroid Build Coastguard Worker 
20*9880d681SAndroid Build Coastguard Worker using namespace llvm;
21*9880d681SAndroid Build Coastguard Worker 
22*9880d681SAndroid Build Coastguard Worker namespace llvm {
23*9880d681SAndroid Build Coastguard Worker   class MachineBasicBlock;
24*9880d681SAndroid Build Coastguard Worker   class MachineFunction;
25*9880d681SAndroid Build Coastguard Worker   class MachineRegisterInfo;
26*9880d681SAndroid Build Coastguard Worker   class TargetRegisterInfo;
27*9880d681SAndroid Build Coastguard Worker   class MachineDominatorTree;
28*9880d681SAndroid Build Coastguard Worker   class MachineDominanceFrontier;
29*9880d681SAndroid Build Coastguard Worker 
30*9880d681SAndroid Build Coastguard Worker namespace rdf {
31*9880d681SAndroid Build Coastguard Worker   struct Liveness {
32*9880d681SAndroid Build Coastguard Worker   public:
33*9880d681SAndroid Build Coastguard Worker     typedef std::map<MachineBasicBlock*,RegisterSet> LiveMapType;
34*9880d681SAndroid Build Coastguard Worker     typedef std::map<RegisterRef,NodeSet> RefMap;
35*9880d681SAndroid Build Coastguard Worker 
LivenessLiveness36*9880d681SAndroid Build Coastguard Worker     Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
37*9880d681SAndroid Build Coastguard Worker       : DFG(g), TRI(g.getTRI()), MDT(g.getDT()), MDF(g.getDF()),
38*9880d681SAndroid Build Coastguard Worker         RAI(g.getRAI()), MRI(mri), Empty(), Trace(false) {}
39*9880d681SAndroid Build Coastguard Worker 
40*9880d681SAndroid Build Coastguard Worker     NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr<RefNode*> RefA,
41*9880d681SAndroid Build Coastguard Worker         bool FullChain = false, const RegisterSet &DefRRs = RegisterSet());
42*9880d681SAndroid Build Coastguard Worker     NodeList getAllReachingDefs(NodeAddr<RefNode*> RefA);
43*9880d681SAndroid Build Coastguard Worker     NodeSet getAllReachingDefsRec(RegisterRef RefRR, NodeAddr<RefNode*> RefA,
44*9880d681SAndroid Build Coastguard Worker         NodeSet &Visited, const NodeSet &Defs);
45*9880d681SAndroid Build Coastguard Worker     NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr<DefNode*> DefA,
46*9880d681SAndroid Build Coastguard Worker         const RegisterSet &DefRRs = RegisterSet());
47*9880d681SAndroid Build Coastguard Worker 
getLiveMapLiveness48*9880d681SAndroid Build Coastguard Worker     LiveMapType &getLiveMap() { return LiveMap; }
getLiveMapLiveness49*9880d681SAndroid Build Coastguard Worker     const LiveMapType &getLiveMap() const { return LiveMap; }
getRealUsesLiveness50*9880d681SAndroid Build Coastguard Worker     const RefMap &getRealUses(NodeId P) const {
51*9880d681SAndroid Build Coastguard Worker       auto F = RealUseMap.find(P);
52*9880d681SAndroid Build Coastguard Worker       return F == RealUseMap.end() ? Empty : F->second;
53*9880d681SAndroid Build Coastguard Worker     }
54*9880d681SAndroid Build Coastguard Worker 
55*9880d681SAndroid Build Coastguard Worker     void computePhiInfo();
56*9880d681SAndroid Build Coastguard Worker     void computeLiveIns();
57*9880d681SAndroid Build Coastguard Worker     void resetLiveIns();
58*9880d681SAndroid Build Coastguard Worker     void resetKills();
59*9880d681SAndroid Build Coastguard Worker     void resetKills(MachineBasicBlock *B);
60*9880d681SAndroid Build Coastguard Worker 
traceLiveness61*9880d681SAndroid Build Coastguard Worker     void trace(bool T) { Trace = T; }
62*9880d681SAndroid Build Coastguard Worker 
63*9880d681SAndroid Build Coastguard Worker   private:
64*9880d681SAndroid Build Coastguard Worker     const DataFlowGraph &DFG;
65*9880d681SAndroid Build Coastguard Worker     const TargetRegisterInfo &TRI;
66*9880d681SAndroid Build Coastguard Worker     const MachineDominatorTree &MDT;
67*9880d681SAndroid Build Coastguard Worker     const MachineDominanceFrontier &MDF;
68*9880d681SAndroid Build Coastguard Worker     const RegisterAliasInfo &RAI;
69*9880d681SAndroid Build Coastguard Worker     MachineRegisterInfo &MRI;
70*9880d681SAndroid Build Coastguard Worker     LiveMapType LiveMap;
71*9880d681SAndroid Build Coastguard Worker     const RefMap Empty;
72*9880d681SAndroid Build Coastguard Worker     bool Trace;
73*9880d681SAndroid Build Coastguard Worker 
74*9880d681SAndroid Build Coastguard Worker     // Cache of mapping from node ids (for RefNodes) to the containing
75*9880d681SAndroid Build Coastguard Worker     // basic blocks. Not computing it each time for each node reduces
76*9880d681SAndroid Build Coastguard Worker     // the liveness calculation time by a large fraction.
77*9880d681SAndroid Build Coastguard Worker     typedef DenseMap<NodeId,MachineBasicBlock*> NodeBlockMap;
78*9880d681SAndroid Build Coastguard Worker     NodeBlockMap NBMap;
79*9880d681SAndroid Build Coastguard Worker 
80*9880d681SAndroid Build Coastguard Worker     // Phi information:
81*9880d681SAndroid Build Coastguard Worker     //
82*9880d681SAndroid Build Coastguard Worker     // map: NodeId -> (map: RegisterRef -> NodeSet)
83*9880d681SAndroid Build Coastguard Worker     //      phi id -> (map: register -> set of reached non-phi uses)
84*9880d681SAndroid Build Coastguard Worker     std::map<NodeId, RefMap> RealUseMap;
85*9880d681SAndroid Build Coastguard Worker 
86*9880d681SAndroid Build Coastguard Worker     // Inverse iterated dominance frontier.
87*9880d681SAndroid Build Coastguard Worker     std::map<MachineBasicBlock*,std::set<MachineBasicBlock*>> IIDF;
88*9880d681SAndroid Build Coastguard Worker 
89*9880d681SAndroid Build Coastguard Worker     // Live on entry.
90*9880d681SAndroid Build Coastguard Worker     std::map<MachineBasicBlock*,RefMap> PhiLON;
91*9880d681SAndroid Build Coastguard Worker 
92*9880d681SAndroid Build Coastguard Worker     // Phi uses are considered to be located at the end of the block that
93*9880d681SAndroid Build Coastguard Worker     // they are associated with. The reaching def of a phi use dominates the
94*9880d681SAndroid Build Coastguard Worker     // block that the use corresponds to, but not the block that contains
95*9880d681SAndroid Build Coastguard Worker     // the phi itself. To include these uses in the liveness propagation (up
96*9880d681SAndroid Build Coastguard Worker     // the dominator tree), create a map: block -> set of uses live on exit.
97*9880d681SAndroid Build Coastguard Worker     std::map<MachineBasicBlock*,RefMap> PhiLOX;
98*9880d681SAndroid Build Coastguard Worker 
99*9880d681SAndroid Build Coastguard Worker     bool isRestricted(NodeAddr<InstrNode*> IA, NodeAddr<RefNode*> RA,
100*9880d681SAndroid Build Coastguard Worker         RegisterRef RR) const;
101*9880d681SAndroid Build Coastguard Worker     RegisterRef getRestrictedRegRef(NodeAddr<RefNode*> RA) const;
102*9880d681SAndroid Build Coastguard Worker     unsigned getPhysReg(RegisterRef RR) const;
103*9880d681SAndroid Build Coastguard Worker     MachineBasicBlock *getBlockWithRef(NodeId RN) const;
104*9880d681SAndroid Build Coastguard Worker     void traverse(MachineBasicBlock *B, RefMap &LiveIn);
105*9880d681SAndroid Build Coastguard Worker     void emptify(RefMap &M);
106*9880d681SAndroid Build Coastguard Worker   };
107*9880d681SAndroid Build Coastguard Worker } // namespace rdf
108*9880d681SAndroid Build Coastguard Worker } // namespace llvm
109*9880d681SAndroid Build Coastguard Worker 
110*9880d681SAndroid Build Coastguard Worker #endif // RDF_LIVENESS_H
111