writing a pass

Hi,

I'm having a problem with opt. According to the "Writing an LLVM Pass"
tutorial, all I have to do to get the Hello pass to work is:

  cd ${LLVM_HOME}/llvm/lib/Transforms/Hello
  gmake
  cd $MYTEST
  opt -load ${OBJ_ROOT}/lib/Release/libhello.so -hello < something.bc > /dev/null

First (just as a friendly reminder), someone may want to go back and
double check a bunch of the command lines given in these tutorials. It
looks like the opt tool, for instance, doesn't take its input from STDIN.
Also, I don't have a Debug subdirectory like the tutorial said I would - I
have Release instead.

That aside, although opt doesn't report any errors when loading
libhello.so, it also doesn't let me do anything with it:

  Unknown command line argument '-hello'. Try: opt --help'

I tried loading the library and specifying '-help' and the '-hello'
transformation was not listed. Any idea what I'm doing wrong?

Thanks,
- Nick

I'm having a problem with opt. According to the "Writing an LLVM Pass"
tutorial, all I have to do to get the Hello pass to work is:

  cd ${LLVM_HOME}/llvm/lib/Transforms/Hello
  gmake
  cd $MYTEST
  opt -load ${OBJ_ROOT}/lib/Release/libhello.so -hello < something.bc > /dev/null

That's pretty much it, assuming a couple of prerequisites, see below.

First (just as a friendly reminder), someone may want to go back and
double check a bunch of the command lines given in these tutorials. It
looks like the opt tool, for instance, doesn't take its input from STDIN.

It always has, and still does (at least for me). In addition, it will
take the last command-line parameter as an input filename, if it's not a
command-line switch. If you have a specific problem, please give me a
specific command-line that does not work as it claims to in the
tutorial, and we'll look into it.

Also, I don't have a Debug subdirectory like the tutorial said I would - I
have Release instead.

1. What version of LLVM are you using (i.e., when did you get a tarball,
   or if you are using anonymous CVS, are you up to date)?
2. Did you run 'make' or 'make ENABLE_OPTIMIZED=1' or 'make
   ENABLE_PROFILING=1'?
3. If you are using a version of LLVM that is new enough to have a
   'configure' script in the top-level directory, how did you run
   'configure'? You may have specified './configure --enable-optimized'
   or the like, with the save effects as in #2.

That aside, although opt doesn't report any errors when loading
libhello.so, it also doesn't let me do anything with it:

  Unknown command line argument '-hello'. Try: opt --help'

I tried loading the library and specifying '-help' and the '-hello'
transformation was not listed. Any idea what I'm doing wrong?

I'm assuming that the file `hello.so' does in fact exist. Did you
register your optimization pass with OPT by using something along the
lines of

  RegisterOpt<Hello> X("hello", "Hello World Pass");

as is mentioned in the `Basic code required' section?

I can't think of much else right now, if none of this helps, please
answer my questions as to the `freshness' of your LLVM tree, and send me
your hello pass for inspection.

> Also, I don't have a Debug subdirectory like the tutorial said I would - I
> have Release instead.

1. What version of LLVM are you using (i.e., when did you get a tarball,
   or if you are using anonymous CVS, are you up to date)?

I use CVS and I updated a couple days ago.

3. If you are using a version of LLVM that is new enough to have a
   'configure' script in the top-level directory, how did you run
   'configure'? You may have specified './configure --enable-optimized'
   or the like, with the save effects as in #2.

Yes, that's it. I should probably disable optimized builds for now
anyway.

I'm assuming that the file `hello.so' does in fact exist.

Not that I saw. 'libhello.so' does exist though. It's a link to
'libhello.so.0.0.0' in the same directory. Also, 'libhello.so.0' in the
same directory is a link to 'libhello.so.0.0.0'. There is also
'libhello.a', 'libhello.la', and 'hello.o'.

Did you register your optimization pass with OPT by using something
along the lines of

  RegisterOpt<Hello> X("hello", "Hello World Pass");

as is mentioned in the `Basic code required' section?

I used lib/Transforms/Hello/Hello.cpp provided in the CVS tree. It has
exactly the line of code you require. I also used the Makefile there.

If you think of anything else, please let me know...
- Nick

Dear Nicholas,

  I've compiled both optimized and debug builds on Linux, and both seem to work as described in the documentation.

  Are you compiling on Sparc or x86? I'd like to know in order to try to reproduce your error.

  Also, can you send us a copy of the bytecode file that you are using as input to opt?

  One thing that I found odd is that opt cannot use a library name unless it is an absolute or relative path. For example,

  opt -load ./libhello.so

  works, but

  opt -load libhello.so

  does not (although it seems to give an error message instead of failing quietly).

  If you could send us the above information, that'd be great.

  Thanks.

-- John T.

Dear Nicholas,

You can call me Nick. :slight_smile:

  Are you compiling on Sparc or x86? I'd like to know in order to try to
reproduce your error.

Sparc. (Solaris 5.8).

  Also, can you send us a copy of the bytecode file that you are using as
input to opt?

Sure - I don't think it's of any use though - I don't even get a
description of the "Hello" transformation in the text generated by

  opt -load ... -help

  One thing that I found odd is that opt cannot use a library name unless
it is an absolute or relative path. For example,

  opt -load ./libhello.so

  works, but

  opt -load libhello.so

  does not (although it seems to give an error message instead of failing
quietly).

I've tried both absolute and relative paths, and they fail quietly. When
I mistyped the path, opt gave an error saying the load failed because the
library file could not be found.

Thanks,
- Nick

dumb.bc (1.04 KB)