MLIR  16.0.0git
LLVMTypes.cpp
Go to the documentation of this file.
1 //
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file implements the types for the LLVM dialect in MLIR. These MLIR types
9 // correspond to the LLVM IR type system.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "TypeDetail.h"
14 
17 #include "mlir/IR/BuiltinTypes.h"
19 #include "mlir/IR/TypeSupport.h"
20 
21 #include "llvm/ADT/ScopeExit.h"
22 #include "llvm/ADT/TypeSwitch.h"
23 #include "llvm/Support/TypeSize.h"
24 
25 using namespace mlir;
26 using namespace mlir::LLVM;
27 
28 constexpr const static unsigned kBitsInByte = 8;
29 
30 //===----------------------------------------------------------------------===//
31 // Array type.
32 //===----------------------------------------------------------------------===//
33 
35  return !type.isa<LLVMVoidType, LLVMLabelType, LLVMMetadataType,
36  LLVMFunctionType, LLVMTokenType, LLVMScalableVectorType>();
37 }
38 
39 LLVMArrayType LLVMArrayType::get(Type elementType, unsigned numElements) {
40  assert(elementType && "expected non-null subtype");
41  return Base::get(elementType.getContext(), elementType, numElements);
42 }
43 
46  Type elementType, unsigned numElements) {
47  assert(elementType && "expected non-null subtype");
48  return Base::getChecked(emitError, elementType.getContext(), elementType,
49  numElements);
50 }
51 
52 Type LLVMArrayType::getElementType() const { return getImpl()->elementType; }
53 
55  return getImpl()->numElements;
56 }
57 
60  Type elementType, unsigned numElements) {
61  if (!isValidElementType(elementType))
62  return emitError() << "invalid array element type: " << elementType;
63  return success();
64 }
65 
66 unsigned LLVMArrayType::getTypeSizeInBits(const DataLayout &dataLayout,
67  DataLayoutEntryListRef params) const {
68  return kBitsInByte * getTypeSize(dataLayout, params);
69 }
70 
71 unsigned LLVMArrayType::getTypeSize(const DataLayout &dataLayout,
72  DataLayoutEntryListRef params) const {
73  return llvm::alignTo(dataLayout.getTypeSize(getElementType()),
74  dataLayout.getTypeABIAlignment(getElementType())) *
76 }
77 
78 unsigned LLVMArrayType::getABIAlignment(const DataLayout &dataLayout,
79  DataLayoutEntryListRef params) const {
80  return dataLayout.getTypeABIAlignment(getElementType());
81 }
82 
83 unsigned
85  DataLayoutEntryListRef params) const {
86  return dataLayout.getTypePreferredAlignment(getElementType());
87 }
88 
90  function_ref<void(Attribute)> walkAttrsFn,
91  function_ref<void(Type)> walkTypesFn) const {
92  walkTypesFn(getElementType());
93 }
94 
96  ArrayRef<Attribute> replAttrs, ArrayRef<Type> replTypes) const {
97  return get(replTypes.front(), getNumElements());
98 }
99 
100 //===----------------------------------------------------------------------===//
101 // Function type.
102 //===----------------------------------------------------------------------===//
103 
105  return !type.isa<LLVMVoidType, LLVMFunctionType>();
106 }
107 
109  return !type.isa<LLVMFunctionType, LLVMMetadataType, LLVMLabelType>();
110 }
111 
113  bool isVarArg) {
114  assert(result && "expected non-null result");
115  return Base::get(result.getContext(), result, arguments, isVarArg);
116 }
117 
120  Type result, ArrayRef<Type> arguments,
121  bool isVarArg) {
122  assert(result && "expected non-null result");
123  return Base::getChecked(emitError, result.getContext(), result, arguments,
124  isVarArg);
125 }
126 
128  TypeRange results) const {
129  assert(results.size() == 1 && "expected a single result type");
130  return get(results[0], llvm::to_vector(inputs), isVarArg());
131 }
132 
134  return getImpl()->getReturnType();
135 }
137  return getImpl()->getReturnType();
138 }
139 
141  return getImpl()->getArgumentTypes().size();
142 }
143 
145  return getImpl()->getArgumentTypes()[i];
146 }
147 
148 bool LLVMFunctionType::isVarArg() const { return getImpl()->isVariadic(); }
149 
151  return getImpl()->getArgumentTypes();
152 }
153 
156  Type result, ArrayRef<Type> arguments, bool) {
157  if (!isValidResultType(result))
158  return emitError() << "invalid function result type: " << result;
159 
160  for (Type arg : arguments)
161  if (!isValidArgumentType(arg))
162  return emitError() << "invalid function argument type: " << arg;
163 
164  return success();
165 }
166 
168  function_ref<void(Attribute)> walkAttrsFn,
169  function_ref<void(Type)> walkTypesFn) const {
170  for (Type type : llvm::concat<const Type>(getReturnTypes(), getParams()))
171  walkTypesFn(type);
172 }
173 
175  ArrayRef<Attribute> replAttrs, ArrayRef<Type> replTypes) const {
176  return get(replTypes.front(), replTypes.drop_front(), isVarArg());
177 }
178 
179 //===----------------------------------------------------------------------===//
180 // Pointer type.
181 //===----------------------------------------------------------------------===//
182 
184  if (!type)
185  return true;
186  return isCompatibleOuterType(type)
187  ? !type.isa<LLVMVoidType, LLVMTokenType, LLVMMetadataType,
188  LLVMLabelType>()
189  : type.isa<PointerElementTypeInterface>();
190 }
191 
192 LLVMPointerType LLVMPointerType::get(Type pointee, unsigned addressSpace) {
193  assert(pointee && "expected non-null subtype, pass the context instead if "
194  "the opaque pointer type is desired");
195  return Base::get(pointee.getContext(), pointee, addressSpace);
196 }
197 
199  unsigned addressSpace) {
200  return Base::get(context, Type(), addressSpace);
201 }
202 
205  Type pointee, unsigned addressSpace) {
206  return Base::getChecked(emitError, pointee.getContext(), pointee,
207  addressSpace);
208 }
209 
212  MLIRContext *context, unsigned addressSpace) {
213  return Base::getChecked(emitError, context, Type(), addressSpace);
214 }
215 
216 Type LLVMPointerType::getElementType() const { return getImpl()->pointeeType; }
217 
218 bool LLVMPointerType::isOpaque() const { return !getImpl()->pointeeType; }
219 
221  return getImpl()->addressSpace;
222 }
223 
226  Type pointee, unsigned) {
227  if (!isValidElementType(pointee))
228  return emitError() << "invalid pointer element type: " << pointee;
229  return success();
230 }
231 
232 constexpr const static unsigned kDefaultPointerSizeBits = 64;
233 constexpr const static unsigned kDefaultPointerAlignment = 8;
234 
236  PtrDLEntryPos pos) {
237  auto spec = attr.cast<DenseIntElementsAttr>();
238  auto idx = static_cast<unsigned>(pos);
239  if (idx >= spec.size())
240  return None;
241  return spec.getValues<unsigned>()[idx];
242 }
243 
244 /// Returns the part of the data layout entry that corresponds to `pos` for the
245 /// given `type` by interpreting the list of entries `params`. For the pointer
246 /// type in the default address space, returns the default value if the entries
247 /// do not provide a custom one, for other address spaces returns None.
248 static Optional<unsigned>
250  PtrDLEntryPos pos) {
251  // First, look for the entry for the pointer in the current address space.
252  Attribute currentEntry;
253  for (DataLayoutEntryInterface entry : params) {
254  if (!entry.isTypeEntry())
255  continue;
256  if (entry.getKey().get<Type>().cast<LLVMPointerType>().getAddressSpace() ==
257  type.getAddressSpace()) {
258  currentEntry = entry.getValue();
259  break;
260  }
261  }
262  if (currentEntry) {
263  return *extractPointerSpecValue(currentEntry, pos) /
264  (pos == PtrDLEntryPos::Size ? 1 : kBitsInByte);
265  }
266 
267  // If not found, and this is the pointer to the default memory space, assume
268  // 64-bit pointers.
269  if (type.getAddressSpace() == 0) {
272  }
273 
274  return llvm::None;
275 }
276 
277 unsigned
279  DataLayoutEntryListRef params) const {
280  if (Optional<unsigned> size =
282  return *size;
283 
284  // For other memory spaces, use the size of the pointer to the default memory
285  // space.
286  if (isOpaque())
287  return dataLayout.getTypeSizeInBits(get(getContext()));
288  return dataLayout.getTypeSizeInBits(get(getElementType()));
289 }
290 
291 unsigned LLVMPointerType::getABIAlignment(const DataLayout &dataLayout,
292  DataLayoutEntryListRef params) const {
293  if (Optional<unsigned> alignment =
295  return *alignment;
296 
297  if (isOpaque())
298  return dataLayout.getTypeABIAlignment(get(getContext()));
299  return dataLayout.getTypeABIAlignment(get(getElementType()));
300 }
301 
302 unsigned
304  DataLayoutEntryListRef params) const {
305  if (Optional<unsigned> alignment =
307  return *alignment;
308 
309  if (isOpaque())
310  return dataLayout.getTypePreferredAlignment(get(getContext()));
311  return dataLayout.getTypePreferredAlignment(get(getElementType()));
312 }
313 
315  DataLayoutEntryListRef newLayout) const {
316  for (DataLayoutEntryInterface newEntry : newLayout) {
317  if (!newEntry.isTypeEntry())
318  continue;
319  unsigned size = kDefaultPointerSizeBits;
320  unsigned abi = kDefaultPointerAlignment;
321  auto newType = newEntry.getKey().get<Type>().cast<LLVMPointerType>();
322  const auto *it =
323  llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
324  if (auto type = entry.getKey().dyn_cast<Type>()) {
325  return type.cast<LLVMPointerType>().getAddressSpace() ==
326  newType.getAddressSpace();
327  }
328  return false;
329  });
330  if (it == oldLayout.end()) {
331  llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
332  if (auto type = entry.getKey().dyn_cast<Type>()) {
333  return type.cast<LLVMPointerType>().getAddressSpace() == 0;
334  }
335  return false;
336  });
337  }
338  if (it != oldLayout.end()) {
341  }
342 
343  Attribute newSpec = newEntry.getValue().cast<DenseIntElementsAttr>();
344  unsigned newSize = *extractPointerSpecValue(newSpec, PtrDLEntryPos::Size);
345  unsigned newAbi = *extractPointerSpecValue(newSpec, PtrDLEntryPos::Abi);
346  if (size != newSize || abi < newAbi || abi % newAbi != 0)
347  return false;
348  }
349  return true;
350 }
351 
353  Location loc) const {
354  for (DataLayoutEntryInterface entry : entries) {
355  if (!entry.isTypeEntry())
356  continue;
357  auto key = entry.getKey().get<Type>().cast<LLVMPointerType>();
358  auto values = entry.getValue().dyn_cast<DenseIntElementsAttr>();
359  if (!values || (values.size() != 3 && values.size() != 4)) {
360  return emitError(loc)
361  << "expected layout attribute for " << entry.getKey().get<Type>()
362  << " to be a dense integer elements attribute with 3 or 4 "
363  "elements";
364  }
365  if (key.getElementType() && !key.getElementType().isInteger(8)) {
366  return emitError(loc) << "unexpected layout attribute for pointer to "
367  << key.getElementType();
368  }
371  return emitError(loc) << "preferred alignment is expected to be at least "
372  "as large as ABI alignment";
373  }
374  }
375  return success();
376 }
377 
379  function_ref<void(Attribute)> walkAttrsFn,
380  function_ref<void(Type)> walkTypesFn) const {
381  walkTypesFn(getElementType());
382 }
383 
385  ArrayRef<Attribute> replAttrs, ArrayRef<Type> replTypes) const {
386  return get(replTypes.front(), getAddressSpace());
387 }
388 
389 //===----------------------------------------------------------------------===//
390 // Struct type.
391 //===----------------------------------------------------------------------===//
392 
394  return !type.isa<LLVMVoidType, LLVMLabelType, LLVMMetadataType,
395  LLVMFunctionType, LLVMTokenType, LLVMScalableVectorType>();
396 }
397 
399  StringRef name) {
400  return Base::get(context, name, /*opaque=*/false);
401 }
402 
405  StringRef name) {
406  return Base::getChecked(emitError, context, name, /*opaque=*/false);
407 }
408 
410  StringRef name,
411  ArrayRef<Type> elements,
412  bool isPacked) {
413  std::string stringName = name.str();
414  unsigned counter = 0;
415  do {
416  auto type = LLVMStructType::getIdentified(context, stringName);
417  if (type.isInitialized() || failed(type.setBody(elements, isPacked))) {
418  counter += 1;
419  stringName = (Twine(name) + "." + std::to_string(counter)).str();
420  continue;
421  }
422  return type;
423  } while (true);
424 }
425 
427  ArrayRef<Type> types, bool isPacked) {
428  return Base::get(context, types, isPacked);
429 }
430 
433  MLIRContext *context, ArrayRef<Type> types,
434  bool isPacked) {
435  return Base::getChecked(emitError, context, types, isPacked);
436 }
437 
439  return Base::get(context, name, /*opaque=*/true);
440 }
441 
444  MLIRContext *context, StringRef name) {
445  return Base::getChecked(emitError, context, name, /*opaque=*/true);
446 }
447 
449  assert(isIdentified() && "can only set bodies of identified structs");
450  assert(llvm::all_of(types, LLVMStructType::isValidElementType) &&
451  "expected valid body types");
452  return Base::mutate(types, isPacked);
453 }
454 
455 bool LLVMStructType::isPacked() const { return getImpl()->isPacked(); }
456 bool LLVMStructType::isIdentified() const { return getImpl()->isIdentified(); }
458  return getImpl()->isIdentified() &&
459  (getImpl()->isOpaque() || !getImpl()->isInitialized());
460 }
461 bool LLVMStructType::isInitialized() { return getImpl()->isInitialized(); }
462 StringRef LLVMStructType::getName() { return getImpl()->getIdentifier(); }
464  return isIdentified() ? getImpl()->getIdentifiedStructBody()
465  : getImpl()->getTypeList();
466 }
467 
469  StringRef, bool) {
470  return success();
471 }
472 
475  ArrayRef<Type> types, bool) {
476  for (Type t : types)
477  if (!isValidElementType(t))
478  return emitError() << "invalid LLVM structure element type: " << t;
479 
480  return success();
481 }
482 
483 unsigned
485  DataLayoutEntryListRef params) const {
486  unsigned structSize = 0;
487  unsigned structAlignment = 1;
488  for (Type element : getBody()) {
489  unsigned elementAlignment =
490  isPacked() ? 1 : dataLayout.getTypeABIAlignment(element);
491  // Add padding to the struct size to align it to the abi alignment of the
492  // element type before than adding the size of the element
493  structSize = llvm::alignTo(structSize, elementAlignment);
494  structSize += dataLayout.getTypeSize(element);
495 
496  // The alignment requirement of a struct is equal to the strictest alignment
497  // requirement of its elements.
498  structAlignment = std::max(elementAlignment, structAlignment);
499  }
500  // At the end, add padding to the struct to satisfy its own alignment
501  // requirement. Otherwise structs inside of arrays would be misaligned.
502  structSize = llvm::alignTo(structSize, structAlignment);
503  return structSize * kBitsInByte;
504 }
505 
506 namespace {
507 enum class StructDLEntryPos { Abi = 0, Preferred = 1 };
508 } // namespace
509 
510 static Optional<unsigned>
512  StructDLEntryPos pos) {
513  const auto *currentEntry =
514  llvm::find_if(params, [](DataLayoutEntryInterface entry) {
515  return entry.isTypeEntry();
516  });
517  if (currentEntry == params.end())
518  return llvm::None;
519 
520  auto attr = currentEntry->getValue().cast<DenseIntElementsAttr>();
521  if (pos == StructDLEntryPos::Preferred &&
522  attr.size() <= static_cast<unsigned>(StructDLEntryPos::Preferred))
523  // If no preferred was specified, fall back to abi alignment
524  pos = StructDLEntryPos::Abi;
525 
526  return attr.getValues<unsigned>()[static_cast<unsigned>(pos)];
527 }
528 
529 static unsigned calculateStructAlignment(const DataLayout &dataLayout,
530  DataLayoutEntryListRef params,
531  LLVMStructType type,
532  StructDLEntryPos pos) {
533  // Packed structs always have an abi alignment of 1
534  if (pos == StructDLEntryPos::Abi && type.isPacked()) {
535  return 1;
536  }
537 
538  // The alignment requirement of a struct is equal to the strictest alignment
539  // requirement of its elements.
540  unsigned structAlignment = 1;
541  for (Type iter : type.getBody()) {
542  structAlignment =
543  std::max(dataLayout.getTypeABIAlignment(iter), structAlignment);
544  }
545 
546  // Entries are only allowed to be stricter than the required alignment
547  if (Optional<unsigned> entryResult =
548  getStructDataLayoutEntry(params, type, pos))
549  return std::max(*entryResult / kBitsInByte, structAlignment);
550 
551  return structAlignment;
552 }
553 
554 unsigned LLVMStructType::getABIAlignment(const DataLayout &dataLayout,
555  DataLayoutEntryListRef params) const {
556  return calculateStructAlignment(dataLayout, params, *this,
558 }
559 
560 unsigned
562  DataLayoutEntryListRef params) const {
563  return calculateStructAlignment(dataLayout, params, *this,
565 }
566 
568  return attr.cast<DenseIntElementsAttr>()
569  .getValues<unsigned>()[static_cast<unsigned>(pos)];
570 }
571 
573  DataLayoutEntryListRef newLayout) const {
574  for (DataLayoutEntryInterface newEntry : newLayout) {
575  if (!newEntry.isTypeEntry())
576  continue;
577 
578  const auto *previousEntry =
579  llvm::find_if(oldLayout, [](DataLayoutEntryInterface entry) {
580  return entry.isTypeEntry();
581  });
582  if (previousEntry == oldLayout.end())
583  continue;
584 
585  unsigned abi = extractStructSpecValue(previousEntry->getValue(),
587  unsigned newAbi =
588  extractStructSpecValue(newEntry.getValue(), StructDLEntryPos::Abi);
589  if (abi < newAbi || abi % newAbi != 0)
590  return false;
591  }
592  return true;
593 }
594 
596  Location loc) const {
597  for (DataLayoutEntryInterface entry : entries) {
598  if (!entry.isTypeEntry())
599  continue;
600 
601  auto key = entry.getKey().get<Type>().cast<LLVMStructType>();
602  auto values = entry.getValue().dyn_cast<DenseIntElementsAttr>();
603  if (!values || (values.size() != 2 && values.size() != 1)) {
604  return emitError(loc)
605  << "expected layout attribute for " << entry.getKey().get<Type>()
606  << " to be a dense integer elements attribute of 1 or 2 elements";
607  }
608 
609  if (key.isIdentified() || !key.getBody().empty()) {
610  return emitError(loc) << "unexpected layout attribute for struct " << key;
611  }
612 
613  if (values.size() == 1)
614  continue;
615 
618  return emitError(loc) << "preferred alignment is expected to be at least "
619  "as large as ABI alignment";
620  }
621  }
622  return mlir::success();
623 }
624 
626  function_ref<void(Attribute)> walkAttrsFn,
627  function_ref<void(Type)> walkTypesFn) const {
628  for (Type type : getBody())
629  walkTypesFn(type);
630 }
631 
633  ArrayRef<Attribute> replAttrs, ArrayRef<Type> replTypes) const {
634  // TODO: It's not clear how we support replacing sub-elements of mutable
635  // types.
636  return nullptr;
637 }
638 
639 //===----------------------------------------------------------------------===//
640 // Vector types.
641 //===----------------------------------------------------------------------===//
642 
643 /// Verifies that the type about to be constructed is well-formed.
644 template <typename VecTy>
645 static LogicalResult
647  Type elementType, unsigned numElements) {
648  if (numElements == 0)
649  return emitError() << "the number of vector elements must be positive";
650 
651  if (!VecTy::isValidElementType(elementType))
652  return emitError() << "invalid vector element type";
653 
654  return success();
655 }
656 
658  unsigned numElements) {
659  assert(elementType && "expected non-null subtype");
660  return Base::get(elementType.getContext(), elementType, numElements);
661 }
662 
665  Type elementType, unsigned numElements) {
666  assert(elementType && "expected non-null subtype");
667  return Base::getChecked(emitError, elementType.getContext(), elementType,
668  numElements);
669 }
670 
672  return static_cast<detail::LLVMTypeAndSizeStorage *>(impl)->elementType;
673 }
674 
676  return getImpl()->numElements;
677 }
678 
680  return type.isa<LLVMPointerType, LLVMPPCFP128Type>();
681 }
682 
685  Type elementType, unsigned numElements) {
686  return verifyVectorConstructionInvariants<LLVMFixedVectorType>(
687  emitError, elementType, numElements);
688 }
689 
691  function_ref<void(Attribute)> walkAttrsFn,
692  function_ref<void(Type)> walkTypesFn) const {
693  walkTypesFn(getElementType());
694 }
695 
697  ArrayRef<Attribute> replAttrs, ArrayRef<Type> replTypes) const {
698  return get(replTypes[0], getNumElements());
699 }
700 
701 //===----------------------------------------------------------------------===//
702 // LLVMScalableVectorType.
703 //===----------------------------------------------------------------------===//
704 
706  unsigned minNumElements) {
707  assert(elementType && "expected non-null subtype");
708  return Base::get(elementType.getContext(), elementType, minNumElements);
709 }
710 
713  Type elementType, unsigned minNumElements) {
714  assert(elementType && "expected non-null subtype");
715  return Base::getChecked(emitError, elementType.getContext(), elementType,
716  minNumElements);
717 }
718 
720  return static_cast<detail::LLVMTypeAndSizeStorage *>(impl)->elementType;
721 }
722 
724  return getImpl()->numElements;
725 }
726 
728  if (auto intType = type.dyn_cast<IntegerType>())
729  return intType.isSignless();
730 
731  return isCompatibleFloatingPointType(type) || type.isa<LLVMPointerType>();
732 }
733 
736  Type elementType, unsigned numElements) {
737  return verifyVectorConstructionInvariants<LLVMScalableVectorType>(
738  emitError, elementType, numElements);
739 }
740 
742  function_ref<void(Attribute)> walkAttrsFn,
743  function_ref<void(Type)> walkTypesFn) const {
744  walkTypesFn(getElementType());
745 }
746 
748  ArrayRef<Attribute> replAttrs, ArrayRef<Type> replTypes) const {
749  return get(replTypes[0], getMinNumElements());
750 }
751 
752 //===----------------------------------------------------------------------===//
753 // Utility functions.
754 //===----------------------------------------------------------------------===//
755 
757  // clang-format off
758  if (type.isa<
759  BFloat16Type,
760  Float16Type,
761  Float32Type,
762  Float64Type,
763  Float80Type,
764  Float128Type,
767  LLVMLabelType,
768  LLVMMetadataType,
769  LLVMPPCFP128Type,
772  LLVMTokenType,
775  LLVMVoidType,
776  LLVMX86MMXType
777  >()) {
778  // clang-format on
779  return true;
780  }
781 
782  // Only signless integers are compatible.
783  if (auto intType = type.dyn_cast<IntegerType>())
784  return intType.isSignless();
785 
786  // 1D vector types are compatible.
787  if (auto vecType = type.dyn_cast<VectorType>())
788  return vecType.getRank() == 1;
789 
790  return false;
791 }
792 
793 static bool isCompatibleImpl(Type type, DenseSet<Type> &compatibleTypes) {
794  if (!compatibleTypes.insert(type).second)
795  return true;
796 
797  auto isCompatible = [&](Type type) {
798  return isCompatibleImpl(type, compatibleTypes);
799  };
800 
801  bool result =
803  .Case<LLVMStructType>([&](auto structType) {
804  return llvm::all_of(structType.getBody(), isCompatible);
805  })
806  .Case<LLVMFunctionType>([&](auto funcType) {
807  return isCompatible(funcType.getReturnType()) &&
808  llvm::all_of(funcType.getParams(), isCompatible);
809  })
810  .Case<IntegerType>([](auto intType) { return intType.isSignless(); })
811  .Case<VectorType>([&](auto vecType) {
812  return vecType.getRank() == 1 &&
813  isCompatible(vecType.getElementType());
814  })
815  .Case<LLVMPointerType>([&](auto pointerType) {
816  if (pointerType.isOpaque())
817  return true;
818  return isCompatible(pointerType.getElementType());
819  })
820  // clang-format off
821  .Case<
825  >([&](auto containerType) {
826  return isCompatible(containerType.getElementType());
827  })
828  .Case<
829  BFloat16Type,
830  Float16Type,
831  Float32Type,
832  Float64Type,
833  Float80Type,
834  Float128Type,
835  LLVMLabelType,
836  LLVMMetadataType,
837  LLVMPPCFP128Type,
838  LLVMTokenType,
839  LLVMVoidType,
840  LLVMX86MMXType
841  >([](Type) { return true; })
842  // clang-format on
843  .Default([](Type) { return false; });
844 
845  if (!result)
846  compatibleTypes.erase(type);
847 
848  return result;
849 }
850 
852  if (auto *llvmDialect =
853  type.getContext()->getLoadedDialect<LLVM::LLVMDialect>())
854  return isCompatibleImpl(type, llvmDialect->compatibleTypes.get());
855 
856  DenseSet<Type> localCompatibleTypes;
857  return isCompatibleImpl(type, localCompatibleTypes);
858 }
859 
861  return LLVMDialect::isCompatibleType(type);
862 }
863 
865  return type.isa<BFloat16Type, Float16Type, Float32Type, Float64Type,
866  Float80Type, Float128Type, LLVMPPCFP128Type>();
867 }
868 
871  return true;
872 
873  if (auto vecType = type.dyn_cast<VectorType>()) {
874  if (vecType.getRank() != 1)
875  return false;
876  Type elementType = vecType.getElementType();
877  if (auto intType = elementType.dyn_cast<IntegerType>())
878  return intType.isSignless();
879  return elementType.isa<BFloat16Type, Float16Type, Float32Type, Float64Type,
880  Float80Type, Float128Type>();
881  }
882  return false;
883 }
884 
886  return llvm::TypeSwitch<Type, Type>(type)
887  .Case<LLVMFixedVectorType, LLVMScalableVectorType, VectorType>(
888  [](auto ty) { return ty.getElementType(); })
889  .Default([](Type) -> Type {
890  llvm_unreachable("incompatible with LLVM vector type");
891  });
892 }
893 
894 llvm::ElementCount mlir::LLVM::getVectorNumElements(Type type) {
896  .Case([](VectorType ty) {
897  if (ty.isScalable())
898  return llvm::ElementCount::getScalable(ty.getNumElements());
899  return llvm::ElementCount::getFixed(ty.getNumElements());
900  })
901  .Case([](LLVMFixedVectorType ty) {
902  return llvm::ElementCount::getFixed(ty.getNumElements());
903  })
904  .Case([](LLVMScalableVectorType ty) {
905  return llvm::ElementCount::getScalable(ty.getMinNumElements());
906  })
907  .Default([](Type) -> llvm::ElementCount {
908  llvm_unreachable("incompatible with LLVM vector type");
909  });
910 }
911 
913  assert(
914  (vectorType
915  .isa<LLVMFixedVectorType, LLVMScalableVectorType, VectorType>()) &&
916  "expected LLVM-compatible vector type");
917  return !vectorType.isa<LLVMFixedVectorType>() &&
918  (vectorType.isa<LLVMScalableVectorType>() ||
919  vectorType.cast<VectorType>().isScalable());
920 }
921 
922 Type mlir::LLVM::getVectorType(Type elementType, unsigned numElements,
923  bool isScalable) {
924  bool useLLVM = LLVMFixedVectorType::isValidElementType(elementType);
925  bool useBuiltIn = VectorType::isValidElementType(elementType);
926  (void)useBuiltIn;
927  assert((useLLVM ^ useBuiltIn) && "expected LLVM-compatible fixed-vector type "
928  "to be either builtin or LLVM dialect type");
929  if (useLLVM) {
930  if (isScalable)
931  return LLVMScalableVectorType::get(elementType, numElements);
932  return LLVMFixedVectorType::get(elementType, numElements);
933  }
934  return VectorType::get(numElements, elementType, (unsigned)isScalable);
935 }
936 
937 Type mlir::LLVM::getFixedVectorType(Type elementType, unsigned numElements) {
938  bool useLLVM = LLVMFixedVectorType::isValidElementType(elementType);
939  bool useBuiltIn = VectorType::isValidElementType(elementType);
940  (void)useBuiltIn;
941  assert((useLLVM ^ useBuiltIn) && "expected LLVM-compatible fixed-vector type "
942  "to be either builtin or LLVM dialect type");
943  if (useLLVM)
944  return LLVMFixedVectorType::get(elementType, numElements);
945  return VectorType::get(numElements, elementType);
946 }
947 
948 Type mlir::LLVM::getScalableVectorType(Type elementType, unsigned numElements) {
949  bool useLLVM = LLVMScalableVectorType::isValidElementType(elementType);
950  bool useBuiltIn = VectorType::isValidElementType(elementType);
951  (void)useBuiltIn;
952  assert((useLLVM ^ useBuiltIn) && "expected LLVM-compatible scalable-vector "
953  "type to be either builtin or LLVM dialect "
954  "type");
955  if (useLLVM)
956  return LLVMScalableVectorType::get(elementType, numElements);
957  return VectorType::get(numElements, elementType, /*numScalableDims=*/1);
958 }
959 
961  assert(isCompatibleType(type) &&
962  "expected a type compatible with the LLVM dialect");
963 
965  .Case<BFloat16Type, Float16Type>(
966  [](Type) { return llvm::TypeSize::Fixed(16); })
967  .Case<Float32Type>([](Type) { return llvm::TypeSize::Fixed(32); })
968  .Case<Float64Type, LLVMX86MMXType>(
969  [](Type) { return llvm::TypeSize::Fixed(64); })
970  .Case<Float80Type>([](Type) { return llvm::TypeSize::Fixed(80); })
971  .Case<Float128Type>([](Type) { return llvm::TypeSize::Fixed(128); })
972  .Case<IntegerType>([](IntegerType intTy) {
973  return llvm::TypeSize::Fixed(intTy.getWidth());
974  })
975  .Case<LLVMPPCFP128Type>([](Type) { return llvm::TypeSize::Fixed(128); })
976  .Case<LLVMFixedVectorType>([](LLVMFixedVectorType t) {
977  llvm::TypeSize elementSize =
979  return llvm::TypeSize(elementSize.getFixedSize() * t.getNumElements(),
980  elementSize.isScalable());
981  })
982  .Case<VectorType>([](VectorType t) {
983  assert(isCompatibleVectorType(t) &&
984  "unexpected incompatible with LLVM vector type");
985  llvm::TypeSize elementSize =
986  getPrimitiveTypeSizeInBits(t.getElementType());
987  return llvm::TypeSize(elementSize.getFixedSize() * t.getNumElements(),
988  elementSize.isScalable());
989  })
990  .Default([](Type ty) {
991  assert((ty.isa<LLVMVoidType, LLVMLabelType, LLVMMetadataType,
992  LLVMTokenType, LLVMStructType, LLVMArrayType,
994  "unexpected missing support for primitive type");
995  return llvm::TypeSize::Fixed(0);
996  });
997 }
998 
999 #include "mlir/Dialect/LLVMIR/LLVMTypeInterfaces.cpp.inc"
Include the generated interface declarations.
static bool isValidArgumentType(Type type)
Checks if the given type can be used an argument in a function type.
Definition: LLVMTypes.cpp:104
bool isCompatibleFloatingPointType(Type type)
Returns true if the given type is a floating-point type compatible with the LLVM dialect.
Definition: LLVMTypes.cpp:864
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Type pointee, unsigned)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:225
llvm::ElementCount getVectorNumElements(Type type)
Returns the element count of any LLVM-compatible vector type.
Definition: LLVMTypes.cpp:894
void walkImmediateSubElements(function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Definition: LLVMTypes.cpp:690
U cast() const
Definition: Attributes.h:136
Type getFixedVectorType(Type elementType, unsigned numElements)
Creates an LLVM dialect-compatible type with the given element type and length.
Definition: LLVMTypes.cpp:937
static LLVMStructType getNewIdentified(MLIRContext *context, StringRef name, ArrayRef< Type > elements, bool isPacked=false)
Gets a new identified struct with the given body.
Definition: LLVMTypes.cpp:409
LLVM dialect scalable vector type, represents a sequence of elements of unknown length that is known ...
Definition: LLVMTypes.h:438
static bool isCompatibleImpl(Type type, DenseSet< Type > &compatibleTypes)
Definition: LLVMTypes.cpp:793
void walkImmediateSubElements(function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Definition: LLVMTypes.cpp:625
StringRef getName()
Returns the name of an identified struct.
Definition: LLVMTypes.cpp:462
Type replaceImmediateSubElements(ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Definition: LLVMTypes.cpp:95
bool isCompatibleOuterType(Type type)
Returns true if the given outer type is compatible with the LLVM dialect without checking its potenti...
Definition: LLVMTypes.cpp:756
static LLVMStructType getOpaque(StringRef name, MLIRContext *context)
Gets or creates an intentionally-opaque identified struct.
Definition: LLVMTypes.cpp:438
static LLVMStructType getLiteral(MLIRContext *context, ArrayRef< Type > types, bool isPacked=false)
Gets or creates a literal struct with the given body in the provided context.
Definition: LLVMTypes.cpp:426
static LLVMPointerType getChecked(function_ref< InFlightDiagnostic()> emitError, Type pointee, unsigned addressSpace=0)
Definition: LLVMTypes.cpp:204
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:307
static LLVMArrayType get(Type elementType, unsigned numElements)
Gets or creates an instance of LLVM dialect array type containing numElements of elementType, in the same context as elementType.
Definition: LLVMTypes.cpp:39
Type getVectorType(Type elementType, unsigned numElements, bool isScalable=false)
Creates an LLVM dialect-compatible vector type with the given element type and length.
Definition: LLVMTypes.cpp:922
Type replaceImmediateSubElements(ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Definition: LLVMTypes.cpp:696
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
Definition: LogicalResult.h:72
ArrayRef< Type > getReturnTypes() const
Returns the result type of the function as an ArrayRef, enabling better integration with generic MLIR...
Definition: LLVMTypes.cpp:136
LLVM dialect function type.
Definition: LLVMTypes.h:130
static unsigned calculateStructAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params, LLVMStructType type, StructDLEntryPos pos)
Definition: LLVMTypes.cpp:529
static LLVMStructType getIdentifiedChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, StringRef name)
Definition: LLVMTypes.cpp:403
bool isOpaque() const
Returns true if this type is the opaque pointer type, i.e., it has no pointed-to type.
Definition: LLVMTypes.cpp:218
unsigned getTypeSizeInBits(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Hooks for DataLayoutTypeInterface.
Definition: LLVMTypes.cpp:484
bool areCompatible(DataLayoutEntryListRef oldLayout, DataLayoutEntryListRef newLayout) const
Definition: LLVMTypes.cpp:314
static bool isValidResultType(Type type)
Checks if the given type can be used as a result in a function type.
Definition: LLVMTypes.cpp:108
static LLVMArrayType getChecked(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned numElements)
Definition: LLVMTypes.cpp:45
unsigned getAddressSpace() const
Returns the address space of the pointer.
Definition: LLVMTypes.cpp:220
static LLVMFunctionType get(Type result, ArrayRef< Type > arguments, bool isVarArg=false)
Gets or creates an instance of LLVM dialect function in the same context as the result type...
Definition: LLVMTypes.cpp:112
bool isOpaque()
Checks if a struct is opaque.
Definition: LLVMTypes.cpp:457
unsigned getMinNumElements() const
Returns the scaling factor of the number of elements in the vector.
Definition: LLVMTypes.cpp:723
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned minNumElements)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:735
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, StringRef, bool)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:468
LLVMFunctionType clone(TypeRange inputs, TypeRange results) const
Returns a clone of this function type with the given argument and result types.
Definition: LLVMTypes.cpp:127
static ConcreteT get(MLIRContext *ctx, Args... args)
Get or create a new ConcreteT instance within the ctx.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:48
static LLVMScalableVectorType getChecked(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned minNumElements)
Definition: LLVMTypes.cpp:712
unsigned getTypeSize(Type t) const
Returns the size of the given type in the current scope.
Type getElementType() const
Returns the element type of the vector.
Definition: LLVMTypes.cpp:719
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Type result, ArrayRef< Type > arguments, bool)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:155
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
unsigned getPreferredAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:84
void walkImmediateSubElements(function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Definition: LLVMTypes.cpp:741
constexpr static const unsigned kDefaultPointerAlignment
Definition: LLVMTypes.cpp:233
bool isCompatibleType(Type type)
Returns true if the given type is compatible with the LLVM dialect.
Definition: LLVMTypes.cpp:851
bool isVarArg() const
Returns whether the function is variadic.
Definition: LLVMTypes.cpp:148
unsigned getTypeSize(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:71
bool isInitialized()
Checks if a struct is initialized.
Definition: LLVMTypes.cpp:461
void walkImmediateSubElements(function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Definition: LLVMTypes.cpp:167
unsigned getPreferredAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:561
Common storage used for LLVM dialect types that need an element type and a number: arrays...
Definition: TypeDetail.h:414
U dyn_cast() const
Definition: Types.h:268
void walkImmediateSubElements(function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Definition: LLVMTypes.cpp:378
Attributes are known-constant values of operations.
Definition: Attributes.h:25
Type getElementType() const
Returns the element type of the array.
Definition: LLVMTypes.cpp:52
bool areCompatible(DataLayoutEntryListRef oldLayout, DataLayoutEntryListRef newLayout) const
Definition: LLVMTypes.cpp:572
unsigned getTypeABIAlignment(Type t) const
Returns the required alignment of the given type in the current scope.
LogicalResult verifyEntries(DataLayoutEntryListRef entries, Location loc) const
Definition: LLVMTypes.cpp:352
Type getElementType() const
Returns the element type of the vector.
Definition: LLVMTypes.cpp:671
Type getParamType(unsigned i)
Returns i-th argument of the function. Asserts on out-of-bounds.
Definition: LLVMTypes.cpp:144
static Optional< unsigned > getPointerDataLayoutEntry(DataLayoutEntryListRef params, LLVMPointerType type, PtrDLEntryPos pos)
Returns the part of the data layout entry that corresponds to pos for the given type by interpreting ...
Definition: LLVMTypes.cpp:249
unsigned getNumParams()
Returns the number of arguments to the function.
Definition: LLVMTypes.cpp:140
static LLVMPointerType get(MLIRContext *context, unsigned addressSpace=0)
Gets or creates an instance of LLVM dialect pointer type pointing to an object of pointee type in the...
Definition: LLVMTypes.cpp:198
This class provides an abstraction over the various different ranges of value types.
Definition: TypeRange.h:32
unsigned getABIAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:554
unsigned getTypeSizeInBits(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Hooks for DataLayoutTypeInterface.
Definition: LLVMTypes.cpp:66
void walkImmediateSubElements(function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Definition: LLVMTypes.cpp:89
ArrayRef< Type > getBody() const
Returns the list of element types contained in a non-opaque struct.
Definition: LLVMTypes.cpp:463
static LLVMStructType getIdentified(MLIRContext *context, StringRef name)
Gets or creates an identified struct with the given name in the provided context. ...
Definition: LLVMTypes.cpp:398
static bool isValidElementType(Type type)
Checks if the given type can be contained in a structure type.
Definition: LLVMTypes.cpp:393
static LLVMFunctionType getChecked(function_ref< InFlightDiagnostic()> emitError, Type result, ArrayRef< Type > arguments, bool isVarArg=false)
Definition: LLVMTypes.cpp:119
static bool isValidElementType(Type type)
Checks if the given type can be used in a vector type.
Definition: LLVMTypes.cpp:679
static LogicalResult verifyVectorConstructionInvariants(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned numElements)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:646
unsigned getPreferredAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:303
Type getScalableVectorType(Type elementType, unsigned numElements)
Creates an LLVM dialect-compatible type with the given element type and length.
Definition: LLVMTypes.cpp:948
unsigned getABIAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:78
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition: Types.cpp:19
ArrayRef< Type > getParams() const
Returns a list of argument types of the function.
Definition: LLVMTypes.cpp:150
unsigned getNumElements() const
Returns the number of elements in the fixed vector.
Definition: LLVMTypes.cpp:675
unsigned getTypeSizeInBits(Type t) const
Returns the size in bits of the given type in the current scope.
LLVM dialect array type.
Definition: LLVMTypes.h:75
static LLVMFixedVectorType getChecked(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned numElements)
Definition: LLVMTypes.cpp:664
Optional< unsigned > extractPointerSpecValue(Attribute attr, PtrDLEntryPos pos)
Returns the value that corresponds to named position pos from the data layout entry attr assuming it&#39;...
Definition: LLVMTypes.cpp:235
static Optional< unsigned > getStructDataLayoutEntry(DataLayoutEntryListRef params, LLVMStructType type, StructDLEntryPos pos)
Definition: LLVMTypes.cpp:511
unsigned getNumElements() const
Returns the number of elements in the array type.
Definition: LLVMTypes.cpp:54
static LLVMFixedVectorType get(Type elementType, unsigned numElements)
Gets or creates a fixed vector type containing numElements of elementType in the same context as elem...
Definition: LLVMTypes.cpp:657
Type replaceImmediateSubElements(ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Definition: LLVMTypes.cpp:632
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
bool isPacked() const
Checks if a struct is packed.
Definition: LLVMTypes.cpp:455
static bool isValidElementType(Type type)
Checks if the given type can be used inside an array type.
Definition: LLVMTypes.cpp:34
unsigned getTypePreferredAlignment(Type t) const
Returns the preferred of the given type in the current scope.
static bool isValidElementType(Type type)
Checks if the given type can have a pointer type pointing to it.
Definition: LLVMTypes.cpp:183
LogicalResult mutate(Args &&...args)
Mutate the current storage instance.
LLVM dialect structure type representing a collection of different-typed elements manipulated togethe...
Definition: LLVMTypes.h:283
ImplType * getImpl() const
Utility for easy access to the storage instance.
bool isCompatibleVectorType(Type type)
Returns true if the given type is a vector type compatible with the LLVM dialect. ...
Definition: LLVMTypes.cpp:869
static VectorType vectorType(CodeGen &codegen, Type etp)
Constructs vector type.
PtrDLEntryPos
The positions of different values in the data layout entry for pointers.
Definition: LLVMTypes.h:539
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:56
Type replaceImmediateSubElements(ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Definition: LLVMTypes.cpp:174
bool isIdentified() const
Checks if a struct is identified.
Definition: LLVMTypes.cpp:456
static unsigned extractStructSpecValue(Attribute attr, StructDLEntryPos pos)
Definition: LLVMTypes.cpp:567
LLVM dialect pointer type.
Definition: LLVMTypes.h:194
llvm::TypeSize getPrimitiveTypeSizeInBits(Type type)
Returns the size of the given primitive LLVM dialect-compatible type (including vectors) in bits...
Definition: LLVMTypes.cpp:960
Type getReturnType() const
Returns the result type of the function.
Definition: LLVMTypes.cpp:133
bool isScalableVectorType(Type vectorType)
Returns whether a vector type is scalable or not.
Definition: LLVMTypes.cpp:912
unsigned getTypeSizeInBits(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Hooks for DataLayoutTypeInterface.
Definition: LLVMTypes.cpp:278
static LLVMStructType getOpaqueChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, StringRef name)
Definition: LLVMTypes.cpp:443
StructDLEntryPos
Definition: LLVMTypes.cpp:507
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned numElements)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:684
static LLVMScalableVectorType get(Type elementType, unsigned minNumElements)
Gets or creates a scalable vector type containing a non-zero multiple of minNumElements of elementTyp...
Definition: LLVMTypes.cpp:705
unsigned getABIAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:291
LogicalResult setBody(ArrayRef< Type > types, bool isPacked)
Set the body of an identified struct.
Definition: LLVMTypes.cpp:448
bool isa() const
Definition: Types.h:258
static bool isValidElementType(Type type)
Checks if the given type can be used in a vector type.
Definition: LLVMTypes.cpp:727
LLVM dialect fixed vector type, represents a sequence of elements of known length that can be process...
Definition: LLVMTypes.h:394
Type replaceImmediateSubElements(ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Definition: LLVMTypes.cpp:384
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned numElements)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:59
Dialect * getLoadedDialect(StringRef name)
Get a registered IR dialect with the given namespace.
constexpr static const unsigned kDefaultPointerSizeBits
Definition: LLVMTypes.cpp:232
LogicalResult verifyEntries(DataLayoutEntryListRef entries, Location loc) const
Definition: LLVMTypes.cpp:595
Type replaceImmediateSubElements(ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Definition: LLVMTypes.cpp:747
Type getVectorElementType(Type type)
Returns the element type of any vector type compatible with the LLVM dialect.
Definition: LLVMTypes.cpp:885
Type getElementType() const
Returns the pointed-to type. It may be null if the pointer is opaque.
Definition: LLVMTypes.cpp:216
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
An attribute that represents a reference to a dense integer vector or tensor object.
U cast() const
Definition: Types.h:278
The main mechanism for performing data layout queries.
static LLVMStructType getLiteralChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, ArrayRef< Type > types, bool isPacked=false)
Definition: LLVMTypes.cpp:432
constexpr static const unsigned kBitsInByte
Definition: LLVMTypes.cpp:28
static ConcreteT getChecked(const Location &loc, Args... args)
Get or create a new ConcreteT instance within the ctx, defined at the given, potentially unknown...