Skip to content

Commit 823e943

Browse files
authored
[CIR] Update cir.dyn_cast to use uniform assemby form w/o parens, commas (#1924)
1 parent 4e4fb8d commit 823e943

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ def CIR_DynamicCastOp : CIR_Op<"dyn_cast"> {
287287
The `relative_layout` argument specifies whether the Itanium C++ ABI vtable
288288
uses relative layout. It is only meaningful when the operation models a
289289
cast-to-complete operation.
290+
291+
Example:
292+
293+
```mlir
294+
%res = cir.dyn_cast ptr %ptr: !cir.ptr<!rec_Base> -> !cir.ptr<!rec_Derived>
295+
%res = cir.dyn_cast ptr relative_layout %ptr: !cir.ptr<!rec_Base> -> !cir.ptr<!rec_Derived>
296+
```
290297
}];
291298

292299
let arguments = (ins
@@ -301,12 +308,9 @@ def CIR_DynamicCastOp : CIR_Op<"dyn_cast"> {
301308
);
302309

303310
let assemblyFormat = [{
304-
`(`
305-
$kind `,` $src `:` qualified(type($src))
306-
(`,` qualified($info)^)?
307-
(`relative_layout` $relative_layout^)?
308-
`)`
309-
`->` qualified(type($result)) attr-dict
311+
$kind (`relative_layout` $relative_layout^)? $src
312+
`:` qualified(type($src)) `->` qualified(type($result))
313+
(qualified($info)^)? attr-dict
310314
}];
311315

312316
let extraClassDeclaration = [{

clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void *ptr_cast_to_complete(Base *ptr) {
1212
}
1313

1414
// BEFORE: cir.func dso_local @_Z20ptr_cast_to_completeP4Base
15-
// BEFORE: %{{.+}} = cir.dyn_cast(ptr, %{{.+}} : !cir.ptr<!rec_Base> relative_layout) -> !cir.ptr<!void>
15+
// BEFORE: %{{.+}} = cir.dyn_cast ptr relative_layout %{{.+}} : !cir.ptr<!rec_Base> -> !cir.ptr<!void>
1616
// BEFORE: }
1717

1818
// AFTER: cir.func dso_local @_Z20ptr_cast_to_completeP4Base

clang/test/CIR/CodeGen/dynamic-cast.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Derived *ptr_cast(Base *b) {
1818
}
1919

2020
// BEFORE: cir.func dso_local @_Z8ptr_castP4Base
21-
// BEFORE: %{{.+}} = cir.dyn_cast(ptr, %{{.+}} : !cir.ptr<!rec_Base>, #dyn_cast_info__ZTI4Base__ZTI7Derived) -> !cir.ptr<!rec_Derived>
21+
// BEFORE: %{{.+}} = cir.dyn_cast ptr %{{.+}} : !cir.ptr<!rec_Base> -> !cir.ptr<!rec_Derived> #dyn_cast_info__ZTI4Base__ZTI7Derived
2222
// BEFORE: }
2323

2424
// AFTER: cir.func dso_local @_Z8ptr_castP4Base
@@ -43,7 +43,7 @@ Derived &ref_cast(Base &b) {
4343
}
4444

4545
// BEFORE: cir.func dso_local @_Z8ref_castR4Base
46-
// BEFORE: %{{.+}} = cir.dyn_cast(ref, %{{.+}} : !cir.ptr<!rec_Base>, #dyn_cast_info__ZTI4Base__ZTI7Derived) -> !cir.ptr<!rec_Derived>
46+
// BEFORE: %{{.+}} = cir.dyn_cast ref %{{.+}} : !cir.ptr<!rec_Base> -> !cir.ptr<!rec_Derived> #dyn_cast_info__ZTI4Base__ZTI7Derived
4747
// BEFORE: }
4848

4949
// AFTER: cir.func dso_local @_Z8ref_castR4Base
@@ -66,7 +66,7 @@ void *ptr_cast_to_complete(Base *ptr) {
6666
}
6767

6868
// BEFORE: cir.func dso_local @_Z20ptr_cast_to_completeP4Base
69-
// BEFORE: %{{.+}} = cir.dyn_cast(ptr, %{{.+}} : !cir.ptr<!rec_Base>) -> !cir.ptr<!void>
69+
// BEFORE: %{{.+}} = cir.dyn_cast ptr %{{.+}} : !cir.ptr<!rec_Base> -> !cir.ptr<!void>
7070
// BEFORE: }
7171

7272
// AFTER: cir.func dso_local @_Z20ptr_cast_to_completeP4Base

clang/test/CIR/IR/invalid.cir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ module {
11921192
cir.func private @__cxa_bad_cast()
11931193
cir.func @test(%arg0 : !cir.ptr<!Base>) {
11941194
// expected-error@+1 {{srcRtti must be an RTTI pointer}}
1195-
%0 = cir.dyn_cast(ptr, %arg0 : !cir.ptr<!Base>, #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u32i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u8i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>) -> !cir.ptr<!Derived>
1195+
%0 = cir.dyn_cast ptr %arg0 : !cir.ptr<!Base> -> !cir.ptr<!Derived> #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u32i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u8i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>
11961196
}
11971197
}
11981198

@@ -1214,7 +1214,7 @@ module {
12141214
cir.func private @__cxa_bad_cast()
12151215
cir.func @test(%arg0 : !cir.ptr<!Base>) {
12161216
// expected-error@+1 {{destRtti must be an RTTI pointer}}
1217-
%0 = cir.dyn_cast(ptr, %arg0 : !cir.ptr<!Base>, #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u32i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>) -> !cir.ptr<!Derived>
1217+
%0 = cir.dyn_cast ptr %arg0 : !cir.ptr<!Base> -> !cir.ptr<!Derived> #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u32i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>
12181218
}
12191219
}
12201220

0 commit comments

Comments
 (0)