peepmatic: Do not use paths in linear IR
Rather than using paths from the root instruction to the instruction we are matching against or checking if it is constant or whatever, use temporary variables. When we successfully match an instruction's opcode, we simultaneously define these temporaries for the instruction's operands. This is similar to how open-coding these matches in Rust would use `match` expressions with pattern matching to bind the operands to variables at the same time. This saves about 1.8% of instructions retired when Peepmatic is enabled.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
//! Interfacing with actual instructions.
|
||||
|
||||
use crate::part::{Constant, Part};
|
||||
use crate::paths::Path;
|
||||
use crate::r#type::Type;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
@@ -54,26 +53,22 @@ pub unsafe trait InstructionSet<'a> {
|
||||
new: Part<Self::Instruction>,
|
||||
) -> Self::Instruction;
|
||||
|
||||
/// Get the instruction, constant, or condition code at the given path.
|
||||
///
|
||||
/// If there is no such entity at the given path (e.g. we run into a
|
||||
/// function parameter and can't traverse the path any further) then `None`
|
||||
/// should be returned.
|
||||
fn get_part_at_path(
|
||||
&self,
|
||||
context: &mut Self::Context,
|
||||
root: Self::Instruction,
|
||||
path: Path,
|
||||
) -> Option<Part<Self::Instruction>>;
|
||||
|
||||
/// Get the given instruction's operator.
|
||||
///
|
||||
/// If the instruction isn't supported, then `None` should be returned.
|
||||
fn operator(
|
||||
///
|
||||
/// Additionally, if `Some` is returned, then the instruction's operands
|
||||
/// must be pushed in order into `operands`. E.g. calling this method on
|
||||
/// `(iadd $x $y)` would return `Some(iadd)` and extend `operands` with
|
||||
/// `[$x, $y]`.
|
||||
fn operator<E>(
|
||||
&self,
|
||||
context: &mut Self::Context,
|
||||
instr: Self::Instruction,
|
||||
) -> Option<Self::Operator>;
|
||||
operands: &mut E,
|
||||
) -> Option<Self::Operator>
|
||||
where
|
||||
E: Extend<Part<Self::Instruction>>;
|
||||
|
||||
/// Make a unary instruction.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user