Ya Xiao
Ya Xiao

Reputation: 941

How to implement a backward dataflow analysis pass in LLVM? Do we need to implement the worklist algorithm by ourselves?

I want to do backward dataflow analysis using LLVM. Currently, I just create a new Pass class:

class BwdfPass: public llvm::ModulePass{}

Then, implement the runOnModule method and runOnFunction method. However, I just saw some examples like:

void BwdfPass::runOnFunction(Function &function){
    for(BasicBlock & bb: function){
        for(Instruction &inst:bb){
            //do some action
        }
    }
}

I once did dataflow analysis with soot. Soot provide an interface BackwardFlowAnalysis, and I only need to implement the transfer function in the method doAnalysis(). The worklist algorithm which achieve fix-point analysis is provided by its interface. However, in LLVM, is there any similar mechanism? Does it mean I need to implement the worklist algorithm and go through all the Instructions in a backward order by by myself?

Upvotes: 1

Views: 749

Answers (1)

Eric
Eric

Reputation: 1393

I encourage you to have a look at our LLVM extension Phasar: https://phasar.org/

It provides functionality similar to Soot does for Java.

Upvotes: 0

Related Questions