LLVM  4.0.0
RDFLiveness.h
Go to the documentation of this file.
1 //===--- RDFLiveness.h ----------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Recalculate the liveness information given a data flow graph.
11 // This includes block live-ins and kill flags.
12 
13 #ifndef RDF_LIVENESS_H
14 #define RDF_LIVENESS_H
15 
16 #include "RDFGraph.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include <map>
19 
20 using namespace llvm;
21 
22 namespace llvm {
23  class MachineBasicBlock;
24  class MachineFunction;
25  class MachineRegisterInfo;
26  class TargetRegisterInfo;
29 
30 namespace rdf {
31  struct Liveness {
32  public:
33  // This is really a std::map, except that it provides a non-trivial
34  // default constructor to the element accessed via [].
35  struct LiveMapType {
36  LiveMapType(const TargetRegisterInfo &tri) : Empty(tri) {}
37 
39  return Map.emplace(B, Empty).first->second;
40  }
41  private:
42  RegisterAggr Empty;
43  std::map<MachineBasicBlock*,RegisterAggr> Map;
44  };
45 
46  typedef std::pair<NodeId,LaneBitmask> NodeRef;
47  typedef std::set<NodeRef> NodeRefSet;
48  // RegisterId in RefMap must be normalized.
49  typedef std::map<RegisterId,NodeRefSet> RefMap;
50 
52  : DFG(g), TRI(g.getTRI()), MDT(g.getDT()), MDF(g.getDF()),
53  MRI(mri), LiveMap(g.getTRI()), Empty(), NoRegs(g.getTRI()),
54  Trace(false) {}
55 
57  bool FullChain, const RegisterAggr &DefRRs);
59  return getAllReachingDefs(RefA.Addr->getRegRef(DFG), RefA, false, NoRegs);
60  }
62  return getAllReachingDefs(RefRR, RefA, false, NoRegs);
63  }
65  NodeSet &Visited, const NodeSet &Defs);
67  const RegisterAggr &DefRRs);
69  return getAllReachedUses(RefRR, DefA, NoRegs);
70  }
71 
72  LiveMapType &getLiveMap() { return LiveMap; }
73  const LiveMapType &getLiveMap() const { return LiveMap; }
74  const RefMap &getRealUses(NodeId P) const {
75  auto F = RealUseMap.find(P);
76  return F == RealUseMap.end() ? Empty : F->second;
77  }
78 
79  void computePhiInfo();
80  void computeLiveIns();
81  void resetLiveIns();
82  void resetKills();
84 
85  void trace(bool T) { Trace = T; }
86 
87  private:
88  const DataFlowGraph &DFG;
89  const TargetRegisterInfo &TRI;
90  const MachineDominatorTree &MDT;
91  const MachineDominanceFrontier &MDF;
93  LiveMapType LiveMap;
94  const RefMap Empty;
95  const RegisterAggr NoRegs;
96  bool Trace;
97 
98  // Cache of mapping from node ids (for RefNodes) to the containing
99  // basic blocks. Not computing it each time for each node reduces
100  // the liveness calculation time by a large fraction.
101  typedef DenseMap<NodeId,MachineBasicBlock*> NodeBlockMap;
102  NodeBlockMap NBMap;
103 
104  // Phi information:
105  //
106  // RealUseMap
107  // map: NodeId -> (map: RegisterId -> NodeRefSet)
108  // phi id -> (map: register -> set of reached non-phi uses)
109  std::map<NodeId, RefMap> RealUseMap;
110 
111  // Inverse iterated dominance frontier.
112  std::map<MachineBasicBlock*,std::set<MachineBasicBlock*>> IIDF;
113 
114  // Live on entry.
115  std::map<MachineBasicBlock*,RefMap> PhiLON;
116 
117  // Phi uses are considered to be located at the end of the block that
118  // they are associated with. The reaching def of a phi use dominates the
119  // block that the use corresponds to, but not the block that contains
120  // the phi itself. To include these uses in the liveness propagation (up
121  // the dominator tree), create a map: block -> set of uses live on exit.
122  std::map<MachineBasicBlock*,RefMap> PhiLOX;
123 
124  bool isRestrictedToRef(NodeAddr<InstrNode*> IA, NodeAddr<RefNode*> RA,
125  RegisterRef RR) const;
126  RegisterRef getRestrictedRegRef(NodeAddr<RefNode*> RA) const;
127  MachineBasicBlock *getBlockWithRef(NodeId RN) const;
128  void traverse(MachineBasicBlock *B, RefMap &LiveIn);
129  void emptify(RefMap &M);
130  };
131 } // namespace rdf
132 } // namespace llvm
133 
134 #endif // RDF_LIVENESS_H
std::set< NodeRef > NodeRefSet
Definition: RDFLiveness.h:47
const LiveMapType & getLiveMap() const
Definition: RDFLiveness.h:73
std::vector< NodeAddr< NodeBase * > > NodeList
Definition: RDFGraph.h:610
RegisterAggr & operator[](MachineBasicBlock *B)
Definition: RDFLiveness.h:38
#define F(x, y, z)
Definition: MD5.cpp:51
#define T
std::map< RegisterId, NodeRefSet > RefMap
Definition: RDFLiveness.h:49
Function Alias Analysis false
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA, bool FullChain, const RegisterAggr &DefRRs)
Definition: RDFLiveness.cpp:87
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
void trace(bool T)
Definition: RDFLiveness.h:85
#define P(N)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr< DefNode * > DefA, const RegisterAggr &DefRRs)
std::pair< NodeId, LaneBitmask > NodeRef
Definition: RDFLiveness.h:46
NodeSet getAllReachingDefsRec(RegisterRef RefRR, NodeAddr< RefNode * > RefA, NodeSet &Visited, const NodeSet &Defs)
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA)
Definition: RDFLiveness.h:61
LiveMapType & getLiveMap()
Definition: RDFLiveness.h:72
std::set< NodeId > NodeSet
Definition: RDFGraph.h:613
NodeList getAllReachingDefs(NodeAddr< RefNode * > RefA)
Definition: RDFLiveness.h:58
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
const RefMap & getRealUses(NodeId P) const
Definition: RDFLiveness.h:74
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr< DefNode * > DefA)
Definition: RDFLiveness.h:68
LiveMapType(const TargetRegisterInfo &tri)
Definition: RDFLiveness.h:36
Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
Definition: RDFLiveness.h:51
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...