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
On Mar 8, 2010, at 11:45 AM, Manousaridis Aggelos wrote:> > Is it even possible to have a MachineFunctionPass externally, or not?Probably not. MachineFunctionPasses aren't regular Passes which opt can meaningfully run, in its current form.> The documentation implies that is should be possible.Which documentation? Dan
On Tue, Mar 09, 2010 at 12:11:04PM -0800, Dan Gohman wrote:> > On Mar 8, 2010, at 11:45 AM, Manousaridis Aggelos wrote: > > > > Is it even possible to have a MachineFunctionPass externally, or not? > > Probably not. MachineFunctionPasses aren't regular Passes which > opt can meaningfully run, in its current form. > > > The documentation implies that is should be possible. > > Which documentation?In "Writing an LLVM Pass" it does mention MachineFunctionPass, and how it has the same behaviour as FunctionPass (no adding of blocks or functions, only new instructions etc). Since this page refers to "writing your own pass", it could be implied that it is possible. Anyway, thanks for the response. -- amanous