From 2e8716bf0debf5edfecd616204d0fd2864dc2f4c Mon Sep 17 00:00:00 2001 From: Andrzej Janik Date: Fri, 25 Jun 2021 01:20:16 +0200 Subject: [PATCH] Clean up warnings --- ptx/src/translate.rs | 108 +++++++------------------------------------ 1 file changed, 17 insertions(+), 91 deletions(-) diff --git a/ptx/src/translate.rs b/ptx/src/translate.rs index 277db5c..3daf937 100644 --- a/ptx/src/translate.rs +++ b/ptx/src/translate.rs @@ -1,13 +1,9 @@ use crate::ast; -use core::borrow; use half::f16; use rspirv::dr; -use std::{borrow::Borrow, cell::RefCell}; +use std::cell::RefCell; +use std::collections::{hash_map, HashMap, HashSet}; use std::{borrow::Cow, collections::BTreeSet, ffi::CString, hash::Hash, iter, mem, rc::Rc}; -use std::{ - collections::{hash_map, HashMap, HashSet}, - convert::TryInto, -}; use rspirv::binary::Assemble; @@ -433,7 +429,7 @@ pub fn to_spirv_module<'a>(ast: ast::Module<'a>) -> Result, _>>()?; let must_link_ptx_impl = ptx_impl_imports.len() > 0; - let mut directives = ptx_impl_imports + let directives = ptx_impl_imports .into_iter() .map(|(_, v)| v) .chain(directives.into_iter()) @@ -1068,8 +1064,10 @@ fn emit_function_header<'a>( }) => { match (**func_decl).borrow().name { ast::MethodName::Func(name) => { - for var in globals { - interface.push(var.name); + if child_fns.contains(&name) { + for var in globals { + interface.push(var.name); + } } } ast::MethodName::Kernel(_) => {} @@ -1264,30 +1262,6 @@ fn to_ssa<'input, 'b>( }) } -fn deparamize_function_decl( - func_decl_rc: &Rc>>, -) -> Result<(), TranslateError> { - let mut func_decl = func_decl_rc.borrow_mut(); - match func_decl.name { - ast::MethodName::Func(..) => { - for decl in func_decl.input_arguments.iter_mut() { - if decl.state_space == ast::StateSpace::Param { - decl.state_space = ast::StateSpace::Reg; - let baseline_type = match decl.v_type { - ast::Type::Scalar(t) => t, - ast::Type::Vector(t, _) => t, // TODO: write a test for this - ast::Type::Array(t, _) => t, // TODO: write a test for this - ast::Type::Pointer(_, _) => return Err(error_unreachable()), - }; - decl.v_type = ast::Type::Pointer(baseline_type, ast::StateSpace::Param); - } - } - } - ast::MethodName::Kernel(..) => {} - }; - Ok(()) -} - fn fix_special_registers( typed_statements: Vec, numeric_id_defs: &mut NumericIdResolver, @@ -1905,17 +1879,6 @@ fn to_ptx_impl_bfi_call( }) } -fn to_resolved_fn_args( - params: Vec, - params_decl: &[ast::Variable], -) -> Vec<(T, ast::Type, ast::StateSpace)> { - params - .into_iter() - .zip(params_decl.iter()) - .map(|(id, var)| (id, var.v_type.clone(), var.state_space)) - .collect::>() -} - fn normalize_labels( func: Vec, id_def: &mut NumericIdResolver, @@ -2644,10 +2607,15 @@ fn emit_function_body_ops( Statement::Label(_) => (), Statement::Call(call) => { let (result_type, result_id) = match &*call.return_arguments { - [(id, typ, space)] => ( - map.get_or_add(builder, SpirvType::new(typ.clone())), - Some(*id), - ), + [(id, typ, space)] => { + if *space != ast::StateSpace::Reg { + return Err(error_unreachable()); + } + ( + map.get_or_add(builder, SpirvType::new(typ.clone())), + Some(*id), + ) + } [] => (map.void(), None), _ => todo!(), }; @@ -4679,7 +4647,7 @@ fn convert_to_stateful_memory_access_postprocess( ) -> Result { Ok(match remapped_ids.get(&arg_desc.op) { Some(new_id) => { - let (new_operand_type, new_operand_space, is_variable) = id_defs.get_typed(*new_id)?; + let (new_operand_type, new_operand_space, _) = id_defs.get_typed(*new_id)?; if let Some((expected_type, expected_space)) = expected_type { let implicit_conversion = arg_desc .non_default_implicit_conversion @@ -4694,7 +4662,6 @@ fn convert_to_stateful_memory_access_postprocess( } } let (old_operand_type, old_operand_space, _) = id_defs.get_typed(arg_desc.op)?; - let new_operand_type_clone = new_operand_type.clone(); let converting_id = id_defs.register_intermediate(Some((old_operand_type.clone(), old_operand_space))); let kind = if new_operand_space.is_compatible(ast::StateSpace::Reg) { @@ -5745,20 +5712,6 @@ pub struct PtrAccess { offset_src: P::Operand, } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub enum ArgumentSemantics { - // normal register access - Default, - // normal register access with relaxed conversion rules (ld/st) - DefaultRelaxed, - // st/ld global - PhysicalPointer, - // st/ld .param, .local - RegisterPointer, - // mov of .local/.global variables - Address, -} - impl ArgumentDescriptor { fn new_op(&self, u: U) -> ArgumentDescriptor { ArgumentDescriptor { @@ -7315,17 +7268,6 @@ impl ast::AtomSemantics { } } -impl ast::StateSpace { - fn semantics(self) -> ArgumentSemantics { - match self { - ast::StateSpace::Reg => ArgumentSemantics::Default, - ast::StateSpace::Param => ArgumentSemantics::RegisterPointer, - ast::StateSpace::Shared => ArgumentSemantics::PhysicalPointer, - _ => todo!(), - } - } -} - fn default_implicit_conversion( (operand_space, operand_type): (ast::StateSpace, &ast::Type), (instruction_space, instruction_type): (ast::StateSpace, &ast::Type), @@ -7475,22 +7417,6 @@ fn implicit_conversion_mov( ) } -fn should_bitcast_wrapper( - operand: &ast::Type, - _: ast::StateSpace, - instr: &ast::Type, - _: ast::StateSpace, -) -> Result, TranslateError> { - if instr == operand { - return Ok(None); - } - if should_bitcast(instr, operand) { - Ok(Some(ConversionKind::Default)) - } else { - Err(TranslateError::MismatchedType) - } -} - fn should_convert_relaxed_src_wrapper( (operand_space, operand_type): (ast::StateSpace, &ast::Type), (instruction_space, instruction_type): (ast::StateSpace, &ast::Type),