LLVM  4.0.0
Type.cpp
Go to the documentation of this file.
1 //===-- Type.cpp - Implement the Type class -------------------------------===//
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 the Type class for the IR library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/IR/Type.h"
15 #include "LLVMContextImpl.h"
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/IR/Module.h"
18 #include <algorithm>
19 #include <cstdarg>
20 using namespace llvm;
21 
22 //===----------------------------------------------------------------------===//
23 // Type Class Implementation
24 //===----------------------------------------------------------------------===//
25 
27  switch (IDNumber) {
28  case VoidTyID : return getVoidTy(C);
29  case HalfTyID : return getHalfTy(C);
30  case FloatTyID : return getFloatTy(C);
31  case DoubleTyID : return getDoubleTy(C);
32  case X86_FP80TyID : return getX86_FP80Ty(C);
33  case FP128TyID : return getFP128Ty(C);
34  case PPC_FP128TyID : return getPPC_FP128Ty(C);
35  case LabelTyID : return getLabelTy(C);
36  case MetadataTyID : return getMetadataTy(C);
37  case X86_MMXTyID : return getX86_MMXTy(C);
38  case TokenTyID : return getTokenTy(C);
39  default:
40  return nullptr;
41  }
42 }
43 
45  if (auto *VTy = dyn_cast<VectorType>(this))
46  return VTy->getElementType();
47  return const_cast<Type*>(this);
48 }
49 
50 bool Type::isIntegerTy(unsigned Bitwidth) const {
51  return isIntegerTy() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;
52 }
53 
55  // Identity cast means no change so return true
56  if (this == Ty)
57  return true;
58 
59  // They are not convertible unless they are at least first class types
60  if (!this->isFirstClassType() || !Ty->isFirstClassType())
61  return false;
62 
63  // Vector -> Vector conversions are always lossless if the two vector types
64  // have the same size, otherwise not. Also, 64-bit vector types can be
65  // converted to x86mmx.
66  if (auto *thisPTy = dyn_cast<VectorType>(this)) {
67  if (auto *thatPTy = dyn_cast<VectorType>(Ty))
68  return thisPTy->getBitWidth() == thatPTy->getBitWidth();
69  if (Ty->getTypeID() == Type::X86_MMXTyID &&
70  thisPTy->getBitWidth() == 64)
71  return true;
72  }
73 
74  if (this->getTypeID() == Type::X86_MMXTyID)
75  if (auto *thatPTy = dyn_cast<VectorType>(Ty))
76  if (thatPTy->getBitWidth() == 64)
77  return true;
78 
79  // At this point we have only various mismatches of the first class types
80  // remaining and ptr->ptr. Just select the lossless conversions. Everything
81  // else is not lossless. Conservatively assume we can't losslessly convert
82  // between pointers with different address spaces.
83  if (auto *PTy = dyn_cast<PointerType>(this)) {
84  if (auto *OtherPTy = dyn_cast<PointerType>(Ty))
85  return PTy->getAddressSpace() == OtherPTy->getAddressSpace();
86  return false;
87  }
88  return false; // Other types have no identity values
89 }
90 
91 bool Type::isEmptyTy() const {
92  if (auto *ATy = dyn_cast<ArrayType>(this)) {
93  unsigned NumElements = ATy->getNumElements();
94  return NumElements == 0 || ATy->getElementType()->isEmptyTy();
95  }
96 
97  if (auto *STy = dyn_cast<StructType>(this)) {
98  unsigned NumElements = STy->getNumElements();
99  for (unsigned i = 0; i < NumElements; ++i)
100  if (!STy->getElementType(i)->isEmptyTy())
101  return false;
102  return true;
103  }
104 
105  return false;
106 }
107 
109  switch (getTypeID()) {
110  case Type::HalfTyID: return 16;
111  case Type::FloatTyID: return 32;
112  case Type::DoubleTyID: return 64;
113  case Type::X86_FP80TyID: return 80;
114  case Type::FP128TyID: return 128;
115  case Type::PPC_FP128TyID: return 128;
116  case Type::X86_MMXTyID: return 64;
117  case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
118  case Type::VectorTyID: return cast<VectorType>(this)->getBitWidth();
119  default: return 0;
120  }
121 }
122 
123 unsigned Type::getScalarSizeInBits() const {
125 }
126 
128  if (auto *VTy = dyn_cast<VectorType>(this))
129  return VTy->getElementType()->getFPMantissaWidth();
130  assert(isFloatingPointTy() && "Not a floating point type!");
131  if (getTypeID() == HalfTyID) return 11;
132  if (getTypeID() == FloatTyID) return 24;
133  if (getTypeID() == DoubleTyID) return 53;
134  if (getTypeID() == X86_FP80TyID) return 64;
135  if (getTypeID() == FP128TyID) return 113;
136  assert(getTypeID() == PPC_FP128TyID && "unknown fp type");
137  return -1;
138 }
139 
140 bool Type::isSizedDerivedType(SmallPtrSetImpl<Type*> *Visited) const {
141  if (auto *ATy = dyn_cast<ArrayType>(this))
142  return ATy->getElementType()->isSized(Visited);
143 
144  if (auto *VTy = dyn_cast<VectorType>(this))
145  return VTy->getElementType()->isSized(Visited);
146 
147  return cast<StructType>(this)->isSized(Visited);
148 }
149 
150 //===----------------------------------------------------------------------===//
151 // Primitive 'Type' data
152 //===----------------------------------------------------------------------===//
153 
165 
172 
174  return IntegerType::get(C, N);
175 }
176 
178  return getHalfTy(C)->getPointerTo(AS);
179 }
180 
182  return getFloatTy(C)->getPointerTo(AS);
183 }
184 
186  return getDoubleTy(C)->getPointerTo(AS);
187 }
188 
190  return getX86_FP80Ty(C)->getPointerTo(AS);
191 }
192 
194  return getFP128Ty(C)->getPointerTo(AS);
195 }
196 
198  return getPPC_FP128Ty(C)->getPointerTo(AS);
199 }
200 
202  return getX86_MMXTy(C)->getPointerTo(AS);
203 }
204 
205 PointerType *Type::getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS) {
206  return getIntNTy(C, N)->getPointerTo(AS);
207 }
208 
210  return getInt1Ty(C)->getPointerTo(AS);
211 }
212 
214  return getInt8Ty(C)->getPointerTo(AS);
215 }
216 
218  return getInt16Ty(C)->getPointerTo(AS);
219 }
220 
222  return getInt32Ty(C)->getPointerTo(AS);
223 }
224 
226  return getInt64Ty(C)->getPointerTo(AS);
227 }
228 
229 
230 //===----------------------------------------------------------------------===//
231 // IntegerType Implementation
232 //===----------------------------------------------------------------------===//
233 
235  assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
236  assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
237 
238  // Check for the built-in integer types
239  switch (NumBits) {
240  case 1: return cast<IntegerType>(Type::getInt1Ty(C));
241  case 8: return cast<IntegerType>(Type::getInt8Ty(C));
242  case 16: return cast<IntegerType>(Type::getInt16Ty(C));
243  case 32: return cast<IntegerType>(Type::getInt32Ty(C));
244  case 64: return cast<IntegerType>(Type::getInt64Ty(C));
245  case 128: return cast<IntegerType>(Type::getInt128Ty(C));
246  default:
247  break;
248  }
249 
250  IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits];
251 
252  if (!Entry)
253  Entry = new (C.pImpl->TypeAllocator) IntegerType(C, NumBits);
254 
255  return Entry;
256 }
257 
259  unsigned BitWidth = getBitWidth();
260  return (BitWidth > 7) && isPowerOf2_32(BitWidth);
261 }
262 
265 }
266 
267 //===----------------------------------------------------------------------===//
268 // FunctionType Implementation
269 //===----------------------------------------------------------------------===//
270 
271 FunctionType::FunctionType(Type *Result, ArrayRef<Type*> Params,
272  bool IsVarArgs)
273  : Type(Result->getContext(), FunctionTyID) {
274  Type **SubTys = reinterpret_cast<Type**>(this+1);
275  assert(isValidReturnType(Result) && "invalid return type for function");
276  setSubclassData(IsVarArgs);
277 
278  SubTys[0] = Result;
279 
280  for (unsigned i = 0, e = Params.size(); i != e; ++i) {
281  assert(isValidArgumentType(Params[i]) &&
282  "Not a valid type for function argument!");
283  SubTys[i+1] = Params[i];
284  }
285 
286  ContainedTys = SubTys;
287  NumContainedTys = Params.size() + 1; // + 1 for result type
288 }
289 
290 // This is the factory function for the FunctionType class.
292  ArrayRef<Type*> Params, bool isVarArg) {
293  LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
294  FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg);
295  auto I = pImpl->FunctionTypes.find_as(Key);
296  FunctionType *FT;
297 
298  if (I == pImpl->FunctionTypes.end()) {
299  FT = (FunctionType *)pImpl->TypeAllocator.Allocate(
300  sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1),
301  alignof(FunctionType));
302  new (FT) FunctionType(ReturnType, Params, isVarArg);
303  pImpl->FunctionTypes.insert(FT);
304  } else {
305  FT = *I;
306  }
307 
308  return FT;
309 }
310 
311 FunctionType *FunctionType::get(Type *Result, bool isVarArg) {
312  return get(Result, None, isVarArg);
313 }
314 
316  return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
317  !RetTy->isMetadataTy();
318 }
319 
321  return ArgTy->isFirstClassType();
322 }
323 
324 //===----------------------------------------------------------------------===//
325 // StructType Implementation
326 //===----------------------------------------------------------------------===//
327 
328 // Primitive Constructors.
329 
331  bool isPacked) {
332  LLVMContextImpl *pImpl = Context.pImpl;
333  AnonStructTypeKeyInfo::KeyTy Key(ETypes, isPacked);
334  auto I = pImpl->AnonStructTypes.find_as(Key);
335  StructType *ST;
336 
337  if (I == pImpl->AnonStructTypes.end()) {
338  // Value not found. Create a new type!
339  ST = new (Context.pImpl->TypeAllocator) StructType(Context);
340  ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
341  ST->setBody(ETypes, isPacked);
342  Context.pImpl->AnonStructTypes.insert(ST);
343  } else {
344  ST = *I;
345  }
346 
347  return ST;
348 }
349 
350 void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
351  assert(isOpaque() && "Struct body already set!");
352 
353  setSubclassData(getSubclassData() | SCDB_HasBody);
354  if (isPacked)
355  setSubclassData(getSubclassData() | SCDB_Packed);
356 
357  NumContainedTys = Elements.size();
358 
359  if (Elements.empty()) {
360  ContainedTys = nullptr;
361  return;
362  }
363 
364  ContainedTys = Elements.copy(getContext().pImpl->TypeAllocator).data();
365 }
366 
368  if (Name == getName()) return;
369 
371  typedef StringMap<StructType *>::MapEntryTy EntryTy;
372 
373  // If this struct already had a name, remove its symbol table entry. Don't
374  // delete the data yet because it may be part of the new name.
375  if (SymbolTableEntry)
376  SymbolTable.remove((EntryTy *)SymbolTableEntry);
377 
378  // If this is just removing the name, we're done.
379  if (Name.empty()) {
380  if (SymbolTableEntry) {
381  // Delete the old string data.
382  ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
383  SymbolTableEntry = nullptr;
384  }
385  return;
386  }
387 
388  // Look up the entry for the name.
389  auto IterBool =
390  getContext().pImpl->NamedStructTypes.insert(std::make_pair(Name, this));
391 
392  // While we have a name collision, try a random rename.
393  if (!IterBool.second) {
394  SmallString<64> TempStr(Name);
395  TempStr.push_back('.');
396  raw_svector_ostream TmpStream(TempStr);
397  unsigned NameSize = Name.size();
398 
399  do {
400  TempStr.resize(NameSize + 1);
401  TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
402 
403  IterBool = getContext().pImpl->NamedStructTypes.insert(
404  std::make_pair(TmpStream.str(), this));
405  } while (!IterBool.second);
406  }
407 
408  // Delete the old string data.
409  if (SymbolTableEntry)
410  ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
411  SymbolTableEntry = &*IterBool.first;
412 }
413 
414 //===----------------------------------------------------------------------===//
415 // StructType Helper functions.
416 
418  StructType *ST = new (Context.pImpl->TypeAllocator) StructType(Context);
419  if (!Name.empty())
420  ST->setName(Name);
421  return ST;
422 }
423 
425  return get(Context, None, isPacked);
426 }
427 
429  assert(type && "Cannot create a struct type with no elements with this");
430  LLVMContext &Ctx = type->getContext();
431  va_list ap;
432  SmallVector<llvm::Type*, 8> StructFields;
433  va_start(ap, type);
434  while (type) {
435  StructFields.push_back(type);
436  type = va_arg(ap, llvm::Type*);
437  }
438  auto *Ret = llvm::StructType::get(Ctx, StructFields);
439  va_end(ap);
440  return Ret;
441 }
442 
444  StringRef Name, bool isPacked) {
445  StructType *ST = create(Context, Name);
446  ST->setBody(Elements, isPacked);
447  return ST;
448 }
449 
451  return create(Context, Elements, StringRef());
452 }
453 
455  return create(Context, StringRef());
456 }
457 
459  bool isPacked) {
460  assert(!Elements.empty() &&
461  "This method may not be invoked with an empty list");
462  return create(Elements[0]->getContext(), Elements, Name, isPacked);
463 }
464 
466  assert(!Elements.empty() &&
467  "This method may not be invoked with an empty list");
468  return create(Elements[0]->getContext(), Elements, StringRef());
469 }
470 
472  assert(type && "Cannot create a struct type with no elements with this");
473  LLVMContext &Ctx = type->getContext();
474  va_list ap;
475  SmallVector<llvm::Type*, 8> StructFields;
476  va_start(ap, type);
477  while (type) {
478  StructFields.push_back(type);
479  type = va_arg(ap, llvm::Type*);
480  }
481  auto *Ret = llvm::StructType::create(Ctx, StructFields, Name);
482  va_end(ap);
483  return Ret;
484 }
485 
487  if ((getSubclassData() & SCDB_IsSized) != 0)
488  return true;
489  if (isOpaque())
490  return false;
491 
492  if (Visited && !Visited->insert(const_cast<StructType*>(this)).second)
493  return false;
494 
495  // Okay, our struct is sized if all of the elements are, but if one of the
496  // elements is opaque, the struct isn't sized *yet*, but may become sized in
497  // the future, so just bail out without caching.
498  for (element_iterator I = element_begin(), E = element_end(); I != E; ++I)
499  if (!(*I)->isSized(Visited))
500  return false;
501 
502  // Here we cheat a bit and cast away const-ness. The goal is to memoize when
503  // we find a sized type, as types can only move from opaque to sized, not the
504  // other way.
505  const_cast<StructType*>(this)->setSubclassData(
506  getSubclassData() | SCDB_IsSized);
507  return true;
508 }
509 
511  assert(!isLiteral() && "Literal structs never have names");
512  if (!SymbolTableEntry) return StringRef();
513 
514  return ((StringMapEntry<StructType*> *)SymbolTableEntry)->getKey();
515 }
516 
517 void StructType::setBody(Type *type, ...) {
518  assert(type && "Cannot create a struct type with no elements with this");
519  va_list ap;
520  SmallVector<llvm::Type*, 8> StructFields;
521  va_start(ap, type);
522  while (type) {
523  StructFields.push_back(type);
524  type = va_arg(ap, llvm::Type*);
525  }
526  setBody(StructFields);
527  va_end(ap);
528 }
529 
531  return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
532  !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
533  !ElemTy->isTokenTy();
534 }
535 
537  if (this == Other) return true;
538 
539  if (isPacked() != Other->isPacked())
540  return false;
541 
542  return elements() == Other->elements();
543 }
544 
546  return getContext().pImpl->NamedStructTypes.lookup(Name);
547 }
548 
549 
550 //===----------------------------------------------------------------------===//
551 // CompositeType Implementation
552 //===----------------------------------------------------------------------===//
553 
555  if (auto *STy = dyn_cast<StructType>(this)) {
556  unsigned Idx =
557  (unsigned)cast<Constant>(V)->getUniqueInteger().getZExtValue();
558  assert(indexValid(Idx) && "Invalid structure index!");
559  return STy->getElementType(Idx);
560  }
561 
562  return cast<SequentialType>(this)->getElementType();
563 }
564 
565 Type *CompositeType::getTypeAtIndex(unsigned Idx) const{
566  if (auto *STy = dyn_cast<StructType>(this)) {
567  assert(indexValid(Idx) && "Invalid structure index!");
568  return STy->getElementType(Idx);
569  }
570 
571  return cast<SequentialType>(this)->getElementType();
572 }
573 
574 bool CompositeType::indexValid(const Value *V) const {
575  if (auto *STy = dyn_cast<StructType>(this)) {
576  // Structure indexes require (vectors of) 32-bit integer constants. In the
577  // vector case all of the indices must be equal.
578  if (!V->getType()->getScalarType()->isIntegerTy(32))
579  return false;
580  const Constant *C = dyn_cast<Constant>(V);
581  if (C && V->getType()->isVectorTy())
582  C = C->getSplatValue();
583  const ConstantInt *CU = dyn_cast_or_null<ConstantInt>(C);
584  return CU && CU->getZExtValue() < STy->getNumElements();
585  }
586 
587  // Sequential types can be indexed by any integer.
588  return V->getType()->isIntOrIntVectorTy();
589 }
590 
591 bool CompositeType::indexValid(unsigned Idx) const {
592  if (auto *STy = dyn_cast<StructType>(this))
593  return Idx < STy->getNumElements();
594  // Sequential types can be indexed by any integer.
595  return true;
596 }
597 
598 
599 //===----------------------------------------------------------------------===//
600 // ArrayType Implementation
601 //===----------------------------------------------------------------------===//
602 
603 ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
604  : SequentialType(ArrayTyID, ElType, NumEl) {}
605 
606 ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
607  assert(isValidElementType(ElementType) && "Invalid type for array element!");
608 
609  LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
610  ArrayType *&Entry =
611  pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)];
612 
613  if (!Entry)
614  Entry = new (pImpl->TypeAllocator) ArrayType(ElementType, NumElements);
615  return Entry;
616 }
617 
619  return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
620  !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
621  !ElemTy->isTokenTy();
622 }
623 
624 //===----------------------------------------------------------------------===//
625 // VectorType Implementation
626 //===----------------------------------------------------------------------===//
627 
628 VectorType::VectorType(Type *ElType, unsigned NumEl)
629  : SequentialType(VectorTyID, ElType, NumEl) {}
630 
631 VectorType *VectorType::get(Type *ElementType, unsigned NumElements) {
632  assert(NumElements > 0 && "#Elements of a VectorType must be greater than 0");
633  assert(isValidElementType(ElementType) && "Element type of a VectorType must "
634  "be an integer, floating point, or "
635  "pointer type.");
636 
637  LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
638  VectorType *&Entry = ElementType->getContext().pImpl
639  ->VectorTypes[std::make_pair(ElementType, NumElements)];
640 
641  if (!Entry)
642  Entry = new (pImpl->TypeAllocator) VectorType(ElementType, NumElements);
643  return Entry;
644 }
645 
647  return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
648  ElemTy->isPointerTy();
649 }
650 
651 //===----------------------------------------------------------------------===//
652 // PointerType Implementation
653 //===----------------------------------------------------------------------===//
654 
656  assert(EltTy && "Can't get a pointer to <null> type!");
657  assert(isValidElementType(EltTy) && "Invalid type for pointer element!");
658 
659  LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
660 
661  // Since AddressSpace #0 is the common case, we special case it.
662  PointerType *&Entry = AddressSpace == 0 ? CImpl->PointerTypes[EltTy]
663  : CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)];
664 
665  if (!Entry)
666  Entry = new (CImpl->TypeAllocator) PointerType(EltTy, AddressSpace);
667  return Entry;
668 }
669 
670 
671 PointerType::PointerType(Type *E, unsigned AddrSpace)
672  : Type(E->getContext(), PointerTyID), PointeeTy(E) {
673  ContainedTys = &PointeeTy;
674  NumContainedTys = 1;
675  setSubclassData(AddrSpace);
676 }
677 
678 PointerType *Type::getPointerTo(unsigned addrs) const {
679  return PointerType::get(const_cast<Type*>(this), addrs);
680 }
681 
683  return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
684  !ElemTy->isMetadataTy() && !ElemTy->isTokenTy();
685 }
686 
688  return isValidElementType(ElemTy) && !ElemTy->isFunctionTy();
689 }
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
Maximum number of bits that can be specified.
Definition: DerivedTypes.h:51
DenseMap< unsigned, IntegerType * > IntegerTypes
void push_back(const T &Elt)
Definition: SmallVector.h:211
7: Labels
Definition: Type.h:63
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:158
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:166
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
Definition: APInt.h:458
LLVMContext & Context
Minimum number of bits that can be specified.
Definition: DerivedTypes.h:50
size_t i
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
Definition: DerivedTypes.h:253
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:36
APInt getMask() const
For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
Definition: Type.cpp:263
void remove(MapEntryTy *KeyValue)
remove - Remove the specified key/value pair from the map, but do not erase it.
Definition: StringMap.h:414
2: 32-bit floating point type
Definition: Type.h:58
Constant * getSplatValue() const
If this is a splat vector constant, meaning that all of the elements have the same value...
Definition: Constants.cpp:1290
static PointerType * getInt32PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:221
bool indexValid(const Value *V) const
Definition: Type.cpp:574
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Definition: Type.cpp:655
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:490
bool isTokenTy() const
Return true if this is 'token'.
Definition: Type.h:192
int getFPMantissaWidth() const
Return the width of the mantissa of this type.
Definition: Type.cpp:127
4: 80-bit floating point type (X87)
Definition: Type.h:60
static bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
Definition: Type.cpp:315
static bool isLoadableOrStorableType(Type *ElemTy)
Return true if we can load or store from a pointer to this type.
Definition: Type.cpp:687
1: 16-bit floating point type
Definition: Type.h:57
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:65
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:170
DenseMap< std::pair< Type *, unsigned >, PointerType * > ASPointerTypes
static Type * getMetadataTy(LLVMContext &C)
Definition: Type.cpp:159
static bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
Definition: Type.cpp:320
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:168
static Type * getX86_MMXTy(LLVMContext &C)
Definition: Type.cpp:164
static PointerType * getX86_MMXPtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:201
StructType * getTypeByName(StringRef Name) const
Return the type with the specified name, or null if there is none by that name.
Definition: Type.cpp:545
static PointerType * getInt64PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:225
static Type * getX86_FP80Ty(LLVMContext &C)
Definition: Type.cpp:161
Type *const * ContainedTys
A pointer to the array of Types contained by this Type.
Definition: Type.h:110
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:345
element_iterator element_end() const
Definition: DerivedTypes.h:280
bool isPacked() const
Definition: DerivedTypes.h:245
static Type * getTokenTy(LLVMContext &C)
Definition: Type.cpp:160
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:278
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:157
Class to represent struct types.
Definition: DerivedTypes.h:199
bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'. ...
Definition: Type.cpp:54
DenseMap< std::pair< Type *, uint64_t >, ArrayType * > ArrayTypes
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition...
Definition: DerivedTypes.h:249
TypeID
Definitions of all of the base types for the Type system.
Definition: Type.h:54
element_iterator element_begin() const
Definition: DerivedTypes.h:279
static PointerType * getInt16PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:217
ArrayRef< T > copy(Allocator &A)
Definition: ArrayRef.h:156
static Type * getPPC_FP128Ty(LLVMContext &C)
Definition: Type.cpp:163
BumpPtrAllocator TypeAllocator
TypeAllocator - All dynamically allocated types are allocated from this.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:154
Class to represent function types.
Definition: DerivedTypes.h:102
static Type * getLabelTy(LLVMContext &C)
Definition: Type.cpp:155
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
ArrayRef< Type * > const elements() const
Definition: DerivedTypes.h:281
Class to represent array types.
Definition: DerivedTypes.h:345
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:646
static PointerType * getDoublePtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:185
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
Definition: Type.h:233
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:291
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:160
unsigned getSubclassData() const
Definition: Type.h:94
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:135
DenseMap< std::pair< Type *, unsigned >, VectorType * > VectorTypes
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.cpp:44
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
Class to represent pointers.
Definition: DerivedTypes.h:443
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
11: Arbitrary bit width integers
Definition: Type.h:70
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:254
0: type with no size
Definition: Type.h:56
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:201
static IntegerType * getInt128Ty(LLVMContext &C)
Definition: Type.cpp:171
constexpr bool isPowerOf2_32(uint32_t Value)
isPowerOf2_32 - This function returns true if the argument is a power of two > 0. ...
Definition: MathExtras.h:399
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:219
This is an important base class in LLVM.
Definition: Constant.h:42
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:212
10: Tokens
Definition: Type.h:66
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:168
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:368
bool isLayoutIdentical(StructType *Other) const
Return true if this is layout identical to the specified struct.
Definition: Type.cpp:536
iterator find_as(const LookupKeyT &Val)
Alternative version of find() which allows a different, and possibly less expensive, key type.
Definition: DenseSet.h:157
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:154
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
Class to represent integer types.
Definition: DerivedTypes.h:39
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:136
static PointerType * getPPC_FP128PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:197
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:530
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:213
static PointerType * getFloatPtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:181
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:213
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
Definition: Type.cpp:350
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:50
static Type * getFP128Ty(LLVMContext &C)
Definition: Type.cpp:162
static PointerType * getX86_FP80PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:189
This is the superclass of the array and vector type classes.
Definition: DerivedTypes.h:319
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:156
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:234
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:209
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:682
This is the shared class of boolean and integer constants.
Definition: Constants.h:88
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:204
16: SIMD 'packed' format, or other vector type
Definition: Type.h:75
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:330
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Definition: Type.cpp:123
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
AllocatorTy & getAllocator()
Definition: StringMap.h:291
AddressSpace
Definition: NVPTXBaseInfo.h:22
FunctionTypeSet FunctionTypes
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:173
static PointerType * getHalfPtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:177
StringRef str()
Return a StringRef for the vector contents.
Definition: raw_ostream.h:515
static Type * getPrimitiveType(LLVMContext &C, TypeID IDNumber)
Return a type based on an identifier.
Definition: Type.cpp:26
static PointerType * getFP128PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:193
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
isSized - Return true if this is a sized type.
Definition: Type.cpp:486
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
8: Metadata
Definition: Type.h:64
Symbol info for RuntimeDyld.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:223
Class to represent vector types.
Definition: DerivedTypes.h:369
Class for arbitrary precision integers.
Definition: APInt.h:77
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:195
StringRef getName() const
Return the name for this struct type if it has an identity.
Definition: Type.cpp:510
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:130
StructTypeSet AnonStructTypes
void setName(StringRef Name)
Change the name of this type to the specified name, or to a name with a suffix if there is a collisio...
Definition: Type.cpp:367
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:169
StringMap< StructType * > NamedStructTypes
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:618
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:606
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:287
bool isPowerOf2ByteWidth() const
This method determines if the width of this IntegerType is a power-of-2 in terms of 8 bit bytes...
Definition: Type.cpp:258
IntegerType(LLVMContext &C, unsigned NumBits)
Definition: DerivedTypes.h:43
static PointerType * getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS=0)
Definition: Type.cpp:205
bool isVarArg() const
Definition: DerivedTypes.h:122
3: 64-bit floating point type
Definition: Type.h:59
void setSubclassData(unsigned val)
Definition: Type.h:96
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty...
Definition: Type.cpp:91
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:108
bool isLabelTy() const
Return true if this is 'label'.
Definition: Type.h:186
LLVM Value Representation.
Definition: Value.h:71
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:631
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:417
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
Definition: Type.cpp:678
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
DenseMap< Type *, PointerType * > PointerTypes
9: MMX vectors (64 bits, X86 specific)
Definition: Type.h:65
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:167
unsigned NumContainedTys
Keeps track of how many Type*'s there are in the ContainedTys list.
Definition: Type.h:103
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Definition: Type.cpp:554
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:222
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:61
bool isMetadataTy() const
Return true if this is 'metadata'.
Definition: Type.h:189
void resize(size_type N)
Definition: SmallVector.h:352