Skip to content

Commit d31bb5f

Browse files
committed
cleanup
1 parent 815161d commit d31bb5f

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

crates/rustc_codegen_spirv/src/linker/inline.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use super::{get_name, get_names};
1010
use rspirv::dr::{Block, Function, Instruction, Module, ModuleHeader, Operand};
1111
use rspirv::spirv::{FunctionControl, Op, StorageClass, Word};
1212
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
13+
use rustc_errors::ErrorGuaranteed;
1314
use rustc_session::Session;
1415
use std::mem::take;
1516

1617
type FunctionMap = FxHashMap<Word, Function>;
1718

1819
pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
1920
// This algorithm gets real sad if there's recursion - but, good news, SPIR-V bans recursion
20-
if module_has_recursion(sess, module) {
21-
return Err(rustc_errors::ErrorReported);
22-
}
21+
deny_recursion_in_module(sess, module)?;
22+
2323
let functions = module
2424
.functions
2525
.iter()
@@ -52,7 +52,7 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
5252
let names = get_names(module);
5353
for f in inlined_dont_inlines {
5454
sess.warn(&format!(
55-
"Function `{}` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types",
55+
"function `{}` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types",
5656
get_name(&names, f)
5757
));
5858
}
@@ -81,7 +81,7 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
8181
}
8282

8383
// https://stackoverflow.com/a/53995651
84-
fn module_has_recursion(sess: &Session, module: &Module) -> bool {
84+
fn deny_recursion_in_module(sess: &Session, module: &Module) -> super::Result<()> {
8585
let func_to_index: FxHashMap<Word, usize> = module
8686
.functions
8787
.iter()
@@ -90,7 +90,7 @@ fn module_has_recursion(sess: &Session, module: &Module) -> bool {
9090
.collect();
9191
let mut discovered = vec![false; module.functions.len()];
9292
let mut finished = vec![false; module.functions.len()];
93-
let mut has_recursion = false;
93+
let mut has_recursion = None;
9494
for index in 0..module.functions.len() {
9595
if !discovered[index] && !finished[index] {
9696
visit(
@@ -111,7 +111,7 @@ fn module_has_recursion(sess: &Session, module: &Module) -> bool {
111111
current: usize,
112112
discovered: &mut Vec<bool>,
113113
finished: &mut Vec<bool>,
114-
has_recursion: &mut bool,
114+
has_recursion: &mut Option<ErrorGuaranteed>,
115115
func_to_index: &FxHashMap<Word, usize>,
116116
) {
117117
discovered[current] = true;
@@ -121,11 +121,10 @@ fn module_has_recursion(sess: &Session, module: &Module) -> bool {
121121
let names = get_names(module);
122122
let current_name = get_name(&names, module.functions[current].def_id().unwrap());
123123
let next_name = get_name(&names, module.functions[next].def_id().unwrap());
124-
sess.err(&format!(
124+
*has_recursion = Some(sess.err(&format!(
125125
"module has recursion, which is not allowed: `{}` calls `{}`",
126126
current_name, next_name
127-
));
128-
*has_recursion = true;
127+
)));
129128
break;
130129
}
131130

@@ -159,7 +158,10 @@ fn module_has_recursion(sess: &Session, module: &Module) -> bool {
159158
})
160159
}
161160

162-
has_recursion
161+
match has_recursion {
162+
Some(err) => Err(err),
163+
None => Ok(()),
164+
}
163165
}
164166

165167
fn compute_disallowed_argument_and_return_types(

crates/rustc_codegen_spirv/src/linker/inline_globals.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rspirv::dr::{Instruction, Module, Operand};
2-
use rspirv::spirv::{Op};
2+
use rspirv::spirv::Op;
33
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_session::Session;
55

@@ -47,17 +47,17 @@ impl NormalizedInstructions {
4747
bound: &mut u32,
4848
new_root: u32,
4949
) {
50-
for op in &mut inst.operands {
51-
match op {
52-
Operand::IdRef(id) => match id_map.get(id) {
53-
Some(new_id) => {
54-
*id = *new_id;
55-
}
56-
_ => {}
57-
},
50+
for op in &mut inst.operands {
51+
match op {
52+
Operand::IdRef(id) => match id_map.get(id) {
53+
Some(new_id) => {
54+
*id = *new_id;
55+
}
5856
_ => {}
59-
}
57+
},
58+
_ => {}
6059
}
60+
}
6161
if let Some(id) = &mut inst.result_id {
6262
if *id != root {
6363
id_map.insert(*id, *bound);
@@ -144,7 +144,13 @@ fn inline_global_varaibles_rec(module: &mut Module) -> super::Result<bool> {
144144
match &inst.operands[i] {
145145
&Operand::IdRef(w) => match &function_args.get(&key) {
146146
None => {
147-
match get_const_arg_insts(bound, &variables, &insts, &ref_stores, w) {
147+
match get_const_arg_insts(
148+
bound,
149+
&variables,
150+
&insts,
151+
&ref_stores,
152+
w,
153+
) {
148154
Some(insts) => {
149155
is_invalid = false;
150156
function_args.insert(key, FunctionArg::Insts(insts));
@@ -153,8 +159,13 @@ fn inline_global_varaibles_rec(module: &mut Module) -> super::Result<bool> {
153159
}
154160
}
155161
Some(FunctionArg::Insts(w2)) => {
156-
let new_insts =
157-
get_const_arg_insts(bound, &variables, &insts, &ref_stores, w);
162+
let new_insts = get_const_arg_insts(
163+
bound,
164+
&variables,
165+
&insts,
166+
&ref_stores,
167+
w,
168+
);
158169
match new_insts {
159170
Some(new_insts) => {
160171
is_invalid = new_insts != *w2;

crates/rustc_codegen_spirv/src/linker/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ mod destructure_composites;
66
mod duplicates;
77
mod entry_interface;
88
mod import_export_link;
9-
mod inline_globals;
109
mod inline;
10+
mod inline_globals;
1111
mod ipo;
1212
mod mem2reg;
1313
mod param_weakening;
@@ -153,7 +153,6 @@ pub fn link(sess: &Session, mut inputs: Vec<Module>, opts: &Options) -> Result<L
153153
std::fs::write(path, spirv_tools::binary::from_binary(&output.assemble())).unwrap();
154154
}
155155

156-
157156
// remove duplicates (https://github.com/KhronosGroup/SPIRV-Tools/blob/e7866de4b1dc2a7e8672867caeb0bdca49f458d3/source/opt/remove_duplicates_pass.cpp)
158157
{
159158
let _timer = sess.timer("link_remove_duplicates");
@@ -355,6 +354,5 @@ pub fn link(sess: &Session, mut inputs: Vec<Module>, opts: &Options) -> Result<L
355354
};
356355
}
357356

358-
359357
Ok(output)
360358
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
warning: Function `nested_ref::deep_load` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types
1+
warning: function `nested_ref::deep_load` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types
22

3-
warning: Function `nested_ref::deep_transpose` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types
3+
warning: function `nested_ref::deep_transpose` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types
44

55
warning: 2 warnings emitted
66

0 commit comments

Comments
 (0)