There is PHINode::getBasicBlockIndex() and PHINode::setIncomingValue() but no function to replace incoming value for a specified BasicBlock* predecessor.
Clearly, there are a lot of places that could use that functionality.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
llvm/include/llvm/IR/Instructions.h | ||
---|---|---|
2729 | can this just be int Idx = getBasicBlockIndex(BB); assert(Idx >= 0 && "Invalid basic block argument!"); return setIncomingValue(Idx, V); similar to getIncomingValueForBlock above? |
llvm/include/llvm/IR/Instructions.h | ||
---|---|---|
2729 | I thought of doing that, but sometimes a phi node may have multiple operands of the same incoming block (not sure why). I am using a similar code pattern as in replaceIncomingBlockWith(). |
llvm/include/llvm/IR/Instructions.h | ||
---|---|---|
2729 | Ah right. I think it is worth mentioning in the doc comment that it will replace all values coming from BB? For the places that use getbasicBlockIndex, this is not a NFC I think, as they would only replace the incoming value of the first occurrence. |
llvm/include/llvm/IR/Instructions.h | ||
---|---|---|
2729 | Removed [NFC] from the title. And updated the comment. |
LGTM, please wait for @fhahn's ok as well.
llvm/include/llvm/IR/Instructions.h | ||
---|---|---|
2677 | [nit] unrelated | |
2729 | It's not forbidden and sometimes cannot even be simplified by fusing edges, e.g. a switch with multiple values branching to the same block. Unfortunately for the PHI it is indistinguishable which of the switch cases was taken. That means, all of the incoming values from the same block should be the same. This patch may actually fix some bugs where only one of the incoming values was changed. | |
2733 | [suggestion] assert when no matching block was found? |
LGTM, thanks for updating. I think it would be good to add an assertion as Micheal suggested, as we have similar ones in related functions.
[nit] unrelated