[LLVMdev] Access to command line from within a pass

Scott Pakin pakin at lanl.gov
Mon May 13 08:46:24 PDT 2013

On 05/11/2013 10:45 AM, Duncan Sands wrote:
> command line options in dynamically loaded passes work exactly the same as
> command line options everywhere else in LLVM AFAIK.  In your example, Foo should
> be set to 123, eg this test should pass:
>    if (Foo == 123) { ... }

Thanks for the response, but apparently I didn't explain my question
well enough.  My pass already processes command-line options just fine
(using "if (Foo == 123) { ... }" sort of lines).  What I additionally
want to do is embed a constant string into the bitcode containing all
of the "-option=value" terms provided to my pass.  For example, if a
user runs "opt -load mypass.so -foo=123 -std-compile-opts -baz", I'd
want to embed something like

     @myoptions.data = private constant [14 x i8] c"-foo=123 -baz\00", align 8
     @myoptions = linkonce_odr constant i8* getelementptr inbounds ([14 x i8]* @myoptions.data, i64 0, i64 0)

in the bitcode.  Yes, I can do this with

     if (Foo != default_Foo)
       mystring += "-foo=" + Foo;

but I have a lot of options and don't want to run the risk of adding a
new option but forgetting to include it in the string accumulation;
I'd like something more automatic.

For the time being, I'm parsing /proc/self/cmdline, but if there's a
more portable or more convenient mechanism, I'd love to find out about

-- Scott

More information about the llvm-dev mailing list