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 cast<PointerType>(ElementType->getContext().getType(
50 llvm::PointerType::get(ElementType->LLVMTy, AddressSpace)));
51}
52
54 return cast<PointerType>(
56}
57
58ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
59 return cast<ArrayType>(ElementType->getContext().getType(
60 llvm::ArrayType::get(ElementType->LLVMTy, NumElements)));
61}
62
64 bool IsPacked) {
65 SmallVector<llvm::Type *> LLVMElements;
66 LLVMElements.reserve(Elements.size());
67 for (Type *Elm : Elements)
68 LLVMElements.push_back(Elm->LLVMTy);
69 return cast<StructType>(
70 Ctx.getType(llvm::StructType::get(Ctx.LLVMCtx, LLVMElements, IsPacked)));
71}
72
74 return cast<VectorType>(ElementType->getContext().getType(
75 llvm::VectorType::get(ElementType->LLVMTy, EC)));
76}
77
79 return Ctx.getType(cast<llvm::VectorType>(LLVMTy)->getElementType());
80}
82 return cast<VectorType>(VTy->getContext().getType(
83 llvm::VectorType::getInteger(cast<llvm::VectorType>(VTy->LLVMTy))));
84}
86 return cast<VectorType>(
88 cast<llvm::VectorType>(VTy->LLVMTy))));
89}
91 return cast<VectorType>(
93 cast<llvm::VectorType>(VTy->LLVMTy))));
94}
96 int NumSubdivs) {
97 return cast<VectorType>(
99 cast<llvm::VectorType>(VTy->LLVMTy), NumSubdivs)));
100}
102 return cast<VectorType>(
104 cast<llvm::VectorType>(VTy->LLVMTy))));
105}
107 return cast<VectorType>(
109 cast<llvm::VectorType>(VTy->LLVMTy))));
110}
113}
114
115FixedVectorType *FixedVectorType::get(Type *ElementType, unsigned NumElts) {
116 return cast<FixedVectorType>(ElementType->getContext().getType(
117 llvm::FixedVectorType::get(ElementType->LLVMTy, NumElts)));
118}
119
121 unsigned NumElts) {
122 return cast<ScalableVectorType>(ElementType->getContext().getType(
123 llvm::ScalableVectorType::get(ElementType->LLVMTy, NumElts)));
124}
125
126IntegerType *IntegerType::get(Context &Ctx, unsigned NumBits) {
127 return cast<IntegerType>(
128 Ctx.getType(llvm::IntegerType::get(Ctx.LLVMCtx, NumBits)));
129}
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:220
LLVMContext & LLVMCtx
Definition: Context.h:46
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