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