Static Value-Flow Analysis
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
SVF::SVFLoopAndDomInfo Class Reference

#include <SVFValue.h>

Public Types

typedef Set< const SVFBasicBlock * > BBSet
 
typedef std::vector< const SVFBasicBlock * > BBList
 
typedef BBList LoopBBs
 

Public Member Functions

 SVFLoopAndDomInfo ()
 
virtual ~SVFLoopAndDomInfo ()
 
const Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap () const
 
Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap ()
 
bool hasLoopInfo (const SVFBasicBlock *bb) const
 
const LoopBBsgetLoopInfo (const SVFBasicBlock *bb) const
 
const SVFBasicBlockgetLoopHeader (const LoopBBs &lp) const
 
bool loopContainsBB (const LoopBBs &lp, const SVFBasicBlock *bb) const
 
void addToBB2LoopMap (const SVFBasicBlock *bb, const SVFBasicBlock *loopBB)
 
const Map< const SVFBasicBlock *, BBSet > & getPostDomTreeMap () const
 
Map< const SVFBasicBlock *, BBSet > & getPostDomTreeMap ()
 
const Map< const SVFBasicBlock *, u32_t > & getBBPDomLevel () const
 
Map< const SVFBasicBlock *, u32_t > & getBBPDomLevel ()
 
const Map< const SVFBasicBlock *, const SVFBasicBlock * > & getBB2PIdom () const
 
Map< const SVFBasicBlock *, const SVFBasicBlock * > & getBB2PIdom ()
 
Map< const SVFBasicBlock *, BBSet > & getDomTreeMap ()
 
const Map< const SVFBasicBlock *, BBSet > & getDomTreeMap () const
 
bool isUnreachable (const SVFBasicBlock *bb) const
 
const BBListgetReachableBBs () const
 
void setReachableBBs (BBList &bbs)
 
void getExitBlocksOfLoop (const SVFBasicBlock *bb, BBList &exitbbs) const
 
bool isLoopHeader (const SVFBasicBlock *bb) const
 
