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