./bin/opt: unknown pass name 'hello' (LLVM15, 16)

Hi,
I’m trying to write a custom pass for LLVM 15 or later version.
Before doing that, I tried to run Hello example. But I got the problem like this.

$ ./bin/opt --load ./lib/LLVMHello.so -passes=hello < /tmp/a.ll > /tmp/b
./bin/opt: unknown pass name ‘hello’

When I do “./bin/opt --load ./lib/LLVMHello.so --help”, it shows that “hello” and “hello2” are valid passes.

However, the following works well regardless of adding “–load ./lib/LLVMHello.so”:
$ ./bin/opt -passes=helloworld < /tmp/a.ll > /tmp/b
foo
bar

I tried the examples for LLVM15.0, 15.7, and 16.0. But got all the same errors. I believe I’m making some stupid mistake. Could anyone help me?

Thanks,
David

1 Like

Using --passes=xyz means that xyz is a “new” pass. The hello pass (and the hello2 pass) built with LLVM is a legacy pass; to invoke it, you’d run opt -hello (or -opt -hello2). However, the helloworld pass is a “new” pass, so --passes=helloworld works as intended in this case.

The reason you don’t need to use -load ./lib/LLVMHello.so is because all three of those passes are already statically linked into LLVM. This is the default behavior when a pass is written in LLVM’s source tree.

1 Like