[LLVMdev] Value liveout (uses)

John McCall rjmccall at apple.com
Fri May 29 23:57:04 PDT 2009


On May 29, 2009, at 11:37 PM, Rotem Varon wrote:
> How can i know, if a value have uses outside of the current basic  
> block (liveout), without iterating through all the basic block ?

If the value is created within the basic block in question, and the  
block doesn't loop to itself, then you can just iterate through the  
uses and note if the use is an instruction in a different block:

bool isLiveOut(Instruction* I) {
	BasicBlock* I_BB = I->getParent():
	for (Value::use_iterator ui = I->use_begin(), ue = I->use_end(); ui ! 
= ue; ++ui)
		if (cast<Instruction>(ui)->getParent() != I_BB)
			return true;
	}
}

If the value is created within the block but the block loops to  
itself, you can get away with a very slight adjustment:

		if (cast<Instruction>(ui)->getParent() != I_BB && !isa<PHINode>(ui))

If the value is created in one block and you want to know if it's live  
out of some dominated block, that's a lot more complicated (and  
expensive).

John.



More information about the llvm-dev mailing list