@@ -594,6 +594,26 @@ SDValue XtensaTargetLowering::LowerSELECT_CC(SDValue Op,
594
594
FalseValue, TargetCC);
595
595
}
596
596
597
+ SDValue XtensaTargetLowering::LowerRETURNADDR (SDValue Op,
598
+ SelectionDAG &DAG) const {
599
+ // check the depth
600
+ // TODO: xtensa-gcc can handle this, by navigating through the stack, we
601
+ // should be able to do this too
602
+ assert ((cast<ConstantSDNode>(Op.getOperand (0 ))->getZExtValue () == 0 ) &&
603
+ " Return address can be determined only for current frame." );
604
+
605
+ MachineFunction &MF = DAG.getMachineFunction ();
606
+ MachineFrameInfo &MFI = MF.getFrameInfo ();
607
+ EVT VT = Op.getValueType ();
608
+ unsigned RA = Xtensa::A0;
609
+ MFI.setReturnAddressIsTaken (true );
610
+
611
+ // Return RA, which contains the return address. Mark it an implicit
612
+ // live-in.
613
+ unsigned Register = MF.addLiveIn (RA, getRegClassFor (MVT::i32 ));
614
+ return DAG.getCopyFromReg (DAG.getEntryNode (), SDLoc (Op), Register, VT);
615
+ }
616
+
597
617
SDValue XtensaTargetLowering::LowerImmediate (SDValue Op,
598
618
SelectionDAG &DAG) const {
599
619
const ConstantSDNode *CN = cast<ConstantSDNode>(Op);
@@ -722,6 +742,24 @@ SDValue XtensaTargetLowering::LowerSTACKRESTORE(SDValue Op,
722
742
Op.getOperand (1 ));
723
743
}
724
744
745
+ SDValue XtensaTargetLowering::LowerFRAMEADDR (SDValue Op,
746
+ SelectionDAG &DAG) const {
747
+ // check the depth
748
+ assert ((cast<ConstantSDNode>(Op.getOperand (0 ))->getZExtValue () == 0 ) &&
749
+ " Frame address can only be determined for current frame." );
750
+
751
+ MachineFunction &MF = DAG.getMachineFunction ();
752
+ MachineFrameInfo &MFI = DAG.getMachineFunction ().getFrameInfo ();
753
+ MFI.setFrameAddressIsTaken (true );
754
+ EVT VT = Op.getValueType ();
755
+ SDLoc DL (Op);
756
+
757
+ unsigned FrameRegister = Subtarget.getRegisterInfo ()->getFrameRegister (MF);
758
+ SDValue FrameAddr =
759
+ DAG.getCopyFromReg (DAG.getEntryNode (), DL, FrameRegister, VT);
760
+ return FrameAddr;
761
+ }
762
+
725
763
SDValue XtensaTargetLowering::LowerDYNAMIC_STACKALLOC (SDValue Op,
726
764
SelectionDAG &DAG) const {
727
765
SDValue Chain = Op.getOperand (0 ); // Legalize the chain.
@@ -867,6 +905,8 @@ SDValue XtensaTargetLowering::LowerOperation(SDValue Op,
867
905
return LowerBR_JT (Op, DAG);
868
906
case ISD::Constant:
869
907
return LowerImmediate (Op, DAG);
908
+ case ISD::RETURNADDR:
909
+ return LowerRETURNADDR (Op, DAG);
870
910
case ISD::GlobalAddress:
871
911
return LowerGlobalAddress (Op, DAG);
872
912
case ISD::BlockAddress:
@@ -883,6 +923,8 @@ SDValue XtensaTargetLowering::LowerOperation(SDValue Op,
883
923
return LowerSTACKSAVE (Op, DAG);
884
924
case ISD::STACKRESTORE:
885
925
return LowerSTACKRESTORE (Op, DAG);
926
+ case ISD::FRAMEADDR:
927
+ return LowerFRAMEADDR (Op, DAG);
886
928
case ISD::DYNAMIC_STACKALLOC:
887
929
return LowerDYNAMIC_STACKALLOC (Op, DAG);
888
930
case ISD::SHL_PARTS:
0 commit comments