LLVM 20.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}
35}
37 return Ctx.getType(llvm::Type::getFloatTy(Ctx.LLVMCtx));
38}
39
40#ifndef NDEBUG
41void Type::dumpOS(raw_ostream &OS) { LLVMTy->print(OS); }
42void Type::dump() {
43 dumpOS(dbgs());
44 dbgs() << "\n";
45}
46#endif
47
49 return get(ElementType->getContext(), AddressSpace);
50}
51
53 return cast<PointerType>(
55}
56
57ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
58 return cast<ArrayType>(ElementType->getContext().getType(
59 llvm::ArrayType::get(ElementType->LLVMTy, NumElements)));
60}
61
63 bool IsPacked) {
64 SmallVector<llvm::Type *> LLVMElements;
65 LLVMElements.reserve(Elements.size());
66 for (Type *Elm : Elements)
67 LLVMElements.push_back(Elm->LLVMTy);
68 return cast<StructType>(
69 Ctx.getType(llvm::StructType::get(Ctx.LLVMCtx, LLVMElements, IsPacked)));
70}
71
73 return cast<VectorType>(ElementType->getContext().getType(
74 llvm::VectorType::get(ElementType->LLVMTy, EC)));
75}
76
78 return Ctx.getType(cast<llvm::VectorType>(LLVMTy)->getElementType());
79}
81 return cast<VectorType>(VTy->getContext().getType(
82 llvm::VectorType::getInteger(cast<llvm::VectorType>(VTy->LLVMTy))));
83}
85 return cast<VectorType>(
87 cast<llvm::VectorType>(VTy->LLVMTy))));
88}
90 return cast<VectorType>(
92 cast<llvm::VectorType>(VTy->LLVMTy))));
93}
95 int NumSubdivs) {
96 return cast<VectorType>(
98 cast<llvm::VectorType>(VTy->LLVMTy), NumSubdivs)));
99}
101 return cast<VectorType>(
103 cast<llvm::VectorType>(VTy->LLVMTy))));
104}
106 return cast<VectorType>(
108 cast<llvm::VectorType>(VTy->LLVMTy))));
109}
112}
113
114FixedVectorType *FixedVectorType::get(Type *ElementType, unsigned NumElts) {
115 return cast<FixedVectorType>(ElementType->getContext().getType(
116 llvm::FixedVectorType::get(ElementType->LLVMTy, NumElts)));
117}
118
120 unsigned NumElts) {
121 return cast<ScalableVectorType>(ElementType->getContext().getType(
122 llvm::ScalableVectorType::get(ElementType->LLVMTy, NumElts)));
123}
124
125IntegerType *IntegerType::get(Context &Ctx, unsigned NumBits) {
126 return cast<IntegerType>(
127 Ctx.getType(llvm::IntegerType::get(Ctx.LLVMCtx, NumBits)));
128}
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
static 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.
Definition: DerivedTypes.h:563
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:791
Class to represent integer types.
Definition: DerivedTypes.h:42
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:311
static 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.
Definition: DerivedTypes.h:610
static ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
Definition: Type.cpp:812
void reserve(size_type N)
Definition: SmallVector.h:663
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
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
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static Type * getDoubleTy(LLVMContext &C)
static IntegerType * getInt1Ty(LLVMContext &C)
void dump() const
static IntegerType * getInt16Ty(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:355
static VectorType * getHalfElementsVectorType(VectorType *VTy)
This static method returns a VectorType with half as many elements as the input type and the same ele...
Definition: DerivedTypes.h:531
static VectorType * getExtendedElementVectorType(VectorType *VTy)
This static method is like getInteger except that the element types are twice as wide as the elements...
Definition: DerivedTypes.h:487
static VectorType * getSubdividedVectorType(VectorType *VTy, int NumSubdivs)
Definition: DerivedTypes.h:521
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
Definition: DerivedTypes.h:478
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static VectorType * getTruncatedElementVectorType(VectorType *VTy)
Definition: DerivedTypes.h:496
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
static VectorType * getDoubleElementsVectorType(VectorType *VTy)
This static method returns a VectorType with twice as many elements as the input type and the same el...
Definition: DerivedTypes.h:541
Type * getElementType() const
Definition: DerivedTypes.h:460
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Type * getType(llvm::Type *LLVMTy)
Definition: Context.h:239
LLVMContext & LLVMCtx
Definition: Context.h:65
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition: Type.h:43
llvm::Type * LLVMTy
Definition: Type.h:45
void dumpOS(raw_ostream &OS)
Context & getContext() const
Definition: Type.h:89
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163