Commit f4d2b56
[CIR][CodeGen] Add initial support for __cxa_rethrow (#1290)
This PR adds an initial support for `__cxa_rethrow`, and one test that
produces a rethrow.
I am very open to suggestions regarding this PR, because I'm still a bit
unsure if this replicates the original codegen properly. For example,
using the test added, the OG CodeGen produces:
```
entry:
invoke void @_ZN1SC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %s)
to label %invoke.cont unwind label %lpad
invoke.cont: ; preds = %entry
invoke void @__cxa_rethrow() #2
to label %unreachable unwind label %lpad
lpad: ; preds = %invoke.cont, %entry
%0 = landingpad { ptr, i32 }
catch ptr null
%1 = extractvalue { ptr, i32 } %0, 0
store ptr %1, ptr %exn.slot, align 8
%2 = extractvalue { ptr, i32 } %0, 1
store i32 %2, ptr %ehselector.slot, align 4
br label %catch
catch: ; preds = %lpad
%exn = load ptr, ptr %exn.slot, align 8
%3 = call ptr @__cxa_begin_catch(ptr %exn) #3
%4 = load i32, ptr %r, align 4
%inc = add nsw i32 %4, 1
store i32 %inc, ptr %r, align 4
call void @__cxa_end_catch()
br label %try.cont
```
and the proposed CIR equivalent produces:
```
invoke void @_ZN1SC2Ev(ptr %1)
to label %5 unwind label %9
5: ; preds = %4
invoke void @__cxa_rethrow()
to label %6 unwind label %13
6: ; preds = %5
br label %7
7: ; preds = %6
unreachable
8: ; No predecessors!
br label %22
9: ; preds = %4
%10 = landingpad { ptr, i32 }
catch ptr null
%11 = extractvalue { ptr, i32 } %10, 0
%12 = extractvalue { ptr, i32 } %10, 1
br label %17
13: ; preds = %5
%14 = landingpad { ptr, i32 }
catch ptr null
%15 = extractvalue { ptr, i32 } %14, 0
%16 = extractvalue { ptr, i32 } %14, 1
br label %17
17: ; preds = %13, %9
%18 = phi ptr [ %11, %9 ], [ %15, %13 ]
%19 = call ptr @__cxa_begin_catch(ptr %18)
%20 = load i32, ptr %2, align 4
%21 = add i32 %20, 1
store i32 %21, ptr %2, align 4
call void @__cxa_end_catch()
br label %22
```
There are quite a number of differences: `phi` in the CIR version VS
loading from `%exn.slot` in the OG, having multiple landing pads, etc.
The CIR version still seems reasonable to me, mostly because currently
we are unable to replicate the exact behavior of the OG codegen. Again,
I am very open to more discussions and suggestions here)1 parent e1a212c commit f4d2b56
File tree
4 files changed
+216
-5
lines changed- clang
- lib/CIR
- CodeGen
- Dialect/Transforms
- test/CIR/CodeGen
4 files changed
+216
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2261 | 2261 | | |
2262 | 2262 | | |
2263 | 2263 | | |
2264 | | - | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
2265 | 2275 | | |
2266 | 2276 | | |
2267 | 2277 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
429 | | - | |
430 | 429 | | |
431 | 430 | | |
432 | 431 | | |
433 | | - | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
434 | 437 | | |
435 | 438 | | |
436 | 439 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
1133 | 1134 | | |
1134 | 1135 | | |
1135 | 1136 | | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
1136 | 1156 | | |
1137 | 1157 | | |
1138 | 1158 | | |
| |||
1195 | 1215 | | |
1196 | 1216 | | |
1197 | 1217 | | |
| 1218 | + | |
| 1219 | + | |
1198 | 1220 | | |
1199 | 1221 | | |
1200 | 1222 | | |
| |||
1211 | 1233 | | |
1212 | 1234 | | |
1213 | 1235 | | |
1214 | | - | |
| 1236 | + | |
1215 | 1237 | | |
1216 | 1238 | | |
1217 | 1239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
0 commit comments