Is it possible for a pass to get access to the command line options passed to it? That is, if I use the CommandLine library to define cl::opt<int> Foo("foo", ...); cl::opt<int> Bar("bar", ...); cl::opt<bool> Baz("baz", ...); and the user runs "opt -load mypass.so -foo=123 -std-compile-opts -baz", can I somehow get a string containing "-foo=123 -baz"? I suppose as a last resort I can process /proc/self/cmdline, but if there's a cleaner approach, I'd prefer that. Thanks, -- Scott
Hi Scott, On 11/05/13 00:09, Scott Pakin wrote:> Is it possible for a pass to get access to the command line options > passed to it? That is, if I use the CommandLine library to define > > cl::opt<int> Foo("foo", ...); > cl::opt<int> Bar("bar", ...); > cl::opt<bool> Baz("baz", ...); > > and the user runs "opt -load mypass.so -foo=123 -std-compile-opts -baz", > can I somehow get a string containing "-foo=123 -baz"? > > I suppose as a last resort I can process /proc/self/cmdline, but if > there's a cleaner approach, I'd prefer that.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) { ... } Ciao, Duncan.
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 it. Thanks, -- Scott
Apparently Analagous Threads
- [LLVMdev] Access to command line from within a pass
- [LLVMdev] Another missed optimization opportunity?
- [RFC] [DebugInfo] Using DW_OP_entry_value within LLVM IR
- Reading in tab (and space) delimited data within a script XXXX
- [LLVMdev] [RFC] Internal command line options should not be statically initialized.