Skip to content
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

Merged
merged 7 commits into from
Dec 12, 2024
Merged

Conversation

andreisfr
Copy link
Contributor

No description provided.

Comment on lines 404 to 405
unsigned RegSize = 4;
MVT RegTy = MVT::getIntegerVT(RegSize * 8);
Copy link
Contributor

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?

Copy link
Contributor Author

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getStoreSize

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 451 to 453
cast<StoreSDNode>(Store.getNode())
->getMemOperand()
->setValue((Value *)nullptr);
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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());
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned VarArgsInRegsFrameIndex;
int VarArgsInRegsFrameIndex;

Frame indexes are signed

Copy link
Contributor Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned getVarArgsOnStackFrameIndex() const {
int getVarArgsOnStackFrameIndex() const {

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void setVarArgsOnStackFrameIndex(unsigned FI) {
void setVarArgsOnStackFrameIndex(int FI) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Fixed.

Comment on lines 55 to 58
unsigned getVarArgsInRegsFrameIndex() const {
return VarArgsInRegsFrameIndex;
}
void setVarArgsInRegsFrameIndex(unsigned FI) { VarArgsInRegsFrameIndex = FI; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned getVarArgsInRegsFrameIndex() const {
return VarArgsInRegsFrameIndex;
}
void setVarArgsInRegsFrameIndex(unsigned FI) { VarArgsInRegsFrameIndex = FI; }
int getVarArgsInRegsFrameIndex() const {
return VarArgsInRegsFrameIndex;
}
void setVarArgsInRegsFrameIndex(int FI) { VarArgsInRegsFrameIndex = FI; }

Copy link
Contributor Author

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));
Copy link
Contributor

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

Copy link
Contributor Author

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()));
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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));
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@andreisfr andreisfr merged commit be4a183 into llvm:main Dec 12, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants