@@ -313,80 +313,87 @@ bool CallLowering::handleAssignments(CCState &CCInfo,
313
313
EVT VAVT = VA.getValVT ();
314
314
const LLT OrigTy = getLLTForType (*Args[i].Ty , DL);
315
315
316
- if (VA.isRegLoc ()) {
317
- if (Handler.isIncomingArgumentHandler () && VAVT != OrigVT) {
318
- if (VAVT.getSizeInBits () < OrigVT.getSizeInBits ()) {
319
- // Expected to be multiple regs for a single incoming arg.
320
- unsigned NumArgRegs = Args[i].Regs .size ();
321
- if (NumArgRegs < 2 )
322
- return false ;
323
-
324
- assert ((j + (NumArgRegs - 1 )) < ArgLocs.size () &&
325
- " Too many regs for number of args" );
326
- for (unsigned Part = 0 ; Part < NumArgRegs; ++Part) {
327
- // There should be Regs.size() ArgLocs per argument.
328
- VA = ArgLocs[j + Part];
329
- Handler.assignValueToReg (Args[i].Regs [Part], VA.getLocReg (), VA);
330
- }
331
- j += NumArgRegs - 1 ;
332
- // Merge the split registers into the expected larger result vreg
333
- // of the original call.
334
- MIRBuilder.buildMerge (Args[i].OrigRegs [0 ], Args[i].Regs );
335
- continue ;
336
- }
337
- const LLT VATy (VAVT.getSimpleVT ());
338
- Register NewReg =
339
- MIRBuilder.getMRI ()->createGenericVirtualRegister (VATy);
340
- Handler.assignValueToReg (NewReg, VA.getLocReg (), VA);
341
- // If it's a vector type, we either need to truncate the elements
342
- // or do an unmerge to get the lower block of elements.
343
- if (VATy.isVector () &&
344
- VATy.getNumElements () > OrigVT.getVectorNumElements ()) {
345
- // Just handle the case where the VA type is 2 * original type.
346
- if (VATy.getNumElements () != OrigVT.getVectorNumElements () * 2 ) {
347
- LLVM_DEBUG (dbgs ()
348
- << " Incoming promoted vector arg has too many elts" );
349
- return false ;
350
- }
351
- auto Unmerge = MIRBuilder.buildUnmerge ({OrigTy, OrigTy}, {NewReg});
352
- MIRBuilder.buildCopy (ArgReg, Unmerge.getReg (0 ));
353
- } else {
354
- MIRBuilder.buildTrunc (ArgReg, {NewReg}).getReg (0 );
316
+ // Expected to be multiple regs for a single incoming arg.
317
+ // There should be Regs.size() ArgLocs per argument.
318
+ unsigned NumArgRegs = Args[i].Regs .size ();
319
+
320
+ assert ((j + (NumArgRegs - 1 )) < ArgLocs.size () &&
321
+ " Too many regs for number of args" );
322
+ for (unsigned Part = 0 ; Part < NumArgRegs; ++Part) {
323
+ // There should be Regs.size() ArgLocs per argument.
324
+ VA = ArgLocs[j + Part];
325
+ if (VA.isMemLoc ()) {
326
+ // Don't currently support loading/storing a type that needs to be split
327
+ // to the stack. Should be easy, just not implemented yet.
328
+ if (NumArgRegs > 1 ) {
329
+ LLVM_DEBUG (
330
+ dbgs ()
331
+ << " Load/store a split arg to/from the stack not implemented yet\n " );
332
+ return false ;
355
333
}
356
- } else if (!Handler.isIncomingArgumentHandler ()) {
357
- assert ((j + (Args[i].Regs .size () - 1 )) < ArgLocs.size () &&
358
- " Too many regs for number of args" );
359
- // This is an outgoing argument that might have been split.
360
- for (unsigned Part = 0 ; Part < Args[i].Regs .size (); ++Part) {
361
- // There should be Regs.size() ArgLocs per argument.
362
- VA = ArgLocs[j + Part];
363
- Handler.assignValueToReg (Args[i].Regs [Part], VA.getLocReg (), VA);
334
+
335
+ // FIXME: Use correct address space for pointer size
336
+ EVT LocVT = VA.getValVT ();
337
+ unsigned MemSize = LocVT == MVT::iPTR ? DL.getPointerSize ()
338
+ : LocVT.getStoreSize ();
339
+ unsigned Offset = VA.getLocMemOffset ();
340
+ MachinePointerInfo MPO;
341
+ Register StackAddr = Handler.getStackAddress (MemSize, Offset, MPO);
342
+ Handler.assignValueToAddress (Args[i], StackAddr,
343
+ MemSize, MPO, VA);
344
+ continue ;
345
+ }
346
+
347
+ assert (VA.isRegLoc () && " custom loc should have been handled already" );
348
+
349
+ if (OrigVT.getSizeInBits () >= VAVT.getSizeInBits () ||
350
+ !Handler.isIncomingArgumentHandler ()) {
351
+ // This is an argument that might have been split. There should be
352
+ // Regs.size() ArgLocs per argument.
353
+
354
+ // Insert the argument copies. If VAVT < OrigVT, we'll insert the merge
355
+ // to the original register after handling all of the parts.
356
+ Handler.assignValueToReg (Args[i].Regs [Part], VA.getLocReg (), VA);
357
+ continue ;
358
+ }
359
+
360
+ // This ArgLoc covers multiple pieces, so we need to split it.
361
+ const LLT VATy (VAVT.getSimpleVT ());
362
+ Register NewReg =
363
+ MIRBuilder.getMRI ()->createGenericVirtualRegister (VATy);
364
+ Handler.assignValueToReg (NewReg, VA.getLocReg (), VA);
365
+ // If it's a vector type, we either need to truncate the elements
366
+ // or do an unmerge to get the lower block of elements.
367
+ if (VATy.isVector () &&
368
+ VATy.getNumElements () > OrigVT.getVectorNumElements ()) {
369
+ // Just handle the case where the VA type is 2 * original type.
370
+ if (VATy.getNumElements () != OrigVT.getVectorNumElements () * 2 ) {
371
+ LLVM_DEBUG (dbgs ()
372
+ << " Incoming promoted vector arg has too many elts" );
373
+ return false ;
364
374
}
365
- j += Args[i].Regs .size () - 1 ;
375
+ auto Unmerge = MIRBuilder.buildUnmerge ({OrigTy, OrigTy}, {NewReg});
376
+ MIRBuilder.buildCopy (ArgReg, Unmerge.getReg (0 ));
366
377
} else {
367
- Handler. assignValueToReg (ArgReg, VA. getLocReg (), VA );
378
+ MIRBuilder. buildTrunc (ArgReg, {NewReg}). getReg ( 0 );
368
379
}
369
- } else if (VA.isMemLoc ()) {
370
- // Don't currently support loading/storing a type that needs to be split
371
- // to the stack. Should be easy, just not implemented yet.
372
- if (Args[i].Regs .size () > 1 ) {
373
- LLVM_DEBUG (
374
- dbgs ()
375
- << " Load/store a split arg to/from the stack not implemented yet" );
376
- return false ;
380
+ }
381
+
382
+ // Now that all pieces have been handled, re-pack any arguments into any
383
+ // wider, original registers.
384
+ if (Handler.isIncomingArgumentHandler ()) {
385
+ if (VAVT.getSizeInBits () < OrigVT.getSizeInBits ()) {
386
+ assert (NumArgRegs >= 2 );
387
+
388
+ // Merge the split registers into the expected larger result vreg
389
+ // of the original call.
390
+ MIRBuilder.buildMerge (Args[i].OrigRegs [0 ], Args[i].Regs );
377
391
}
378
- MVT VT = MVT::getVT (Args[i].Ty );
379
- unsigned Size = VT == MVT::iPTR ? DL.getPointerSize ()
380
- : alignTo (VT.getSizeInBits (), 8 ) / 8 ;
381
- unsigned Offset = VA.getLocMemOffset ();
382
- MachinePointerInfo MPO;
383
- Register StackAddr = Handler.getStackAddress (Size , Offset, MPO);
384
- Handler.assignValueToAddress (Args[i], StackAddr, Size , MPO, VA);
385
- } else {
386
- // FIXME: Support byvals and other weirdness
387
- return false ;
388
392
}
393
+
394
+ j += NumArgRegs - 1 ;
389
395
}
396
+
390
397
return true ;
391
398
}
392
399
0 commit comments