MLIR 22.0.0git
LLVMTypes.h
Go to the documentation of this file.
1//===- LLVMTypes.h - MLIR LLVM dialect types --------------------*- C++ -*-===//
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 defines the types for the LLVM dialect in MLIR. These MLIR types
10// correspond to the LLVM IR type system.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_DIALECT_LLVMIR_LLVMTYPES_H_
15#define MLIR_DIALECT_LLVMIR_LLVMTYPES_H_
16
17#include "mlir/IR/Types.h"
20#include <optional>
21
22namespace llvm {
23class ElementCount;
24class TypeSize;
25} // namespace llvm
26
27namespace mlir {
28
29class AsmParser;
30class AsmPrinter;
31class DataLayout;
32
33namespace LLVM {
34class LLVMDialect;
35
36namespace detail {
37struct LLVMFunctionTypeStorage;
38struct LLVMPointerTypeStorage;
41} // namespace detail
42} // namespace LLVM
43} // namespace mlir
44
45//===----------------------------------------------------------------------===//
46// ODS-Generated Declarations
47//===----------------------------------------------------------------------===//
48
49#include "mlir/Dialect/LLVMIR/LLVMTypeInterfaces.h.inc"
50
51#define GET_TYPEDEF_CLASSES
52#include "mlir/Dialect/LLVMIR/LLVMTypes.h.inc"
53
54namespace mlir {
55namespace LLVM {
56
57//===----------------------------------------------------------------------===//
58// Trivial types.
59//===----------------------------------------------------------------------===//
60
61// Batch-define trivial types.
62#define DEFINE_TRIVIAL_LLVM_TYPE(ClassName, TypeName) \
63 class ClassName : public Type::TypeBase<ClassName, Type, TypeStorage> { \
64 public: \
65 using Base::Base; \
66 static constexpr StringLiteral name = TypeName; \
67 }
68
69DEFINE_TRIVIAL_LLVM_TYPE(LLVMVoidType, "llvm.void");
70DEFINE_TRIVIAL_LLVM_TYPE(LLVMTokenType, "llvm.token");
71DEFINE_TRIVIAL_LLVM_TYPE(LLVMLabelType, "llvm.label");
72DEFINE_TRIVIAL_LLVM_TYPE(LLVMMetadataType, "llvm.metadata");
73
74#undef DEFINE_TRIVIAL_LLVM_TYPE
75
76//===----------------------------------------------------------------------===//
77// Printing and parsing.
78//===----------------------------------------------------------------------===//
79
80namespace detail {
81/// Parses an LLVM dialect type.
83
84/// Prints an LLVM Dialect type.
85void printType(Type type, AsmPrinter &printer);
86} // namespace detail
87
88/// Parse any MLIR type or a concise syntax for LLVM types.
89ParseResult parsePrettyLLVMType(AsmParser &p, Type &type);
90/// Print any MLIR type or a concise syntax for LLVM types.
92
93//===----------------------------------------------------------------------===//
94// Utility functions.
95//===----------------------------------------------------------------------===//
96
97/// Returns `true` if the given type is compatible with the LLVM dialect. This
98/// is an alias to `LLVMDialect::isCompatibleType`.
99bool isCompatibleType(Type type);
100
101/// Returns `true` if the given outer type is compatible with the LLVM dialect
102/// without checking its potential nested types such as struct elements.
103bool isCompatibleOuterType(Type type);
104
105/// Returns `true` if the given type is a floating-point type compatible with
106/// the LLVM dialect.
108
109/// Returns `true` if the given type is a vector type compatible with the LLVM
110/// dialect. Compatible types include 1D built-in vector types of built-in
111/// integers and floating-point values, LLVM dialect fixed vector types of LLVM
112/// dialect pointers and LLVM dialect scalable vector types.
114
115/// Returns `true` if the given type is a loadable type compatible with the LLVM
116/// dialect.
117bool isLoadableType(Type type);
118
119/// Returns true if the given type is supported by atomic operations. All
120/// integer, float, and pointer types with a power-of-two bitsize and a minimal
121/// size of 8 bits are supported.
122bool isTypeCompatibleWithAtomicOp(Type type, const DataLayout &dataLayout);
123
124/// Returns the element count of any LLVM-compatible vector type.
125llvm::ElementCount getVectorNumElements(Type type);
126
127/// Returns whether a vector type is scalable or not.
128bool isScalableVectorType(Type vectorType);
129
130/// Creates an LLVM dialect-compatible vector type with the given element type
131/// and length.
132Type getVectorType(Type elementType, unsigned numElements,
133 bool isScalable = false);
134
135/// Creates an LLVM dialect-compatible vector type with the given element type
136/// and length.
137Type getVectorType(Type elementType, const llvm::ElementCount &numElements);
138
139/// Returns the size of the given primitive LLVM dialect-compatible type
140/// (including vectors) in bits, for example, the size of i16 is 16 and
141/// the size of vector<4xi16> is 64. Returns 0 for non-primitive
142/// (aggregates such as struct) or types that don't have a size (such as void).
143llvm::TypeSize getPrimitiveTypeSizeInBits(Type type);
144
145/// The positions of different values in the data layout entry for pointers.
146enum class PtrDLEntryPos { Size = 0, Abi = 1, Preferred = 2, Index = 3 };
147
148/// Returns the value that corresponds to named position `pos` from the
149/// data layout entry `attr` assuming it's a dense integer elements attribute.
150/// Returns `std::nullopt` if `pos` is not present in the entry.
151/// Currently only `PtrDLEntryPos::Index` is optional, and all other positions
152/// may be assumed to be present.
153std::optional<uint64_t> extractPointerSpecValue(Attribute attr,
154 PtrDLEntryPos pos);
155
156} // namespace LLVM
157} // namespace mlir
158
159#endif // MLIR_DIALECT_LLVMIR_LLVMTYPES_H_
#define DEFINE_TRIVIAL_LLVM_TYPE(ClassName, TypeName)
Definition LLVMTypes.h:62
This base class exposes generic asm parser hooks, usable across the various derived parsers.
This base class exposes generic asm printer hooks, usable across the various derived printers.
Attributes are known-constant values of operations.
Definition Attributes.h:25
The main mechanism for performing data layout queries.
The DialectAsmParser has methods for interacting with the asm parser when parsing attributes and type...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
void printType(Type type, AsmPrinter &printer)
Prints an LLVM Dialect type.
Type parseType(DialectAsmParser &parser)
Parses an LLVM dialect type.
Type getVectorType(Type elementType, unsigned numElements, bool isScalable=false)
Creates an LLVM dialect-compatible vector type with the given element type and length.
llvm::TypeSize getPrimitiveTypeSizeInBits(Type type)
Returns the size of the given primitive LLVM dialect-compatible type (including vectors) in bits,...
void printPrettyLLVMType(AsmPrinter &p, Type type)
Print any MLIR type or a concise syntax for LLVM types.
bool isLoadableType(Type type)
Returns true if the given type is a loadable type compatible with the LLVM dialect.
bool isScalableVectorType(Type vectorType)
Returns whether a vector type is scalable or not.
ParseResult parsePrettyLLVMType(AsmParser &p, Type &type)
Parse any MLIR type or a concise syntax for LLVM types.
bool isCompatibleVectorType(Type type)
Returns true if the given type is a vector type compatible with the LLVM dialect.
bool isCompatibleOuterType(Type type)
Returns true if the given outer type is compatible with the LLVM dialect without checking its potenti...
PtrDLEntryPos
The positions of different values in the data layout entry for pointers.
Definition LLVMTypes.h:146
std::optional< uint64_t > extractPointerSpecValue(Attribute attr, PtrDLEntryPos pos)
Returns the value that corresponds to named position pos from the data layout entry attr assuming it'...
bool isCompatibleType(Type type)
Returns true if the given type is compatible with the LLVM dialect.
bool isTypeCompatibleWithAtomicOp(Type type, const DataLayout &dataLayout)
Returns true if the given type is supported by atomic operations.
bool isCompatibleFloatingPointType(Type type)
Returns true if the given type is a floating-point type compatible with the LLVM dialect.
llvm::ElementCount getVectorNumElements(Type type)
Returns the element count of any LLVM-compatible vector type.
Include the generated interface declarations.
Type storage for LLVM structure types.
Definition TypeDetail.h:61
Common storage used for LLVM dialect types that need an element type and a number: arrays,...
Definition TypeDetail.h:366