pub fn estimate_insts_for_ir(inst: &Instruction) -> usize {
    use ast::inst::Instruction_::*;

    match inst.v {
        // simple
        BinOp(_, _, _) => 1,
        BinOpWithStatus(_, _, _, _) => 2,
        CmpOp(_, _, _) => 1,
        ConvOp { .. } => 0,

        CommonInst_Tr64IsFp(_) |
        CommonInst_Tr64IsInt(_) |
        CommonInst_Tr64IsRef(_) |
        CommonInst_Tr64FromFp(_) |
        CommonInst_Tr64FromInt(_) |
        CommonInst_Tr64FromRef(_, _) |
        CommonInst_Tr64ToFp(_) |
        CommonInst_Tr64ToInt(_) |
        CommonInst_Tr64ToRef(_) |
        CommonInst_Tr64ToTag(_) => 3,

        // control flow
        Branch1(_) => 1,
        Branch2 { .. } => 1,
        Select { .. } => 2,
        Watchpoint { .. } => 1,
        WPBranch { .. } => 2,
        Switch { .. } => 3,

        // call
        ExprCall { .. } | ExprCCall { .. } | Call { .. } | CCall { .. } => 5,
        Return(_) => 1,
        TailCall(_) => 1,

        // memory access
        Load { .. } | Store { .. } => 1,
        CmpXchg { .. } => 1,
        AtomicRMW { .. } => 1,
        AllocA(_) => 1,
        AllocAHybrid(_, _) => 1,
        Fence(_) => 1,

        // memory addressing
        GetIRef(_) |
        GetFieldIRef { .. } |
        GetElementIRef { .. } |
        ShiftIRef { .. } |
        GetVarPartIRef { .. } => 0,

        // runtime call
        New(_) | NewHybrid(_, _) => 10,
        NewStack(_) | NewThread { .. } | NewFrameCursor(_) => 10,
        ThreadExit => 10,
        CurrentStack => 10,
        KillStack(_) => 10,
        Throw(_) => 10,
        SwapStackExpr { .. } | SwapStackExc { .. } | SwapStackKill { .. } => 10,
        CommonInst_GetThreadLocal | CommonInst_SetThreadLocal(_) => 10,
        CommonInst_Pin(_) | CommonInst_Unpin(_) | CommonInst_GetAddr(_) => 10,

        // others
        Move(_) => 0,
        PrintHex(_) => 10,
        SetRetval(_) => 10,
        GetVMThreadLocal => 10,
        ExnInstruction { ref inner, .. } => estimate_insts_for_ir(&inner)
    }
}
/// estimate the number of machine instruction for each IR instruction
estimate the number of machine instruction for each IR instruction
estimate the number of machine instruction for each IR instruction
pub fn estimate_insts_for_ir(inst: &Instruction) -> usize {
    use ast::inst::Instruction_::*;
    match inst.v {
        // simple
        BinOp(_, _, _) => 1,
        BinOpWithStatus(_, _, _, _) => 2,
        CmpOp(_, _, _) => 1,
        ConvOp { .. } => 0,
        CommonInst_Tr64IsFp(_) |
        CommonInst_Tr64IsInt(_) |
        CommonInst_Tr64IsRef(_) |
        CommonInst_Tr64FromFp(_) |
        CommonInst_Tr64FromInt(_) |
        CommonInst_Tr64FromRef(_, _) |
        CommonInst_Tr64ToFp(_) |
        CommonInst_Tr64ToInt(_) |
        CommonInst_Tr64ToRef(_) |
        CommonInst_Tr64ToTag(_) => 3,
        // control flow
        Branch1(_) => 1,
        Branch2 { .. } => 1,
        Select { .. } => 2,
        Watchpoint { .. } => 1,
        WPBranch { .. } => 2,
        Switch { .. } => 3,
        // call
        ExprCall { .. } | ExprCCall { .. } | Call { .. } | CCall { .. } => 5,
        Return(_) => 1,
        TailCall(_) => 1,
        // memory access
        Load { .. } | Store { .. } => 1,
        CmpXchg { .. } => 1,
        AtomicRMW { .. } => 1,
        AllocA(_) => 1,
        AllocAHybrid(_, _) => 1,
        Fence(_) => 1,
        // memory addressing
        GetIRef(_) |
        GetFieldIRef { .. } |
        GetElementIRef { .. } |
        ShiftIRef { .. } |
        GetVarPartIRef { .. } => 0,
        // runtime call
        New(_) | NewHybrid(_, _) => 10,
        NewStack(_) | NewThread { .. } | NewFrameCursor(_) => 10,
        ThreadExit => 10,
        CurrentStack => 10,
        KillStack(_) => 10,
        Throw(_) => 10,
        SwapStackExpr { .. } | SwapStackExc { .. } | SwapStackKill { .. } => 10,
        CommonInst_GetThreadLocal | CommonInst_SetThreadLocal(_) => 10,
        CommonInst_Pin(_) | CommonInst_Unpin(_) | CommonInst_GetAddr(_) => 10,
        // others
        Move(_) => 0,
        PrintHex(_) => 10,
        SetRetval(_) => 10,
        GetVMThreadLocal => 10,
        ExnInstruction { ref inner, .. } => estimate_insts_for_ir(&inner)
    }
}
pub fn estimate_insts_for_ir ( inst : & Instruction ) -> usize { use ast :: inst :: Instruction_ :: * ; match inst . v { // simple BinOp ( _ , _ , _ ) => 1 , BinOpWithStatus ( _ , _ , _ , _ ) => 2 , CmpOp ( _ , _ , _ ) => 1 , ConvOp { .. } => 0 , CommonInst_Tr64IsFp ( _ ) | CommonInst_Tr64IsInt ( _ ) | CommonInst_Tr64IsRef ( _ ) | CommonInst_Tr64FromFp ( _ ) | CommonInst_Tr64FromInt ( _ ) | CommonInst_Tr64FromRef ( _ , _ ) | CommonInst_Tr64ToFp ( _ ) | CommonInst_Tr64ToInt ( _ ) | CommonInst_Tr64ToRef ( _ ) | CommonInst_Tr64ToTag ( _ ) => 3 , // control flow Branch1 ( _ ) => 1 , Branch2 { .. } => 1 , Select { .. } => 2 , Watchpoint { .. } => 1 , WPBranch { .. } => 2 , Switch { .. } => 3 , // call ExprCall { .. } | ExprCCall { .. } | Call { .. } | CCall { .. } => 5 , Return ( _ ) => 1 , TailCall ( _ ) => 1 , // memory access Load { .. } | Store { .. } => 1 , CmpXchg { .. } => 1 , AtomicRMW { .. } => 1 , AllocA ( _ ) => 1 , AllocAHybrid ( _ , _ ) => 1 , Fence ( _ ) => 1 , // memory addressing GetIRef ( _ ) | GetFieldIRef { .. } | GetElementIRef { .. } | ShiftIRef { .. } | GetVarPartIRef { .. } => 0 , // runtime call New ( _ ) | NewHybrid ( _ , _ ) => 10 , NewStack ( _ ) | NewThread { .. } | NewFrameCursor ( _ ) => 10 , ThreadExit => 10 , CurrentStack => 10 , KillStack ( _ ) => 10 , Throw ( _ ) => 10 , SwapStackExpr { .. } | SwapStackExc { .. } | SwapStackKill { .. } => 10 , CommonInst_GetThreadLocal | CommonInst_SetThreadLocal ( _ ) => 10 , CommonInst_Pin ( _ ) | CommonInst_Unpin ( _ ) | CommonInst_GetAddr ( _ ) => 10 , // others Move ( _ ) => 0 , PrintHex ( _ ) => 10 , SetRetval ( _ ) => 10 , GetVMThreadLocal => 10 , ExnInstruction { ref inner , .. } => estimate_insts_for_ir ( & inner ) } }
estimate the number of machine instruction for each IR instruction
estimate the number of machine instruction for each IR instruction
inst
&Instruction
inst
&Instruction