Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use an exisiting function pass from my LLVM - pass?

I have been using LLVM and I was confused how to use a different already present pass from my own pass ? Precisely my program needs Dominance Frontier Calculation for any given instruction. LLVM already has the Dominance function Class that is implemented as a function pass. How can i invoke it/make use of it in my Module Pass ?

like image 250
Sharad Avatar asked Feb 17 '12 18:02

Sharad


People also ask

What are passes in LLVM?

All LLVM passes are subclasses of the Pass class, which implement functionality by overriding virtual methods inherited from Pass .

What is a pass Manager LLVM?

What is a pass manager? A pass manager schedules transformation passes and analyses to be run on IR in a specific order. Passes can run on an entire module, a single function, or something more abstract such as a strongly connected component (SCC) in a call graph or a loop inside of a function.

What is mem2reg?

-mem2reg : Promote Memory to Register This file promotes memory references to be register references. It promotes alloca instructions which only have loads and stores as uses.


1 Answers

WARNING: I have no real experience and answer may be incorrect or outdated. (it is based largely on outdated LLVM sources: version 1.3.)

Add an include:

#include "llvm/Analysis/DominanceFrontier.h"

If your pass if Function Pass, add to your class the method (if it is not implemented):

virtual void getAnalysisUsage(AnalysisUsage &AU) const { }

And put this into it:

 AU.addRequired<DominanceFrontier>();

Then, in your class runOnFunction method:

 DominanceFrontier *DF = &getAnalysis<DominanceFrontier>();

After this you can use:

    BasicBlock *BB = /* some BB */;
    DominanceFrontier::iterator DFI = DF->find(BB);
like image 154
osgx Avatar answered Sep 23 '22 01:09

osgx