Skip to content

Commit 9d01faa

Browse files
eddybFirestar99
authored andcommitted
Use ExitInvocation for panics (avoiding deeply nested structurization).
1 parent 9939114 commit 9d01faa

File tree

7 files changed

+74
-65
lines changed

7 files changed

+74
-65
lines changed

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ pub fn link(
442442
}
443443

444444
// NOTE(eddyb) this *must* run on unstructured CFGs, to do its job.
445+
// FIXME(eddyb) no longer relying on structurization, try porting this
446+
// to replace custom aborts in `Block`s and inject `ExitInvocation`s
447+
// after them (truncating the `Block` and/or parent region if necessary).
445448
{
446449
let _timer = sess.timer("spirt_passes::controlflow::convert_custom_aborts_to_unstructured_returns_in_entry_points");
447450
spirt_passes::controlflow::convert_custom_aborts_to_unstructured_returns_in_entry_points(opts, &mut module);

crates/rustc_codegen_spirv/src/linker/spirt_passes/controlflow.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use std::fmt::Write as _;
1111

1212
/// Replace our custom extended instruction `Abort`s with standard `OpReturn`s,
1313
/// but only in entry-points (and only before CFG structurization).
14+
//
15+
// FIXME(eddyb) no longer relying on structurization, try porting this
16+
// to replace custom aborts in `Block`s and inject `ExitInvocation`s
17+
// after them (truncating the `Block` and/or parent region if necessary).
1418
pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
1519
linker_options: &crate::linker::Options,
1620
module: &mut Module,
@@ -252,7 +256,9 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
252256
)) = custom_terminator_inst
253257
{
254258
let abort_inst = func_at_abort_inst.position;
255-
terminator.kind = cfg::ControlInstKind::Return;
259+
terminator.kind = cfg::ControlInstKind::ExitInvocation(
260+
cfg::ExitInvocationKind::SpvInst(wk.OpReturn.into()),
261+
);
256262

257263
match abort_strategy {
258264
Some(Strategy::Unreachable) => {

tests/ui/dis/entry-pass-mode-cast-array.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ OpNoLine
88
OpSelectionMerge %13 None
99
OpBranchConditional %9 %14 %15
1010
%14 = OpLabel
11+
OpBranch %13
12+
%15 = OpLabel
13+
OpReturn
14+
%13 = OpLabel
1115
OpLine %5 14 4
1216
%16 = OpCompositeExtract %17 %6 0
1317
%18 = OpFAdd %17 %16 %19
1418
%20 = OpCompositeInsert %7 %18 %6 0
1519
OpLine %5 15 4
1620
OpStore %21 %20
1721
OpNoLine
18-
OpBranch %13
19-
%15 = OpLabel
20-
OpBranch %13
21-
%13 = OpLabel
2222
OpReturn
2323
OpFunctionEnd

tests/ui/dis/index_user_dst.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ OpNoLine
99
OpSelectionMerge %14 None
1010
OpBranchConditional %12 %15 %16
1111
%15 = OpLabel
12+
OpBranch %14
13+
%16 = OpLabel
14+
OpReturn
15+
%14 = OpLabel
1216
OpLine %5 10 21
1317
%17 = OpInBoundsAccessChain %18 %6 %9
1418
%19 = OpLoad %20 %17
1519
OpNoLine
16-
OpBranch %14
17-
%16 = OpLabel
18-
OpBranch %14
19-
%14 = OpLabel
2020
OpReturn
2121
OpFunctionEnd

tests/ui/dis/issue-731.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ OpNoLine
88
OpSelectionMerge %13 None
99
OpBranchConditional %9 %14 %15
1010
%14 = OpLabel
11+
OpBranch %13
12+
%15 = OpLabel
13+
OpReturn
14+
%13 = OpLabel
1115
OpLine %5 12 4
1216
%16 = OpCompositeExtract %17 %6 0
1317
%18 = OpFAdd %17 %16 %19
1418
%20 = OpCompositeInsert %7 %18 %6 0
1519
OpLine %5 13 4
1620
OpStore %21 %20
1721
OpNoLine
18-
OpBranch %13
19-
%15 = OpLabel
20-
OpBranch %13
21-
%13 = OpLabel
2222
OpReturn
2323
OpFunctionEnd

tests/ui/dis/panic_builtin_bounds_check.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ OpBranch %14
3232
OpLine %4 275 4
3333
%17 = OpExtInst %6 %1 1 %3 %11 %10
3434
OpNoLine
35-
OpBranch %14
35+
OpReturn
3636
%14 = OpLabel
3737
OpReturn
3838
OpFunctionEnd

tests/ui/dis/panic_sequential_many.stderr

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ OpBranchConditional %18 %20 %21
4545
OpLine %7 29 9
4646
%22 = OpExtInst %11 %1 1 %6
4747
OpNoLine
48-
OpBranch %19
48+
OpReturn
4949
%21 = OpLabel
50+
OpBranch %19
51+
%19 = OpLabel
5052
OpLine %7 29 9
5153
%23 = OpUDiv %8 %16 %17
5254
%24 = OpIEqual %13 %17 %14
@@ -57,8 +59,10 @@ OpBranchConditional %24 %26 %27
5759
OpLine %7 29 9
5860
%28 = OpExtInst %11 %1 1 %6
5961
OpNoLine
60-
OpBranch %25
62+
OpReturn
6163
%27 = OpLabel
64+
OpBranch %25
65+
%25 = OpLabel
6266
OpLine %7 29 9
6367
%29 = OpUDiv %8 %23 %17
6468
%30 = OpIEqual %13 %17 %14
@@ -69,8 +73,10 @@ OpBranchConditional %30 %32 %33
6973
OpLine %7 29 9
7074
%34 = OpExtInst %11 %1 1 %6
7175
OpNoLine
72-
OpBranch %31
76+
OpReturn
7377
%33 = OpLabel
78+
OpBranch %31
79+
%31 = OpLabel
7480
OpLine %7 29 9
7581
%35 = OpUDiv %8 %29 %17
7682
%36 = OpIEqual %13 %17 %14
@@ -81,8 +87,10 @@ OpBranchConditional %36 %38 %39
8187
OpLine %7 29 9
8288
%40 = OpExtInst %11 %1 1 %6
8389
OpNoLine
84-
OpBranch %37
90+
OpReturn
8591
%39 = OpLabel
92+
OpBranch %37
93+
%37 = OpLabel
8694
OpLine %7 29 9
8795
%41 = OpUDiv %8 %35 %17
8896
%42 = OpIEqual %13 %17 %14
@@ -93,8 +101,10 @@ OpBranchConditional %42 %44 %45
93101
OpLine %7 29 9
94102
%46 = OpExtInst %11 %1 1 %6
95103
OpNoLine
96-
OpBranch %43
104+
OpReturn
97105
%45 = OpLabel
106+
OpBranch %43
107+
%43 = OpLabel
98108
OpLine %7 29 9
99109
%47 = OpUDiv %8 %41 %17
100110
%48 = OpIEqual %13 %17 %14
@@ -105,8 +115,10 @@ OpBranchConditional %48 %50 %51
105115
OpLine %7 29 9
106116
%52 = OpExtInst %11 %1 1 %6
107117
OpNoLine
108-
OpBranch %49
118+
OpReturn
109119
%51 = OpLabel
120+
OpBranch %49
121+
%49 = OpLabel
110122
OpLine %7 29 9
111123
%53 = OpUDiv %8 %47 %17
112124
%54 = OpIEqual %13 %17 %14
@@ -117,8 +129,10 @@ OpBranchConditional %54 %56 %57
117129
OpLine %7 29 9
118130
%58 = OpExtInst %11 %1 1 %6
119131
OpNoLine
120-
OpBranch %55
132+
OpReturn
121133
%57 = OpLabel
134+
OpBranch %55
135+
%55 = OpLabel
122136
OpLine %7 29 9
123137
%59 = OpUDiv %8 %53 %17
124138
%60 = OpIEqual %13 %17 %14
@@ -129,8 +143,10 @@ OpBranchConditional %60 %62 %63
129143
OpLine %7 29 9
130144
%64 = OpExtInst %11 %1 1 %6
131145
OpNoLine
132-
OpBranch %61
146+
OpReturn
133147
%63 = OpLabel
148+
OpBranch %61
149+
%61 = OpLabel
134150
OpLine %7 29 9
135151
%65 = OpUDiv %8 %59 %17
136152
%66 = OpIEqual %13 %17 %14
@@ -141,8 +157,10 @@ OpBranchConditional %66 %68 %69
141157
OpLine %7 29 9
142158
%70 = OpExtInst %11 %1 1 %6
143159
OpNoLine
144-
OpBranch %67
160+
OpReturn
145161
%69 = OpLabel
162+
OpBranch %67
163+
%67 = OpLabel
146164
OpLine %7 29 9
147165
%71 = OpUDiv %8 %65 %17
148166
%72 = OpIEqual %13 %17 %14
@@ -153,8 +171,10 @@ OpBranchConditional %72 %74 %75
153171
OpLine %7 29 9
154172
%76 = OpExtInst %11 %1 1 %6
155173
OpNoLine
156-
OpBranch %73
174+
OpReturn
157175
%75 = OpLabel
176+
OpBranch %73
177+
%73 = OpLabel
158178
OpLine %7 29 9
159179
%77 = OpUDiv %8 %71 %17
160180
%78 = OpIEqual %13 %17 %14
@@ -165,8 +185,10 @@ OpBranchConditional %78 %80 %81
165185
OpLine %7 29 9
166186
%82 = OpExtInst %11 %1 1 %6
167187
OpNoLine
168-
OpBranch %79
188+
OpReturn
169189
%81 = OpLabel
190+
OpBranch %79
191+
%79 = OpLabel
170192
OpLine %7 29 9
171193
%83 = OpUDiv %8 %77 %17
172194
%84 = OpIEqual %13 %17 %14
@@ -177,8 +199,10 @@ OpBranchConditional %84 %86 %87
177199
OpLine %7 29 9
178200
%88 = OpExtInst %11 %1 1 %6
179201
OpNoLine
180-
OpBranch %85
202+
OpReturn
181203
%87 = OpLabel
204+
OpBranch %85
205+
%85 = OpLabel
182206
OpLine %7 29 9
183207
%89 = OpUDiv %8 %83 %17
184208
%90 = OpIEqual %13 %17 %14
@@ -189,8 +213,10 @@ OpBranchConditional %90 %92 %93
189213
OpLine %7 29 9
190214
%94 = OpExtInst %11 %1 1 %6
191215
OpNoLine
192-
OpBranch %91
216+
OpReturn
193217
%93 = OpLabel
218+
OpBranch %91
219+
%91 = OpLabel
194220
OpLine %7 29 9
195221
%95 = OpUDiv %8 %89 %17
196222
%96 = OpIEqual %13 %17 %14
@@ -201,8 +227,10 @@ OpBranchConditional %96 %98 %99
201227
OpLine %7 29 9
202228
%100 = OpExtInst %11 %1 1 %6
203229
OpNoLine
204-
OpBranch %97
230+
OpReturn
205231
%99 = OpLabel
232+
OpBranch %97
233+
%97 = OpLabel
206234
OpLine %7 29 9
207235
%101 = OpUDiv %8 %95 %17
208236
%102 = OpIEqual %13 %17 %14
@@ -213,8 +241,10 @@ OpBranchConditional %102 %104 %105
213241
OpLine %7 29 9
214242
%106 = OpExtInst %11 %1 1 %6
215243
OpNoLine
216-
OpBranch %103
244+
OpReturn
217245
%105 = OpLabel
246+
OpBranch %103
247+
%103 = OpLabel
218248
OpLine %7 29 9
219249
%107 = OpUDiv %8 %101 %17
220250
%108 = OpIEqual %13 %17 %14
@@ -225,8 +255,10 @@ OpBranchConditional %108 %110 %111
225255
OpLine %7 29 9
226256
%112 = OpExtInst %11 %1 1 %6
227257
OpNoLine
228-
OpBranch %109
258+
OpReturn
229259
%111 = OpLabel
260+
OpBranch %109
261+
%109 = OpLabel
230262
OpLine %7 29 9
231263
%113 = OpUDiv %8 %107 %17
232264
%114 = OpIEqual %13 %17 %14
@@ -237,45 +269,13 @@ OpBranchConditional %114 %116 %117
237269
OpLine %7 29 9
238270
%118 = OpExtInst %11 %1 1 %6
239271
OpNoLine
240-
OpBranch %115
272+
OpReturn
241273
%117 = OpLabel
274+
OpBranch %115
275+
%115 = OpLabel
242276
OpLine %7 29 4
243277
%119 = OpUDiv %8 %113 %17
244278
OpStore %5 %119
245279
OpNoLine
246-
OpBranch %115
247-
%115 = OpLabel
248-
OpBranch %109
249-
%109 = OpLabel
250-
OpBranch %103
251-
%103 = OpLabel
252-
OpBranch %97
253-
%97 = OpLabel
254-
OpBranch %91
255-
%91 = OpLabel
256-
OpBranch %85
257-
%85 = OpLabel
258-
OpBranch %79
259-
%79 = OpLabel
260-
OpBranch %73
261-
%73 = OpLabel
262-
OpBranch %67
263-
%67 = OpLabel
264-
OpBranch %61
265-
%61 = OpLabel
266-
OpBranch %55
267-
%55 = OpLabel
268-
OpBranch %49
269-
%49 = OpLabel
270-
OpBranch %43
271-
%43 = OpLabel
272-
OpBranch %37
273-
%37 = OpLabel
274-
OpBranch %31
275-
%31 = OpLabel
276-
OpBranch %25
277-
%25 = OpLabel
278-
OpBranch %19
279-
%19 = OpLabel
280280
OpReturn
281281
OpFunctionEnd

0 commit comments

Comments
 (0)