1*0fca6ea1SDimitry Andric //===- MachineDomTreeUpdater.cpp -----------------------------------------===// 2*0fca6ea1SDimitry Andric // 3*0fca6ea1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0fca6ea1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0fca6ea1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0fca6ea1SDimitry Andric // 7*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===// 8*0fca6ea1SDimitry Andric // 9*0fca6ea1SDimitry Andric // This file implements the MachineDomTreeUpdater class, which provides a 10*0fca6ea1SDimitry Andric // uniform way to update dominator tree related data structures. 11*0fca6ea1SDimitry Andric // 12*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===// 13*0fca6ea1SDimitry Andric 14*0fca6ea1SDimitry Andric #include "llvm/CodeGen/MachineDomTreeUpdater.h" 15*0fca6ea1SDimitry Andric #include "llvm/ADT/SmallSet.h" 16*0fca6ea1SDimitry Andric #include "llvm/Analysis/GenericDomTreeUpdaterImpl.h" 17*0fca6ea1SDimitry Andric #include "llvm/CodeGen/MachinePostDominators.h" 18*0fca6ea1SDimitry Andric #include "llvm/Support/GenericDomTree.h" 19*0fca6ea1SDimitry Andric #include <algorithm> 20*0fca6ea1SDimitry Andric #include <functional> 21*0fca6ea1SDimitry Andric #include <utility> 22*0fca6ea1SDimitry Andric 23*0fca6ea1SDimitry Andric namespace llvm { 24*0fca6ea1SDimitry Andric 25*0fca6ea1SDimitry Andric template class GenericDomTreeUpdater< 26*0fca6ea1SDimitry Andric MachineDomTreeUpdater, MachineDominatorTree, MachinePostDominatorTree>; 27*0fca6ea1SDimitry Andric 28*0fca6ea1SDimitry Andric template void 29*0fca6ea1SDimitry Andric GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree, 30*0fca6ea1SDimitry Andric MachinePostDominatorTree>::recalculate(MachineFunction 31*0fca6ea1SDimitry Andric &MF); 32*0fca6ea1SDimitry Andric forceFlushDeletedBB()33*0fca6ea1SDimitry Andricbool MachineDomTreeUpdater::forceFlushDeletedBB() { 34*0fca6ea1SDimitry Andric if (DeletedBBs.empty()) 35*0fca6ea1SDimitry Andric return false; 36*0fca6ea1SDimitry Andric 37*0fca6ea1SDimitry Andric for (auto *BB : DeletedBBs) { 38*0fca6ea1SDimitry Andric eraseDelBBNode(BB); 39*0fca6ea1SDimitry Andric BB->eraseFromParent(); 40*0fca6ea1SDimitry Andric } 41*0fca6ea1SDimitry Andric DeletedBBs.clear(); 42*0fca6ea1SDimitry Andric return true; 43*0fca6ea1SDimitry Andric } 44*0fca6ea1SDimitry Andric 45*0fca6ea1SDimitry Andric // The DT and PDT require the nodes related to updates 46*0fca6ea1SDimitry Andric // are not deleted when update functions are called. 47*0fca6ea1SDimitry Andric // So MachineBasicBlock deletions must be pended when the 48*0fca6ea1SDimitry Andric // UpdateStrategy is Lazy. When the UpdateStrategy is 49*0fca6ea1SDimitry Andric // Eager, the MachineBasicBlock will be deleted immediately. deleteBB(MachineBasicBlock * DelBB)50*0fca6ea1SDimitry Andricvoid MachineDomTreeUpdater::deleteBB(MachineBasicBlock *DelBB) { 51*0fca6ea1SDimitry Andric validateDeleteBB(DelBB); 52*0fca6ea1SDimitry Andric if (Strategy == UpdateStrategy::Lazy) { 53*0fca6ea1SDimitry Andric DeletedBBs.insert(DelBB); 54*0fca6ea1SDimitry Andric return; 55*0fca6ea1SDimitry Andric } 56*0fca6ea1SDimitry Andric 57*0fca6ea1SDimitry Andric eraseDelBBNode(DelBB); 58*0fca6ea1SDimitry Andric DelBB->eraseFromParent(); 59*0fca6ea1SDimitry Andric } 60*0fca6ea1SDimitry Andric validateDeleteBB(MachineBasicBlock * DelBB)61*0fca6ea1SDimitry Andricvoid MachineDomTreeUpdater::validateDeleteBB(MachineBasicBlock *DelBB) { 62*0fca6ea1SDimitry Andric assert(DelBB && "Invalid push_back of nullptr DelBB."); 63*0fca6ea1SDimitry Andric assert(DelBB->pred_empty() && "DelBB has one or more predecessors."); 64*0fca6ea1SDimitry Andric } 65*0fca6ea1SDimitry Andric 66*0fca6ea1SDimitry Andric } // namespace llvm 67