blob: 0705b4019217ebb14f85f81da62b7fb613c9449a [file] [log] [blame]
Krzysztof Parzyszekacdff462016-01-12 15:56:33 +00001//===--- 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
20using namespace llvm;
21
22namespace llvm {
23 class MachineBasicBlock;
24 class MachineFunction;
25 class MachineRegisterInfo;
26 class TargetRegisterInfo;
27 class MachineDominatorTree;
28 class MachineDominanceFrontier;
29}
30
31namespace rdf {
32 struct Liveness {
33 public:
34 typedef std::map<MachineBasicBlock*,RegisterSet> LiveMapType;
35 typedef std::map<RegisterRef,NodeSet> RefMap;
36
37 Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
38 : DFG(g), TRI(g.getTRI()), MDT(g.getDT()), MDF(g.getDF()),
39 RAI(g.getRAI()), MRI(mri), Empty(), Trace(false) {}
40
41 NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr<RefNode*> RefA,
42 bool FullChain = false, const RegisterSet &DefRRs = RegisterSet());
43 NodeList getAllReachingDefs(NodeAddr<RefNode*> RefA);
Krzysztof Parzyszekf5cbac92016-04-29 15:49:13 +000044 NodeSet getAllReachingDefsRec(RegisterRef RefRR, NodeAddr<RefNode*> RefA,
45 NodeSet &Visited, const NodeSet &Defs);
46 NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr<DefNode*> DefA,
47 const RegisterSet &DefRRs = RegisterSet());
Krzysztof Parzyszekacdff462016-01-12 15:56:33 +000048
49 LiveMapType &getLiveMap() { return LiveMap; }
50 const LiveMapType &getLiveMap() const { return LiveMap; }
51 const RefMap &getRealUses(NodeId P) const {
52 auto F = RealUseMap.find(P);
53 return F == RealUseMap.end() ? Empty : F->second;
54 }
55
56 void computePhiInfo();
57 void computeLiveIns();
58 void resetLiveIns();
59 void resetKills();
60 void resetKills(MachineBasicBlock *B);
61
62 void trace(bool T) { Trace = T; }
63
64 private:
65 const DataFlowGraph &DFG;
66 const TargetRegisterInfo &TRI;
67 const MachineDominatorTree &MDT;
68 const MachineDominanceFrontier &MDF;
69 const RegisterAliasInfo &RAI;
70 MachineRegisterInfo &MRI;
71 LiveMapType LiveMap;
72 const RefMap Empty;
73 bool Trace;
74
75 // Cache of mapping from node ids (for RefNodes) to the containing
76 // basic blocks. Not computing it each time for each node reduces
77 // the liveness calculation time by a large fraction.
78 typedef DenseMap<NodeId,MachineBasicBlock*> NodeBlockMap;
79 NodeBlockMap NBMap;
80
81 // Phi information:
82 //
83 // map: NodeId -> (map: RegisterRef -> NodeSet)
84 // phi id -> (map: register -> set of reached non-phi uses)
85 std::map<NodeId, RefMap> RealUseMap;
86
87 // Inverse iterated dominance frontier.
88 std::map<MachineBasicBlock*,std::set<MachineBasicBlock*>> IIDF;
89
90 // Live on entry.
91 std::map<MachineBasicBlock*,RefMap> PhiLON;
92
93 // Phi uses are considered to be located at the end of the block that
94 // they are associated with. The reaching def of a phi use dominates the
95 // block that the use corresponds to, but not the block that contains
96 // the phi itself. To include these uses in the liveness propagation (up
97 // the dominator tree), create a map: block -> set of uses live on exit.
98 std::map<MachineBasicBlock*,RefMap> PhiLOX;
99
100 bool isRestricted(NodeAddr<InstrNode*> IA, NodeAddr<RefNode*> RA,
101 RegisterRef RR) const;
102 RegisterRef getRestrictedRegRef(NodeAddr<RefNode*> RA) const;
103 unsigned getPhysReg(RegisterRef RR) const;
104 MachineBasicBlock *getBlockWithRef(NodeId RN) const;
105 void traverse(MachineBasicBlock *B, RefMap &LiveIn);
106 void emptify(RefMap &M);
107 };
108}
109
110#endif // RDF_LIVENESS_H