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