How to pass command-line options to LLVM Compiler API?

Hi,

I’m keenly interested in this command-line option -bpf-expand-memcpy-in-order.

The reason I want to use it is in order to emit longer memset/memcpy in bpftrace.

But the example code described in that patch enables the flag by passing a command-line option to llc:

llc < %s -march=bpfel -bpf-expand-memcpy-in-order

Whereas in bpftrace we use C++ to create an LLVM Module via the Compiler API, and emit IR programmatically.

Given that we don’t invoke llc, but rather invoke LLVM via its C++ APIs: is there any way for us to pass command-line options such as -bpf-expand-memcpy-in-order?

I note that the LLVM Command Line docs mention a difference between external/internal storage for command-line options. Could it be that there’s no external-facing way to set this option?

Thanks for any assistance you can give!

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Unfortunately this option is not exposed programmatically and can only be set by parsing command line options. In general options that aren’t exposes in APIs are rather used for debugging/tuning the compiler, so if there is a use for this here a patch to expose this may be welcome.

thanks for the quick response! yeah, it certainly looks that way… hm, do you know what would be the idiomatic way to expose this via the compiler API? is there an example where a backend has done this before?

TargetOptions or MCTargetOptions sound potentially-relevant… I note that MCTargetOptions has a property ArrayRef<const char *> CommandLineArgs — I wonder whether that’s related at all?