How to know if an instruction is "usable"

Is there an easy way to know if, at a certain instruction, a certain value is usable or not? i.e., I am sure that if i use that value i don’t to get the error “Instruction does not dominate all uses!”
Thanks,
GT

Check if the block containing the definition dominates the block where you want to use the value. If this is the same block, the definition has to appear before the use. This follows directly from the error message, so I'm not sure if this answers your question. Use the dominator tree analysis to check the dominance.

-Krzysztof

Thanks,
So, how do I check if a block dominates another one?

In IR use analysis DominatorTree from "include/llvm/Analysis/Dominators.h". For machine instructions, use MachineDominatorTree
from "include/llvm/CodeGen/MachineDominators.h".

Both of them implement function "dominates" that takes two blocks (BasicBlock* or MachineBasicBlock*) and returns a boolean value indicating whether one dominates the other. A block will always dominate itself, so this case needs to be handled separately to determine relative position between the def and the use instruction.

-Krzysztof

Thanks! I checked that module. If I use dominates(const Instruction *Def,const Instruction *User) it will automatically check everything, so I don’t have to handle the case with instructions in the same BB, right?
Thanks,
GT

Sounds like it should, but I've never used it. You can always check how it's defined.

-Krzysztof