且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

LLVM OPT没有提供优化的文件作为输出。

更新时间:2022-05-04 00:46:03

如果您查看由clang生成的.ll文件,将包含这样的行:

If you look at the .ll file generated by clang, it will contain a line like this:

attributes #0 = { noinline nounwind optnone sspstrong uwtable ...}

您应删除 optnone 属性在这里。每当具有 optnone 属性的函数时, opt 根本就不会涉及该函数。

You should remove the optnone attribute here. Whenever a function has the optnone attribute, opt won't touch that function at all.

现在,如果再试一次,您会发现...什么也没有。

Now if you try again, you'll notice ... nothing. It still does not work.

这一次的问题是代码在内存上而不是寄存器上工作。我们需要做的是使用 -mem2reg alloca 转换为寄存器。实际上,这样做已经可以优化 b 了,因此您甚至不需要 -dce 标志。

This time the problem is that the code is working on memory, not registers. What we need to do is to convert the allocas to registers using -mem2reg. In fact doing this will already optimize away b, so you don't even need the -dce flag.