gpt4 book ai didi

llvm - 如何在没有优化的情况下在llvm中获得 "phi"指令

转载 作者:行者123 更新时间:2023-12-01 08:00:35 33 4
gpt4 key购买 nike

当我使用命令 clang -emit-llvm -S test.c -o test.ll 时,IR 文件中没有任何“phi”指令。我怎么才能得到它?

我知道我可以使用传递“-mem2reg”或“-gvn”来获取“phi”指令。但他们会做一些优化。我只想在没有任何优化的情况下获得“phi”。

最佳答案

我不确定你所说的“做一些优化”是什么意思,但在我看来 mem2reg 正是你所需要的。这是 described in the documentation 的样子:

This file promotes memory references to be register references. It promotes alloca instructions which only have loads and stores as uses. An alloca is transformed by using dominator frontiers to place phi nodes, then traversing the function in depth-first order to rewrite loads and stores as appropriate. This is just the standard SSA construction algorithm to construct “pruned” SSA form.



Clang 本身不会产生优化的 LLVM IR。它产生相当简单的 IR,其中本地人保存在内存中(使用 alloca s)。优化是由 opt 在 LLVM IR 级别完成的,最重要的优化之一确实是 mem2reg,它确保在 LLVM 的 SSA 值而不是内存中表示局部变量。

关于llvm - 如何在没有优化的情况下在llvm中获得 "phi"指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20341616/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com