Skip to content

Commit 4e7a223

Browse files
authored
[CIR] Rename cir.struct to cir.record and associated changes (#1559)
During the initial upstreaming of `cir.struct` support, a request was made to rename `cir.struct` to `cir.record` for consistency with its multiple uses. This change makes the modification along with renaming various other related classes. I've attempted to also update variable names and comments to keep everything consistent. This creates an unfortunate name collision between cir::RecordType and clang::RecordType, but the impact of that overlaps was relatively small. The only intended behavioral change is in the names used in the emitted CIR files and diagnostics.
1 parent 6502f55 commit 4e7a223

File tree

126 files changed

+1017
-1019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1017
-1019
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
143143
return getZeroAttr(arrTy);
144144
if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
145145
return getConstNullPtrAttr(ptrTy);
146-
if (auto structTy = mlir::dyn_cast<cir::StructType>(ty))
147-
return getZeroAttr(structTy);
146+
if (auto RecordTy = mlir::dyn_cast<cir::RecordType>(ty))
147+
return getZeroAttr(RecordTy);
148148
if (auto methodTy = mlir::dyn_cast<cir::MethodType>(ty))
149149
return getNullMethodAttr(methodTy);
150150
if (mlir::isa<cir::BoolType>(ty)) {
@@ -496,16 +496,16 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
496496
return createCast(cir::CastKind::int_to_ptr, src, newTy);
497497
}
498498

499-
mlir::Value createGetMemberOp(mlir::Location &loc, mlir::Value structPtr,
499+
mlir::Value createGetMemberOp(mlir::Location &loc, mlir::Value recordPtr,
500500
const char *fldName, unsigned idx) {
501501

502-
assert(mlir::isa<cir::PointerType>(structPtr.getType()));
503-
auto structBaseTy =
504-
mlir::cast<cir::PointerType>(structPtr.getType()).getPointee();
505-
assert(mlir::isa<cir::StructType>(structBaseTy));
506-
auto fldTy = mlir::cast<cir::StructType>(structBaseTy).getMembers()[idx];
502+
assert(mlir::isa<cir::PointerType>(recordPtr.getType()));
503+
auto recordBaseTy =
504+
mlir::cast<cir::PointerType>(recordPtr.getType()).getPointee();
505+
assert(mlir::isa<cir::RecordType>(recordBaseTy));
506+
auto fldTy = mlir::cast<cir::RecordType>(recordBaseTy).getMembers()[idx];
507507
auto fldPtrTy = cir::PointerType::get(getContext(), fldTy);
508-
return create<cir::GetMemberOp>(loc, fldPtrTy, structPtr, fldName, idx);
508+
return create<cir::GetMemberOp>(loc, fldPtrTy, recordPtr, fldName, idx);
509509
}
510510

511511
mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RecordDecl;
3737

3838
namespace cir {
3939
class ArrayType;
40-
class StructType;
40+
class RecordType;
4141
class BoolType;
4242
} // namespace cir
4343

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -331,37 +331,37 @@ def ConstVectorAttr : CIR_Attr<"ConstVector", "const_vector",
331331
}
332332

333333
//===----------------------------------------------------------------------===//
334-
// ConstStructAttr
334+
// ConstRecordAttr
335335
//===----------------------------------------------------------------------===//
336336

337-
def ConstStructAttr : CIR_Attr<"ConstStruct", "const_struct",
337+
def ConstRecordAttr : CIR_Attr<"ConstRecord", "const_record",
338338
[TypedAttrInterface]> {
339-
let summary = "Represents a constant struct";
339+
let summary = "Represents a constant record";
340340
let description = [{
341341
Effectively supports "struct-like" constants. It's must be built from
342342
an `mlir::ArrayAttr `instance where each elements is a typed attribute
343343
(`mlir::TypedAttribute`).
344344

345345
Example:
346346
```
347-
cir.global external @rgb2 = #cir.const_struct<{0 : i8,
347+
cir.global external @rgb2 = #cir.const_record<{0 : i8,
348348
5 : i64, #cir.null : !cir.ptr<i8>
349-
}> : !cir.struct<"", i8, i64, !cir.ptr<i8>>
349+
}> : !cir.record<"", i8, i64, !cir.ptr<i8>>
350350
```
351351
}];
352352

353353
let parameters = (ins AttributeSelfTypeParameter<"">:$type,
354354
"mlir::ArrayAttr":$members);
355355

356356
let builders = [
357-
AttrBuilderWithInferredContext<(ins "cir::StructType":$type,
357+
AttrBuilderWithInferredContext<(ins "cir::RecordType":$type,
358358
"mlir::ArrayAttr":$members), [{
359359
return $_get(type.getContext(), type, members);
360360
}]>
361361
];
362362

363363
let assemblyFormat = [{
364-
`<` custom<StructMembers>($members) `>`
364+
`<` custom<RecordMembers>($members) `>`
365365
}];
366366

367367
let genVerifyDecl = 1;
@@ -576,7 +576,7 @@ def DataMemberAttr : CIR_Attr<"DataMember", "data_member",
576576
pointer-to-data-member value.
577577

578578
The `member_index` parameter represents the index of the pointed-to member
579-
within its containing struct. It is an optional parameter; lack of this
579+
within its containing record. It is an optional parameter; lack of this
580580
parameter indicates a null pointer-to-data-member value.
581581

582582
Example:
@@ -687,7 +687,7 @@ def GlobalViewAttr : CIR_Attr<"GlobalView", "global_view", [TypedAttrInterface]>
687687

688688
A list of indices can be optionally passed and each element subsequently
689689
indexes underlying types. For `symbol` types like `!cir.array`
690-
and `!cir.struct`, it leads to the constant address of sub-elements, while
690+
and `!cir.record`, it leads to the constant address of sub-elements, while
691691
for `!cir.ptr`, an offset is applied. The first index is relative to the
692692
original symbol type, not the produced one.
693693

@@ -764,9 +764,9 @@ def TypeInfoAttr : CIR_Attr<"TypeInfo", "typeinfo", [TypedAttrInterface]> {
764764
layout is determined by the C++ ABI used (clang only implements
765765
itanium on CIRGen).
766766

767-
The verifier enforces that the output type is always a `!cir.struct`,
767+
The verifier enforces that the output type is always a `!cir.record`,
768768
and that the ArrayAttr element types match the equivalent member type
769-
for the resulting struct, i.e, a GlobalViewAttr for symbol reference or
769+
for the resulting record, i.e, a GlobalViewAttr for symbol reference or
770770
an IntAttr for flags.
771771

772772
Example:
@@ -776,7 +776,7 @@ def TypeInfoAttr : CIR_Attr<"TypeInfo", "typeinfo", [TypedAttrInterface]> {
776776

777777
cir.global external @type_info_B = #cir.typeinfo<<
778778
{#cir.global_view<@_ZTVN10__cxxabiv120__si_class_type_infoE, [2]> : !cir.ptr<i8>}
779-
>> : !cir.struct<"", !cir.ptr<i8>>
779+
>> : !cir.record<"", !cir.ptr<i8>>
780780
```
781781
}];
782782

@@ -790,11 +790,11 @@ def TypeInfoAttr : CIR_Attr<"TypeInfo", "typeinfo", [TypedAttrInterface]> {
790790
}]>
791791
];
792792

793-
// Checks struct element types should match the array for every equivalent
793+
// Checks record element types should match the array for every equivalent
794794
// element type.
795795
let genVerifyDecl = 1;
796796
let assemblyFormat = [{
797-
`<` custom<StructMembers>($data) `>`
797+
`<` custom<RecordMembers>($data) `>`
798798
}];
799799
}
800800

@@ -805,7 +805,7 @@ def TypeInfoAttr : CIR_Attr<"TypeInfo", "typeinfo", [TypedAttrInterface]> {
805805
def VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
806806
let summary = "Represents a C++ vtable";
807807
let description = [{
808-
Wraps a #cir.const_struct containing vtable data.
808+
Wraps a #cir.const_record containing vtable data.
809809

810810
Example:
811811
```
@@ -816,11 +816,11 @@ def VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
816816
#cir.global_view<@_ZN1BD0Ev> : !cir.ptr<i8>,
817817
#cir.global_view<@_ZNK1A5quackEv> : !cir.ptr<i8>]>
818818
: !cir.array<!cir.ptr<i8> x 5>}>>
819-
: !cir.struct<"", !cir.array<!cir.ptr<i8> x 5>>
819+
: !cir.record<"", !cir.array<!cir.ptr<i8> x 5>>
820820
```
821821
}];
822822

823-
// `vtable_data` is const struct with one element, containing an array of
823+
// `vtable_data` is const record with one element, containing an array of
824824
// vtable information.
825825
let parameters = (ins AttributeSelfTypeParameter<"">:$type,
826826
"mlir::ArrayAttr":$vtable_data);
@@ -834,21 +834,21 @@ def VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
834834

835835
let genVerifyDecl = 1;
836836
let assemblyFormat = [{
837-
`<` custom<StructMembers>($vtable_data) `>`
837+
`<` custom<RecordMembers>($vtable_data) `>`
838838
}];
839839
}
840840

841841
//===----------------------------------------------------------------------===//
842-
// StructLayoutAttr
842+
// RecordLayoutAttr
843843
//===----------------------------------------------------------------------===//
844844

845-
// Used to decouple layout information from the struct type. StructType's
845+
// Used to decouple layout information from the record type. RecordType's
846846
// uses this attribute to cache that information.
847847

848-
def StructLayoutAttr : CIR_Attr<"StructLayout", "struct_layout"> {
849-
let summary = "ABI specific information about a struct layout";
848+
def RecordLayoutAttr : CIR_Attr<"RecordLayout", "record_layout"> {
849+
let summary = "ABI specific information about a record layout";
850850
let description = [{
851-
Holds layout information often queried by !cir.struct users
851+
Holds layout information often queried by !cir.record users
852852
during lowering passes and optimizations.
853853
}];
854854

@@ -888,7 +888,7 @@ def DynamicCastInfoAttr
888888
Provide ABI specific information about a dynamic cast operation.
889889

890890
The `srcRtti` and the `destRtti` parameters give the RTTI of the source
891-
struct type and the destination struct type, respectively.
891+
record type and the destination record type, respectively.
892892

893893
The `runtimeFunc` parameter gives the `__dynamic_cast` function which is
894894
provided by the runtime. The `badCastFunc` parameter gives the

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace cir {
2424

25-
class StructLayout;
25+
class RecordLayout;
2626

2727
// FIXME(cir): This might be replaced by a CIRDataLayout interface which can
2828
// provide the same functionalities.
@@ -31,9 +31,9 @@ class CIRDataLayout {
3131

3232
/// Primitive type alignment data. This is sorted by type and bit
3333
/// width during construction.
34-
llvm::DataLayout::PrimitiveSpec StructAlignment;
34+
llvm::DataLayout::PrimitiveSpec RecordAlignment;
3535

36-
// The StructType -> StructLayout map.
36+
// The RecordType -> RecordLayout map.
3737
mutable void *LayoutMap = nullptr;
3838

3939
TypeSizeInfoAttr typeSizeInfo;
@@ -52,11 +52,11 @@ class CIRDataLayout {
5252

5353
bool isBigEndian() const { return bigEndian; }
5454

55-
/// Returns a StructLayout object, indicating the alignment of the
56-
/// struct, its size, and the offsets of its fields.
55+
/// Returns a RecordLayout object, indicating the alignment of the
56+
/// record, its size, and the offsets of its fields.
5757
///
5858
/// Note that this information is lazily cached.
59-
const StructLayout *getStructLayout(cir::StructType Ty) const;
59+
const RecordLayout *getRecordLayout(cir::RecordType Ty) const;
6060

6161
/// Internal helper method that returns requested alignment for type.
6262
llvm::Align getAlignment(mlir::Type Ty, bool abiOrPref) const;
@@ -121,21 +121,21 @@ class CIRDataLayout {
121121

122122
/// Used to lazily calculate structure layout information for a target machine,
123123
/// based on the DataLayout structure.
124-
class StructLayout final
125-
: public llvm::TrailingObjects<StructLayout, llvm::TypeSize> {
126-
llvm::TypeSize StructSize;
127-
llvm::Align StructAlignment;
124+
class RecordLayout final
125+
: public llvm::TrailingObjects<RecordLayout, llvm::TypeSize> {
126+
llvm::TypeSize RecordSize;
127+
llvm::Align RecordAlignment;
128128
unsigned IsPadded : 1;
129129
unsigned NumElements : 31;
130130

131131
public:
132-
llvm::TypeSize getSizeInBytes() const { return StructSize; }
132+
llvm::TypeSize getSizeInBytes() const { return RecordSize; }
133133

134-
llvm::TypeSize getSizeInBits() const { return 8 * StructSize; }
134+
llvm::TypeSize getSizeInBits() const { return 8 * RecordSize; }
135135

136-
llvm::Align getAlignment() const { return StructAlignment; }
136+
llvm::Align getAlignment() const { return RecordAlignment; }
137137

138-
/// Returns whether the struct has padding or not between its fields.
138+
/// Returns whether the record has padding or not between its fields.
139139
/// NB: Padding in nested element is not taken into account.
140140
bool hasPadding() const { return IsPadded; }
141141

@@ -164,7 +164,7 @@ class StructLayout final
164164
private:
165165
friend class CIRDataLayout; // Only DataLayout can create this class
166166

167-
StructLayout(cir::StructType ST, const CIRDataLayout &DL);
167+
RecordLayout(cir::RecordType ST, const CIRDataLayout &DL);
168168

169169
size_t numTrailingObjects(OverloadToken<llvm::TypeSize>) const {
170170
return NumElements;

0 commit comments

Comments
 (0)