Skip to content

Commit 8536685

Browse files
committed
IP
1 parent 4ea5c60 commit 8536685

File tree

4 files changed

+26
-41
lines changed

4 files changed

+26
-41
lines changed

llvm/include/llvm/CodeGen/MachineFrameInfo.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,17 @@ class MachineFrameInfo {
638638
bool hasTailCall() const { return HasTailCall; }
639639
void setHasTailCall(bool V = true) { HasTailCall = V; }
640640

641-
/// Computes the maximum size of a callframe and the AdjustsStack property.
641+
/// Computes the maximum size of a callframe.
642642
/// This only works for targets defining
643643
/// TargetInstrInfo::getCallFrameSetupOpcode(), getCallFrameDestroyOpcode(),
644644
/// and getFrameSize().
645645
/// This is usually computed by the prologue epilogue inserter but some
646646
/// targets may call this to compute it earlier.
647-
void computeMaxCallFrameSize(const MachineFunction &MF);
647+
/// If FrameSDOps is passed, the frame instructions in the MF will be
648+
/// inserted into it.
649+
void computeMaxCallFrameSize(
650+
MachineFunction &MF,
651+
std::vector<MachineBasicBlock::iterator> *FrameSDOps = nullptr);
648652

649653
/// Return the maximum size of a call frame that must be
650654
/// allocated for an outgoing function call. This is only available if

llvm/lib/CodeGen/MachineFrameInfo.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,24 @@ uint64_t MachineFrameInfo::estimateStackSize(const MachineFunction &MF) const {
184184
return alignTo(Offset, StackAlign);
185185
}
186186

187-
void MachineFrameInfo::computeMaxCallFrameSize(const MachineFunction &MF) {
187+
void MachineFrameInfo::computeMaxCallFrameSize(
188+
MachineFunction &MF, std::vector<MachineBasicBlock::iterator> *FrameSDOps) {
188189
const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
189190
unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
190191
unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
191192
assert(FrameSetupOpcode != ~0u && FrameDestroyOpcode != ~0u &&
192193
"Can only compute MaxCallFrameSize if Setup/Destroy opcode are known");
193194

194195
MaxCallFrameSize = 0;
195-
for (const MachineBasicBlock &MBB : MF) {
196-
for (const MachineInstr &MI : MBB) {
196+
for (MachineBasicBlock &MBB : MF) {
197+
for (MachineInstr &MI : MBB) {
197198
unsigned Opcode = MI.getOpcode();
198199
if (Opcode == FrameSetupOpcode || Opcode == FrameDestroyOpcode) {
199200
unsigned Size = TII.getFrameSize(MI);
200201
MaxCallFrameSize = std::max(MaxCallFrameSize, Size);
201202
AdjustsStack = true;
202-
} else if (MI.isInlineAsm()) {
203-
// Some inline asm's need a stack frame, as indicated by operand 1.
204-
unsigned ExtraInfo = MI.getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
205-
if (ExtraInfo & InlineAsm::Extra_IsAlignStack)
206-
AdjustsStack = true;
203+
if (FrameSDOps != nullptr)
204+
FrameSDOps->push_back(&MI);
207205
}
208206
}
209207
}

llvm/lib/CodeGen/PrologEpilogInserter.cpp

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) {
228228
FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging(MF);
229229
ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
230230

231-
// Calculate the MaxCallFrameSize and AdjustsStack variables for the
232-
// function's frame information. Also eliminates call frame pseudo
233-
// instructions.
231+
// Calculate the MaxCallFrameSize value for the function's frame
232+
// information. Also eliminates call frame pseudo instructions.
234233
calculateCallFrameInfo(MF);
235234

236235
// Determine placement of CSR spill/restore code and prolog/epilog code:
@@ -350,17 +349,13 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) {
350349
return true;
351350
}
352351

353-
/// Calculate the MaxCallFrameSize and AdjustsStack
354-
/// variables for the function's frame information and eliminate call frame
355-
/// pseudo instructions.
352+
/// Calculate the MaxCallFrameSize variables for the function's frame
353+
/// information and eliminate call frame pseudo instructions.
356354
void PEI::calculateCallFrameInfo(MachineFunction &MF) {
357355
const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
358356
const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
359357
MachineFrameInfo &MFI = MF.getFrameInfo();
360358

361-
unsigned MaxCallFrameSize = 0;
362-
bool AdjustsStack = MFI.adjustsStack();
363-
364359
// Get the function call frame set-up and tear-down instruction opcode
365360
unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
366361
unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
@@ -370,26 +365,14 @@ void PEI::calculateCallFrameInfo(MachineFunction &MF) {
370365
if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
371366
return;
372367

368+
// (Re-)Compute the MaxCallFrameSize with some sanity checks.
369+
bool WasComputed = MFI.isMaxCallFrameSizeComputed();
370+
unsigned MaxCFSIn = MFI.getMaxCallFrameSize();
371+
bool AdjStackIn = MFI.adjustsStack();
373372
std::vector<MachineBasicBlock::iterator> FrameSDOps;
374-
for (MachineBasicBlock &BB : MF)
375-
for (MachineBasicBlock::iterator I = BB.begin(); I != BB.end(); ++I)
376-
if (TII.isFrameInstr(*I)) {
377-
unsigned Size = TII.getFrameSize(*I);
378-
if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
379-
AdjustsStack = true;
380-
FrameSDOps.push_back(I);
381-
} else if (I->isInlineAsm()) {
382-
// Some inline asm's need a stack frame, as indicated by operand 1.
383-
unsigned ExtraInfo = I->getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
384-
if (ExtraInfo & InlineAsm::Extra_IsAlignStack)
385-
AdjustsStack = true;
386-
}
387-
388-
assert(!MFI.isMaxCallFrameSizeComputed() ||
389-
(MFI.getMaxCallFrameSize() >= MaxCallFrameSize &&
390-
!(AdjustsStack && !MFI.adjustsStack())));
391-
MFI.setAdjustsStack(AdjustsStack);
392-
MFI.setMaxCallFrameSize(MaxCallFrameSize);
373+
MFI.computeMaxCallFrameSize(MF, &FrameSDOps);
374+
assert(!WasComputed || (MaxCFSIn >= MFI.getMaxCallFrameSize() &&
375+
!(!AdjStackIn && MFI.adjustsStack())));
393376

394377
if (TFI->canSimplifyCallFramePseudos(MF)) {
395378
// If call frames are not being included as part of the stack frame, and

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,12 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
670670

671671
for (const auto &MI : MBB) {
672672
const MCInstrDesc &MCID = TII->get(MI.getOpcode());
673-
if ((MCID.isCall() && !MCID.isReturn()) ||
674-
MI.isStackAligningInlineAsm()) {
673+
if ((MCID.isCall() && !MCID.isReturn()) || MI.isStackAligningInlineAsm())
675674
MFI.setHasCalls(true);
676-
}
677675
if (MI.isInlineAsm()) {
678676
MF->setHasInlineAsm(true);
677+
if (MI.isStackAligningInlineAsm())
678+
MFI.setAdjustsStack(true);
679679
}
680680
}
681681
}

0 commit comments

Comments
 (0)