[llvm-dev] Is there a way to pass Optimization passes to clang?

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 2 10:39:51 PST 2015


On 2 Dec 2015, at 18:30, Phil Tomson <phil.a.tomson at gmail.com> wrote:
> 
>> If you want to pass LLVM arguments to clang, then you must prefix them with -llvm (e.g. -mllvm -loops -mllvm lcssa).
> 
> 
> I just tried this:
> CFLAGS += -mllvm adce -mllvm loops -mllvm loop-simplify -mllvm lcssa -mllvm simplify-libcalls
> 
> And get:
> 
> clang (LLVM option parsing): Unknown command line argument 'adce'.  Try: 'clang (LLVM option parsing) -help'
> clang (LLVM option parsing): Unknown command line argument 'loops'.  Try: 'clang (LLVM option parsing) -help'
> clang (LLVM option parsing): Unknown command line argument 'loop-simplify'.  Try: 'clang (LLVM option parsing) -help'
> clang (LLVM option parsing): Unknown command line argument 'lcssa'.  Try: 'clang (LLVM option parsing) -help'
> clang (LLVM option parsing): Unknown command line argument 'simplify-libcalls'.  Try: 'clang (LLVM option parsing) -help'

Sorry, I wasn’t thinking.  These are options provided by opt, not by LLVM libraries.  Clang has made an explicit design decision not to expose the optimisation pipeline details to consumers (because it’s far from stable and there is no desire to maintain backwards compatibility for things that are implementation details and because it’s very hard for someone to use correctly).  Your best bet if you *really* want this is probably to wrap clang in a shell script that does something along the lines of clang -c -emit-llvm && opt -whatever | llc, with appropriate handling / replacing of the last -o argument to clang.

David



More information about the llvm-dev mailing list