SVF
OfflineConsG.h
Go to the documentation of this file.
1 //===- OfflineConsG.h -- Offline constraint graph -----------------------------//
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  * OfflineConsG.h
25  *
26  * Created on: Oct 28, 2018
27  * Author: Yuxiang Lei
28  */
29 
30 #ifndef OFFLINECONSG_H
31 #define OFFLINECONSG_H
32 
33 #include "Graphs/ConsG.h"
34 #include "Util/SCC.h"
35 
36 namespace SVF
37 {
38 
45 {
46 
47 public:
51 
52 protected:
55  NodeToRepMap norToRepMap; // for each *a construct a --> rep, i.e., mapping a node of to a rep node for online constraint solving
56 
57 public:
59  nodeToRefMap( {}), norToRepMap({})
60  {
62  }
63 
64  // Determine whether a node has a OCG rep node
65  inline bool hasOCGRep(NodeID node) const
66  {
67  return hasNorRep(node);
68  }
69  // Get a node's OCG rep node
70  inline NodeID getOCGRep(NodeID node) const
71  {
72  return getNorRep(node);
73  }
74  // Get the OCG node to rep map (this map is const and should not be modified)
75  inline const NodeToRepMap& getOCGRepMap () const
76  {
77  return norToRepMap;
78  }
79 
80  // Determine whether a node is a ref node
81  inline bool isaRef(NodeID node) const
82  {
83  NodeSet::const_iterator it = refNodes.find(node);
84  return it != refNodes.end();
85  };
86  // Determine whether a node has ref nodes
87  inline bool hasRef(NodeID node) const
88  {
89  NodeToRepMap::const_iterator it = nodeToRefMap.find(node);
90  return it != nodeToRefMap.end();
91  };
92  // Use a constraint node to track its corresponding ref node
93  inline NodeID getRef(NodeID node) const
94  {
95  NodeToRepMap::const_iterator it = nodeToRefMap.find(node);
96  assert(it != nodeToRefMap.end() && "No such ref node in ref to node map!");
97  return it->second;
98  }
99 
100  // Constraint solver of offline constraint graph
101  //{@
102  void solveOfflineSCC(OSCC* oscc);
103  void buildOfflineMap(OSCC* oscc);
105 
106  // Dump graph into dot file
107  void dump(std::string name);
108 
109 protected:
110  inline bool hasNorRep(NodeID nor) const
111  {
112  NodeToRepMap::const_iterator it = norToRepMap.find(nor);
113  return it != norToRepMap.end();
114  };
115 
116  inline void setNorRep(NodeID nor, NodeID rep)
117  {
118  norToRepMap.insert(std::pair<NodeID, NodeID>(nor, rep));
119  };
120 
121  inline NodeID getNorRep(NodeID nor) const
122  {
123  NodeToRepMap::const_iterator it = norToRepMap.find(nor);
124  assert(it != norToRepMap.end() && "No such rep node in nor to rep map!");
125  return it->second;
126  };
127  NodeID solveRep(OSCC* oscc, NodeID rep);
128 
129  void buildOfflineCG();
130  bool addRefLoadEdge(NodeID src, NodeID dst);
131  bool addRefStoreEdge(NodeID src, NodeID dst);
132  bool createRefNode(NodeID nodeId);
133 };
134 
135 } // End namespace SVF
136 
137 namespace llvm
138 {
139 /* !
140  * GraphTraits specializations for the generic graph algorithms.
141  * Provide graph traits for traversing from a constraint node using standard graph traversals.
142  */
143 
144 template<> struct GraphTraits<SVF::OfflineConsG*> : public GraphTraits<SVF::GenericGraph<SVF::ConstraintNode,SVF::ConstraintEdge>* >
145 {
147 };
148 
149 } // End namespace llvm
150 
151 #endif //OFFLINECONSG_H
Definition: ConsG.h:385
Set< NodeID > NodeSet
bool hasOCGRep(NodeID node) const
Definition: OfflineConsG.h:65
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
bool addRefLoadEdge(NodeID src, NodeID dst)
Map< NodeID, NodeID > NodeToRepMap
Definition: ConsG.h:50
void setNorRep(NodeID nor, NodeID rep)
Definition: OfflineConsG.h:116
void solveOfflineSCC(OSCC *oscc)
Definition: PAG.h:47
NodeID getNorRep(NodeID nor) const
Definition: OfflineConsG.h:121
bool hasRef(NodeID node) const
Definition: OfflineConsG.h:87
Set< StoreCGEdge * > StoreEdges
Definition: OfflineConsG.h:50
NodeToRepMap nodeToRefMap
Definition: OfflineConsG.h:54
bool hasNorRep(NodeID nor) const
Definition: OfflineConsG.h:110
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: SVFBasicTypes.h:93
const NodeToRepMap & getOCGRepMap() const
Definition: OfflineConsG.h:75
bool isaRef(NodeID node) const
Definition: OfflineConsG.h:81
bool addRefStoreEdge(NodeID src, NodeID dst)
NodeID getOCGRep(NodeID node) const
Definition: OfflineConsG.h:70
bool createRefNode(NodeID nodeId)
SCCDetection< OfflineConsG * > OSCC
Definition: OfflineConsG.h:48
Set< LoadCGEdge * > LoadEdges
Definition: OfflineConsG.h:49
void buildOfflineMap(OSCC *oscc)
NodeID solveRep(OSCC *oscc, NodeID rep)
void dump(std::string name)
for isBitcode
Definition: ContextDDA.h:15
OfflineConsG(PAG *p)
Definition: OfflineConsG.h:58
NodeID getRef(NodeID node) const
Definition: OfflineConsG.h:93
NodeToRepMap norToRepMap
Definition: OfflineConsG.h:55