@@ -312,6 +312,11 @@ def ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", [TypedAttrInterface]>
312312 zeros = typeSize - mlir::cast<mlir::ArrayAttr>(elts).size();
313313
314314 return $_get(type.getContext(), type, elts, zeros);
315+ }]>,
316+ AttrBuilderWithInferredContext<(ins "cir::ArrayType":$type,
317+ "mlir::Attribute":$elts,
318+ "int":$trailingZerosNum), [{
319+ return $_get(type.getContext(), type, elts, trailingZerosNum);
315320 }]>
316321 ];
317322
@@ -510,11 +515,7 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
510515 let builders = [
511516 AttrBuilderWithInferredContext<(ins "mlir::Type":$type, "mlir::IntegerAttr":$value), [{
512517 return $_get(type.getContext(), mlir::cast<cir::PointerType>(type), value);
513- }]>,
514- AttrBuilder<(ins "mlir::Type":$type,
515- "mlir::IntegerAttr":$value), [{
516- return $_get($_ctxt, mlir::cast<cir::PointerType>(type), value);
517- }]>,
518+ }]>
518519 ];
519520 let extraClassDeclaration = [{
520521 bool isNullValue() const { return getValue().getInt() == 0; }
@@ -614,6 +615,16 @@ def DataMemberAttr : CIR_Attr<"DataMember", "data_member",
614615 ```
615616 }];
616617
618+ let builders = [
619+ AttrBuilderWithInferredContext<(ins "cir::DataMemberType":$type), [{
620+ return $_get(type.getContext(), type, std::nullopt);
621+ }]>,
622+ AttrBuilderWithInferredContext<(ins "cir::DataMemberType":$type,
623+ "unsigned":$member_index), [{
624+ return $_get(type.getContext(), type, member_index);
625+ }]>,
626+ ];
627+
617628 let genVerifyDecl = 1;
618629
619630 let assemblyFormat = [{
@@ -733,12 +744,12 @@ def GlobalViewAttr : CIR_Attr<"GlobalView", "global_view", [TypedAttrInterface]>
733744 cir.global external @elt_ptr = #cir.global_view<@rgb, [1]> : !cir.ptr<i8>
734745 cir.global external @table_of_ptrs = #cir.const_array<[#cir.global_view<@rgb, [1]> : !cir.ptr<i8>] : !cir.array<!cir.ptr<i8> x 1>>
735746 ```
736-
747+
737748 Note, that unlike LLVM IR's gep instruction, CIR doesn't add the leading zero index
738749 when it's known to be constant zero, e.g. for pointers, i.e. we use indexes exactly
739750 to access sub elements or for the offset. The leading zero index is added later in
740751 the lowering.
741-
752+
742753 Example:
743754 ```
744755 struct A {
@@ -751,7 +762,7 @@ def GlobalViewAttr : CIR_Attr<"GlobalView", "global_view", [TypedAttrInterface]>
751762 ```
752763 VTT for B:
753764 ```
754- cir.global linkonce_odr @_ZTT1B = #cir.const_array<[#cir.global_view<@_ZTV1B, [0 : i32, 3 : i32]> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 1>
765+ cir.global linkonce_odr @_ZTT1B = #cir.const_array<[#cir.global_view<@_ZTV1B, [0 : i32, 3 : i32]> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 1>
755766 ```
756767 The same for LLVM IR after CIR:
757768 ```
@@ -1189,6 +1200,12 @@ def ExtraFuncAttr : CIR_Attr<"ExtraFuncAttributes", "extra"> {
11891200
11901201 let parameters = (ins "mlir::DictionaryAttr":$elements);
11911202
1203+ let builders = [
1204+ AttrBuilderWithInferredContext<(ins "mlir::DictionaryAttr":$elements), [{
1205+ return $_get(elements.getContext(), elements);
1206+ }]>
1207+ ];
1208+
11921209 let assemblyFormat = [{ `(` $elements `)` }];
11931210
11941211 // Printing and parsing also available in CIRDialect.cpp
@@ -1281,6 +1298,10 @@ class CIR_GlobalCtorDtor<string name, string attrMnemonic,
12811298 AttrBuilder<(ins "llvm::StringRef":$name,
12821299 CArg<"int", "65536">:$priority), [{
12831300 return $_get($_ctxt, mlir::StringAttr::get($_ctxt, name), priority);
1301+ }]>,
1302+ AttrBuilderWithInferredContext<(ins "mlir::StringAttr":$name,
1303+ CArg<"int", "65536">:$priority), [{
1304+ return $_get(name.getContext(), name, priority);
12841305 }]>
12851306 ];
12861307 let extraClassDeclaration = [{
@@ -1349,6 +1370,13 @@ def AnnotationAttr : CIR_Attr<"Annotation", "annotation"> {
13491370 let parameters = (ins "mlir::StringAttr":$name,
13501371 "mlir::ArrayAttr":$args);
13511372
1373+ let builders = [
1374+ AttrBuilderWithInferredContext<(ins "mlir::StringAttr":$name,
1375+ CArg<"mlir::ArrayAttr", "{}">:$args), [{
1376+ return $_get(name.getContext(), name, args);
1377+ }]>
1378+ ];
1379+
13521380 let assemblyFormat = "`<` struct($name, $args) `>`";
13531381
13541382 let extraClassDeclaration = [{
@@ -1389,6 +1417,12 @@ def GlobalAnnotationValuesAttr : CIR_Attr<"GlobalAnnotationValues",
13891417
13901418 let parameters = (ins "mlir::ArrayAttr":$annotations);
13911419
1420+ let builders = [
1421+ AttrBuilderWithInferredContext<(ins "mlir::ArrayAttr":$annotations), [{
1422+ return $_get(annotations.getContext(), annotations);
1423+ }]>
1424+ ];
1425+
13921426 let assemblyFormat = [{ $annotations }];
13931427
13941428 // Enable verifier.
@@ -1402,7 +1436,7 @@ def GlobalAnnotationValuesAttr : CIR_Attr<"GlobalAnnotationValues",
14021436def AddressPointAttr : CIR_Attr<"AddressPoint", "address_point"> {
14031437 let summary = "Address point attribute";
14041438
1405- let description = [{
1439+ let description = [{
14061440 Attribute specifying the address point within a C++ virtual table (vtable).
14071441
14081442 The `index` (vtable index) parameter identifies which vtable to use within a vtable
0 commit comments