[llvm] [VFABI] Add support for vector functions that return struct types (PR #119000)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 13 09:00:53 PST 2024
================
@@ -0,0 +1,74 @@
+//===----------- 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/IR/DerivedTypes.h"
+#include "llvm/IR/StructWideningUtils.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));
+}
+
+/// 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.
+inline Type *ToWideTy(Type *Ty, ElementCount EC) {
+ if (StructType *StructTy = dyn_cast<StructType>(Ty))
+ return ToWideStructTy(StructTy, EC);
+ return ToVectorTy(Ty, EC);
+}
+
+/// A helper for converting wide types to narrow (non-vector) types. For vector
+/// types, this is equivalent to calling .getScalarType(). For struct types,
+/// this returns a new struct where each element type has been converted to a
+/// scalar type. Note: Only unpacked literal struct types are supported.
+inline Type *ToNarrowTy(Type *Ty) {
+ if (StructType *StructTy = dyn_cast<StructType>(Ty))
+ return ToNarrowStructTy(StructTy);
+ return Ty->getScalarType();
+}
+
+/// Returns true if `Ty` is a vector type or a struct of vector types where all
+/// vector types share the same VF.
+inline bool isWideTy(Type *Ty) {
----------------
MacDue wrote:
Right, I've gone with `toVectorizedTy` / `toScalarizedTy`. I think that's the best option, as it refers to what we're doing to the type (vectorizing or scalarizing it), rather than what the result type is.
https://github.com/llvm/llvm-project/pull/119000
More information about the llvm-commits
mailing list