[LLVMdev] write a simple MachineFunctionPass

Alexandru Ionut Diaconescu alexandruionutdiaconescu at gmail.com
Fri Mar 15 05:41:40 PDT 2013


I found that : "Code generator passes are registered and initialized
specially by TargetMachine::addPassesToEmitFile and similar routines, so
they cannot generally be run from the *opt* or *bugpoint* commands."...So
how I can run a MachineFunctionPass? In the end, I just want to apply a DFS
on a CFG of a function. And I need oriented edges and wanted to use
MachineBasicBlock::const_succ_iterator. It is there a way to get the CFG
with oriented edges by using a FunctionPass?

Thank you !

On Fri, Mar 15, 2013 at 1:30 PM, Alexandru Ionut Diaconescu <
alexandruionutdiaconescu at gmail.com> wrote:

> Hello everyone,
>
> I have written several complex passes till now, but I cannot write a
> MachineFunctionPass pass. It just gives me segfault. Hence I reduced the
> pass to the following form :
>
>
> using namespace llvm;
>
> namespace {
>   class CFGexplorator : public MachineFunctionPass {
>   public:
>     static char ID; // Pass identification, replacement for typeid
>     CFGexplorator() : MachineFunctionPass(ID) {
>       //initializeMemDepPrinterPass(*PassRegistry::getPassRegistry());
>     }
>
>   private:
>     virtual bool runOnMachineFunction(MachineFunction &MF);
>
>     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>       MachineFunctionPass::getAnalysisUsage(AU);
>     }
>   };
> } // end anonymous namespace
>
> char CFGexplorator::ID = 0;
> static RegisterPass<CFGexplorator> Y("mycfg", "mycfg", false, false);
>
> bool CFGexplorator::runOnMachineFunction(MachineFunction &MF) {
> return false;
> }
>
>
>
> I get the error :
> Pass 'mycfg' is not initialized.
> Verify if there is a pass dependency cycle.
> Required Passes:
> opt: PassManager.cpp:638: void
> llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI &&
> "Expected required passes to be initialized"' failed.
>
>
> So I have to initialize the pass. But in my all other passes I did not any
> initialization and I don't want to use INITIALIZE_PASS since I have to
> recompile the llvm file that is keeping the pass registration... Is there a
> way to keep using static RegisterPass for a MachineFunctionPass ? I mention
> that if I change to FunctionPass, I have no problems and that is weird..
>
> Thank you for any advice !
>
>
>
>


-- 
Best regards,
Alexandru Ionut Diaconescu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130315/6af0d924/attachment.html>


More information about the llvm-dev mailing list