Skip to content

Commit c40a840

Browse files
committed
more review comments
1 parent db31493 commit c40a840

File tree

10 files changed

+67
-42
lines changed

10 files changed

+67
-42
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ def GlobalDtorAttr : CIR_GlobalCtorDtor<"Dtor", "dtor",
13521352
>;
13531353

13541354
def CIR_CtorKind : CIR_I32EnumAttr<"CtorKind", "CXX Constructor Kind", [
1355-
I32EnumAttrCase<"None", 0, "none">,
1355+
I32EnumAttrCase<"Custom", 0, "custom">,
13561356
I32EnumAttrCase<"Default", 1, "default">,
13571357
I32EnumAttrCase<"Copy", 2, "copy">,
13581358
]> {
@@ -1364,17 +1364,21 @@ def CIR_CXXCtorAttr
13641364
let summary = "Marks a function as a CXX constructor";
13651365
let description = [{
13661366
Functions with this attribute are CXX constructors.
1367+
The `custom` kind is used if the constructor is a custom constructor.
13671368
The `default` kind is used if the constructor is a default constructor.
13681369
The `copy` kind is used if the constructor is a copy constructor.
13691370
}];
13701371
let parameters = (ins "mlir::Type":$type,
13711372
EnumParameter<CIR_CtorKind>:$ctorKind);
1373+
13721374
let assemblyFormat = [{
13731375
`<` $type `,` $ctorKind `>`
13741376
}];
1377+
// Printing and parsing also available in CIRDialect.cpp
1378+
13751379
let builders =
13761380
[AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
1377-
CArg<"CtorKind", "cir::CtorKind::None">:$ctorKind), [{
1381+
CArg<"CtorKind", "cir::CtorKind::Custom">:$ctorKind), [{
13781382
return $_get(type.getContext(), type, ctorKind);
13791383
}]>];
13801384
}
@@ -1386,9 +1390,12 @@ def CIR_CXXDtorAttr
13861390
Functions with this attribute are CXX destructors
13871391
}];
13881392
let parameters = (ins "mlir::Type":$type);
1393+
13891394
let assemblyFormat = [{
13901395
`<` $type `>`
13911396
}];
1397+
// Printing and parsing also available in CIRDialect.cpp
1398+
13921399
let builders =
13931400
[AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
13941401
return $_get(type.getContext(), type);

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,20 +766,18 @@ cir::FuncOp CIRGenFunction::generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
766766
assert(!cir::MissingFeatures::shouldInstrumentFunction());
767767
if (auto dtor = dyn_cast<CXXDestructorDecl>(fd)) {
768768
auto cxxDtor = cir::CXXDtorAttr::get(
769-
&getMLIRContext(),
770769
convertType(getContext().getRecordType(dtor->getParent())));
771770
fn.setCxxSpecialMemberAttr(cxxDtor);
772771

773772
emitDestructorBody(args);
774773
} else if (auto ctor = dyn_cast<CXXConstructorDecl>(fd)) {
775-
cir::CtorKind ctorKind = cir::CtorKind::None;
774+
cir::CtorKind ctorKind = cir::CtorKind::Custom;
776775
if (ctor->isDefaultConstructor())
777776
ctorKind = cir::CtorKind::Default;
778777
if (ctor->isCopyConstructor())
779778
ctorKind = cir::CtorKind::Copy;
780779

781780
auto cxxCtor = cir::CXXCtorAttr::get(
782-
&getMLIRContext(),
783781
convertType(getContext().getRecordType(ctor->getParent())), ctorKind);
784782
fn.setCxxSpecialMemberAttr(cxxCtor);
785783

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,20 +2742,18 @@ cir::FuncOp CIRGenModule::createCIRFunction(mlir::Location loc, StringRef name,
27422742
if (fd) {
27432743
if (auto dtor = dyn_cast<CXXDestructorDecl>(fd)) {
27442744
auto cxxDtor = cir::CXXDtorAttr::get(
2745-
&getMLIRContext(),
27462745
convertType(getASTContext().getRecordType(dtor->getParent())));
27472746
f.setCxxSpecialMemberAttr(cxxDtor);
27482747
}
27492748

27502749
if (auto ctor = dyn_cast<CXXConstructorDecl>(fd)) {
2751-
cir::CtorKind ctorKind = cir::CtorKind::None;
2750+
cir::CtorKind ctorKind = cir::CtorKind::Custom;
27522751
if (ctor->isDefaultConstructor())
27532752
ctorKind = cir::CtorKind::Default;
27542753
if (ctor->isCopyConstructor())
27552754
ctorKind = cir::CtorKind::Copy;
27562755

27572756
auto cxxCtor = cir::CXXCtorAttr::get(
2758-
&getMLIRContext(),
27592757
convertType(getASTContext().getRecordType(ctor->getParent())),
27602758
ctorKind);
27612759
f.setCxxSpecialMemberAttr(cxxCtor);

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ REGISTER_ENUM_TYPE(GlobalLinkageKind);
172172
REGISTER_ENUM_TYPE(VisibilityKind);
173173
REGISTER_ENUM_TYPE(CallingConv);
174174
REGISTER_ENUM_TYPE(SideEffect);
175+
REGISTER_ENUM_TYPE(CtorKind);
175176
} // namespace
176177

177178
/// Parse an enum from the keyword, or default to the provided default value.
@@ -2619,18 +2620,35 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
26192620
state.addAttribute(annotationsNameAttr, annotations);
26202621
}
26212622

2622-
// Add CXXSpecialMember attribute.
2623-
if (mlir::succeeded(parser.parseOptionalKeyword("cxx_special_member"))) {
2623+
// Parse CXXSpecialMember attribute
2624+
if (mlir::succeeded(parser.parseOptionalKeyword("cxx_ctor"))) {
26242625
if (parser.parseLess().failed())
26252626
return failure();
2626-
cir::CXXCtorAttr ctor;
2627-
if (auto oa = parser.parseOptionalAttribute(ctor); oa.has_value())
2628-
state.addAttribute(cxxSpecialMemberAttr, ctor);
2629-
cir::CXXDtorAttr dtor;
2630-
if (auto oa = parser.parseOptionalAttribute(dtor); oa.has_value())
2631-
state.addAttribute(cxxSpecialMemberAttr, dtor);
2627+
mlir::Type type;
2628+
if (parser.parseType(type).failed())
2629+
return failure();
2630+
if (parser.parseComma().failed())
2631+
return failure();
2632+
cir::CtorKind ctorKind;
2633+
if (parseCIRKeyword<cir::CtorKind>(parser, ctorKind).failed())
2634+
return failure();
2635+
if (parser.parseGreater().failed())
2636+
return failure();
2637+
2638+
state.addAttribute(cxxSpecialMemberAttr,
2639+
cir::CXXCtorAttr::get(type, ctorKind));
2640+
}
2641+
2642+
if (mlir::succeeded(parser.parseOptionalKeyword("cxx_dtor"))) {
2643+
if (parser.parseLess().failed())
2644+
return failure();
2645+
mlir::Type type;
2646+
if (parser.parseType(type).failed())
2647+
return failure();
26322648
if (parser.parseGreater().failed())
26332649
return failure();
2650+
2651+
state.addAttribute(cxxSpecialMemberAttr, cir::CXXDtorAttr::get(type));
26342652
}
26352653

26362654
// If additional attributes are present, parse them.
@@ -2814,12 +2832,16 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
28142832
}
28152833

28162834
if (getCxxSpecialMember()) {
2817-
p << " cxx_special_member<";
2818-
if (auto cxxCtor = dyn_cast<cir::CXXCtorAttr>(*getCxxSpecialMember()))
2819-
p.printAttribute(cxxCtor);
2820-
if (auto cxxDtor = dyn_cast<cir::CXXDtorAttr>(*getCxxSpecialMember()))
2821-
p.printAttribute(cxxDtor);
2822-
p << '>';
2835+
if (auto cxxCtor = dyn_cast<cir::CXXCtorAttr>(*getCxxSpecialMember())) {
2836+
if (cxxCtor.getCtorKind() != cir::CtorKind::Custom)
2837+
p << " cxx_ctor<" << cxxCtor.getType() << ", " << cxxCtor.getCtorKind()
2838+
<< ">";
2839+
} else if (auto cxxDtor =
2840+
dyn_cast<cir::CXXDtorAttr>(*getCxxSpecialMember())) {
2841+
p << " cxx_dtor<" << cxxDtor.getType() << ">";
2842+
} else {
2843+
assert(false && "expected a CXX special member");
2844+
}
28232845
}
28242846

28252847
function_interface_impl::printFunctionAttributes(

clang/test/CIR/CodeGen/ctor-alias.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ B::B() {
3737
// CHECK: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!rec_B>>, !cir.ptr<!rec_B>
3838
// CHECK: cir.return
3939
// CHECK: }
40-
// CHECK: cir.func private dso_local @_ZN1BC1Ev(!cir.ptr<!rec_B>) cxx_special_member<#cir.cxx_ctor<!rec_B, default>> alias(@_ZN1BC2Ev)
40+
// CHECK: cir.func private dso_local @_ZN1BC1Ev(!cir.ptr<!rec_B>) cxx_ctor<!rec_B, default> alias(@_ZN1BC2Ev)

clang/test/CIR/CodeGen/static.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ static Init __ioinit(true);
1717
static Init __ioinit2(false);
1818

1919
// BEFORE: module {{.*}} {
20-
// BEFORE-NEXT: cir.func private @_ZN4InitC1Eb(!cir.ptr<!rec_Init>, !cir.bool) cxx_special_member<#cir.cxx_ctor<!rec_Init, none>
21-
// BEFORE-NEXT: cir.func private @_ZN4InitD1Ev(!cir.ptr<!rec_Init>) cxx_special_member<#cir.cxx_dtor<!rec_Init>
20+
// BEFORE-NEXT: cir.func private @_ZN4InitC1Eb(!cir.ptr<!rec_Init>, !cir.bool)
21+
// BEFORE-NEXT: cir.func private @_ZN4InitD1Ev(!cir.ptr<!rec_Init>) cxx_dtor<!rec_Init>
2222
// BEFORE-NEXT: cir.global "private" internal dso_local @_ZL8__ioinit = ctor : !rec_Init {
2323
// BEFORE-NEXT: %0 = cir.get_global @_ZL8__ioinit : !cir.ptr<!rec_Init>
2424
// BEFORE-NEXT: %1 = cir.const #true
@@ -41,8 +41,8 @@ static Init __ioinit2(false);
4141
// AFTER: module {{.*}} attributes {{.*}}cir.global_ctors = [#cir.global_ctor<"__cxx_global_var_init", 65536>, #cir.global_ctor<"__cxx_global_var_init.1", 65536>]
4242
// AFTER-NEXT: cir.global "private" external @__dso_handle : i8
4343
// AFTER-NEXT: cir.func private @__cxa_atexit(!cir.ptr<!cir.func<(!cir.ptr<!void>)>>, !cir.ptr<!void>, !cir.ptr<i8>)
44-
// AFTER-NEXT: cir.func private @_ZN4InitC1Eb(!cir.ptr<!rec_Init>, !cir.bool) cxx_special_member<#cir.cxx_ctor<!rec_Init, none>
45-
// AFTER-NEXT: cir.func private @_ZN4InitD1Ev(!cir.ptr<!rec_Init>) cxx_special_member<#cir.cxx_dtor<!rec_Init>
44+
// AFTER-NEXT: cir.func private @_ZN4InitC1Eb(!cir.ptr<!rec_Init>, !cir.bool)
45+
// AFTER-NEXT: cir.func private @_ZN4InitD1Ev(!cir.ptr<!rec_Init>) cxx_dtor<!rec_Init>
4646
// AFTER-NEXT: cir.global "private" internal dso_local @_ZL8__ioinit = #cir.zero : !rec_Init {alignment = 1 : i64, ast = #cir.var.decl.ast}
4747
// AFTER-NEXT: cir.func internal private @__cxx_global_var_init()
4848
// AFTER-NEXT: %0 = cir.get_global @_ZL8__ioinit : !cir.ptr<!rec_Init>

clang/test/CIR/CodeGen/temporaries.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ void f() {
1414
!E();
1515
}
1616

17-
// CIR: cir.func private @_ZN1EC1Ev(!cir.ptr<!rec_E>) cxx_special_member<#cir.cxx_ctor<!rec_E, default>> extra(#fn_attr)
17+
// CIR: cir.func private @_ZN1EC1Ev(!cir.ptr<!rec_E>) cxx_ctor<!rec_E, default> extra(#fn_attr)
1818
// CIR-NEXT: cir.func private @_ZN1EntEv(!cir.ptr<!rec_E>) -> !rec_E
19-
// CIR-NEXT: cir.func private @_ZN1ED1Ev(!cir.ptr<!rec_E>) cxx_special_member<#cir.cxx_dtor<!rec_E>> extra(#fn_attr)
19+
// CIR-NEXT: cir.func private @_ZN1ED1Ev(!cir.ptr<!rec_E>) cxx_dtor<!rec_E> extra(#fn_attr)
2020
// CIR-NEXT: cir.func dso_local @_Z1fv() extra(#fn_attr1) {
2121
// CIR-NEXT: cir.scope {
2222
// CIR-NEXT: %[[ONE:[0-9]+]] = cir.alloca !rec_E, !cir.ptr<!rec_E>, ["agg.tmp.ensured"] {alignment = 1 : i64}

clang/test/CIR/CodeGen/tempref.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
struct A { ~A(); };
77
A &&a = dynamic_cast<A&&>(A{});
88

9-
// CHECK: cir.func private @_ZN1AD1Ev(!cir.ptr<!rec_A>) cxx_special_member<#cir.cxx_dtor<!rec_A>> extra(#fn_attr)
9+
// CHECK: cir.func private @_ZN1AD1Ev(!cir.ptr<!rec_A>) cxx_dtor<!rec_A> extra(#fn_attr)
1010
// CHECK-NEXT: cir.global external @a = #cir.ptr<null> : !cir.ptr<!rec_A> {alignment = 8 : i64, ast = #cir.var.decl.ast}
1111
// CHECK-NEXT: cir.func internal private @__cxx_global_var_init() {
1212
// CHECK-NEXT: cir.scope {

clang/test/CIR/CodeGen/virtual-destructor-calls.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct B : A {
3232
// LLVM: call void @_ZN1AD2Ev
3333

3434
// Complete dtor: just an alias because there are no virtual bases.
35-
// CIR: cir.func private dso_local @_ZN1BD1Ev(!cir.ptr<!rec_B>) cxx_special_member<#cir.cxx_dtor<!rec_B>> alias(@_ZN1BD2Ev)
35+
// CIR: cir.func private dso_local @_ZN1BD1Ev(!cir.ptr<!rec_B>) cxx_dtor<!rec_B> alias(@_ZN1BD2Ev)
3636
// FIXME: LLVM output should be: @_ZN1BD1Ev ={{.*}} unnamed_addr alias {{.*}} @_ZN1BD2Ev
3737
// LLVM: declare dso_local void @_ZN1BD1Ev(ptr)
3838

@@ -43,11 +43,11 @@ struct B : A {
4343

4444
// (aliases from C)
4545
// CIR: cir.func dso_local @_ZN1CD2Ev(%arg0: !cir.ptr<!rec_C>{{.*}})) {{.*}} {
46-
// CIR: cir.func private dso_local @_ZN1CD1Ev(!cir.ptr<!rec_C>) cxx_special_member<#cir.cxx_dtor<!rec_C>> alias(@_ZN1CD2Ev)
46+
// CIR: cir.func private dso_local @_ZN1CD1Ev(!cir.ptr<!rec_C>) cxx_dtor<!rec_C> alias(@_ZN1CD2Ev)
4747

4848
// CIR_O1-NOT: cir.func dso_local @_ZN1CD2Ev(%arg0: !cir.ptr<!rec_C>{{.*}})) {{.*}} {
49-
// CIR_O1: cir.func private dso_local @_ZN1CD2Ev(!cir.ptr<!rec_C>) cxx_special_member<#cir.cxx_dtor<!rec_C>> alias(@_ZN1BD2Ev)
50-
// CIR_O1: cir.func private dso_local @_ZN1CD1Ev(!cir.ptr<!rec_C>) cxx_special_member<#cir.cxx_dtor<!rec_C>> alias(@_ZN1CD2Ev)
49+
// CIR_O1: cir.func private dso_local @_ZN1CD2Ev(!cir.ptr<!rec_C>) cxx_dtor<!rec_C> alias(@_ZN1BD2Ev)
50+
// CIR_O1: cir.func private dso_local @_ZN1CD1Ev(!cir.ptr<!rec_C>) cxx_dtor<!rec_C> alias(@_ZN1CD2Ev)
5151

5252
// FIXME: LLVM output should be: @_ZN1CD2Ev ={{.*}} unnamed_addr alias {{.*}} @_ZN1BD2Ev
5353
// LLVM: define dso_local void @_ZN1CD2Ev(ptr

clang/test/CIR/IR/cxx-special-member.cir

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
!s32i = !cir.int<s, 32>
55
!rec_S = !cir.record<struct "S" {!s32i}>
66
module {
7-
cir.func private @_ZN1SC1ERKS_(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) cxx_special_member<#cir.cxx_ctor<!rec_S, copy>>
8-
cir.func private @_ZN1SC2Ei(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) cxx_special_member<#cir.cxx_ctor<!rec_S, none>>
9-
cir.func private @_ZN1SC2Ev(!cir.ptr<!rec_S>) cxx_special_member<#cir.cxx_ctor<!rec_S, default>>
10-
cir.func private @_ZN1SD2Ev(!cir.ptr<!rec_S>) cxx_special_member<#cir.cxx_dtor<!rec_S>>
7+
cir.func private @_ZN1SC1ERKS_(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) cxx_ctor<!rec_S, copy>
8+
cir.func private @_ZN1SC2Ei(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>)
9+
cir.func private @_ZN1SC2Ev(!cir.ptr<!rec_S>) cxx_ctor<!rec_S, default>
10+
cir.func private @_ZN1SD2Ev(!cir.ptr<!rec_S>) cxx_dtor<!rec_S>
1111
}
1212

1313
// CHECK: !s32i = !cir.int<s, 32>
1414
// CHECK: !rec_S = !cir.record<struct "S" {!s32i}>
1515
// CHECK: module {
16-
// CHECK: cir.func private @_ZN1SC1ERKS_(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) cxx_special_member<#cir.cxx_ctor<!rec_S, copy>>
17-
// CHECK: cir.func private @_ZN1SC2Ei(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) cxx_special_member<#cir.cxx_ctor<!rec_S, none>>
18-
// CHECK: cir.func private @_ZN1SC2Ev(!cir.ptr<!rec_S>) cxx_special_member<#cir.cxx_ctor<!rec_S, default>>
19-
// CHECK: cir.func private @_ZN1SD2Ev(!cir.ptr<!rec_S>) cxx_special_member<#cir.cxx_dtor<!rec_S>>
16+
// CHECK: cir.func private @_ZN1SC1ERKS_(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) cxx_ctor<!rec_S, copy>
17+
// CHECK: cir.func private @_ZN1SC2Ei(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>)
18+
// CHECK: cir.func private @_ZN1SC2Ev(!cir.ptr<!rec_S>) cxx_ctor<!rec_S, default>
19+
// CHECK: cir.func private @_ZN1SD2Ev(!cir.ptr<!rec_S>) cxx_dtor<!rec_S>
2020
// CHECK: }

0 commit comments

Comments
 (0)