LLVM: include/llvm/CodeGen/ReachingDefAnalysis.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef LLVM_CODEGEN_REACHINGDEFANALYSIS_H
22#define LLVM_CODEGEN_REACHINGDEFANALYSIS_H
23
31
32namespace llvm {
33
36
37
38
39
40
41class ReachingDef {
42 uintptr_t Encoded;
44 explicit ReachingDef(uintptr_t Encoded) : Encoded(Encoded) {}
45
46public:
48 ReachingDef(int Instr) : Encoded(((uintptr_t) Instr << 2) | 2) {}
49 operator int() const { return ((int) Encoded) >> 2; }
50};
51
52template<>
55
57 return reinterpret_cast<void *>(RD.Encoded);
58 }
59
63
67};
68
69
71public:
72 void init(unsigned NumBlockIDs) { AllReachingDefs.resize(NumBlockIDs); }
73
74 unsigned numBlockIDs() const { return AllReachingDefs.size(); }
75
77 AllReachingDefs[MBBNumber].resize(NumRegUnits);
78 }
79
80 void append(unsigned MBBNumber, MCRegUnit Unit, int Def) {
81 AllReachingDefs[MBBNumber][static_cast<unsigned>(Unit)].push_back(Def);
82 }
83
84 void prepend(unsigned MBBNumber, MCRegUnit Unit, int Def) {
85 auto &Defs = AllReachingDefs[MBBNumber][static_cast<unsigned>(Unit)];
86 Defs.insert(Defs.begin(), Def);
87 }
88
89 void replaceFront(unsigned MBBNumber, MCRegUnit Unit, int Def) {
90 assert(!AllReachingDefs[MBBNumber][static_cast<unsigned>(Unit)].empty());
91 *AllReachingDefs[MBBNumber][static_cast<unsigned>(Unit)].begin() = Def;
92 }
93
94 void clear() { AllReachingDefs.clear(); }
95
97 if (AllReachingDefs[MBBNumber].empty())
98
100 return AllReachingDefs[MBBNumber][static_cast<unsigned>(Unit)];
101 }
102
103private:
104
106
107 using MBBDefsInfo = std::vector;
108
109
111};
112
113
115private:
120 unsigned NumRegUnits = 0;
121 unsigned NumStackObjects = 0;
122 int ObjectIndexBegin = 0;
123
124
125
126
127 using LiveRegsDefInfo = std::vector;
128 LiveRegsDefInfo LiveRegs;
129
130
131
132
134 OutRegsInfoMap MBBOutRegsInfos;
135
136
137
138 int CurInstr = -1;
139
140
141
143
145
146
147
148
149 using MBBFrameObjsReachingDefsInfo =
151 MBBFrameObjsReachingDefsInfo MBBFrameObjsReachingDefs;
152
153
154 const int ReachingDefDefaultVal = -(1 << 21);
155
158
159public:
163
165 MachineFunctionAnalysisManager::Invalidator &);
166
170
171
173
174
176
177
179
180
181
182
184
185
187
188
189
191
192
193
196
197
198
200
201
202
204
205
206
208
209
210
212
213
214
216
217
219
220
221
223
224
225
227 InstSet &Uses) const;
228
229
230
232 BlockSet &VisitedBBs) const;
234
235
236
237
239
240
241
243
244
245
247 InstSet &Defs) const;
248
249
251
252
254
255
256
258
259
260
262
263
264
265
267 InstSet &Ignore) const;
268
269
270
272
273
274
275
277
278private:
279
281
282
284
285
287
288
290
291
292
294
295
296 template
298
299
300
301
304
305
306
308
309
310
311
313};
314
324
325
328
329public:
331
334
336};
337
340
341public:
343
345
350
353};
354
355}
356
357#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ReachingDefInfo InstSet InstSet & Ignore
ReachingDefInfo InstSet & ToRemove
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
Remove Loads Into Fake Uses
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
SmallVector< TraversedMBBInfo, 4 > TraversalOrder
Identifies basic blocks that are part of loops and should to be visited twice and returns efficient t...
void clear()
Definition ReachingDefAnalysis.h:94
void prepend(unsigned MBBNumber, MCRegUnit Unit, int Def)
Definition ReachingDefAnalysis.h:84
void replaceFront(unsigned MBBNumber, MCRegUnit Unit, int Def)
Definition ReachingDefAnalysis.h:89
ArrayRef< ReachingDef > defs(unsigned MBBNumber, MCRegUnit Unit) const
Definition ReachingDefAnalysis.h:96
void init(unsigned NumBlockIDs)
Definition ReachingDefAnalysis.h:72
void append(unsigned MBBNumber, MCRegUnit Unit, int Def)
Definition ReachingDefAnalysis.h:80
void startBasicBlock(unsigned MBBNumber, unsigned NumRegUnits)
Definition ReachingDefAnalysis.h:76
unsigned numBlockIDs() const
Definition ReachingDefAnalysis.h:74
MachineFunctionPass(char &ID)
Properties which a MachineFunction may have at a given point in time.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
A set of analyses that are preserved following a run of a transformation pass.
ReachingDefInfo Result
Definition ReachingDefAnalysis.h:320
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const ReachingDefInfo & getRDI() const
Definition ReachingDefAnalysis.h:352
ReachingDefInfoWrapperPass()
MachineFunctionProperties getRequiredProperties() const override
ReachingDefInfo & getRDI()
Definition ReachingDefAnalysis.h:351
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition ReachingDefAnalysis.h:349
static char ID
Definition ReachingDefAnalysis.h:342
This class provides the reaching def analysis.
Definition ReachingDefAnalysis.h:114
MachineInstr * getUniqueReachingMIDef(MachineInstr *MI, Register Reg) const
If a single MachineInstr creates the reaching definition, then return it.
bool isReachingDefLiveOut(MachineInstr *MI, Register Reg) const
Return whether the reaching def for MI also is live out of its parent block.
bool isSafeToMoveForwards(MachineInstr *From, MachineInstr *To) const
Return whether From can be moved forwards to just before To.
int getReachingDef(MachineInstr *MI, Register Reg) const
Provides the instruction id of the closest reaching def instruction of Reg that reaches MI,...
void run(MachineFunction &mf)
void getReachingLocalUses(MachineInstr *MI, Register Reg, InstSet &Uses) const
Provides the uses, in the same block as MI, of register that MI defines.
int getClearance(MachineInstr *MI, Register Reg) const
Provides the clearance - the number of instructions since the closest reaching def instuction of Reg ...
bool isRegDefinedAfter(MachineInstr *MI, Register Reg) const
Return whether the given register is defined after MI.
void init()
Initialize data structures.
void print(raw_ostream &OS)
bool hasLocalDefBefore(MachineInstr *MI, Register Reg) const
Provide whether the register has been defined in the same basic block as, and before,...
void reset()
Re-run the analysis.
void getGlobalUses(MachineInstr *MI, Register Reg, InstSet &Uses) const
Collect the users of the value stored in Reg, which is defined by MI.
MachineInstr * getMIOperand(MachineInstr *MI, unsigned Idx) const
If a single MachineInstr creates the reaching definition, for MIs operand at Idx, then return it.
void getLiveOuts(MachineBasicBlock *MBB, Register Reg, InstSet &Defs, BlockSet &VisitedBBs) const
Search MBB for a definition of Reg and insert it into Defs.
void traverse()
Traverse the machine function, mapping definitions.
bool isSafeToMoveBackwards(MachineInstr *From, MachineInstr *To) const
Return whether From can be moved backwards to just after To.
void collectKilledOperands(MachineInstr *MI, InstSet &Dead) const
Assuming MI is dead, recursively search the incoming operands which are killed by MI and collect thos...
bool hasSameReachingDef(MachineInstr *A, MachineInstr *B, Register Reg) const
Return whether A and B use the same def of Reg.
bool isRegUsedAfter(MachineInstr *MI, Register Reg) const
Return whether the given register is used after MI, whether it's a local use or a live out.
void getGlobalReachingDefs(MachineInstr *MI, Register Reg, InstSet &Defs) const
Collect all possible definitions of the value stored in Reg, which is used by MI.
bool isSafeToRemove(MachineInstr *MI, InstSet &ToRemove) const
Return whether removing this instruction will have no effect on the program, returning the redundant ...
ReachingDefInfo(ReachingDefInfo &&)
MachineInstr * getLocalLiveOutMIDef(MachineBasicBlock *MBB, Register Reg) const
Return the local MI that produces the live out value for Reg, or nullptr for a non-live out or non-lo...
bool invalidate(MachineFunction &F, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
bool getLiveInUses(MachineBasicBlock *MBB, Register Reg, InstSet &Uses) const
For the given block, collect the instructions that use the live-in value of the provided register.
bool isSafeToDefRegAt(MachineInstr *MI, Register Reg) const
Return whether a MachineInstr could be inserted at MI and safely define the given register without af...
ReachingDefPrinterPass(raw_ostream &OS)
Definition ReachingDefAnalysis.h:330
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
static bool isRequired()
Definition ReachingDefAnalysis.h:335
Thin wrapper around "int" used to store reaching definitions, using an encoding that makes it compati...
Definition ReachingDefAnalysis.h:41
ReachingDef(std::nullptr_t)
Definition ReachingDefAnalysis.h:47
ReachingDef(int Instr)
Definition ReachingDefAnalysis.h:48
Wrapper class representing virtual and physical registers.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
ArrayRef(const T &OneElt) -> ArrayRef< T >
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
A CRTP mix-in to automatically provide informational APIs needed for passes.
static ReachingDef getFromVoidPointer(const void *P)
Definition ReachingDefAnalysis.h:64
static constexpr int NumLowBitsAvailable
Definition ReachingDefAnalysis.h:54
static ReachingDef getFromVoidPointer(void *P)
Definition ReachingDefAnalysis.h:60
static void * getAsVoidPointer(const ReachingDef &RD)
Definition ReachingDefAnalysis.h:56
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...