[LLVMdev] Variable-length Phi-node

Filip Pizlo fpizlo at apple.com
Sat Nov 9 09:59:40 PST 2013


You can call addIncoming().

  /// addIncoming - Add an incoming value to the end of the PHI list
  ///
  void addIncoming(Value *V, BasicBlock *BB) {
    assert(V && "PHI node got a null value!");
    assert(BB && "PHI node got a null basic block!");
    assert(getType() == V->getType() &&
           "All operands to PHI node must be the same type as the PHI node!");
    if (NumOperands == ReservedSpace)
      growOperands();  // Get more space!
    // Initialize some new operands.
    ++NumOperands;
    setIncomingValue(NumOperands - 1, V);
    setIncomingBlock(NumOperands - 1, BB);
  }

-Filip


On Nov 9, 2013, at 9:56 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:

> On 9 Nov 2013, at 16:35, William Moses <moses.williamsteven at gmail.com> wrote:
> 
>> 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.
> 
> The PHI node preallocates its storage, so no.
> 
>> 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?
> 
> 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?
> 
> David
> 
> 
> _______________________________________________
> 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/20131109/e7898887/attachment.html>


More information about the llvm-dev mailing list