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