[llvm] [ABI] Add DefaultTargetInfo for default argument/return classification (PR #225009)

Konstantinos Parasyris via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 06:46:28 PDT 2026


================
@@ -0,0 +1,62 @@
+//===- DefaultTargetInfo.cpp - Default ABI classification -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ABI/DefaultTargetInfo.h"
+#include "llvm/Support/Casting.h"
+
+using namespace llvm::abi;
+using llvm::dyn_cast;
+
+ArgInfo DefaultTargetInfo::classifyArgumentType(const Type *Ty) const {
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  if (isAggregateTypeForABI(Ty)) {
+    // Records with non-trivial destructors/copy-constructors should not be
+    // passed by value.
+    if (RecordArgABI RAA = getRecordArgABI(Ty))
+      return getNaturalAlignIndirect(Ty, /*ByVal=*/RAA == RAA_DirectInMemory);
+    return getNaturalAlignIndirect(Ty);
+  }
+
+  if (const auto *IT = dyn_cast<IntegerType>(Ty)) {
+    // A _BitInt too wide for the largest integer register goes indirect.
+    if (IT->isBitInt() &&
+        IT->getSizeInBits().getFixedValue() > getBitIntRegThreshold())
+      return getNaturalAlignIndirect(Ty);
+    if (isPromotableInteger(IT))
+      return ArgInfo::getExtend(Ty);
+  }
+
+  return ArgInfo::getDirect();
+}
+
+ArgInfo DefaultTargetInfo::classifyReturnType(const Type *RetTy) const {
+  if (RetTy->isVoid())
+    return ArgInfo::getIgnore();
+
+  if (isAggregateTypeForABI(RetTy))
+    return getNaturalAlignIndirect(RetTy);
----------------
koparasy wrote:

By default, this will have `byval=true`. That looks consistent with OG, IIRC byval is ignored in return args. Nothing for you to change, this is what OG does. 

https://github.com/llvm/llvm-project/pull/225009


More information about the llvm-commits mailing list