Skip to content

Commit 6486c6d

Browse files
definelichtlanza
authored andcommitted
[CIR][NFC] Homogenize printing/parsing of CIR_PointerType (#575)
This PR relegates the responsibility of printing/parsing CIR_PointerType back to the type itself, getting rid of explicit `cir.ptr` tokens in the assembly format of CIR operations. This means that CIR pointers would now always be printed as `!cir.ptr<type>`, so update all tests that had a space before the bracket (i.e., `!cir.ptr <type>`) or missing the type alias prefix (`cir.ptr` instead of `!cir.ptr`).
1 parent 04ec1c4 commit 6486c6d

File tree

168 files changed

+1620
-1649
lines changed

Some content is hidden

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

168 files changed

+1620
-1649
lines changed

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

+28-40
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def AllocaOp : CIR_Op<"alloca", [
392392
%0 = cir.alloca i32, !cir.ptr<i32>, ["count", init] {alignment = 4 : i64}
393393

394394
// int *ptr;
395-
%1 = cir.alloca !cir.ptr<i32>, cir.ptr <!cir.ptr<i32>>, ["ptr"] {alignment = 8 : i64}
395+
%1 = cir.alloca !cir.ptr<i32>, !cir.ptr<!cir.ptr<i32>>, ["ptr"] {alignment = 8 : i64}
396396
...
397397
```
398398
}];
@@ -434,10 +434,8 @@ def AllocaOp : CIR_Op<"alloca", [
434434
bool isDynamic() { return (bool)getDynAllocSize(); }
435435
}];
436436

437-
// FIXME: we should not be printing `cir.ptr` below, that should come
438-
// from the pointer type directly.
439437
let assemblyFormat = [{
440-
$allocaType `,` `cir.ptr` type($addr) `,`
438+
$allocaType `,` qualified(type($addr)) `,`
441439
($dynAllocSize^ `:` type($dynAllocSize) `,`)?
442440
`[` $name
443441
(`,` `init` $init^)?
@@ -474,7 +472,7 @@ def LoadOp : CIR_Op<"load", [
474472

475473
// Load address from memory at address %0. %3 is used by at least one
476474
// operation that dereferences a pointer.
477-
%3 = cir.load deref %0 : cir.ptr <!cir.ptr<i32>>
475+
%3 = cir.load deref %0 : !cir.ptr<!cir.ptr<i32>>
478476

479477
// Perform a volatile load from address in %0.
480478
%4 = cir.load volatile %0 : !cir.ptr<i32>, i32
@@ -487,13 +485,11 @@ def LoadOp : CIR_Op<"load", [
487485
OptionalAttr<MemOrder>:$mem_order);
488486
let results = (outs CIR_AnyType:$result);
489487

490-
// FIXME: we should not be printing `cir.ptr` below, that should come
491-
// from the pointer type directly.
492488
let assemblyFormat = [{
493489
(`deref` $isDeref^)?
494490
(`volatile` $is_volatile^)?
495491
(`atomic` `(` $mem_order^ `)`)?
496-
$addr `:` `cir.ptr` type($addr) `,` type($result) attr-dict
492+
$addr `:` qualified(type($addr)) `,` type($result) attr-dict
497493
}];
498494

499495
// FIXME: add verifier.
@@ -532,12 +528,10 @@ def StoreOp : CIR_Op<"store", [
532528
UnitAttr:$is_volatile,
533529
OptionalAttr<MemOrder>:$mem_order);
534530

535-
// FIXME: we should not be printing `cir.ptr` below, that should come
536-
// from the pointer type directly.
537531
let assemblyFormat = [{
538532
(`volatile` $is_volatile^)?
539533
(`atomic` `(` $mem_order^ `)`)?
540-
$value `,` $addr attr-dict `:` type($value) `,` `cir.ptr` type($addr)
534+
$value `,` $addr attr-dict `:` type($value) `,` qualified(type($addr))
541535
}];
542536

543537
// FIXME: add verifier.
@@ -999,7 +993,7 @@ def BinOp : CIR_Op<"binop", [Pure,
999993
UnitAttr:$no_signed_wrap);
1000994

1001995
let assemblyFormat = [{
1002-
`(` $kind `,` $lhs `,` $rhs `)`
996+
`(` $kind `,` $lhs `,` $rhs `)`
1003997
(`nsw` $no_signed_wrap^)?
1004998
(`nuw` $no_unsigned_wrap^)?
1005999
`:` type($lhs) attr-dict
@@ -1871,11 +1865,9 @@ def GetGlobalOp : CIR_Op<"get_global",
18711865
let arguments = (ins FlatSymbolRefAttr:$name, UnitAttr:$tls);
18721866
let results = (outs Res<CIR_PointerType, "", []>:$addr);
18731867

1874-
// FIXME: we should not be printing `cir.ptr` below, that should come
1875-
// from the pointer type directly.
18761868
let assemblyFormat = [{
18771869
(`thread_local` $tls^)?
1878-
$name `:` `cir.ptr` type($addr) attr-dict
1870+
$name `:` qualified(type($addr)) attr-dict
18791871
}];
18801872

18811873
// `GetGlobalOp` is fully verified by its traits.
@@ -1904,7 +1896,7 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point",
19041896
```mlir
19051897
cir.global linkonce_odr @_ZTV1B = ...
19061898
...
1907-
%3 = cir.vtable.address_point(@_ZTV1B, vtable_index = 0, address_point_index = 2) : cir.ptr <!cir.ptr<() -> i32>>
1899+
%3 = cir.vtable.address_point(@_ZTV1B, vtable_index = 0, address_point_index = 2) : !cir.ptr<!cir.ptr<() -> i32>>
19081900
```
19091901
}];
19101902

@@ -1914,8 +1906,6 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point",
19141906
I32Attr:$address_point_index);
19151907
let results = (outs Res<CIR_PointerType, "", []>:$addr);
19161908

1917-
// FIXME: we should not be printing `cir.ptr` below, that should come
1918-
// from the pointer type directly.
19191909
let assemblyFormat = [{
19201910
`(`
19211911
($name^)?
@@ -1924,7 +1914,7 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point",
19241914
`vtable_index` `=` $vtable_index `,`
19251915
`address_point_index` `=` $address_point_index
19261916
`)`
1927-
`:` `cir.ptr` type($addr) attr-dict
1917+
`:` qualified(type($addr)) attr-dict
19281918
}];
19291919

19301920
let hasVerifier = 1;
@@ -1972,7 +1962,7 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
19721962
#bfi_d = #cir.bitfield_info<name = "d", storage_type = !u32i, size = 2, offset = 17, is_signed = true>
19731963

19741964
%1 = cir.const(#cir.int<3> : !s32i) : !s32i
1975-
%2 = cir.load %0 : cir.ptr <!cir.ptr<!struct_type>>, !cir.ptr<!struct_type>
1965+
%2 = cir.load %0 : !cir.ptr<!cir.ptr<!struct_type>>, !cir.ptr<!struct_type>
19761966
%3 = cir.get_member %2[1] {name = "d"} : !cir.ptr<!struct_type> -> !cir.ptr<!u32i>
19771967
%4 = cir.set_bitfield(#bfi_d, %3 : !cir.ptr<!u32i>, %1 : !s32i) -> !s32i
19781968
```
@@ -2051,7 +2041,7 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
20512041
!struct_type = !cir.struct<struct "S" {!cir.int<u, 32>, !cir.int<u, 32>, !cir.int<u, 16>} #cir.record.decl.ast>
20522042
#bfi_d = #cir.bitfield_info<name = "d", storage_type = !u32i, size = 2, offset = 17, is_signed = true>
20532043

2054-
%2 = cir.load %0 : cir.ptr <!cir.ptr<!struct_type>>, !cir.ptr<!struct_type>
2044+
%2 = cir.load %0 : !cir.ptr<!cir.ptr<!struct_type>>, !cir.ptr<!struct_type>
20552045
%3 = cir.get_member %2[1] {name = "d"} : !cir.ptr<!struct_type> -> !cir.ptr<!u32i>
20562046
%4 = cir.get_bitfield(#bfi_d, %3 : !cir.ptr<!u32i>) -> !s32i
20572047
```
@@ -2453,12 +2443,10 @@ def BaseClassAddrOp : CIR_Op<"base_class_addr"> {
24532443

24542444
let results = (outs Res<CIR_PointerType, "">:$base_addr);
24552445

2456-
// FIXME: we should not be printing `cir.ptr` below, that should come
2457-
// from the pointer type directly.
24582446
let assemblyFormat = [{
24592447
`(`
2460-
$derived_addr `:` `cir.ptr` type($derived_addr)
2461-
`)` `->` `cir.ptr` type($base_addr) attr-dict
2448+
$derived_addr `:` qualified(type($derived_addr))
2449+
`)` `->` qualified(type($base_addr)) attr-dict
24622450
}];
24632451

24642452
// FIXME: add verifier.
@@ -2761,7 +2749,7 @@ def TryCallOp : CIR_CallOp<"try_call"> {
27612749

27622750
```mlir
27632751
cir.try {
2764-
%0 = cir.alloca !cir.ptr<!cir.eh.info>, cir.ptr <!cir.ptr<!cir.eh.info>>
2752+
%0 = cir.alloca !cir.ptr<!cir.eh.info>, !cir.ptr<!cir.ptr<!cir.eh.info>>
27652753
...
27662754
%r = cir.try_call %exception(%0) @division(%1, %2)
27672755
} ...
@@ -3393,10 +3381,10 @@ def StackRestoreOp : CIR_Op<"stack_restore"> {
33933381
Useful for implementing language features like variable length arrays.
33943382

33953383
```mlir
3396-
%0 = cir.alloca !cir.ptr<!u8i>, cir.ptr <!cir.ptr<!u8i>>, ["saved_stack"] {alignment = 8 : i64}
3384+
%0 = cir.alloca !cir.ptr<!u8i>, !cir.ptr<!cir.ptr<!u8i>>, ["saved_stack"] {alignment = 8 : i64}
33973385
%1 = cir.stack_save : <!u8i>
3398-
cir.store %1, %0 : !cir.ptr<!u8i>, cir.ptr <!cir.ptr<!u8i>>
3399-
%2 = cir.load %0 : cir.ptr <!cir.ptr<!u8i>>, !cir.ptr<!u8i>
3386+
cir.store %1, %0 : !cir.ptr<!u8i>, !cir.ptr<!cir.ptr<!u8i>>
3387+
%2 = cir.load %0 : !cir.ptr<!cir.ptr<!u8i>>, !cir.ptr<!u8i>
34003388
cir.stack_restore %2 : !cir.ptr<!u8i>
34013389
```
34023390
}];
@@ -3419,16 +3407,16 @@ def CIR_InlineAsmOp : CIR_Op<"asm", [RecursiveMemoryEffects]> {
34193407
let description = [{
34203408
The `cir.asm` operation represents C/C++ asm inline.
34213409

3422-
CIR constraints strings follow barelly the same rules that are established
3423-
for the C level assembler constraints with several differences caused by
3424-
clang::AsmStmt processing.
3410+
CIR constraints strings follow barelly the same rules that are established
3411+
for the C level assembler constraints with several differences caused by
3412+
clang::AsmStmt processing.
34253413

34263414
Thus, numbers that appears in the constraint string may also refer to:
34273415
- the output variable index referenced by the input operands.
34283416
- the index of early-clobber operand
34293417

34303418
Operand attributes is a storage, where each element corresponds to the operand with
3431-
the same index. The first index relates to the operation result (if any).
3419+
the same index. The first index relates to the operation result (if any).
34323420
Note, the operands themselves are stored as VariadicOfVariadic in the next order:
34333421
output, input and then in/out operands.
34343422

@@ -3441,16 +3429,16 @@ def CIR_InlineAsmOp : CIR_Op<"asm", [RecursiveMemoryEffects]> {
34413429
__asm__("bar $42 %[val]" : [val] "=r" (x), "+&r"(x));
34423430
__asm__("baz $42 %[val]" : [val] "=r" (x), "+&r"(x) : "[val]"(y));
34433431
```
3444-
3432+
34453433
```mlir
34463434
!ty_22anon2E022 = !cir.struct<struct "anon.0" {!cir.int<s, 32>, !cir.int<s, 32>}>
34473435
!ty_22anon2E122 = !cir.struct<struct "anon.1" {!cir.int<s, 32>, !cir.int<s, 32>}>
34483436
...
3449-
%0 = cir.alloca !s32i, cir.ptr <!s32i>, ["x", init]
3450-
%1 = cir.alloca !s32i, cir.ptr <!s32i>, ["y", init]
3451-
...
3452-
%2 = cir.load %0 : cir.ptr <!s32i>, !s32i
3453-
%3 = cir.load %1 : cir.ptr <!s32i>, !s32i
3437+
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init]
3438+
%1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["y", init]
3439+
...
3440+
%2 = cir.load %0 : !cir.ptr<!s32i>, !s32i
3441+
%3 = cir.load %1 : !cir.ptr<!s32i>, !s32i
34543442

34553443
cir.asm(x86_att,
34563444
out = [],
@@ -3493,7 +3481,7 @@ def CIR_InlineAsmOp : CIR_Op<"asm", [RecursiveMemoryEffects]> {
34933481
"ArrayRef<Attribute>":$operand_attrs
34943482
)>
34953483
];
3496-
3484+
34973485
let hasCustomAssemblyFormat = 1;
34983486
}
34993487

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def PrimitiveInt
127127
// FloatType
128128
//===----------------------------------------------------------------------===//
129129

130-
class CIR_FloatType<string name, string mnemonic>
130+
class CIR_FloatType<string name, string mnemonic>
131131
: CIR_Type<name, mnemonic,
132132
[
133133
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
@@ -196,7 +196,7 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr",
196196

197197
let parameters = (ins "mlir::Type":$pointee);
198198

199-
let hasCustomAssemblyFormat = 1;
199+
let assemblyFormat = "`<` $pointee `>`";
200200
}
201201

202202
//===----------------------------------------------------------------------===//

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

-17
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,6 @@ void CIRDialect::printType(Type type, DialectAsmPrinter &os) const {
9696
});
9797
}
9898

99-
Type PointerType::parse(mlir::AsmParser &parser) {
100-
if (parser.parseLess())
101-
return Type();
102-
Type pointeeType;
103-
if (parser.parseType(pointeeType))
104-
return Type();
105-
if (parser.parseGreater())
106-
return Type();
107-
return get(parser.getContext(), pointeeType);
108-
}
109-
110-
void PointerType::print(mlir::AsmPrinter &printer) const {
111-
printer << "<";
112-
printer.printType(getPointee());
113-
printer << '>';
114-
}
115-
11699
Type BoolType::parse(mlir::AsmParser &parser) {
117100
return get(parser.getContext());
118101
}

clang/test/CIR/CodeGen/String.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,47 @@ void test() {
2323
// CHECK-NEXT: %1 = cir.load %0
2424
// CHECK-NEXT: %2 = cir.get_member %1[0] {name = "storage"}
2525
// CHECK-NEXT: %3 = cir.const(#cir.ptr<null> : !cir.ptr<!s8i>) : !cir.ptr<!s8i>
26-
// CHECK-NEXT: cir.store %3, %2 : !cir.ptr<!s8i>, cir.ptr <!cir.ptr<!s8i>>
26+
// CHECK-NEXT: cir.store %3, %2 : !cir.ptr<!s8i>, !cir.ptr<!cir.ptr<!s8i>>
2727
// CHECK-NEXT: %4 = cir.get_member %1[1] {name = "size"} : !cir.ptr<!ty_22String22> -> !cir.ptr<!s64i>
2828
// CHECK-NEXT: %5 = cir.const(#cir.int<0> : !s32i) : !s32i
2929
// CHECK-NEXT: %6 = cir.cast(integral, %5 : !s32i), !s64i
30-
// CHECK-NEXT: cir.store %6, %4 : !s64i, cir.ptr <!s64i>
30+
// CHECK-NEXT: cir.store %6, %4 : !s64i, !cir.ptr<!s64i>
3131
// CHECK-NEXT: cir.return
3232
// CHECK-NEXT: }
3333
// CHECK: cir.func linkonce_odr @_ZN6StringC2Ei
3434
// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_22String22>
35-
// CHECK-NEXT: %1 = cir.alloca !s32i, cir.ptr <!s32i>, ["size", init]
35+
// CHECK-NEXT: %1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["size", init]
3636
// CHECK-NEXT: cir.store %arg0, %0
3737
// CHECK-NEXT: cir.store %arg1, %1
3838
// CHECK-NEXT: %2 = cir.load %0
3939
// CHECK-NEXT: %3 = cir.get_member %2[0] {name = "storage"}
4040
// CHECK-NEXT: %4 = cir.const(#cir.ptr<null> : !cir.ptr<!s8i>)
4141
// CHECK-NEXT: cir.store %4, %3
4242
// CHECK-NEXT: %5 = cir.get_member %2[1] {name = "size"} : !cir.ptr<!ty_22String22> -> !cir.ptr<!s64i>
43-
// CHECK-NEXT: %6 = cir.load %1 : cir.ptr <!s32i>, !s32i
43+
// CHECK-NEXT: %6 = cir.load %1 : !cir.ptr<!s32i>, !s32i
4444
// CHECK-NEXT: %7 = cir.cast(integral, %6 : !s32i), !s64i
45-
// CHECK-NEXT: cir.store %7, %5 : !s64i, cir.ptr <!s64i>
45+
// CHECK-NEXT: cir.store %7, %5 : !s64i, !cir.ptr<!s64i>
4646
// CHECK-NEXT: cir.return
4747
// CHECK-NEXT: }
4848

4949
// CHECK: cir.func linkonce_odr @_ZN6StringC2EPKc
50-
// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_22String22>, cir.ptr <!cir.ptr<!ty_22String22>>, ["this", init] {alignment = 8 : i64}
51-
// CHECK-NEXT: %1 = cir.alloca !cir.ptr<!s8i>, cir.ptr <!cir.ptr<!s8i>>, ["s", init] {alignment = 8 : i64}
52-
// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_22String22>, cir.ptr <!cir.ptr<!ty_22String22>>
53-
// CHECK-NEXT: cir.store %arg1, %1 : !cir.ptr<!s8i>, cir.ptr <!cir.ptr<!s8i>>
54-
// CHECK-NEXT: %2 = cir.load %0 : cir.ptr <!cir.ptr<!ty_22String22>>, !cir.ptr<!ty_22String22>
50+
// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_22String22>, !cir.ptr<!cir.ptr<!ty_22String22>>, ["this", init] {alignment = 8 : i64}
51+
// CHECK-NEXT: %1 = cir.alloca !cir.ptr<!s8i>, !cir.ptr<!cir.ptr<!s8i>>, ["s", init] {alignment = 8 : i64}
52+
// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_22String22>, !cir.ptr<!cir.ptr<!ty_22String22>>
53+
// CHECK-NEXT: cir.store %arg1, %1 : !cir.ptr<!s8i>, !cir.ptr<!cir.ptr<!s8i>>
54+
// CHECK-NEXT: %2 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_22String22>>, !cir.ptr<!ty_22String22>
5555
// CHECK-NEXT: %3 = cir.get_member %2[0] {name = "storage"} : !cir.ptr<!ty_22String22> -> !cir.ptr<!cir.ptr<!s8i>>
5656
// CHECK-NEXT: %4 = cir.const(#cir.ptr<null> : !cir.ptr<!s8i>) : !cir.ptr<!s8i>
57-
// CHECK-NEXT: cir.store %4, %3 : !cir.ptr<!s8i>, cir.ptr <!cir.ptr<!s8i>>
57+
// CHECK-NEXT: cir.store %4, %3 : !cir.ptr<!s8i>, !cir.ptr<!cir.ptr<!s8i>>
5858
// CHECK-NEXT: cir.return
5959

6060
// CHECK: cir.func linkonce_odr @_ZN6StringC1EPKc
61-
// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_22String22>, cir.ptr <!cir.ptr<!ty_22String22>>, ["this", init] {alignment = 8 : i64}
62-
// CHECK-NEXT: %1 = cir.alloca !cir.ptr<!s8i>, cir.ptr <!cir.ptr<!s8i>>, ["s", init] {alignment = 8 : i64}
63-
// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_22String22>, cir.ptr <!cir.ptr<!ty_22String22>>
64-
// CHECK-NEXT: cir.store %arg1, %1 : !cir.ptr<!s8i>, cir.ptr <!cir.ptr<!s8i>>
65-
// CHECK-NEXT: %2 = cir.load %0 : cir.ptr <!cir.ptr<!ty_22String22>>, !cir.ptr<!ty_22String22>
66-
// CHECK-NEXT: %3 = cir.load %1 : cir.ptr <!cir.ptr<!s8i>>, !cir.ptr<!s8i>
61+
// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_22String22>, !cir.ptr<!cir.ptr<!ty_22String22>>, ["this", init] {alignment = 8 : i64}
62+
// CHECK-NEXT: %1 = cir.alloca !cir.ptr<!s8i>, !cir.ptr<!cir.ptr<!s8i>>, ["s", init] {alignment = 8 : i64}
63+
// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_22String22>, !cir.ptr<!cir.ptr<!ty_22String22>>
64+
// CHECK-NEXT: cir.store %arg1, %1 : !cir.ptr<!s8i>, !cir.ptr<!cir.ptr<!s8i>>
65+
// CHECK-NEXT: %2 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_22String22>>, !cir.ptr<!ty_22String22>
66+
// CHECK-NEXT: %3 = cir.load %1 : !cir.ptr<!cir.ptr<!s8i>>, !cir.ptr<!s8i>
6767
// CHECK-NEXT: cir.call @_ZN6StringC2EPKc(%2, %3) : (!cir.ptr<!ty_22String22>, !cir.ptr<!s8i>) -> ()
6868
// CHECK-NEXT: cir.return
6969

0 commit comments

Comments
 (0)