-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[VFABI] Add support for vector functions that return struct types #119000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
16afa09
[VFABI] Add support for vector functions that return struct types
MacDue 349b678
Fixups
MacDue 8199c23
Rm include
MacDue 7b23397
Update comment
MacDue 0bb3c80
Fixups
MacDue 54c6244
Fix typo
MacDue 91085c6
Fixups
MacDue 899f19a
Move helpers
MacDue ee19f4e
Fixups
MacDue b0ff8df
RM
MacDue 5c155ce
RM
MacDue dd90ff4
RM
MacDue cbf5ff9
fix typo
MacDue 39c5bc4
widened type -> vectorized type
MacDue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //===--- StructWideningUtils.h - Utils for widening/narrowing struct types ===// | ||
| // | ||
| // 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_STRUCTWIDENINGUTILS_H | ||
| #define LLVM_IR_STRUCTWIDENINGUTILS_H | ||
|
|
||
| #include "llvm/IR/DerivedTypes.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| /// A helper for converting structs of scalar types to structs of vector types. | ||
| /// Note: Only unpacked literal struct types are supported. | ||
| Type *ToWideStructTy(StructType *StructTy, ElementCount EC); | ||
|
|
||
| /// A helper for converting structs of vector types to structs of scalar types. | ||
| /// Note: Only unpacked literal struct types are supported. | ||
| Type *ToNarrowStructTy(StructType *StructTy); | ||
MacDue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Returns true if `StructTy` is an unpacked literal struct where all elements | ||
| /// are vectors of matching element count. This does not include empty structs. | ||
| bool isWideStructTy(StructType *StructTy); | ||
|
|
||
| } // namespace llvm | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
MacDue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (StructType *StructTy = dyn_cast<StructType>(Ty)) | ||
| return isWideStructTy(StructTy); | ||
| return Ty->isVectorTy(); | ||
| } | ||
|
|
||
| /// Returns the types contained in `Ty`. For struct types, it returns the | ||
| /// elements, all other types are returned directly. | ||
| inline ArrayRef<Type *> getContainedTypes(Type *const &Ty) { | ||
MacDue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (auto *StructTy = dyn_cast<StructType>(Ty)) | ||
| return StructTy->elements(); | ||
| return ArrayRef<Type *>{&Ty, 1}; | ||
MacDue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Returns the vectorization factor for a widened type. | ||
MacDue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| inline ElementCount getWideTypeVF(Type *Ty) { | ||
| assert(isWideTy(Ty) && "expected widened type"); | ||
| return cast<VectorType>(getContainedTypes(Ty).front())->getElementCount(); | ||
| } | ||
|
|
||
| } // namespace llvm | ||
MacDue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //===- StructWideningUtils.cpp - Utils for widening/narrowing struct types ===// | ||
| // | ||
| // 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/StructWideningUtils.h" | ||
| #include "llvm/ADT/SmallVectorExtras.h" | ||
| #include "llvm/IR/VectorUtils.h" | ||
|
|
||
| using namespace llvm; | ||
|
|
||
| static bool isUnpackedStructLiteral(StructType *StructTy) { | ||
| return StructTy->isLiteral() && !StructTy->isPacked(); | ||
| } | ||
|
|
||
| /// A helper for converting structs of scalar types to structs of vector types. | ||
| /// Note: Only unpacked literal struct types are supported. | ||
| Type *llvm::ToWideStructTy(StructType *StructTy, ElementCount EC) { | ||
MacDue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (EC.isScalar()) | ||
| return StructTy; | ||
| assert(isUnpackedStructLiteral(StructTy) && | ||
| "expected unpacked struct literal"); | ||
| return StructType::get( | ||
| StructTy->getContext(), | ||
| map_to_vector(StructTy->elements(), [&](Type *ElTy) -> Type * { | ||
| return VectorType::get(ElTy, EC); | ||
| })); | ||
| } | ||
|
|
||
| /// A helper for converting structs of vector types to structs of scalar types. | ||
| /// Note: Only unpacked literal struct types are supported. | ||
| Type *llvm::ToNarrowStructTy(StructType *StructTy) { | ||
| assert(isUnpackedStructLiteral(StructTy) && | ||
| "expected unpacked struct literal"); | ||
| return StructType::get( | ||
| StructTy->getContext(), | ||
| map_to_vector(StructTy->elements(), [](Type *ElTy) -> Type * { | ||
| return ElTy->getScalarType(); | ||
| })); | ||
| } | ||
|
|
||
| /// Returns true if `StructTy` is an unpacked literal struct where all elements | ||
| /// are vectors of matching element count. This does not include empty structs. | ||
| bool llvm::isWideStructTy(StructType *StructTy) { | ||
| if (!isUnpackedStructLiteral(StructTy)) | ||
| return false; | ||
| auto ElemTys = StructTy->elements(); | ||
| if (ElemTys.empty() || !ElemTys.front()->isVectorTy()) | ||
| return false; | ||
| ElementCount VF = cast<VectorType>(ElemTys.front())->getElementCount(); | ||
| return all_of(ElemTys, [&](Type *Ty) { | ||
| return Ty->isVectorTy() && cast<VectorType>(Ty)->getElementCount() == VF; | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MacDue marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.