Pass is not automatically registered

I am not sure if my problem is similar to:
  http://lists.cs.uiuc.edu/pipermail/llvmdev/2003-December/000715.html

It seems that the constructor of the static global pass object isn't called:

lib/CodeGen/DependenceAnalyzer.cpp:

static RegisterAnalysis<DependenceAnalyzer> X("depana", "Dependence Analysis");

I traced into struct RegisterAnalysis ctor, but my pass doesn't
appear. I put it in an anonymous namespace, it doesn't work too.

The class definitions:

class DependenceAnalyzer : public MachineFunctionPass {
  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
    AU.setPreservesAll();
    AU.addRequired<LiveIntervals>();
    AU.addRequired<LiveVariables>();
    MachineFunctionPass::getAnalysisUsage(AU);
  }

class RegAllocMultibank : public MachineFunctionPass {
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<LiveIntervals>();
      AU.addRequired<DependenceAnalyzer>();
      MachineFunctionPass::getAnalysisUsage(AU);
    }
};

If you are using Visual Studio, the linker will throw away object files which have no external references to them -- even if the object file contains static objects with constructors which might (or in the case of LLVM passes, definitly) have side effects. The solution is to use the linker option to force symbol references to a symbol in the object file so it doesn't throw it away. This problem is the motivation for having the _X86TargetMachineModule symbol in LLVM.

m.

Tzu-Chien Chiu wrote:

Tzu-Chien,

The static construction of the RegisterAnalysis objects occurs very early in the process' life (before main is entered). If you're not using VC++ (as Morten mentioned), then you should be able to see the static object constructed very early in the debugging session.

Reid.

Tzu-Chien Chiu wrote: