2 ms·
clang -S -emit-llvm xyz.cpp generates an optnone attribute. attributes #0 = { noinline norecurse nounwind optnone ssp uwtable "darwin-stkchk-strong-link" "di
by CalChris 5y ago
clang -S -emit-llvm xyz.cpp generates an optnone attribute.
attributes #0 = { noinline norecurse nounwind optnone ssp uwtable "darwin-stkchk-strong-link" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "probe-stack"="___chkstk_darwin" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
This means you can't then run it through opt and watch it pass by pass get optimized with opt --print-after-all -O3 xyz.ll -S -o abc.ll. Clang doesn't take the --print-after-all flag.
What is the purpose of the optnone attribute? Why is Clang preventing later optimization?
- woodruffw 5y agoI’m not sure about the why, but it’s been that way for quite a while (since at least LLVM 5). You can explicitly override the optnone by passing `-disable-O0-optnone` to the underlying driver (i.e., you might need to pass `-Xclang` first.) Edit: if I had to wager a guess, it’s because someone generated an IR module at some point with -O0 and then re-ran opt to perform a specific non-destructive analysis, at which point LLVM happily ran all of its default passes. So someone decided that initially building with -O0 is equivalent to saying “my code should never be optimized, even in subsequent invocations of the compiler.”
- jcranmer 5y agoThe purpose is to keep optimization flags around if you're, say, compiling with LTO or PGO--cases where the regular compilation process will keep bitcode files around. The usual trick I do is clang -S -emit-llvm -O2 -Xclang --disable-llvm-passes. > Clang doesn't take the --print-after-all flag. You have to prefix it with -mllvm, e.g., clang -mllvm -print-after-all -O2 foo.cpp.