Assertion failed in Pass.cpp

Hi all,

I am trying to write a pass for the llc tool. I register this pass with the RegisterLLC template. However, when I try to run llc and load up the pass, I get a failed assertion:

$ /storage/anshuman/llvmCVS/llvm/tools/Debug/llc -load=./libTest.so --help
...
llc: Pass.cpp:327: void llvm::RegisterPassBase::unregisterPass(llvm::PassInfo*): Assertion `I != PassInfoMap->end() && "Pass registered but not in map!"' failed.

Any ideas why I'm getting this? I've attached the pass code below.

(I'm using the cvs version of the LLVM code.)

Thanks
-Anshu

--- Begin pass code ---
#include <iostream>
#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/PassSupport.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/Passes.h"

namespace llvm {

   class testfn : public MachineFunctionPass {

   public:

     virtual bool runOnMachineFunction(MachineFunction &F) {
       std::cout << "Reached a function" << std::endl;
       return false;
     }

   };

   RegisterLLC<testfn> X("testfn", "testfn");

}

I am trying to write a pass for the llc tool. I register this pass
with the RegisterLLC template. However, when I try to run llc and load
up the pass, I get a failed assertion:

Hrm, interesting. It's not actually legal to load machine code passes
into LLC yet. :slight_smile:

The problem is that there currently isn't enough information to specify
_where_ in the code generator to insert an arbitrary machine code pass
(before register allocation? after it? before instruction selection?,
etc).

To do this you have to edit one of the target machines
addPassesToEmitAssembly/addPassesToJITCompile method to include your pass.
In the future, given a few PassManager improvements that I am going to be
working on in the not-too-distant future, hopefully this can be
implemented.

Anyway, for this reason, the -load option shouldn't even even exist in the
LLC tool. It's there currently only for historical reasons, but this
patch removes it:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20031215/010215.html

   RegisterLLC<testfn> X("testfn", "testfn");

Getting back to your assertion failure. I'm not sure that RegisterLLC
actually works, even if your code was compiled into the LLC executable.
I'm inclined to think not, as there are currently no clients of it.

Basically, if you want to work on the code generator, this is what you
should do: Add your pass to the addPassesToEmitAssembly method for the
target of your choice, and in your pass implement the getPassName() method
to provide a nice user-friendly name. You shouldn't have to register LLC
passes, because they can't be specified on the command line.

Because of this, I'll just go ahead and remove the RegisterLLC template to
avoid future problems...

Sorry for the confusion,

-Chris