Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
VectorTypeUtils.cpp
Go to the documentation of this file.
1//===------- VectorTypeUtils.cpp - Vector type utility functions ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/IR/VectorTypeUtils.h"
10#include "llvm/ADT/SmallVectorExtras.h"
11
12using namespacellvm;
13
14/// A helper for converting structs of scalar types to structs of vector types.
15/// Note: Only unpacked literal struct types are supported.
16Type *llvm::toVectorizedStructTy(StructType *StructTy,ElementCount EC) {
17if (EC.isScalar())
18return StructTy;
19assert(isUnpackedStructLiteral(StructTy) &&
20"expected unpacked struct literal");
21assert(all_of(StructTy->elements(), VectorType::isValidElementType) &&
22"expected all element types to be valid vector element types");
23returnStructType::get(
24 StructTy->getContext(),
25map_to_vector(StructTy->elements(), [&](Type *ElTy) ->Type * {
26 return VectorType::get(ElTy, EC);
27 }));
28}
29
30/// A helper for converting structs of vector types to structs of scalar types.
31/// Note: Only unpacked literal struct types are supported.
32Type *llvm::toScalarizedStructTy(StructType *StructTy) {
33assert(isUnpackedStructLiteral(StructTy) &&
34"expected unpacked struct literal");
35returnStructType::get(
36 StructTy->getContext(),
37map_to_vector(StructTy->elements(), [](Type *ElTy) ->Type * {
38 return ElTy->getScalarType();
39 }));
40}
41
42/// Returns true if `StructTy` is an unpacked literal struct where all elements
43/// are vectors of matching element count. This does not include empty structs.
44boolllvm::isVectorizedStructTy(StructType *StructTy) {
45if (!isUnpackedStructLiteral(StructTy))
46returnfalse;
47auto ElemTys = StructTy->elements();
48if (ElemTys.empty() || !ElemTys.front()->isVectorTy())
49returnfalse;
50ElementCount VF = cast<VectorType>(ElemTys.front())->getElementCount();
51returnall_of(ElemTys, [&](Type *Ty) {
52return Ty->isVectorTy() && cast<VectorType>(Ty)->getElementCount() == VF;
53 });
54}
55
56/// Returns true if `StructTy` is an unpacked literal struct where all elements
57/// are scalars that can be used as vector element types.
58boolllvm::canVectorizeStructTy(StructType *StructTy) {
59auto ElemTys = StructTy->elements();
60return !ElemTys.empty() &&isUnpackedStructLiteral(StructTy) &&
61all_of(ElemTys, VectorType::isValidElementType);
62}
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SmallVectorExtras.h
This file defines less commonly used SmallVector utilities.
VectorTypeUtils.h
llvm::ElementCount
Definition:TypeSize.h:300
llvm::StructType
Class to represent struct types.
Definition:DerivedTypes.h:218
llvm::StructType::get
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition:Type.cpp:406
llvm::StructType::elements
ArrayRef< Type * > elements() const
Definition:DerivedTypes.h:357
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Type::isVectorTy
bool isVectorTy() const
True if this is an instance of VectorType.
Definition:Type.h:270
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition:Type.h:128
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1739
llvm::canVectorizeStructTy
bool canVectorizeStructTy(StructType *StructTy)
Returns true if StructTy is an unpacked literal struct where all elements are scalars that can be use...
Definition:VectorTypeUtils.cpp:58
llvm::isUnpackedStructLiteral
bool isUnpackedStructLiteral(StructType *StructTy)
Definition:VectorTypeUtils.h:104
llvm::map_to_vector
auto map_to_vector(ContainerTy &&C, FuncTy &&F)
Map a range to a SmallVector with element types deduced from the mapping.
Definition:SmallVectorExtras.h:38
llvm::toVectorizedStructTy
Type * toVectorizedStructTy(StructType *StructTy, ElementCount EC)
A helper for converting structs of scalar types to structs of vector types.
Definition:VectorTypeUtils.cpp:16
llvm::toScalarizedStructTy
Type * toScalarizedStructTy(StructType *StructTy)
A helper for converting structs of vector types to structs of scalar types.
Definition:VectorTypeUtils.cpp:32
llvm::isVectorizedStructTy
bool isVectorizedStructTy(StructType *StructTy)
Returns true if StructTy is an unpacked literal struct where all elements are vectors of matching ele...
Definition:VectorTypeUtils.cpp:44

Generated on Sun Jul 20 2025 09:42:22 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp