MLIR 24.0.0git
OpenACCUtilsType.h
Go to the documentation of this file.
1//===- OpenACCUtilsType.h - OpenACC Type Utilities -------------*- 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 type utilities for OpenACC.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_OPENACC_OPENACCUTILSTYPE_H_
14#define MLIR_DIALECT_OPENACC_OPENACCUTILSTYPE_H_
15
16#include "mlir/IR/Value.h"
17#include "llvm/Support/TypeSize.h"
18#include <optional>
19#include <utility>
20
21namespace mlir {
22class DataLayout;
23class Location;
24class ModuleOp;
25class OpBuilder;
26class Type;
27class Value;
28
29namespace acc {
30
31class OpenACCSupport;
32
33using TypeSizeAndAlignment = std::pair<llvm::TypeSize, llvm::TypeSize>;
34
35/// Returns the size and ABI alignment in bytes.
36///
37/// For aggregate structures and arrays, padding between members or elements is
38/// not taken into account. The result is a close estimate suitable for early
39/// OpenACC layout decisions, but not a complete ABI guarantee. For final size
40/// computations, use LLVM materialized types.
41///
42/// \p ty itself is sized dialect-agnostically; when \p support is provided it
43/// sizes aggregate element types, so that nested dialect types are handled.
44/// Callers that hold an OpenACCSupport should therefore ask it directly -
45/// OpenACCSupport::getTypeSizeAndAlignment covers dialect types and falls back
46/// to this utility - and call this utility directly only for a type this
47/// utility is expected to know.
48///
49/// When \p var is provided, MappableType sizes the mapped object rather than
50/// the type's storage alone.
51///
52/// Returns std::nullopt when the size is not statically computable or the type
53/// is not supported.
54std::optional<TypeSizeAndAlignment>
55getTypeSizeAndAlignment(Type ty, ModuleOp module, const DataLayout &dl,
56 OpenACCSupport *support = nullptr, Value var = {});
57
58/// Same as above, obtaining \p dl from \p module via getDataLayout.
59std::optional<TypeSizeAndAlignment>
60getTypeSizeAndAlignment(Type ty, ModuleOp module,
61 OpenACCSupport *support = nullptr, Value var = {});
62
63/// Cast \p value to \p resultType via PointerLikeType::genCast when needed.
64/// Returns \p value unchanged if types already match. Emits an error and
65/// returns \p value if no cast can be generated.
66Value castPointerLikeTypeIfNeeded(OpBuilder &builder, Location loc, Value value,
67 Type resultType);
68
69} // namespace acc
70} // namespace mlir
71
72#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSTYPE_H_
The main mechanism for performing data layout queries.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:210
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Value castPointerLikeTypeIfNeeded(OpBuilder &builder, Location loc, Value value, Type resultType)
Cast value to resultType via PointerLikeType::genCast when needed.
std::pair< llvm::TypeSize, llvm::TypeSize > TypeSizeAndAlignment
std::optional< TypeSizeAndAlignment > getTypeSizeAndAlignment(Type ty, ModuleOp module, const DataLayout &dl, OpenACCSupport *support=nullptr, Value var={})
Returns the size and ABI alignment in bytes.
Include the generated interface declarations.