llvm-analysis-0.1.0: A Haskell library for analyzing LLVM bitcode

Safe HaskellNone

LLVM.Analysis.CFG

Contents

Description

This module defines control flow graphs over the LLVM IR.

Synopsis

Types

data CFG Source

The control flow graph representation

Constructors

CFG 

Fields

cfgGraph :: CFGType
 
cfgEntryValue :: Instruction
 
cfgEntryNode :: NodeType
 
cfgExitValue :: Instruction
 
cfgExitNode :: NodeType
 
cfgFunction :: Function
 

data RCFG Source

The control flow graph with the edges reversed

Constructors

RCFG 

Fields

rcfgGraph :: CFGType
 
rcfgEntryValue :: Instruction
 
rcfgEntryNode :: NodeType
 
rcfgExitValue :: Instruction
 
rcfgExitNode :: NodeType
 
rcfgFunction :: Function
 

Instances

HasFunction RCFG 
HasPostdomTree RCFG 

data CFGEdge Source

The types of edges that appear in the CFG

Constructors

UnconditionalEdge

An unconditional jump from somewhere

DefaultEdge

A default jump due to a case statement

TrueEdge Value

True edge successor for the comparison contained in the value. This value was the argument to the branch instruction.

FalseEdge Value

False edge successor for the comparison contained in the value. This value was the argument to a branch instruction.

EqualityEdge Value Value

A case equality edge (the case value v1 was equal to val v2)

IndirectEdge Value

Jump from the given indirect branch value

NormalEdge Instruction

The normal return from an invoke

UnwindEdge Instruction

Exceptional return from an invoke

Instances

type CFGType = DenseDigraph Instruction CFGEdgeSource

class HasCFG a whereSource

Types that have control flow graphs.

Methods

getCFG :: a -> CFGSource

Instances

HasCFG Function 
HasCFG CFG 
HasCFG CDG 

Constructors

mkCFG :: Function -> CFGSource

Build a control flow graph for the given function. Each instruction in the function body is a node in the graph. Branching instructions induce edges. This form of the CFG is fine-grained in that each instruction has its own CFG node.

The other function, mkCompactCFG, has a basic-block-granularity CFG that can be easier to visualize.

Accessors

basicBlockPredecessors :: CFG -> BasicBlock -> [BasicBlock]Source

Get all of the predecessor blocks for basic block bb

 basicBlockPredecessors cfg bb

basicBlockSuccessors :: CFG -> BasicBlock -> [BasicBlock]Source

Get all of the successor blocks for basic block bb

 basicBlockSuccessors cfg bb

basicBlockLabeledPredecessors :: CFG -> BasicBlock -> [(BasicBlock, CFGEdge)]Source

basicBlockLabeledSuccessors :: CFG -> BasicBlock -> [(BasicBlock, CFGEdge)]Source

instructionReachable :: CFG -> Instruction -> BoolSource

An instruction is reachable if its basic block has predecessors *OR* (if there are no predecessors) it is the first basic block.

Visualization

cfgGraphvizRepr :: CFG -> DotGraph NodeTypeSource