Skip to content

Is it reasonable to add API for adding params for a BasicBlock? #28

Description

@hsqStephenZhang

Background

  1. When implementing mem2reg, I have to patch koopa and add this method to DataFlowGraph
  2. there are some existing discussion on the current design, see https://pku-minic.github.io/online-doc/#/lv9p-reincarnation/ssa-form

Proposal

#[must_use = "must fix arguments in predecessors' terminators to match the params"]
  pub fn append_bb_param(&mut self, bb: BasicBlock, ty: crate::ir::Type) -> Value {
    assert!(!ty.is_unit(), "parameter type must not be `unit`!");
    let index = self.bb(bb).params().len();
    let value = self.new_value_data(crate::ir::values::BlockArgRef::new_data(index, ty));
    self.bb_mut(bb).params_mut().push(value);
    value
  }

I think it's a reasonable design, otherwise user might have to clone a brand new BB just to add one BasicBlock param/Phi, or they should patch their own koopa.

We could apply this API to FunctionArgRef if it's wanted

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