Static Value-Flow Analysis
Loading...
Searching...
No Matches
MTASlicer.h
Go to the documentation of this file.
1//===- MTASlicer.h -- Multi-stage on-demand program slicers ---------------===//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <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 Affero 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 Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * MTASlicer.h
25 *
26 * Author: Jiawei Yang
27 */
28
29#ifndef MTA_MTASLICER_H
30#define MTA_MTASLICER_H
31
32#include "SVFIR/SVFIR.h"
33#include "SVFIR/SVFStatements.h"
34#include "SVFIR/SVFVariables.h"
35#include "WPA/Andersen.h"
36#include "MTA/MHP.h"
37#include "MTA/LockAnalysis.h"
38#include "MTA/TCT.h"
39#include "Graphs/SlicedGraphs.h"
41#include "Graphs/ICFG.h"
42#include "Graphs/ICFGNode.h"
43#include <deque>
44#include "Graphs/ICFGEdge.h"
45#include "Graphs/CallGraph.h"
46#include "Util/WorkList.h"
47#include <memory>
48#include <vector>
49#include <utility>
50
51namespace SVF
52{
53
54// Forward declarations
55class SVFG;
56class VFGNode; // SVFGNode is a typedef for VFGNode
57class PointerAnalysis;
58
60{
63
65 {
66 NodeBS ids;
67 for (const SVFGNode* node : svfgNodes)
68 ids.set(node->getId());
69 return ids;
70 }
71};
72
73
74//===----------------------------------------------------------------------===//
75// SlicedTCT - the Thread-Create-Tree rebuilt over a SlicedThreadCallGraphView.
76//
77// Inherits TCT and overrides the ThreadCallGraph-traversing steps to use the
78// sliced view. It sits at the sliced-representation layer (built from the view,
79// consumed by the sliced MHP/LockAnalysis graph-access), which is why it lives
80// here with the views rather than beside the analyses.
81//===----------------------------------------------------------------------===//
82class SlicedTCT : public TCT
83{
84public:
88 static std::unique_ptr<SlicedTCT> create(
91
92 ~SlicedTCT() override = default;
93
94protected:
95 void build() override;
96 void markRelProcs() override;
97 void markRelProcs(const FunObjVar* fun) override;
98 void collectLoopInfoForJoin() override;
99 void handleCallRelation(CxtThreadProc& ctp, const CallGraphEdge* cgEdge, const CallICFGNode* cs) override;
100
101private:
104
105 void collectEntryFunInCallGraph() override;
106
108 bool isKeptNode(const CallGraphNode* node) const;
109 bool isKeptEdge(const CallGraphEdge* edge) const;
110 void getKeptForkSites(std::vector<const ICFGNode*>& out) const;
111 void getKeptJoinSites(std::vector<const ICFGNode*>& out) const;
112};
113
114
122{
123public:
125 LockAnalysis* lockAnalysis, SVFG* svfg = nullptr);
126
127protected:
134
135 // === Data flow analysis helper ===
142
143 static void enqueueSVFGNode(const SVFGNode* node,
145 std::deque<const SVFGNode*>& worklist);
146
150
151 // === Thread analysis helpers ===
154
155 // === Lock analysis helpers ===
161
162 // === Common slicing helpers ===
168 std::pair<OrderedSet<const CallICFGNode*>, OrderedSet<const CallICFGNode*>>
170
177
178 // === ICFG analysis helpers ===
188
189};
190
241
266
267} // End namespace SVF
268
269#endif // MTA_MTASLICER_H
Definition MHP.h:52
OrderedSet< const CallICFGNode * > collectMutexStatements(const OrderedSet< const ICFGNode * > &sourceNodes)
std::pair< OrderedSet< const CallICFGNode * >, OrderedSet< const CallICFGNode * > > collectCommonThreadStatements(const OrderedSet< const ICFGNode * > &sourceNodes)
OrderedSet< const CallICFGNode * > collectPthreadStatements(const OrderedSet< const ICFGNode * > &sourceNodes)
OrderedSet< const VFGNode * > computeDataDependenceSVFGNodes(const OrderedSet< const SVFStmt * > &seeds, SVFG *svfg)
OrderedSet< const ICFGNode * > expandCallDependence(const OrderedSet< const ICFGNode * > &nodes)
AndersenBase * pta
Definition MTASlicer.h:129
OrderedSet< const ICFGNode * > getLockSet(const ICFGNode *node)
OrderedSet< const TCTNode * > getTCTNodeSetFromNode(const ICFGNode *node)
LockAnalysis * lockAnalysis
Definition MTASlicer.h:131
OrderedSet< const ICFGNode * > svfgNodesToICFGNodes(const OrderedSet< const VFGNode * > &nodes, const OrderedSet< const SVFStmt * > &seeds)
Project the retained VFG nodes (plus the seeds) onto their ICFG nodes.
static void enqueueSVFGNode(const SVFGNode *node, OrderedSet< const SVFGNode * > &visited, std::deque< const SVFGNode * > &worklist)
CallGraph * callGraph
Definition MTASlicer.h:132
SVFG * svfg
thread-aware VFG_pre (PTA/Single slicers; null for MTA)
Definition MTASlicer.h:133
void addSynchronizationDependencies(const OrderedSet< const CallICFGNode * > &pthreadCallNodes, const OrderedSet< const CallICFGNode * > &mutexCallNodes, OrderedSet< const ICFGNode * > &retainedNodes)
OrderedSet< const CallICFGNode * > getDependentThreadCreate(const ICFGNode *node)
ValueFlowSlice preCandidateSlice
Definition MTASlicer.h:238
OrderedSet< const ICFGNode * > runILASlicing(const OrderedSet< const SVFStmt * > &vulnerableStatements, const OrderedSet< const ICFGNode * > &threadVFSources={})
const ValueFlowSlice & getPreCandidateSlice() const
Return the pre-candidate slice after computePreCandidateSlice().
void computePreCandidateSlice(const OrderedSet< const SVFStmt * > &vulnerableStatements)
ValueFlowSlice runPTASlicing(const OrderedSet< const SVFStmt * > &vulnerableStatements, SVFG *refinedMainVFG)
ValueFlowSlice runSlicing(const OrderedSet< const SVFStmt * > &vulnerableStatements)
void getKeptForkSites(std::vector< const ICFGNode * > &out) const
~SlicedTCT() override=default
void collectEntryFunInCallGraph() override
Get entry functions that are neither called by other functions nor extern functions.
void collectLoopInfoForJoin() override
Handle join site in loop.
void handleCallRelation(CxtThreadProc &ctp, const CallGraphEdge *cgEdge, const CallICFGNode *cs) override
Handle call relations.
bool isKeptEdge(const CallGraphEdge *edge) const
void getKeptJoinSites(std::vector< const ICFGNode * > &out) const
bool isKeptNode(const CallGraphNode *node) const
const SlicedThreadCallGraphView & tcgView
Definition MTASlicer.h:107
static std::unique_ptr< SlicedTCT > create(PointerAnalysis &pointerAnalysis, const SlicedSVFIRView &slicedView, u32_t contextLimit)
Definition MTASlicer.cpp:56
void build() override
Build TCT.
Definition MTASlicer.cpp:73
void markRelProcs() override
Mark relevant procedures that are backward reachable from any fork/join site.
void set(unsigned Idx)
const u32_t contextLimit
Definition TCT.h:459
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
unsigned u32_t
Definition GeneralType.h:67
NodeBS nodeIds() const
Definition MTASlicer.h:64
OrderedSet< const SVFGNode * > svfgNodes
Definition MTASlicer.h:61
OrderedSet< const ICFGNode * > icfgNodes
Definition MTASlicer.h:62