MLIR 23.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(LLVMLabelType, "llvm.label");
71DEFINE_TRIVIAL_LLVM_TYPE(LLVMMetadataType, "llvm.metadata");
72
73#undef DEFINE_TRIVIAL_LLVM_TYPE
74
75//===----------------------------------------------------------------------===//
76// Printing and parsing.
77//===----------------------------------------------------------------------===//
78
79namespace detail {
80/// Parses an LLVM dialect type.
82
83/// Prints an LLVM Dialect type.
84void printType(Type type, AsmPrinter &printer);
85} // namespace detail
86
87/// Parse any MLIR type or a concise syntax for LLVM types.
88ParseResult parsePrettyLLVMType(AsmParser &p, Type &type);
89/// Print any MLIR type or a concise syntax for LLVM types.
91
92//===----------------------------------------------------------------------===//
93// Utility functions.
94//===----------------------------------------------------------------------===//
95
96/// Returns `true` if the given type is compatible with the LLVM dialect. This
97/// is an alias to `LLVMDialect::isCompatibleType`.
98bool isCompatibleType(Type type);
99
100/// Returns `true` if the given outer type is compatible with the LLVM dialect
101/// without checking its potential nested types such as struct elements.
102bool isCompatibleOuterType(Type type);
103
104/// Returns `true` if the given type is a floating-point type compatible with
105/// the LLVM dialect.
107
108/// Returns `true` if the given type is a vector type compatible with the LLVM
109/// dialect. Compatible types include 1D built-in vector types of built-in
110/// integers and floating-point values, LLVM dialect fixed vector types of LLVM
111/// dialect pointers and LLVM dialect scalable vector types.
113
114/// Returns `true` if the given type is a loadable type compatible with the LLVM
115/// dialect.
116bool isLoadableType(Type type);
117
118/// Returns true if the given type is supported by atomic operations. All
119/// integer, float, and pointer types with a power-of-two bitsize and a minimal
120/// size of 8 bits are supported.
121bool isTypeCompatibleWithAtomicOp(Type type, const DataLayout &dataLayout);
122
123/// Returns the element count of any LLVM-compatible vector type.
124llvm::ElementCount getVectorNumElements(Type type);
125
126/// Returns whether a vector type is scalable or not.
127bool isScalableVectorType(Type vectorType);
128
129/// Creates an LLVM dialect-compatible vector type with the given element type
130/// and length.
131Type getVectorType(Type elementType, unsigned numElements,
132 bool isScalable = false);
133
134/// Creates an LLVM dialect-compatible vector type with the given element type
135/// and length.
136Type getVectorType(Type elementType, const llvm::ElementCount &numElements);
137
138/// Returns the size of the given primitive LLVM dialect-compatible type
139/// (including vectors) in bits, for example, the size of i16 is 16 and
140/// the size of vector<4xi16> is 64. Returns 0 for non-primitive
141/// (aggregates such as struct) or types that don't have a size (such as void).
142llvm::TypeSize getPrimitiveTypeSizeInBits(Type type);
143
144/// The positions of different values in the data layout entry for pointers.
145enum class PtrDLEntryPos { Size = 0, Abi = 1, Preferred = 2, Index = 3 };
146
147/// Returns the value that corresponds to named position `pos` from the
148/// data layout entry `attr` assuming it's a dense integer elements attribute.
149/// Returns `std::nullopt` if `pos` is not present in the entry.
150/// Currently only `PtrDLEntryPos::Index` is optional, and all other positions
151/// may be assumed to be present.
152std::optional<uint64_t> extractPointerSpecValue(Attribute attr,
153 PtrDLEntryPos pos);
154
155} // namespace LLVM
156} // namespace mlir
157
158#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:227
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:145
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