[llvm] [Xtensa] Lowering FRAMEADDR/RETURNADDR operations. (PR #107363)

Andrei Safronov via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 14:57:09 PDT 2024


================
@@ -594,6 +594,26 @@ SDValue XtensaTargetLowering::LowerSELECT_CC(SDValue Op,
                      FalseValue, TargetCC);
 }
 
+SDValue XtensaTargetLowering::LowerRETURNADDR(SDValue Op,
+                                              SelectionDAG &DAG) const {
+  // check the depth
+  // TODO: xtensa-gcc can handle this, by navigating through the stack, we
+  // should be able to do this too
+  assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) &&
+         "Return address can be determined only for current frame.");
+
+  MachineFunction &MF = DAG.getMachineFunction();
+  MachineFrameInfo &MFI = MF.getFrameInfo();
+  EVT VT = Op.getValueType();
+  unsigned RA = Xtensa::A0;
+  MFI.setReturnAddressIsTaken(true);
+
+  // Return RA, which contains the return address. Mark it an implicit
+  // live-in.
+  unsigned Register = MF.addLiveIn(RA, getRegClassFor(MVT::i32));
----------------
andreisfr wrote:

Fixed

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


More information about the llvm-commits mailing list