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_set>
22#include <utility>
23
24namespace llvm {
25
31
32namespace rdf {
33namespace detail {
34
35using NodeRef = std::pair<NodeId, LaneBitmask>;
36
37} // namespace detail
38} // namespace rdf
39} // namespace llvm
40
41namespace std {
42
43template <> struct hash<llvm::rdf::detail::NodeRef> {
45 return std::hash<llvm::rdf::NodeId>{}(R.first) ^
46 std::hash<llvm::LaneBitmask::Type>{}(R.second.getAsInteger());
47 }
48};
49
50} // namespace std
51
52namespace llvm::rdf {
53
54struct Liveness {
55public:
58 using NodeRefSet = std::unordered_set<NodeRef>;
60
62 : DFG(g), TRI(g.getTRI()), PRI(g.getPRI()), MDT(g.getDT()),
63 MDF(g.getDF()), LiveMap(g.getPRI()), Empty(), NoRegs(g.getPRI()) {}
64
67 bool TopShadows, bool FullChain,
68 const RegisterAggr &DefRRs);
69
71 return getAllReachingDefs(RefA.Addr->getRegRef(DFG), RefA, false, false,
72 NoRegs);
73 }
74
76 return getAllReachingDefs(RefRR, RefA, false, false, NoRegs);
77 }
78
81 const RegisterAggr &DefRRs);
82
84 return getAllReachedUses(RefRR, DefA, NoRegs);
85 }
86
87 LLVM_ABI std::pair<NodeSet, bool>
89 NodeSet &Visited, const NodeSet &Defs);
90
93
94 LiveMapType &getLiveMap() { return LiveMap; }
95 const LiveMapType &getLiveMap() const { return LiveMap; }
96
97 const RefMap &getRealUses(NodeId P) const {
98 auto F = RealUseMap.find(P);
99 return F == RealUseMap.end() ? Empty : F->second;
100 }
101
104 LLVM_ABI void resetLiveIns();
105 LLVM_ABI void resetKills();
107
108 void trace(bool T) { Trace = T; }
109
110private:
111 const DataFlowGraph &DFG;
112 const TargetRegisterInfo &TRI;
113 const PhysicalRegisterInfo &PRI;
114 const MachineDominatorTree &MDT;
115 const MachineDominanceFrontier &MDF;
116 LiveMapType LiveMap;
117 const RefMap Empty;
118 const RegisterAggr NoRegs;
119 bool Trace = false;
120
121 // Cache of mapping from node ids (for RefNodes) to the containing
122 // basic blocks. Not computing it each time for each node reduces
123 // the liveness calculation time by a large fraction.
125
126 // Phi information:
127 //
128 // RealUseMap
129 // map: NodeId -> (map: RegisterId -> NodeRefSet)
130 // phi id -> (map: register -> set of reached non-phi uses)
131 DenseMap<NodeId, RefMap> RealUseMap;
132
133 // Inverse iterated dominance frontier.
134 std::map<MachineBasicBlock *, std::set<MachineBasicBlock *>> IIDF;
135
136 // Live on entry.
137 std::map<MachineBasicBlock *, RefMap> PhiLON;
138
139 // Phi uses are considered to be located at the end of the block that
140 // they are associated with. The reaching def of a phi use dominates the
141 // block that the use corresponds to, but not the block that contains
142 // the phi itself. To include these uses in the liveness propagation (up
143 // the dominator tree), create a map: block -> set of uses live on exit.
144 std::map<MachineBasicBlock *, RefMap> PhiLOX;
145
146 MachineBasicBlock *getBlockWithRef(NodeId RN) const;
147 void traverse(MachineBasicBlock *B, RefMap &LiveIn);
148 void emptify(RefMap &M);
149
150 std::pair<NodeSet, bool>
151 getAllReachingDefsRecImpl(RegisterRef RefRR, NodeAddr<RefNode *> RefA,
152 NodeSet &Visited, const NodeSet &Defs,
153 unsigned Nest, unsigned MaxNest);
154};
155
158
159} // end namespace llvm::rdf
160
161#endif // LLVM_CODEGEN_RDFLIVENESS_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
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:35
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:860
LiveMapType & getLiveMap()
Definition RDFLiveness.h:94
LLVM_ABI NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA, bool TopShadows, bool FullChain, const RegisterAggr &DefRRs)
std::unordered_set< NodeRef > NodeRefSet
Definition RDFLiveness.h:58
const RefMap & getRealUses(NodeId P) const
Definition RDFLiveness.h:97
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:56
NodeList getAllReachingDefs(NodeAddr< RefNode * > RefA)
Definition RDFLiveness.h:70
Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
Definition RDFLiveness.h:61
LLVM_ABI void resetKills()
LLVM_ABI void resetLiveIns()
DenseMap< RegisterId, NodeRefSet > RefMap
Definition RDFLiveness.h:59
detail::NodeRef NodeRef
Definition RDFLiveness.h:57
LLVM_ABI void computePhiInfo()
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA)
Definition RDFLiveness.h:75
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:83
LLVM_ABI void computeLiveIns()
void trace(bool T)
const LiveMapType & getLiveMap() const
Definition RDFLiveness.h:95
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:44