如何获得的LLVM控制流图(CFG)的强连通分量(SCC)的拓扑排序(topological order)

本文介绍了如何使用LLVM库中的scc_iterator获取控制流图(CFG)的强连通分量(SCC)的逆拓扑排序,并详细说明由于scc_iterator返回的是逆序,因此需要通过栈来实现正序的拓扑排序。同时提供了相关的代码示例,参考了LLVM的PrintSCC.cpp和SCCIterator.h文件。
摘要由CSDN通过智能技术生成

一、思路

使用llvm/ADT/SCCIterator.h中定义的scc_iterator迭代器获得。

但是scc_iterator获得是逆拓扑排序的。它的注释如下:

// The SCC iterator has the important property that if a node in SCC S1 has an
// edge to a node in SCC S2, then it visits S1 *after* S2.


/// scc_iterator - Enumerate the SCCs of a directed graph, in
/// reverse topological order of the SCC DAG

所以我们使用栈进行获得SCC正序的拓扑排序(因为scc_iterator不支持自减)

二、获得SCC拓扑排序的代码:

代码如下,其中F是Function*类型的,是待分析的函数

132     std::stack<scc_iterator<Function*> > sccs;
133     for(scc_iterator<Function*> SCCI=scc_begin(F),SCCE=scc_end(F);SCCI!=SCCE;++SCCI)
134         sccs.push(SCCI);
135 
136     //按照顺序遍历强连通分量(SCC)
137     unsigned sccNum=0;
138     while(!sccs.empty()){
139         scc_iterator<Function*> SCCI=sccs.top();
140         sccs.pop();
141         std::vector<BasicBlock*> & next
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值