LLVM: lib/CodeGen/CFIFixup.cpp 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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
69
84
85#include
86
87using namespace llvm;
88
89#define DEBUG_TYPE "cfi-fixup"
90
92
94 "Insert CFI remember/restore state instructions", false, false)
96
98 return MI.getOpcode() == TargetOpcode::CFI_INSTRUCTION &&
100}
101
104 return MI.getOpcode() == TargetOpcode::CFI_INSTRUCTION &&
106 });
107}
108
111
112
113
114
118 continue;
119 PrologueEnd = std::next(MI.getIterator());
120 return &MBB;
121 }
122 }
123 return nullptr;
124}
125
126
127
128
138
139
141
142
143
148 BlockInfo[0].Reachable = true;
149 BlockInfo[0].StrongNoFrameOnEntry = true;
150
151
155
156
157
158 bool HasPrologue = MBB == PrologueBlock;
159 bool HasEpilogue = false;
160
161 if (Info.HasFrameOnEntry || HasPrologue)
163
164
165
166
167 Info.HasFrameOnExit = (Info.HasFrameOnEntry || HasPrologue) && !HasEpilogue;
168
169
171 BlockFlags &SuccInfo = BlockInfo[Succ->getNumber()];
174 Info.StrongNoFrameOnEntry && !HasPrologue;
176 }
177 }
178
179 return BlockInfo;
180}
181
182
183
184
185
190
191
192
193
199
200
201 unsigned CFIIndex =
204 TII.get(TargetOpcode::CFI_INSTRUCTION))
206
207
209
210 return {RestoreInsertPt.MBB,
212 DebugLoc(), TII.get(TargetOpcode::CFI_INSTRUCTION))
215}
216
217
218
219
223
228 [&](const MachineInstr &MI) { return MF.CloneMachineInstr(&MI); });
230 ToClone.end());
231 };
232
233
235 cloneCfiInstructions(MBB.begin(), MBB.end());
236
237 cloneCfiInstructions(PrologueEnd.MBB->begin(), PrologueEnd.Iterator);
238 return DstInsertPt;
239}
240
241
242
243
244static bool
251
252 if (.Reachable)
253 return false;
254
255
256
258 return false;
259
260
261
263 BlockInfo[std::prev(CurrBB.getIterator())->getNumber()];
265 bool NeedsFrame = Info.HasFrameOnEntry && .StrongNoFrameOnEntry;
266
267#ifndef NDEBUG
268 if (.StrongNoFrameOnEntry) {
270 const BlockFlags &PredInfo = BlockInfo[Pred->getNumber()];
271 assert((!PredInfo.Reachable ||
272 Info.HasFrameOnEntry == PredInfo.HasFrameOnExit) &&
273 "Inconsistent call frame state");
274 }
275 }
276#endif
277
278 if (HasFrame == NeedsFrame)
279 return false;
280
281 if (!NeedsFrame) {
282
284 return true;
285 }
286
287
289 if (InsertPt.MBB == nullptr) {
290
291
292
294 } else {
295
296
297
298
300 }
301 return true;
302}
303
306 return false;
307
309 return false;
310
311
312
315 if (PrologueBlock == nullptr)
316 return false;
317
319
320
321
322
323
324 bool Change = false;
325
326
327
329 InsertionPts[PrologueBlock->getSectionID()] = {PrologueBlock, PrologueEnd};
330
331 assert(PrologueEnd != PrologueBlock->begin() &&
332 "Inconsistent notion of \"prologue block\"");
333
334
335
336
339 Change |=
340 fixupBlock(MBB, BlockInfo, InsertionPts, {PrologueBlock, PrologueEnd});
341 }
342
343 return Change;
344}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const TargetInstrInfo & TII
static InsertionPoint insertRememberRestorePair(const InsertionPoint &RememberInsertPt, const InsertionPoint &RestoreInsertPt)
Definition CFIFixup.cpp:195
static bool fixupBlock(MachineBasicBlock &CurrBB, const BlockFlagsVector &BlockInfo, SmallDenseMap< MBBSectionID, InsertionPoint > &InsertionPts, const InsertionPoint &Prologue)
Definition CFIFixup.cpp:245
static InsertionPoint cloneCfiPrologue(const InsertionPoint &PrologueEnd, const InsertionPoint &DstInsertPt)
Definition CFIFixup.cpp:220
static bool isPrologueCFIInstruction(const MachineInstr &MI)
Definition CFIFixup.cpp:97
static BlockFlagsVector computeBlockInfo(const MachineFunction &MF, const MachineBasicBlock *PrologueBlock)
Definition CFIFixup.cpp:145
static MachineBasicBlock * findPrologueEnd(MachineFunction &MF, MachineBasicBlock::iterator &PrologueEnd)
Definition CFIFixup.cpp:110
static bool containsEpilogue(const MachineBasicBlock &MBB)
Definition CFIFixup.cpp:102
SmallVector< BlockFlags, 32 > BlockFlagsVector
Definition CFIFixup.cpp:140
Contains definition of the base CFIFixup pass.
Analysis containing CSE Info
This file defines the DenseMap class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
This file defines the SmallVector class.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition CFIFixup.cpp:304
FunctionPass class - This class is used to implement most global optimizations.
static MCCFIInstruction createRememberState(MCSymbol *L, SMLoc Loc={})
.cfi_remember_state Save all current rules for all registers.
static MCCFIInstruction createRestoreState(MCSymbol *L, SMLoc Loc={})
.cfi_restore_state Restore the previously saved state.
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool isBeginSection() const
Returns true if this block begins any section.
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
unsigned addFrameInst(const MCCFIInstruction &Inst)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
Representation of each machine instruction.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Information about stack frame layout on the target.
virtual bool enableFullCFIFixup(const MachineFunction &MF) const
enableFullCFIFixup - Returns true if we may need to fix the unwind information such that it is accura...
virtual void resetCFIToInitialState(MachineBasicBlock &MBB) const
Emit CFI instructions that recreate the state of the unwind information upon function entry.
virtual bool enableCFIFixup(const MachineFunction &MF) const
Returns true if we may need to fix the unwind information for the function.
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
self_iterator getIterator()
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI FunctionPass * createCFIFixup()
Creates CFI Fixup pass.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto map_range(ContainerTy &&C, FuncTy F)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition CFIFixup.cpp:129
bool HasFrameOnEntry
Definition CFIFixup.cpp:132
bool HasFrameOnExit
Definition CFIFixup.cpp:133
bool StrongNoFrameOnEntry
Definition CFIFixup.cpp:131
BlockFlags()
Definition CFIFixup.cpp:134
bool Reachable
Definition CFIFixup.cpp:130
Definition CFIFixup.cpp:186
MachineBasicBlock::iterator Iterator
Definition CFIFixup.cpp:188
MachineBasicBlock * MBB
Definition CFIFixup.cpp:187