================
@@ -371,17 +371,25 @@ ABIArgInfo SparcV9ABIInfo::classifyType(QualType Ty, 
unsigned SizeLimit,
 
   CoerceBuilder CB(VMContext, getDataLayout());
   CB.addStruct(0, StrTy);
-  // All structs, even empty ones, should take up a register argument slot,
-  // so pin the minimum struct size to one bit.
-  CB.pad(llvm::alignTo(
-      std::max(CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue(), uint64_t(1)),
-      64));
+
+  // All structs, even empty ones, should take up a register argument slot, so
+  // pin the minimum struct size to one bit. However, empty structs don't take
+  // up any stack slot, so only do it on register arguments (i.e. the first
+  // six).
+  bool IsStackArgument = RegOffset > 5;
+  uint64_t ActualSize = CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue();
+  uint64_t ExpandedSize = std::max(ActualSize, uint64_t(1));
+  if (IsStackArgument)
+    ExpandedSize = ActualSize;
+
+  CB.pad(llvm::alignTo(ExpandedSize, 64));
   RegOffset += PaddingSlots + CB.Size / 64;
 
   // Try to use the original type for coercion.
   llvm::Type *CoerceTy = CB.isUsableType(StrTy) ? StrTy : CB.getType();
 
-  ABIArgInfo AAI = ABIArgInfo::getDirect(CoerceTy, 0, Padding);
+  ABIArgInfo AAI = ABIArgInfo::getDirect(CoerceTy, 0, Padding,
+                                         !IsStackArgument && ExpandedSize == 
0);
----------------
s-barannikov wrote:

If an argument should completely disappear from IR (an argument passed on the 
stack?), use `ABIArgInfo::getIgnore()`. I'm not sure what happens if one tries 
to take an address of a removed argument, but other targets seem to be fine 
with it.
Beware that "zero-sized structs" and "empty structs" are not always equivalent. 
See `CodeGen::isEmptyRecord()` if it can be a better fit.


https://github.com/llvm/llvm-project/pull/217065
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to