source: parabix-LLVM/scripts/ValueTypes.cpp.pytemplate @ 4077

Last change on this file since 4077 was 4077, checked in by linmengl, 5 years ago

move templates and gen.py into folder scripts

File size: 9.0 KB
Line 
1//===----------- ValueTypes.cpp - Implementation of EVT methods -----------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements methods in the CodeGen/ValueTypes.h header.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/ValueTypes.h"
15#include "llvm/ADT/StringExtras.h"
16#include "llvm/IR/DerivedTypes.h"
17#include "llvm/IR/LLVMContext.h"
18#include "llvm/IR/Type.h"
19#include "llvm/Support/ErrorHandling.h"
20#include "llvm/Support/Debug.h"
21using namespace llvm;
22
23EVT EVT::changeExtendedVectorElementTypeToInteger() const {
24  LLVMContext &Context = LLVMTy->getContext();
25  EVT IntTy = getIntegerVT(Context, getVectorElementType().getSizeInBits());
26  return getVectorVT(Context, IntTy, getVectorNumElements());
27}
28
29EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
30  EVT VT;
31  VT.LLVMTy = IntegerType::get(Context, BitWidth);
32  assert(VT.isExtended() && "Type is not extended!");
33  return VT;
34}
35
36EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT,
37                             unsigned NumElements) {
38  EVT ResultVT;
39  ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), NumElements);
40  assert(ResultVT.isExtended() && "Type is not extended!");
41  return ResultVT;
42}
43
44bool EVT::isExtendedFloatingPoint() const {
45  assert(isExtended() && "Type is not extended!");
46  return LLVMTy->isFPOrFPVectorTy();
47}
48
49bool EVT::isExtendedInteger() const {
50  assert(isExtended() && "Type is not extended!");
51  return LLVMTy->isIntOrIntVectorTy();
52}
53
54bool EVT::isExtendedVector() const {
55  assert(isExtended() && "Type is not extended!");
56  return LLVMTy->isVectorTy();
57}
58
59bool EVT::isExtended16BitVector() const {
60  return isExtendedVector() && getExtendedSizeInBits() == 16;
61}
62
63bool EVT::isExtended32BitVector() const {
64  return isExtendedVector() && getExtendedSizeInBits() == 32;
65}
66
67bool EVT::isExtended64BitVector() const {
68  return isExtendedVector() && getExtendedSizeInBits() == 64;
69}
70
71bool EVT::isExtended128BitVector() const {
72  return isExtendedVector() && getExtendedSizeInBits() == 128;
73}
74
75bool EVT::isExtended256BitVector() const {
76  return isExtendedVector() && getExtendedSizeInBits() == 256;
77}
78
79bool EVT::isExtended512BitVector() const {
80  return isExtendedVector() && getExtendedSizeInBits() == 512;
81}
82
83bool EVT::isExtended1024BitVector() const {
84  return isExtendedVector() && getExtendedSizeInBits() == 1024;
85}
86
87EVT EVT::getExtendedVectorElementType() const {
88  assert(isExtended() && "Type is not extended!");
89  return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
90}
91
92unsigned EVT::getExtendedVectorNumElements() const {
93  assert(isExtended() && "Type is not extended!");
94  return cast<VectorType>(LLVMTy)->getNumElements();
95}
96
97unsigned EVT::getExtendedSizeInBits() const {
98  assert(isExtended() && "Type is not extended!");
99  if (IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
100    return ITy->getBitWidth();
101  if (VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
102    return VTy->getBitWidth();
103  llvm_unreachable("Unrecognized extended type!");
104}
105
106/// getEVTString - This function returns value type as a string, e.g. "i32".
107std::string EVT::getEVTString() const {
108  switch (V.SimpleTy) {
109  default:
110    if (isVector())
111      return "v" + utostr(getVectorNumElements()) +
112             getVectorElementType().getEVTString();
113    if (isInteger())
114      return "i" + utostr(getSizeInBits());
115    llvm_unreachable("Invalid EVT!");
116  case MVT::i1:      return "i1";
117  case MVT::i8:      return "i8";
118  case MVT::i16:     return "i16";
119  case MVT::i32:     return "i32";
120  case MVT::i64:     return "i64";
121  case MVT::i128:    return "i128";
122  case MVT::f16:     return "f16";
123  case MVT::f32:     return "f32";
124  case MVT::f64:     return "f64";
125  case MVT::f80:     return "f80";
126  case MVT::f128:    return "f128";
127  case MVT::ppcf128: return "ppcf128";
128  case MVT::isVoid:  return "isVoid";
129  case MVT::Other:   return "ch";
130  case MVT::Glue:    return "glue";
131  case MVT::x86mmx:  return "x86mmx";
132  case MVT::v2i1:    return "v2i1";
133  case MVT::v4i1:    return "v4i1";
134  case MVT::v8i1:    return "v8i1";
135  case MVT::v16i1:   return "v16i1";
136  case MVT::v32i1:   return "v32i1";
137  case MVT::v64i1:   return "v64i1";
138  case MVT::v1i8:    return "v1i8";
139  case MVT::v2i8:    return "v2i8";
140  case MVT::v4i8:    return "v4i8";
141  case MVT::v8i8:    return "v8i8";
142  case MVT::v16i8:   return "v16i8";
143  case MVT::v32i8:   return "v32i8";
144  case MVT::v64i8:   return "v64i8";
145  case MVT::v1i16:   return "v1i16";
146  case MVT::v2i16:   return "v2i16";
147  case MVT::v4i16:   return "v4i16";
148  case MVT::v8i16:   return "v8i16";
149  case MVT::v16i16:  return "v16i16";
150  case MVT::v32i16:  return "v32i16";
151  case MVT::v1i32:   return "v1i32";
152  case MVT::v2i32:   return "v2i32";
153  case MVT::v4i32:   return "v4i32";
154  case MVT::v8i32:   return "v8i32";
155  case MVT::v16i32:  return "v16i32";
156  case MVT::v1i64:   return "v1i64";
157  case MVT::v2i64:   return "v2i64";
158  case MVT::v4i64:   return "v4i64";
159  case MVT::v8i64:   return "v8i64";
160  case MVT::v16i64:  return "v16i64";
161  case MVT::v1f32:   return "v1f32";
162  case MVT::v2f32:   return "v2f32";
163  case MVT::v2f16:   return "v2f16";
164  case MVT::v4f16:   return "v4f16";
165  case MVT::v8f16:   return "v8f16";
166  case MVT::v4f32:   return "v4f32";
167  case MVT::v8f32:   return "v8f32";
168  case MVT::v16f32:  return "v16f32";
169  case MVT::v1f64:   return "v1f64";
170  case MVT::v2f64:   return "v2f64";
171  case MVT::v4f64:   return "v4f64";
172  case MVT::v8f64:   return "v8f64";
173  case MVT::Metadata:return "Metadata";
174  case MVT::Untyped: return "Untyped";
175  }
176}
177
178/// getTypeForEVT - This method returns an LLVM type corresponding to the
179/// specified EVT.  For integer types, this returns an unsigned type.  Note
180/// that this will abort for types that cannot be represented.
181Type *EVT::getTypeForEVT(LLVMContext &Context) const {
182  switch (V.SimpleTy) {
183  default:
184    dbgs() << "EVT String: " << getEVTString() << '\n';
185    assert(isExtended() && "Type is not extended!");
186    return LLVMTy;
187  case MVT::isVoid:  return Type::getVoidTy(Context);
188  case MVT::i1:      return Type::getInt1Ty(Context);
189  case MVT::i2:      return Type::getIntNTy(Context, 2);
190  case MVT::i4:      return Type::getIntNTy(Context, 4);
191  case MVT::i8:      return Type::getInt8Ty(Context);
192  case MVT::i16:     return Type::getInt16Ty(Context);
193  case MVT::i32:     return Type::getInt32Ty(Context);
194  case MVT::i64:     return Type::getInt64Ty(Context);
195  case MVT::i128:    return IntegerType::get(Context, 128);
196  case MVT::i256:    return IntegerType::get(Context, 256);
197  case MVT::i512:    return IntegerType::get(Context, 512);
198  case MVT::i1024:   return IntegerType::get(Context, 1024);
199  case MVT::f16:     return Type::getHalfTy(Context);
200  case MVT::f32:     return Type::getFloatTy(Context);
201  case MVT::f64:     return Type::getDoubleTy(Context);
202  case MVT::f80:     return Type::getX86_FP80Ty(Context);
203  case MVT::f128:    return Type::getFP128Ty(Context);
204  case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
205  case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
206
207${get_type_for_vector_EVT}
208
209  case MVT::Metadata: return Type::getMetadataTy(Context);
210 }
211}
212
213/// Return the value type corresponding to the specified type.  This returns all
214/// pointers as MVT::iPTR.  If HandleUnknown is true, unknown types are returned
215/// as Other, otherwise they are invalid.
216MVT MVT::getVT(Type *Ty, bool HandleUnknown){
217  switch (Ty->getTypeID()) {
218  default:
219    if (HandleUnknown) return MVT(MVT::Other);
220    llvm_unreachable("Unknown type!");
221  case Type::VoidTyID:
222    return MVT::isVoid;
223  case Type::IntegerTyID:
224    return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
225  case Type::HalfTyID:      return MVT(MVT::f16);
226  case Type::FloatTyID:     return MVT(MVT::f32);
227  case Type::DoubleTyID:    return MVT(MVT::f64);
228  case Type::X86_FP80TyID:  return MVT(MVT::f80);
229  case Type::X86_MMXTyID:   return MVT(MVT::x86mmx);
230  case Type::FP128TyID:     return MVT(MVT::f128);
231  case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
232  case Type::PointerTyID:   return MVT(MVT::iPTR);
233  case Type::VectorTyID: {
234    VectorType *VTy = cast<VectorType>(Ty);
235    return getVectorVT(
236      getVT(VTy->getElementType(), false), VTy->getNumElements());
237  }
238  }
239}
240
241/// getEVT - Return the value type corresponding to the specified type.  This
242/// returns all pointers as MVT::iPTR.  If HandleUnknown is true, unknown types
243/// are returned as Other, otherwise they are invalid.
244EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
245  switch (Ty->getTypeID()) {
246  default:
247    return MVT::getVT(Ty, HandleUnknown);
248  case Type::IntegerTyID:
249    return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
250  case Type::VectorTyID: {
251    VectorType *VTy = cast<VectorType>(Ty);
252    return getVectorVT(Ty->getContext(), getEVT(VTy->getElementType(), false),
253                       VTy->getNumElements());
254  }
255  }
256}
Note: See TracBrowser for help on using the repository browser.