How to check if a variable is used within a code block (either in RHS or in LHS)


I’m trying to find all the statements within a code region which uses a specific variable either in RHS or in LHS after parsing but before IR code generation. I am implementing it by visiting all the statements within the code region and check if the variables in a statement has a variable having the same name using getQualifiedNameAsString(). I have to consider all the different classes of the statement to extract variable, which seems to be redoing what Clang already does.
I guess there must be a better way to do it.
Is there any method which finds if a variable is used in a statement either in RHS or in LHS?
Or any idea what methods should I use to implement it efficiently without duplicating the existing work in Clang?