Is there an easy way to obtain all liveout variables of a basic block? Liveins can be found for each MachineBasicBlock, but I can only find liveouts for the whole function, at MachineRegisterInfo. Do I need to find them out manually?
They cannot be found like the live in values because different values may be live out. For instance the psudocode may look like: BB0: vreg1 = rand() if( vreg1 > .5 ) goto BB1; else goto BB2; BB1: vreg 2 = rand(); EAX = copy vreg2; Return BB2: vreg 3 = rand() * rand()' EAX = copy vreg3; Return On Fri, Nov 5, 2010 at 7:41 AM, s Last namerc <srcsrc84 at yahoo.com> wrote:> Is there an easy way to obtain all liveout variables of a basic block? > Liveins > can be found for each MachineBasicBlock, but I can only find liveouts for > the > whole function, at MachineRegisterInfo. Do I need to find them out > manually? > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101105/2b11417f/attachment.html>
Sorry, I think I answered the wrong question. On Fri, Nov 5, 2010 at 12:07 PM, Jeff Kunkel <jdkunk3 at gmail.com> wrote:> They cannot be found like the live in values because different values may > be live out. > > For instance the psudocode may look like: > > BB0: > vreg1 = rand() > if( vreg1 > .5 ) goto BB1; > else goto BB2; > BB1: > vreg 2 = rand(); > EAX = copy vreg2; > Return > BB2: > vreg 3 = rand() * rand()' > EAX = copy vreg3; > Return > > On Fri, Nov 5, 2010 at 7:41 AM, s Last namerc <srcsrc84 at yahoo.com> wrote: > >> Is there an easy way to obtain all liveout variables of a basic block? >> Liveins >> can be found for each MachineBasicBlock, but I can only find liveouts for >> the >> whole function, at MachineRegisterInfo. Do I need to find them out >> manually? >> >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101105/75109c51/attachment.html>
Because I feel bad for giving a non-answer: An easy way to find if a virtual register is alive after the basic block is to While iterating over the virtual registers - Check to see if the virtual register's "next" value exists outside of the basic block. for instance: std::vector<unsigned> findLiveOut( MachineBasicBlock * mbb ) { std::vector<unsigned> liveout; for( MachineBasicBlock::iterator mbbi = mbb->begin(), mbbe = mbb->end(); mbbi != mbbe; ++mbbi ) { for( opi = 0, ope = mbbi->getNumOperands(); opi < ope; ++opi ) { MachineOperand & operand = mbbi->getOperand(opi); if( operand.isReg() == false ) continue; if( operand.getReg() == 0 ) continue; if( ! TargetRegisterInfo::isVirtualRegister(operand.getReg()) ) continue; if( mbb != operand.getNextOperandForReg()->getParent()->getParent() ) liveout.push_back( operand.getReg() ); } } return liveout; } On Fri, Nov 5, 2010 at 7:41 AM, s Last namerc <srcsrc84 at yahoo.com> wrote:> Is there an easy way to obtain all liveout variables of a basic block? > Liveins > can be found for each MachineBasicBlock, but I can only find liveouts for > the > whole function, at MachineRegisterInfo. Do I need to find them out > manually? > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101105/83e56d86/attachment.html>
I'm not sure this will work: The "next" use may be in a sibling block, rather than a successor, or there could be intervening definitions. In either case the value isn't really live out of the block. I think the live-ins list only includes physical registers too. You're probably best off running the LiveIntervals pass and seeing which intervals are live across the last index in the basic block (see LiveIntervals::getMBBEndIdx()). - Lang. On Fri, Nov 5, 2010 at 1:05 PM, Jeff Kunkel <jdkunk3 at gmail.com> wrote:> Because I feel bad for giving a non-answer: > An easy way to find if a virtual register is alive after the basic block is > to > While iterating over the virtual registers > - Check to see if the virtual register's "next" value exists outside of the > basic block. > for instance: > std::vector<unsigned> findLiveOut( MachineBasicBlock * mbb ) { > std::vector<unsigned> liveout; > for( MachineBasicBlock::iterator mbbi = mbb->begin(), mbbe = mbb->end(); > mbbi != mbbe; ++mbbi ) { > for( opi = 0, ope = mbbi->getNumOperands(); opi < ope; ++opi ) { > MachineOperand & operand = mbbi->getOperand(opi); > if( operand.isReg() == false ) > continue; > if( operand.getReg() == 0 ) > continue; > if( ! TargetRegisterInfo::isVirtualRegister(operand.getReg()) ) > continue; > if( mbb != operand.getNextOperandForReg()->getParent()->getParent() ) > liveout.push_back( operand.getReg() ); > } > } > return liveout; > } > > > On Fri, Nov 5, 2010 at 7:41 AM, s Last namerc <srcsrc84 at yahoo.com> wrote: >> >> Is there an easy way to obtain all liveout variables of a basic block? >> Liveins >> can be found for each MachineBasicBlock, but I can only find liveouts for >> the >> whole function, at MachineRegisterInfo. Do I need to find them out >> manually? >> >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >