如何在LLVM 3.5中遍历支配者树

How to traverse the dominator tree in LLVM 3.5?

本文关键字:遍历 支配者 LLVM      更新时间:2023-10-16

有人知道如何遍历LLVM 3.5中的支配者树吗?我可以使用DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();检索DOM树。然而,我不确定我该如何穿越它。有什么想法吗?

这里的"遍历"是什么意思?DominatorTree具有有用的调用,如dominatesgetDescendantsisReachableFromEntry。请注意,它也是从DominatorTreeBase派生的,因此您可能需要检查此类提供的方法。

LLVM本身中有大量使用DominatorTree的示例。

如果您只想按深度优先顺序遍历一个支配树,您可以尝试:

for (auto node = GraphTraits<DominatorTree *>::nodes_begin(DT);
     node != GraphTraits<DominatorTree *>::nodes_end(DT); ++node) {
  BasicBlock *BB = node->getBlock();
  // whatever you want to do with BB
}

此代码片段摘自StraightLineStrengthReduce。