@@ -138,32 +138,38 @@ ABIPassingInformation RiscV64Classifier::Classify(Compiler* comp,
138138 else
139139 {
140140 // Integer calling convention
141- auto passSlot = [this ](unsigned offset, unsigned size) -> ABIPassingSegment {
141+ auto passOnStack = [this ](unsigned offset, unsigned size) -> ABIPassingSegment {
142142 assert (size > 0 );
143- assert (size <= TARGET_POINTER_SIZE);
144- if (m_intRegs.Count () > 0 )
143+ assert (size <= 2 * TARGET_POINTER_SIZE);
144+ assert ((m_stackArgSize % TARGET_POINTER_SIZE) == 0 );
145+ ABIPassingSegment seg = ABIPassingSegment::OnStack (m_stackArgSize, offset, size);
146+ m_stackArgSize += (size > TARGET_POINTER_SIZE) ? (2 * TARGET_POINTER_SIZE) : TARGET_POINTER_SIZE;
147+ return seg;
148+ };
149+
150+ if (m_intRegs.Count () > 0 )
151+ {
152+ if (passedSize <= TARGET_POINTER_SIZE)
145153 {
146- return ABIPassingSegment::InRegister (m_intRegs.Dequeue (), offset, size);
154+ ABIPassingSegment seg = ABIPassingSegment::InRegister (m_intRegs.Dequeue (), 0 , passedSize);
155+ return ABIPassingInformation::FromSegment (comp, seg);
147156 }
148157 else
149158 {
150- assert ((m_stackArgSize % TARGET_POINTER_SIZE) == 0 );
151- ABIPassingSegment seg = ABIPassingSegment::OnStack (m_stackArgSize, offset, size);
152- m_stackArgSize += TARGET_POINTER_SIZE;
153- return seg;
159+ assert (varTypeIsStruct (type));
160+ unsigned int tailSize = passedSize - TARGET_POINTER_SIZE;
161+
162+ ABIPassingSegment head = ABIPassingSegment::InRegister (m_intRegs.Dequeue (), 0 , TARGET_POINTER_SIZE);
163+ ABIPassingSegment tail =
164+ (m_intRegs.Count () > 0 )
165+ ? ABIPassingSegment::InRegister (m_intRegs.Dequeue (), TARGET_POINTER_SIZE, tailSize)
166+ : passOnStack (TARGET_POINTER_SIZE, tailSize);
167+ return {2 , new (comp, CMK_ABI) ABIPassingSegment[2 ]{head, tail}};
154168 }
155- };
156-
157- if (passedSize <= TARGET_POINTER_SIZE)
158- {
159- return ABIPassingInformation::FromSegment (comp, passSlot (0 , passedSize));
160169 }
161170 else
162171 {
163- assert (varTypeIsStruct (type));
164- return {2 , new (comp, CMK_ABI)
165- ABIPassingSegment[2 ]{passSlot (0 , TARGET_POINTER_SIZE),
166- passSlot (TARGET_POINTER_SIZE, passedSize - TARGET_POINTER_SIZE)}};
172+ return ABIPassingInformation::FromSegment (comp, passOnStack (0 , passedSize));
167173 }
168174 }
169175}
0 commit comments