[llvm] [VFABI] Add support for vector functions that return struct types (PR #119000)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 12 05:17:19 PST 2024


================
@@ -0,0 +1,73 @@
+//===----------- VectorUtils.cpp - Vector type utility functions ----------===//
+//
+// 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/IR/CallWideningUtils.h"
+#include "llvm/ADT/SmallVectorExtras.h"
+#include "llvm/IR/VectorUtils.h"
+
+using namespace llvm;
+
+/// A helper for converting to wider (vector) types. For scalar types, this is
+/// equivalent to calling `ToVectorTy`. For struct types, this returns a new
+/// struct where each element type has been widened to a vector type. Note: Only
+/// unpacked literal struct types are supported.
+Type *llvm::ToWideTy(Type *Ty, ElementCount EC) {
+  if (EC.isScalar())
+    return Ty;
+  auto *StructTy = dyn_cast<StructType>(Ty);
+  if (!StructTy)
+    return ToVectorTy(Ty, EC);
+  assert(StructTy->isLiteral() && !StructTy->isPacked() &&
----------------
david-arm wrote:

In three different functions you have similar checks. Is it worth pulling out into a helper function, i.e.

```
bool canWidenStruct(StructType *Ty) {
  return StructTy->isLiteral() && !StructTy->isPacked();
}
```

that way you can transform the various asserts and checks into

```
  assert(canWidenStruct(StructTy) && ...);
```

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


More information about the llvm-commits mailing list