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