[llvm] [AMDGPU] Add support for the llvm.frameaddress intrinsic (PR #205588)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 23:44:16 PDT 2026


================
@@ -8705,6 +8770,26 @@ SDValue SITargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const {
   return DAG.getCopyFromReg(DAG.getEntryNode(), DL, Reg, VT);
 }
 
+SDValue SITargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const {
+  MVT VT = Op.getSimpleValueType();
+  SDLoc DL(Op);
+  if (Op.getConstantOperandVal(0) != 0)
+    return DAG.getConstant(0, DL, VT);
+
+  MachineFunction &MF = DAG.getMachineFunction();
+  const SIRegisterInfo *TRI = getSubtarget()->getRegisterInfo();
+  Register FrameReg = TRI->getFrameRegister(MF);
+
+  // Entry functions without a reserved FP have scratch base 0. Setting
+  // FrameAddressIsTaken here would force hasFP with FP_REG still unset.
+  if (MF.getInfo<SIMachineFunctionInfo>()->isEntryFunction() && !FrameReg)
+    return DAG.getConstant(0, DL, VT);
+
+  MF.getFrameInfo().setFrameAddressIsTaken(true);
+  FrameReg = TRI->getFrameRegister(MF);
----------------
arsenm wrote:

I thought getFrameRegister wasn't going to work since the function isn't fully determined at this point. It only works because you setFrameAddressIsTaken. You can more directly just use MFI->getFrameOffsetReg()

https://github.com/llvm/llvm-project/pull/205588


More information about the llvm-commits mailing list