MLIR  14.0.0git
LLVMTypes.cpp
Go to the documentation of this file.
1 //===- LLVMTypes.cpp - MLIR LLVM Dialect types ----------------------------===//
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 types for the LLVM dialect in MLIR. These MLIR types
10 // correspond to the LLVM IR type system.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "TypeDetail.h"
15 
18 #include "mlir/IR/BuiltinTypes.h"
20 #include "mlir/IR/TypeSupport.h"
21 
22 #include "llvm/ADT/TypeSwitch.h"
23 #include "llvm/Support/TypeSize.h"
24 
25 using namespace mlir;
26 using namespace mlir::LLVM;
27 
28 //===----------------------------------------------------------------------===//
29 // Array type.
30 //===----------------------------------------------------------------------===//
31 
33  return !type.isa<LLVMVoidType, LLVMLabelType, LLVMMetadataType,
34  LLVMFunctionType, LLVMTokenType, LLVMScalableVectorType>();
35 }
36 
37 LLVMArrayType LLVMArrayType::get(Type elementType, unsigned numElements) {
38  assert(elementType && "expected non-null subtype");
39  return Base::get(elementType.getContext(), elementType, numElements);
40 }
41 
44  Type elementType, unsigned numElements) {
45  assert(elementType && "expected non-null subtype");
46  return Base::getChecked(emitError, elementType.getContext(), elementType,
47  numElements);
48 }
49 
50 Type LLVMArrayType::getElementType() { return getImpl()->elementType; }
51 
52 unsigned LLVMArrayType::getNumElements() { return getImpl()->numElements; }
53 
56  Type elementType, unsigned numElements) {
57  if (!isValidElementType(elementType))
58  return emitError() << "invalid array element type: " << elementType;
59  return success();
60 }
61 
62 //===----------------------------------------------------------------------===//
63 // Function type.
64 //===----------------------------------------------------------------------===//
65 
67  return !type.isa<LLVMVoidType, LLVMFunctionType>();
68 }
69 
71  return !type.isa<LLVMFunctionType, LLVMMetadataType, LLVMLabelType>();
72 }
73 
75  bool isVarArg) {
76  assert(result && "expected non-null result");
77  return Base::get(result.getContext(), result, arguments, isVarArg);
78 }
79 
82  Type result, ArrayRef<Type> arguments,
83  bool isVarArg) {
84  assert(result && "expected non-null result");
85  return Base::getChecked(emitError, result.getContext(), result, arguments,
86  isVarArg);
87 }
88 
89 Type LLVMFunctionType::getReturnType() { return getImpl()->getReturnType(); }
90 
92  return getImpl()->getArgumentTypes().size();
93 }
94 
96  return getImpl()->getArgumentTypes()[i];
97 }
98 
99 bool LLVMFunctionType::isVarArg() { return getImpl()->isVariadic(); }
100 
102  return getImpl()->getArgumentTypes();
103 }
104 
107  Type result, ArrayRef<Type> arguments, bool) {
108  if (!isValidResultType(result))
109  return emitError() << "invalid function result type: " << result;
110 
111  for (Type arg : arguments)
112  if (!isValidArgumentType(arg))
113  return emitError() << "invalid function argument type: " << arg;
114 
115  return success();
116 }
117 
118 //===----------------------------------------------------------------------===//
119 // Pointer type.
120 //===----------------------------------------------------------------------===//
121 
123  return isCompatibleType(type) ? !type.isa<LLVMVoidType, LLVMTokenType,
124  LLVMMetadataType, LLVMLabelType>()
125  : type.isa<PointerElementTypeInterface>();
126 }
127 
128 LLVMPointerType LLVMPointerType::get(Type pointee, unsigned addressSpace) {
129  assert(pointee && "expected non-null subtype");
130  return Base::get(pointee.getContext(), pointee, addressSpace);
131 }
132 
135  Type pointee, unsigned addressSpace) {
136  return Base::getChecked(emitError, pointee.getContext(), pointee,
137  addressSpace);
138 }
139 
140 Type LLVMPointerType::getElementType() const { return getImpl()->pointeeType; }
141 
143  return getImpl()->addressSpace;
144 }
145 
148  Type pointee, unsigned) {
149  if (!isValidElementType(pointee))
150  return emitError() << "invalid pointer element type: " << pointee;
151  return success();
152 }
153 
154 namespace {
155 /// The positions of different values in the data layout entry.
156 enum class DLEntryPos { Size = 0, Abi = 1, Preferred = 2, Address = 3 };
157 } // namespace
158 
159 constexpr const static unsigned kDefaultPointerSizeBits = 64;
160 constexpr const static unsigned kDefaultPointerAlignment = 8;
161 constexpr const static unsigned kBitsInByte = 8;
162 
163 /// Returns the value that corresponds to named position `pos` from the
164 /// attribute `attr` assuming it's a dense integer elements attribute.
165 static unsigned extractPointerSpecValue(Attribute attr, DLEntryPos pos) {
166  return attr.cast<DenseIntElementsAttr>()
167  .getValues<unsigned>()[static_cast<unsigned>(pos)];
168 }
169 
170 /// Returns the part of the data layout entry that corresponds to `pos` for the
171 /// given `type` by interpreting the list of entries `params`. For the pointer
172 /// type in the default address space, returns the default value if the entries
173 /// do not provide a custom one, for other address spaces returns None.
174 static Optional<unsigned>
176  DLEntryPos pos) {
177  // First, look for the entry for the pointer in the current address space.
178  Attribute currentEntry;
179  for (DataLayoutEntryInterface entry : params) {
180  if (!entry.isTypeEntry())
181  continue;
182  if (entry.getKey().get<Type>().cast<LLVMPointerType>().getAddressSpace() ==
183  type.getAddressSpace()) {
184  currentEntry = entry.getValue();
185  break;
186  }
187  }
188  if (currentEntry) {
189  return extractPointerSpecValue(currentEntry, pos) /
190  (pos == DLEntryPos::Size ? 1 : kBitsInByte);
191  }
192 
193  // If not found, and this is the pointer to the default memory space, assume
194  // 64-bit pointers.
195  if (type.getAddressSpace() == 0) {
196  return pos == DLEntryPos::Size ? kDefaultPointerSizeBits
198  }
199 
200  return llvm::None;
201 }
202 
203 unsigned
205  DataLayoutEntryListRef params) const {
206  if (Optional<unsigned> size =
207  getPointerDataLayoutEntry(params, *this, DLEntryPos::Size))
208  return *size;
209 
210  // For other memory spaces, use the size of the pointer to the default memory
211  // space.
212  return dataLayout.getTypeSizeInBits(get(getElementType()));
213 }
214 
215 unsigned LLVMPointerType::getABIAlignment(const DataLayout &dataLayout,
216  DataLayoutEntryListRef params) const {
217  if (Optional<unsigned> alignment =
218  getPointerDataLayoutEntry(params, *this, DLEntryPos::Abi))
219  return *alignment;
220 
221  return dataLayout.getTypeABIAlignment(get(getElementType()));
222 }
223 
224 unsigned
226  DataLayoutEntryListRef params) const {
227  if (Optional<unsigned> alignment =
228  getPointerDataLayoutEntry(params, *this, DLEntryPos::Preferred))
229  return *alignment;
230 
231  return dataLayout.getTypePreferredAlignment(get(getElementType()));
232 }
233 
235  DataLayoutEntryListRef newLayout) const {
236  for (DataLayoutEntryInterface newEntry : newLayout) {
237  if (!newEntry.isTypeEntry())
238  continue;
239  unsigned size = kDefaultPointerSizeBits;
240  unsigned abi = kDefaultPointerAlignment;
241  auto newType = newEntry.getKey().get<Type>().cast<LLVMPointerType>();
242  auto it = llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
243  if (auto type = entry.getKey().dyn_cast<Type>()) {
244  return type.cast<LLVMPointerType>().getAddressSpace() ==
245  newType.getAddressSpace();
246  }
247  return false;
248  });
249  if (it == oldLayout.end()) {
250  llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
251  if (auto type = entry.getKey().dyn_cast<Type>()) {
252  return type.cast<LLVMPointerType>().getAddressSpace() == 0;
253  }
254  return false;
255  });
256  }
257  if (it != oldLayout.end()) {
258  size = extractPointerSpecValue(*it, DLEntryPos::Size);
259  abi = extractPointerSpecValue(*it, DLEntryPos::Abi);
260  }
261 
262  Attribute newSpec = newEntry.getValue().cast<DenseIntElementsAttr>();
263  unsigned newSize = extractPointerSpecValue(newSpec, DLEntryPos::Size);
264  unsigned newAbi = extractPointerSpecValue(newSpec, DLEntryPos::Abi);
265  if (size != newSize || abi < newAbi || abi % newAbi != 0)
266  return false;
267  }
268  return true;
269 }
270 
272  Location loc) const {
273  for (DataLayoutEntryInterface entry : entries) {
274  if (!entry.isTypeEntry())
275  continue;
276  auto key = entry.getKey().get<Type>().cast<LLVMPointerType>();
277  auto values = entry.getValue().dyn_cast<DenseIntElementsAttr>();
278  if (!values || (values.size() != 3 && values.size() != 4)) {
279  return emitError(loc)
280  << "expected layout attribute for " << entry.getKey().get<Type>()
281  << " to be a dense integer elements attribute with 3 or 4 "
282  "elements";
283  }
284  if (!key.getElementType().isInteger(8)) {
285  return emitError(loc) << "unexpected layout attribute for pointer to "
286  << key.getElementType();
287  }
288  if (extractPointerSpecValue(values, DLEntryPos::Abi) >
289  extractPointerSpecValue(values, DLEntryPos::Preferred)) {
290  return emitError(loc) << "preferred alignment is expected to be at least "
291  "as large as ABI alignment";
292  }
293  }
294  return success();
295 }
296 
297 //===----------------------------------------------------------------------===//
298 // Struct type.
299 //===----------------------------------------------------------------------===//
300 
302  return !type.isa<LLVMVoidType, LLVMLabelType, LLVMMetadataType,
303  LLVMFunctionType, LLVMTokenType, LLVMScalableVectorType>();
304 }
305 
307  StringRef name) {
308  return Base::get(context, name, /*opaque=*/false);
309 }
310 
313  StringRef name) {
314  return Base::getChecked(emitError, context, name, /*opaque=*/false);
315 }
316 
318  StringRef name,
319  ArrayRef<Type> elements,
320  bool isPacked) {
321  std::string stringName = name.str();
322  unsigned counter = 0;
323  do {
324  auto type = LLVMStructType::getIdentified(context, stringName);
325  if (type.isInitialized() || failed(type.setBody(elements, isPacked))) {
326  counter += 1;
327  stringName = (Twine(name) + "." + std::to_string(counter)).str();
328  continue;
329  }
330  return type;
331  } while (true);
332 }
333 
335  ArrayRef<Type> types, bool isPacked) {
336  return Base::get(context, types, isPacked);
337 }
338 
341  MLIRContext *context, ArrayRef<Type> types,
342  bool isPacked) {
343  return Base::getChecked(emitError, context, types, isPacked);
344 }
345 
347  return Base::get(context, name, /*opaque=*/true);
348 }
349 
352  MLIRContext *context, StringRef name) {
353  return Base::getChecked(emitError, context, name, /*opaque=*/true);
354 }
355 
357  assert(isIdentified() && "can only set bodies of identified structs");
358  assert(llvm::all_of(types, LLVMStructType::isValidElementType) &&
359  "expected valid body types");
360  return Base::mutate(types, isPacked);
361 }
362 
363 bool LLVMStructType::isPacked() { return getImpl()->isPacked(); }
364 bool LLVMStructType::isIdentified() { return getImpl()->isIdentified(); }
366  return getImpl()->isIdentified() &&
367  (getImpl()->isOpaque() || !getImpl()->isInitialized());
368 }
369 bool LLVMStructType::isInitialized() { return getImpl()->isInitialized(); }
370 StringRef LLVMStructType::getName() { return getImpl()->getIdentifier(); }
372  return isIdentified() ? getImpl()->getIdentifiedStructBody()
373  : getImpl()->getTypeList();
374 }
375 
377  StringRef, bool) {
378  return success();
379 }
380 
383  ArrayRef<Type> types, bool) {
384  for (Type t : types)
385  if (!isValidElementType(t))
386  return emitError() << "invalid LLVM structure element type: " << t;
387 
388  return success();
389 }
390 
391 //===----------------------------------------------------------------------===//
392 // Vector types.
393 //===----------------------------------------------------------------------===//
394 
395 /// Verifies that the type about to be constructed is well-formed.
396 template <typename VecTy>
397 static LogicalResult
399  Type elementType, unsigned numElements) {
400  if (numElements == 0)
401  return emitError() << "the number of vector elements must be positive";
402 
403  if (!VecTy::isValidElementType(elementType))
404  return emitError() << "invalid vector element type";
405 
406  return success();
407 }
408 
410  unsigned numElements) {
411  assert(elementType && "expected non-null subtype");
412  return Base::get(elementType.getContext(), elementType, numElements);
413 }
414 
417  Type elementType, unsigned numElements) {
418  assert(elementType && "expected non-null subtype");
419  return Base::getChecked(emitError, elementType.getContext(), elementType,
420  numElements);
421 }
422 
424  return static_cast<detail::LLVMTypeAndSizeStorage *>(impl)->elementType;
425 }
426 
428  return getImpl()->numElements;
429 }
430 
432  return type.isa<LLVMPointerType, LLVMPPCFP128Type>();
433 }
434 
437  Type elementType, unsigned numElements) {
438  return verifyVectorConstructionInvariants<LLVMFixedVectorType>(
439  emitError, elementType, numElements);
440 }
441 
442 //===----------------------------------------------------------------------===//
443 // LLVMScalableVectorType.
444 //===----------------------------------------------------------------------===//
445 
447  unsigned minNumElements) {
448  assert(elementType && "expected non-null subtype");
449  return Base::get(elementType.getContext(), elementType, minNumElements);
450 }
451 
454  Type elementType, unsigned minNumElements) {
455  assert(elementType && "expected non-null subtype");
456  return Base::getChecked(emitError, elementType.getContext(), elementType,
457  minNumElements);
458 }
459 
461  return static_cast<detail::LLVMTypeAndSizeStorage *>(impl)->elementType;
462 }
463 
465  return getImpl()->numElements;
466 }
467 
469  if (auto intType = type.dyn_cast<IntegerType>())
470  return intType.isSignless();
471 
472  return isCompatibleFloatingPointType(type) || type.isa<LLVMPointerType>();
473 }
474 
477  Type elementType, unsigned numElements) {
478  return verifyVectorConstructionInvariants<LLVMScalableVectorType>(
479  emitError, elementType, numElements);
480 }
481 
482 //===----------------------------------------------------------------------===//
483 // Utility functions.
484 //===----------------------------------------------------------------------===//
485 
487  // Only signless integers are compatible.
488  if (auto intType = type.dyn_cast<IntegerType>())
489  return intType.isSignless();
490 
491  // 1D vector types are compatible if their element types are.
492  if (auto vecType = type.dyn_cast<VectorType>())
493  return vecType.getRank() == 1 && isCompatibleType(vecType.getElementType());
494 
495  // clang-format off
496  return type.isa<
497  BFloat16Type,
498  Float16Type,
499  Float32Type,
500  Float64Type,
501  Float80Type,
502  Float128Type,
505  LLVMLabelType,
506  LLVMMetadataType,
507  LLVMPPCFP128Type,
510  LLVMTokenType,
513  LLVMVoidType,
514  LLVMX86MMXType
515  >();
516  // clang-format on
517 }
518 
520  return type.isa<BFloat16Type, Float16Type, Float32Type, Float64Type,
521  Float80Type, Float128Type, LLVMPPCFP128Type>();
522 }
523 
526  return true;
527 
528  if (auto vecType = type.dyn_cast<VectorType>()) {
529  if (vecType.getRank() != 1)
530  return false;
531  Type elementType = vecType.getElementType();
532  if (auto intType = elementType.dyn_cast<IntegerType>())
533  return intType.isSignless();
534  return elementType.isa<BFloat16Type, Float16Type, Float32Type, Float64Type,
535  Float80Type, Float128Type>();
536  }
537  return false;
538 }
539 
541  return llvm::TypeSwitch<Type, Type>(type)
542  .Case<LLVMFixedVectorType, LLVMScalableVectorType, VectorType>(
543  [](auto ty) { return ty.getElementType(); })
544  .Default([](Type) -> Type {
545  llvm_unreachable("incompatible with LLVM vector type");
546  });
547 }
548 
549 llvm::ElementCount mlir::LLVM::getVectorNumElements(Type type) {
551  .Case<LLVMFixedVectorType, VectorType>([](auto ty) {
552  return llvm::ElementCount::getFixed(ty.getNumElements());
553  })
554  .Case([](LLVMScalableVectorType ty) {
555  return llvm::ElementCount::getScalable(ty.getMinNumElements());
556  })
557  .Default([](Type) -> llvm::ElementCount {
558  llvm_unreachable("incompatible with LLVM vector type");
559  });
560 }
561 
562 Type mlir::LLVM::getFixedVectorType(Type elementType, unsigned numElements) {
563  bool useLLVM = LLVMFixedVectorType::isValidElementType(elementType);
564  bool useBuiltIn = VectorType::isValidElementType(elementType);
565  (void)useBuiltIn;
566  assert((useLLVM ^ useBuiltIn) && "expected LLVM-compatible fixed-vector type "
567  "to be either builtin or LLVM dialect type");
568  if (useLLVM)
569  return LLVMFixedVectorType::get(elementType, numElements);
570  return VectorType::get(numElements, elementType);
571 }
572 
574  assert(isCompatibleType(type) &&
575  "expected a type compatible with the LLVM dialect");
576 
578  .Case<BFloat16Type, Float16Type>(
579  [](Type) { return llvm::TypeSize::Fixed(16); })
580  .Case<Float32Type>([](Type) { return llvm::TypeSize::Fixed(32); })
581  .Case<Float64Type, LLVMX86MMXType>(
582  [](Type) { return llvm::TypeSize::Fixed(64); })
583  .Case<Float80Type>([](Type) { return llvm::TypeSize::Fixed(80); })
584  .Case<Float128Type>([](Type) { return llvm::TypeSize::Fixed(128); })
585  .Case<IntegerType>([](IntegerType intTy) {
586  return llvm::TypeSize::Fixed(intTy.getWidth());
587  })
588  .Case<LLVMPPCFP128Type>([](Type) { return llvm::TypeSize::Fixed(128); })
589  .Case<LLVMFixedVectorType>([](LLVMFixedVectorType t) {
590  llvm::TypeSize elementSize =
592  return llvm::TypeSize(elementSize.getFixedSize() * t.getNumElements(),
593  elementSize.isScalable());
594  })
595  .Case<VectorType>([](VectorType t) {
596  assert(isCompatibleVectorType(t) &&
597  "unexpected incompatible with LLVM vector type");
598  llvm::TypeSize elementSize =
599  getPrimitiveTypeSizeInBits(t.getElementType());
600  return llvm::TypeSize(elementSize.getFixedSize() * t.getNumElements(),
601  elementSize.isScalable());
602  })
603  .Default([](Type ty) {
604  assert((ty.isa<LLVMVoidType, LLVMLabelType, LLVMMetadataType,
605  LLVMTokenType, LLVMStructType, LLVMArrayType,
607  "unexpected missing support for primitive type");
608  return llvm::TypeSize::Fixed(0);
609  });
610 }
611 
612 #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:66
bool isCompatibleFloatingPointType(Type type)
Returns true if the given type is a floating-point type compatible with the LLVM dialect.
Definition: LLVMTypes.cpp:519
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Type pointee, unsigned)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:147
llvm::ElementCount getVectorNumElements(Type type)
Returns the element count of any LLVM-compatible vector type.
Definition: LLVMTypes.cpp:549
U cast() const
Definition: Attributes.h:126
Type getFixedVectorType(Type elementType, unsigned numElements)
Creates an LLVM dialect-compatible type with the given element type and length.
Definition: LLVMTypes.cpp:562
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:317
LLVM dialect scalable vector type, represents a sequence of elements of unknown length that is known ...
Definition: LLVMTypes.h:382
unsigned getMinNumElements()
Returns the scaling factor of the number of elements in the vector.
Definition: LLVMTypes.cpp:464
StringRef getName()
Returns the name of an identified struct.
Definition: LLVMTypes.cpp:370
static LLVMStructType getOpaque(StringRef name, MLIRContext *context)
Gets or creates an intentionally-opaque identified struct.
Definition: LLVMTypes.cpp:346
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:334
static LLVMPointerType getChecked(function_ref< InFlightDiagnostic()> emitError, Type pointee, unsigned addressSpace=0)
Definition: LLVMTypes.cpp:134
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:299
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:37
ArrayRef< Type > getParams()
Returns a list of argument types of the function.
Definition: LLVMTypes.cpp:101
Type getElementType()
Returns the element type of the vector.
Definition: LLVMTypes.cpp:423
bool isIdentified()
Checks if a struct is identified.
Definition: LLVMTypes.cpp:364
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
Definition: LogicalResult.h:72
LLVM dialect function type.
Definition: LLVMTypes.h:108
static LLVMStructType getIdentifiedChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, StringRef name)
Definition: LLVMTypes.cpp:311
bool areCompatible(DataLayoutEntryListRef oldLayout, DataLayoutEntryListRef newLayout) const
Definition: LLVMTypes.cpp:234
static bool isValidResultType(Type type)
Checks if the given type can be used as a result in a function type.
Definition: LLVMTypes.cpp:70
static LLVMArrayType getChecked(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned numElements)
Definition: LLVMTypes.cpp:43
unsigned getAddressSpace() const
Returns the address space of the pointer.
Definition: LLVMTypes.cpp:142
static LLVMPointerType get(Type pointee, 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:128
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:74
bool isOpaque()
Checks if a struct is opaque.
Definition: LLVMTypes.cpp:365
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:476
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, StringRef, bool)
Verifies that the type about to be constructed is well-formed.
Definition: LLVMTypes.cpp:376
static Optional< unsigned > getPointerDataLayoutEntry(DataLayoutEntryListRef params, LLVMPointerType type, DLEntryPos pos)
Returns the part of the data layout entry that corresponds to pos for the given type by interpreting ...
Definition: LLVMTypes.cpp:175
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:453
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:106
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
constexpr static const unsigned kDefaultPointerAlignment
Definition: LLVMTypes.cpp:160
bool isCompatibleType(Type type)
Returns true if the given type is compatible with the LLVM dialect.
Definition: LLVMTypes.cpp:486
bool isInitialized()
Checks if a struct is initialized.
Definition: LLVMTypes.cpp:369
unsigned getNumElements()
Returns the number of elements in the array type.
Definition: LLVMTypes.cpp:52
Common storage used for LLVM dialect types that need an element type and a number: arrays...
Definition: TypeDetail.h:409
U dyn_cast() const
Definition: Types.h:244
Attributes are known-constant values of operations.
Definition: Attributes.h:27
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:271
Type getParamType(unsigned i)
Returns i-th argument of the function. Asserts on out-of-bounds.
Definition: LLVMTypes.cpp:95
Type getReturnType()
Returns the result type of the function.
Definition: LLVMTypes.cpp:89
static unsigned extractPointerSpecValue(Attribute attr, DLEntryPos pos)
Returns the value that corresponds to named position pos from the attribute attr assuming it&#39;s a dens...
Definition: LLVMTypes.cpp:165
unsigned getNumParams()
Returns the number of arguments to the function.
Definition: LLVMTypes.cpp:91
unsigned getNumElements()
Returns the number of elements in the fixed vector.
Definition: LLVMTypes.cpp:427
static LLVMStructType getIdentified(MLIRContext *context, StringRef name)
Gets or creates an identified struct with the given name in the provided context. ...
Definition: LLVMTypes.cpp:306
static bool isValidElementType(Type type)
Checks if the given type can be contained in a structure type.
Definition: LLVMTypes.cpp:301
static LLVMFunctionType getChecked(function_ref< InFlightDiagnostic()> emitError, Type result, ArrayRef< Type > arguments, bool isVarArg=false)
Definition: LLVMTypes.cpp:81
static bool isValidElementType(Type type)
Checks if the given type can be used in a vector type.
Definition: LLVMTypes.cpp:431
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:398
unsigned getPreferredAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:225
Type getElementType()
Returns the element type of the vector.
Definition: LLVMTypes.cpp:460
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:72
bool isVarArg()
Returns whether the function is variadic.
Definition: LLVMTypes.cpp:99
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition: Types.cpp:19
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:74
static LLVMFixedVectorType getChecked(function_ref< InFlightDiagnostic()> emitError, Type elementType, unsigned numElements)
Definition: LLVMTypes.cpp:416
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:409
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
Type getElementType()
Returns the element type of the array.
Definition: LLVMTypes.cpp:50
static bool isValidElementType(Type type)
Checks if the given type can be used inside an array type.
Definition: LLVMTypes.cpp:32
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:122
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:229
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:524
bool isPacked()
Checks if a struct is packed.
Definition: LLVMTypes.cpp:363
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:55
LLVM dialect pointer type.
Definition: LLVMTypes.h:158
llvm::TypeSize getPrimitiveTypeSizeInBits(Type type)
Returns the size of the given primitive LLVM dialect-compatible type (including vectors) in bits...
Definition: LLVMTypes.cpp:573
unsigned getTypeSizeInBits(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Hooks for DataLayoutTypeInterface.
Definition: LLVMTypes.cpp:204
static LLVMStructType getOpaqueChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, StringRef name)
Definition: LLVMTypes.cpp:351
DLEntryPos
The positions of different values in the data layout entry.
Definition: LLVMTypes.cpp:156
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:436
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:446
unsigned getABIAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const
Definition: LLVMTypes.cpp:215
LogicalResult setBody(ArrayRef< Type > types, bool isPacked)
Set the body of an identified struct.
Definition: LLVMTypes.cpp:356
ArrayRef< Type > getBody()
Returns the list of element types contained in a non-opaque struct.
Definition: LLVMTypes.cpp:371
bool isa() const
Definition: Types.h:234
static bool isValidElementType(Type type)
Checks if the given type can be used in a vector type.
Definition: LLVMTypes.cpp:468
LLVM dialect fixed vector type, represents a sequence of elements of known length that can be process...
Definition: LLVMTypes.h:344
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:55
constexpr static const unsigned kDefaultPointerSizeBits
Definition: LLVMTypes.cpp:159
Type getVectorElementType(Type type)
Returns the element type of any vector type compatible with the LLVM dialect.
Definition: LLVMTypes.cpp:540
Type getElementType() const
Returns the pointed-to type.
Definition: LLVMTypes.cpp:140
An attribute that represents a reference to a dense integer vector or tensor object.
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:340
constexpr static const unsigned kBitsInByte
Definition: LLVMTypes.cpp:161
static ConcreteT getChecked(const Location &loc, Args... args)
Get or create a new ConcreteT instance within the ctx, defined at the given, potentially unknown...