LLVM 23.0.0git
Type.cpp
Go to the documentation of this file.
1//===- Type.cpp - Sandbox IR Type -----------------------------------------===//
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
11
12using namespace llvm::sandboxir;
13
15 return Ctx.getType(LLVMTy->getScalarType());
16}
17
34 return cast<ByteType>(Ctx.getType(llvm::Type::getByteNTy(Ctx.LLVMCtx, N)));
35}
55 return Ty->getContext().getType(llvm::Type::getIntFromByteType(Ty->LLVMTy));
56}
58 return Ty->getContext().getType(llvm::Type::getByteFromIntType(Ty->LLVMTy));
59}
61 return Ctx.getType(llvm::Type::getDoubleTy(Ctx.LLVMCtx));
62}
64 return Ctx.getType(llvm::Type::getFloatTy(Ctx.LLVMCtx));
67 return Ctx.getType(llvm::Type::getHalfTy(Ctx.LLVMCtx));
68}
69
70#ifndef NDEBUG
71void Type::dumpOS(raw_ostream &OS) { LLVMTy->print(OS); }
72void Type::dump() {
74 dbgs() << "\n";
75}
76#endif
77
78PointerType *PointerType::get(Context &Ctx, unsigned AddressSpace) {
79 return cast<PointerType>(
80 Ctx.getType(llvm::PointerType::get(Ctx.LLVMCtx, AddressSpace)));
81}
82
83ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
84 return cast<ArrayType>(ElementType->getContext().getType(
85 llvm::ArrayType::get(ElementType->LLVMTy, NumElements)));
86}
87
89 bool IsPacked) {
90 SmallVector<llvm::Type *> LLVMElements;
91 LLVMElements.reserve(Elements.size());
92 for (Type *Elm : Elements)
93 LLVMElements.push_back(Elm->LLVMTy);
95 Ctx.getType(llvm::StructType::get(Ctx.LLVMCtx, LLVMElements, IsPacked)));
96}
97
99 return cast<VectorType>(ElementType->getContext().getType(
100 llvm::VectorType::get(ElementType->LLVMTy, EC)));
101}
102
121 int NumSubdivs) {
122 return cast<VectorType>(
124 cast<llvm::VectorType>(VTy->LLVMTy), NumSubdivs)));
125}
127 return cast<VectorType>(
130}
137 return llvm::VectorType::isValidElementType(ElemTy->LLVMTy);
138}
139
140FixedVectorType *FixedVectorType::get(Type *ElementType, unsigned NumElts) {
141 return cast<FixedVectorType>(ElementType->getContext().getType(
142 llvm::FixedVectorType::get(ElementType->LLVMTy, NumElts)));
143}
144
146 unsigned NumElts) {
147 return cast<ScalableVectorType>(ElementType->getContext().getType(
148 llvm::ScalableVectorType::get(ElementType->LLVMTy, NumElts)));
149}
151IntegerType *IntegerType::get(Context &Ctx, unsigned NumBits) {
152 return cast<IntegerType>(
153 Ctx.getType(llvm::IntegerType::get(Ctx.LLVMCtx, NumBits)));
154}
155
156ByteType *ByteType::get(Context &Ctx, unsigned NumBits) {
157 return cast<ByteType>(Ctx.getType(llvm::ByteType::get(Ctx.LLVMCtx, NumBits)));
158}
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Class to represent byte types.
static LLVM_ABI ByteType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing a ByteType.
Definition Type.cpp:384
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:873
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:354
Class to represent pointers.
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Class to represent scalable SIMD vectors.
static LLVM_ABI ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
Definition Type.cpp:895
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI 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:483
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI ByteType * getByte16Ty(LLVMContext &C)
Definition Type.cpp:301
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:314
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:313
static LLVM_ABI Type * getByteFromIntType(Type *)
Returns a byte (vector of byte) type with the same size of an integer of the given integer (vector of...
Definition Type.cpp:330
static LLVM_ABI ByteType * getByte32Ty(LLVMContext &C)
Definition Type.cpp:302
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:311
Type(LLVMContext &C, TypeID tid)
Definition Type.h:95
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:312
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
LLVM_ABI void dump() const
static LLVM_ABI Type * getIntFromByteType(Type *)
Returns an integer (vector of integer) type with the same size of a byte of the given byte (vector of...
Definition Type.cpp:321
static LLVM_ABI ByteType * getByte8Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:310
static LLVM_ABI ByteType * getByte128Ty(LLVMContext &C)
Definition Type.cpp:304
static LLVM_ABI ByteType * getByte1Ty(LLVMContext &C)
Definition Type.cpp:299
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:291
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:290
static LLVM_ABI ByteType * getByteNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:306
static LLVM_ABI ByteType * getByte64Ty(LLVMContext &C)
Definition Type.cpp:303
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:288
Base class of all SIMD vector types.
static VectorType * getHalfElementsVectorType(VectorType *VTy)
This static method returns a VectorType with half as many elements as the input type and the same ele...
static VectorType * getExtendedElementVectorType(VectorType *VTy)
This static method is like getInteger except that the element types are twice as wide as the elements...
static VectorType * getSubdividedVectorType(VectorType *VTy, int NumSubdivs)
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
static VectorType * getTruncatedElementVectorType(VectorType *VTy)
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static VectorType * getDoubleElementsVectorType(VectorType *VTy)
This static method returns a VectorType with twice as many elements as the input type and the same el...
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Type * getElementType() const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
Type * getType(llvm::Type *LLVMTy)
Definition Context.h:265
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition Type.h:50
llvm::Type * LLVMTy
Definition Type.h:52
Type(llvm::Type *LLVMTy, Context &Ctx)
Definition Type.h:85
friend class VectorType
Definition Type.h:56
LLVM_ABI Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
friend class IntegerType
Definition Type.h:61
void dumpOS(raw_ostream &OS)
Definition Type.cpp:71
friend class Context
Definition Type.h:86
friend class StructType
Definition Type.h:55
Context & Ctx
Definition Type.h:83
Context & getContext() const
Definition Type.h:101
friend class ByteType
Definition Type.h:54
LLVM_ABI_FOR_TEST void dumpOS(raw_ostream &OS) const final
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
#define N