Skip to content

Implement core arena infrastructure #433

@Kroisse

Description

@Kroisse

Summary

Add cranelift-entity dependency to trunk-ir and implement the core arena-based IR infrastructure.

Scope

  • Add cranelift-entity to crates/trunk-ir/Cargo.toml
  • Define typed indices: OpRef, ValueRef, BlockRef, RegionRef (via entity_impl!)
  • Implement IrContext with PrimaryMap-backed storage for all node types
  • Implement CRUD operations: create_op, remove_op, create_block, create_region, etc.
  • Implement use-chain tracking in ValueData (SmallVec<[Use; 4]>)
  • Implement replace_all_uses(old, new) (RAUW) with O(uses) complexity
  • Auto-maintain use-chains on op create/remove

Key Types

pub struct OpRef(u32);
entity_impl!(OpRef, "op");

pub struct Use { pub user: OpRef, pub operand_index: u32 }

pub struct ValueData {
    pub def: ValueDef,
    pub ty: TypeRef,
    pub uses: SmallVec<[Use; 4]>,
}

pub struct OperationData {
    pub dialect: Symbol,
    pub name: Symbol,
    pub operands: EntityList<ValueRef>,
    pub results: EntityList<ValueRef>,
    pub attributes: BTreeMap<Symbol, Attribute>,
    pub regions: SmallVec<[RegionRef; 1]>,
    pub successors: SmallVec<[BlockRef; 2]>,
    pub location: Location,
    pub parent_block: Option<BlockRef>,
}

Key Files

  • crates/trunk-ir/Cargo.toml
  • crates/trunk-ir/src/arena/ (new module)

Acceptance Criteria

  • cranelift-entity added as dependency
  • All typed refs defined with entity_impl!
  • IrContext supports create/read/remove for ops, values, blocks, regions
  • Use-chain automatically maintained on create/remove
  • replace_all_uses works correctly
  • Unit tests for CRUD and RAUW

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions