LLVM  5.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 PhysicalRegisterInfo &pri) : Empty(pri) {}
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()), PRI(g.getPRI()), MDT(g.getDT()),
53  MDF(g.getDF()), LiveMap(g.getPRI()), Empty(),
54  NoRegs(g.getPRI()), Trace(false) {}
55 
57  bool TopShadows, bool FullChain, const RegisterAggr &DefRRs);
59  return getAllReachingDefs(RefA.Addr->getRegRef(DFG), RefA, false,
60  false, NoRegs);
61  }
63  return getAllReachingDefs(RefRR, RefA, false, false, NoRegs);
64  }
66  const RegisterAggr &DefRRs);
68  return getAllReachedUses(RefRR, DefA, NoRegs);
69  }
70 
71  std::pair<NodeSet,bool> getAllReachingDefsRec(RegisterRef RefRR,
72  NodeAddr<RefNode*> RefA, NodeSet &Visited, const NodeSet &Defs);
73 
76 
77  LiveMapType &getLiveMap() { return LiveMap; }
78  const LiveMapType &getLiveMap() const { return LiveMap; }
79  const RefMap &getRealUses(NodeId P) const {
80  auto F = RealUseMap.find(P);
81  return F == RealUseMap.end() ? Empty : F->second;
82  }
83 
84  void computePhiInfo();
85  void computeLiveIns();
86  void resetLiveIns();
87  void resetKills();
89 
90  void trace(bool T) { Trace = T; }
91 
92  private:
93  const DataFlowGraph &DFG;
94  const TargetRegisterInfo &TRI;
95  const PhysicalRegisterInfo &PRI;
96  const MachineDominatorTree &MDT;
97  const MachineDominanceFrontier &MDF;
98  LiveMapType LiveMap;
99  const RefMap Empty;
100  const RegisterAggr NoRegs;
101  bool Trace;
102 
103  // Cache of mapping from node ids (for RefNodes) to the containing
104  // basic blocks. Not computing it each time for each node reduces
105  // the liveness calculation time by a large fraction.
106  typedef DenseMap<NodeId,MachineBasicBlock*> NodeBlockMap;
107  NodeBlockMap NBMap;
108 
109  // Phi information:
110  //
111  // RealUseMap
112  // map: NodeId -> (map: RegisterId -> NodeRefSet)
113  // phi id -> (map: register -> set of reached non-phi uses)
114  std::map<NodeId, RefMap> RealUseMap;
115 
116  // Inverse iterated dominance frontier.
117  std::map<MachineBasicBlock*,std::set<MachineBasicBlock*>> IIDF;
118 
119  // Live on entry.
120  std::map<MachineBasicBlock*,RefMap> PhiLON;
121 
122  // Phi uses are considered to be located at the end of the block that
123  // they are associated with. The reaching def of a phi use dominates the
124  // block that the use corresponds to, but not the block that contains
125  // the phi itself. To include these uses in the liveness propagation (up
126  // the dominator tree), create a map: block -> set of uses live on exit.
127  std::map<MachineBasicBlock*,RefMap> PhiLOX;
128 
129  MachineBasicBlock *getBlockWithRef(NodeId RN) const;
130  void traverse(MachineBasicBlock *B, RefMap &LiveIn);
131  void emptify(RefMap &M);
132 
133  std::pair<NodeSet,bool> getAllReachingDefsRecImpl(RegisterRef RefRR,
134  NodeAddr<RefNode*> RefA, NodeSet &Visited, const NodeSet &Defs,
135  unsigned Nest, unsigned MaxNest);
136  };
137 } // namespace rdf
138 } // namespace llvm
139 
140 #endif // RDF_LIVENESS_H
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA, bool TopShadows, bool FullChain, const RegisterAggr &DefRRs)
Definition: RDFLiveness.cpp:91
std::set< NodeRef > NodeRefSet
Definition: RDFLiveness.h:47
const LiveMapType & getLiveMap() const
Definition: RDFLiveness.h:78
LiveMapType(const PhysicalRegisterInfo &pri)
Definition: RDFLiveness.h:36
RegisterAggr & operator[](MachineBasicBlock *B)
Definition: RDFLiveness.h:38
#define F(x, y, z)
Definition: MD5.cpp:55
#define T
std::map< RegisterId, NodeRefSet > RefMap
Definition: RDFLiveness.h:49
void trace(bool T)
Definition: RDFLiveness.h:90
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...
Function Alias Analysis false
#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
#define B
Definition: LargeTest.cpp:24
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA)
Definition: RDFLiveness.h:62
LiveMapType & getLiveMap()
Definition: RDFLiveness.h:77
std::set< NodeId > NodeSet
Definition: RDFGraph.h:513
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:79
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr< DefNode * > DefA)
Definition: RDFLiveness.h:67
Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
Definition: RDFLiveness.h:51
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
std::pair< NodeSet, bool > getAllReachingDefsRec(RegisterRef RefRR, NodeAddr< RefNode * > RefA, NodeSet &Visited, const NodeSet &Defs)