-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[Xtensa] Implement vararg support. #117126
Conversation
174b461
to
d3db27e
Compare
unsigned RegSize = 4; | ||
MVT RegTy = MVT::getIntegerVT(RegSize * 8); |
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.
Just use MVT::i32 directly?
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.
XtensaFI->setVarArgsFirstGPR(Idx + 2); // 2 - number of a2 register | ||
|
||
XtensaFI->setVarArgsStackOffset(MFI.CreateFixedObject( | ||
PtrVT.getSizeInBits() / 8, CCInfo.getStackSize(), true)); |
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.
getStoreSize
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.
cast<StoreSDNode>(Store.getNode()) | ||
->getMemOperand() | ||
->setValue((Value *)nullptr); |
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.
You shouldn't be adjusting this after the creation of the store
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.
// to the vararg save area. | ||
for (unsigned I = Idx; I < ArgRegs.size(); ++I, VaArgOffset += RegSize) { | ||
const unsigned Reg = RegInfo.createVirtualRegister(RC); | ||
unsigned FrameReg = Subtarget.getRegisterInfo()->getFrameRegister(MF); |
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.
use Register, and pull out of loop
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.
I removed redundant code. Fixed.
@@ -304,13 +318,14 @@ SDValue XtensaTargetLowering::LowerFormalArguments( | |||
SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const { | |||
MachineFunction &MF = DAG.getMachineFunction(); | |||
MachineFrameInfo &MFI = MF.getFrameInfo(); | |||
XtensaMachineFunctionInfo *XtensaFI = MF.getInfo<XtensaMachineFunctionInfo>(); | |||
EVT PtrVT = getPointerTy(MF.getDataLayout()); |
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.
In context this probably should be getFrameIndexTy
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.
report_fatal_error("RegVT not supported by FormalArguments Lowering"); | ||
|
||
// Transform the arguments stored on | ||
// physical registers into virtual ones | ||
unsigned Register = MF.addLiveIn(VA.getLocReg(), RC); | ||
unsigned Register = MF.addLiveIn(VA.getLocReg(), &Xtensa::ARRegClass); |
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.
unsigned Register = MF.addLiveIn(VA.getLocReg(), &Xtensa::ARRegClass); | |
Register Reg = MF.addLiveIn(VA.getLocReg(), &Xtensa::ARRegClass); |
Use Register type and try to avoid shadowing type names with variable names
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.
Thank you very much for comments. Fixed.
static const MCPhysReg XtensaArgRegs[6] = { | ||
Xtensa::A2, Xtensa::A3, Xtensa::A4, Xtensa::A5, Xtensa::A6, Xtensa::A7}; | ||
ArrayRef<MCPhysReg> ArgRegs = ArrayRef(XtensaArgRegs); | ||
ArrayRef<MCPhysReg> ArgRegs = ArrayRef(IntRegs); | ||
unsigned Idx = CCInfo.getFirstUnallocated(ArgRegs); |
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.
Directly passing IntRegs to getFirstUnallocated should work I think
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
Fix variable names in XtensaMachineFunctionInfo class. Fix LowerFormalArguments function.
int VarArgsStackOffset; | ||
unsigned VarArgsFrameIndex; | ||
unsigned VarArgsOnStackFrameIndex; | ||
unsigned VarArgsInRegsFrameIndex; |
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.
unsigned VarArgsInRegsFrameIndex; | |
int VarArgsInRegsFrameIndex; |
Frame indexes are signed
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
@@ -43,12 +44,18 @@ class XtensaMachineFunctionInfo : public MachineFunctionInfo { | |||
unsigned getVarArgsFirstGPR() const { return VarArgsFirstGPR; } | |||
void setVarArgsFirstGPR(unsigned GPR) { VarArgsFirstGPR = GPR; } | |||
|
|||
int getVarArgsOnStackFrameIndex() const { return VarArgsStackOffset; } | |||
void setVarArgsOnStackFrameIndex(int Offset) { VarArgsStackOffset = Offset; } | |||
unsigned getVarArgsOnStackFrameIndex() const { |
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.
unsigned getVarArgsOnStackFrameIndex() const { | |
int getVarArgsOnStackFrameIndex() const { |
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
unsigned getVarArgsOnStackFrameIndex() const { | ||
return VarArgsOnStackFrameIndex; | ||
} | ||
void setVarArgsOnStackFrameIndex(unsigned FI) { |
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.
void setVarArgsOnStackFrameIndex(unsigned FI) { | |
void setVarArgsOnStackFrameIndex(int FI) { |
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.
Thank you. Fixed.
unsigned getVarArgsInRegsFrameIndex() const { | ||
return VarArgsInRegsFrameIndex; | ||
} | ||
void setVarArgsInRegsFrameIndex(unsigned FI) { VarArgsInRegsFrameIndex = FI; } |
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.
unsigned getVarArgsInRegsFrameIndex() const { | |
return VarArgsInRegsFrameIndex; | |
} | |
void setVarArgsInRegsFrameIndex(unsigned FI) { VarArgsInRegsFrameIndex = FI; } | |
int getVarArgsInRegsFrameIndex() const { | |
return VarArgsInRegsFrameIndex; | |
} | |
void setVarArgsInRegsFrameIndex(int FI) { VarArgsInRegsFrameIndex = FI; } |
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
|
||
SDValue StkIndex = | ||
DAG.getNode(ISD::ADD, DL, PtrVT, VAIndex, | ||
DAG.getConstant(32 + VASizeInBytes, DL, MVT::i32)); |
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.
Maybe should use getObjectPtrOffset in a follow up for all of these adds
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.
I added use of getObjectPtrOffset to access vararg struct fields.
Align ArgAlignment = TD.getPrefTypeAlign(VT.getTypeForEVT(*DAG.getContext())); | ||
unsigned ArgAlignInBytes = ArgAlignment.value(); | ||
unsigned ArgSizeInBytes = | ||
TD.getTypeAllocSize(VT.getTypeForEVT(*DAG.getContext())); |
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.
Don't repeat getTypeForEVT twice. I also find it more confusing to use query the type alloc size and the alignment. If you need the explicit alignment, do the alignment yourself
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
b0f50ea
to
ae7bff0
Compare
OrigIndex = DAG.getNode(ISD::ADD, DL, PtrVT, OrigIndex, | ||
DAG.getConstant(ArgAlignInBytes - 1, DL, MVT::i32)); | ||
OrigIndex = DAG.getNode(ISD::AND, DL, PtrVT, OrigIndex, | ||
DAG.getConstant(-ArgAlignInBytes, DL, MVT::i32)); |
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.
This will trigger an assertion. Signed constants should be created with getSignedConstant
.
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.
Thank you for comment. Fixed.
No description provided.