[llvm-dev] Confused on how to do a machinefunction pass

fateme Hoseini via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 3 12:47:09 PST 2015


Hi everyone,
I am a LLVM newbie. I need to write a machinefunction pass for my project.
This should be an analyzer of the machine code to do some profiling. I have
written a couple of function passes for front end, but it seems they are
completely different. I searched through forum and llvm documents, but
couldn't find anything useful or questions were unanswered. Can anyone
reference me to any material on how to do that or help me with my roblem.

I have created a folder in: lib/Transform and put my pass in it.
I am writing a simple pass like this:

using namespace llvm;

namespace {
    struct analyzer : public MachineFunctionPass {
static char ID;
analyzer() : MachineFunctionPass(ID) {}
virtual bool runOnMachineFunction(MachineFunction &MF) {
errs() << "hello " ;
return false;
}
  };
}
char analyzer::ID = 0;
static RegisterPass<analyzer> X("analyzer", "WAW analyzer");

I make it successfully. But when I load it for my test code I get this
error:

Pass 'WAW analyzer' is not initialized.
Verify if there is a pass dependency cycle.
Required Passes:
opt: /llvm/llvm-3.7/lib/IR/LegacyPassManager.cpp:635: void
llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI &&
"Expected required passes to be initialized"' failed.
.....

I don't know how to solve it? Do we have to run machinefunction passes with
OPT command? Is this correct to put machinefunction pass in an external
folder or do we have to change some llvm built-in files?

Regards,
Fami
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151103/b09ef7ef/attachment.html>


More information about the llvm-dev mailing list