如何使用SSA形式处理数据流分析中的别名寄存器? (例如 x86 中的 EAX/AX/AH/AL)

发布于 2024-08-30 04:02:17 字数 473 浏览 2 评论 0原文

例如:

SSA form 中表示以下 x86:

xor  eax, eax
inc  ax

如何 引入一些伪函数,我想出:

eax@1 = eax@0 ^ eax@0
ax@1 = LOWORD(eax@1)
al@1 = LOBYTE(ax@1)
ah@1 = HIBYTE(ax@1)
hax@1 = HIWORD(eax@1)

ax@2 = ax@1 + 1
eax@2 = MAKEDWORD(ax@2, HIWORD(eax@1))
al@2 = LOBYTE(ax@2)
ah@2 = HIBYTE(ax@2)

但我认为它太冗长了

For exmaple:

How to represent the following x86 in SSA form:

xor  eax, eax
inc  ax

By introducing some pseudo functions, I come up with:

eax@1 = eax@0 ^ eax@0
ax@1 = LOWORD(eax@1)
al@1 = LOBYTE(ax@1)
ah@1 = HIBYTE(ax@1)
hax@1 = HIWORD(eax@1)

ax@2 = ax@1 + 1
eax@2 = MAKEDWORD(ax@2, HIWORD(eax@1))
al@2 = LOBYTE(ax@2)
ah@2 = HIBYTE(ax@2)

But I think it's too much verbose

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落墨 2024-09-06 04:02:17

使用您的符号:

  1. eax@0 = ... 无论这里之前是什么 ...
  2. eax@1 = 0
  3. ax@2 = ax@1 + 1

之间有一个隐式步骤

  1. 因为 eax 包含 ax,所以在 2 和 3 eax@0 = ...
  2. eax@1 = 0
  3. ax@1 = 0 (因为如果 eax 为零,则 ax 不能为非零)
  4. ax@2 = ax@1 + 1

步骤 2 因为任何数字与其自身异或都是 0.. eax@0 此时已死,因此 eax@1 可以重命名(使用 ebx 进行重命名,使其可读;显然您将使用虚拟寄存器,而不是真实的寄存器):

  1. --- 已删除,eax 不再相关
  2. ebx@0 = 0
  3. bx@0 = 0
  4. bx@1 = bx@0 + 1

然后您可以注意到,因为步骤 3 是一个常量函数,所以步骤 4(将常量添加到常量)也是如此,并将两者压缩在一起(即常量折叠)

  1. -- 已删除,eax 不再相关
  2. ebx@0 = 0
  3. bx@0 = 1

如果 ebx 的高 16 位不支配下面的任何内容,您也可以删除步骤 2。

Using your notation:

  1. eax@0 = ... whatever it was before here ...
  2. eax@1 = 0
  3. ax@2 = ax@1 + 1

Because eax contains ax, there's an implicit step in between 2 and 3

  1. eax@0 = ...
  2. eax@1 = 0
  3. ax@1 = 0 (because ax cannot be non-zero if eax is zero)
  4. ax@2 = ax@1 + 1

Step 2 because any number xor'ed with itself is 0... eax@0 is dead at that point, and thus eax@1 can be renamed (using ebx as renaming so it's readable; obviously you would use a virtual register, not a real one):

  1. --- deleted, eax no longer relevant
  2. ebx@0 = 0
  3. bx@0 = 0
  4. bx@1 = bx@0 + 1

You could then note that because step 3 is a constant function, so is step 4 (adding a constant to a constant) and compress the two together (i.e. constant folding)

  1. -- deleted, eax no longer relevant
  2. ebx@0 = 0
  3. bx@0 = 1

If the upper 16 bits of ebx don't dominate anything below this, you could also delete step 2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文