<div dir="ltr">Excellent.<div><br>> <span style="font-family:arial,sans-serif;font-size:13px">What are you doing that means that you don't know how many incoming blocks a block has when you create it?</span></div><div>

<font face="arial, sans-serif">I'm making a higher-level abstraction on top of allocated memory or "LazyVariable" -- the goal is be able to create a variable (whose value can be get or set, and whose location (e.g. a pointer to the memory) can be found) which can use cached values instead of having to do many load/stores.</font></div>

<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">This is being implemented by a struct containing the pointer to the allocated memory, and map from BasicBlocks to the most recent cached Value (NULL if it is unknown / changed by an external process such as passing the pointer itself to a function). Since I always write instructions to BasicBlocks sequentially, this method is very efficient for removing unnecessary code without an additional pass. The reason I need the PHINode is to be able to combine cached values from previous blocks in a new cached value for the current node. However, as this only deals with LLVM code and not upper-level knowledge of how the variable is used, the "LazyVariable" won't know how many predecessors a block will have.</font></div>

<div><font face="arial, sans-serif"><br></font>Additionally, (for the finalization of the "LazyVariable") is there a fast way to retrieve all of the predecessors to a BasicBlock in a function. Specifically, is there a fast way to iterate through all BasicBlocks which can break to a specific BasicBlock? </div>

</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 9, 2013 at 12:59 PM, Filip Pizlo <span dir="ltr"><<a href="mailto:fpizlo@apple.com" target="_blank">fpizlo@apple.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>You can call addIncoming().</div><div><br></div><div>  /// addIncoming - Add an incoming value to the end of the PHI list</div>

<div>  ///</div><div>  void addIncoming(Value *V, BasicBlock *BB) {</div><div>    assert(V && "PHI node got a null value!");</div><div>    assert(BB && "PHI node got a null basic block!");</div>

<div>    assert(getType() == V->getType() &&</div><div>           "All operands to PHI node must be the same type as the PHI node!");</div><div>    if (NumOperands == ReservedSpace)</div><div>      growOperands();  // Get more space!</div>

<div>    // Initialize some new operands.</div><div>    ++NumOperands;</div><div>    setIncomingValue(NumOperands - 1, V);</div><div>    setIncomingBlock(NumOperands - 1, BB);</div><div>  }</div><div><br></div><div>-Filip</div>

<div><br></div><div><br></div><div><div><div class="h5"><div>On Nov 9, 2013, at 9:56 AM, David Chisnall <<a href="mailto:David.Chisnall@cl.cam.ac.uk" target="_blank">David.Chisnall@cl.cam.ac.uk</a>> wrote:</div><br>

</div></div><blockquote type="cite"><div style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">

<div><div class="h5">On 9 Nov 2013, at 16:35, William Moses <<a href="mailto:moses.williamsteven@gmail.com" target="_blank">moses.williamsteven@gmail.com</a>> wrote:<br><br><blockquote type="cite">Is it possible to create something which has the same effect of a variable-length phi node in the C++ api. Specifically, create a phi-node where the number of incoming values is not known at the time of its creation.<br>

</blockquote><br>The PHI node preallocates its storage, so no.<br><br><blockquote type="cite">If there is no such way of creating a phinode like that, would it be possible to create a dummy instruction and perform a replaceAllUsesWith? If so, what should the dummy instruction be?<br>

</blockquote><br>You could use a PHI node with a small number if incoming blocks, and when you go past that number you could replace it with another one.  Ideally though, you'd defer creating the block with the PHI node in it until you knew what the CFG would look like.  What are you doing that means that you don't know how many incoming blocks a block has when you create it?<br>

<br>David<br><br><br></div></div>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a><span> </span>        <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>

<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></div></blockquote></div><br></div></blockquote></div><br></div>