LLVM 23.0.0git
RDFLiveness.h
Go to the documentation of this file.
1//===- RDFLiveness.h --------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Recalculate the liveness information given a data flow graph.
10// This includes block live-ins and kill flags.
11
12#ifndef LLVM_CODEGEN_RDFLIVENESS_H
13#define LLVM_CODEGEN_RDFLIVENESS_H
14
15#include "RDFGraph.h"
16#include "RDFRegisters.h"
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/MC/LaneBitmask.h"
19#include <map>
20#include <set>
21#include <unordered_map>
22#include <unordered_set>
23#include <utility>
24
25namespace llvm {
26
32
33namespace rdf {
34namespace detail {
35
36using NodeRef = std::pair<NodeId, LaneBitmask>;
37
38} // namespace detail
39} // namespace rdf
40} // namespace llvm
41
42namespace std {
43
44template <> struct hash<llvm::rdf::detail::NodeRef> {
46 return std::hash<llvm::rdf::NodeId>{}(R.first) ^
47 std::hash<llvm::LaneBitmask::Type>{}(R.second.getAsInteger());
48 }
49};
50
51} // namespace std
52
53namespace llvm::rdf {
54
55struct Liveness {
56public:
59 using NodeRefSet = std::unordered_set<NodeRef>;
60 using RefMap = std::unordered_map<RegisterId, NodeRefSet>;
61
63 : DFG(g), TRI(g.getTRI()), PRI(g.getPRI()), MDT(g.getDT()),
64 MDF(g.getDF()), LiveMap(g.getPRI()), Empty(), NoRegs(g.getPRI()) {}
65
68 bool TopShadows, bool FullChain,
69 const RegisterAggr &DefRRs);
70
72 return getAllReachingDefs(RefA.Addr->getRegRef(DFG), RefA, false, false,
73 NoRegs);
74 }
75
77 return getAllReachingDefs(RefRR, RefA, false, false, NoRegs);
78 }
79
82 const RegisterAggr &DefRRs);
83
85 return getAllReachedUses(RefRR, DefA, NoRegs);
86 }
87
88 LLVM_ABI std::pair<NodeSet, bool>
90 NodeSet &Visited, const NodeSet &Defs);
91
94
95 LiveMapType &getLiveMap() { return LiveMap; }
96 const LiveMapType &getLiveMap() const { return LiveMap; }
97
98 const RefMap &getRealUses(NodeId P) const {
99 auto F = RealUseMap.find(P);
100 return F == RealUseMap.end() ? Empty : F->second;
101 }
102
105 LLVM_ABI void resetLiveIns();
106 LLVM_ABI void resetKills();
108
109 void trace(bool T) { Trace = T; }
110
111private:
112 const DataFlowGraph &DFG;
113 const TargetRegisterInfo &TRI;
114 const PhysicalRegisterInfo &PRI;
115 const MachineDominatorTree &MDT;
116 const MachineDominanceFrontier &MDF;
117 LiveMapType LiveMap;
118 const RefMap Empty;
119 const RegisterAggr NoRegs;
120 bool Trace = false;
121
122 // Cache of mapping from node ids (for RefNodes) to the containing
123 // basic blocks. Not computing it each time for each node reduces
124 // the liveness calculation time by a large fraction.
126
127 // Phi information:
128 //
129 // RealUseMap
130 // map: NodeId -> (map: RegisterId -> NodeRefSet)
131 // phi id -> (map: register -> set of reached non-phi uses)
132 DenseMap<NodeId, RefMap> RealUseMap;
133
134 // Inverse iterated dominance frontier.
135 std::map<MachineBasicBlock *, std::set<MachineBasicBlock *>> IIDF;
136
137 // Live on entry.
138 std::map<MachineBasicBlock *, RefMap> PhiLON;
139
140 // Phi uses are considered to be located at the end of the block that
141 // they are associated with. The reaching def of a phi use dominates the
142 // block that the use corresponds to, but not the block that contains
143 // the phi itself. To include these uses in the liveness propagation (up
144 // the dominator tree), create a map: block -> set of uses live on exit.
145 std::map<MachineBasicBlock *, RefMap> PhiLOX;
146
147 MachineBasicBlock *getBlockWithRef(NodeId RN) const;
148 void traverse(MachineBasicBlock *B, RefMap &LiveIn);
149 void emptify(RefMap &M);
150
151 std::pair<NodeSet, bool>
152 getAllReachingDefsRecImpl(RegisterRef RefRR, NodeAddr<RefNode *> RefA,
153 NodeSet &Visited, const NodeSet &Defs,
154 unsigned Nest, unsigned MaxNest);
155};
156
159
160} // end namespace llvm::rdf
161
162#endif // LLVM_CODEGEN_RDFLIVENESS_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
A common definition of LaneBitmask for use in TableGen and CodeGen.
#define F(x, y, z)
Definition MD5.cpp:54
Register const TargetRegisterInfo * TRI
#define T
#define P(N)
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
INLINE void g(uint32_t *state, size_t a, size_t b, size_t c, size_t d, uint32_t x, uint32_t y)
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
std::pair< NodeId, LaneBitmask > NodeRef
Definition RDFLiveness.h:36
Print(const T &, const DataFlowGraph &) -> Print< T >
uint32_t NodeId
Definition RDFGraph.h:262
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const Print< RegisterRef > &P)
Definition RDFGraph.cpp:44
std::set< NodeId > NodeSet
Definition RDFGraph.h:551
SmallVector< Node, 4 > NodeList
Definition RDFGraph.h:550
This is an optimization pass for GlobalISel generic memory operations.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:874
LiveMapType & getLiveMap()
Definition RDFLiveness.h:95
LLVM_ABI NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA, bool TopShadows, bool FullChain, const RegisterAggr &DefRRs)
std::unordered_set< NodeRef > NodeRefSet
Definition RDFLiveness.h:59
const RefMap & getRealUses(NodeId P) const
Definition RDFLiveness.h:98
LLVM_ABI 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...
RegisterAggrMap< MachineBasicBlock * > LiveMapType
Definition RDFLiveness.h:57
NodeList getAllReachingDefs(NodeAddr< RefNode * > RefA)
Definition RDFLiveness.h:71
Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
Definition RDFLiveness.h:62
LLVM_ABI void resetKills()
LLVM_ABI void resetLiveIns()
detail::NodeRef NodeRef
Definition RDFLiveness.h:58
LLVM_ABI void computePhiInfo()
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA)
Definition RDFLiveness.h:76
LLVM_ABI std::pair< NodeSet, bool > getAllReachingDefsRec(RegisterRef RefRR, NodeAddr< RefNode * > RefA, NodeSet &Visited, const NodeSet &Defs)
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr< DefNode * > DefA)
Definition RDFLiveness.h:84
LLVM_ABI void computeLiveIns()
void trace(bool T)
std::unordered_map< RegisterId, NodeRefSet > RefMap
Definition RDFLiveness.h:60
const LiveMapType & getLiveMap() const
Definition RDFLiveness.h:96
LLVM_ABI NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr< DefNode * > DefA, const RegisterAggr &DefRRs)
std::size_t operator()(llvm::rdf::detail::NodeRef R) const
Definition RDFLiveness.h:45