LLVM 24.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
128 return llvm::Type::getHalfTy(C);
141 default:
142 llvm_unreachable("unhandled float format");
143 }
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 return TargetExtType::get(C, "wasm.externref", {}, {});
338}
339
341 return TargetExtType::get(C, "wasm.funcref", {}, {});
342}
343
344//===----------------------------------------------------------------------===//
345// IntegerType Implementation
346//===----------------------------------------------------------------------===//
347
348IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
349 assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
350 assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
351
352 // Check for the built-in integer types
353 switch (NumBits) {
354 case 1: return Type::getInt1Ty(C);
355 case 8: return Type::getInt8Ty(C);
356 case 16: return Type::getInt16Ty(C);
357 case 32: return Type::getInt32Ty(C);
358 case 64: return Type::getInt64Ty(C);
359 case 128: return Type::getInt128Ty(C);
360 default:
361 break;
362 }
363
364 IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits];
365
366 if (!Entry)
367 Entry = new (C.pImpl->Alloc) IntegerType(C, NumBits);
368
369 return Entry;
370}
371
373
374//===----------------------------------------------------------------------===//
375// ByteType Implementation
376//===----------------------------------------------------------------------===//
377
378ByteType *ByteType::get(LLVMContext &C, unsigned NumBits) {
379 assert(NumBits >= MIN_BYTE_BITS && "bitwidth too small");
380 assert(NumBits <= MAX_BYTE_BITS && "bitwidth too large");
381
382 // Check for the built-in byte types
383 switch (NumBits) {
384 case 8:
385 return Type::getByte8Ty(C);
386 case 16:
387 return Type::getByte16Ty(C);
388 case 32:
389 return Type::getByte32Ty(C);
390 case 64:
391 return Type::getByte64Ty(C);
392 case 128:
393 return Type::getByte128Ty(C);
394 default:
395 break;
396 }
397
398 ByteType *&Entry = C.pImpl->ByteTypes[NumBits];
399
400 if (!Entry)
401 Entry = new (C.pImpl->Alloc) ByteType(C, NumBits);
402
403 return Entry;
404}
405
407
408//===----------------------------------------------------------------------===//
409// FunctionType Implementation
410//===----------------------------------------------------------------------===//
411
413 bool IsVarArgs)
414 : Type(Result->getContext(), FunctionTyID) {
415 Type **SubTys = reinterpret_cast<Type**>(this+1);
416 assert(isValidReturnType(Result) && "invalid return type for function");
417 setSubclassData(IsVarArgs);
418
419 SubTys[0] = Result;
420
421 for (unsigned i = 0, e = Params.size(); i != e; ++i) {
422 assert(isValidArgumentType(Params[i]) &&
423 "Not a valid type for function argument!");
424 SubTys[i+1] = Params[i];
425 }
426
427 ContainedTys = SubTys;
428 NumContainedTys = Params.size() + 1; // + 1 for result type
429}
430
431// This is the factory function for the FunctionType class.
432FunctionType *FunctionType::get(Type *ReturnType,
433 ArrayRef<Type*> Params, bool isVarArg) {
434 LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
435 const FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg);
436 FunctionType *FT;
437 // Since we only want to allocate a fresh function type in case none is found
438 // and we don't want to perform two lookups (one for checking if existent and
439 // one for inserting the newly allocated one), here we instead lookup based on
440 // Key and update the reference to the function type in-place to a newly
441 // allocated one if not found.
442 auto Insertion = pImpl->FunctionTypes.insert_as(nullptr, Key);
443 if (Insertion.second) {
444 // The function type was not found. Allocate one and update FunctionTypes
445 // in-place.
446 FT = (FunctionType *)pImpl->Alloc.Allocate(
447 sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1),
448 alignof(FunctionType));
449 new (FT) FunctionType(ReturnType, Params, isVarArg);
450 *Insertion.first = FT;
451 } else {
452 // The function type was found. Just return it.
453 FT = *Insertion.first;
454 }
455 return FT;
456}
457
458FunctionType *FunctionType::get(Type *Result, bool isVarArg) {
459 return get(Result, {}, isVarArg);
460}
461
462bool FunctionType::isValidReturnType(Type *RetTy) {
463 return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
464 !RetTy->isMetadataTy();
465}
466
467bool FunctionType::isValidArgumentType(Type *ArgTy) {
468 return ArgTy->isFirstClassType() && !ArgTy->isLabelTy();
469}
470
471//===----------------------------------------------------------------------===//
472// StructType Implementation
473//===----------------------------------------------------------------------===//
474
475// Primitive Constructors.
476
478 bool isPacked) {
479 LLVMContextImpl *pImpl = Context.pImpl;
480 const AnonStructTypeKeyInfo::KeyTy Key(ETypes, isPacked);
481
482 StructType *ST;
483 // Since we only want to allocate a fresh struct type in case none is found
484 // and we don't want to perform two lookups (one for checking if existent and
485 // one for inserting the newly allocated one), here we instead lookup based on
486 // Key and update the reference to the struct type in-place to a newly
487 // allocated one if not found.
488 auto Insertion = pImpl->AnonStructTypes.insert_as(nullptr, Key);
489 if (Insertion.second) {
490 // The struct type was not found. Allocate one and update AnonStructTypes
491 // in-place.
492 ST = new (Context.pImpl->Alloc) StructType(Context);
493 ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
494 ST->setBody(ETypes, isPacked);
495 *Insertion.first = ST;
496 } else {
497 // The struct type was found. Just return it.
498 ST = *Insertion.first;
499 }
500
501 return ST;
502}
503
505 if ((getSubclassData() & SCDB_ContainsScalableVector) != 0)
506 return true;
507
508 if ((getSubclassData() & SCDB_NotContainsScalableVector) != 0)
509 return false;
510
511 if (!Visited.insert(this).second)
512 return false;
513
514 for (Type *Ty : elements()) {
515 if (Ty->isScalableTy(Visited)) {
516 const_cast<StructType *>(this)->setSubclassData(
517 getSubclassData() | SCDB_ContainsScalableVector);
518 return true;
519 }
520 }
521
522 // For structures that are opaque, return false but do not set the
523 // SCDB_NotContainsScalableVector flag since it may gain scalable vector type
524 // when it becomes non-opaque.
525 if (!isOpaque())
526 const_cast<StructType *>(this)->setSubclassData(
527 getSubclassData() | SCDB_NotContainsScalableVector);
528 return false;
529}
530
532 SmallPtrSetImpl<const Type *> &Visited) const {
533 if ((getSubclassData() & SCDB_ContainsNonGlobalTargetExtType) != 0)
534 return true;
535
536 if ((getSubclassData() & SCDB_NotContainsNonGlobalTargetExtType) != 0)
537 return false;
538
539 if (!Visited.insert(this).second)
540 return false;
541
542 for (Type *Ty : elements()) {
543 if (Ty->containsNonGlobalTargetExtType(Visited)) {
544 const_cast<StructType *>(this)->setSubclassData(
545 getSubclassData() | SCDB_ContainsNonGlobalTargetExtType);
546 return true;
547 }
548 }
549
550 // For structures that are opaque, return false but do not set the
551 // SCDB_NotContainsNonGlobalTargetExtType flag since it may gain non-global
552 // target extension types when it becomes non-opaque.
553 if (!isOpaque())
554 const_cast<StructType *>(this)->setSubclassData(
555 getSubclassData() | SCDB_NotContainsNonGlobalTargetExtType);
556 return false;
557}
558
560 SmallPtrSetImpl<const Type *> &Visited) const {
561 if ((getSubclassData() & SCDB_ContainsNonLocalTargetExtType) != 0)
562 return true;
563
564 if ((getSubclassData() & SCDB_NotContainsNonLocalTargetExtType) != 0)
565 return false;
566
567 if (!Visited.insert(this).second)
568 return false;
569
570 for (Type *Ty : elements()) {
571 if (Ty->containsNonLocalTargetExtType(Visited)) {
572 const_cast<StructType *>(this)->setSubclassData(
573 getSubclassData() | SCDB_ContainsNonLocalTargetExtType);
574 return true;
575 }
576 }
577
578 // For structures that are opaque, return false but do not set the
579 // SCDB_NotContainsNonLocalTargetExtType flag since it may gain non-local
580 // target extension types when it becomes non-opaque.
581 if (!isOpaque())
582 const_cast<StructType *>(this)->setSubclassData(
583 getSubclassData() | SCDB_NotContainsNonLocalTargetExtType);
584 return false;
585}
586
588 if (getNumElements() <= 0 || !isa<ScalableVectorType>(elements().front()))
589 return false;
590 return containsHomogeneousTypes();
591}
592
594 ArrayRef<Type *> ElementTys = elements();
595 return !ElementTys.empty() && all_equal(ElementTys);
596}
597
598void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
599 cantFail(setBodyOrError(Elements, isPacked));
600}
601
602Error StructType::setBodyOrError(ArrayRef<Type *> Elements, bool isPacked) {
603 assert(isOpaque() && "Struct body already set!");
604
605 if (auto E = checkBody(Elements))
606 return E;
607
608 setSubclassData(getSubclassData() | SCDB_HasBody);
609 if (isPacked)
610 setSubclassData(getSubclassData() | SCDB_Packed);
611
612 NumContainedTys = Elements.size();
613 ContainedTys = Elements.empty()
614 ? nullptr
615 : Elements.copy(getContext().pImpl->Alloc).data();
616
617 return Error::success();
618}
619
621 SmallSetVector<Type *, 4> Worklist(Elements.begin(), Elements.end());
622 for (unsigned I = 0; I < Worklist.size(); ++I) {
623 Type *Ty = Worklist[I];
624 if (Ty == this)
625 return createStringError(Twine("identified structure type '") +
626 getName() + "' is recursive");
627 Worklist.insert_range(Ty->subtypes());
628 }
629 return Error::success();
630}
631
633 if (Name == getName()) return;
634
635 StringMap<StructType *> &SymbolTable = getContext().pImpl->NamedStructTypes;
636
638
639 // If this struct already had a name, remove its symbol table entry. Don't
640 // delete the data yet because it may be part of the new name.
642 SymbolTable.remove((EntryTy *)SymbolTableEntry);
643
644 // If this is just removing the name, we're done.
645 if (Name.empty()) {
646 if (SymbolTableEntry) {
647 // Delete the old string data.
648 ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
649 SymbolTableEntry = nullptr;
650 }
651 return;
652 }
653
654 // Look up the entry for the name.
655 auto IterBool =
656 getContext().pImpl->NamedStructTypes.insert(std::make_pair(Name, this));
657
658 // While we have a name collision, try a random rename.
659 if (!IterBool.second) {
660 SmallString<64> TempStr(Name);
661 TempStr.push_back('.');
662 raw_svector_ostream TmpStream(TempStr);
663 unsigned NameSize = Name.size();
664
665 do {
666 TempStr.resize(NameSize + 1);
667 TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
668
669 IterBool = getContext().pImpl->NamedStructTypes.insert(
670 std::make_pair(TmpStream.str(), this));
671 } while (!IterBool.second);
672 }
673
674 // Delete the old string data.
676 ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
677 SymbolTableEntry = &*IterBool.first;
678}
679
680//===----------------------------------------------------------------------===//
681// StructType Helper functions.
682
684 StructType *ST = new (Context.pImpl->Alloc) StructType(Context);
685 if (!Name.empty())
686 ST->setName(Name);
687 return ST;
688}
689
690StructType *StructType::get(LLVMContext &Context, bool isPacked) {
691 return get(Context, {}, isPacked);
692}
693
695 StringRef Name, bool isPacked) {
696 StructType *ST = create(Context, Name);
697 ST->setBody(Elements, isPacked);
698 return ST;
699}
700
702 return create(Context, Elements, StringRef());
703}
704
706 return create(Context, StringRef());
707}
708
710 bool isPacked) {
711 assert(!Elements.empty() &&
712 "This method may not be invoked with an empty list");
713 return create(Elements[0]->getContext(), Elements, Name, isPacked);
714}
715
717 assert(!Elements.empty() &&
718 "This method may not be invoked with an empty list");
719 return create(Elements[0]->getContext(), Elements, StringRef());
720}
721
722bool StructType::isSized(SmallPtrSetImpl<Type*> *Visited) const {
723 if ((getSubclassData() & SCDB_IsSized) != 0)
724 return true;
725 if (isOpaque())
726 return false;
727
728 if (Visited && !Visited->insert(const_cast<StructType*>(this)).second)
729 return false;
730
731 // Okay, our struct is sized if all of the elements are, but if one of the
732 // elements is opaque, the struct isn't sized *yet*, but may become sized in
733 // the future, so just bail out without caching.
734 // The ONLY special case inside a struct that is considered sized is when the
735 // elements are homogeneous of a scalable vector type.
736 if (containsHomogeneousScalableVectorTypes()) {
737 const_cast<StructType *>(this)->setSubclassData(getSubclassData() |
738 SCDB_IsSized);
739 return true;
740 }
741 for (Type *Ty : elements()) {
742 // If the struct contains a scalable vector type, don't consider it sized.
743 // This prevents it from being used in loads/stores/allocas/GEPs. The ONLY
744 // special case right now is a structure of homogenous scalable vector
745 // types and is handled by the if-statement before this for-loop.
746 if (Ty->isScalableTy())
747 return false;
748 if (!Ty->isSized(Visited))
749 return false;
750 }
751
752 // Here we cheat a bit and cast away const-ness. The goal is to memoize when
753 // we find a sized type, as types can only move from opaque to sized, not the
754 // other way.
755 const_cast<StructType*>(this)->setSubclassData(
756 getSubclassData() | SCDB_IsSized);
757 return true;
758}
759
761 assert(!isLiteral() && "Literal structs never have names");
762 if (!SymbolTableEntry) return StringRef();
763
764 return ((StringMapEntry<StructType*> *)SymbolTableEntry)->getKey();
765}
766
767bool StructType::isValidElementType(Type *ElemTy) {
768 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
769 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
770 !ElemTy->isTokenTy();
771}
772
774 if (this == Other) return true;
775
776 if (isPacked() != Other->isPacked())
777 return false;
778
779 return elements() == Other->elements();
780}
781
782Type *StructType::getTypeAtIndex(const Value *V) const {
783 unsigned Idx = (unsigned)cast<Constant>(V)->getUniqueInteger().getZExtValue();
784 assert(indexValid(Idx) && "Invalid structure index!");
785 return getElementType(Idx);
786}
787
788bool StructType::indexValid(const Value *V) const {
789 // Structure indexes require (vectors of) 32-bit integer constants. In the
790 // vector case all of the indices must be equal.
791 if (!V->getType()->isIntOrIntVectorTy(32))
792 return false;
793 if (isa<ScalableVectorType>(V->getType()))
794 return false;
795 const Constant *C = dyn_cast<Constant>(V);
796 if (C && V->getType()->isVectorTy())
797 C = C->getSplatValue();
799 return CU && CU->getZExtValue() < getNumElements();
800}
801
803 return C.pImpl->NamedStructTypes.lookup(Name);
804}
805
806//===----------------------------------------------------------------------===//
807// ArrayType Implementation
808//===----------------------------------------------------------------------===//
809
810ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
811 : Type(ElType->getContext(), ArrayTyID), ContainedType(ElType),
812 NumElements(NumEl) {
813 ContainedTys = &ContainedType;
814 NumContainedTys = 1;
815}
816
817ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
818 assert(isValidElementType(ElementType) && "Invalid type for array element!");
819
820 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
821 ArrayType *&Entry =
822 pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)];
823
824 if (!Entry)
825 Entry = new (pImpl->Alloc) ArrayType(ElementType, NumElements);
826 return Entry;
827}
828
829bool ArrayType::isValidElementType(Type *ElemTy) {
830 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
831 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
832 !ElemTy->isTokenTy() && !ElemTy->isX86_AMXTy();
833}
834
835//===----------------------------------------------------------------------===//
836// VectorType Implementation
837//===----------------------------------------------------------------------===//
838
839VectorType::VectorType(Type *ElType, unsigned EQ, Type::TypeID TID)
840 : Type(ElType->getContext(), TID), ContainedType(ElType),
841 ElementQuantity(EQ) {
842 ContainedTys = &ContainedType;
843 NumContainedTys = 1;
844}
845
846VectorType *VectorType::get(Type *ElementType, ElementCount EC) {
847 if (EC.isScalable())
848 return ScalableVectorType::get(ElementType, EC.getKnownMinValue());
849 else
850 return FixedVectorType::get(ElementType, EC.getKnownMinValue());
851}
852
853bool VectorType::isValidElementType(Type *ElemTy) {
854 if (ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
855 ElemTy->isPointerTy() || ElemTy->getTypeID() == TypedPointerTyID ||
856 ElemTy->isByteTy())
857 return true;
858 if (auto *TTy = dyn_cast<TargetExtType>(ElemTy))
859 return TTy->hasProperty(TargetExtType::CanBeVectorElement);
860 return false;
861}
862
863//===----------------------------------------------------------------------===//
864// FixedVectorType Implementation
865//===----------------------------------------------------------------------===//
866
867FixedVectorType *FixedVectorType::get(Type *ElementType, unsigned NumElts) {
868 assert(NumElts > 0 && "#Elements of a VectorType must be greater than 0");
869 assert(isValidElementType(ElementType) && "Element type of a VectorType must "
870 "be an integer, floating point, "
871 "pointer type, or a valid target "
872 "extension type.");
873
874 auto EC = ElementCount::getFixed(NumElts);
875
876 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
877 VectorType *&Entry = ElementType->getContext()
878 .pImpl->VectorTypes[std::make_pair(ElementType, EC)];
879
880 if (!Entry)
881 Entry = new (pImpl->Alloc) FixedVectorType(ElementType, NumElts);
882 return cast<FixedVectorType>(Entry);
883}
884
885//===----------------------------------------------------------------------===//
886// ScalableVectorType Implementation
887//===----------------------------------------------------------------------===//
888
890 unsigned MinNumElts) {
891 assert(MinNumElts > 0 && "#Elements of a VectorType must be greater than 0");
892 assert(isValidElementType(ElementType) && "Element type of a VectorType must "
893 "be an integer, floating point, or "
894 "pointer type.");
895
896 auto EC = ElementCount::getScalable(MinNumElts);
897
898 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
899 VectorType *&Entry = ElementType->getContext()
900 .pImpl->VectorTypes[std::make_pair(ElementType, EC)];
901
902 if (!Entry)
903 Entry = new (pImpl->Alloc) ScalableVectorType(ElementType, MinNumElts);
904 return cast<ScalableVectorType>(Entry);
905}
906
907//===----------------------------------------------------------------------===//
908// PointerType Implementation
909//===----------------------------------------------------------------------===//
910
912 LLVMContextImpl *CImpl = C.pImpl;
913
914 // Since AddressSpace #0 is the common case, we special case it.
916 : CImpl->PointerTypes[AddressSpace];
917
918 if (!Entry)
919 Entry = new (CImpl->Alloc) PointerType(C, AddressSpace);
920 return Entry;
921}
922
923PointerType::PointerType(LLVMContext &C, unsigned AddrSpace)
924 : Type(C, PointerTyID) {
925 setSubclassData(AddrSpace);
926}
927
928bool PointerType::isValidElementType(Type *ElemTy) {
929 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
930 !ElemTy->isMetadataTy() && !ElemTy->isTokenTy() &&
931 !ElemTy->isX86_AMXTy();
932}
933
934bool PointerType::isLoadableOrStorableType(Type *ElemTy) {
935 return isValidElementType(ElemTy) && !ElemTy->isFunctionTy();
936}
937
938//===----------------------------------------------------------------------===//
939// TargetExtType Implementation
940//===----------------------------------------------------------------------===//
941
942TargetExtType::TargetExtType(LLVMContext &C, StringRef Name,
944 : Type(C, TargetExtTyID), Name(C.pImpl->Saver.save(Name)) {
945 NumContainedTys = Types.size();
946
947 // Parameter storage immediately follows the class in allocation.
948 Type **Params = reinterpret_cast<Type **>(this + 1);
949 ContainedTys = Params;
950 for (Type *T : Types)
951 *Params++ = T;
952
953 setSubclassData(Ints.size());
954 unsigned *IntParamSpace = reinterpret_cast<unsigned *>(Params);
955 IntParams = IntParamSpace;
956 for (unsigned IntParam : Ints)
957 *IntParamSpace++ = IntParam;
958}
959
961 ArrayRef<Type *> Types,
962 ArrayRef<unsigned> Ints) {
963 return cantFail(getOrError(C, Name, Types, Ints));
964}
965
966Expected<TargetExtType *> TargetExtType::getOrError(LLVMContext &C,
967 StringRef Name,
968 ArrayRef<Type *> Types,
969 ArrayRef<unsigned> Ints) {
970 const TargetExtTypeKeyInfo::KeyTy Key(Name, Types, Ints);
972 // Since we only want to allocate a fresh target type in case none is found
973 // and we don't want to perform two lookups (one for checking if existent and
974 // one for inserting the newly allocated one), here we instead lookup based on
975 // Key and update the reference to the target type in-place to a newly
976 // allocated one if not found.
977 auto [Iter, Inserted] = C.pImpl->TargetExtTypes.insert_as(nullptr, Key);
978 if (Inserted) {
979 // The target type was not found. Allocate one and update TargetExtTypes
980 // in-place.
981 TT = (TargetExtType *)C.pImpl->Alloc.Allocate(
982 sizeof(TargetExtType) + sizeof(Type *) * Types.size() +
983 sizeof(unsigned) * Ints.size(),
984 alignof(TargetExtType));
985 new (TT) TargetExtType(C, Name, Types, Ints);
986 *Iter = TT;
987 return checkParams(TT);
988 }
989
990 // The target type was found. Just return it.
991 return *Iter;
992}
993
994Expected<TargetExtType *> TargetExtType::checkParams(TargetExtType *TTy) {
995 // Opaque types in the AArch64 name space.
996 if (TTy->Name == "aarch64.svcount" &&
997 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() != 0))
998 return createStringError(
999 "target extension type aarch64.svcount should have no parameters");
1000
1001 // Opaque types in the RISC-V name space.
1002 if (TTy->Name == "riscv.vector.tuple" &&
1003 (TTy->getNumTypeParameters() != 1 || TTy->getNumIntParameters() != 1))
1004 return createStringError(
1005 "target extension type riscv.vector.tuple should have one "
1006 "type parameter and one integer parameter");
1007
1008 // Opaque types in the AMDGPU name space.
1009 if (TTy->Name == "amdgcn.named.barrier" &&
1010 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() != 1)) {
1011 return createStringError("target extension type amdgcn.named.barrier "
1012 "should have no type parameters "
1013 "and one integer parameter");
1014 }
1015 if (TTy->Name == "amdgpu.stridemark" &&
1016 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() > 1)) {
1017 return createStringError("target extension type amdgpu.stridemark "
1018 "should have no type parameters "
1019 "and at most one integer parameter");
1020 }
1021
1022 return TTy;
1023}
1024
1025namespace {
1026struct TargetTypeInfo {
1027 Type *LayoutType;
1028 uint64_t Properties;
1029
1030 template <typename... ArgTys>
1031 TargetTypeInfo(Type *LayoutType, ArgTys... Properties)
1032 : LayoutType(LayoutType), Properties((0 | ... | Properties)) {
1033 assert((!(this->Properties & TargetExtType::CanBeVectorElement) ||
1034 LayoutType->isSized()) &&
1035 "Vector element type must be sized");
1036 }
1037};
1038} // anonymous namespace
1039
1040static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
1041 LLVMContext &C = Ty->getContext();
1042 StringRef Name = Ty->getName();
1043 if (Name == "spirv.Image" || Name == "spirv.SignedImage")
1044 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal,
1046 if (Name == "spirv.Type") {
1047 assert(Ty->getNumIntParameters() == 3 &&
1048 "Wrong number of parameters for spirv.Type");
1049
1050 auto Size = Ty->getIntParameter(1);
1051 auto Alignment = Ty->getIntParameter(2);
1052
1053 llvm::Type *LayoutType = nullptr;
1054 if (Size > 0 && Alignment > 0) {
1055 LayoutType =
1056 ArrayType::get(Type::getIntNTy(C, Alignment), Size * 8 / Alignment);
1057 } else {
1058 // LLVM expects variables that can be allocated to have an alignment and
1059 // size. Default to using a 32-bit int as the layout type if none are
1060 // present.
1061 LayoutType = Type::getInt32Ty(C);
1062 }
1063
1064 return TargetTypeInfo(LayoutType, TargetExtType::CanBeGlobal,
1066 }
1067 if (Name == "spirv.IntegralConstant" || Name == "spirv.Literal")
1068 return TargetTypeInfo(Type::getVoidTy(C));
1069 if (Name == "spirv.Padding")
1070 return TargetTypeInfo(
1071 ArrayType::get(Type::getInt8Ty(C), Ty->getIntParameter(0)),
1073 if (Name.starts_with("spirv."))
1074 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::HasZeroInit,
1077
1078 // Opaque types in the AArch64 name space.
1079 if (Name == "aarch64.svcount")
1080 return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
1083
1084 // RISC-V vector tuple type. The layout is represented as the type that needs
1085 // the same number of vector registers(VREGS) as this tuple type, represented
1086 // as <vscale x (RVVBitsPerBlock * VREGS / 8) x i8>.
1087 if (Name == "riscv.vector.tuple") {
1088 unsigned TotalNumElts =
1089 std::max(cast<ScalableVectorType>(Ty->getTypeParameter(0))
1090 ->getMinNumElements(),
1092 Ty->getIntParameter(0);
1093 return TargetTypeInfo(
1096 }
1097
1098 // DirectX resources
1099 if (Name == "dx.Padding")
1100 return TargetTypeInfo(
1101 ArrayType::get(Type::getInt8Ty(C), Ty->getIntParameter(0)),
1103 if (Name.starts_with("dx."))
1104 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal,
1107
1108 // Opaque types in the AMDGPU name space.
1109 if (Name == "amdgcn.named.barrier") {
1110 return TargetTypeInfo(FixedVectorType::get(Type::getInt32Ty(C), 4),
1112 }
1113 if (Name == "amdgpu.stridemark")
1114 return TargetTypeInfo(Type::getVoidTy(C), TargetExtType::IsTokenLike);
1115
1116 // Type used to test vector element target extension property.
1117 // Can be removed once a public target extension type uses CanBeVectorElement.
1118 if (Name == "llvm.test.vectorelement") {
1119 return TargetTypeInfo(Type::getInt32Ty(C), TargetExtType::CanBeLocal,
1121 }
1122
1123 // Opaque types in the WebAssembly name space.
1124 if (Name == "wasm.funcref" || Name == "wasm.externref")
1125 return TargetTypeInfo(PointerType::getUnqual(C), TargetExtType::HasZeroInit,
1128
1129 return TargetTypeInfo(Type::getVoidTy(C));
1130}
1131
1132bool Type::isTokenLikeTy() const {
1133 if (isTokenTy())
1134 return true;
1135 if (auto *TT = dyn_cast<TargetExtType>(this))
1136 return TT->hasProperty(TargetExtType::Property::IsTokenLike);
1137 return false;
1138}
1139
1140Type *TargetExtType::getLayoutType() const {
1141 return getTargetTypeInfo(this).LayoutType;
1142}
1143
1144bool TargetExtType::hasProperty(Property Prop) const {
1145 uint64_t Properties = getTargetTypeInfo(this).Properties;
1146 return (Properties & Prop) == Prop;
1147}
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 bool isValidElementType(Type *Ty)
Predicate for the element types that the SLP vectorizer supports.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty)
Definition Type.cpp:1040
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_)
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
Definition APFloat.cpp:183
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:829
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:378
LLVM_ABI APInt getMask() const
For example, this is 0xFF for an 8 bit byte, 0xFFFF for b16, etc.
Definition Type.cpp:406
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:867
static LLVM_ABI bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
Definition Type.cpp:467
static LLVM_ABI bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
Definition Type.cpp:462
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:348
LLVM_ABI APInt getMask() const
For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
Definition Type.cpp:372
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 PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
static LLVM_ABI bool isLoadableOrStorableType(Type *ElemTy)
Return true if we can load or store from a pointer to this type.
Definition Type.cpp:934
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
Definition Type.cpp:911
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:928
Class to represent scalable SIMD vectors.
static LLVM_ABI ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
Definition Type.cpp:889
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:345
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:128
void remove(MapEntryTy *KeyValue)
remove - Remove the specified key/value pair from the map, but do not erase it.
Definition StringMap.h:412
AllocatorTy & getAllocator()
StringMapEntry< ValueTy > MapEntryTy
Definition StringMap.h:132
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:788
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:477
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:559
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:598
LLVM_ABI bool containsHomogeneousScalableVectorTypes() const
Returns true if this struct contains homogeneous scalable vector types.
Definition Type.cpp:587
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:620
LLVM_ABI bool containsHomogeneousTypes() const
Return true if this struct is non-empty and all element types are the same.
Definition Type.cpp:593
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:531
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:802
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition Type.cpp:683
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:767
LLVM_ABI bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
isSized - Return true if this is a sized type.
Definition Type.cpp:722
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:632
LLVM_ABI bool isLayoutIdentical(StructType *Other) const
Return true if this is layout identical to the specified struct.
Definition Type.cpp:773
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:602
LLVM_ABI Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Definition Type.cpp:782
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Returns true if this struct contains a scalable vector.
Definition Type.cpp:504
LLVM_ABI StringRef getName() const
Return the name for this struct type if it has an identity.
Definition Type.cpp:760
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:960
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:994
LLVM_ABI bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
Definition Type.cpp:1144
@ 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:966
LLVM_ABI Type * getLayoutType() const
Returns an underlying layout type for the target extension type.
Definition Type.cpp:1140
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:1132
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
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:340
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:220
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 bool isPacked(const T &...O)
Definition SIDefines.h:333
constexpr size_t NameSize
Definition XCOFF.h:30
ElementType
The element type of an SRV or UAV resource.
Definition DXILABI.h:68
LLVM_ABI Instruction & front() const
unsigned getNumElements(Type *Ty)
Definition SLPUtils.cpp:63
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:2166
#define N
#define EQ(a, b)
Definition regexec.c:65