Stream: git-cranelift

Topic: cranelift / Issue #596 Remove redundant matches on ir::Inst.


view this post on Zulip GitHub (Feb 28 2020 at 23:25):

alexcrichton transferred Issue #596:

I have a hunch that there is a decent amount of overhead from repetitive matches on dfg[inst]. We see a lot of

match pos.func.dfg[inst] {
    ir::InstructionData::StackLoad {
        ...
    } => ...,
    _ => panic!(...),
};

when we already know that inst is a stack_load.

This is required by the way that InstructionData is defined. We can't just pass a single instruction type into a function, we must pass an instance of the entire enum.

pub enum InstructionData {
    Unary {
        opcode: Opcode,
        arg: Value,
    },
    UnaryImm {
        opcode: Opcode,
        imm: ir::immediates::Imm64,
    },
    ...
}

I propose that we define a struct for each instruction type, as below:

struct UnaryImm {
    opcode: Opcode,
    imm: ir::immediates::Imm64,
}

enum InstructionData {
    Unary(Unary),
    UnaryImm(UnaryImm),
    ...
}

I think we should also go further, like #595 suggests and do this:

struct InstructionData {
    opcode: Opcode,
    args: ValueList,
    inst: Instruction,
}

enum Instruction {
    Unary(Unary),
    UnaryImm(UnaryImm),
    ...
}

Last updated: Oct 23 2024 at 20:03 UTC