Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include "GCNSubtarget.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "SIMachineFunctionInfo.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/LiveRegUnits.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/RegisterScavenging.h"
#include "llvm/Target/TargetMachine.h"

Expand Down Expand Up @@ -619,6 +621,34 @@ void SIFrameLowering::emitEntryFunctionPrologue(MachineFunction &MF,

assert(MFI->isEntryFunction());

// Debug location must be unknown since the first debug location is used to
// determine the end of the prologue.
DebugLoc DL;
MachineBasicBlock::iterator I = MBB.begin();

if (MF.needsFrameMoves()) {
// On entry the SP/FP are not set up, so we need to define the CFA in terms
// of a literal location expression.
static const char CFAEncodedInstUserOpsArr[] = {
dwarf::DW_CFA_def_cfa_expression,
4, // length
static_cast<char>(dwarf::DW_OP_lit0),
static_cast<char>(dwarf::DW_OP_lit0 +
dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave),
static_cast<char>(dwarf::DW_OP_LLVM_user),
static_cast<char>(dwarf::DW_OP_LLVM_form_aspace_address)};
static StringRef CFAEncodedInstUserOps =
StringRef(CFAEncodedInstUserOpsArr, sizeof(CFAEncodedInstUserOpsArr));
buildCFI(MBB, I, DL,
MCCFIInstruction::createEscape(nullptr, CFAEncodedInstUserOps,
SMLoc(),
"CFA is 0 in private_wave aspace"));
// Unwinding halts when the return address (PC) is undefined.
buildCFI(MBB, I, DL,
MCCFIInstruction::createUndefined(
nullptr, TRI->getDwarfRegNum(AMDGPU::PC_REG, false)));
}

Register PreloadedScratchWaveOffsetReg = MFI->getPreloadedReg(
AMDGPUFunctionArgInfo::PRIVATE_SEGMENT_WAVE_BYTE_OFFSET);

Expand Down Expand Up @@ -655,11 +685,6 @@ void SIFrameLowering::emitEntryFunctionPrologue(MachineFunction &MF,
}
}

// Debug location must be unknown since the first debug location is used to
// determine the end of the prologue.
DebugLoc DL;
MachineBasicBlock::iterator I = MBB.begin();

// We found the SRSRC first because it needs four registers and has an
// alignment requirement. If the SRSRC that we found is clobbering with
// the scratch wave offset, which may be in a fixed SGPR or a free SGPR
Expand Down Expand Up @@ -2212,3 +2237,15 @@ bool SIFrameLowering::requiresStackPointerReference(
// references the SP, like variable sized stack objects.
return frameTriviallyRequiresSP(MFI);
}

MachineInstr *SIFrameLowering::buildCFI(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
const DebugLoc &DL,
const MCCFIInstruction &CFIInst,
MachineInstr::MIFlag flag) const {
MachineFunction &MF = *MBB.getParent();
const SIInstrInfo *TII = MF.getSubtarget<GCNSubtarget>().getInstrInfo();
return BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
.addCFIIndex(MF.addFrameInst(CFIInst))
.setMIFlag(flag);
}
6 changes: 6 additions & 0 deletions llvm/lib/Target/AMDGPU/SIFrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class SIFrameLowering final : public AMDGPUFrameLowering {
public:
bool requiresStackPointerReference(const MachineFunction &MF) const;

/// Create a CFI index for CFIInst and build a MachineInstr around it.
MachineInstr *
buildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
const DebugLoc &DL, const MCCFIInstruction &CFIInst,
MachineInstr::MIFlag flag = MachineInstr::FrameSetup) const;

// Returns true if the function may need to reserve space on the stack for the
// CWSR trap handler.
bool mayReserveScratchForCWSR(const MachineFunction &MF) const;
Expand Down
Loading
Loading