1 //==- bolt/Core/BinaryDomTree.h - Dominator Tree at low-level IR -*- C++ -*-==// 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 defines the BinaryDomTree class, which represents a dominator tree 10 // in the CFG of a binary function. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef BOLT_CORE_BINARY_DOMTREE_H 15 #define BOLT_CORE_BINARY_DOMTREE_H 16 17 #include "bolt/Core/BinaryBasicBlock.h" 18 #include "llvm/IR/Dominators.h" 19 20 namespace llvm { 21 namespace bolt { 22 23 using BinaryDomTreeNode = DomTreeNodeBase<BinaryBasicBlock>; 24 using BinaryDominatorTree = DomTreeBase<BinaryBasicBlock>; 25 26 } // namespace bolt 27 28 // BinaryDominatorTree GraphTraits specializations. 29 template <> 30 struct GraphTraits<bolt::BinaryDomTreeNode *> 31 : public DomTreeGraphTraitsBase<bolt::BinaryDomTreeNode, 32 bolt::BinaryDomTreeNode::iterator> {}; 33 34 template <> 35 struct GraphTraits<const bolt::BinaryDomTreeNode *> 36 : public DomTreeGraphTraitsBase<const bolt::BinaryDomTreeNode, 37 bolt::BinaryDomTreeNode::const_iterator> {}; 38 39 template <> 40 struct GraphTraits<bolt::BinaryDominatorTree *> 41 : public GraphTraits<bolt::BinaryDomTreeNode *> { 42 static NodeRef getEntryNode(bolt::BinaryDominatorTree *DT) { 43 return DT->getRootNode(); 44 } 45 46 static nodes_iterator nodes_begin(bolt::BinaryDominatorTree *N) { 47 return df_begin(getEntryNode(N)); 48 } 49 50 static nodes_iterator nodes_end(bolt::BinaryDominatorTree *N) { 51 return df_end(getEntryNode(N)); 52 } 53 }; 54 55 } // namespace llvm 56 57 #endif 58