Skip to content

Commit db83d31

Browse files
[AArch64][DebugInfo]Add Target hooks for InstrRef on AArch64
According to llvm/docs/InstrRefDebugInfo.md, to support proper instruction referecing on any platform, the target specific `TargetInstrInfo::isLoadFromStackSlotPostFE` and `TargetInstrInfo::isStoreToStackSlotPostFE` functions are needed to be implemented for the Instruction Reference-based LiveDebugValues pass to identify spill and restore instructions. This patch is attempting to reland #162327
1 parent 290ff95 commit db83d31

File tree

4 files changed

+380
-22
lines changed

4 files changed

+380
-22
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,11 +2392,10 @@ bool AArch64InstrInfo::isFPRCopy(const MachineInstr &MI) {
23922392
return false;
23932393
}
23942394

2395-
Register AArch64InstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
2396-
int &FrameIndex) const {
2397-
switch (MI.getOpcode()) {
2395+
static bool isFrameLoadOpcode(int Opcode) {
2396+
switch (Opcode) {
23982397
default:
2399-
break;
2398+
return false;
24002399
case AArch64::LDRWui:
24012400
case AArch64::LDRXui:
24022401
case AArch64::LDRBui:
@@ -2405,22 +2404,27 @@ Register AArch64InstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
24052404
case AArch64::LDRDui:
24062405
case AArch64::LDRQui:
24072406
case AArch64::LDR_PXI:
2408-
if (MI.getOperand(0).getSubReg() == 0 && MI.getOperand(1).isFI() &&
2409-
MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) {
2410-
FrameIndex = MI.getOperand(1).getIndex();
2411-
return MI.getOperand(0).getReg();
2412-
}
2413-
break;
2407+
return true;
24142408
}
2409+
}
24152410

2416-
return 0;
2411+
Register AArch64InstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
2412+
int &FrameIndex) const {
2413+
if (!isFrameLoadOpcode(MI.getOpcode()))
2414+
return Register();
2415+
2416+
if (MI.getOperand(0).getSubReg() == 0 && MI.getOperand(1).isFI() &&
2417+
MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) {
2418+
FrameIndex = MI.getOperand(1).getIndex();
2419+
return MI.getOperand(0).getReg();
2420+
}
2421+
return Register();
24172422
}
24182423

2419-
Register AArch64InstrInfo::isStoreToStackSlot(const MachineInstr &MI,
2420-
int &FrameIndex) const {
2421-
switch (MI.getOpcode()) {
2424+
static bool isFrameStoreOpcode(int Opcode) {
2425+
switch (Opcode) {
24222426
default:
2423-
break;
2427+
return false;
24242428
case AArch64::STRWui:
24252429
case AArch64::STRXui:
24262430
case AArch64::STRBui:
@@ -2429,14 +2433,56 @@ Register AArch64InstrInfo::isStoreToStackSlot(const MachineInstr &MI,
24292433
case AArch64::STRDui:
24302434
case AArch64::STRQui:
24312435
case AArch64::STR_PXI:
2432-
if (MI.getOperand(0).getSubReg() == 0 && MI.getOperand(1).isFI() &&
2433-
MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) {
2434-
FrameIndex = MI.getOperand(1).getIndex();
2435-
return MI.getOperand(0).getReg();
2436-
}
2437-
break;
2436+
return true;
24382437
}
2439-
return 0;
2438+
}
2439+
2440+
Register AArch64InstrInfo::isStoreToStackSlot(const MachineInstr &MI,
2441+
int &FrameIndex) const {
2442+
if (!isFrameStoreOpcode(MI.getOpcode()))
2443+
return Register();
2444+
2445+
if (MI.getOperand(0).getSubReg() == 0 && MI.getOperand(1).isFI() &&
2446+
MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) {
2447+
FrameIndex = MI.getOperand(1).getIndex();
2448+
return MI.getOperand(0).getReg();
2449+
}
2450+
return Register();
2451+
}
2452+
2453+
Register AArch64InstrInfo::isStoreToStackSlotPostFE(const MachineInstr &MI,
2454+
int &FrameIndex) const {
2455+
if (!isFrameStoreOpcode(MI.getOpcode()))
2456+
return Register();
2457+
2458+
SmallVector<const MachineMemOperand *, 1> Accesses;
2459+
if (Register Reg = isStoreToStackSlot(MI, FrameIndex))
2460+
return Reg;
2461+
2462+
if (hasStoreToStackSlot(MI, Accesses)) {
2463+
FrameIndex =
2464+
cast<FixedStackPseudoSourceValue>(Accesses.front()->getPseudoValue())
2465+
->getFrameIndex();
2466+
return MI.getOperand(0).getReg();
2467+
}
2468+
return Register();
2469+
}
2470+
2471+
Register AArch64InstrInfo::isLoadFromStackSlotPostFE(const MachineInstr &MI,
2472+
int &FrameIndex) const {
2473+
if (!isFrameLoadOpcode(MI.getOpcode()))
2474+
return Register();
2475+
2476+
if (Register Reg = isLoadFromStackSlot(MI, FrameIndex))
2477+
return Reg;
2478+
SmallVector<const MachineMemOperand *, 1> Accesses;
2479+
if (hasLoadFromStackSlot(MI, Accesses)) {
2480+
FrameIndex =
2481+
cast<FixedStackPseudoSourceValue>(Accesses.front()->getPseudoValue())
2482+
->getFrameIndex();
2483+
return MI.getOperand(0).getReg();
2484+
}
2485+
return Register();
24402486
}
24412487

24422488
/// Check all MachineMemOperands for a hint to suppress pairing.

llvm/lib/Target/AArch64/AArch64InstrInfo.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ class AArch64InstrInfo final : public AArch64GenInstrInfo {
205205
Register isStoreToStackSlot(const MachineInstr &MI,
206206
int &FrameIndex) const override;
207207

208+
/// Check for post-frame ptr elimination stack locations as well. This uses a
209+
/// heuristic so it isn't reliable for correctness.
210+
Register isStoreToStackSlotPostFE(const MachineInstr &MI,
211+
int &FrameIndex) const override;
212+
/// Check for post-frame ptr elimination stack locations as well. This uses a
213+
/// heuristic so it isn't reliable for correctness.
214+
Register isLoadFromStackSlotPostFE(const MachineInstr &MI,
215+
int &FrameIndex) const override;
216+
208217
/// Does this instruction set its full destination register to zero?
209218
static bool isGPRZero(const MachineInstr &MI);
210219

0 commit comments

Comments
 (0)