MLIR 23.0.0git
ABITypeMapper.h
Go to the documentation of this file.
1//===- ABITypeMapper.h - Map MLIR types to ABI 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 ABITypeMapper, which translates mlir::Type instances into
10// the llvm::abi::Type hierarchy defined in llvm/ABI/Types.h. Dialect-specific
11// types are handled via MLIR's DataLayoutTypeInterface.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_ABI_ABITYPEMAPPER_H
16#define MLIR_ABI_ABITYPEMAPPER_H
17
19#include "mlir/IR/Types.h"
21#include "llvm/ABI/Types.h"
22#include "llvm/Support/Allocator.h"
23
24namespace mlir {
25namespace abi {
26
27/// ABITypeMapper translates mlir::Type values into the llvm::abi::Type
28/// hierarchy used by the LLVM ABI Lowering Library.
29///
30/// Standard MLIR types (IntegerType, FloatType, IndexType, VectorType,
31/// MemRefType) are mapped directly. Dialect-specific types are mapped
32/// by querying the MLIR DataLayout for size and alignment.
33///
34/// Callers must supply a DataLayout (typically from the enclosing module)
35/// so the mapper can determine sizes and alignments.
36///
37/// The mapper owns a BumpPtrAllocator; all returned abi::Type pointers
38/// are valid for the lifetime of the mapper.
40public:
41 explicit ABITypeMapper(const DataLayout &dl);
42
43 /// Map an MLIR type to its ABI type representation. Returns nullptr
44 /// if the type cannot be mapped.
45 const llvm::abi::Type *map(mlir::Type type);
46
47 /// Access the underlying TypeBuilder for advanced use.
48 llvm::abi::TypeBuilder &getTypeBuilder() { return builder; }
49
50private:
51 const llvm::abi::Type *mapIntegerType(mlir::IntegerType type);
52 const llvm::abi::Type *mapFloatType(mlir::FloatType type);
53 const llvm::abi::Type *mapIndexType(mlir::IndexType type);
54 const llvm::abi::Type *mapVectorType(mlir::VectorType type);
55 const llvm::abi::Type *mapMemRefType(mlir::MemRefType type);
56 const llvm::abi::Type *mapNoneType(mlir::NoneType type);
57
58 const DataLayout &dl;
59 llvm::BumpPtrAllocator allocator;
60 llvm::abi::TypeBuilder builder;
61};
62
63} // namespace abi
64} // namespace mlir
65
66#endif // MLIR_ABI_ABITYPEMAPPER_H
The main mechanism for performing data layout queries.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
const llvm::abi::Type * map(mlir::Type type)
Map an MLIR type to its ABI type representation.
ABITypeMapper(const DataLayout &dl)
llvm::abi::TypeBuilder & getTypeBuilder()
Access the underlying TypeBuilder for advanced use.
Include the generated interface declarations.