llvm.org GIT mirror llvm / 261aa93
[NFC] BasicBlock: generalize replaceSuccessorsPhiUsesWith(), take Old bb Thus it does not assume that the old basic block is the basic block for which we are looking at successors. Not reviewed, but seems rather trivial, in line with the rest of previous few patches. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359997 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Lebedev 1 year, 5 months ago
2 changed file(s) with 14 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
394394 void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New);
395395
396396 /// Update all phi nodes in this basic block's successors to refer to basic
397 /// block \p New instead of basic block \p Old.
398 void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New);
399
400 /// Update all phi nodes in this basic block's successors to refer to basic
397401 /// block \p New instead of to it.
398402 void replaceSuccessorsPhiUsesWith(BasicBlock *New);
399403
424424 // Now we must loop through all of the successors of the New block (which
425425 // _were_ the successors of the 'this' block), and update any PHI nodes in
426426 // successors. If there were PHI nodes in the successors, then they need to
427 // know that incoming branches will be from New, not from Old.
427 // know that incoming branches will be from New, not from Old (this).
428428 //
429 llvm::for_each(successors(New), [this, New](BasicBlock *Succ) {
430 Succ->replacePhiUsesWith(this, New);
431 });
429 New->replaceSuccessorsPhiUsesWith(this, New);
432430 return New;
433431 }
434432
443441 }
444442 }
445443
446 void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
444 void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,
445 BasicBlock *New) {
447446 Instruction *TI = getTerminator();
448447 if (!TI)
449448 // Cope with being called on a BasicBlock that doesn't have a terminator
450449 // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
451450 return;
452 llvm::for_each(successors(TI), [this, New](BasicBlock *Succ) {
453 Succ->replacePhiUsesWith(this, New);
451 llvm::for_each(successors(TI), [Old, New](BasicBlock *Succ) {
452 Succ->replacePhiUsesWith(Old, New);
454453 });
454 }
455
456 void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
457 this->replaceSuccessorsPhiUsesWith(this, New);
455458 }
456459
457460 /// Return true if this basic block is a landing pad. I.e., it's