Skip to content

Commit

Permalink
Use ExitInvocation for panics (avoiding deeply nested structurizati…
Browse files Browse the repository at this point in the history
…on).
  • Loading branch information
eddyb authored and LegNeato committed Oct 18, 2024
1 parent 395aee0 commit 61f7e7a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 65 deletions.
3 changes: 3 additions & 0 deletions crates/rustc_codegen_spirv/src/linker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ pub fn link(
}

// NOTE(eddyb) this *must* run on unstructured CFGs, to do its job.
// FIXME(eddyb) no longer relying on structurization, try porting this
// to replace custom aborts in `Block`s and inject `ExitInvocation`s
// after them (truncating the `Block` and/or parent region if necessary).
{
let _timer = sess.timer("spirt_passes::controlflow::convert_custom_aborts_to_unstructured_returns_in_entry_points");
spirt_passes::controlflow::convert_custom_aborts_to_unstructured_returns_in_entry_points(opts, &mut module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use std::fmt::Write as _;

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

match abort_strategy {
Some(Strategy::Unreachable) => {
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/dis/entry-pass-mode-cast-array.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ OpNoLine
OpSelectionMerge %13 None
OpBranchConditional %9 %14 %15
%14 = OpLabel
OpBranch %13
%15 = OpLabel
OpReturn
%13 = OpLabel
OpLine %5 14 4
%16 = OpCompositeExtract %17 %6 0
%18 = OpFAdd %17 %16 %19
%20 = OpCompositeInsert %7 %18 %6 0
OpLine %5 15 4
OpStore %21 %20
OpNoLine
OpBranch %13
%15 = OpLabel
OpBranch %13
%13 = OpLabel
OpReturn
OpFunctionEnd
8 changes: 4 additions & 4 deletions tests/ui/dis/index_user_dst.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ OpNoLine
OpSelectionMerge %14 None
OpBranchConditional %12 %15 %16
%15 = OpLabel
OpBranch %14
%16 = OpLabel
OpReturn
%14 = OpLabel
OpLine %5 10 21
%17 = OpInBoundsAccessChain %18 %6 %9
%19 = OpLoad %20 %17
OpNoLine
OpBranch %14
%16 = OpLabel
OpBranch %14
%14 = OpLabel
OpReturn
OpFunctionEnd
8 changes: 4 additions & 4 deletions tests/ui/dis/issue-731.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ OpNoLine
OpSelectionMerge %13 None
OpBranchConditional %9 %14 %15
%14 = OpLabel
OpBranch %13
%15 = OpLabel
OpReturn
%13 = OpLabel
OpLine %5 12 4
%16 = OpCompositeExtract %17 %6 0
%18 = OpFAdd %17 %16 %19
%20 = OpCompositeInsert %7 %18 %6 0
OpLine %5 13 4
OpStore %21 %20
OpNoLine
OpBranch %13
%15 = OpLabel
OpBranch %13
%13 = OpLabel
OpReturn
OpFunctionEnd
2 changes: 1 addition & 1 deletion tests/ui/dis/panic_builtin_bounds_check.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ OpBranch %14
OpLine %4 275 4
%17 = OpExtInst %6 %1 1 %3 %11 %10
OpNoLine
OpBranch %14
OpReturn
%14 = OpLabel
OpReturn
OpFunctionEnd
102 changes: 51 additions & 51 deletions tests/ui/dis/panic_sequential_many.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ OpBranchConditional %18 %20 %21
OpLine %7 29 9
%22 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %19
OpReturn
%21 = OpLabel
OpBranch %19
%19 = OpLabel
OpLine %7 29 9
%23 = OpUDiv %8 %16 %17
%24 = OpIEqual %13 %17 %14
Expand All @@ -57,8 +59,10 @@ OpBranchConditional %24 %26 %27
OpLine %7 29 9
%28 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %25
OpReturn
%27 = OpLabel
OpBranch %25
%25 = OpLabel
OpLine %7 29 9
%29 = OpUDiv %8 %23 %17
%30 = OpIEqual %13 %17 %14
Expand All @@ -69,8 +73,10 @@ OpBranchConditional %30 %32 %33
OpLine %7 29 9
%34 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %31
OpReturn
%33 = OpLabel
OpBranch %31
%31 = OpLabel
OpLine %7 29 9
%35 = OpUDiv %8 %29 %17
%36 = OpIEqual %13 %17 %14
Expand All @@ -81,8 +87,10 @@ OpBranchConditional %36 %38 %39
OpLine %7 29 9
%40 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %37
OpReturn
%39 = OpLabel
OpBranch %37
%37 = OpLabel
OpLine %7 29 9
%41 = OpUDiv %8 %35 %17
%42 = OpIEqual %13 %17 %14
Expand All @@ -93,8 +101,10 @@ OpBranchConditional %42 %44 %45
OpLine %7 29 9
%46 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %43
OpReturn
%45 = OpLabel
OpBranch %43
%43 = OpLabel
OpLine %7 29 9
%47 = OpUDiv %8 %41 %17
%48 = OpIEqual %13 %17 %14
Expand All @@ -105,8 +115,10 @@ OpBranchConditional %48 %50 %51
OpLine %7 29 9
%52 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %49
OpReturn
%51 = OpLabel
OpBranch %49
%49 = OpLabel
OpLine %7 29 9
%53 = OpUDiv %8 %47 %17
%54 = OpIEqual %13 %17 %14
Expand All @@ -117,8 +129,10 @@ OpBranchConditional %54 %56 %57
OpLine %7 29 9
%58 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %55
OpReturn
%57 = OpLabel
OpBranch %55
%55 = OpLabel
OpLine %7 29 9
%59 = OpUDiv %8 %53 %17
%60 = OpIEqual %13 %17 %14
Expand All @@ -129,8 +143,10 @@ OpBranchConditional %60 %62 %63
OpLine %7 29 9
%64 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %61
OpReturn
%63 = OpLabel
OpBranch %61
%61 = OpLabel
OpLine %7 29 9
%65 = OpUDiv %8 %59 %17
%66 = OpIEqual %13 %17 %14
Expand All @@ -141,8 +157,10 @@ OpBranchConditional %66 %68 %69
OpLine %7 29 9
%70 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %67
OpReturn
%69 = OpLabel
OpBranch %67
%67 = OpLabel
OpLine %7 29 9
%71 = OpUDiv %8 %65 %17
%72 = OpIEqual %13 %17 %14
Expand All @@ -153,8 +171,10 @@ OpBranchConditional %72 %74 %75
OpLine %7 29 9
%76 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %73
OpReturn
%75 = OpLabel
OpBranch %73
%73 = OpLabel
OpLine %7 29 9
%77 = OpUDiv %8 %71 %17
%78 = OpIEqual %13 %17 %14
Expand All @@ -165,8 +185,10 @@ OpBranchConditional %78 %80 %81
OpLine %7 29 9
%82 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %79
OpReturn
%81 = OpLabel
OpBranch %79
%79 = OpLabel
OpLine %7 29 9
%83 = OpUDiv %8 %77 %17
%84 = OpIEqual %13 %17 %14
Expand All @@ -177,8 +199,10 @@ OpBranchConditional %84 %86 %87
OpLine %7 29 9
%88 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %85
OpReturn
%87 = OpLabel
OpBranch %85
%85 = OpLabel
OpLine %7 29 9
%89 = OpUDiv %8 %83 %17
%90 = OpIEqual %13 %17 %14
Expand All @@ -189,8 +213,10 @@ OpBranchConditional %90 %92 %93
OpLine %7 29 9
%94 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %91
OpReturn
%93 = OpLabel
OpBranch %91
%91 = OpLabel
OpLine %7 29 9
%95 = OpUDiv %8 %89 %17
%96 = OpIEqual %13 %17 %14
Expand All @@ -201,8 +227,10 @@ OpBranchConditional %96 %98 %99
OpLine %7 29 9
%100 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %97
OpReturn
%99 = OpLabel
OpBranch %97
%97 = OpLabel
OpLine %7 29 9
%101 = OpUDiv %8 %95 %17
%102 = OpIEqual %13 %17 %14
Expand All @@ -213,8 +241,10 @@ OpBranchConditional %102 %104 %105
OpLine %7 29 9
%106 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %103
OpReturn
%105 = OpLabel
OpBranch %103
%103 = OpLabel
OpLine %7 29 9
%107 = OpUDiv %8 %101 %17
%108 = OpIEqual %13 %17 %14
Expand All @@ -225,8 +255,10 @@ OpBranchConditional %108 %110 %111
OpLine %7 29 9
%112 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %109
OpReturn
%111 = OpLabel
OpBranch %109
%109 = OpLabel
OpLine %7 29 9
%113 = OpUDiv %8 %107 %17
%114 = OpIEqual %13 %17 %14
Expand All @@ -237,45 +269,13 @@ OpBranchConditional %114 %116 %117
OpLine %7 29 9
%118 = OpExtInst %11 %1 1 %6
OpNoLine
OpBranch %115
OpReturn
%117 = OpLabel
OpBranch %115
%115 = OpLabel
OpLine %7 29 4
%119 = OpUDiv %8 %113 %17
OpStore %5 %119
OpNoLine
OpBranch %115
%115 = OpLabel
OpBranch %109
%109 = OpLabel
OpBranch %103
%103 = OpLabel
OpBranch %97
%97 = OpLabel
OpBranch %91
%91 = OpLabel
OpBranch %85
%85 = OpLabel
OpBranch %79
%79 = OpLabel
OpBranch %73
%73 = OpLabel
OpBranch %67
%67 = OpLabel
OpBranch %61
%61 = OpLabel
OpBranch %55
%55 = OpLabel
OpBranch %49
%49 = OpLabel
OpBranch %43
%43 = OpLabel
OpBranch %37
%37 = OpLabel
OpBranch %31
%31 = OpLabel
OpBranch %25
%25 = OpLabel
OpBranch %19
%19 = OpLabel
OpReturn
OpFunctionEnd

0 comments on commit 61f7e7a

Please sign in to comment.