Skip to content

Commit

Permalink
Implement third pass
Browse files Browse the repository at this point in the history
  • Loading branch information
vosen committed Aug 24, 2024
1 parent 69175d2 commit 4e6dc07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
23 changes: 6 additions & 17 deletions ptx/src/pass/convert_to_typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,9 @@ pub(crate) fn run(
src: src_reg,
}));
}
ast::Instruction::Call(call) => {
let resolver = fn_defs.get_fn_sig_resolver(call.func)?;
let resolved_call = resolver.resolve_in_spirv_repr(call)?;
let mut visitor = VectorRepackVisitor::new(&mut result, id_defs);
let reresolved_call = resolved_call.visit(&mut visitor)?;
visitor.func.push(reresolved_call);
visitor.func.extend(visitor.post_stmts);
}
inst => {
let mut visitor = VectorRepackVisitor::new(&mut result, id_defs);
let instruction = Statement::Instruction(inst.map(&mut visitor)?);
let instruction = Statement::Instruction(ast::visit_map(inst, &mut visitor)?);
visitor.func.push(instruction);
visitor.func.extend(visitor.post_stmts);
}
Expand Down Expand Up @@ -68,12 +60,7 @@ impl<'a, 'b> VectorRepackVisitor<'a, 'b> {
fn convert_vector(
&mut self,
is_dst: bool,
non_default_implicit_conversion: Option<
fn(
(ast::StateSpace, &ast::Type),
(ast::StateSpace, &ast::Type),
) -> Result<Option<ConversionKind>, TranslateError>,
>,
relaxed_type_check: bool,
typ: &ast::Type,
state_space: ast::StateSpace,
idx: Vec<SpirvWord>,
Expand All @@ -91,7 +78,7 @@ impl<'a, 'b> VectorRepackVisitor<'a, 'b> {
typ: scalar_t,
packed: temp_vec,
unpacked: idx,
non_default_implicit_conversion,
relaxed_type_check,
});
if is_dst {
self.post_stmts = Some(statement);
Expand All @@ -110,6 +97,7 @@ impl<'a, 'b> ast::VisitorMap<ast::ParsedOperand<SpirvWord>, TypedOperand, Transl
ident: SpirvWord,
_: Option<(&ptx_parser::Type, ptx_parser::StateSpace)>,
_: bool,
_: bool,
) -> Result<SpirvWord, TranslateError> {
Ok(ident)
}
Expand All @@ -119,6 +107,7 @@ impl<'a, 'b> ast::VisitorMap<ast::ParsedOperand<SpirvWord>, TypedOperand, Transl
op: ast::ParsedOperand<SpirvWord>,
type_space: Option<(&ptx_parser::Type, ptx_parser::StateSpace)>,
is_dst: bool,
relaxed_type_check: bool,
) -> Result<TypedOperand, TranslateError> {
Ok(match op {
ast::ParsedOperand::Reg(reg) => TypedOperand::Reg(reg),
Expand All @@ -129,7 +118,7 @@ impl<'a, 'b> ast::VisitorMap<ast::ParsedOperand<SpirvWord>, TypedOperand, Transl
let (type_, space) = type_space.ok_or(TranslateError::MismatchedType)?;
TypedOperand::Reg(self.convert_vector(
is_dst,
desc.non_default_implicit_conversion,
relaxed_type_check,
type_,
space,
vec,
Expand Down
7 changes: 1 addition & 6 deletions ptx/src/pass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,7 @@ struct RepackVectorDetails {
typ: ast::ScalarType,
packed: SpirvWord,
unpacked: Vec<SpirvWord>,
non_default_implicit_conversion: Option<
fn(
(ast::StateSpace, &ast::Type),
(ast::StateSpace, &ast::Type),
) -> Result<Option<ConversionKind>, TranslateError>,
>,
relaxed_type_check: bool
}

struct FunctionPointerDetails {
Expand Down
1 change: 1 addition & 0 deletions ptx/src/pass/normalize_identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn expand_map_variables<'a, 'b>(
.transpose()?,
ast::visit_map(i, &mut |id,
_: Option<(&ast::Type, ast::StateSpace)>,
_: bool,
_: bool| {
id_defs.get_id(id)
})?,
Expand Down

0 comments on commit 4e6dc07

Please sign in to comment.