循环,重要性不必多说。
llvm与循环相关的优化有很多:
- loop unroll and jam : 循环展开+ 合并
- loop unroll
- SCEV
- loop invariant code motion
- loop interchange
- loop rotation
- loop splitting
- loop fusion
- loop unswitching
- loop vectorization
….
- 从非结构化的CFG中识别loop:
- 识别循环迭代变量
- Loop 定义
A loop in a control flow graph is a set of nodes S including a header node h, with the following properties:
- From any node in S there is a path leading to h
- There is a path from h to any node in S
- There is no edge from any node outside S to any node in S other than h
back edge
A control flow graph edge from a node n to a node h that dominates n is called a back edge.natural loop
The natural loop of a backedge (n,h), where h dominates n, is
• the set of nodes x such that h dominates x and
• there is a path from x to n not containing h.
The header of this loop will be h
Each back-edge has a corresponding natural loopnested loop
Suppose:
– A and B are loops with headers a and b, such that a != b, and b is in A
Then
– The nodes of B must be a proper subset of the nodes of A
– We say that loop B is nested within A
– B is the inner loop
loop识别
假设已经有domtree。
根据loop的定义,从遍历domtree开始构建loop。
用后序方式遍历domtree,即先识别内层loop,然后识别外层loop。
1 |
|