【问题标题】:Reaching Definitions analysis - is my solution correct达到定义分析 - 我的解决方案是否正确
【发布时间】:2021-05-09 13:52:58
【问题描述】:

我被要求为以下代码编写到达定义,我想知道我的解决方案是否正确?我什至走在正确的轨道上吗?我真的很感激任何帮助或提示。谢谢。

代码:

a = 0;
while (a < 100) {
    b = a + 1
    c = c + b
    a = b * 2
}
return c;

第 1 步:查找块并标记

a = 0;             // block 1  | a1

while (a < 100)    // block 2  |

    b = a + 1      // block 3  | b2
    c = c + b                  | c3
    a = b * 2                  | a3

return c;          // block 3  | 

步骤 #2:为每个块找到 GEN 和 KILL 集

BLOCK GEN KILL
1 a1 a3
2
3 b3, c3, a3 a1
4

第 4 步:检查算法以找到 IN 和 OUT 集

input: control flow graph CFG = (N, E, Entry, Exit)
// Boundary condition
OUT[Entry] = ∅

// Initialization for an iterative algorithm
For each basic block B other than Entry
OUT[B] = ∅

// iterate
While (changes to any OUT occur) {
  For each basic block B other than Entry {
    in[B] = ∪ (out[p]), for all predecessors p of B
    out[B] = fB(in[B]) // out[B]=gen[B]∪(in[B]-kill[B])
}

步骤 #5 导出 IN 和 OUT 集

BLOCK GEN KILL IN OUT
ENTRY
1 a1 a3 a1
2 a1 a1
3 b3, c3, a3 a1 a1 b3, c3, a3
4 b3, c3, a3, a1 b3, c3, a3, a1
EXIT b3, c3, a3, a1 b3, c3, a3, a1

【问题讨论】:

    标签: compiler-construction compiler-optimization rda


    【解决方案1】:

    看看这个例子:https://engineering.purdue.edu/~milind/ece573/2011spring/ps8-sol.pdf

    在该示例中分析的代码比您的稍微复杂一些,但对整个解决方案进行了非常详细的解释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      相关资源
      最近更新 更多