-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Xtensa] Lowering FRAMEADDR/RETURNADDR operations. #107363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -594,6 +594,27 @@ SDValue XtensaTargetLowering::LowerSELECT_CC(SDValue Op, | |||||
FalseValue, TargetCC); | ||||||
} | ||||||
|
||||||
SDValue XtensaTargetLowering::LowerRETURNADDR(SDValue Op, | ||||||
SelectionDAG &DAG) const { | ||||||
// This nodes represent llvm.returnaddress on the DAG. | ||||||
// It takes one operand, the index of the return address to return. | ||||||
// An index of zero corresponds to the current function's return address. | ||||||
// An index of one to the parent's return address, and so on. | ||||||
// Depths > 0 not supported yet! | ||||||
if (Op.getConstantOperandVal(0) > 0) | ||||||
return SDValue(); | ||||||
|
||||||
MachineFunction &MF = DAG.getMachineFunction(); | ||||||
MachineFrameInfo &MFI = MF.getFrameInfo(); | ||||||
EVT VT = Op.getValueType(); | ||||||
MFI.setReturnAddressIsTaken(true); | ||||||
|
||||||
// Return RA, which contains the return address. Mark it an implicit | ||||||
// live-in. | ||||||
Register RA = MF.addLiveIn(Xtensa::A0, getRegClassFor(MVT::i32)); | ||||||
return DAG.getCopyFromReg(DAG.getEntryNode(), SDLoc(Op), RA, VT); | ||||||
} | ||||||
|
||||||
SDValue XtensaTargetLowering::LowerImmediate(SDValue Op, | ||||||
SelectionDAG &DAG) const { | ||||||
const ConstantSDNode *CN = cast<ConstantSDNode>(Op); | ||||||
|
@@ -722,6 +743,28 @@ SDValue XtensaTargetLowering::LowerSTACKRESTORE(SDValue Op, | |||||
Op.getOperand(1)); | ||||||
} | ||||||
|
||||||
SDValue XtensaTargetLowering::LowerFRAMEADDR(SDValue Op, | ||||||
SelectionDAG &DAG) const { | ||||||
// This nodes represent llvm.frameaddress on the DAG. | ||||||
// It takes one operand, the index of the frame address to return. | ||||||
// An index of zero corresponds to the current function's frame address. | ||||||
// An index of one to the parent's frame address, and so on. | ||||||
// Depths > 0 not supported yet! | ||||||
if (Op.getConstantOperandVal(0) > 0) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. != 0 |
||||||
return SDValue(); | ||||||
|
||||||
MachineFunction &MF = DAG.getMachineFunction(); | ||||||
MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||
MFI.setFrameAddressIsTaken(true); | ||||||
EVT VT = Op.getValueType(); | ||||||
SDLoc DL(Op); | ||||||
|
||||||
Register FrameRegister = Subtarget.getRegisterInfo()->getFrameRegister(MF); | ||||||
SDValue FrameAddr = | ||||||
DAG.getCopyFromReg(DAG.getEntryNode(), DL, FrameRegister, VT); | ||||||
return FrameAddr; | ||||||
} | ||||||
|
||||||
SDValue XtensaTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, | ||||||
SelectionDAG &DAG) const { | ||||||
SDValue Chain = Op.getOperand(0); // Legalize the chain. | ||||||
|
@@ -867,6 +910,8 @@ SDValue XtensaTargetLowering::LowerOperation(SDValue Op, | |||||
return LowerBR_JT(Op, DAG); | ||||||
case ISD::Constant: | ||||||
return LowerImmediate(Op, DAG); | ||||||
case ISD::RETURNADDR: | ||||||
return LowerRETURNADDR(Op, DAG); | ||||||
case ISD::GlobalAddress: | ||||||
return LowerGlobalAddress(Op, DAG); | ||||||
case ISD::BlockAddress: | ||||||
|
@@ -883,6 +928,8 @@ SDValue XtensaTargetLowering::LowerOperation(SDValue Op, | |||||
return LowerSTACKSAVE(Op, DAG); | ||||||
case ISD::STACKRESTORE: | ||||||
return LowerSTACKRESTORE(Op, DAG); | ||||||
case ISD::FRAMEADDR: | ||||||
return LowerFRAMEADDR(Op, DAG); | ||||||
case ISD::DYNAMIC_STACKALLOC: | ||||||
return LowerDYNAMIC_STACKALLOC(Op, DAG); | ||||||
case ISD::SHL_PARTS: | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc -mtriple=xtensa < %s \ | ||
; RUN: | FileCheck %s | ||
|
||
declare ptr @llvm.frameaddress(i32) | ||
declare ptr @llvm.returnaddress(i32) | ||
|
||
define ptr @test_frameaddress_0() nounwind { | ||
; CHECK-LABEL: test_frameaddress_0: | ||
; CHECK: or a2, a1, a1 | ||
; CHECK-NEXT: ret | ||
%frameaddr = call ptr @llvm.frameaddress(i32 0) | ||
ret ptr %frameaddr | ||
} | ||
|
||
define ptr @test_returnaddress_0() nounwind { | ||
; CHECK-LABEL: test_returnaddress_0: | ||
; CHECK: or a2, a0, a0 | ||
; CHECK-NEXT: ret | ||
%retaddr = call ptr @llvm.returnaddress(i32 0) | ||
ret ptr %retaddr | ||
} | ||
|
||
define ptr @test_frameaddress_1() nounwind { | ||
; CHECK-LABEL: test_frameaddress_1: | ||
; CHECK: movi a2, 0 | ||
; CHECK-NEXT: ret | ||
%frameaddr = call ptr @llvm.frameaddress(i32 1) | ||
ret ptr %frameaddr | ||
} | ||
|
||
define ptr @test_returnaddress_1() nounwind { | ||
; CHECK-LABEL: test_returnaddress_1: | ||
; CHECK: movi a2, 0 | ||
; CHECK-NEXT: ret | ||
%retaddr = call ptr @llvm.returnaddress(i32 1) | ||
ret ptr %retaddr | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test the non-0 cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added new tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!= 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed