compor / llvm-ir-cmake-utils

LLVM IR CMake utils for bitcode file manipulation by opt and friends
GNU Lesser General Public License v2.1
68 stars 14 forks source link

Correctly produce unoptimized LLVM IR code based on LLVM version #14

Closed compor closed 6 years ago

compor commented 6 years ago

There seems to have been a change in the way -O0 works in conjunction with --emit-llvm.

If -O0 is used with the latest LLVM versions, functions get annotated with optnone attribute, which prohibits further optimizations. The workaround seems to be to use -O1 along with -disable-llvm-optzns and/or -disable-llvm-passes.

The related discussion can be found here.

compor commented 6 years ago

From so far use it seems not to affect:

These can get unoptimized IR that can be optimized later with --emit-llvm -O0.

compor commented 6 years ago

The minimum affected version is:

according to this thread and added with this review.

compor commented 6 years ago

Since we simply add -emit-llvm to the already provided options, if we just want to get raw unoptimized IR, but with the ability to further optimize it (i.e. IR without the optnone attribute) we need to add the following options for clang:

-O1 -Xclang -disable-llvm-passes

or

-O0 -Xclang -disable-O0-optnone

Please note that cmake uses -O1 if no optimization level is explicitly specified.

compor commented 6 years ago

Addressed in documentation in a7058f9fe5b662fce7076c857ff2c96ffee839b7 with version tag 2.6.0.