LLVM 22.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
19 return Ctx.getType(llvm::Type::getInt64Ty(Ctx.LLVMCtx));
20}
22 return Ctx.getType(llvm::Type::getInt32Ty(Ctx.LLVMCtx));
23}
25 return Ctx.getType(llvm::Type::getInt16Ty(Ctx.LLVMCtx));
26}
28 return Ctx.getType(llvm::Type::getInt8Ty(Ctx.LLVMCtx));
29}
31 return Ctx.getType(llvm::Type::getInt1Ty(Ctx.LLVMCtx));
32}
34 return Ctx.getType(llvm::Type::getDoubleTy(Ctx.LLVMCtx));
35}
37 return Ctx.getType(llvm::Type::getFloatTy(Ctx.LLVMCtx));
38}
40 return Ctx.getType(llvm::Type::getHalfTy(Ctx.LLVMCtx));
41}
42
43#ifndef NDEBUG
44void Type::dumpOS(raw_ostream &OS) { LLVMTy->print(OS); }
45void Type::dump() {
46 dumpOS(dbgs());
47 dbgs() << "\n";
48}
49#endif
50
55
56ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
57 return cast<ArrayType>(ElementType->getContext().getType(
58 llvm::ArrayType::get(ElementType->LLVMTy, NumElements)));
59}
60
62 bool IsPacked) {
63 SmallVector<llvm::Type *> LLVMElements;
64 LLVMElements.reserve(Elements.size());
65 for (Type *Elm : Elements)
66 LLVMElements.push_back(Elm->LLVMTy);
67 return cast<StructType>(
68 Ctx.getType(llvm::StructType::get(Ctx.LLVMCtx, LLVMElements, IsPacked)));
69}
72 return cast<VectorType>(ElementType->getContext().getType(
73 llvm::VectorType::get(ElementType->LLVMTy, EC)));
74}
84 return cast<VectorType>(
87}
89 return cast<VectorType>(
92}
100 return cast<VectorType>(
103}
105 return cast<VectorType>(
108}
110 return llvm::VectorType::isValidElementType(ElemTy->LLVMTy);
111}
112
113FixedVectorType *FixedVectorType::get(Type *ElementType, unsigned NumElts) {
114 return cast<FixedVectorType>(ElementType->getContext().getType(
115 llvm::FixedVectorType::get(ElementType->LLVMTy, NumElts)));
116}
117
119 unsigned NumElts) {
120 return cast<ScalableVectorType>(ElementType->getContext().getType(
121 llvm::ScalableVectorType::get(ElementType->LLVMTy, NumElts)));
122}
123
124IntegerType *IntegerType::get(Context &Ctx, unsigned NumBits) {
125 return cast<IntegerType>(
126 Ctx.getType(llvm::IntegerType::get(Ctx.LLVMCtx, NumBits)));
127}
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:803
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:319
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:825
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:414
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:298
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:295
Type(LLVMContext &C, TypeID tid)
Definition Type.h:93
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:296
LLVM_ABI void dump() const
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:294
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:286
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:285
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:283
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:262
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition Type.h:47
llvm::Type * LLVMTy
Definition Type.h:49
Type(llvm::Type *LLVMTy, Context &Ctx)
Definition Type.h:78
friend class VectorType
Definition Type.h:52
LLVM_ABI Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
void dumpOS(raw_ostream &OS)
Definition Type.cpp:44
friend class PointerType
Definition Type.h:55
friend class Context
Definition Type.h:79
friend class StructType
Definition Type.h:51
Context & Ctx
Definition Type.h:76
Context & getContext() const
Definition Type.h:94
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:207
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565