Lifetime analysis of variables within a module

Hi all,

I'm looking for a LLVM method/class/strategy to know the lifetime of every variable/value used in a given Module.
I want to know the variables that must be alive at the input and at the end of every function call (and every BasicBlock).

By creating a pass inheriting from ModulePass I can reach up to here:

virtual bool runOnFunction(Function &F) {
   for (Function::iterator bbi = F.begin(), bbf = F.end(); bbi != bbf; bbi++)
     for (BasicBlock::iterator insi = bbi->begin(), insf = bbi->end(); insi != insf; insi++)
         for (User::op_iterator opi = insi->op_begin(), opf = insi->op_end(); opi != opf; opi++)

                 if(isa<Instruction>(opi) || isa<Argument>(opi))

                 // Here I am <===============


How can I use LiveIntervals/LiveVariables/LiveRange to obtain the live range for a given variable of interest?

BTW, do you know any working example of using MachineFunctionPass or LiveIntervals LLVM passes? Every time I use it, opt generates output such as:

opt: PassManager.cpp:597: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed.
0 0x00007f42eb6469ef
7 0x00007f42eb1ccafa llvm::PMTopLevelManager::schedulePass(llvm::Pass*) + 1226

Thank you in advance !!!!

These passes operate on machine instructions (registers). You are trying to run them on bitcode.