@@ -116,32 +116,6 @@ findPrologueEnd(MachineFunction &MF, MachineBasicBlock::iterator &PrologueEnd) {
116
116
return nullptr ;
117
117
}
118
118
119
- // Inserts a `.cfi_remember_state` instruction before PrologueEnd and a
120
- // `.cfi_restore_state` instruction before DstInsertPt. Returns an iterator
121
- // to the first instruction after the inserted `.cfi_restore_state` instruction.
122
- static MachineBasicBlock::iterator
123
- insertRememberRestorePair (MachineBasicBlock::iterator RememberInsertPt,
124
- MachineBasicBlock::iterator RestoreInsertPt) {
125
- MachineBasicBlock *RememberMBB = RememberInsertPt->getParent ();
126
- MachineBasicBlock *RestoreMBB = RestoreInsertPt->getParent ();
127
- MachineFunction &MF = *RememberMBB->getParent ();
128
- const TargetInstrInfo &TII = *MF.getSubtarget ().getInstrInfo ();
129
-
130
- // Insert the `.cfi_remember_state` instruction.
131
- unsigned CFIIndex =
132
- MF.addFrameInst (MCCFIInstruction::createRememberState (nullptr ));
133
- BuildMI (*RememberMBB, RememberInsertPt, DebugLoc (),
134
- TII.get (TargetOpcode::CFI_INSTRUCTION))
135
- .addCFIIndex (CFIIndex);
136
-
137
- // Insert the `.cfi_restore_state` instruction.
138
- CFIIndex = MF.addFrameInst (MCCFIInstruction::createRestoreState (nullptr ));
139
- BuildMI (*RestoreMBB, RestoreInsertPt, DebugLoc (),
140
- TII.get (TargetOpcode::CFI_INSTRUCTION))
141
- .addCFIIndex (CFIIndex);
142
- return RestoreInsertPt;
143
- }
144
-
145
119
bool CFIFixup::runOnMachineFunction (MachineFunction &MF) {
146
120
const TargetFrameLowering &TFL = *MF.getSubtarget ().getFrameLowering ();
147
121
if (!TFL.enableCFIFixup (MF))
@@ -200,10 +174,12 @@ bool CFIFixup::runOnMachineFunction(MachineFunction &MF) {
200
174
// Every block inherits the frame state (as recorded in the unwind tables)
201
175
// of the previous block. If the intended frame state is different, insert
202
176
// compensating CFI instructions.
177
+ const TargetInstrInfo &TII = *MF.getSubtarget ().getInstrInfo ();
203
178
bool Change = false ;
204
179
// `InsertPt` always points to the point in a preceding block where we have to
205
180
// insert a `.cfi_remember_state`, in the case that the current block needs a
206
181
// `.cfi_restore_state`.
182
+ MachineBasicBlock *InsertMBB = PrologueBlock;
207
183
MachineBasicBlock::iterator InsertPt = PrologueEnd;
208
184
209
185
assert (InsertPt != PrologueBlock->begin () &&
@@ -234,10 +210,20 @@ bool CFIFixup::runOnMachineFunction(MachineFunction &MF) {
234
210
if (!Info.StrongNoFrameOnEntry && Info.HasFrameOnEntry && !HasFrame) {
235
211
// Reset to the "after prologue" state.
236
212
237
- // There's an earlier block known to have a stack frame. Insert a
238
- // `.cfi_remember_state` instruction into that block and a
239
- // `.cfi_restore_state` instruction at the beginning of the current block.
240
- InsertPt = insertRememberRestorePair (InsertPt, CurrBB->begin ());
213
+ // Insert a `.cfi_remember_state` into the last block known to have a
214
+ // stack frame.
215
+ unsigned CFIIndex =
216
+ MF.addFrameInst (MCCFIInstruction::createRememberState (nullptr ));
217
+ BuildMI (*InsertMBB, InsertPt, DebugLoc (),
218
+ TII.get (TargetOpcode::CFI_INSTRUCTION))
219
+ .addCFIIndex (CFIIndex);
220
+ // Insert a `.cfi_restore_state` at the beginning of the current block.
221
+ CFIIndex = MF.addFrameInst (MCCFIInstruction::createRestoreState (nullptr ));
222
+ InsertPt = BuildMI (*CurrBB, CurrBB->begin (), DebugLoc (),
223
+ TII.get (TargetOpcode::CFI_INSTRUCTION))
224
+ .addCFIIndex (CFIIndex);
225
+ ++InsertPt;
226
+ InsertMBB = &*CurrBB;
241
227
Change = true ;
242
228
} else if ((Info.StrongNoFrameOnEntry || !Info.HasFrameOnEntry ) &&
243
229
HasFrame) {
0 commit comments