SVF
DataFlowUtil.cpp
Go to the documentation of this file.
1 //===- DataFlowUtil.cpp -- Helper class for data-flow analysis----------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2017> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 
24 /*
25  * DataFlowUtil.cpp
26  *
27  * Created on: Jun 4, 2013
28  * Author: Yulei Sui
29  */
30 
31 #include "SVF-FE/DataFlowUtil.h"
32 #include "SVF-FE/LLVMModule.h"
33 
34 using namespace SVF;
35 using namespace llvm;
36 
38 //static RegisterPass<IteratedDominanceFrontier> IDF("IDF",
39 // "IteratedDominanceFrontier Pass");
40 
42 {
43 // Module* mod = LLVMModuleSet::getLLVMModuleSet()->getMainLLVMModule();
44 // llvm::legacy::PassManager PM;
45 // PM.add(new llvm::PTACFInfoBuilderPass());
46 // PM.run(*mod);
47 }
48 
50  for(FunToLoopInfoMap::iterator it = funToLoopInfoMap.begin(), eit = funToLoopInfoMap.end(); it!=eit; ++it)
51  {
52  if(it->second != nullptr)
53  {
54  delete it->second;
55  }
56  }
57  for(FunToDTMap::iterator it = funToDTMap.begin(), eit = funToDTMap.end(); it!=eit; ++it)
58  {
59  if(it->second != nullptr)
60  {
61  delete it->second;
62  }
63  }
64  for(FunToPostDTMap::iterator it = funToPDTMap.begin(), eit = funToPDTMap.end(); it!=eit; ++it)
65  {
66  if(it->second != nullptr)
67  {
68  delete it->second;
69  }
70  }
71 }
72 
75 {
76  assert(f->isDeclaration()==false && "external function (without body) does not have a loopInfo");
77  Function* fun = const_cast<Function*>(f);
78  FunToLoopInfoMap::iterator it = funToLoopInfoMap.find(fun);
79  if(it==funToLoopInfoMap.end())
80  {
81  DominatorTree* dt = new DominatorTree(*fun);
82  LoopInfo* loopInfo = new LoopInfo(*dt);
83  funToLoopInfoMap[fun] = loopInfo;
84  return loopInfo;
85  }
86  else
87  return it->second;
88 }
89 
92 {
93  assert(f->isDeclaration()==false && "external function (without body) does not have a PostDominatorTree");
94 
95  Function* fun = const_cast<Function*>(f);
96  if(f->isDeclaration())
97  return nullptr;
98  FunToPostDTMap::iterator it = funToPDTMap.find(fun);
99  if(it==funToPDTMap.end())
100  {
101  PostDominatorTree * PDT = new PostDominatorTree(*fun);
102  funToPDTMap[fun] = PDT;
103  return PDT;
104  }
105  else
106  return it->second;
107 }
108 
111 {
112  Function* fun = const_cast<Function*>(f);
113  FunToDTMap::iterator it = funToDTMap.find(fun);
114  if(it==funToDTMap.end())
115  {
116  DominatorTree* dt = new DominatorTree(*fun);
117  funToDTMap[fun] = dt;
118  return dt;
119  }
120  else
121  return it->second;
122 }
123 
124 
126  const DominanceFrontier &DF)
127 {
128 
129  DomSetType worklist;
130 
132  assert(it != DF.end());
133 
134  worklist.insert(it->second.begin(), it->second.end());
135  while (!worklist.empty())
136  {
137  BasicBlock *item = *worklist.begin();
138  worklist.erase(worklist.begin());
139  if (Frontiers[bb].find(item) == Frontiers[bb].end())
140  {
141  Frontiers[bb].insert(item);
142  const_iterator parent = DF.find(item);
143  assert(parent != DF.end());
144  worklist.insert(parent->second.begin(), parent->second.end());
145  }
146  }
147 }
void calculate(BasicBlock *, const DominanceFrontier &DF)
Definition: ConsG.h:385
llvm::BasicBlock BasicBlock
Definition: BasicTypes.h:77
#define assert(ex)
Definition: util.h:141
llvm::LoopInfo LoopInfo
Definition: BasicTypes.h:89
llvm::DominanceFrontier DominanceFrontier
LLVM Dominators.
Definition: BasicTypes.h:192
PostDominatorTree * getPostDT(const Function *f)
Get post dominator tree of a function.
llvm::PostDominatorTree PostDominatorTree
Definition: BasicTypes.h:194
llvm::Function Function
Definition: BasicTypes.h:76
LoopInfo * getLoopInfo(const Function *f)
Get loop info of a function.
llvm::DominanceFrontierBase< BasicBlock, false > DominanceFrontierBase
Definition: BasicTypes.h:196
llvm::DominatorTree DominatorTree
Definition: BasicTypes.h:193
DominatorTree * getDT(const Function *f)
Get dominator tree of a function.
PTACFInfoBuilder()
Constructor.
for isBitcode
Definition: ContextDDA.h:15