Skip to content

Commit 849a08a

Browse files
committed
[Xtensa] Change using of Frame Pointer.
Do not use Frame Pointer by default. Also improve storing function argument from a7 register to a8 register. Corrected funnel shift test. Closes llvm#19
1 parent 22aa883 commit 849a08a

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ static bool useFramePointerForTargetByDefault(const ArgList &Args,
533533
case llvm::Triple::riscv64:
534534
case llvm::Triple::amdgcn:
535535
case llvm::Triple::r600:
536+
case llvm::Triple::xtensa:
536537
return !areOptimizationsEnabled(Args);
537538
default:
538539
break;

llvm/lib/Target/Xtensa/XtensaFrameLowering.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "XtensaFrameLowering.h"
1616
#include "XtensaInstrInfo.h"
17+
#include "XtensaMachineFunctionInfo.h"
1718
#include "XtensaSubtarget.h"
1819
#include "llvm/CodeGen/MachineInstrBuilder.h"
1920
#include "llvm/CodeGen/MachineModuleInfo.h"
@@ -99,6 +100,7 @@ void XtensaFrameLowering::emitPrologue(MachineFunction &MF,
99100
unsigned FP = RegInfo->getFrameRegister(MF);
100101
MachineModuleInfo &MMI = MF.getMMI();
101102
const MCRegisterInfo *MRI = MMI.getContext().getRegisterInfo();
103+
XtensaFunctionInfo *XtensaFI = MF.getInfo<XtensaFunctionInfo>();
102104

103105
// First, compute final stack size.
104106
uint64_t StackSize = MFI.getStackSize();
@@ -130,9 +132,11 @@ void XtensaFrameLowering::emitPrologue(MachineFunction &MF,
130132

131133
// Store FP register in A8, because FP may be used to pass function
132134
// arguments
133-
BuildMI(MBB, MBBI, dl, TII.get(Xtensa::OR), Xtensa::A8)
134-
.addReg(FP)
135-
.addReg(FP);
135+
if (XtensaFI->isSaveFrameRegister()) {
136+
BuildMI(MBB, MBBI, dl, TII.get(Xtensa::OR), Xtensa::A8)
137+
.addReg(FP)
138+
.addReg(FP);
139+
}
136140

137141
// if framepointer enabled, set it to point to the stack pointer.
138142
if (hasFP(MF)) {

llvm/lib/Target/Xtensa/XtensaISelLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ SDValue XtensaTargetLowering::LowerFormalArguments(
786786
// so load argument from A8
787787
if (Subtarget.isWinABI() && (VA.getLocReg() == FrameReg)) {
788788
Reg = MF.addLiveIn(Xtensa::A8, RC);
789+
XtensaFI->setSaveFrameRegister();
789790
} else {
790791
Reg = MF.addLiveIn(VA.getLocReg(), RC);
791792
}
@@ -880,6 +881,7 @@ SDValue XtensaTargetLowering::LowerFormalArguments(
880881
// so load argument from A8
881882
if (ArgRegs[I] == FrameReg) {
882883
RegInfo.addLiveIn(Xtensa::A8, Reg);
884+
XtensaFI->setSaveFrameRegister();
883885
} else {
884886
RegInfo.addLiveIn(ArgRegs[I], Reg);
885887
}

llvm/lib/Target/Xtensa/XtensaMachineFunctionInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class XtensaFunctionInfo : public MachineFunctionInfo {
2727
unsigned VarArgsFirstGPR;
2828
int VarArgsStackOffset;
2929
unsigned VarArgsFrameIndex;
30+
bool SaveFrameRegister = false;
3031

3132
public:
3233
explicit XtensaFunctionInfo(MachineFunction &MF)
@@ -45,6 +46,9 @@ class XtensaFunctionInfo : public MachineFunctionInfo {
4546
unsigned getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
4647
void setVarArgsFrameIndex(unsigned FI) { VarArgsFrameIndex = FI; }
4748

49+
bool isSaveFrameRegister() const { return SaveFrameRegister; }
50+
void setSaveFrameRegister() { SaveFrameRegister = true; }
51+
4852
// TODO: large frame size definition should be specified more precisely
4953
bool isLargeFrame() {
5054
return (MF.getFrameInfo().estimateStackSize(MF) > 512) ? true : false;

llvm/test/CodeGen/Xtensa/funnel-shift.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ entry:
1111

1212
define dso_local i32 @test_fshl(i32 %value, i32 %shift) nounwind {
1313
; CHECK-LABEL: @test_fshl
14-
; CHECK: mov.n a8, a1
1514
; CHECK: movi.n a8, 32
1615
; CHECK: sub a8, a8, a3
1716
; CHECK: ssr a8

0 commit comments

Comments
 (0)