LLVM 23.0.0git
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/SetVector.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"
23#include "llvm/IR/LLVMContext.h"
24#include "llvm/IR/Value.h"
26#include "llvm/Support/Error.h"
30#include <cassert>
31
32using 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 BFloatTyID : return getBFloatTy(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_AMXTyID : return getX86_AMXTy(C);
51 case TokenTyID : return getTokenTy(C);
52 default:
53 return nullptr;
54 }
55}
56
57bool Type::isByteTy(unsigned BitWidth) const {
58 return isByteTy() && cast<ByteType>(this)->getBitWidth() == BitWidth;
59}
60
62 if (const auto *ATy = dyn_cast<ArrayType>(this))
63 return ATy->getElementType()->isScalableTy(Visited);
64 if (const auto *STy = dyn_cast<StructType>(this))
65 return STy->isScalableTy(Visited);
67}
68
69bool Type::isScalableTy() const {
70 SmallPtrSet<const Type *, 4> Visited;
71 return isScalableTy(Visited);
72}
73
75 SmallPtrSetImpl<const Type *> &Visited) const {
76 if (const auto *ATy = dyn_cast<ArrayType>(this))
77 return ATy->getElementType()->containsNonGlobalTargetExtType(Visited);
78 if (const auto *STy = dyn_cast<StructType>(this))
79 return STy->containsNonGlobalTargetExtType(Visited);
80 if (auto *TT = dyn_cast<TargetExtType>(this))
81 return !TT->hasProperty(TargetExtType::CanBeGlobal);
82 return false;
83}
84
86 SmallPtrSet<const Type *, 4> Visited;
87 return containsNonGlobalTargetExtType(Visited);
88}
89
91 SmallPtrSetImpl<const Type *> &Visited) const {
92 if (const auto *ATy = dyn_cast<ArrayType>(this))
93 return ATy->getElementType()->containsNonLocalTargetExtType(Visited);
94 if (const auto *STy = dyn_cast<StructType>(this))
95 return STy->containsNonLocalTargetExtType(Visited);
96 if (auto *TT = dyn_cast<TargetExtType>(this))
97 return !TT->hasProperty(TargetExtType::CanBeLocal);
98 return false;
99}
100
102 SmallPtrSet<const Type *, 4> Visited;
103 return containsNonLocalTargetExtType(Visited);
104}
105
106const fltSemantics &Type::getFltSemantics() const {
107 switch (getTypeID()) {
108 case HalfTyID: return APFloat::IEEEhalf();
109 case BFloatTyID: return APFloat::BFloat();
110 case FloatTyID: return APFloat::IEEEsingle();
111 case DoubleTyID: return APFloat::IEEEdouble();
112 case X86_FP80TyID: return APFloat::x87DoubleExtended();
113 case FP128TyID: return APFloat::IEEEquad();
114 case PPC_FP128TyID: return APFloat::PPCDoubleDouble();
115 default: llvm_unreachable("Invalid floating type");
116 }
117}
118
119bool Type::isScalableTargetExtTy() const {
120 if (auto *TT = dyn_cast<TargetExtType>(this))
121 return isa<ScalableVectorType>(TT->getLayoutType());
122 return false;
123}
124
126 Type *Ty;
127 if (&S == &APFloat::IEEEhalf())
128 Ty = Type::getHalfTy(C);
129 else if (&S == &APFloat::BFloat())
130 Ty = Type::getBFloatTy(C);
131 else if (&S == &APFloat::IEEEsingle())
132 Ty = Type::getFloatTy(C);
133 else if (&S == &APFloat::IEEEdouble())
134 Ty = Type::getDoubleTy(C);
135 else if (&S == &APFloat::x87DoubleExtended())
136 Ty = Type::getX86_FP80Ty(C);
137 else if (&S == &APFloat::IEEEquad())
138 Ty = Type::getFP128Ty(C);
139 else {
140 assert(&S == &APFloat::PPCDoubleDouble() && "Unknown FP format");
141 Ty = Type::getPPC_FP128Ty(C);
142 }
143 return Ty;
144}
145
146bool Type::isRISCVVectorTupleTy() const {
147 if (!isTargetExtTy())
148 return false;
149
150 return cast<TargetExtType>(this)->getName() == "riscv.vector.tuple";
151}
152
153bool Type::canLosslesslyBitCastTo(Type *Ty) const {
154 // Identity cast means no change so return true
155 if (this == Ty)
156 return true;
157
158 // They are not convertible unless they are at least first class types
159 if (!this->isFirstClassType() || !Ty->isFirstClassType())
160 return false;
161
162 // Vector -> Vector conversions are always lossless if the two vector types
163 // have the same size, otherwise not.
164 if (isa<VectorType>(this) && isa<VectorType>(Ty))
165 return getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits();
166
167 // 8192-bit fixed width vector types can be losslessly converted to x86amx.
168 if (((isa<FixedVectorType>(this)) && Ty->isX86_AMXTy()) &&
169 getPrimitiveSizeInBits().getFixedValue() == 8192)
170 return true;
171 if ((isX86_AMXTy() && isa<FixedVectorType>(Ty)) &&
172 Ty->getPrimitiveSizeInBits().getFixedValue() == 8192)
173 return true;
174
175 // Conservatively assume we can't losslessly convert between pointers with
176 // different address spaces.
177 return false;
178}
179
180bool Type::isEmptyTy() const {
181 if (auto *ATy = dyn_cast<ArrayType>(this)) {
182 unsigned NumElements = ATy->getNumElements();
183 return NumElements == 0 || ATy->getElementType()->isEmptyTy();
184 }
185
186 if (auto *STy = dyn_cast<StructType>(this)) {
187 unsigned NumElements = STy->getNumElements();
188 for (unsigned i = 0; i < NumElements; ++i)
189 if (!STy->getElementType(i)->isEmptyTy())
190 return false;
191 return true;
192 }
193
194 return false;
195}
196
198 switch (getTypeID()) {
199 case Type::HalfTyID:
200 return TypeSize::getFixed(16);
201 case Type::BFloatTyID:
202 return TypeSize::getFixed(16);
203 case Type::FloatTyID:
204 return TypeSize::getFixed(32);
205 case Type::DoubleTyID:
206 return TypeSize::getFixed(64);
207 case Type::X86_FP80TyID:
208 return TypeSize::getFixed(80);
209 case Type::FP128TyID:
210 return TypeSize::getFixed(128);
211 case Type::PPC_FP128TyID:
212 return TypeSize::getFixed(128);
213 case Type::X86_AMXTyID:
214 return TypeSize::getFixed(8192);
215 case Type::ByteTyID:
216 return TypeSize::getFixed(cast<ByteType>(this)->getBitWidth());
217 case Type::IntegerTyID:
218 return TypeSize::getFixed(cast<IntegerType>(this)->getBitWidth());
219 case Type::FixedVectorTyID:
220 case Type::ScalableVectorTyID: {
221 const VectorType *VTy = cast<VectorType>(this);
222 ElementCount EC = VTy->getElementCount();
223 TypeSize ETS = VTy->getElementType()->getPrimitiveSizeInBits();
224 assert(!ETS.isScalable() && "Vector type should have fixed-width elements");
225 return {ETS.getFixedValue() * EC.getKnownMinValue(), EC.isScalable()};
226 }
227 default:
228 return TypeSize::getFixed(0);
229 }
230}
231
232unsigned Type::getScalarSizeInBits() const {
233 // It is safe to assume that the scalar types have a fixed size.
234 return getScalarType()->getPrimitiveSizeInBits().getFixedValue();
235}
236
237int Type::getFPMantissaWidth() const {
238 if (auto *VTy = dyn_cast<VectorType>(this))
239 return VTy->getElementType()->getFPMantissaWidth();
240 assert(isFloatingPointTy() && "Not a floating point type!");
241 if (getTypeID() == HalfTyID) return 11;
242 if (getTypeID() == BFloatTyID) return 8;
243 if (getTypeID() == FloatTyID) return 24;
244 if (getTypeID() == DoubleTyID) return 53;
245 if (getTypeID() == X86_FP80TyID) return 64;
246 if (getTypeID() == FP128TyID) return 113;
247 assert(getTypeID() == PPC_FP128TyID && "unknown fp type");
248 return -1;
249}
250
251bool Type::isFirstClassType() const {
252 switch (getTypeID()) {
253 default:
254 return true;
255 case FunctionTyID:
256 case VoidTyID:
257 return false;
258 case StructTyID: {
259 auto *ST = cast<StructType>(this);
260 return !ST->isOpaque();
261 }
262 }
263}
264
265bool Type::isSizedDerivedType(SmallPtrSetImpl<Type*> *Visited) const {
266 if (auto *ATy = dyn_cast<ArrayType>(this))
267 return ATy->getElementType()->isSized(Visited);
268
269 if (auto *VTy = dyn_cast<VectorType>(this))
270 return VTy->getElementType()->isSized(Visited);
271
272 if (auto *TTy = dyn_cast<TargetExtType>(this))
273 return TTy->getLayoutType()->isSized(Visited);
274
275 return cast<StructType>(this)->isSized(Visited);
276}
277
278//===----------------------------------------------------------------------===//
279// Primitive 'Type' data
280//===----------------------------------------------------------------------===//
281
282Type *Type::getVoidTy(LLVMContext &C) { return &C.pImpl->VoidTy; }
283Type *Type::getLabelTy(LLVMContext &C) { return &C.pImpl->LabelTy; }
284Type *Type::getHalfTy(LLVMContext &C) { return &C.pImpl->HalfTy; }
285Type *Type::getBFloatTy(LLVMContext &C) { return &C.pImpl->BFloatTy; }
286Type *Type::getFloatTy(LLVMContext &C) { return &C.pImpl->FloatTy; }
287Type *Type::getDoubleTy(LLVMContext &C) { return &C.pImpl->DoubleTy; }
288Type *Type::getMetadataTy(LLVMContext &C) { return &C.pImpl->MetadataTy; }
289Type *Type::getTokenTy(LLVMContext &C) { return &C.pImpl->TokenTy; }
290Type *Type::getX86_FP80Ty(LLVMContext &C) { return &C.pImpl->X86_FP80Ty; }
291Type *Type::getFP128Ty(LLVMContext &C) { return &C.pImpl->FP128Ty; }
292Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; }
293Type *Type::getX86_AMXTy(LLVMContext &C) { return &C.pImpl->X86_AMXTy; }
294
295ByteType *Type::getByte1Ty(LLVMContext &C) { return &C.pImpl->Byte1Ty; }
296ByteType *Type::getByte8Ty(LLVMContext &C) { return &C.pImpl->Byte8Ty; }
297ByteType *Type::getByte16Ty(LLVMContext &C) { return &C.pImpl->Byte16Ty; }
298ByteType *Type::getByte32Ty(LLVMContext &C) { return &C.pImpl->Byte32Ty; }
299ByteType *Type::getByte64Ty(LLVMContext &C) { return &C.pImpl->Byte64Ty; }
300ByteType *Type::getByte128Ty(LLVMContext &C) { return &C.pImpl->Byte128Ty; }
301
303 return ByteType::get(C, N);
304}
305
306IntegerType *Type::getInt1Ty(LLVMContext &C) { return &C.pImpl->Int1Ty; }
307IntegerType *Type::getInt8Ty(LLVMContext &C) { return &C.pImpl->Int8Ty; }
308IntegerType *Type::getInt16Ty(LLVMContext &C) { return &C.pImpl->Int16Ty; }
309IntegerType *Type::getInt32Ty(LLVMContext &C) { return &C.pImpl->Int32Ty; }
310IntegerType *Type::getInt64Ty(LLVMContext &C) { return &C.pImpl->Int64Ty; }
311IntegerType *Type::getInt128Ty(LLVMContext &C) { return &C.pImpl->Int128Ty; }
312
314 return IntegerType::get(C, N);
315}
316
317Type *Type::getIntFromByteType(Type *Ty) {
318 assert(Ty->isByteOrByteVectorTy() && "Expected a byte or byte vector type.");
319 unsigned NumBits = Ty->getScalarSizeInBits();
320 IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
321 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
322 return VectorType::get(IntTy, VecTy);
323 return IntTy;
324}
325
326Type *Type::getByteFromIntType(Type *Ty) {
327 assert(!Ty->isPtrOrPtrVectorTy() &&
328 "Expected a non-pointer or non-pointer vector type.");
329 unsigned NumBits = Ty->getScalarSizeInBits();
330 ByteType *ByteTy = ByteType::get(Ty->getContext(), NumBits);
331 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
332 return VectorType::get(ByteTy, VecTy);
333 return ByteTy;
334}
335
337 // opaque pointer in addrspace(10)
338 return PointerType::get(C, 10);
339}
340
342 // opaque pointer in addrspace(20)
343 return PointerType::get(C, 20);
344}
345
346//===----------------------------------------------------------------------===//
347// IntegerType Implementation
348//===----------------------------------------------------------------------===//
349
350IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
351 assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
352 assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
353
354 // Check for the built-in integer types
355 switch (NumBits) {
356 case 1: return Type::getInt1Ty(C);
357 case 8: return Type::getInt8Ty(C);
358 case 16: return Type::getInt16Ty(C);
359 case 32: return Type::getInt32Ty(C);
360 case 64: return Type::getInt64Ty(C);
361 case 128: return Type::getInt128Ty(C);
362 default:
363 break;
364 }
365
366 IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits];
367
368 if (!Entry)
369 Entry = new (C.pImpl->Alloc) IntegerType(C, NumBits);
370
371 return Entry;
372}
373
375
376//===----------------------------------------------------------------------===//
377// ByteType Implementation
378//===----------------------------------------------------------------------===//
379
380ByteType *ByteType::get(LLVMContext &C, unsigned NumBits) {
381 assert(NumBits >= MIN_BYTE_BITS && "bitwidth too small");
382 assert(NumBits <= MAX_BYTE_BITS && "bitwidth too large");
383
384 // Check for the built-in byte types
385 switch (NumBits) {
386 case 8:
387 return Type::getByte8Ty(C);
388 case 16:
389 return Type::getByte16Ty(C);
390 case 32:
391 return Type::getByte32Ty(C);
392 case 64:
393 return Type::getByte64Ty(C);
394 case 128:
395 return Type::getByte128Ty(C);
396 default:
397 break;
398 }
399
400 ByteType *&Entry = C.pImpl->ByteTypes[NumBits];
401
402 if (!Entry)
403 Entry = new (C.pImpl->Alloc) ByteType(C, NumBits);
404
405 return Entry;
406}
407
409
410//===----------------------------------------------------------------------===//
411// FunctionType Implementation
412//===----------------------------------------------------------------------===//
413
415 bool IsVarArgs)
416 : Type(Result->getContext(), FunctionTyID) {
417 Type **SubTys = reinterpret_cast<Type**>(this+1);
418 assert(isValidReturnType(Result) && "invalid return type for function");
419 setSubclassData(IsVarArgs);
420
421 SubTys[0] = Result;
422
423 for (unsigned i = 0, e = Params.size(); i != e; ++i) {
424 assert(isValidArgumentType(Params[i]) &&
425 "Not a valid type for function argument!");
426 SubTys[i+1] = Params[i];
427 }
428
429 ContainedTys = SubTys;
430 NumContainedTys = Params.size() + 1; // + 1 for result type
431}
432
433// This is the factory function for the FunctionType class.
434FunctionType *FunctionType::get(Type *ReturnType,
435 ArrayRef<Type*> Params, bool isVarArg) {
436 LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
437 const FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg);
438 FunctionType *FT;
439 // Since we only want to allocate a fresh function type in case none is found
440 // and we don't want to perform two lookups (one for checking if existent and
441 // one for inserting the newly allocated one), here we instead lookup based on
442 // Key and update the reference to the function type in-place to a newly
443 // allocated one if not found.
444 auto Insertion = pImpl->FunctionTypes.insert_as(nullptr, Key);
445 if (Insertion.second) {
446 // The function type was not found. Allocate one and update FunctionTypes
447 // in-place.
448 FT = (FunctionType *)pImpl->Alloc.Allocate(
449 sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1),
450 alignof(FunctionType));
451 new (FT) FunctionType(ReturnType, Params, isVarArg);
452 *Insertion.first = FT;
453 } else {
454 // The function type was found. Just return it.
455 FT = *Insertion.first;
456 }
457 return FT;
458}
459
460FunctionType *FunctionType::get(Type *Result, bool isVarArg) {
461 return get(Result, {}, isVarArg);
462}
463
464bool FunctionType::isValidReturnType(Type *RetTy) {
465 return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
466 !RetTy->isMetadataTy();
467}
468
469bool FunctionType::isValidArgumentType(Type *ArgTy) {
470 return ArgTy->isFirstClassType() && !ArgTy->isLabelTy();
471}
472
473//===----------------------------------------------------------------------===//
474// StructType Implementation
475//===----------------------------------------------------------------------===//
476
477// Primitive Constructors.
478
480 bool isPacked) {
481 LLVMContextImpl *pImpl = Context.pImpl;
482 const AnonStructTypeKeyInfo::KeyTy Key(ETypes, isPacked);
483
484 StructType *ST;
485 // Since we only want to allocate a fresh struct type in case none is found
486 // and we don't want to perform two lookups (one for checking if existent and
487 // one for inserting the newly allocated one), here we instead lookup based on
488 // Key and update the reference to the struct type in-place to a newly
489 // allocated one if not found.
490 auto Insertion = pImpl->AnonStructTypes.insert_as(nullptr, Key);
491 if (Insertion.second) {
492 // The struct type was not found. Allocate one and update AnonStructTypes
493 // in-place.
494 ST = new (Context.pImpl->Alloc) StructType(Context);
495 ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
496 ST->setBody(ETypes, isPacked);
497 *Insertion.first = ST;
498 } else {
499 // The struct type was found. Just return it.
500 ST = *Insertion.first;
501 }
502
503 return ST;
504}
505
507 if ((getSubclassData() & SCDB_ContainsScalableVector) != 0)
508 return true;
509
510 if ((getSubclassData() & SCDB_NotContainsScalableVector) != 0)
511 return false;
512
513 if (!Visited.insert(this).second)
514 return false;
515
516 for (Type *Ty : elements()) {
517 if (Ty->isScalableTy(Visited)) {
518 const_cast<StructType *>(this)->setSubclassData(
519 getSubclassData() | SCDB_ContainsScalableVector);
520 return true;
521 }
522 }
523
524 // For structures that are opaque, return false but do not set the
525 // SCDB_NotContainsScalableVector flag since it may gain scalable vector type
526 // when it becomes non-opaque.
527 if (!isOpaque())
528 const_cast<StructType *>(this)->setSubclassData(
529 getSubclassData() | SCDB_NotContainsScalableVector);
530 return false;
531}
532
534 SmallPtrSetImpl<const Type *> &Visited) const {
535 if ((getSubclassData() & SCDB_ContainsNonGlobalTargetExtType) != 0)
536 return true;
537
538 if ((getSubclassData() & SCDB_NotContainsNonGlobalTargetExtType) != 0)
539 return false;
540
541 if (!Visited.insert(this).second)
542 return false;
543
544 for (Type *Ty : elements()) {
545 if (Ty->containsNonGlobalTargetExtType(Visited)) {
546 const_cast<StructType *>(this)->setSubclassData(
547 getSubclassData() | SCDB_ContainsNonGlobalTargetExtType);
548 return true;
549 }
550 }
551
552 // For structures that are opaque, return false but do not set the
553 // SCDB_NotContainsNonGlobalTargetExtType flag since it may gain non-global
554 // target extension types when it becomes non-opaque.
555 if (!isOpaque())
556 const_cast<StructType *>(this)->setSubclassData(
557 getSubclassData() | SCDB_NotContainsNonGlobalTargetExtType);
558 return false;
559}
560
562 SmallPtrSetImpl<const Type *> &Visited) const {
563 if ((getSubclassData() & SCDB_ContainsNonLocalTargetExtType) != 0)
564 return true;
565
566 if ((getSubclassData() & SCDB_NotContainsNonLocalTargetExtType) != 0)
567 return false;
568
569 if (!Visited.insert(this).second)
570 return false;
571
572 for (Type *Ty : elements()) {
573 if (Ty->containsNonLocalTargetExtType(Visited)) {
574 const_cast<StructType *>(this)->setSubclassData(
575 getSubclassData() | SCDB_ContainsNonLocalTargetExtType);
576 return true;
577 }
578 }
579
580 // For structures that are opaque, return false but do not set the
581 // SCDB_NotContainsNonLocalTargetExtType flag since it may gain non-local
582 // target extension types when it becomes non-opaque.
583 if (!isOpaque())
584 const_cast<StructType *>(this)->setSubclassData(
585 getSubclassData() | SCDB_NotContainsNonLocalTargetExtType);
586 return false;
587}
588
590 if (getNumElements() <= 0 || !isa<ScalableVectorType>(elements().front()))
591 return false;
592 return containsHomogeneousTypes();
593}
594
596 ArrayRef<Type *> ElementTys = elements();
597 return !ElementTys.empty() && all_equal(ElementTys);
598}
599
600void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
601 cantFail(setBodyOrError(Elements, isPacked));
602}
603
604Error StructType::setBodyOrError(ArrayRef<Type *> Elements, bool isPacked) {
605 assert(isOpaque() && "Struct body already set!");
606
607 if (auto E = checkBody(Elements))
608 return E;
609
610 setSubclassData(getSubclassData() | SCDB_HasBody);
611 if (isPacked)
612 setSubclassData(getSubclassData() | SCDB_Packed);
613
614 NumContainedTys = Elements.size();
615 ContainedTys = Elements.empty()
616 ? nullptr
617 : Elements.copy(getContext().pImpl->Alloc).data();
618
619 return Error::success();
620}
621
623 SmallSetVector<Type *, 4> Worklist(Elements.begin(), Elements.end());
624 for (unsigned I = 0; I < Worklist.size(); ++I) {
625 Type *Ty = Worklist[I];
626 if (Ty == this)
627 return createStringError(Twine("identified structure type '") +
628 getName() + "' is recursive");
629 Worklist.insert_range(Ty->subtypes());
630 }
631 return Error::success();
632}
633
635 if (Name == getName()) return;
636
637 StringMap<StructType *> &SymbolTable = getContext().pImpl->NamedStructTypes;
638
640
641 // If this struct already had a name, remove its symbol table entry. Don't
642 // delete the data yet because it may be part of the new name.
644 SymbolTable.remove((EntryTy *)SymbolTableEntry);
645
646 // If this is just removing the name, we're done.
647 if (Name.empty()) {
648 if (SymbolTableEntry) {
649 // Delete the old string data.
650 ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
651 SymbolTableEntry = nullptr;
652 }
653 return;
654 }
655
656 // Look up the entry for the name.
657 auto IterBool =
658 getContext().pImpl->NamedStructTypes.insert(std::make_pair(Name, this));
659
660 // While we have a name collision, try a random rename.
661 if (!IterBool.second) {
662 SmallString<64> TempStr(Name);
663 TempStr.push_back('.');
664 raw_svector_ostream TmpStream(TempStr);
665 unsigned NameSize = Name.size();
666
667 do {
668 TempStr.resize(NameSize + 1);
669 TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
670
671 IterBool = getContext().pImpl->NamedStructTypes.insert(
672 std::make_pair(TmpStream.str(), this));
673 } while (!IterBool.second);
674 }
675
676 // Delete the old string data.
678 ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
679 SymbolTableEntry = &*IterBool.first;
680}
681
682//===----------------------------------------------------------------------===//
683// StructType Helper functions.
684
686 StructType *ST = new (Context.pImpl->Alloc) StructType(Context);
687 if (!Name.empty())
688 ST->setName(Name);
689 return ST;
690}
691
692StructType *StructType::get(LLVMContext &Context, bool isPacked) {
693 return get(Context, {}, isPacked);
694}
695
697 StringRef Name, bool isPacked) {
698 StructType *ST = create(Context, Name);
699 ST->setBody(Elements, isPacked);
700 return ST;
701}
702
704 return create(Context, Elements, StringRef());
705}
706
708 return create(Context, StringRef());
709}
710
712 bool isPacked) {
713 assert(!Elements.empty() &&
714 "This method may not be invoked with an empty list");
715 return create(Elements[0]->getContext(), Elements, Name, isPacked);
716}
717
719 assert(!Elements.empty() &&
720 "This method may not be invoked with an empty list");
721 return create(Elements[0]->getContext(), Elements, StringRef());
722}
723
724bool StructType::isSized(SmallPtrSetImpl<Type*> *Visited) const {
725 if ((getSubclassData() & SCDB_IsSized) != 0)
726 return true;
727 if (isOpaque())
728 return false;
729
730 if (Visited && !Visited->insert(const_cast<StructType*>(this)).second)
731 return false;
732
733 // Okay, our struct is sized if all of the elements are, but if one of the
734 // elements is opaque, the struct isn't sized *yet*, but may become sized in
735 // the future, so just bail out without caching.
736 // The ONLY special case inside a struct that is considered sized is when the
737 // elements are homogeneous of a scalable vector type.
738 if (containsHomogeneousScalableVectorTypes()) {
739 const_cast<StructType *>(this)->setSubclassData(getSubclassData() |
740 SCDB_IsSized);
741 return true;
742 }
743 for (Type *Ty : elements()) {
744 // If the struct contains a scalable vector type, don't consider it sized.
745 // This prevents it from being used in loads/stores/allocas/GEPs. The ONLY
746 // special case right now is a structure of homogenous scalable vector
747 // types and is handled by the if-statement before this for-loop.
748 if (Ty->isScalableTy())
749 return false;
750 if (!Ty->isSized(Visited))
751 return false;
752 }
753
754 // Here we cheat a bit and cast away const-ness. The goal is to memoize when
755 // we find a sized type, as types can only move from opaque to sized, not the
756 // other way.
757 const_cast<StructType*>(this)->setSubclassData(
758 getSubclassData() | SCDB_IsSized);
759 return true;
760}
761
763 assert(!isLiteral() && "Literal structs never have names");
764 if (!SymbolTableEntry) return StringRef();
765
766 return ((StringMapEntry<StructType*> *)SymbolTableEntry)->getKey();
767}
768
769bool StructType::isValidElementType(Type *ElemTy) {
770 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
771 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
772 !ElemTy->isTokenTy();
773}
774
776 if (this == Other) return true;
777
778 if (isPacked() != Other->isPacked())
779 return false;
780
781 return elements() == Other->elements();
782}
783
784Type *StructType::getTypeAtIndex(const Value *V) const {
785 unsigned Idx = (unsigned)cast<Constant>(V)->getUniqueInteger().getZExtValue();
786 assert(indexValid(Idx) && "Invalid structure index!");
787 return getElementType(Idx);
788}
789
790bool StructType::indexValid(const Value *V) const {
791 // Structure indexes require (vectors of) 32-bit integer constants. In the
792 // vector case all of the indices must be equal.
793 if (!V->getType()->isIntOrIntVectorTy(32))
794 return false;
795 if (isa<ScalableVectorType>(V->getType()))
796 return false;
797 const Constant *C = dyn_cast<Constant>(V);
798 if (C && V->getType()->isVectorTy())
799 C = C->getSplatValue();
801 return CU && CU->getZExtValue() < getNumElements();
802}
803
805 return C.pImpl->NamedStructTypes.lookup(Name);
806}
807
808//===----------------------------------------------------------------------===//
809// ArrayType Implementation
810//===----------------------------------------------------------------------===//
811
812ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
813 : Type(ElType->getContext(), ArrayTyID), ContainedType(ElType),
814 NumElements(NumEl) {
815 ContainedTys = &ContainedType;
816 NumContainedTys = 1;
817}
818
819ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
820 assert(isValidElementType(ElementType) && "Invalid type for array element!");
821
822 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
823 ArrayType *&Entry =
824 pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)];
825
826 if (!Entry)
827 Entry = new (pImpl->Alloc) ArrayType(ElementType, NumElements);
828 return Entry;
829}
830
831bool ArrayType::isValidElementType(Type *ElemTy) {
832 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
833 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
834 !ElemTy->isTokenTy() && !ElemTy->isX86_AMXTy();
835}
836
837//===----------------------------------------------------------------------===//
838// VectorType Implementation
839//===----------------------------------------------------------------------===//
840
841VectorType::VectorType(Type *ElType, unsigned EQ, Type::TypeID TID)
842 : Type(ElType->getContext(), TID), ContainedType(ElType),
843 ElementQuantity(EQ) {
844 ContainedTys = &ContainedType;
845 NumContainedTys = 1;
846}
847
848VectorType *VectorType::get(Type *ElementType, ElementCount EC) {
849 if (EC.isScalable())
850 return ScalableVectorType::get(ElementType, EC.getKnownMinValue());
851 else
852 return FixedVectorType::get(ElementType, EC.getKnownMinValue());
853}
854
855bool VectorType::isValidElementType(Type *ElemTy) {
856 if (ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
857 ElemTy->isPointerTy() || ElemTy->getTypeID() == TypedPointerTyID ||
858 ElemTy->isByteTy())
859 return true;
860 if (auto *TTy = dyn_cast<TargetExtType>(ElemTy))
861 return TTy->hasProperty(TargetExtType::CanBeVectorElement);
862 return false;
863}
864
865//===----------------------------------------------------------------------===//
866// FixedVectorType Implementation
867//===----------------------------------------------------------------------===//
868
869FixedVectorType *FixedVectorType::get(Type *ElementType, unsigned NumElts) {
870 assert(NumElts > 0 && "#Elements of a VectorType must be greater than 0");
871 assert(isValidElementType(ElementType) && "Element type of a VectorType must "
872 "be an integer, floating point, "
873 "pointer type, or a valid target "
874 "extension type.");
875
876 auto EC = ElementCount::getFixed(NumElts);
877
878 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
879 VectorType *&Entry = ElementType->getContext()
880 .pImpl->VectorTypes[std::make_pair(ElementType, EC)];
881
882 if (!Entry)
883 Entry = new (pImpl->Alloc) FixedVectorType(ElementType, NumElts);
884 return cast<FixedVectorType>(Entry);
885}
886
887//===----------------------------------------------------------------------===//
888// ScalableVectorType Implementation
889//===----------------------------------------------------------------------===//
890
892 unsigned MinNumElts) {
893 assert(MinNumElts > 0 && "#Elements of a VectorType must be greater than 0");
894 assert(isValidElementType(ElementType) && "Element type of a VectorType must "
895 "be an integer, floating point, or "
896 "pointer type.");
897
898 auto EC = ElementCount::getScalable(MinNumElts);
899
900 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
901 VectorType *&Entry = ElementType->getContext()
902 .pImpl->VectorTypes[std::make_pair(ElementType, EC)];
903
904 if (!Entry)
905 Entry = new (pImpl->Alloc) ScalableVectorType(ElementType, MinNumElts);
906 return cast<ScalableVectorType>(Entry);
907}
908
909//===----------------------------------------------------------------------===//
910// PointerType Implementation
911//===----------------------------------------------------------------------===//
912
913PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) {
914 assert(EltTy && "Can't get a pointer to <null> type!");
915 assert(isValidElementType(EltTy) && "Invalid type for pointer element!");
916
917 // Automatically convert typed pointers to opaque pointers.
918 return get(EltTy->getContext(), AddressSpace);
919}
920
922 LLVMContextImpl *CImpl = C.pImpl;
923
924 // Since AddressSpace #0 is the common case, we special case it.
926 : CImpl->PointerTypes[AddressSpace];
927
928 if (!Entry)
929 Entry = new (CImpl->Alloc) PointerType(C, AddressSpace);
930 return Entry;
931}
932
933PointerType::PointerType(LLVMContext &C, unsigned AddrSpace)
934 : Type(C, PointerTyID) {
935 setSubclassData(AddrSpace);
936}
937
938PointerType *Type::getPointerTo(unsigned AddrSpace) const {
939 return PointerType::get(getContext(), AddrSpace);
940}
941
942bool PointerType::isValidElementType(Type *ElemTy) {
943 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
944 !ElemTy->isMetadataTy() && !ElemTy->isTokenTy() &&
945 !ElemTy->isX86_AMXTy();
946}
947
948bool PointerType::isLoadableOrStorableType(Type *ElemTy) {
949 return isValidElementType(ElemTy) && !ElemTy->isFunctionTy();
950}
951
952//===----------------------------------------------------------------------===//
953// TargetExtType Implementation
954//===----------------------------------------------------------------------===//
955
956TargetExtType::TargetExtType(LLVMContext &C, StringRef Name,
958 : Type(C, TargetExtTyID), Name(C.pImpl->Saver.save(Name)) {
959 NumContainedTys = Types.size();
960
961 // Parameter storage immediately follows the class in allocation.
962 Type **Params = reinterpret_cast<Type **>(this + 1);
963 ContainedTys = Params;
964 for (Type *T : Types)
965 *Params++ = T;
966
967 setSubclassData(Ints.size());
968 unsigned *IntParamSpace = reinterpret_cast<unsigned *>(Params);
969 IntParams = IntParamSpace;
970 for (unsigned IntParam : Ints)
971 *IntParamSpace++ = IntParam;
972}
973
975 ArrayRef<Type *> Types,
976 ArrayRef<unsigned> Ints) {
977 return cantFail(getOrError(C, Name, Types, Ints));
978}
979
980Expected<TargetExtType *> TargetExtType::getOrError(LLVMContext &C,
981 StringRef Name,
982 ArrayRef<Type *> Types,
983 ArrayRef<unsigned> Ints) {
984 const TargetExtTypeKeyInfo::KeyTy Key(Name, Types, Ints);
986 // Since we only want to allocate a fresh target type in case none is found
987 // and we don't want to perform two lookups (one for checking if existent and
988 // one for inserting the newly allocated one), here we instead lookup based on
989 // Key and update the reference to the target type in-place to a newly
990 // allocated one if not found.
991 auto [Iter, Inserted] = C.pImpl->TargetExtTypes.insert_as(nullptr, Key);
992 if (Inserted) {
993 // The target type was not found. Allocate one and update TargetExtTypes
994 // in-place.
995 TT = (TargetExtType *)C.pImpl->Alloc.Allocate(
996 sizeof(TargetExtType) + sizeof(Type *) * Types.size() +
997 sizeof(unsigned) * Ints.size(),
998 alignof(TargetExtType));
999 new (TT) TargetExtType(C, Name, Types, Ints);
1000 *Iter = TT;
1001 return checkParams(TT);
1002 }
1003
1004 // The target type was found. Just return it.
1005 return *Iter;
1006}
1007
1008Expected<TargetExtType *> TargetExtType::checkParams(TargetExtType *TTy) {
1009 // Opaque types in the AArch64 name space.
1010 if (TTy->Name == "aarch64.svcount" &&
1011 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() != 0))
1012 return createStringError(
1013 "target extension type aarch64.svcount should have no parameters");
1014
1015 // Opaque types in the RISC-V name space.
1016 if (TTy->Name == "riscv.vector.tuple" &&
1017 (TTy->getNumTypeParameters() != 1 || TTy->getNumIntParameters() != 1))
1018 return createStringError(
1019 "target extension type riscv.vector.tuple should have one "
1020 "type parameter and one integer parameter");
1021
1022 // Opaque types in the AMDGPU name space.
1023 if (TTy->Name == "amdgcn.named.barrier" &&
1024 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() != 1)) {
1025 return createStringError("target extension type amdgcn.named.barrier "
1026 "should have no type parameters "
1027 "and one integer parameter");
1028 }
1029 if (TTy->Name == "amdgpu.stridemark" &&
1030 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() > 1)) {
1031 return createStringError("target extension type amdgpu.stridemark "
1032 "should have no type parameters "
1033 "and at most one integer parameter");
1034 }
1035
1036 return TTy;
1037}
1038
1039namespace {
1040struct TargetTypeInfo {
1041 Type *LayoutType;
1042 uint64_t Properties;
1043
1044 template <typename... ArgTys>
1045 TargetTypeInfo(Type *LayoutType, ArgTys... Properties)
1046 : LayoutType(LayoutType), Properties((0 | ... | Properties)) {
1047 assert((!(this->Properties & TargetExtType::CanBeVectorElement) ||
1048 LayoutType->isSized()) &&
1049 "Vector element type must be sized");
1050 }
1051};
1052} // anonymous namespace
1053
1054static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
1055 LLVMContext &C = Ty->getContext();
1056 StringRef Name = Ty->getName();
1057 if (Name == "spirv.Image" || Name == "spirv.SignedImage")
1058 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal,
1060 if (Name == "spirv.Type") {
1061 assert(Ty->getNumIntParameters() == 3 &&
1062 "Wrong number of parameters for spirv.Type");
1063
1064 auto Size = Ty->getIntParameter(1);
1065 auto Alignment = Ty->getIntParameter(2);
1066
1067 llvm::Type *LayoutType = nullptr;
1068 if (Size > 0 && Alignment > 0) {
1069 LayoutType =
1070 ArrayType::get(Type::getIntNTy(C, Alignment), Size * 8 / Alignment);
1071 } else {
1072 // LLVM expects variables that can be allocated to have an alignment and
1073 // size. Default to using a 32-bit int as the layout type if none are
1074 // present.
1075 LayoutType = Type::getInt32Ty(C);
1076 }
1077
1078 return TargetTypeInfo(LayoutType, TargetExtType::CanBeGlobal,
1080 }
1081 if (Name == "spirv.IntegralConstant" || Name == "spirv.Literal")
1082 return TargetTypeInfo(Type::getVoidTy(C));
1083 if (Name == "spirv.Padding")
1084 return TargetTypeInfo(
1085 ArrayType::get(Type::getInt8Ty(C), Ty->getIntParameter(0)),
1087 if (Name.starts_with("spirv."))
1088 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::HasZeroInit,
1091
1092 // Opaque types in the AArch64 name space.
1093 if (Name == "aarch64.svcount")
1094 return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
1097
1098 // RISC-V vector tuple type. The layout is represented as the type that needs
1099 // the same number of vector registers(VREGS) as this tuple type, represented
1100 // as <vscale x (RVVBitsPerBlock * VREGS / 8) x i8>.
1101 if (Name == "riscv.vector.tuple") {
1102 unsigned TotalNumElts =
1103 std::max(cast<ScalableVectorType>(Ty->getTypeParameter(0))
1104 ->getMinNumElements(),
1106 Ty->getIntParameter(0);
1107 return TargetTypeInfo(
1110 }
1111
1112 // DirectX resources
1113 if (Name == "dx.Padding")
1114 return TargetTypeInfo(
1115 ArrayType::get(Type::getInt8Ty(C), Ty->getIntParameter(0)),
1117 if (Name.starts_with("dx."))
1118 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal,
1121
1122 // Opaque types in the AMDGPU name space.
1123 if (Name == "amdgcn.named.barrier") {
1124 return TargetTypeInfo(FixedVectorType::get(Type::getInt32Ty(C), 4),
1126 }
1127 if (Name == "amdgpu.stridemark")
1128 return TargetTypeInfo(Type::getVoidTy(C), TargetExtType::IsTokenLike);
1129
1130 // Type used to test vector element target extension property.
1131 // Can be removed once a public target extension type uses CanBeVectorElement.
1132 if (Name == "llvm.test.vectorelement") {
1133 return TargetTypeInfo(Type::getInt32Ty(C), TargetExtType::CanBeLocal,
1135 }
1136
1137 return TargetTypeInfo(Type::getVoidTy(C));
1138}
1139
1140bool Type::isTokenLikeTy() const {
1141 if (isTokenTy())
1142 return true;
1143 if (auto *TT = dyn_cast<TargetExtType>(this))
1144 return TT->hasProperty(TargetExtType::Property::IsTokenLike);
1145 return false;
1146}
1147
1148Type *TargetExtType::getLayoutType() const {
1149 return getTargetTypeInfo(this).LayoutType;
1150}
1151
1152bool TargetExtType::hasProperty(Property Prop) const {
1153 uint64_t Properties = getTargetTypeInfo(this).Properties;
1154 return (Properties & Prop) == Prop;
1155}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static char getTypeID(Type *Ty)
@ FunctionTyID
Functions.
@ ArrayTyID
Arrays.
@ PointerTyID
Pointers.
@ TargetExtTyID
Target extension type.
#define I(x, y, z)
Definition MD5.cpp:57
Type::TypeID TypeID
#define T
const uint64_t BitWidth
static StringRef getName(Value *V)
static unsigned getNumElements(Type *Ty)
static bool isValidElementType(Type *Ty)
Predicate for the element types that the SLP vectorizer supports.
static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty)
Definition Type.cpp:1054
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallString class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
ArrayType(const Node *Base_, Node *Dimension_)
FunctionType(const Node *Ret_, NodeArray Params_, Qualifiers CVQuals_, FunctionRefQual RefQual_, const Node *ExceptionSpec_)
PointerType(const Node *Pointee_)
VectorType(const Node *BaseType_, const Node *Dimension_)
Class for arbitrary precision integers.
Definition APInt.h:78
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:235
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:831
Class to represent byte types.
static LLVM_ABI ByteType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing a ByteType.
Definition Type.cpp:380
LLVM_ABI APInt getMask() const
For example, this is 0xFF for an 8 bit byte, 0xFFFF for b16, etc.
Definition Type.cpp:408
This is the shared class of boolean and integer constants.
Definition Constants.h:87
static constexpr ElementCount getScalable(ScalarTy MinVal)
Definition TypeSize.h:312
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:309
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:869
static LLVM_ABI bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
Definition Type.cpp:469
static LLVM_ABI bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
Definition Type.cpp:464
bool isVarArg() const
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:350
LLVM_ABI APInt getMask() const
For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
Definition Type.cpp:374
StructTypeSet AnonStructTypes
DenseMap< std::pair< Type *, uint64_t >, ArrayType * > ArrayTypes
DenseMap< unsigned, PointerType * > PointerTypes
FunctionTypeSet FunctionTypes
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
static LLVM_ABI bool isLoadableOrStorableType(Type *ElemTy)
Return true if we can load or store from a pointer to this type.
Definition Type.cpp:948
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:942
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Class to represent scalable SIMD vectors.
static LLVM_ABI ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
Definition Type.cpp:891
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:339
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
void remove(MapEntryTy *KeyValue)
remove - Remove the specified key/value pair from the map, but do not erase it.
Definition StringMap.h:425
AllocatorTy & getAllocator()
StringMapEntry< ValueTy > MapEntryTy
Definition StringMap.h:137
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent struct types.
LLVM_ABI bool indexValid(const Value *V) const
Definition Type.cpp:790
static LLVM_ABI 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:479
LLVM_ABI bool containsNonLocalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a local.
Definition Type.cpp:561
LLVM_ABI void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type, which must not make the type recursive.
Definition Type.cpp:600
LLVM_ABI bool containsHomogeneousScalableVectorTypes() const
Returns true if this struct contains homogeneous scalable vector types.
Definition Type.cpp:589
LLVM_ABI Error checkBody(ArrayRef< Type * > Elements)
Return an error if the body for an opaque identified type would make it recursive.
Definition Type.cpp:622
LLVM_ABI bool containsHomogeneousTypes() const
Return true if this struct is non-empty and all element types are the same.
Definition Type.cpp:595
LLVM_ABI bool containsNonGlobalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a global...
Definition Type.cpp:533
static LLVM_ABI StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
Definition Type.cpp:804
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition Type.cpp:685
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:769
LLVM_ABI bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
isSized - Return true if this is a sized type.
Definition Type.cpp:724
LLVM_ABI 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:634
LLVM_ABI bool isLayoutIdentical(StructType *Other) const
Return true if this is layout identical to the specified struct.
Definition Type.cpp:775
LLVM_ABI Error setBodyOrError(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type or return an error if it would make the type recursive.
Definition Type.cpp:604
LLVM_ABI Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Definition Type.cpp:784
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Returns true if this struct contains a scalable vector.
Definition Type.cpp:506
LLVM_ABI StringRef getName() const
Return the name for this struct type if it has an identity.
Definition Type.cpp:762
Symbol info for RuntimeDyld.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
unsigned getNumIntParameters() const
static LLVM_ABI TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters.
Definition Type.cpp:974
unsigned getNumTypeParameters() const
static LLVM_ABI Expected< TargetExtType * > checkParams(TargetExtType *TTy)
Check that a newly created target extension type has the expected number of type parameters and integ...
Definition Type.cpp:1008
LLVM_ABI bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
Definition Type.cpp:1152
@ IsTokenLike
In particular, it cannot be used in select and phi instructions.
@ HasZeroInit
zeroinitializer is valid for this target extension type.
@ CanBeVectorElement
This type may be used as an element in a vector.
@ CanBeGlobal
This type may be used as the value type of a global variable.
@ CanBeLocal
This type may be allocated on the stack, either as the allocated type of an alloca instruction or as ...
static LLVM_ABI Expected< TargetExtType * > getOrError(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters,...
Definition Type.cpp:980
LLVM_ABI Type * getLayoutType() const
Returns an underlying layout type for the target extension type.
Definition Type.cpp:1148
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI ByteType * getByte16Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:310
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
Definition Type.cpp:293
LLVM_ABI 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:180
bool isByteTy() const
True if this is an instance of ByteType.
Definition Type.h:242
static LLVM_ABI Type * getWasm_ExternrefTy(LLVMContext &C)
Definition Type.cpp:336
LLVM_ABI bool containsNonGlobalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a global...
Definition Type.cpp:74
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:288
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
Definition Type.cpp:289
LLVM_ABI bool containsNonLocalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a local.
Definition Type.cpp:90
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
Definition Type.cpp:61
static LLVM_ABI IntegerType * getInt128Ty(LLVMContext &C)
Definition Type.cpp:311
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:309
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
Definition Type.cpp:292
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
Definition Type.cpp:291
static LLVM_ABI Type * getLabelTy(LLVMContext &C)
Definition Type.cpp:283
LLVM_ABI bool isTokenLikeTy() const
Returns true if this is 'token' or a token-like target type.s.
Definition Type.cpp:1140
static LLVM_ABI Type * getByteFromIntType(Type *)
Returns a byte (vector of byte) type with the same size of an integer of the given integer (vector of...
Definition Type.cpp:326
TypeID
Definitions of all of the base types for the Type system.
Definition Type.h:55
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition Type.h:67
@ FunctionTyID
Functions.
Definition Type.h:73
@ TypedPointerTyID
Typed pointer used by some GPU targets.
Definition Type.h:79
@ HalfTyID
16-bit floating point type
Definition Type.h:57
@ VoidTyID
type with no size
Definition Type.h:64
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition Type.h:78
@ LabelTyID
Labels.
Definition Type.h:65
@ FloatTyID
32-bit floating point type
Definition Type.h:59
@ StructTyID
Structures.
Definition Type.h:75
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition Type.h:58
@ DoubleTyID
64-bit floating point type
Definition Type.h:60
@ X86_FP80TyID
80-bit floating point type (X87)
Definition Type.h:61
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition Type.h:63
@ MetadataTyID
Metadata.
Definition Type.h:66
@ TokenTyID
Tokens.
Definition Type.h:68
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition Type.h:62
static LLVM_ABI ByteType * getByte32Ty(LLVMContext &C)
Definition Type.cpp:298
LLVM_ABI bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
Definition Type.cpp:153
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:282
LLVM_ABI bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
Definition Type.cpp:251
static LLVM_ABI Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
Definition Type.cpp:125
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:307
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:368
Type(LLVMContext &C, TypeID tid)
Definition Type.h:95
LLVM_ABI bool isRISCVVectorTupleTy() const
Definition Type.cpp:146
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:197
bool isTargetExtTy() const
Return true if this is a target extension type.
Definition Type.h:205
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:308
static LLVM_ABI Type * getPrimitiveType(LLVMContext &C, TypeID IDNumber)
Return a type based on an identifier.
Definition Type.cpp:38
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
static LLVM_ABI Type * getIntFromByteType(Type *)
Returns an integer (vector of integer) type with the same size of a byte of the given byte (vector of...
Definition Type.cpp:317
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:232
static LLVM_ABI ByteType * getByte8Ty(LLVMContext &C)
Definition Type.cpp:296
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:306
friend class LLVMContextImpl
Definition Type.h:93
static LLVM_ABI ByteType * getByte128Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI ByteType * getByte1Ty(LLVMContext &C)
Definition Type.cpp:295
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:186
bool isX86_AMXTy() const
Return true if this is X86 AMX.
Definition Type.h:202
bool isTokenTy() const
Return true if this is 'token'.
Definition Type.h:236
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:313
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:287
static LLVM_ABI Type * getX86_FP80Ty(LLVMContext &C)
Definition Type.cpp:290
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:286
LLVM_ABI int getFPMantissaWidth() const
Return the width of the mantissa of this type.
Definition Type.cpp:237
static LLVM_ABI ByteType * getByteNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:302
LLVM_ABI const fltSemantics & getFltSemantics() const
Definition Type.cpp:106
static LLVM_ABI Type * getWasm_FuncrefTy(LLVMContext &C)
Definition Type.cpp:341
static LLVM_ABI ByteType * getByte64Ty(LLVMContext &C)
Definition Type.cpp:299
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:285
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:284
LLVM_ABI bool isScalableTargetExtTy() const
Return true if this is a target extension type with a scalable layout.
Definition Type.cpp:119
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
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:223
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:168
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Key
PAL metadata keys.
@ Entry
Definition COFF.h:862
static constexpr unsigned RVVBytesPerBlock
constexpr size_t NameSize
Definition XCOFF.h:30
ElementType
The element type of an SRV or UAV resource.
Definition DXILABI.h:68
Context & getContext() const
Definition BasicBlock.h:99
LLVM_ABI Instruction & front() const
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Other
Any other memory.
Definition ModRef.h:68
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition STLExtras.h:2165
#define N
#define EQ(a, b)
Definition regexec.c:65