[AMDGPU] prevent shrinking udiv/urem if either operand is in (SignedMax,UnsignedMax...
[llvm-project.git] / llvm / lib / SandboxIR / Type.cpp
blob7bb788ecf25a64c10502adb6ded2e04685bf3c09
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 //===----------------------------------------------------------------------===//
9 #include "llvm/SandboxIR/Type.h"
10 #include "llvm/SandboxIR/Context.h"
12 using namespace llvm::sandboxir;
14 Type *Type::getScalarType() const {
15 return Ctx.getType(LLVMTy->getScalarType());
18 Type *Type::getInt64Ty(Context &Ctx) {
19 return Ctx.getType(llvm::Type::getInt64Ty(Ctx.LLVMCtx));
21 Type *Type::getInt32Ty(Context &Ctx) {
22 return Ctx.getType(llvm::Type::getInt32Ty(Ctx.LLVMCtx));
24 Type *Type::getInt16Ty(Context &Ctx) {
25 return Ctx.getType(llvm::Type::getInt16Ty(Ctx.LLVMCtx));
27 Type *Type::getInt8Ty(Context &Ctx) {
28 return Ctx.getType(llvm::Type::getInt8Ty(Ctx.LLVMCtx));
30 Type *Type::getInt1Ty(Context &Ctx) {
31 return Ctx.getType(llvm::Type::getInt1Ty(Ctx.LLVMCtx));
33 Type *Type::getDoubleTy(Context &Ctx) {
34 return Ctx.getType(llvm::Type::getDoubleTy(Ctx.LLVMCtx));
36 Type *Type::getFloatTy(Context &Ctx) {
37 return Ctx.getType(llvm::Type::getFloatTy(Ctx.LLVMCtx));
39 PointerType *PointerType::get(Type *ElementType, unsigned AddressSpace) {
40 return cast<PointerType>(ElementType->getContext().getType(
41 llvm::PointerType::get(ElementType->LLVMTy, AddressSpace)));
44 PointerType *PointerType::get(Context &Ctx, unsigned AddressSpace) {
45 return cast<PointerType>(
46 Ctx.getType(llvm::PointerType::get(Ctx.LLVMCtx, AddressSpace)));
49 ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
50 return cast<ArrayType>(ElementType->getContext().getType(
51 llvm::ArrayType::get(ElementType->LLVMTy, NumElements)));
54 StructType *StructType::get(Context &Ctx, ArrayRef<Type *> Elements,
55 bool IsPacked) {
56 SmallVector<llvm::Type *> LLVMElements;
57 LLVMElements.reserve(Elements.size());
58 for (Type *Elm : Elements)
59 LLVMElements.push_back(Elm->LLVMTy);
60 return cast<StructType>(
61 Ctx.getType(llvm::StructType::get(Ctx.LLVMCtx, LLVMElements, IsPacked)));
64 VectorType *VectorType::get(Type *ElementType, ElementCount EC) {
65 return cast<VectorType>(ElementType->getContext().getType(
66 llvm::VectorType::get(ElementType->LLVMTy, EC)));
69 Type *VectorType::getElementType() const {
70 return Ctx.getType(cast<llvm::VectorType>(LLVMTy)->getElementType());
72 VectorType *VectorType::getInteger(VectorType *VTy) {
73 return cast<VectorType>(VTy->getContext().getType(
74 llvm::VectorType::getInteger(cast<llvm::VectorType>(VTy->LLVMTy))));
76 VectorType *VectorType::getExtendedElementVectorType(VectorType *VTy) {
77 return cast<VectorType>(
78 VTy->getContext().getType(llvm::VectorType::getExtendedElementVectorType(
79 cast<llvm::VectorType>(VTy->LLVMTy))));
81 VectorType *VectorType::getTruncatedElementVectorType(VectorType *VTy) {
82 return cast<VectorType>(
83 VTy->getContext().getType(llvm::VectorType::getTruncatedElementVectorType(
84 cast<llvm::VectorType>(VTy->LLVMTy))));
86 VectorType *VectorType::getSubdividedVectorType(VectorType *VTy,
87 int NumSubdivs) {
88 return cast<VectorType>(
89 VTy->getContext().getType(llvm::VectorType::getSubdividedVectorType(
90 cast<llvm::VectorType>(VTy->LLVMTy), NumSubdivs)));
92 VectorType *VectorType::getHalfElementsVectorType(VectorType *VTy) {
93 return cast<VectorType>(
94 VTy->getContext().getType(llvm::VectorType::getHalfElementsVectorType(
95 cast<llvm::VectorType>(VTy->LLVMTy))));
97 VectorType *VectorType::getDoubleElementsVectorType(VectorType *VTy) {
98 return cast<VectorType>(
99 VTy->getContext().getType(llvm::VectorType::getDoubleElementsVectorType(
100 cast<llvm::VectorType>(VTy->LLVMTy))));
102 bool VectorType::isValidElementType(Type *ElemTy) {
103 return llvm::VectorType::isValidElementType(ElemTy->LLVMTy);
106 FixedVectorType *FixedVectorType::get(Type *ElementType, unsigned NumElts) {
107 return cast<FixedVectorType>(ElementType->getContext().getType(
108 llvm::FixedVectorType::get(ElementType->LLVMTy, NumElts)));
111 ScalableVectorType *ScalableVectorType::get(Type *ElementType,
112 unsigned NumElts) {
113 return cast<ScalableVectorType>(ElementType->getContext().getType(
114 llvm::ScalableVectorType::get(ElementType->LLVMTy, NumElts)));
117 IntegerType *IntegerType::get(Context &Ctx, unsigned NumBits) {
118 return cast<IntegerType>(
119 Ctx.getType(llvm::IntegerType::get(Ctx.LLVMCtx, NumBits)));