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

    let mut ud = HashMap::new();

    for location in rd.keys() {
        let defs = match location.function_location().apply(function).unwrap() {
            il::RefFunctionLocation::Instruction(_, instruction) => instruction
                .operation()
                .scalars_read()
                .into_iter()
                .fold(LocationSet::new(), |mut defs, 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 {
                                    defs.insert(rd.clone());
                                }
                            })
                    });
                    defs
                }),
            il::RefFunctionLocation::Edge(edge) => edge
                .condition()
                .map(|condition| {
                    condition.scalars().into_iter().fold(
                        LocationSet::new(),
                        |mut defs, 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 {
                                            defs.insert(rd.clone());
                                        }
                                    })
                                }
                            });
                            defs
                        },
                    )
                })
                .unwrap_or_else(LocationSet::new),
            il::RefFunctionLocation::EmptyBlock(_) => LocationSet::new(),
        };
        ud.insert(location.clone(), defs);
    }

    Ok(ud)
}
/// Compute use definition chains for the given function.
Compute use definition chains for the given function.
Compute use definition chains for the given function .
pub fn use_def(function: &il::Function) -> Result<HashMap<il::ProgramLocation, LocationSet>> {
    let rd = reaching_definitions::reaching_definitions(function)?;
    let mut ud = HashMap::new();
    for location in rd.keys() {
        let defs = match location.function_location().apply(function).unwrap() {
            il::RefFunctionLocation::Instruction(_, instruction) => instruction
                .operation()
                .scalars_read()
                .into_iter()
                .fold(LocationSet::new(), |mut defs, 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 {
                                    defs.insert(rd.clone());
                                }
                            })
                    });
                    defs
                }),
            il::RefFunctionLocation::Edge(edge) => edge
                .condition()
                .map(|condition| {
                    condition.scalars().into_iter().fold(
                        LocationSet::new(),
                        |mut defs, 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 {
                                            defs.insert(rd.clone());
                                        }
                                    })
                                }
                            });
                            defs
                        },
                    )
                })
                .unwrap_or_else(LocationSet::new),
            il::RefFunctionLocation::EmptyBlock(_) => LocationSet::new(),
        };
        ud.insert(location.clone(), defs);
    }
    Ok(ud)
}
pub fn use_def ( function : & il :: Function ) -> Result < HashMap < il :: ProgramLocation , LocationSet > > { let rd = reaching_definitions :: reaching_definitions ( function ) ? ; let mut ud = HashMap :: new ( ) ; for location in rd . keys ( ) { let defs = match location . function_location ( ) . apply ( function ) . unwrap ( ) { il :: RefFunctionLocation :: Instruction ( _ , instruction ) => instruction . operation ( ) . scalars_read ( ) . into_iter ( ) . fold ( LocationSet :: new ( ) , | mut defs , 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 { defs . insert ( rd . clone ( ) ) ; } } ) } ) ; defs } ) , il :: RefFunctionLocation :: Edge ( edge ) => edge . condition ( ) . map ( | condition | { condition . scalars ( ) . into_iter ( ) . fold ( LocationSet :: new ( ) , | mut defs , 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 { defs . insert ( rd . clone ( ) ) ; } } ) } } ) ; defs } , ) } ) . unwrap_or_else ( LocationSet :: new ) , il :: RefFunctionLocation :: EmptyBlock ( _ ) => LocationSet :: new ( ) , } ; ud . insert ( location . clone ( ) , defs ) ; } Ok ( ud ) }
Compute use definition chains for the given function.
Compute use definition chains for the given function .
function
&il::Function
function
&il::Function