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