Skip to content

Commit ca8c49f

Browse files
committed
Change cir.struct to cir.record
1 parent 5e85698 commit ca8c49f

File tree

12 files changed

+95
-105
lines changed

12 files changed

+95
-105
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace cir {
2222

2323
namespace detail {
24-
struct StructTypeStorage;
24+
struct RecordTypeStorage;
2525
} // namespace detail
2626

2727
bool isAnyFloatingPointType(mlir::Type t);

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

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -401,52 +401,51 @@ def VoidPtr : Type<
401401
}
402402

403403
//===----------------------------------------------------------------------===//
404-
// StructType
404+
// RecordType
405405
//
406406
// The base type for all RecordDecls.
407407
//===----------------------------------------------------------------------===//
408408

409-
def CIR_StructType : CIR_Type<"Struct", "struct",
409+
def CIR_RecordType : CIR_Type<"Record", "record",
410410
[
411411
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
412412
MutableType,
413413
]> {
414-
let summary = "CIR struct type";
414+
let summary = "CIR record type";
415415
let description = [{
416-
Each unique clang::RecordDecl is mapped to a `cir.struct` and any object in
417-
C/C++ that has a struct type will have a `cir.struct` in CIR.
416+
Each unique clang::RecordDecl is mapped to a `cir.record` and any object in
417+
C/C++ that has a struct or class type will have a `cir.record` in CIR.
418418

419419
There are three possible formats for this type:
420420

421-
- Identified and complete structs: unique name and a known body.
422-
- Identified and incomplete structs: unique name and unknown body.
423-
- Anonymous structs: no name and a known body.
421+
- Identified and complete records: unique name and a known body.
422+
- Identified and incomplete records: unique name and unknown body.
423+
- Anonymous records: no name and a known body.
424424

425-
Identified structs are uniqued by their name, and anonymous structs are
426-
uniqued by their body. This means that two anonymous structs with the same
427-
body will be the same type, and two identified structs with the same name
428-
will be the same type. Attempting to build a struct with an existing name,
425+
Identified records are uniqued by their name, and anonymous records are
426+
uniqued by their body. This means that two anonymous records with the same
427+
body will be the same type, and two identified records with the same name
428+
will be the same type. Attempting to build a record with an existing name,
429429
but a different body will result in an error.
430430

431431
A few examples:
432432

433433
```mlir
434-
!complete = !cir.struct<struct "complete" {!cir.int<u, 8>}>
435-
!incomplete = !cir.struct<struct "incomplete" incomplete>
436-
!anonymous = !cir.struct<struct {!cir.int<u, 8>}>
434+
!complete = !cir.record<struct "complete" {!cir.int<u, 8>}>
435+
!incomplete = !cir.record<struct "incomplete" incomplete>
436+
!anonymous = !cir.record<struct {!cir.int<u, 8>}>
437437
```
438438

439-
Incomplete structs are mutable, meaning they can be later completed with a
439+
Incomplete records are mutable, meaning they can be later completed with a
440440
body automatically updating in place every type in the code that uses the
441-
incomplete struct. Mutability allows for recursive types to be represented,
442-
meaning the struct can have members that refer to itself. This is useful for
441+
incomplete record. Mutability allows for recursive types to be represented,
442+
meaning the record can have members that refer to itself. This is useful for
443443
representing recursive records and is implemented through a special syntax.
444-
In the example below, the `Node` struct has a member that is a pointer to a
445-
`Node` struct:
444+
In the example below, the `Node` record has a member that is a pointer to a
445+
`Node` record:
446446

447447
```mlir
448-
!struct = !cir.struct<struct "Node" {!cir.ptr<!cir.struct<struct
449-
"Node">>}>
448+
!s = !cir.record<struct "Node" {!cir.ptr<!cir.record<struct "Node">>}>
450449
```
451450
}];
452451

@@ -456,18 +455,18 @@ def CIR_StructType : CIR_Type<"Struct", "struct",
456455
"bool":$incomplete,
457456
"bool":$packed,
458457
"bool":$padded,
459-
"StructType::RecordKind":$kind
458+
"RecordType::RecordKind":$kind
460459
);
461460

462461
// StorageClass is defined in C++ for mutability.
463-
let storageClass = "StructTypeStorage";
462+
let storageClass = "RecordTypeStorage";
464463
let genStorageClass = 0;
465464

466465
let skipDefaultBuilders = 1;
467466
let genVerifyDecl = 1;
468467

