pub fn def_use(function: &il::Function) -> Result<HashMap<il::ProgramLocation, LocationSet>> {
    let rd = reaching_definitions::reaching_definitions(function)?;

    let mut du: HashMap<il::ProgramLocation, LocationSet> = HashMap::new();

    for location in rd.keys() {
        du.entry(location.clone()).or_insert_with(LocationSet::new);
        match location.function_location().apply(function).unwrap() {
            il::RefFunctionLocation::Instruction(_, instruction) => instruction
                .operation()
                .scalars_read()
                .into_iter()
                .for_each(|scalar_read| {
                    rd[location].locations().iter().for_each(|rd| {
                        rd.function_location()
                            .apply(function)
                            .unwrap()
                            .instruction()
                            .unwrap()
                            .operation()
                            .scalars_written()
                            .into_iter()
                            .for_each(|scalar_written| {
                                if scalar_written == scalar_read {
                                    du.entry(rd.clone())
                                        .or_insert_with(LocationSet::new)
                                        .insert(location.clone());
                                }
                            })
                    })
                }),
            il::RefFunctionLocation::Edge(edge) => {
                if let Some(condition) = edge.condition() {
                    condition.scalars().into_iter().for_each(|scalar_read| {
                        rd[location].locations().iter().for_each(|rd| {
                            if let Some(scalars_written) = rd
                                .function_location()
                                .apply(function)
                                .unwrap()
                                .instruction()
                                .unwrap()
                                .operation()
                                .scalars_written()
                            {
                                scalars_written.into_iter().for_each(|scalar_written| {
                                    if scalar_written == scalar_read {
                                        du.entry(rd.clone())
                                            .or_insert_with(LocationSet::new)
                                            .insert(location.clone());
                                    }
                                })
                            }
                        })
                    })
                }
            }
            il::RefFunctionLocation::EmptyBlock(_) => {}
        }
    }

    Ok(du)
}
/// Compute definition use chains for the given function.
Compute definition use chains for the given function.
Compute definition use chains for the given function .
pub fn def_use(function: &il::Function) -> Result<HashMap<il::ProgramLocation, LocationSet>> {
    let rd = reaching_definitions::reaching_definitions(function)?;
    let mut du: HashMap<il::ProgramLocation, LocationSet> = HashMap::new();
    for location in rd.keys() {
        du.entry(location.clone()).or_insert_with(LocationSet::new);
        match location.function_location().apply(function).unwrap() {
            il::RefFunctionLocation::Instruction(_, instruction) => instruction
                .operation()
                .scalars_read()
                .into_iter()
                .for_each(|scalar_read| {
                    rd[location].locations().iter().for_each(|rd| {
                        rd.function_location()
                            .apply(function)
                            .unwrap()
                            .instruction()
                            .unwrap()
                            .operation()
                            .scalars_written()
                            .into_iter()
                            .for_each(|scalar_written| {
                                if scalar_written == scalar_read {
                                    du.entry(rd.clone())
                                        .or_insert_with(LocationSet::new)
                                        .insert(location.clone());
                                }
                            })
                    })
                }),
            il::RefFunctionLocation::Edge(edge) => {
                if let Some(condition) = edge.condition() {
                    condition.scalars().into_iter().for_each(|scalar_read| {
                        rd[location].locations().iter().for_each(|rd| {
                            if let Some(scalars_written) = rd
                                .function_location()
                                .apply(function)
                                .unwrap()
                                .instruction()
                                .unwrap()
                                .operation()
                                .scalars_written()
                            {
                                scalars_written.into_iter().for_each(|scalar_written| {
                                    if scalar_written == scalar_read {
                                        du.entry(rd.clone())
                                            .or_insert_with(LocationSet::new)
                                            .insert(location.clone());
                                    }
                                })
                            }
                        })
                    })
                }
            }
            il::RefFunctionLocation::EmptyBlock(_) => {}
        }
    }
    Ok(du)
}
pub fn def_use ( function : & il :: Function ) -> Result < HashMap < il :: ProgramLocation , LocationSet > > { let rd = reaching_definitions :: reaching_definitions ( function ) ? ; let mut du : HashMap < il :: ProgramLocation , LocationSet > = HashMap :: new ( ) ; for location in rd . keys ( ) { du . entry ( location . clone ( ) ) . or_insert_with ( LocationSet :: new ) ; match location . function_location ( ) . apply ( function ) . unwrap ( ) { il :: RefFunctionLocation :: Instruction ( _ , instruction ) => instruction . operation ( ) . scalars_read ( ) . into_iter ( ) . for_each ( | scalar_read | { rd [ location ] . locations ( ) . iter ( ) . for_each ( | rd | { rd . function_location ( ) . apply ( function ) . unwrap ( ) . instruction ( ) . unwrap ( ) . operation ( ) . scalars_written ( ) . into_iter ( ) . for_each ( | scalar_written | { if scalar_written == scalar_read { du . entry ( rd . clone ( ) ) . or_insert_with ( LocationSet :: new ) . insert ( location . clone ( ) ) ; } } ) } ) } ) , il :: RefFunctionLocation :: Edge ( edge ) => { if let Some ( condition ) = edge . condition ( ) { condition . scalars ( ) . into_iter ( ) . for_each ( | scalar_read | { rd [ location ] . locations ( ) . iter ( ) . for_each ( | rd | { if let Some ( scalars_written ) = rd . function_location ( ) . apply ( function ) . unwrap ( ) . instruction ( ) . unwrap ( ) . operation ( ) . scalars_written ( ) { scalars_written . into_iter ( ) . for_each ( | scalar_written | { if scalar_written == scalar_read { du . entry ( rd . clone ( ) ) . or_insert_with ( LocationSet :: new ) . insert ( location . clone ( ) ) ; } } ) } } ) } ) } } il :: RefFunctionLocation :: EmptyBlock ( _ ) => { } } } Ok ( du ) }
Compute definition use chains for the given function.
Compute definition use chains for the given function .
function
&il::Function
function
&il::Function