diff options
author | Andrzej Janik <[email protected]> | 2024-09-23 06:02:28 +0200 |
---|---|---|
committer | Andrzej Janik <[email protected]> | 2024-09-23 06:02:28 +0200 |
commit | 78a9f22cf7e6c819f04991c1624578c969c1a146 (patch) | |
tree | 89bab98e3071aedd12f755bfde8a7c7382138ed7 /ptx/src/pass/hoist_globals.rs | |
parent | 7bd4179d1dd24f81b56e66fd13c16631b518495f (diff) | |
download | ZLUDA-repass.tar.gz ZLUDA-repass.zip |
Refactor implicit conversions, explicit ld/st and global hoistingrepass
Diffstat (limited to 'ptx/src/pass/hoist_globals.rs')
-rw-r--r-- | ptx/src/pass/hoist_globals.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ptx/src/pass/hoist_globals.rs b/ptx/src/pass/hoist_globals.rs new file mode 100644 index 0000000..753172a --- /dev/null +++ b/ptx/src/pass/hoist_globals.rs @@ -0,0 +1,45 @@ +use super::*;
+
+pub(super) fn run<'input>(
+ directives: Vec<Directive2<'input, ast::Instruction<SpirvWord>, SpirvWord>>,
+) -> Result<Vec<Directive2<'input, ast::Instruction<SpirvWord>, SpirvWord>>, TranslateError> {
+ let mut result = Vec::with_capacity(directives.len());
+ for mut directive in directives.into_iter() {
+ run_directive(&mut result, &mut directive);
+ result.push(directive);
+ }
+ Ok(result)
+}
+
+fn run_directive<'input>(
+ result: &mut Vec<Directive2<'input, ptx_parser::Instruction<SpirvWord>, SpirvWord>>,
+ directive: &mut Directive2<'input, ptx_parser::Instruction<SpirvWord>, SpirvWord>,
+) -> Result<(), TranslateError> {
+ match directive {
+ Directive2::Variable(..) => {}
+ Directive2::Method(function2) => run_function(result, function2),
+ }
+ Ok(())
+}
+
+fn run_function<'input>(
+ result: &mut Vec<Directive2<'input, ptx_parser::Instruction<SpirvWord>, SpirvWord>>,
+ function: &mut Function2<'input, ptx_parser::Instruction<SpirvWord>, SpirvWord>,
+) {
+ function.body = function.body.take().map(|statements| {
+ statements
+ .into_iter()
+ .filter_map(|statement| match statement {
+ Statement::Variable(var @ ast::Variable {
+ state_space:
+ ast::StateSpace::Global | ast::StateSpace::Const | ast::StateSpace::Shared,
+ ..
+ }) => {
+ result.push(Directive2::Variable(ast::LinkingDirective::NONE, var));
+ None
+ }
+ s => Some(s),
+ })
+ .collect()
+ });
+}
|