Running specific passes

Hello,
in the implementation of some analysis, I need to change the program and then
invoke Mem2Reg pass. That pass, in turn, requires other analysis, so I must
use PassManager. Here's the code I ended up with:

        bool runOnFunction(llvm::Function& m)
        {
            visit(m);

            ExistingModuleProvider mp(m.getParent());
            FunctionPassManager pm(&mp);
            .....
            //m.add(createPromoteMemoryToRegister());
            pm.run(m);

There are several problems, though:

1. This looks inefficient -- the analyses necessary for Mem2Reg will be run
again, even if they are already run by the global pass manager. But how to
ask the global pass manager to run a pass immediately?

2. This does not work. ExistingModuleProvider takes ownership of m.getParent()
and deletes it at the end.

3. This does not work. The Mem2Reg pass requires TargetData which does not
seem to be available. The only reason why it requires it, is to pass to
lib/Transforms/Utils/PromoteMemoryToRegister.cpp:isAllocaPromotable, which
does not use that data at all.

Could anybody suggest a better solution?

- Volodya

in the implementation of some analysis, I need to change the program and then
invoke Mem2Reg pass. That pass, in turn, requires other analysis, so I must

Usually you want to do this at a higher level, why not just use 'opt
-yourpass -mem2reg'?

Alternatively, if you don't want to do that, you can build mem2reg into
your pass if it works better. To do this, your pass needs to
'addRequired' DominatorTree and DominatorFrontier, then use the
interfaces exposed through
include/llvm/Transforms/Utils/PromoteMemToReg.h.

-Chris

use PassManager. Here's the code I ended up with:

        bool runOnFunction(llvm::Function& m)
        {
            visit(m);

            ExistingModuleProvider mp(m.getParent());
            FunctionPassManager pm(&mp);
            .....
            //m.add(createPromoteMemoryToRegister());
            pm.run(m);

There are several problems, though:

1. This looks inefficient -- the analyses necessary for Mem2Reg will be run
again, even if they are already run by the global pass manager. But how to
ask the global pass manager to run a pass immediately?

2. This does not work. ExistingModuleProvider takes ownership of m.getParent()
and deletes it at the end.

3. This does not work. The Mem2Reg pass requires TargetData which does not
seem to be available. The only reason why it requires it, is to pass to
lib/Transforms/Utils/PromoteMemoryToRegister.cpp:isAllocaPromotable, which
does not use that data at all.

Could anybody suggest a better solution?

- Volodya

_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev

-Chris

> in the implementation of some analysis, I need to change the program and
> then invoke Mem2Reg pass. That pass, in turn, requires other analysis, so
> I must

Usually you want to do this at a higher level, why not just use 'opt
-yourpass -mem2reg'?

Because my pass must first modify the code, then run mem2reg pass and then do
some more work. There's absolutely no way it could work without mem2reg pass.
(That's the value analysis path I talked about earlier).

Alternatively, if you don't want to do that, you can build mem2reg into
your pass if it works better. To do this, your pass needs to
'addRequired' DominatorTree and DominatorFrontier, then use the
interfaces exposed through
include/llvm/Transforms/Utils/PromoteMemToReg.h.

This still leaves the question of TargetData parameter -- which is not used by
the PromoteMemToReg function, AFAICT. Passing *(TargetData*)0 is dirty.

- Volodya

> > in the implementation of some analysis, I need to change the program and
> > then invoke Mem2Reg pass. That pass, in turn, requires other analysis, so
> > I must
>
> Usually you want to do this at a higher level, why not just use 'opt
> -yourpass -mem2reg'?

Because my pass must first modify the code, then run mem2reg pass and then do
some more work. There's absolutely no way it could work without mem2reg pass.
(That's the value analysis path I talked about earlier).

ok

> Alternatively, if you don't want to do that, you can build mem2reg into
> your pass if it works better. To do this, your pass needs to
> 'addRequired' DominatorTree and DominatorFrontier, then use the
> interfaces exposed through
> include/llvm/Transforms/Utils/PromoteMemToReg.h.

This still leaves the question of TargetData parameter -- which is not used by
the PromoteMemToReg function, AFAICT. Passing *(TargetData*)0 is dirty.

Just addRequired<TargetData>(), and pass in getAnalysis<TargetData>() as
appropriate.

-Chris

This did not work for me -- it seems the "analyze" program does not provide
any TargetData. Probably, analysis pass which modifies program is not
typical, but then it's surely not transformation pass, either.

- Volodya

I have trouble using the llvm tools.Some of the errors are :

$ llvm-dis prog.bc
$ llvm-dis: Invalid Top Level Block Length! Type:1, Size:456 (Vers=0, Pos=12)

Hrm, analyze.cpp:143 adds TargetData to the pass manager. Can you give me
more information about how you are running your pass?

-Chris

I have trouble using the llvm tools.Some of the errors are :

$ llvm-dis prog.bc
$ llvm-dis: Invalid Top Level Block Length! Type:1, Size:456 (Vers=0, Pos=12)

Can you explain how you generated this bytecode file? It looks corrupted
or something. Also, can you send the actual bytecode file itself?

Thanks!

-Chris

-------------------------------------

$ extract -o=outprog prog.bc
$ extract: bytecode didn't read correctly.

Where am I doing wrong ?I wish to get human readable form of my bytecode file.The tool giving similar error.

Thanks

Tanu

---------------------------------
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.

-Chris

Thanks for replying,

Yes, I think too that the bytecode file is corrupted.
This is the file :

Could you send the bytecode file as an attachment, please?

Thanks,

Reid.

Okay, Tanu sent the bytecode file and it works fine with llvm-bcanalyzer
and llvm-dis. The output from those tools are attached.

So, I think the real question is: "what llvm-dis where you running?".

Reid.

prog.ll (1.27 KB)

prog.bca (2.65 KB)

Thanks for trying it out and replying.

This is weird but I tried again and again and the tools are working fine now.
I was working in school account, maybe some change in permissions worked.
Otherwise I am confused.

Thanks anyways
Tanu