[LLVMdev] Machine Function pass

Manousaridis Aggelos amanous at closure.softlab.ece.ntua.gr
Mon Mar 8 11:45:21 PST 2010


I am trying to write a MachineFunction pass and build it as a loadable module.
I want the pass to run after prolog/epilog emmiter.  So far, I have been using
MachineFunctionPass, but by inserting it to lib/Codegen and hacking the
LLVMTargetMachine file, and Pass.h files.

I have created a directory "lib/Transforms/MyPass", and inside I have
the code of the pass (which is just a placeholder for now):

-----------------------
#define DEBUG_TYPE "mypass"
#include "llvm/Pass.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/Function.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;

namespace {
  struct MyPass : public MachineFunctionPass {
    static char ID; // Pass identification, replacement for typeid
    MyPass() : MachineFunctionPass(&ID) {}

    virtual bool runOnMachineFunction(MachineFunction &MF) {
       errs() << MF.getFunction()->getName().data() << ":\n";
      return false;
    }
  };
}

char MyPass::ID = 0;
static RegisterPass<MyPass> X("mypass", "MyPass Pass");
-----------------------

And a makefile:

-----------------------
LEVEL = ../../..
LIBRARYNAME = LLVMMyPass
LOADABLE_MODULE = 1
USEDLIBS =

include $(LEVEL)/Makefile.common
-----------------------

I managed to build the pass, but when I use it, i get:

-----------------------
opt -load ~/.../libLLVMMyPass.so 
Error opening 'libLLVMMyPass.so': libLLVMMyPass.so: undefined symbol: _ZNK4llvm19MachineFunctionPass16getAnalysisUsageERNS_13AnalysisUsageE
  -load request ignored.
-----------------------

I tried replacing USEDLIBS with:

-----------------------
USEDLIBS = LLVMCodeGen.a LLVMTarget.a
-----------------------

And now I am getting:

-----------------------
opt: Pass.cpp:234: void<unnamed>::PassRegistrar::RegisterPass(const llvm::PassInfo&): Assertion `Inserted && "Pass registered multiple times!"' failed.
....
-----------------------

Is it even possible to have a MachineFunctionPass externally, or not?
The documentation implies that is should be possible. I have failed in both the
2.6 version (with different error messages) and the latest trunk.

--
Angelos Manousarides



More information about the llvm-dev mailing list