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