clang 24.0.0git
CIRTypes.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 declares the types in the CIR dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CLANG_CIR_DIALECT_IR_CIRTYPES_H
14#define CLANG_CIR_DIALECT_IR_CIRTYPES_H
15
16#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
17#include "mlir/IR/Attributes.h"
18#include "mlir/IR/BuiltinAttributes.h"
19#include "mlir/IR/MLIRContext.h"
20#include "mlir/IR/Types.h"
21#include "mlir/Interfaces/DataLayoutInterfaces.h"
26
27namespace llvm {
28struct fltSemantics;
29} // namespace llvm
30
31namespace cir {
32
33namespace detail {
35struct UnionTypeStorage;
36} // namespace detail
37
38bool isValidFundamentalIntWidth(unsigned width);
39
40/// Returns true if the type is a CIR sized type.
41///
42/// Types are sized if they implement SizedTypeInterface and
43/// return true from its method isSized.
44///
45/// Unsized types are those that do not have a size, such as
46/// void, or abstract types.
47bool isSized(mlir::Type ty);
48
49/// Returns the CIR floating-point type for the given semantics, or a null
50/// type if CIR has no type for it (e.g. PPCDoubleDouble or a Float8 format).
51/// Mirrors llvm::Type::getFloatingPointTy.
52cir::FPTypeInterface getFloatingPointType(const llvm::fltSemantics &sem,
53 mlir::MLIRContext *ctx);
54
55//===----------------------------------------------------------------------===//
56// AddressSpace helpers
57//===----------------------------------------------------------------------===//
58
59cir::LangAddressSpace toCIRLangAddressSpace(clang::LangAS langAS);
60
61// Compare a CIR memory space attribute with a Clang LangAS.
62bool isMatchingAddressSpace(mlir::ptr::MemorySpaceAttrInterface cirAS,
63 clang::LangAS as);
64
65/// Convert an AST LangAS to the appropriate CIR address space attribute
66/// interface.
67mlir::ptr::MemorySpaceAttrInterface
68toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS);
69
70/// Normalize LangAddressSpace::Default to null (empty attribute).
71mlir::ptr::MemorySpaceAttrInterface
72normalizeDefaultAddressSpace(mlir::ptr::MemorySpaceAttrInterface addrSpace);
73
75 mlir::ptr::MemorySpaceAttrInterface memorySpace);
76
77} // namespace cir
78
79//===----------------------------------------------------------------------===//
80// CIR Dialect Tablegen'd Types
81//===----------------------------------------------------------------------===//
82
83namespace cir {
84
85#include "clang/CIR/Dialect/IR/CIRTypeConstraints.h.inc"
86
87} // namespace cir
88
89#define GET_TYPEDEF_CLASSES
90#include "clang/CIR/Dialect/IR/CIROpsTypes.h.inc"
91
92namespace cir {
93
94/// C++ view class that accepts both !cir.struct and !cir.union types.
95///
96/// Follows the MLIR BaseMemRefType pattern: StructType and UnionType are the
97/// concrete tablegen types; RecordType is a hand-written view class that
98/// covers both. Use it when code must handle either kind generically.
99///
100/// Methods that are common to both types are forwarded through dyn_cast
101/// dispatch. Type-specific methods (getPadding, getUnionStorageType) are only
102/// available on the concrete type.
103class RecordType : public mlir::Type {
104public:
105 using mlir::Type::Type;
106
107 // Allow implicit construction from concrete record types so that
108 // functions returning cir::RecordType can return StructType/UnionType
109 // values without an explicit cast.
110 // NOLINTNEXTLINE(google-explicit-constructor)
111 RecordType(StructType t) : mlir::Type(t) {}
112 // NOLINTNEXTLINE(google-explicit-constructor)
113 RecordType(UnionType t) : mlir::Type(t) {}
114
115 static bool classof(mlir::Type t) {
116 return mlir::isa<StructType>(t) || mlir::isa<UnionType>(t);
117 }
118
120 mlir::StringAttr getName() const;
121 bool isIncomplete() const;
122 bool isComplete() const { return !isIncomplete(); }
123 bool getPacked() const;
124 bool getPadded() const;
125
126 bool isClass() const;
127 bool isStruct() const;
128 bool isUnion() const { return mlir::isa<UnionType>(*this); }
129
130 size_t getNumElements() const { return getMembers().size(); }
131 mlir::Type getElementType(size_t idx) const { return getMembers()[idx]; }
132 std::string getKindAsStr() const;
133 std::string getPrefixedName() const;
134
135 void complete(llvm::ArrayRef<mlir::Type> members, bool packed, bool padded,
136 mlir::Type padding = {});
137 uint64_t getElementOffset(const mlir::DataLayout &dataLayout,
138 unsigned idx) const;
139 bool isLayoutIdentical(const RecordType &other);
140
141 bool isABIConvertedRecord() const;
142 mlir::StringAttr getABIConvertedName() const;
144};
145
146} // namespace cir
147
148#endif // CLANG_CIR_DIALECT_IR_CIRTYPES_H
Provides definitions for the various language-specific address spaces.
bool isUnion() const
Definition CIRTypes.h:128
bool isLayoutIdentical(const RecordType &other)
Definition CIRTypes.cpp:577
mlir::Type getElementType(size_t idx) const
Definition CIRTypes.h:131
bool isComplete() const
Definition CIRTypes.h:122
bool isABIConvertedRecord() const
Definition CIRTypes.cpp:590
bool isIncomplete() const
Definition CIRTypes.cpp:529
std::string getPrefixedName() const
Definition CIRTypes.cpp:559
llvm::ArrayRef< mlir::Type > getMembers() const
Definition CIRTypes.cpp:519
RecordType(UnionType t)
Definition CIRTypes.h:113
bool isClass() const
Definition CIRTypes.cpp:544
void removeABIConversionNamePrefix()
Definition CIRTypes.cpp:600
static bool classof(mlir::Type t)
Definition CIRTypes.h:115
bool getPacked() const
Definition CIRTypes.cpp:534
RecordType(StructType t)
Definition CIRTypes.h:111
void complete(llvm::ArrayRef< mlir::Type > members, bool packed, bool padded, mlir::Type padding={})
Definition CIRTypes.cpp:562
mlir::StringAttr getName() const
Definition CIRTypes.cpp:524
mlir::StringAttr getABIConvertedName() const
Definition CIRTypes.cpp:595
std::string getKindAsStr() const
Definition CIRTypes.cpp:554
bool isStruct() const
Definition CIRTypes.cpp:549
bool getPadded() const
Definition CIRTypes.cpp:539
size_t getNumElements() const
Definition CIRTypes.h:130
uint64_t getElementOffset(const mlir::DataLayout &dataLayout, unsigned idx) const
Definition CIRTypes.cpp:571
bool isMatchingAddressSpace(mlir::ptr::MemorySpaceAttrInterface cirAS, clang::LangAS as)
cir::LangAddressSpace toCIRLangAddressSpace(clang::LangAS langAS)
bool isValidFundamentalIntWidth(unsigned width)
Definition CIRTypes.cpp:858
cir::FPTypeInterface getFloatingPointType(const llvm::fltSemantics &sem, mlir::MLIRContext *ctx)
Returns the CIR floating-point type for the given semantics, or a null type if CIR has no type for it...
Definition CIRTypes.cpp:42
mlir::ptr::MemorySpaceAttrInterface toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS)
Convert an AST LangAS to the appropriate CIR address space attribute interface.
mlir::ptr::MemorySpaceAttrInterface normalizeDefaultAddressSpace(mlir::ptr::MemorySpaceAttrInterface addrSpace)
Normalize LangAddressSpace::Default to null (empty attribute).
bool isSized(mlir::Type ty)
Returns true if the type is a CIR sized type.
Definition CIRTypes.cpp:35
bool isSupportedCIRMemorySpaceAttr(mlir::ptr::MemorySpaceAttrInterface memorySpace)
LangAS
Defines the address space values used by the address space qualifier of QualType.
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
Type storage for CIR struct/class types.
Type storage for CIR union types.