LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  default:
39  return 0;
40  }
41 }
42 
43 /// getScalarType - If this is a vector type, return the element type,
44 /// otherwise return this.
46  if (VectorType *VTy = dyn_cast<VectorType>(this))
47  return VTy->getElementType();
48  return this;
49 }
50 
51 const Type *Type::getScalarType() const {
52  if (const VectorType *VTy = dyn_cast<VectorType>(this))
53  return VTy->getElementType();
54  return this;
55 }
56 
57 /// isIntegerTy - Return true if this is an IntegerType of the specified width.
58 bool Type::isIntegerTy(unsigned Bitwidth) const {
59  return isIntegerTy() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;
60 }
61 
62 // canLosslesslyBitCastTo - Return true if this type can be converted to
63 // 'Ty' without any reinterpretation of bits. For example, i8* to i32*.
64 //
66  // Identity cast means no change so return true
67  if (this == Ty)
68  return true;
69 
70  // They are not convertible unless they are at least first class types
71  if (!this->isFirstClassType() || !Ty->isFirstClassType())
72  return false;
73 
74  // Vector -> Vector conversions are always lossless if the two vector types
75  // have the same size, otherwise not. Also, 64-bit vector types can be
76  // converted to x86mmx.
77  if (const VectorType *thisPTy = dyn_cast<VectorType>(this)) {
78  if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
79  return thisPTy->getBitWidth() == thatPTy->getBitWidth();
80  if (Ty->getTypeID() == Type::X86_MMXTyID &&
81  thisPTy->getBitWidth() == 64)
82  return true;
83  }
84 
85  if (this->getTypeID() == Type::X86_MMXTyID)
86  if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
87  if (thatPTy->getBitWidth() == 64)
88  return true;
89 
90  // At this point we have only various mismatches of the first class types
91  // remaining and ptr->ptr. Just select the lossless conversions. Everything
92  // else is not lossless.
93  if (this->isPointerTy())
94  return Ty->isPointerTy();
95  return false; // Other types have no identity values
96 }
97 
98 bool Type::isEmptyTy() const {
99  const ArrayType *ATy = dyn_cast<ArrayType>(this);
100  if (ATy) {
101  unsigned NumElements = ATy->getNumElements();
102  return NumElements == 0 || ATy->getElementType()->isEmptyTy();
103  }
104 
105  const StructType *STy = dyn_cast<StructType>(this);
106  if (STy) {
107  unsigned NumElements = STy->getNumElements();
108  for (unsigned i = 0; i < NumElements; ++i)
109  if (!STy->getElementType(i)->isEmptyTy())
110  return false;
111  return true;
112  }
113 
114  return false;
115 }
116 
118  switch (getTypeID()) {
119  case Type::HalfTyID: return 16;
120  case Type::FloatTyID: return 32;
121  case Type::DoubleTyID: return 64;
122  case Type::X86_FP80TyID: return 80;
123  case Type::FP128TyID: return 128;
124  case Type::PPC_FP128TyID: return 128;
125  case Type::X86_MMXTyID: return 64;
126  case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
127  case Type::VectorTyID: return cast<VectorType>(this)->getBitWidth();
128  default: return 0;
129  }
130 }
131 
132 /// getScalarSizeInBits - If this is a vector type, return the
133 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
134 /// getPrimitiveSizeInBits value for this type.
137 }
138 
139 /// getFPMantissaWidth - Return the width of the mantissa of this type. This
140 /// is only valid on floating point types. If the FP type does not
141 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
143  if (const VectorType *VTy = dyn_cast<VectorType>(this))
144  return VTy->getElementType()->getFPMantissaWidth();
145  assert(isFloatingPointTy() && "Not a floating point type!");
146  if (getTypeID() == HalfTyID) return 11;
147  if (getTypeID() == FloatTyID) return 24;
148  if (getTypeID() == DoubleTyID) return 53;
149  if (getTypeID() == X86_FP80TyID) return 64;
150  if (getTypeID() == FP128TyID) return 113;
151  assert(getTypeID() == PPC_FP128TyID && "unknown fp type");
152  return -1;
153 }
154 
155 /// isSizedDerivedType - Derived types like structures and arrays are sized
156 /// iff all of the members of the type are sized as well. Since asking for
157 /// their size is relatively uncommon, move this operation out of line.
158 bool Type::isSizedDerivedType() const {
159  if (this->isIntegerTy())
160  return true;
161 
162  if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
163  return ATy->getElementType()->isSized();
164 
165  if (const VectorType *VTy = dyn_cast<VectorType>(this))
166  return VTy->getElementType()->isSized();
167 
168  if (!this->isStructTy())
169  return false;
170 
171  return cast<StructType>(this)->isSized();
172 }
173 
174 //===----------------------------------------------------------------------===//
175 // Subclass Helper Methods
176 //===----------------------------------------------------------------------===//
177 
178 unsigned Type::getIntegerBitWidth() const {
179  return cast<IntegerType>(this)->getBitWidth();
180 }
181 
183  return cast<FunctionType>(this)->isVarArg();
184 }
185 
186 Type *Type::getFunctionParamType(unsigned i) const {
187  return cast<FunctionType>(this)->getParamType(i);
188 }
189 
190 unsigned Type::getFunctionNumParams() const {
191  return cast<FunctionType>(this)->getNumParams();
192 }
193 
195  return cast<StructType>(this)->getName();
196 }
197 
198 unsigned Type::getStructNumElements() const {
199  return cast<StructType>(this)->getNumElements();
200 }
201 
203  return cast<StructType>(this)->getElementType(N);
204 }
205 
207  return cast<SequentialType>(this)->getElementType();
208 }
209 
210 uint64_t Type::getArrayNumElements() const {
211  return cast<ArrayType>(this)->getNumElements();
212 }
213 
214 unsigned Type::getVectorNumElements() const {
215  return cast<VectorType>(this)->getNumElements();
216 }
217 
219  return cast<PointerType>(getScalarType())->getAddressSpace();
220 }
221 
222 
223 //===----------------------------------------------------------------------===//
224 // Primitive 'Type' data
225 //===----------------------------------------------------------------------===//
226 
237 
243 
245  return IntegerType::get(C, N);
246 }
247 
249  return getHalfTy(C)->getPointerTo(AS);
250 }
251 
253  return getFloatTy(C)->getPointerTo(AS);
254 }
255 
257  return getDoubleTy(C)->getPointerTo(AS);
258 }
259 
261  return getX86_FP80Ty(C)->getPointerTo(AS);
262 }
263 
265  return getFP128Ty(C)->getPointerTo(AS);
266 }
267 
269  return getPPC_FP128Ty(C)->getPointerTo(AS);
270 }
271 
273  return getX86_MMXTy(C)->getPointerTo(AS);
274 }
275 
276 PointerType *Type::getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS) {
277  return getIntNTy(C, N)->getPointerTo(AS);
278 }
279 
281  return getInt1Ty(C)->getPointerTo(AS);
282 }
283 
285  return getInt8Ty(C)->getPointerTo(AS);
286 }
287 
289  return getInt16Ty(C)->getPointerTo(AS);
290 }
291 
293  return getInt32Ty(C)->getPointerTo(AS);
294 }
295 
297  return getInt64Ty(C)->getPointerTo(AS);
298 }
299 
300 
301 //===----------------------------------------------------------------------===//
302 // IntegerType Implementation
303 //===----------------------------------------------------------------------===//
304 
306  assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
307  assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
308 
309  // Check for the built-in integer types
310  switch (NumBits) {
311  case 1: return cast<IntegerType>(Type::getInt1Ty(C));
312  case 8: return cast<IntegerType>(Type::getInt8Ty(C));
313  case 16: return cast<IntegerType>(Type::getInt16Ty(C));
314  case 32: return cast<IntegerType>(Type::getInt32Ty(C));
315  case 64: return cast<IntegerType>(Type::getInt64Ty(C));
316  default:
317  break;
318  }
319 
320  IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits];
321 
322  if (Entry == 0)
323  Entry = new (C.pImpl->TypeAllocator) IntegerType(C, NumBits);
324 
325  return Entry;
326 }
327 
329  unsigned BitWidth = getBitWidth();
330  return (BitWidth > 7) && isPowerOf2_32(BitWidth);
331 }
332 
335 }
336 
337 //===----------------------------------------------------------------------===//
338 // FunctionType Implementation
339 //===----------------------------------------------------------------------===//
340 
341 FunctionType::FunctionType(Type *Result, ArrayRef<Type*> Params,
342  bool IsVarArgs)
343  : Type(Result->getContext(), FunctionTyID) {
344  Type **SubTys = reinterpret_cast<Type**>(this+1);
345  assert(isValidReturnType(Result) && "invalid return type for function");
346  setSubclassData(IsVarArgs);
347 
348  SubTys[0] = const_cast<Type*>(Result);
349 
350  for (unsigned i = 0, e = Params.size(); i != e; ++i) {
351  assert(isValidArgumentType(Params[i]) &&
352  "Not a valid type for function argument!");
353  SubTys[i+1] = Params[i];
354  }
355 
356  ContainedTys = SubTys;
357  NumContainedTys = Params.size() + 1; // + 1 for result type
358 }
359 
360 // FunctionType::get - The factory function for the FunctionType class.
362  ArrayRef<Type*> Params, bool isVarArg) {
363  LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
364  FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg);
366  pImpl->FunctionTypes.find_as(Key);
367  FunctionType *FT;
368 
369  if (I == pImpl->FunctionTypes.end()) {
370  FT = (FunctionType*) pImpl->TypeAllocator.
371  Allocate(sizeof(FunctionType) + sizeof(Type*) * (Params.size() + 1),
373  new (FT) FunctionType(ReturnType, Params, isVarArg);
374  pImpl->FunctionTypes[FT] = true;
375  } else {
376  FT = I->first;
377  }
378 
379  return FT;
380 }
381 
382 FunctionType *FunctionType::get(Type *Result, bool isVarArg) {
383  return get(Result, None, isVarArg);
384 }
385 
386 /// isValidReturnType - Return true if the specified type is valid as a return
387 /// type.
389  return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
390  !RetTy->isMetadataTy();
391 }
392 
393 /// isValidArgumentType - Return true if the specified type is valid as an
394 /// argument type.
396  return ArgTy->isFirstClassType();
397 }
398 
399 //===----------------------------------------------------------------------===//
400 // StructType Implementation
401 //===----------------------------------------------------------------------===//
402 
403 // Primitive Constructors.
404 
406  bool isPacked) {
407  LLVMContextImpl *pImpl = Context.pImpl;
408  AnonStructTypeKeyInfo::KeyTy Key(ETypes, isPacked);
410  pImpl->AnonStructTypes.find_as(Key);
411  StructType *ST;
412 
413  if (I == pImpl->AnonStructTypes.end()) {
414  // Value not found. Create a new type!
415  ST = new (Context.pImpl->TypeAllocator) StructType(Context);
416  ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
417  ST->setBody(ETypes, isPacked);
418  Context.pImpl->AnonStructTypes[ST] = true;
419  } else {
420  ST = I->first;
421  }
422 
423  return ST;
424 }
425 
426 void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
427  assert(isOpaque() && "Struct body already set!");
428 
429  setSubclassData(getSubclassData() | SCDB_HasBody);
430  if (isPacked)
431  setSubclassData(getSubclassData() | SCDB_Packed);
432 
433  unsigned NumElements = Elements.size();
434  Type **Elts = getContext().pImpl->TypeAllocator.Allocate<Type*>(NumElements);
435  memcpy(Elts, Elements.data(), sizeof(Elements[0]) * NumElements);
436 
437  ContainedTys = Elts;
438  NumContainedTys = NumElements;
439 }
440 
442  if (Name == getName()) return;
443 
445  typedef StringMap<StructType *>::MapEntryTy EntryTy;
446 
447  // If this struct already had a name, remove its symbol table entry. Don't
448  // delete the data yet because it may be part of the new name.
449  if (SymbolTableEntry)
450  SymbolTable.remove((EntryTy *)SymbolTableEntry);
451 
452  // If this is just removing the name, we're done.
453  if (Name.empty()) {
454  if (SymbolTableEntry) {
455  // Delete the old string data.
456  ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
457  SymbolTableEntry = 0;
458  }
459  return;
460  }
461 
462  // Look up the entry for the name.
463  EntryTy *Entry = &getContext().pImpl->NamedStructTypes.GetOrCreateValue(Name);
464 
465  // While we have a name collision, try a random rename.
466  if (Entry->getValue()) {
467  SmallString<64> TempStr(Name);
468  TempStr.push_back('.');
469  raw_svector_ostream TmpStream(TempStr);
470  unsigned NameSize = Name.size();
471 
472  do {
473  TempStr.resize(NameSize + 1);
474  TmpStream.resync();
475  TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
476 
477  Entry = &getContext().pImpl->
478  NamedStructTypes.GetOrCreateValue(TmpStream.str());
479  } while (Entry->getValue());
480  }
481 
482  // Okay, we found an entry that isn't used. It's us!
483  Entry->setValue(this);
484 
485  // Delete the old string data.
486  if (SymbolTableEntry)
487  ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
488  SymbolTableEntry = Entry;
489 }
490 
491 //===----------------------------------------------------------------------===//
492 // StructType Helper functions.
493 
495  StructType *ST = new (Context.pImpl->TypeAllocator) StructType(Context);
496  if (!Name.empty())
497  ST->setName(Name);
498  return ST;
499 }
500 
501 StructType *StructType::get(LLVMContext &Context, bool isPacked) {
502  return get(Context, None, isPacked);
503 }
504 
506  assert(type != 0 && "Cannot create a struct type with no elements with this");
507  LLVMContext &Ctx = type->getContext();
508  va_list ap;
509  SmallVector<llvm::Type*, 8> StructFields;
510  va_start(ap, type);
511  while (type) {
512  StructFields.push_back(type);
513  type = va_arg(ap, llvm::Type*);
514  }
515  return llvm::StructType::get(Ctx, StructFields);
516 }
517 
519  StringRef Name, bool isPacked) {
520  StructType *ST = create(Context, Name);
521  ST->setBody(Elements, isPacked);
522  return ST;
523 }
524 
526  return create(Context, Elements, StringRef());
527 }
528 
530  return create(Context, StringRef());
531 }
532 
534  bool isPacked) {
535  assert(!Elements.empty() &&
536  "This method may not be invoked with an empty list");
537  return create(Elements[0]->getContext(), Elements, Name, isPacked);
538 }
539 
541  assert(!Elements.empty() &&
542  "This method may not be invoked with an empty list");
543  return create(Elements[0]->getContext(), Elements, StringRef());
544 }
545 
547  assert(type != 0 && "Cannot create a struct type with no elements with this");
548  LLVMContext &Ctx = type->getContext();
549  va_list ap;
550  SmallVector<llvm::Type*, 8> StructFields;
551  va_start(ap, type);
552  while (type) {
553  StructFields.push_back(type);
554  type = va_arg(ap, llvm::Type*);
555  }
556  return llvm::StructType::create(Ctx, StructFields, Name);
557 }
558 
559 bool StructType::isSized() const {
560  if ((getSubclassData() & SCDB_IsSized) != 0)
561  return true;
562  if (isOpaque())
563  return false;
564 
565  // Okay, our struct is sized if all of the elements are, but if one of the
566  // elements is opaque, the struct isn't sized *yet*, but may become sized in
567  // the future, so just bail out without caching.
568  for (element_iterator I = element_begin(), E = element_end(); I != E; ++I)
569  if (!(*I)->isSized())
570  return false;
571 
572  // Here we cheat a bit and cast away const-ness. The goal is to memoize when
573  // we find a sized type, as types can only move from opaque to sized, not the
574  // other way.
575  const_cast<StructType*>(this)->setSubclassData(
576  getSubclassData() | SCDB_IsSized);
577  return true;
578 }
579 
581  assert(!isLiteral() && "Literal structs never have names");
582  if (SymbolTableEntry == 0) return StringRef();
583 
584  return ((StringMapEntry<StructType*> *)SymbolTableEntry)->getKey();
585 }
586 
587 void StructType::setBody(Type *type, ...) {
588  assert(type != 0 && "Cannot create a struct type with no elements with this");
589  va_list ap;
590  SmallVector<llvm::Type*, 8> StructFields;
591  va_start(ap, type);
592  while (type) {
593  StructFields.push_back(type);
594  type = va_arg(ap, llvm::Type*);
595  }
596  setBody(StructFields);
597 }
598 
600  return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
601  !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
602 }
603 
604 /// isLayoutIdentical - Return true if this is layout identical to the
605 /// specified struct.
607  if (this == Other) return true;
608 
609  if (isPacked() != Other->isPacked() ||
610  getNumElements() != Other->getNumElements())
611  return false;
612 
613  return std::equal(element_begin(), element_end(), Other->element_begin());
614 }
615 
616 /// getTypeByName - Return the type with the specified name, or null if there
617 /// is none by that name.
619  return getContext().pImpl->NamedStructTypes.lookup(Name);
620 }
621 
622 
623 //===----------------------------------------------------------------------===//
624 // CompositeType Implementation
625 //===----------------------------------------------------------------------===//
626 
628  if (StructType *STy = dyn_cast<StructType>(this)) {
629  unsigned Idx =
630  (unsigned)cast<Constant>(V)->getUniqueInteger().getZExtValue();
631  assert(indexValid(Idx) && "Invalid structure index!");
632  return STy->getElementType(Idx);
633  }
634 
635  return cast<SequentialType>(this)->getElementType();
636 }
638  if (StructType *STy = dyn_cast<StructType>(this)) {
639  assert(indexValid(Idx) && "Invalid structure index!");
640  return STy->getElementType(Idx);
641  }
642 
643  return cast<SequentialType>(this)->getElementType();
644 }
645 bool CompositeType::indexValid(const Value *V) const {
646  if (const StructType *STy = dyn_cast<StructType>(this)) {
647  // Structure indexes require (vectors of) 32-bit integer constants. In the
648  // vector case all of the indices must be equal.
649  if (!V->getType()->getScalarType()->isIntegerTy(32))
650  return false;
651  const Constant *C = dyn_cast<Constant>(V);
652  if (C && V->getType()->isVectorTy())
653  C = C->getSplatValue();
654  const ConstantInt *CU = dyn_cast_or_null<ConstantInt>(C);
655  return CU && CU->getZExtValue() < STy->getNumElements();
656  }
657 
658  // Sequential types can be indexed by any integer.
659  return V->getType()->isIntOrIntVectorTy();
660 }
661 
662 bool CompositeType::indexValid(unsigned Idx) const {
663  if (const StructType *STy = dyn_cast<StructType>(this))
664  return Idx < STy->getNumElements();
665  // Sequential types can be indexed by any integer.
666  return true;
667 }
668 
669 
670 //===----------------------------------------------------------------------===//
671 // ArrayType Implementation
672 //===----------------------------------------------------------------------===//
673 
674 ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
675  : SequentialType(ArrayTyID, ElType) {
676  NumElements = NumEl;
677 }
678 
679 ArrayType *ArrayType::get(Type *elementType, uint64_t NumElements) {
680  Type *ElementType = const_cast<Type*>(elementType);
681  assert(isValidElementType(ElementType) && "Invalid type for array element!");
682 
683  LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
684  ArrayType *&Entry =
685  pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)];
686 
687  if (Entry == 0)
688  Entry = new (pImpl->TypeAllocator) ArrayType(ElementType, NumElements);
689  return Entry;
690 }
691 
693  return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
694  !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
695 }
696 
697 //===----------------------------------------------------------------------===//
698 // VectorType Implementation
699 //===----------------------------------------------------------------------===//
700 
701 VectorType::VectorType(Type *ElType, unsigned NumEl)
702  : SequentialType(VectorTyID, ElType) {
703  NumElements = NumEl;
704 }
705 
706 VectorType *VectorType::get(Type *elementType, unsigned NumElements) {
707  Type *ElementType = const_cast<Type*>(elementType);
708  assert(NumElements > 0 && "#Elements of a VectorType must be greater than 0");
709  assert(isValidElementType(ElementType) &&
710  "Elements of a VectorType must be a primitive type");
711 
712  LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
713  VectorType *&Entry = ElementType->getContext().pImpl
714  ->VectorTypes[std::make_pair(ElementType, NumElements)];
715 
716  if (Entry == 0)
717  Entry = new (pImpl->TypeAllocator) VectorType(ElementType, NumElements);
718  return Entry;
719 }
720 
722  return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
723  ElemTy->isPointerTy();
724 }
725 
726 //===----------------------------------------------------------------------===//
727 // PointerType Implementation
728 //===----------------------------------------------------------------------===//
729 
731  assert(EltTy && "Can't get a pointer to <null> type!");
732  assert(isValidElementType(EltTy) && "Invalid type for pointer element!");
733 
734  LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
735 
736  // Since AddressSpace #0 is the common case, we special case it.
737  PointerType *&Entry = AddressSpace == 0 ? CImpl->PointerTypes[EltTy]
738  : CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)];
739 
740  if (Entry == 0)
741  Entry = new (CImpl->TypeAllocator) PointerType(EltTy, AddressSpace);
742  return Entry;
743 }
744 
745 
746 PointerType::PointerType(Type *E, unsigned AddrSpace)
747  : SequentialType(PointerTyID, E) {
748 #ifndef NDEBUG
749  const unsigned oldNCT = NumContainedTys;
750 #endif
751  setSubclassData(AddrSpace);
752  // Check for miscompile. PR11652.
753  assert(oldNCT == NumContainedTys && "bitfield written out of bounds?");
754 }
755 
756 PointerType *Type::getPointerTo(unsigned addrs) {
757  return PointerType::get(this, addrs);
758 }
759 
761  return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
762  !ElemTy->isMetadataTy();
763 }
DenseMap< unsigned, IntegerType * > IntegerTypes
void push_back(const T &Elt)
Definition: SmallVector.h:236
7: Labels
Definition: Type.h:62
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:231
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:238
unsigned getStructNumElements() const
Definition: Type.cpp:198
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
Definition: APInt.h:450
Type * getSequentialElementType() const
Definition: Type.cpp:206
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
bool isOpaque() const
Definition: DerivedTypes.h:249
APInt getMask() const
Get a bit mask for this type.
Definition: Type.cpp:333
unsigned getScalarSizeInBits()
Definition: Type.cpp:135
void remove(MapEntryTy *KeyValue)
Definition: StringMap.h:389
2: 32-bit floating point type
Definition: Type.h:57
Constant * getSplatValue() const
Definition: Constants.cpp:1276
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:266
static PointerType * getInt32PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:292
bool indexValid(const Value *V) const
Definition: Type.cpp:645
static PointerType * get(Type *ElementType, unsigned AddressSpace)
Definition: Type.cpp:730
int getFPMantissaWidth() const
Definition: Type.cpp:142
4: 80-bit floating point type (X87)
Definition: Type.h:59
FunctionTypeMap FunctionTypes
static bool isValidReturnType(Type *RetTy)
Definition: Type.cpp:388
1: 16-bit floating point type
Definition: Type.h:56
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:61
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:242
DenseMap< std::pair< Type *, unsigned >, PointerType * > ASPointerTypes
static Type * getMetadataTy(LLVMContext &C)
Definition: Type.cpp:232
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: Type.cpp:218
static bool isValidArgumentType(Type *ArgTy)
Definition: Type.cpp:395
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:240
static Type * getX86_MMXTy(LLVMContext &C)
Definition: Type.cpp:236
static PointerType * getX86_MMXPtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:272
StructType * getTypeByName(StringRef Name) const
Definition: Type.cpp:618
static PointerType * getInt64PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:296
static Type * getX86_FP80Ty(LLVMContext &C)
Definition: Type.cpp:233
Type *const * ContainedTys
Definition: Type.h:121
element_iterator element_end() const
Definition: DerivedTypes.h:279
bool isPacked() const
Definition: DerivedTypes.h:241
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:277
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:230
bool canLosslesslyBitCastTo(Type *Ty) const
Determine if this type could be losslessly bitcast to Ty.
Definition: Type.cpp:65
iterator find_as(const LookupKeyT &Val)
Definition: DenseMap.h:127
DenseMap< std::pair< Type *, uint64_t >, ArrayType * > ArrayTypes
bool isLiteral() const
Definition: DerivedTypes.h:245
TypeID
Definition: Type.h:53
StringRef getStructName() const
Definition: Type.cpp:194
element_iterator element_begin() const
Definition: DerivedTypes.h:278
static PointerType * getInt16PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:288
Type * getFunctionParamType(unsigned i) const
Definition: Type.cpp:186
static Type * getPPC_FP128Ty(LLVMContext &C)
Definition: Type.cpp:235
BumpPtrAllocator TypeAllocator
uint64_t getZExtValue() const
Return the zero extended value.
Definition: Constants.h:116
static Type * getLabelTy(LLVMContext &C)
Definition: Type.cpp:228
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
Minimum number of bits that can be specified.
Definition: DerivedTypes.h:47
static bool isValidElementType(Type *ElemTy)
Definition: Type.cpp:721
static PointerType * getDoublePtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:256
bool isFirstClassType() const
Definition: Type.h:251
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
Definition: Type.cpp:361
TypeID getTypeID() const
Definition: Type.h:137
bool isFloatingPointTy() const
Definition: Type.h:162
unsigned getSubclassData() const
Definition: Type.h:104
DenseMap< std::pair< Type *, unsigned >, VectorType * > VectorTypes
Type * getElementType() const
Definition: DerivedTypes.h:319
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:109
10: Arbitrary bit width integers
Definition: Type.h:68
unsigned getFunctionNumParams() const
Definition: Type.cpp:190
0: type with no size
Definition: Type.h:55
bool isIntOrIntVectorTy() const
Definition: Type.h:204
StructTypeMap AnonStructTypes
bool isVectorTy() const
Definition: Type.h:229
Type * getElementType(unsigned N) const
Definition: DerivedTypes.h:287
LLVM Constant Representation.
Definition: Constant.h:41
bool isLayoutIdentical(StructType *Other) const
Definition: Type.cpp:606
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:227
Type * getTypeAtIndex(const Value *V)
Definition: Type.cpp:627
uint64_t getNumElements() const
Definition: DerivedTypes.h:348
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:61
iterator end()
Definition: DenseMap.h:57
Integer representation type.
Definition: DerivedTypes.h:37
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:104
static PointerType * getPPC_FP128PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:268
static bool isValidElementType(Type *ElemTy)
Definition: Type.cpp:599
bool isPointerTy() const
Definition: Type.h:220
static PointerType * getFloatPtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:252
PointerType * getPointerTo(unsigned AddrSpace=0)
Definition: Type.cpp:756
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:284
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
setBody - Specify a body for an opaque identified type.
Definition: Type.cpp:426
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:39
static Type * getFP128Ty(LLVMContext &C)
Definition: Type.cpp:234
static PointerType * getX86_FP80PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:260
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:229
static IntegerType * get(LLVMContext &C, unsigned NumBits)
Get or create an IntegerType instance.
Definition: Type.cpp:305
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:280
unsigned getIntegerBitWidth() const
Definition: Type.cpp:178
static bool isValidElementType(Type *ElemTy)
Definition: Type.cpp:760
Class for constant integers.
Definition: Constants.h:51
bool isFunctionTy() const
Definition: Type.h:208
15: SIMD 'packed' format, or other vector type
Definition: Type.h:73
unsigned getVectorNumElements() const
Definition: Type.cpp:214
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
Definition: Type.cpp:405
bool isFunctionVarArg() const
Definition: Type.cpp:182
Type * getType() const
Definition: Value.h:111
AddressSpace
Definition: NVPTXBaseInfo.h:22
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:244
static PointerType * getHalfPtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:248
static Type * getPrimitiveType(LLVMContext &C, TypeID IDNumber)
getPrimitiveType - Return a type based on an identifier.
Definition: Type.cpp:26
static PointerType * getFP128PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:264
8: Metadata
Definition: Type.h:63
Class for arbitrary precision integers.
Definition: APInt.h:75
void * Allocate(size_t Size, size_t Alignment)
Definition: Allocator.cpp:95
bool isIntegerTy() const
Definition: Type.h:196
StringRef getName() const
Definition: Type.cpp:580
bool isStructTy() const
Definition: Type.h:212
void setName(StringRef Name)
Definition: Type.cpp:441
std::string getName(ID id, ArrayRef< Type * > Tys=None)
Definition: Function.cpp:400
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:241
StringMap< StructType * > NamedStructTypes
static bool isValidElementType(Type *ElemTy)
Definition: Type.cpp:692
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
static ArrayType * get(Type *ElementType, uint64_t NumElements)
Definition: Type.cpp:679
bool isSized() const
isSized - Return true if this is a sized type.
Definition: Type.cpp:559
bool isPowerOf2ByteWidth() const
Is this a power-of-2 byte-width IntegerType ?
Definition: Type.cpp:328
const Type * getScalarType() const
Definition: Type.cpp:51
uint64_t getArrayNumElements() const
Definition: Type.cpp:210
unsigned getPrimitiveSizeInBits() const
Definition: Type.cpp:117
IntegerType(LLVMContext &C, unsigned NumBits)
Definition: DerivedTypes.h:41
static PointerType * getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS=0)
Definition: Type.cpp:276
bool isVarArg() const
Definition: DerivedTypes.h:120
3: 64-bit floating point type
Definition: Type.h:58
void setSubclassData(unsigned val)
Definition: Type.h:106
bool isEmptyTy() const
Definition: Type.cpp:98
bool isLabelTy() const
isLabelTy - Return true if this is 'label'.
Definition: Type.h:189
LLVM Value Representation.
Definition: Value.h:66
static VectorType * get(Type *ElementType, unsigned NumElements)
Definition: Type.cpp:706
static StructType * create(LLVMContext &Context, StringRef Name)
StructType::create - This creates an identified struct.
Definition: Type.cpp:494
bool isSized() const
Definition: Type.h:278
Type * getStructElementType(unsigned N) const
Definition: Type.cpp:202
bool isPowerOf2_32(uint32_t Value)
Definition: MathExtras.h:354
AllocatorRefTy getAllocator()
Definition: StringMap.h:267
DenseMap< Type *, PointerType * > PointerTypes
9: MMX vectors (64 bits, X86 specific)
Definition: Type.h:64
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:286
const T * data() const
Definition: ArrayRef.h:106
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:239
unsigned NumContainedTys
Definition: Type.h:114
LLVMContext & getContext() const
Definition: Module.h:249
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
Definition: Type.h:140
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:60
bool isMetadataTy() const
isMetadataTy - Return true if this is 'metadata'.
Definition: Type.h:192