@@ -187,6 +187,65 @@ ABIPassingSegment ABIPassingSegment::OnStack(unsigned stackOffset, unsigned offs
187187 return segment;
188188}
189189
190+ // -----------------------------------------------------------------------------
191+ // ABIPassingInformation:
192+ // Construct an instance with the specified number of segments allocated in
193+ // the backing storage.
194+ //
195+ // Parameters:
196+ // comp - Compiler instance
197+ // numSegments - Number of segments
198+ //
199+ // Remarks:
200+ // The segments are expected to be filled out by the caller after the
201+ // allocation; they are not zeroed out by the allocation.
202+ //
203+ ABIPassingInformation::ABIPassingInformation (Compiler* comp, unsigned numSegments)
204+ {
205+ NumSegments = numSegments;
206+
207+ if (numSegments > 1 )
208+ {
209+ Segments = new (comp, CMK_ABI) ABIPassingSegment[numSegments];
210+ }
211+ }
212+
213+ // -----------------------------------------------------------------------------
214+ // Segment:
215+ // Access a segment by the specified index.
216+ //
217+ // Parameters:
218+ // index - The index of the segment
219+ //
220+ // Returns:
221+ // Reference to segment.
222+ //
223+ const ABIPassingSegment& ABIPassingInformation::Segment (unsigned index) const
224+ {
225+ assert (index < NumSegments);
226+ if (NumSegments == 1 )
227+ {
228+ return SingleSegment;
229+ }
230+
231+ return Segments[index];
232+ }
233+
234+ // -----------------------------------------------------------------------------
235+ // Segment:
236+ // Access a segment by the specified index.
237+ //
238+ // Parameters:
239+ // index - The index of the segment
240+ //
241+ // Returns:
242+ // Reference to segment.
243+ //
244+ ABIPassingSegment& ABIPassingInformation::Segment (unsigned index)
245+ {
246+ return const_cast <ABIPassingSegment&>(static_cast <const ABIPassingInformation&>(*this ).Segment (index));
247+ }
248+
190249// -----------------------------------------------------------------------------
191250// HasAnyRegisterSegment:
192251// Check if any part of this value is passed in a register.
@@ -198,7 +257,7 @@ bool ABIPassingInformation::HasAnyRegisterSegment() const
198257{
199258 for (unsigned i = 0 ; i < NumSegments; i++)
200259 {
201- if (Segments[i] .IsPassedInRegister ())
260+ if (Segment (i) .IsPassedInRegister ())
202261 {
203262 return true ;
204263 }
@@ -217,7 +276,7 @@ bool ABIPassingInformation::HasAnyStackSegment() const
217276{
218277 for (unsigned i = 0 ; i < NumSegments; i++)
219278 {
220- if (Segments[i] .IsPassedOnStack ())
279+ if (Segment (i) .IsPassedOnStack ())
221280 {
222281 return true ;
223282 }
@@ -234,7 +293,7 @@ bool ABIPassingInformation::HasAnyStackSegment() const
234293//
235294bool ABIPassingInformation::HasExactlyOneRegisterSegment () const
236295{
237- return (NumSegments == 1 ) && Segments[ 0 ] .IsPassedInRegister ();
296+ return (NumSegments == 1 ) && Segment ( 0 ) .IsPassedInRegister ();
238297}
239298
240299// -----------------------------------------------------------------------------
@@ -246,7 +305,7 @@ bool ABIPassingInformation::HasExactlyOneRegisterSegment() const
246305//
247306bool ABIPassingInformation::HasExactlyOneStackSegment () const
248307{
249- return (NumSegments == 1 ) && Segments[ 0 ] .IsPassedOnStack ();
308+ return (NumSegments == 1 ) && Segment ( 0 ) .IsPassedOnStack ();
250309}
251310
252311// -----------------------------------------------------------------------------
@@ -264,10 +323,10 @@ bool ABIPassingInformation::IsSplitAcrossRegistersAndStack() const
264323 return false ;
265324 }
266325
267- bool isFirstInReg = Segments[ 0 ] .IsPassedInRegister ();
326+ bool isFirstInReg = Segment ( 0 ) .IsPassedInRegister ();
268327 for (unsigned i = 1 ; i < NumSegments; i++)
269328 {
270- if (isFirstInReg != Segments[i] .IsPassedInRegister ())
329+ if (isFirstInReg != Segment (i) .IsPassedInRegister ())
271330 {
272331 return true ;
273332 }
@@ -288,7 +347,32 @@ bool ABIPassingInformation::IsSplitAcrossRegistersAndStack() const
288347//
289348ABIPassingInformation ABIPassingInformation::FromSegment (Compiler* comp, const ABIPassingSegment& segment)
290349{
291- return {1 , new (comp, CMK_ABI) ABIPassingSegment (segment)};
350+ ABIPassingInformation info;
351+ info.NumSegments = 1 ;
352+ info.SingleSegment = segment;
353+ return info;
354+ }
355+
356+ // -----------------------------------------------------------------------------
357+ // FromSegments:
358+ // Create ABIPassingInformation from two segments.
359+ //
360+ // Parameters:
361+ // comp - Compiler instance
362+ // firstSegment - The first segment that represents the passing information
363+ // secondSegment - The second segment that represents the passing information
364+ //
365+ // Return Value:
366+ // An instance of ABIPassingInformation.
367+ //
368+ ABIPassingInformation ABIPassingInformation::FromSegments (Compiler* comp,
369+ const ABIPassingSegment& firstSegment,
370+ const ABIPassingSegment& secondSegment)
371+ {
372+ ABIPassingInformation info;
373+ info.NumSegments = 2 ;
374+ info.Segments = new (comp, CMK_ABI) ABIPassingSegment[2 ]{firstSegment, secondSegment};
375+ return info;
292376}
293377
294378#ifdef DEBUG
@@ -310,9 +394,9 @@ void ABIPassingInformation::Dump() const
310394 printf (" [%u] " , i);
311395 }
312396
313- const ABIPassingSegment& seg = Segments[i] ;
397+ const ABIPassingSegment& seg = Segment (i) ;
314398
315- if (Segments[i] .IsPassedInRegister ())
399+ if (seg .IsPassedInRegister ())
316400 {
317401 printf (" [%02u..%02u) reg %s\n " , seg.Offset , seg.Offset + seg.Size , getRegName (seg.GetRegister ()));
318402 }
@@ -418,7 +502,7 @@ ABIPassingInformation SwiftABIClassifier::Classify(Compiler* comp,
418502
419503 for (unsigned j = 0 ; j < elemInfo.NumSegments ; j++)
420504 {
421- ABIPassingSegment newSegment = elemInfo.Segments [j] ;
505+ ABIPassingSegment newSegment = elemInfo.Segment (j) ;
422506 newSegment.Offset += lowering->offsets [i];
423507 // Adjust the tail size if necessary; the lowered sequence can
424508 // pass the tail as a larger type than the tail size.
@@ -427,12 +511,10 @@ ABIPassingInformation SwiftABIClassifier::Classify(Compiler* comp,
427511 }
428512 }
429513
430- ABIPassingInformation result;
431- result.NumSegments = static_cast <unsigned >(segments.Height ());
432- result.Segments = new (comp, CMK_ABI) ABIPassingSegment[result.NumSegments ];
514+ ABIPassingInformation result (comp, static_cast <unsigned >(segments.Height ()));
433515 for (int i = 0 ; i < segments.Height (); i++)
434516 {
435- result.Segments [i] = segments.Bottom (i);
517+ result.Segment (i) = segments.Bottom (i);
436518 }
437519
438520 return result;
0 commit comments