469468
let builders = [
470-
// Create an identified and incomplete struct type.
469+
// Create an identified and incomplete record type.
471470
TypeBuilder<(ins
472471
"mlir::StringAttr":$name,
473472
"RecordKind":$kind
@@ -480,9 +479,8 @@ def CIR_StructType : CIR_Type<"Struct", "struct",
480479
let extraClassDeclaration = [{
481480
using Base::verifyInvariants;
482481

483-
enum RecordKind : uint32_t { Class, Union, Struct };
482+
enum RecordKind : uint32_t { Struct, Union };
484483

485-
bool isClass() const { return getKind() == RecordKind::Class; };
486484
bool isStruct() const { return getKind() == RecordKind::Struct; };
487485
bool isUnion() const { return getKind() == RecordKind::Union; };
488486
bool isComplete() const { return !isIncomplete(); };
@@ -491,14 +489,12 @@ def CIR_StructType : CIR_Type<"Struct", "struct",
491489
size_t getNumElements() const { return getMembers().size(); };
492490
std::string getKindAsStr() {
493491
switch (getKind()) {
494-
case RecordKind::Class:
495-
return "class";
496492
case RecordKind::Union:
497493
return "union";
498494
case RecordKind::Struct:
499495
return "struct";
500496
}
501-
llvm_unreachable("Invalid value for StructType::getKind()");
497+
llvm_unreachable("Invalid value for RecordType::getKind()");
502498
}
503499
std::string getPrefixedName() {
504500
return getKindAsStr() + "." + getName().getValue().str();
@@ -508,18 +504,18 @@ def CIR_StructType : CIR_Type<"Struct", "struct",
508504
let hasCustomAssemblyFormat = 1;
509505
}
510506

511-
// Note CIRStructType is used instead of CIR_StructType
507+
// Note CIRRecordType is used instead of CIR_RecordType
512508
// because of tablegen conflicts.
513-
def CIRStructType : Type<
514-
CPred<"::mlir::isa<::cir::StructType>($_self)">, "CIR struct type">;
509+
def CIRRecordType : Type<
510+
CPred<"::mlir::isa<::cir::RecordType>($_self)">, "CIR record type">;
515511

516512
//===----------------------------------------------------------------------===//
517513
// Global type constraints
518514
//===----------------------------------------------------------------------===//
519515

520516
def CIR_AnyType : AnyTypeOf<[
521517
CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_IntType, CIR_AnyFloat,
522-
CIR_PointerType, CIR_FuncType, CIR_StructType
518+
CIR_PointerType, CIR_FuncType, CIR_RecordType
523519
]>;
524520

525521
#endif // MLIR_CIR_DIALECT_CIR_TYPES

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ namespace cir {
2222
namespace detail {
2323

2424
//===----------------------------------------------------------------------===//
25-
// CIR StructTypeStorage
25+
// CIR RecordTypeStorage
2626
//===----------------------------------------------------------------------===//
2727

2828
/// Type storage for CIR record types.
29-
struct StructTypeStorage : public mlir::TypeStorage {
29+
struct RecordTypeStorage : public mlir::TypeStorage {
3030
struct KeyTy {
3131
llvm::ArrayRef<mlir::Type> members;
3232
mlir::StringAttr name;
3333
bool incomplete;
3434
bool packed;
3535
bool padded;
36-
StructType::RecordKind kind;
36+
RecordType::RecordKind kind;
3737

3838
KeyTy(llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name,
3939
bool incomplete, bool packed, bool padded,
40-
StructType::RecordKind kind)
40+
RecordType::RecordKind kind)
4141
: members(members), name(name), incomplete(incomplete), packed(packed),
4242
padded(padded), kind(kind) {}
4343
};
@@ -47,14 +47,14 @@ struct StructTypeStorage : public mlir::TypeStorage {
4747
bool incomplete;
4848
bool packed;
4949
bool padded;
50-
StructType::RecordKind kind;
50+
RecordType::RecordKind kind;
5151

52-
StructTypeStorage(llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name,
52+
RecordTypeStorage(llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name,
5353
bool incomplete, bool packed, bool padded,
54-
StructType::RecordKind kind)
54+
RecordType::RecordKind kind)
5555
: members(members), name(name), incomplete(incomplete), packed(packed),
5656
padded(padded), kind(kind) {
57-
assert(name || !incomplete && "Incomplete structs must have a name");
57+
assert(name || !incomplete && "Incomplete records must have a name");
5858
}
5959

6060
KeyTy getAsKey() const {
@@ -76,33 +76,33 @@ struct StructTypeStorage : public mlir::TypeStorage {
7676
key.padded, key.kind);
7777
}
7878

79-
static StructTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
79+
static RecordTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
8080
const KeyTy &key) {
81-
return new (allocator.allocate<StructTypeStorage>())
82-
StructTypeStorage(allocator.copyInto(key.members), key.name,
81+
return new (allocator.allocate<RecordTypeStorage>())
82+
RecordTypeStorage(allocator.copyInto(key.members), key.name,
8383
key.incomplete, key.packed, key.padded, key.kind);
8484
}
8585

86-
/// Mutates the members and attributes an identified struct.
86+
/// Mutates the members and attributes an identified record.
8787
///
8888
/// Once a record is mutated, it is marked as complete, preventing further
89-
/// mutations. Anonymous structs are always complete and cannot be mutated.
90-
/// This method does not fail if a mutation of a complete struct does not
91-
/// change the struct.
89+
/// mutations. Anonymous records are always complete and cannot be mutated.
90+
/// This method does not fail if a mutation of a complete record does not
91+
/// change the record.
9292
llvm::LogicalResult mutate(mlir::TypeStorageAllocator &allocator,
9393
llvm::ArrayRef<mlir::Type> members, bool packed,
9494
bool padded) {
95-
// Anonymous structs cannot mutate.
95+
// Anonymous records cannot mutate.
9696
if (!name)
9797
return llvm::failure();
9898

99-
// Mutation of complete structs are allowed if they change nothing.
99+
// Mutation of complete records are allowed if they change nothing.
100100
if (!incomplete)
101101
return mlir::success((this->members == members) &&
102102
(this->packed == packed) &&
103103
(this->padded == padded));
104104

105-
// Mutate incomplete struct.
105+
// Mutate incomplete record.
106106
this->members = allocator.copyInto(members);
107107
this->packed = packed;
108108
this->padded = padded;

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ struct MissingFeatures {
101101
static bool mayHaveIntegerOverflow() { return false; }
102102
static bool shouldReverseUnaryCondOnBoolExpr() { return false; }
103103

104-
// StructType
105-
static bool structTypeLayoutInfo() { return false; }
104+
// RecordType
105+
static bool recordTypeLayoutInfo() { return false; }
106106

107107
// Misc
108108
static bool cxxABI() { return false; }

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
5151
}
5252

5353
/// Get a CIR record kind from a AST declaration tag.
54-
cir::StructType::RecordKind getRecordKind(const clang::TagTypeKind kind) {
54+
cir::RecordType::RecordKind getRecordKind(const clang::TagTypeKind kind) {
5555
switch (kind) {
56+
case clang::TagTypeKind::Class:
5657
case clang::TagTypeKind::Struct:
57-
return cir::StructType::Struct;
58+
return cir::RecordType::Struct;
5859
case clang::TagTypeKind::Union:
59-
return cir::StructType::Union;
60-
case clang::TagTypeKind::Class:
61-
return cir::StructType::Class;
60+
return cir::RecordType::Union;
6261
case clang::TagTypeKind::Interface:
6362
llvm_unreachable("interface records are NYI");
6463
case clang::TagTypeKind::Enum:
@@ -69,13 +68,13 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
6968
/// Get an incomplete CIR struct type. If we have a complete record
7069
/// declaration, we may create an incomplete type and then add the
7170
/// members, so \p rd here may be complete.
72-
cir::StructType getIncompleteStructTy(llvm::StringRef name,
71+
cir::RecordType getIncompleteRecordTy(llvm::StringRef name,
7372
const clang::RecordDecl *rd) {
7473
const mlir::StringAttr nameAttr = getStringAttr(name);
75-
cir::StructType::RecordKind kind = cir::StructType::RecordKind::Struct;
74+
cir::RecordType::RecordKind kind = cir::RecordType::RecordKind::Struct;
7675
if (rd)
7776
kind = getRecordKind(rd->getTagKind());
78-
return getType<cir::StructType>(nameAttr, kind);
77+
return getType<cir::RecordType>(nameAttr, kind);
7978
}
8079

8180
bool isSized(mlir::Type ty) {

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) {
117117
// TagDecl's are not necessarily unique, instead use the (clang) type
118118
// connected to the decl.
119119
const Type *key = astContext.getTagDeclType(rd).getTypePtr();
120-
cir::StructType entry = recordDeclTypes[key];
120+
cir::RecordType entry = recordDeclTypes[key];
121121

122122
// If we don't have an entry for this record yet, create one.
123123
// We create an incomplete type initially. If `rd` is complete, we will
124124
// add the members below.
125125
if (!entry) {
126126
auto name = getRecordTypeName(rd, "");
127-
entry = builder.getIncompleteStructTy(name, rd);
127+
entry = builder.getIncompleteRecordTy(name, rd);
128128
recordDeclTypes[key] = entry;
129129
}
130130

clang/lib/CIR/CodeGen/CIRGenTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CIRGenTypes {
4646
CIRGenBuilderTy &builder;
4747

4848
/// Contains the CIR type for any converted RecordDecl
49-
llvm::DenseMap<const clang::Type *, cir::StructType> recordDeclTypes;
49+
llvm::DenseMap<const clang::Type *, cir::RecordType> recordDeclTypes;
5050

5151
/// Hold memoized CIRGenFunctionInfo results
5252
llvm::FoldingSet<CIRGenFunctionInfo> functionInfos;

0 commit comments

Comments
 (0)