Skip to content

[CIR] Rename cir.struct to cir.record and associated changes #1559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return getZeroAttr(arrTy);
if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
return getConstNullPtrAttr(ptrTy);
if (auto structTy = mlir::dyn_cast<cir::StructType>(ty))
return getZeroAttr(structTy);
if (auto RecordTy = mlir::dyn_cast<cir::RecordType>(ty))
return getZeroAttr(RecordTy);
if (auto methodTy = mlir::dyn_cast<cir::MethodType>(ty))
return getNullMethodAttr(methodTy);
if (mlir::isa<cir::BoolType>(ty)) {
Expand Down Expand Up @@ -496,16 +496,16 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return createCast(cir::CastKind::int_to_ptr, src, newTy);
}

mlir::Value createGetMemberOp(mlir::Location &loc, mlir::Value structPtr,
mlir::Value createGetMemberOp(mlir::Location &loc, mlir::Value recordPtr,
const char *fldName, unsigned idx) {

assert(mlir::isa<cir::PointerType>(structPtr.getType()));
auto structBaseTy =
mlir::cast<cir::PointerType>(structPtr.getType()).getPointee();
assert(mlir::isa<cir::StructType>(structBaseTy));
auto fldTy = mlir::cast<cir::StructType>(structBaseTy).getMembers()[idx];
assert(mlir::isa<cir::PointerType>(recordPtr.getType()));
auto recordBaseTy =
mlir::cast<cir::PointerType>(recordPtr.getType()).getPointee();
assert(mlir::isa<cir::RecordType>(recordBaseTy));
auto fldTy = mlir::cast<cir::RecordType>(recordBaseTy).getMembers()[idx];
auto fldPtrTy = cir::PointerType::get(getContext(), fldTy);
return create<cir::GetMemberOp>(loc, fldPtrTy, structPtr, fldName, idx);
return create<cir::GetMemberOp>(loc, fldPtrTy, recordPtr, fldName, idx);
}

mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy) {
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RecordDecl;

namespace cir {
class ArrayType;
class StructType;
class RecordType;
class BoolType;
} // namespace cir

Expand Down
48 changes: 24 additions & 24 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -331,37 +331,37 @@ def ConstVectorAttr : CIR_Attr<"ConstVector", "const_vector",
}

//===----------------------------------------------------------------------===//
// ConstStructAttr
// ConstRecordAttr
//===----------------------------------------------------------------------===//

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

Example:
```
cir.global external @rgb2 = #cir.const_struct<{0 : i8,
cir.global external @rgb2 = #cir.const_record<{0 : i8,
5 : i64, #cir.null : !cir.ptr<i8>
}> : !cir.struct<"", i8, i64, !cir.ptr<i8>>
}> : !cir.record<"", i8, i64, !cir.ptr<i8>>
```
}];

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

let builders = [
AttrBuilderWithInferredContext<(ins "cir::StructType":$type,
AttrBuilderWithInferredContext<(ins "cir::RecordType":$type,
"mlir::ArrayAttr":$members), [{
return $_get(type.getContext(), type, members);
}]>
];

let assemblyFormat = [{
`<` custom<StructMembers>($members) `>`
`<` custom<RecordMembers>($members) `>`
}];

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

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

Example:
Expand Down Expand Up @@ -687,7 +687,7 @@ def GlobalViewAttr : CIR_Attr<"GlobalView", "global_view", [TypedAttrInterface]>

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

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

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

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

cir.global external @type_info_B = #cir.typeinfo<<
{#cir.global_view<@_ZTVN10__cxxabiv120__si_class_type_infoE, [2]> : !cir.ptr<i8>}
>> : !cir.struct<"", !cir.ptr<i8>>
>> : !cir.record<"", !cir.ptr<i8>>
```
}];

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

// Checks struct element types should match the array for every equivalent
// Checks record element types should match the array for every equivalent
// element type.
let genVerifyDecl = 1;
let assemblyFormat = [{
`<` custom<StructMembers>($data) `>`
`<` custom<RecordMembers>($data) `>`
}];
}

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

Example:
```
Expand All @@ -816,11 +816,11 @@ def VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
#cir.global_view<@_ZN1BD0Ev> : !cir.ptr<i8>,
#cir.global_view<@_ZNK1A5quackEv> : !cir.ptr<i8>]>
: !cir.array<!cir.ptr<i8> x 5>}>>
: !cir.struct<"", !cir.array<!cir.ptr<i8> x 5>>
: !cir.record<"", !cir.array<!cir.ptr<i8> x 5>>
```
}];

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

let genVerifyDecl = 1;
let assemblyFormat = [{
`<` custom<StructMembers>($vtable_data) `>`
`<` custom<RecordMembers>($vtable_data) `>`
}];
}

//===----------------------------------------------------------------------===//
// StructLayoutAttr
// RecordLayoutAttr
//===----------------------------------------------------------------------===//

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

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

Expand Down Expand Up @@ -888,7 +888,7 @@ def DynamicCastInfoAttr
Provide ABI specific information about a dynamic cast operation.

The `srcRtti` and the `destRtti` parameters give the RTTI of the source
struct type and the destination struct type, respectively.
record type and the destination record type, respectively.

The `runtimeFunc` parameter gives the `__dynamic_cast` function which is
provided by the runtime. The `badCastFunc` parameter gives the
Expand Down
30 changes: 15 additions & 15 deletions clang/include/clang/CIR/Dialect/IR/CIRDataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace cir {

class StructLayout;
class RecordLayout;

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

/// Primitive type alignment data. This is sorted by type and bit
/// width during construction.
llvm::DataLayout::PrimitiveSpec StructAlignment;
llvm::DataLayout::PrimitiveSpec RecordAlignment;

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

TypeSizeInfoAttr typeSizeInfo;
Expand All @@ -52,11 +52,11 @@ class CIRDataLayout {

bool isBigEndian() const { return bigEndian; }

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

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

/// Used to lazily calculate structure layout information for a target machine,
/// based on the DataLayout structure.
class StructLayout final
: public llvm::TrailingObjects<StructLayout, llvm::TypeSize> {
llvm::TypeSize StructSize;
llvm::Align StructAlignment;
class RecordLayout final
: public llvm::TrailingObjects<RecordLayout, llvm::TypeSize> {
llvm::TypeSize RecordSize;
llvm::Align RecordAlignment;
unsigned IsPadded : 1;
unsigned NumElements : 31;

public:
llvm::TypeSize getSizeInBytes() const { return StructSize; }
llvm::TypeSize getSizeInBytes() const { return RecordSize; }

llvm::TypeSize getSizeInBits() const { return 8 * StructSize; }
llvm::TypeSize getSizeInBits() const { return 8 * RecordSize; }

llvm::Align getAlignment() const { return StructAlignment; }
llvm::Align getAlignment() const { return RecordAlignment; }

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

Expand Down Expand Up @@ -164,7 +164,7 @@ class StructLayout final
private:
friend class CIRDataLayout; // Only DataLayout can create this class

StructLayout(cir::StructType ST, const CIRDataLayout &DL);
RecordLayout(cir::RecordType ST, const CIRDataLayout &DL);

size_t numTrailingObjects(OverloadToken<llvm::TypeSize>) const {
return NumElements;
Expand Down
Loading
Loading