bool dominate (const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
 
bool postDominate (const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
 
const SVFBasicBlockfindNearestCommonPDominator (const SVFBasicBlock *A, const SVFBasicBlock *B) const
 find nearest common post dominator of two basic blocks More...
 

Private Attributes

BBList reachableBBs
 reachable BasicBlocks from the function entry. More...
 
Map< const SVFBasicBlock *, BBSetdtBBsMap
 map a BasicBlock to BasicBlocks it Dominates More...
 
Map< const SVFBasicBlock *, BBSetpdtBBsMap
 map a BasicBlock to BasicBlocks it PostDominates More...
 
Map< const SVFBasicBlock *, BBSetdfBBsMap
 map a BasicBlock to its Dominate Frontier BasicBlocks More...
 
Map< const SVFBasicBlock *, LoopBBsbb2LoopMap
 map a BasicBlock (if it is in a loop) to all the BasicBlocks in this loop More...
 
Map< const SVFBasicBlock *, u32_tbb2PdomLevel
 map a BasicBlock to its level in pdom tree, used in findNearestCommonPDominator More...
 
Map< const SVFBasicBlock *, const SVFBasicBlock * > bb2PIdom
 map a BasicBlock to its immediate dominator in pdom tree, used in findNearestCommonPDominator More...
 

Friends

class SVFIRWriter
 
class SVFIRReader
 

Detailed Description

Definition at line 50 of file SVFValue.h.

Member Typedef Documentation

◆ BBList

typedef std::vector<const SVFBasicBlock*> SVF::SVFLoopAndDomInfo::BBList

Definition at line 56 of file SVFValue.h.

◆ BBSet

Definition at line 55 of file SVFValue.h.

◆ LoopBBs

Definition at line 57 of file SVFValue.h.

Constructor & Destructor Documentation

◆ SVFLoopAndDomInfo()

SVF::SVFLoopAndDomInfo::SVFLoopAndDomInfo ( )
inline

Definition at line 69 of file SVFValue.h.

70  {
71  }

◆ ~SVFLoopAndDomInfo()

virtual SVF::SVFLoopAndDomInfo::~SVFLoopAndDomInfo ( )
inlinevirtual

Definition at line 73 of file SVFValue.h.

73 {}

Member Function Documentation

◆ addToBB2LoopMap()

void SVF::SVFLoopAndDomInfo::addToBB2LoopMap ( const SVFBasicBlock bb,
const SVFBasicBlock loopBB 
)
inline

Definition at line 103 of file SVFValue.h.

104  {
105  bb2LoopMap[bb].push_back(loopBB);
106  }
Map< const SVFBasicBlock *, LoopBBs > bb2LoopMap
map a BasicBlock (if it is in a loop) to all the BasicBlocks in this loop
Definition: SVFValue.h:64

◆ dominate()

bool SVFLoopAndDomInfo::dominate ( const SVFBasicBlock bbKey,
const SVFBasicBlock bbValue 
) const

Definition at line 54 of file SVFValue.cpp.

55 {
56  if (bbKey == bbValue)
57  return true;
58 
59  // An unreachable node is dominated by anything.
60  if (isUnreachable(bbValue))
61  {
62  return true;
63  }
64 
65  // And dominates nothing.
66  if (isUnreachable(bbKey))
67  {
68  return false;
69  }
70 
73  if (mapIter != dtBBsMap.end())
74  {
75  const BBSet & dtBBs = mapIter->second;
76  if (dtBBs.find(bbValue) != dtBBs.end())
77  {
78  return true;
79  }
80  }
81 
82  return false;
83 }
Map< const SVFBasicBlock *, BBSet > & getDomTreeMap()
Definition: SVFValue.h:139
Map< const SVFBasicBlock *, BBSet > dtBBsMap
map a BasicBlock to BasicBlocks it Dominates
Definition: SVFValue.h:61
bool isUnreachable(const SVFBasicBlock *bb) const
Definition: SVFValue.h:149
Set< const SVFBasicBlock * > BBSet
Definition: SVFValue.h:55
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101

◆ findNearestCommonPDominator()

const SVFBasicBlock * SVFLoopAndDomInfo::findNearestCommonPDominator ( const SVFBasicBlock A,
const SVFBasicBlock B 
) const

find nearest common post dominator of two basic blocks

Definition at line 115 of file SVFValue.cpp.

116 {
117  assert(A && B && "Pointers are not valid");
118  assert(A->getParent() == B->getParent() &&
119  "Two blocks are not in same function");
120 
121  // Use level information to go up the tree until the levels match. Then
122  // continue going up til we arrive at the same node.
123  while (A != B)
124  {
125  // no common PDominator
126  if(A == NULL) return NULL;
127  const auto lvA = getBBPDomLevel().find(A);
128  const auto lvB = getBBPDomLevel().find(B);
129  assert(lvA != getBBPDomLevel().end() && lvB != getBBPDomLevel().end());
130 
131  if (lvA->second < lvB->second) std::swap(A, B);
132 
133  const auto lvAIdom = getBB2PIdom().find(A);
134  assert(lvAIdom != getBB2PIdom().end());
135  A = lvAIdom->second;
136  }
137 
138  return A;
139 }
return NULL
Definition: cJSON.cpp:1173
const SVFFunction * getParent() const
Definition: SVFValue.h:584
const Map< const SVFBasicBlock *, u32_t > & getBBPDomLevel() const
Definition: SVFValue.h:118
const Map< const SVFBasicBlock *, const SVFBasicBlock * > & getBB2PIdom() const
Definition: SVFValue.h:128

◆ getBB2PIdom() [1/2]

Map<const SVFBasicBlock*,const SVFBasicBlock*>& SVF::SVFLoopAndDomInfo::getBB2PIdom ( )
inline

Definition at line 133 of file SVFValue.h.

134  {
135  return bb2PIdom;
136  }
Map< const SVFBasicBlock *, const SVFBasicBlock * > bb2PIdom
map a BasicBlock to its immediate dominator in pdom tree, used in findNearestCommonPDominator
Definition: SVFValue.h:66

◆ getBB2PIdom() [2/2]

const Map<const SVFBasicBlock*,const SVFBasicBlock*>& SVF::SVFLoopAndDomInfo::getBB2PIdom ( ) const
inline

Definition at line 128 of file SVFValue.h.

129  {
130  return bb2PIdom;
131  }

◆ getBBPDomLevel() [1/2]

Map<const SVFBasicBlock*,u32_t>& SVF::SVFLoopAndDomInfo::getBBPDomLevel ( )
inline

Definition at line 123 of file SVFValue.h.

124  {
125  return bb2PdomLevel;
126  }
Map< const SVFBasicBlock *, u32_t > bb2PdomLevel
map a BasicBlock to its level in pdom tree, used in findNearestCommonPDominator
Definition: SVFValue.h:65

◆ getBBPDomLevel() [2/2]

const Map<const SVFBasicBlock*,u32_t>& SVF::SVFLoopAndDomInfo::getBBPDomLevel ( ) const
inline

Definition at line 118 of file SVFValue.h.

119  {
120  return bb2PdomLevel;
121  }

◆ getDomFrontierMap() [1/2]

Map<const SVFBasicBlock*,BBSet>& SVF::SVFLoopAndDomInfo::getDomFrontierMap ( )
inline

Definition at line 80 of file SVFValue.h.

81  {
82  return dfBBsMap;
83  }
Map< const SVFBasicBlock *, BBSet > dfBBsMap
map a BasicBlock to its Dominate Frontier BasicBlocks
Definition: SVFValue.h:63

◆ getDomFrontierMap() [2/2]

const Map<const SVFBasicBlock*,BBSet>& SVF::SVFLoopAndDomInfo::getDomFrontierMap ( ) const
inline

Definition at line 75 of file SVFValue.h.

76  {
77  return dfBBsMap;
78  }

◆ getDomTreeMap() [1/2]

Map<const SVFBasicBlock*,BBSet>& SVF::SVFLoopAndDomInfo::getDomTreeMap ( )
inline

Definition at line 139 of file SVFValue.h.

140  {
141  return dtBBsMap;
142  }

◆ getDomTreeMap() [2/2]

const Map<const SVFBasicBlock*,BBSet>& SVF::SVFLoopAndDomInfo::getDomTreeMap ( ) const
inline

Definition at line 144 of file SVFValue.h.

145  {
146  return dtBBsMap;
147  }

◆ getExitBlocksOfLoop()

void SVFLoopAndDomInfo::getExitBlocksOfLoop ( const SVFBasicBlock bb,
BBList exitbbs 
) const

Definition at line 35 of file SVFValue.cpp.

36 {
37  if (hasLoopInfo(bb))
38  {
39  const LoopBBs blocks = getLoopInfo(bb);
40  if (!blocks.empty())
41  {
42  for (const SVFBasicBlock* block : blocks)
43  {
44  for (const SVFBasicBlock* succ : block->getSuccessors())
45  {
46  if ((std::find(blocks.begin(), blocks.end(), succ)==blocks.end()))
47  exitbbs.push_back(succ);
48  }
49  }
50  }
51  }
52 }
const std::vector< const SVFBasicBlock * > & getSuccessors() const
Definition: SVFValue.h:606
const LoopBBs & getLoopInfo(const SVFBasicBlock *bb) const
Definition: SVFValue.cpp:28
bool hasLoopInfo(const SVFBasicBlock *bb) const
Definition: SVFValue.h:85

◆ getLoopHeader()

const SVFBasicBlock* SVF::SVFLoopAndDomInfo::getLoopHeader ( const LoopBBs lp) const
inline

Definition at line 92 of file SVFValue.h.

93  {
94  assert(!lp.empty() && "this is not a loop, empty basic block");
95  return lp.front();
96  }

◆ getLoopInfo()

const SVFLoopAndDomInfo::LoopBBs & SVFLoopAndDomInfo::getLoopInfo ( const SVFBasicBlock bb) const

Definition at line 28 of file SVFValue.cpp.

29 {
30  assert(hasLoopInfo(bb) && "loopinfo does not exist (bb not in a loop)");
32  return mapIter->second;
33 }

◆ getPostDomTreeMap() [1/2]

Map<const SVFBasicBlock*,BBSet>& SVF::SVFLoopAndDomInfo::getPostDomTreeMap ( )
inline

Definition at line 113 of file SVFValue.h.

114  {
115  return pdtBBsMap;
116  }
Map< const SVFBasicBlock *, BBSet > pdtBBsMap
map a BasicBlock to BasicBlocks it PostDominates
Definition: SVFValue.h:62

◆ getPostDomTreeMap() [2/2]

const Map<const SVFBasicBlock*,BBSet>& SVF::SVFLoopAndDomInfo::getPostDomTreeMap ( ) const
inline

Definition at line 108 of file SVFValue.h.

109  {
110  return pdtBBsMap;
111  }

◆ getReachableBBs()

const BBList& SVF::SVFLoopAndDomInfo::getReachableBBs ( ) const
inline

Definition at line 155 of file SVFValue.h.

156  {
157  return reachableBBs;
158  }
BBList reachableBBs
reachable BasicBlocks from the function entry.
Definition: SVFValue.h:60

◆ hasLoopInfo()

bool SVF::SVFLoopAndDomInfo::hasLoopInfo ( const SVFBasicBlock bb) const
inline

Definition at line 85 of file SVFValue.h.

86  {
87  return bb2LoopMap.find(bb) != bb2LoopMap.end();
88  }

◆ isLoopHeader()

bool SVFLoopAndDomInfo::isLoopHeader ( const SVFBasicBlock bb) const

Definition at line 141 of file SVFValue.cpp.

142 {
143  if (hasLoopInfo(bb))
144  {
145  const LoopBBs& blocks = getLoopInfo(bb);
146  assert(!blocks.empty() && "no available loop info?");
147  return blocks.front() == bb;
148  }
149  return false;
150 }

◆ isUnreachable()

bool SVF::SVFLoopAndDomInfo::isUnreachable ( const SVFBasicBlock bb) const
inline

Definition at line 149 of file SVFValue.h.

150  {
151  return std::find(reachableBBs.begin(), reachableBBs.end(), bb) ==
152  reachableBBs.end();
153  }

◆ loopContainsBB()

bool SVF::SVFLoopAndDomInfo::loopContainsBB ( const LoopBBs lp,
const SVFBasicBlock bb 
) const
inline

Definition at line 98 of file SVFValue.h.

99  {
100  return std::find(lp.begin(), lp.end(), bb) != lp.end();
101  }

◆ postDominate()

bool SVFLoopAndDomInfo::postDominate ( const SVFBasicBlock bbKey,
const SVFBasicBlock bbValue 
) const

Definition at line 85 of file SVFValue.cpp.

86 {
87  if (bbKey == bbValue)
88  return true;
89 
90  // An unreachable node is dominated by anything.
91  if (isUnreachable(bbValue))
92  {
93  return true;
94  }
95 
96  // And dominates nothing.
97  if (isUnreachable(bbKey))
98  {
99  return false;
100  }
101 
104  if (mapIter != dtBBsMap.end())
105  {
106  const BBSet & dtBBs = mapIter->second;
107  if (dtBBs.find(bbValue) != dtBBs.end())
108  {
109  return true;
110  }
111  }
112  return false;
113 }
const Map< const SVFBasicBlock *, BBSet > & getPostDomTreeMap() const
Definition: SVFValue.h:108

◆ setReachableBBs()

void SVF::SVFLoopAndDomInfo::setReachableBBs ( BBList bbs)
inline

Definition at line 160 of file SVFValue.h.

161  {
162  reachableBBs = bbs;
163  }

Friends And Related Function Documentation

◆ SVFIRReader

friend class SVFIRReader
friend

Definition at line 53 of file SVFValue.h.

◆ SVFIRWriter

friend class SVFIRWriter
friend

Definition at line 52 of file SVFValue.h.

Member Data Documentation

◆ bb2LoopMap

Map<const SVFBasicBlock*, LoopBBs> SVF::SVFLoopAndDomInfo::bb2LoopMap
private

map a BasicBlock (if it is in a loop) to all the BasicBlocks in this loop

Definition at line 64 of file SVFValue.h.

◆ bb2PdomLevel

Map<const SVFBasicBlock*, u32_t> SVF::SVFLoopAndDomInfo::bb2PdomLevel
private

map a BasicBlock to its level in pdom tree, used in findNearestCommonPDominator

Definition at line 65 of file SVFValue.h.

◆ bb2PIdom

Map<const SVFBasicBlock*, const SVFBasicBlock*> SVF::SVFLoopAndDomInfo::bb2PIdom
private

map a BasicBlock to its immediate dominator in pdom tree, used in findNearestCommonPDominator

Definition at line 66 of file SVFValue.h.

◆ dfBBsMap

Map<const SVFBasicBlock*,BBSet> SVF::SVFLoopAndDomInfo::dfBBsMap
private

map a BasicBlock to its Dominate Frontier BasicBlocks

Definition at line 63 of file SVFValue.h.

◆ dtBBsMap

Map<const SVFBasicBlock*,BBSet> SVF::SVFLoopAndDomInfo::dtBBsMap
private

map a BasicBlock to BasicBlocks it Dominates

Definition at line 61 of file SVFValue.h.

◆ pdtBBsMap

Map<const SVFBasicBlock*,BBSet> SVF::SVFLoopAndDomInfo::pdtBBsMap
private

map a BasicBlock to BasicBlocks it PostDominates

Definition at line 62 of file SVFValue.h.

◆ reachableBBs

BBList SVF::SVFLoopAndDomInfo::reachableBBs
private

reachable BasicBlocks from the function entry.

Definition at line 60 of file SVFValue.h.


The documentation for this class was generated from the following files: