Running a pass

Hi,

I assume that since each pass is in its own anonymous
namespace, we cannot directly create a new pass object;
looking at the code for 'opt' utility, it seems we need a
PassInfo object, using which we create a new pass object.
I tried the following code (which I wrote after looking at
the code for bugpoint), but the list of passes seems to be
empty:

// Create a list of all the registered passses
static cl::list<const PassInfo*, bool, PassNameParser>
PassList(cl::desc("Passes available:"), cl::ZeroOrMore);

mem2reg_pass = NULL;
for(It i = PassList.begin(); i != PassList.end(); i++) {
   std::cout << (*i)->getPassName() << endl;
   if(string("mem2reg") == (*i)->getPassName()) {
      mem2reg_pass = *i;
      break;
    }
}
assert(mem2reg_pass);
assert(mem2reg_pass->getNormalCtor());

The first assert always fails, and none of the pass names
appear on the output. So how can I obtain a pointer to the
pass I want to run, so that I can use the pass manager?

I'm not sure what is causing this problem, if main is not even executing
yet, then it shouldn't matter what your main does. :slight_smile:

This is apparently caused by the linking the 'ipo' library.
I removed that from my Makefile, and it does not happen any
more.

Thanks,
Rahul

I assume that since each pass is in its own anonymous
namespace, we cannot directly create a new pass object;
looking at the code for 'opt' utility, it seems we need a
PassInfo object, using which we create a new pass object.
I tried the following code (which I wrote after looking at
the code for bugpoint), but the list of passes seems to be
empty:

Being in an anonymous namespace just means you cannot invoke the methods
of the pass directly. Given a pointer to an object of that pass, however,
you can invoke virtual methods and otherwise use the pass.

To get a pointer to an instance of the mem2reg pass, just call
createPromoteMemoryToRegister(), declared in
include/llvm/Transforms/Scalar.h

>I'm not sure what is causing this problem, if main is not even executing
>yet, then it shouldn't matter what your main does. :slight_smile:

This is apparently caused by the linking the 'ipo' library.
I removed that from my Makefile, and it does not happen any
more.

I'm not sure what could possibly cause this. If you send me details
(off-list) I would be happy to look into it.

-Chris