Skip to content

Commit 15a4a12

Browse files
committed
Merge remote-tracking branch 'origin/main' into cxx-ctor-dtor
2 parents f10b62f + 30718ac commit 15a4a12

33 files changed

+730
-129
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,17 @@ def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
444444
value of the specified floating-point type. Supporting only CIR FP types.
445445
}];
446446
let parameters = (ins
447-
AttributeSelfTypeParameter<"", "::cir::CIRFPTypeInterface">:$type,
447+
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
448448
APFloatParameter<"">:$value
449449
);
450450
let builders = [
451451
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
452452
"const llvm::APFloat &":$value), [{
453-
return $_get(type.getContext(), mlir::cast<CIRFPTypeInterface>(type), value);
453+
return $_get(type.getContext(), mlir::cast<FPTypeInterface>(type), value);
454454
}]>,
455455
AttrBuilder<(ins "mlir::Type":$type,
456456
"const llvm::APFloat &":$value), [{
457-
return $_get($_ctxt, mlir::cast<CIRFPTypeInterface>(type), value);
457+
return $_get($_ctxt, mlir::cast<FPTypeInterface>(type), value);
458458
}]>,
459459
];
460460
let extraClassDeclaration = [{

clang/include/clang/CIR/Dialect/IR/CIRTypes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "mlir/Interfaces/DataLayoutInterfaces.h"
1919
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
2020
#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
21-
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
21+
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
2222

2323
namespace cir {
2424
namespace detail {
@@ -27,6 +27,9 @@ struct RecordTypeStorage;
2727

2828
bool isValidFundamentalIntWidth(unsigned width);
2929

30+
// Returns true if the type is a CIR sized type.
31+
bool isSized(mlir::Type ty);
32+
3033
} // namespace cir
3134

3235
mlir::ParseResult parseAddrSpaceAttribute(mlir::AsmParser &p,

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
include "clang/CIR/Dialect/IR/CIRDialect.td"
1717
include "clang/CIR/Dialect/IR/CIRTypeConstraints.td"
1818
include "clang/CIR/Interfaces/ASTAttrInterfaces.td"
19-
include "clang/CIR/Interfaces/CIRFPTypeInterface.td"
19+
include "clang/CIR/Interfaces/CIRTypeInterfaces.td"
2020
include "mlir/Interfaces/DataLayoutInterfaces.td"
2121
include "mlir/IR/AttrTypeBase.td"
2222
include "mlir/IR/EnumAttr.td"
@@ -35,8 +35,10 @@ class CIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
3535
// IntType
3636
//===----------------------------------------------------------------------===//
3737

38-
def CIR_IntType : CIR_Type<"Int", "int",
39-
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
38+
def CIR_IntType : CIR_Type<"Int", "int", [
39+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
40+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
41+
]> {
4042
let summary = "Integer type with arbitrary precision up to a fixed limit";
4143
let description = [{
4244
CIR type that represents integer types with arbitrary precision.
@@ -81,8 +83,9 @@ def CIR_IntType : CIR_Type<"Int", "int",
8183
//===----------------------------------------------------------------------===//
8284

8385
class CIR_FloatType<string name, string mnemonic> : CIR_Type<name, mnemonic, [
84-
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
85-
DeclareTypeInterfaceMethods<CIRFPTypeInterface>
86+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
87+
DeclareTypeInterfaceMethods<CIR_FPTypeInterface>,
88+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>
8689
]>;
8790

8891
def CIR_Single : CIR_FloatType<"Single", "float"> {
@@ -151,9 +154,10 @@ def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
151154
// ComplexType
152155
//===----------------------------------------------------------------------===//
153156

154-
def CIR_ComplexType : CIR_Type<"Complex", "complex",
155-
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
156-
157+
def CIR_ComplexType : CIR_Type<"Complex", "complex", [
158+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
159+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>
160+
]> {
157161
let summary = "CIR complex type";
158162
let description = [{
159163
CIR type that represents a C complex number. `cir.complex` models the C type
@@ -194,9 +198,10 @@ def CIR_ComplexType : CIR_Type<"Complex", "complex",
194198
// PointerType
195199
//===----------------------------------------------------------------------===//
196200

197-
def CIR_PointerType : CIR_Type<"Pointer", "ptr",
198-
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
199-
201+
def CIR_PointerType : CIR_Type<"Pointer", "ptr", [
202+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
203+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>
204+
]> {
200205
let summary = "CIR pointer type";
201206
let description = [{
202207
`CIR.ptr` is a type returned by any op generating a pointer in C++.
@@ -295,9 +300,10 @@ def CIR_DataMemberType : CIR_Type<"DataMember", "data_member",
295300
// BoolType
296301
//===----------------------------------------------------------------------===//
297302

298-
def CIR_BoolType : CIR_Type<"Bool", "bool",
299-
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
300-
303+
def CIR_BoolType : CIR_Type<"Bool", "bool", [
304+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
305+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>
306+
]> {
301307
let summary = "CIR bool type";
302308
let description = [{
303309
`cir.bool` represent's C++ bool type.
@@ -308,9 +314,10 @@ def CIR_BoolType : CIR_Type<"Bool", "bool",
308314
// ArrayType
309315
//===----------------------------------------------------------------------===//
310316

311-
def CIR_ArrayType : CIR_Type<"Array", "array",
312-
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
313-
317+
def CIR_ArrayType : CIR_Type<"Array", "array", [
318+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
319+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface, ["isSized"]>,
320+
]> {
314321
let summary = "CIR array type";
315322
let description = [{
316323
`CIR.array` represents C/C++ constant arrays.
@@ -329,14 +336,22 @@ def CIR_ArrayType : CIR_Type<"Array", "array",
329336
let assemblyFormat = [{
330337
`<` $elementType `x` $size `>`
331338
}];
339+
340+
let extraClassDefinition = [{
341+
bool $cppClass::isSized() const {
342+
return ::cir::isSized(getElementType());
343+
}
344+
}];
332345
}
333346

334347
//===----------------------------------------------------------------------===//
335348
// VectorType (fixed size)
336349
//===----------------------------------------------------------------------===//
337350

338-
def CIR_VectorType : CIR_Type<"Vector", "vector",
339-
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
351+
def CIR_VectorType : CIR_Type<"Vector", "vector", [
352+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
353+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface, ["isSized"]>,
354+
]> {
340355

341356
let summary = "CIR vector type";
342357
let description = [{
@@ -378,6 +393,12 @@ def CIR_VectorType : CIR_Type<"Vector", "vector",
378393
`<` $elementType `x` $size `>`
379394
}];
380395

396+
let extraClassDefinition = [{
397+
bool $cppClass::isSized() const {
398+
return ::cir::isSized(getElementType());
399+
}
400+
}];
401+
381402
let genVerifyDecl = 1;
382403
}
383404

@@ -524,11 +545,11 @@ def CIR_VoidType : CIR_Type<"Void", "void"> {
524545
// The base type for all RecordDecls.
525546
//===----------------------------------------------------------------------===//
526547

527-
def CIR_RecordType : CIR_Type<"Record", "record",
528-
[
529-
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
530-
MutableType,
531-
]> {
548+
def CIR_RecordType : CIR_Type<"Record", "record", [
549+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
550+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
551+
MutableType,
552+
]> {
532553
let summary = "CIR record type";
533554
let description = [{
534555
Each unique clang::RecordDecl is mapped to a `cir.record` and any object in
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
//===- CIRFPTypeInterface.h - Interface for CIR FP types -------*- C++ -*-===//
1+
//===---------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===---------------------------------------------------------------------===//
88
//
9-
// Defines the interface to generically handle CIR floating-point types.
9+
// Defines cir type interfaces.
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
14-
#define CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
13+
#ifndef CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H
14+
#define CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H
1515

1616
#include "mlir/IR/Types.h"
1717
#include "llvm/ADT/APFloat.h"
1818

1919
/// Include the tablegen'd interface declarations.
20-
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h.inc"
20+
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h.inc"
2121

22-
#endif // CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
22+
#endif // CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H

clang/include/clang/CIR/Interfaces/CIRFPTypeInterface.td renamed to clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
//===- CIRFPTypeInterface.td - CIR FP Interface Definitions -----*- C++ -*-===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
// Defines cir type interfaces.
10+
//
11+
//===----------------------------------------------------------------------===//
812

9-
#ifndef MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
10-
#define MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
13+
#ifndef CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD
14+
#define CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD
1115

1216
include "mlir/IR/OpBase.td"
1317

14-
def CIRFPTypeInterface : TypeInterface<"CIRFPTypeInterface"> {
18+
def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
1519
let description = [{
1620
Contains helper functions to query properties about a floating-point type.
1721
}];
@@ -49,4 +53,32 @@ def CIRFPTypeInterface : TypeInterface<"CIRFPTypeInterface"> {
4953
];
5054
}
5155

52-
#endif // MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
56+
def CIR_SizedTypeInterface : TypeInterface<"SizedTypeInterface"> {
57+
let description = [{
58+
Annotates types that have known size. Types that don't have a size are
59+
abstract types and void.
60+
}];
61+
62+
let cppNamespace = "::cir";
63+
64+
let methods = [
65+
InterfaceMethod<[{
66+
Returns true if this is a sized type. This mirrors sizedness from the
67+
clang AST, where a type is sized if it has a known size.
68+
69+
By default type defining this interface returns true,
70+
but this can be overridden if sizedness depends on properties of the type.
71+
For example, whether a struct is not sized if it is incomplete.
72+
}],
73+
/*retTy=*/"bool",
74+
/*methodName=*/"isSized",
75+
/*args=*/(ins),
76+
/*methodBody=*/"",
77+
/*defaultImplementation=*/[{
78+
return true;
79+
}]
80+
>,
81+
];
82+
}
83+
84+
#endif // CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD

clang/include/clang/CIR/Interfaces/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ endfunction()
3131
add_clang_mlir_attr_interface(ASTAttrInterfaces)
3232
add_clang_mlir_op_interface(CIROpInterfaces)
3333
add_clang_mlir_op_interface(CIRLoopOpInterface)
34-
add_clang_mlir_type_interface(CIRFPTypeInterface)
34+
add_clang_mlir_type_interface(CIRTypeInterfaces)

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -527,18 +527,6 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
527527
return getCompleteRecordTy(members, name, packed, padded, ast);
528528
}
529529

530-
bool isSized(mlir::Type ty) {
531-
if (mlir::isa<cir::PointerType, cir::RecordType, cir::ArrayType,
532-
cir::BoolType, cir::IntType, cir::CIRFPTypeInterface,
533-
cir::ComplexType>(ty))
534-
return true;
535-
if (mlir::isa<cir::VectorType>(ty)) {
536-
return isSized(mlir::cast<cir::VectorType>(ty).getElementType());
537-
}
538-
assert(0 && "Unimplemented size for type");
539-
return false;
540-
}
541-
542530
//
543531
// Constant creation helpers
544532
// -------------------------

0 commit comments

Comments
 (0)