From 0a54d446364d531411da8a5f66975a9892475e35 Mon Sep 17 00:00:00 2001 From: Vinicius Couto Espindola Date: Fri, 11 Aug 2023 17:08:16 -0300 Subject: [PATCH] [CIR] Refactor StructType printing/parsing This change simplifies the StructType printing/parsing methods. It also updates the representations to group members between braces and to remove commas between type attributes (e.g. id, packed, etc.). [ghstack-poisoned] --- .../include/clang/CIR/Dialect/IR/CIRTypes.td | 12 -- clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 37 ++++--- clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 104 +++++++++--------- clang/test/CIR/CodeGen/agg-init.cpp | 4 +- clang/test/CIR/CodeGen/atomic.cpp | 2 +- clang/test/CIR/CodeGen/bitfields.cpp | 4 +- clang/test/CIR/CodeGen/coro-task.cpp | 14 +-- clang/test/CIR/CodeGen/ctor.cpp | 2 +- clang/test/CIR/CodeGen/derived-to-base.cpp | 4 +- clang/test/CIR/CodeGen/dtors.cpp | 4 +- clang/test/CIR/CodeGen/lambda.cpp | 2 +- clang/test/CIR/CodeGen/move.cpp | 2 +- clang/test/CIR/CodeGen/nrvo.cpp | 2 +- clang/test/CIR/CodeGen/rangefor.cpp | 6 +- clang/test/CIR/CodeGen/struct.c | 4 +- clang/test/CIR/CodeGen/struct.cpp | 12 +- clang/test/CIR/CodeGen/union.cpp | 10 +- clang/test/CIR/CodeGen/vtable-rtti.cpp | 8 +- clang/test/CIR/IR/global.cir | 7 +- clang/test/CIR/IR/invalid.cir | 2 +- clang/test/CIR/IR/struct.cir | 16 +-- clang/test/CIR/IR/vtableAttr.cir | 2 +- clang/test/CIR/Lowering/globals.cir | 2 +- clang/test/CIR/Lowering/struct.cir | 10 +- clang/test/CIR/Lowering/variadics.cir | 2 +- 25 files changed, 132 insertions(+), 142 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td index b84c9222be41..178d944f1df7 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td @@ -113,18 +113,6 @@ def CIR_StructType : CIR_Type<"Struct", "struct", "std::optional<::mlir::cir::ASTRecordDeclAttr>":$ast ); - let builders = [ - TypeBuilder<(ins - "ArrayRef":$members, "StringRef":$typeName, - "bool":$body - ), [{ - auto id = mlir::StringAttr::get(context, typeName); - auto sTy = StructType::get(context, members, id, body, - /*packed=*/false, std::nullopt); - return sTy; - }]> - ]; - let hasCustomAssemblyFormat = 1; let extraClassDeclaration = [{ diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index ea1908495d05..a03262eab335 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -14,6 +14,7 @@ #include "clang/CIR/Dialect/IR/CIRAttrs.h" #include "clang/CIR/Dialect/IR/CIROpsEnums.h" #include "clang/CIR/Dialect/IR/CIRTypes.h" +#include #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMTypes.h" @@ -1150,7 +1151,7 @@ LogicalResult LoopOp::verify() { static void printGlobalOpTypeAndInitialValue(OpAsmPrinter &p, GlobalOp op, TypeAttr type, Attribute initAttr, - mlir::Region& ctorRegion) { + mlir::Region &ctorRegion) { auto printType = [&]() { p << ": " << type; }; if (!op.isDeclaration()) { p << "= "; @@ -1177,15 +1178,14 @@ static void printGlobalOpTypeAndInitialValue(OpAsmPrinter &p, GlobalOp op, static ParseResult parseGlobalOpTypeAndInitialValue(OpAsmParser &parser, TypeAttr &typeAttr, Attribute &initialValueAttr, - mlir::Region& ctorRegion) { + mlir::Region &ctorRegion) { mlir::Type opTy; if (parser.parseOptionalEqual().failed()) { // Absence of equal means a declaration, so we need to parse the type. // cir.global @a : i32 if (parser.parseColonType(opTy)) return failure(); - } - else { + } else { // Parse contructor, example: // cir.global @rgb = ctor : type { ... } if (!parser.parseOptionalKeyword("ctor")) { @@ -1274,10 +1274,10 @@ LogicalResult GlobalOp::verify() { return success(); } -void GlobalOp::build( - OpBuilder &odsBuilder, OperationState &odsState, StringRef sym_name, - Type sym_type, bool isConstant, cir::GlobalLinkageKind linkage, - function_ref ctorBuilder) { +void GlobalOp::build(OpBuilder &odsBuilder, OperationState &odsState, + StringRef sym_name, Type sym_type, bool isConstant, + cir::GlobalLinkageKind linkage, + function_ref ctorBuilder) { odsState.addAttribute(getSymNameAttrName(odsState.name), odsBuilder.getStringAttr(sym_name)); odsState.addAttribute(getSymTypeAttrName(odsState.name), @@ -2065,9 +2065,10 @@ void SignedOverflowBehaviorAttr::print(::mlir::AsmPrinter &printer) const { ::mlir::Attribute ASTFunctionDeclAttr::parse(::mlir::AsmParser &parser, ::mlir::Type type) { - // We cannot really parse anything AST related at this point - // since we have no serialization/JSON story. - return ASTFunctionDeclAttr::get(parser.getContext(), nullptr); + // We cannot really parse anything AST related at this point since we have no + // serialization/JSON story. Even if the attr is parsed, it just holds nullptr + // instead of the AST node. + return get(parser.getContext(), nullptr); } void ASTFunctionDeclAttr::print(::mlir::AsmPrinter &printer) const { @@ -2082,9 +2083,10 @@ LogicalResult ASTFunctionDeclAttr::verify( ::mlir::Attribute ASTVarDeclAttr::parse(::mlir::AsmParser &parser, ::mlir::Type type) { - // We cannot really parse anything AST related at this point - // since we have no serialization/JSON story. - return ASTVarDeclAttr::get(parser.getContext(), nullptr); + // We cannot really parse anything AST related at this point since we have no + // serialization/JSON story. Even if the attr is parsed, it just holds nullptr + // instead of the AST node. + return get(parser.getContext(), nullptr); } void ASTVarDeclAttr::print(::mlir::AsmPrinter &printer) const { @@ -2099,9 +2101,10 @@ LogicalResult ASTVarDeclAttr::verify( ::mlir::Attribute ASTRecordDeclAttr::parse(::mlir::AsmParser &parser, ::mlir::Type type) { - // We cannot really parse anything AST related at this point - // since we have no serialization/JSON story. - return ASTRecordDeclAttr::get(parser.getContext(), nullptr); + // We cannot really parse anything AST related at this point since we have no + // serialization/JSON story. Even if the attr is parsed, it just holds nullptr + // instead of the AST node. + return get(parser.getContext(), nullptr); } void ASTRecordDeclAttr::print(::mlir::AsmPrinter &printer) const { diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp index 0e633f1061e3..66183034704b 100644 --- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp @@ -11,9 +11,11 @@ //===----------------------------------------------------------------------===// #include "clang/CIR/Dialect/IR/CIRTypes.h" +#include "clang/CIR/Dialect/IR/CIRAttrs.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "mlir/IR/Attributes.h" +#include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/DialectImplementation.h" #include "mlir/Support/LogicalResult.h" @@ -22,6 +24,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/Support/ErrorHandling.h" +#include //===----------------------------------------------------------------------===// // CIR Custom Parser/Printer Signatures @@ -87,72 +90,69 @@ Type BoolType::parse(mlir::AsmParser &parser) { void BoolType::print(mlir::AsmPrinter &printer) const {} +//===----------------------------------------------------------------------===// +// StructType Definitions +//===----------------------------------------------------------------------===// + Type StructType::parse(mlir::AsmParser &parser) { + llvm::SmallVector members; + mlir::StringAttr id; + bool body = false; + bool packed = false; + mlir::cir::ASTRecordDeclAttr ast = nullptr; + if (parser.parseLess()) - return Type(); - std::string typeName; - if (parser.parseString(&typeName)) - return Type(); + return {}; - llvm::SmallVector members; - bool parsedBody = false; - - auto parseASTAttribute = [&](Attribute &attr) { - auto optAttr = parser.parseOptionalAttribute(attr); - if (optAttr.has_value()) { - if (failed(*optAttr)) - return false; - if (attr.isa() || attr.isa() || - attr.isa()) - return true; - parser.emitError(parser.getCurrentLocation(), - "Unknown cir.struct attribute"); - return false; - } - return false; - }; - - while (mlir::succeeded(parser.parseOptionalComma())) { - if (mlir::succeeded(parser.parseOptionalKeyword("incomplete"))) - continue; - - parsedBody = true; - Type nextMember; - auto optTy = parser.parseOptionalType(nextMember); - if (optTy.has_value()) { - if (failed(*optTy)) - return Type(); - members.push_back(nextMember); - continue; - } + if (parser.parseAttribute(id)) + return {}; - // Maybe it's an AST attribute: always last member, break. - Attribute astAttr; - if (parseASTAttribute(astAttr)) - break; + if (parser.parseOptionalKeyword("packed").succeeded()) + packed = true; + + if (parser.parseOptionalKeyword("incomplete").failed()) { + body = true; + const auto delim = AsmParser::Delimiter::Braces; + auto result = parser.parseCommaSeparatedList(delim, [&]() -> ParseResult { + mlir::Type ty; + if (parser.parseType(ty)) + return mlir::failure(); + members.push_back(ty); + return mlir::success(); + }); + + if (result.failed()) + return {}; } + parser.parseOptionalAttribute(ast); + if (parser.parseGreater()) - return Type(); - auto sTy = get(parser.getContext(), members, typeName, parsedBody); - return sTy; + return {}; + + return StructType::get(parser.getContext(), members, id, body, packed, + std::nullopt); } void StructType::print(mlir::AsmPrinter &printer) const { - printer << '<' << getTypeName(); + printer << '<' << getTypeName() << " "; + + if (getPacked()) + printer << "packed "; + if (!getBody()) { - printer << ", incomplete"; + printer << "incomplete"; } else { - auto members = getMembers(); - if (!members.empty()) { - printer << ", "; - llvm::interleaveComma(getMembers(), printer); - } + printer << "{"; + llvm::interleaveComma(getMembers(), printer); + printer << "}"; } - if (getAst()) { - printer << ", "; - printer.printAttributeWithoutType(*getAst()); + + if (getAst().has_value()) { + printer << " "; + printer.printAttribute(getAst().value()); } + printer << '>'; } diff --git a/clang/test/CIR/CodeGen/agg-init.cpp b/clang/test/CIR/CodeGen/agg-init.cpp index c7c01e3a5a8a..2c2adf5c0f2c 100644 --- a/clang/test/CIR/CodeGen/agg-init.cpp +++ b/clang/test/CIR/CodeGen/agg-init.cpp @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir-enable -Wno-unused-value -emit-cir %s -o %t.cir // RUN: FileCheck --input-file=%t.cir %s -// CHECK: !ty_22struct2EZero22 = !cir.struct<"struct.Zero", !u8i> -// CHECK: !ty_22struct2Eyep_22 = !cir.struct<"struct.yep_", !u32i, !u32i> +// CHECK: !ty_22struct2EZero22 = !cir.struct<"struct.Zero" {!u8i}> +// CHECK: !ty_22struct2Eyep_22 = !cir.struct<"struct.yep_" {!u32i, !u32i}> struct Zero { void yolo(); diff --git a/clang/test/CIR/CodeGen/atomic.cpp b/clang/test/CIR/CodeGen/atomic.cpp index dcd829d1cfe7..72c3b13905a7 100644 --- a/clang/test/CIR/CodeGen/atomic.cpp +++ b/clang/test/CIR/CodeGen/atomic.cpp @@ -7,4 +7,4 @@ typedef struct _a { void m() { at y; } -// CHECK: !ty_22struct2E_a22 = !cir.struct<"struct._a", !s32i> \ No newline at end of file +// CHECK: !ty_22struct2E_a22 = !cir.struct<"struct._a" {!s32i}> \ No newline at end of file diff --git a/clang/test/CIR/CodeGen/bitfields.cpp b/clang/test/CIR/CodeGen/bitfields.cpp index e06b89191985..bbacc920e071 100644 --- a/clang/test/CIR/CodeGen/bitfields.cpp +++ b/clang/test/CIR/CodeGen/bitfields.cpp @@ -14,5 +14,5 @@ void m() { __long l; } -// CHECK: !ty_22struct2Eanon22 = !cir.struct<"struct.anon", !u32i, #cir.recdecl.ast> -// CHECK: !ty_22struct2E__long22 = !cir.struct<"struct.__long", !ty_22struct2Eanon22, !u32i, !cir.ptr> \ No newline at end of file +// CHECK: !ty_22struct2Eanon22 = !cir.struct<"struct.anon" {!u32i} #cir.recdecl.ast> +// CHECK: !ty_22struct2E__long22 = !cir.struct<"struct.__long" {!ty_22struct2Eanon22, !u32i, !cir.ptr}> \ No newline at end of file diff --git a/clang/test/CIR/CodeGen/coro-task.cpp b/clang/test/CIR/CodeGen/coro-task.cpp index 96f024e8e83f..367d2403c753 100644 --- a/clang/test/CIR/CodeGen/coro-task.cpp +++ b/clang/test/CIR/CodeGen/coro-task.cpp @@ -126,13 +126,13 @@ co_invoke_fn co_invoke; }} // namespace folly::coro -// CHECK: ![[VoidTask:ty_.*]] = !cir.struct<"struct.folly::coro::Task", !u8i> -// CHECK: ![[IntTask:ty_.*]] = !cir.struct<"struct.folly::coro::Task", !u8i> -// CHECK: ![[VoidPromisse:ty_.*]] = !cir.struct<"struct.folly::coro::Task::promise_type", !u8i> -// CHECK: ![[CoroHandleVoid:ty_.*]] = !cir.struct<"struct.std::coroutine_handle", !u8i> -// CHECK: ![[CoroHandlePromise:ty_.*]] = !cir.struct<"struct.std::coroutine_handle", !u8i> -// CHECK: ![[StdString:ty_.*]] = !cir.struct<"struct.std::string", !u8i -// CHECK: ![[SuspendAlways:ty_.*]] = !cir.struct<"struct.std::suspend_always", !u8i> +// CHECK: ![[VoidTask:ty_.*]] = !cir.struct<"struct.folly::coro::Task" {!u8i}> +// CHECK: ![[IntTask:ty_.*]] = !cir.struct<"struct.folly::coro::Task" {!u8i}> +// CHECK: ![[VoidPromisse:ty_.*]] = !cir.struct<"struct.folly::coro::Task::promise_type" {!u8i}> +// CHECK: ![[CoroHandleVoid:ty_.*]] = !cir.struct<"struct.std::coroutine_handle" {!u8i}> +// CHECK: ![[CoroHandlePromise:ty_.*]] = !cir.struct<"struct.std::coroutine_handle" {!u8i}> +// CHECK: ![[StdString:ty_.*]] = !cir.struct<"struct.std::string" {!u8i} +// CHECK: ![[SuspendAlways:ty_.*]] = !cir.struct<"struct.std::suspend_always" {!u8i}> // CHECK: module {{.*}} { // CHECK-NEXT: cir.global external @_ZN5folly4coro9co_invokeE = #cir.zero : !ty_22struct2Efolly3A3Acoro3A3Aco_invoke_fn22 diff --git a/clang/test/CIR/CodeGen/ctor.cpp b/clang/test/CIR/CodeGen/ctor.cpp index 6338d0683fcc..897535ca9f21 100644 --- a/clang/test/CIR/CodeGen/ctor.cpp +++ b/clang/test/CIR/CodeGen/ctor.cpp @@ -11,7 +11,7 @@ void baz() { Struk s; } -// CHECK: !ty_22struct2EStruk22 = !cir.struct<"struct.Struk", !s32i> +// CHECK: !ty_22struct2EStruk22 = !cir.struct<"struct.Struk" {!s32i}> // CHECK: cir.func linkonce_odr @_ZN5StrukC2Ev(%arg0: !cir.ptr // CHECK-NEXT: %0 = cir.alloca !cir.ptr, cir.ptr >, ["this", init] {alignment = 8 : i64} diff --git a/clang/test/CIR/CodeGen/derived-to-base.cpp b/clang/test/CIR/CodeGen/derived-to-base.cpp index dade17c83583..3a22d65368ce 100644 --- a/clang/test/CIR/CodeGen/derived-to-base.cpp +++ b/clang/test/CIR/CodeGen/derived-to-base.cpp @@ -75,8 +75,8 @@ void C3::Layer::Initialize() { } } -// CHECK: !ty_22class2EC23A3ALayer22 = !cir.struct<"class.C2::Layer", !ty_22class2EC13A3ALayer22, !cir.ptr -// CHECK: !ty_22struct2EC33A3ALayer22 = !cir.struct<"struct.C3::Layer", !ty_22class2EC23A3ALayer22 +// CHECK: !ty_22class2EC23A3ALayer22 = !cir.struct<"class.C2::Layer" {!ty_22class2EC13A3ALayer22, !cir.ptr +// CHECK: !ty_22struct2EC33A3ALayer22 = !cir.struct<"struct.C3::Layer" {!ty_22class2EC23A3ALayer22 // CHECK: cir.func @_ZN2C35Layer10InitializeEv diff --git a/clang/test/CIR/CodeGen/dtors.cpp b/clang/test/CIR/CodeGen/dtors.cpp index e0a1d5819306..3fd6a7330ac6 100644 --- a/clang/test/CIR/CodeGen/dtors.cpp +++ b/clang/test/CIR/CodeGen/dtors.cpp @@ -37,10 +37,10 @@ class B : public A }; // Class A -// CHECK: ![[ClassA:ty_.*]] = !cir.struct<"class.A", !cir.ptr>>, #cir.recdecl.ast> +// CHECK: ![[ClassA:ty_.*]] = !cir.struct<"class.A" {!cir.ptr>>} #cir.recdecl.ast> // Class B -// CHECK: ![[ClassB:ty_.*]] = !cir.struct<"class.B", ![[ClassA]]> +// CHECK: ![[ClassB:ty_.*]] = !cir.struct<"class.B" {![[ClassA]]}> // CHECK: cir.func @_Z4bluev() // CHECK: %0 = cir.alloca !ty_22class2EPSEvent22, cir.ptr , ["p", init] {alignment = 8 : i64} diff --git a/clang/test/CIR/CodeGen/lambda.cpp b/clang/test/CIR/CodeGen/lambda.cpp index 5ad622dd1cd8..6fdd9b3c36b3 100644 --- a/clang/test/CIR/CodeGen/lambda.cpp +++ b/clang/test/CIR/CodeGen/lambda.cpp @@ -6,7 +6,7 @@ void fn() { a(); } -// CHECK: !ty_22class2Eanon22 = !cir.struct<"class.anon", !u8i> +// CHECK: !ty_22class2Eanon22 = !cir.struct<"class.anon" {!u8i}> // CHECK-DAG: module // CHECK: cir.func lambda internal private @_ZZ2fnvENK3$_0clEv diff --git a/clang/test/CIR/CodeGen/move.cpp b/clang/test/CIR/CodeGen/move.cpp index 2f148f3b3e8c..2f8856e23e37 100644 --- a/clang/test/CIR/CodeGen/move.cpp +++ b/clang/test/CIR/CodeGen/move.cpp @@ -16,7 +16,7 @@ struct string { } // std namespace -// CHECK: ![[StdString:ty_.*]] = !cir.struct<"struct.std::string", !u8i> +// CHECK: ![[StdString:ty_.*]] = !cir.struct<"struct.std::string" {!u8i}> std::string getstr(); void emplace(std::string &&s); diff --git a/clang/test/CIR/CodeGen/nrvo.cpp b/clang/test/CIR/CodeGen/nrvo.cpp index 3e70b75592e1..37fa8cfc416b 100644 --- a/clang/test/CIR/CodeGen/nrvo.cpp +++ b/clang/test/CIR/CodeGen/nrvo.cpp @@ -9,7 +9,7 @@ std::vector test_nrvo() { return result; } -// CHECK: !ty_22class2Estd3A3Avector22 = !cir.struct<"class.std::vector", !cir.ptr>, !cir.ptr>, !cir.ptr>> +// CHECK: !ty_22class2Estd3A3Avector22 = !cir.struct<"class.std::vector" {!cir.ptr>, !cir.ptr>, !cir.ptr>}> // CHECK: cir.func @_Z9test_nrvov() -> !ty_22class2Estd3A3Avector22 // CHECK: %0 = cir.alloca !ty_22class2Estd3A3Avector22, cir.ptr , ["__retval", init] {alignment = 8 : i64} diff --git a/clang/test/CIR/CodeGen/rangefor.cpp b/clang/test/CIR/CodeGen/rangefor.cpp index 04d2535b12e5..175f51128f5b 100644 --- a/clang/test/CIR/CodeGen/rangefor.cpp +++ b/clang/test/CIR/CodeGen/rangefor.cpp @@ -21,9 +21,9 @@ void init(unsigned numImages) { } } -// CHECK: !ty_22struct2Etriple22 = !cir.struct<"struct.triple", !u32i, !cir.ptr, !u32i> -// CHECK: !ty_22class2Estd3A3Avector22 = !cir.struct<"class.std::vector", !cir.ptr, !cir.ptr, !cir.ptr> -// CHECK: !ty_22struct2E__vector_iterator22 = !cir.struct<"struct.__vector_iterator", !cir.ptr> +// CHECK: !ty_22struct2Etriple22 = !cir.struct<"struct.triple" {!u32i, !cir.ptr, !u32i}> +// CHECK: !ty_22class2Estd3A3Avector22 = !cir.struct<"class.std::vector" {!cir.ptr, !cir.ptr, !cir.ptr}> +// CHECK: !ty_22struct2E__vector_iterator22 = !cir.struct<"struct.__vector_iterator" {!cir.ptr}> // CHECK: cir.func @_Z4initj(%arg0: !u32i // CHECK: %0 = cir.alloca !u32i, cir.ptr , ["numImages", init] {alignment = 4 : i64} diff --git a/clang/test/CIR/CodeGen/struct.c b/clang/test/CIR/CodeGen/struct.c index cd2b7931000f..b86ffda3ac4a 100644 --- a/clang/test/CIR/CodeGen/struct.c +++ b/clang/test/CIR/CodeGen/struct.c @@ -17,8 +17,8 @@ void baz(void) { struct Foo f; } -// CHECK-DAG: !ty_22struct2EBar22 = !cir.struct<"struct.Bar", !s32i, !s8i> -// CHECK-DAG: !ty_22struct2EFoo22 = !cir.struct<"struct.Foo", !s32i, !s8i, !ty_22struct2EBar22> +// CHECK-DAG: !ty_22struct2EBar22 = !cir.struct<"struct.Bar" {!s32i, !s8i}> +// CHECK-DAG: !ty_22struct2EFoo22 = !cir.struct<"struct.Foo" {!s32i, !s8i, !ty_22struct2EBar22}> // CHECK-DAG: module {{.*}} { // CHECK: cir.func @baz() // CHECK-NEXT: %0 = cir.alloca !ty_22struct2EBar22, cir.ptr , ["b"] {alignment = 4 : i64} diff --git a/clang/test/CIR/CodeGen/struct.cpp b/clang/test/CIR/CodeGen/struct.cpp index 8525d2dc76ee..bf9eda10edef 100644 --- a/clang/test/CIR/CodeGen/struct.cpp +++ b/clang/test/CIR/CodeGen/struct.cpp @@ -26,13 +26,13 @@ void baz() { struct incomplete; void yoyo(incomplete *i) {} -// CHECK: !ty_22struct2Eincomplete22 = !cir.struct<"struct.incomplete", incomplete -// CHECK: !ty_22struct2EBar22 = !cir.struct<"struct.Bar", !s32i, !s8i> +// CHECK: !ty_22struct2Eincomplete22 = !cir.struct<"struct.incomplete" incomplete +// CHECK: !ty_22struct2EBar22 = !cir.struct<"struct.Bar" {!s32i, !s8i}> -// CHECK: !ty_22struct2EFoo22 = !cir.struct<"struct.Foo", !s32i, !s8i, !ty_22struct2EBar22> -// CHECK: !ty_22struct2EMandalore22 = !cir.struct<"struct.Mandalore", !u32i, !cir.ptr, !s32i, #cir.recdecl.ast> -// CHECK: !ty_22class2EAdv22 = !cir.struct<"class.Adv", !ty_22struct2EMandalore22> -// CHECK: !ty_22struct2EEntry22 = !cir.struct<"struct.Entry", !cir.ptr, !cir.ptr)>>> +// CHECK: !ty_22struct2EFoo22 = !cir.struct<"struct.Foo" {!s32i, !s8i, !ty_22struct2EBar22}> +// CHECK: !ty_22struct2EMandalore22 = !cir.struct<"struct.Mandalore" {!u32i, !cir.ptr, !s32i} #cir.recdecl.ast> +// CHECK: !ty_22class2EAdv22 = !cir.struct<"class.Adv" {!ty_22struct2EMandalore22}> +// CHECK: !ty_22struct2EEntry22 = !cir.struct<"struct.Entry" {!cir.ptr, !cir.ptr)>>}> // CHECK: cir.func linkonce_odr @_ZN3Bar6methodEv(%arg0: !cir.ptr // CHECK-NEXT: %0 = cir.alloca !cir.ptr, cir.ptr >, ["this", init] {alignment = 8 : i64} diff --git a/clang/test/CIR/CodeGen/union.cpp b/clang/test/CIR/CodeGen/union.cpp index 264699403184..b93af75baccd 100644 --- a/clang/test/CIR/CodeGen/union.cpp +++ b/clang/test/CIR/CodeGen/union.cpp @@ -12,12 +12,12 @@ void m() { yolm3 q3; } -// CHECK: !ty_22struct2Eanon22 = !cir.struct<"struct.anon", !cir.bool, !s32i, #cir.recdecl.ast> -// CHECK: !ty_22struct2Eyolo22 = !cir.struct<"struct.yolo", !s32i, #cir.recdecl.ast> -// CHECK: !ty_22struct2Eanon221 = !cir.struct<"struct.anon", !cir.ptr, !s32i, #cir.recdecl.ast> +// CHECK: !ty_22struct2Eanon22 = !cir.struct<"struct.anon" {!cir.bool, !s32i} #cir.recdecl.ast> +// CHECK: !ty_22struct2Eyolo22 = !cir.struct<"struct.yolo" {!s32i} #cir.recdecl.ast> +// CHECK: !ty_22struct2Eanon221 = !cir.struct<"struct.anon" {!cir.ptr, !s32i} #cir.recdecl.ast> -// CHECK: !ty_22union2Eyolm22 = !cir.struct<"union.yolm", !ty_22struct2Eyolo22> -// CHECK: !ty_22union2Eyolm222 = !cir.struct<"union.yolm2", !ty_22struct2Eanon221> +// CHECK: !ty_22union2Eyolm22 = !cir.struct<"union.yolm" {!ty_22struct2Eyolo22}> +// CHECK: !ty_22union2Eyolm222 = !cir.struct<"union.yolm2" {!ty_22struct2Eanon221}> // CHECK: cir.func @_Z1mv() // CHECK: cir.alloca !ty_22union2Eyolm22, cir.ptr , ["q"] {alignment = 4 : i64} diff --git a/clang/test/CIR/CodeGen/vtable-rtti.cpp b/clang/test/CIR/CodeGen/vtable-rtti.cpp index 9e0cec7806bd..e128b55b143c 100644 --- a/clang/test/CIR/CodeGen/vtable-rtti.cpp +++ b/clang/test/CIR/CodeGen/vtable-rtti.cpp @@ -18,16 +18,16 @@ class B : public A }; // Type info B. -// CHECK: ![[TypeInfoB:ty_.*]] = !cir.struct<"", !cir.ptr, !cir.ptr, !cir.ptr> +// CHECK: ![[TypeInfoB:ty_.*]] = !cir.struct<"" {!cir.ptr, !cir.ptr, !cir.ptr}> // vtable for A type -// CHECK: ![[VTableTypeA:ty_.*]] = !cir.struct<"", !cir.array x 5>> +// CHECK: ![[VTableTypeA:ty_.*]] = !cir.struct<"" {!cir.array x 5>}> // Class A -// CHECK: ![[ClassA:ty_.*]] = !cir.struct<"class.A", !cir.ptr>>, #cir.recdecl.ast> +// CHECK: ![[ClassA:ty_.*]] = !cir.struct<"class.A" {!cir.ptr>>} #cir.recdecl.ast> // Class B -// CHECK: ![[ClassB:ty_.*]] = !cir.struct<"class.B", ![[ClassA]]> +// CHECK: ![[ClassB:ty_.*]] = !cir.struct<"class.B" {![[ClassA]]}> // B ctor => @B::B() // Calls @A::A() and initialize __vptr with address of B's vtable. diff --git a/clang/test/CIR/IR/global.cir b/clang/test/CIR/IR/global.cir index d572cb21c29b..d860f2632d25 100644 --- a/clang/test/CIR/IR/global.cir +++ b/clang/test/CIR/IR/global.cir @@ -3,12 +3,12 @@ !s8i = !cir.int !s32i = !cir.int !s64i = !cir.int -!ty_22class2EInit22 = !cir.struct<"class.Init", !s8i, #cir.recdecl.ast> +!ty_22class2EInit22 = !cir.struct<"class.Init" {!s8i} #cir.recdecl.ast> module { cir.global external @a = #cir.int<3> : !s32i cir.global external @rgb = #cir.const_array<[#cir.int<0> : !s8i, #cir.int<-23> : !s8i, #cir.int<33> : !s8i] : !cir.array> cir.global external @b = #cir.const_array<"example\00" : !cir.array> - cir.global external @rgb2 = #cir.const_struct<{#cir.int<0> : !s8i, #cir.int<5> : !s64i, #cir.null : !cir.ptr}> : !cir.struct<"", !s8i, !s64i, !cir.ptr> + cir.global external @rgb2 = #cir.const_struct<{#cir.int<0> : !s8i, #cir.int<5> : !s64i, #cir.null : !cir.ptr}> : !cir.struct<"" {!s8i, !s64i, !cir.ptr}> cir.global "private" constant internal @".str" : !cir.array {alignment = 1 : i64} cir.global "private" internal @c : !s32i cir.global "private" constant internal @".str2" = #cir.const_array<"example\00" : !cir.array> : !cir.array {alignment = 1 : i64} @@ -31,8 +31,7 @@ module { #cir.global_view<@_ZTVN10__cxxabiv120__si_class_type_infoE, [2]> : !cir.ptr, #cir.global_view<@type_info_name_B> : !cir.ptr, #cir.global_view<@type_info_A> : !cir.ptr}> - : !cir.struct<"", !cir.ptr, !cir.ptr, !cir.ptr - > + : !cir.struct<"" {!cir.ptr, !cir.ptr, !cir.ptr}> cir.func private @_ZN4InitC1Eb(!cir.ptr, !s8i) cir.global "private" internal @_ZL8__ioinit = ctor : !ty_22class2EInit22 { %0 = cir.get_global @_ZL8__ioinit : cir.ptr diff --git a/clang/test/CIR/IR/invalid.cir b/clang/test/CIR/IR/invalid.cir index b81e42ca4507..49f18ad710b8 100644 --- a/clang/test/CIR/IR/invalid.cir +++ b/clang/test/CIR/IR/invalid.cir @@ -309,7 +309,7 @@ module { cir.global external @type_info_B = #cir.typeinfo<{ // expected-error {{element at index 0 has type '!cir.ptr>' but return type for this element is '!cir.ptr>'}} #cir.global_view<@_ZTVN10__cxxabiv120__si_class_type_infoE, [2]> : !cir.ptr}> - : !cir.struct<"", !cir.ptr> + : !cir.struct<"" {!cir.ptr}> } // expected-error {{'cir.global' expected constant attribute to match type}} // ----- diff --git a/clang/test/CIR/IR/struct.cir b/clang/test/CIR/IR/struct.cir index e82dc92ce431..4f98102a3bad 100644 --- a/clang/test/CIR/IR/struct.cir +++ b/clang/test/CIR/IR/struct.cir @@ -5,17 +5,17 @@ !s32i = !cir.int !u32i = !cir.int -!ty_2222 = !cir.struct<"", !cir.array x 5>> -!ty_22221 = !cir.struct<"", !cir.ptr, !cir.ptr, !cir.ptr> -!ty_22class2EA22 = !cir.struct<"class.A", incomplete, #cir.recdecl.ast> -// CHECK: !ty_22i22 = !cir.struct<"i", incomplete> -// CHECK: !ty_22S22 = !cir.struct<"S", !u8i, !u16i, !u32i> -!ty_22struct2ES22 = !cir.struct<"struct.S", !s32i, !s32i> +!ty_2222 = !cir.struct<"" {!cir.array x 5>}> +!ty_22221 = !cir.struct<"" {!cir.ptr, !cir.ptr, !cir.ptr}> +!ty_22class2EA22 = !cir.struct<"class.A" incomplete #cir.recdecl.ast> +// CHECK: !ty_22i22 = !cir.struct<"i" incomplete> +// CHECK: !ty_22S22 = !cir.struct<"S" {!u8i, !u16i, !u32i}> +!ty_22struct2ES22 = !cir.struct<"struct.S" {!s32i, !s32i}> module { cir.func @structs() { - %0 = cir.alloca !cir.ptr>, cir.ptr >>, ["s", init] - %1 = cir.alloca !cir.ptr>, cir.ptr >>, ["i", init] + %0 = cir.alloca !cir.ptr>, cir.ptr >>, ["s", init] + %1 = cir.alloca !cir.ptr>, cir.ptr >>, ["i", init] cir.return } diff --git a/clang/test/CIR/IR/vtableAttr.cir b/clang/test/CIR/IR/vtableAttr.cir index 5c9f414feb98..596644d2cfc7 100644 --- a/clang/test/CIR/IR/vtableAttr.cir +++ b/clang/test/CIR/IR/vtableAttr.cir @@ -1,7 +1,7 @@ // RUN: cir-opt %s | FileCheck %s !u8i = !cir.int -!ty_2222 = !cir.struct<"", !cir.array x 1>> +!ty_2222 = !cir.struct<"" {!cir.array x 1>}> module { // Should parse VTable attribute. cir.global external @testVTable = #cir.vtable<{#cir.const_array<[#cir.null : !cir.ptr]> : !cir.array x 1>}> : !ty_2222 diff --git a/clang/test/CIR/Lowering/globals.cir b/clang/test/CIR/Lowering/globals.cir index 98873930e23b..a83d5a2972de 100644 --- a/clang/test/CIR/Lowering/globals.cir +++ b/clang/test/CIR/Lowering/globals.cir @@ -10,7 +10,7 @@ !u32i = !cir.int !u64i = !cir.int !u8i = !cir.int -!ty_22struct2EA22 = !cir.struct<"struct.A", !s32i, !cir.array x 2>, #cir.recdecl.ast> +!ty_22struct2EA22 = !cir.struct<"struct.A" {!s32i, !cir.array x 2>} #cir.recdecl.ast> module { cir.global external @a = #cir.int<3> : !s32i diff --git a/clang/test/CIR/Lowering/struct.cir b/clang/test/CIR/Lowering/struct.cir index c297d7e75ce3..4edaf6d753f4 100644 --- a/clang/test/CIR/Lowering/struct.cir +++ b/clang/test/CIR/Lowering/struct.cir @@ -3,11 +3,11 @@ !s32i = !cir.int !u8i = !cir.int -!ty_22struct2ES22 = !cir.struct<"struct.S", !u8i, !s32i> -!ty_22struct2ES2A22 = !cir.struct<"struct.S2A", !s32i, #cir.recdecl.ast> -!ty_22struct2ES122 = !cir.struct<"struct.S1", !s32i, f32, !cir.ptr, #cir.recdecl.ast> -!ty_22struct2ES222 = !cir.struct<"struct.S2", !ty_22struct2ES2A22, #cir.recdecl.ast> -!ty_22struct2ES322 = !cir.struct<"struct.S3", !s32i, #cir.recdecl.ast> +!ty_22struct2ES22 = !cir.struct<"struct.S" {!u8i, !s32i}> +!ty_22struct2ES2A22 = !cir.struct<"struct.S2A" {!s32i} #cir.recdecl.ast> +!ty_22struct2ES122 = !cir.struct<"struct.S1" {!s32i, f32, !cir.ptr} #cir.recdecl.ast> +!ty_22struct2ES222 = !cir.struct<"struct.S2" {!ty_22struct2ES2A22} #cir.recdecl.ast> +!ty_22struct2ES322 = !cir.struct<"struct.S3" {!s32i} #cir.recdecl.ast> module { cir.func @test() { diff --git a/clang/test/CIR/Lowering/variadics.cir b/clang/test/CIR/Lowering/variadics.cir index 9394091146df..36e0bbd7b9b9 100644 --- a/clang/test/CIR/Lowering/variadics.cir +++ b/clang/test/CIR/Lowering/variadics.cir @@ -5,7 +5,7 @@ !u32i = !cir.int !u8i = !cir.int -!ty_22struct2E__va_list_tag22 = !cir.struct<"struct.__va_list_tag", !u32i, !u32i, !cir.ptr, !cir.ptr, #cir.recdecl.ast> +!ty_22struct2E__va_list_tag22 = !cir.struct<"struct.__va_list_tag" {!u32i, !u32i, !cir.ptr, !cir.ptr} #cir.recdecl.ast> module { cir.func @average(%arg0: !s32i, ...) -> !s32i {