[LLVMdev] Phi Node Question

Eli Friedman eli.friedman at gmail.com
Tue Jun 9 18:51:56 PDT 2009


On Tue, Jun 9, 2009 at 6:15 PM, Nyx<mcheva at cs.mcgill.ca> wrote:
> Now, the question I have is as follows... If I only define this object once
> at the start of the function, do I need to create phi nodes to propagate its
> value everywhere, or can I keep using the same llvm::Value object everywhere
> in the function, regargless of which basic block I'm currently in?

If you put an instruction in the entry block, you can use the returned
value directly in every other block in the function; that's the magic
of SSA.  If you're doing something more complicated, like creating a
variable whose value might change over the course of the function, you
can stick an alloca in the entry block, use loads and stores to modify
and access the value, and let the mem2reg pass take care of converting
it into PHI nodes.  You never need to create a PHI node yourself if
you don't want to mess with figuring out how exactly they work.

-Eli



More information about the llvm-dev mailing list