clang 23.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 cir {
28
29namespace detail {
31struct UnionTypeStorage;
32} // namespace detail
33
34bool isValidFundamentalIntWidth(unsigned width);
35
36/// Returns true if the type is a CIR sized type.
37///
38/// Types are sized if they implement SizedTypeInterface and
39/// return true from its method isSized.
40///
41/// Unsized types are those that do not have a size, such as
42/// void, or abstract types.
43bool isSized(mlir::Type ty);
44
45//===----------------------------------------------------------------------===//
46// AddressSpace helpers
47//===----------------------------------------------------------------------===//
48
49cir::LangAddressSpace toCIRLangAddressSpace(clang::LangAS langAS);
50
51// Compare a CIR memory space attribute with a Clang LangAS.
52bool isMatchingAddressSpace(mlir::ptr::MemorySpaceAttrInterface cirAS,
53 clang::LangAS as);
54
55/// Convert an AST LangAS to the appropriate CIR address space attribute
56/// interface.
57mlir::ptr::MemorySpaceAttrInterface
58toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS);
59
60/// Normalize LangAddressSpace::Default to null (empty attribute).
61mlir::ptr::MemorySpaceAttrInterface
62normalizeDefaultAddressSpace(mlir::ptr::MemorySpaceAttrInterface addrSpace);
63
65 mlir::ptr::MemorySpaceAttrInterface memorySpace);
66
67} // namespace cir
68
69//===----------------------------------------------------------------------===//
70// CIR Dialect Tablegen'd Types
71//===----------------------------------------------------------------------===//
72
73namespace cir {
74
75#include "clang/CIR/Dialect/IR/CIRTypeConstraints.h.inc"
76
77} // namespace cir
78
79#define GET_TYPEDEF_CLASSES
80#include "clang/CIR/Dialect/IR/CIROpsTypes.h.inc"
81
82namespace cir {
83
84/// C++ view class that accepts both !cir.struct and !cir.union types.
85///
86/// Follows the MLIR BaseMemRefType pattern: StructType and UnionType are the
87/// concrete tablegen types; RecordType is a hand-written view class that
88/// covers both. Use it when code must handle either kind generically.
89///
90/// Methods that are common to both types are forwarded through dyn_cast
91/// dispatch. Type-specific methods (getPadding, getUnionStorageType) are only
92/// available on the concrete type.
93class RecordType : public mlir::Type {
94public:
95 using mlir::Type::Type;
96
97 // Allow implicit construction from concrete record types so that
98 // functions returning cir::RecordType can return StructType/UnionType
99 // values without an explicit cast.
100 // NOLINTNEXTLINE(google-explicit-constructor)
101 RecordType(StructType t) : mlir::Type(t) {}
102 // NOLINTNEXTLINE(google-explicit-constructor)
103 RecordType(UnionType t) : mlir::Type(t) {}
104
105 static bool classof(mlir::Type t) {
106 return mlir::isa<StructType>(t) || mlir::isa<UnionType>(t);
107 }
108
110 mlir::StringAttr getName() const;
111 bool isIncomplete() const;
112 bool isComplete() const { return !isIncomplete(); }
113 bool getPacked() const;
114 bool getPadded() const;
115
116 bool isClass() const;
117 bool isStruct() const;
118 bool isUnion() const { return mlir::isa<UnionType>(*this); }
119
120 size_t getNumElements() const { return getMembers().size(); }
121 mlir::Type getElementType(size_t idx) const { return getMembers()[idx]; }
122 std::string getKindAsStr() const;
123 std::string getPrefixedName() const;
124
125 void complete(llvm::ArrayRef<mlir::Type> members, bool packed, bool padded,
126 mlir::Type padding = {});
127 uint64_t getElementOffset(const mlir::DataLayout &dataLayout,
128 unsigned idx) const;
129 bool isLayoutIdentical(const RecordType &other);
130
131 bool isABIConvertedRecord() const;
132 mlir::StringAttr getABIConvertedName() const;
134};
135
136} // namespace cir
137
138#endif // CLANG_CIR_DIALECT_IR_CIRTYPES_H
Provides definitions for the various language-specific address spaces.
bool isUnion() const
Definition CIRTypes.h:118
bool isLayoutIdentical(const RecordType &other)
Definition CIRTypes.cpp:550
mlir::Type getElementType(size_t idx) const
Definition CIRTypes.h:121
bool isComplete() const
Definition CIRTypes.h:112
bool isABIConvertedRecord() const
Definition CIRTypes.cpp:563
bool isIncomplete() const
Definition CIRTypes.cpp:502
std::string getPrefixedName() const
Definition CIRTypes.cpp:532
llvm::ArrayRef< mlir::Type > getMembers() const
Definition CIRTypes.cpp:492
RecordType(UnionType t)
Definition CIRTypes.h:103
bool isClass() const
Definition CIRTypes.cpp:517
void removeABIConversionNamePrefix()
Definition CIRTypes.cpp:573
static bool classof(mlir::Type t)
Definition CIRTypes.h:105
bool getPacked() const
Definition CIRTypes.cpp:507
RecordType(StructType t)
Definition CIRTypes.h:101
void complete(llvm::ArrayRef< mlir::Type > members, bool packed, bool padded, mlir::Type padding={})
Definition CIRTypes.cpp:535
mlir::StringAttr getName() const
Definition CIRTypes.cpp:497
mlir::StringAttr getABIConvertedName() const
Definition CIRTypes.cpp:568
std::string getKindAsStr() const
Definition CIRTypes.cpp:527
bool isStruct() const
Definition CIRTypes.cpp:522
bool getPadded() const
Definition CIRTypes.cpp:512
size_t getNumElements() const
Definition CIRTypes.h:120
uint64_t getElementOffset(const mlir::DataLayout &dataLayout, unsigned idx) const
Definition CIRTypes.cpp:544
bool isMatchingAddressSpace(mlir::ptr::MemorySpaceAttrInterface cirAS, clang::LangAS as)
cir::LangAddressSpace toCIRLangAddressSpace(clang::LangAS langAS)
bool isValidFundamentalIntWidth(unsigned width)
Definition CIRTypes.cpp:825
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:34
bool isSupportedCIRMemorySpaceAttr(mlir::ptr::MemorySpaceAttrInterface memorySpace)
LangAS
Defines the address space values used by the address space qualifier of QualType.
Type storage for CIR struct/class types.
Type storage for CIR union types.