[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,32 @@
+//===----------- VectorUtils.h - Vector type utility functions -*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_VECTORUTILS_H
+#define LLVM_IR_VECTORUTILS_H
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/DerivedTypes.h"
+
+namespace llvm {
+
+/// A helper function for converting Scalar types to vector types. If
+/// the incoming type is void, we return void. If the EC represents a
+/// scalar, we return the scalar type.
+inline Type *ToVectorTy(Type *Scalar, ElementCount EC) {
+ if (Scalar->isVoidTy() || Scalar->isMetadataTy() || EC.isScalar())
+ return Scalar;
+ return VectorType::get(Scalar, EC);
+}
+
+inline Type *ToVectorTy(Type *Scalar, unsigned VF) {
+ return ToVectorTy(Scalar, ElementCount::getFixed(VF));
+}
+
+} // namespace llvm
----------------
david-arm wrote:
This is just a suggestion, but how about putting declarations of `ToWideTy` and `ToNarrowTy` here, with the struct specific aspects living in `CallWideningUtils` (or whatever name we decide for the file). For example, you could have:
```
inline Type *ToWideTy(Type *Scalar, ElementCount EC) {
if (isa<StructType>(Scalar))
return ToWideStructTy(Scalar, EC);
return ToVectorTy(Scalar, EC);
}
```
and something similarly for `ToNarrowTy`?
I like the separation of vectorisation of scalars and structs in different files though.
https://github.com/llvm/llvm-project/pull/119000
More information about the llvm-commits
mailing list