Skip to content

LiftContext::lift_op responsible for ~25% of the generated llvm ir #220

@bjorn3

Description

@bjorn3
$ cargo llvm-lines -p rspirv
  Lines          Copies       Function name
  -----          ------       -------------
  434621 (100%)  6861 (100%)  (TOTAL)
  113962 (26.2%)    1 (0.0%)  rspirv::lift::LiftContext::lift_op

I wonder if it would be possible to have all operand matches of all instructions with the same "function signature" be grouped together. Something like:

145u32 | 146u32 => {
    let id1 = (match operands.next() {
        Some(&dr::Operand::IdRef(ref value)) => Some(*value),
        Some(_) => return Err(OperandError::WrongType.into()),
        None => None,
    }).ok_or(OperandError::Missing)?;
    let id2 = (match operands.next() {
        Some(&dr::Operand::IdRef(ref value)) => Some(*value),
        Some(_) => return Err(OperandError::WrongType.into()),
        None => None,
    })
    .ok_or(OperandError::Missing)?;
    match raw.class.opcode as u32 {
        145u32 => ops::Op::MatrixTimesVector { matrix: id1, vector: id2 },
        146u32 => ops::Op::MatrixTimesMatrix { left_matrix: id1, right_matrix: id2 },
        _ => unreachable!(),
    }
}

instead of

145u32 => Ok(ops::Op::MatrixTimesVector {
    matrix: (match operands.next() {
        Some(&dr::Operand::IdRef(ref value)) => Some(*value),
        Some(_) => return Err(OperandError::WrongType.into()),
        None => None,
    })
    .ok_or(OperandError::Missing)?,
    vector: (match operands.next() {
        Some(&dr::Operand::IdRef(ref value)) => Some(*value),
        Some(_) => return Err(OperandError::WrongType.into()),
        None => None,
    })
    .ok_or(OperandError::Missing)?,
}),
146u32 => Ok(ops::Op::MatrixTimesMatrix {
    left_matrix: (match operands.next() {
        Some(&dr::Operand::IdRef(ref value)) => Some(*value),
        Some(_) => return Err(OperandError::WrongType.into()),
        None => None,
    })
    .ok_or(OperandError::Missing)?,
        right_matrix: (match operands.next() {
        Some(&dr::Operand::IdRef(ref value)) => Some(*value),
        Some(_) => return Err(OperandError::WrongType.into()),
        None => None,
    })
    .ok_or(OperandError::Missing)?,
}),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions