Static Value-Flow Analysis
Loading...
Searching...
No Matches
MTA.h
Go to the documentation of this file.
1//===- MTA.h -- Analysis of multithreaded programs-------------//
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 * MTA.h
25 *
26 * Created on: May 14, 2014
27 * Author: Yulei Sui, Peng Di
28 *
29 * The base data race detector is based on
30 * Yulei Sui, Peng Di, and Jingling Xue. "Sparse Flow-Sensitive Pointer Analysis for Multithreaded Programs".
31 * 2016 International Symposium on Code Generation and Optimization (CGO'16)
32 *
33 * This file also declares SlicedMTA, the multi-stage on-demand program slicing
34 * pipeline (MSli) introduced in "Multi-Stage On-Demand Program Slicing for
35 * Modular Analysis of Multi-Threaded Programs" (ISSTA 2026).
36 */
37
38#ifndef MTA_H_
39#define MTA_H_
40
41#include <set>
42#include <string>
43#include <vector>
44#include <functional>
45#include <memory>
46#include <utility>
47#include "SVFIR/SVFIR.h"
48#include "SVFIR/SVFValue.h"
49#include "SVFIR/SVFStatements.h"
50#include "SVFIR/SVFVariables.h"
52#include "MTA/MHP.h"
53#include "MTA/LockAnalysis.h"
54#include "WPA/Andersen.h"
55#include "Graphs/CallGraph.h"
56
57namespace SVF
58{
59
60class PointerAnalysis;
61class AndersenWaveDiff;
62class AndersenBase;
63class ThreadCallGraph;
64class CallGraph;
65class MTAStat;
66class TCT;
67class MHP;
68class LockAnalysis;
69class SVFStmt;
70class SVFIR;
71class ICFGNode;
72// Forward declarations for the SlicedMTA slicing pipeline (see SlicedMTA impl).
73class MTASVFGBuilder;
74class SVFG;
75class FlowSensitive;
76class SlicedSVFGView;
77class MultiStageSlicer;
78class SingleSlicer;
79class SlicedSVFIRView;
80class SlicedTCT;
81
85class MTA
86{
87
88public:
90 MTA();
91
93 virtual ~MTA();
94
95
97 virtual bool runOnModule(SVFIR* module);
99 virtual MHP* computeMHP(TCT* tct);
103 virtual void reportRaces();
104
105 // Not implemented for now
106 // void dump(Module &module, MHP *mhp, LockAnalysis *lsa);
107
109 {
110 return mhp;
111 }
112
114 {
115 return lsa;
116 }
117
119 struct RacePair
120 {
123 RacePair(const SVFStmt* s1, const SVFStmt* s2) : stmt1(s1), stmt2(s2) {}
124 bool operator<(const RacePair& other) const
125 {
126 if (stmt1 != other.stmt1) return stmt1 < other.stmt1;
127 return stmt2 < other.stmt2;
128 }
129 };
130
133 static std::set<const SVFStmt*> detectRace(
134 SVFIR* svfIr, AndersenBase* pta, MHP* mhp, LockAnalysis* lockAnalysis,
135 CallGraph* callGraph, std::set<RacePair>& outRacePairs);
136
140
143 static bool hasThreadFunctions(CallGraph* callGraph);
144
145private:
156
158
159 static bool occurrencesRace(MHP* mhp, const RaceOccurrence& first, const RaceOccurrence& second);
160 static void commitRacePair(std::set<RacePair>& out,
163
165 std::unique_ptr<TCT> tct;
166 std::unique_ptr<MTAStat> stat;
169};
170
189{
190public:
194 using ResolveIndirectCalls = std::function<void(CallGraph*)>;
195
198
199 // Out-of-line (defined where the member types are complete) so callers that
200 // only see the forward-declared unique_ptr member types need not be complete.
202 ~SlicedMTA();
203
204 SlicedMTA(const SlicedMTA&) = delete;
205 SlicedMTA& operator=(const SlicedMTA&) = delete;
206
209
210private:
211 // --- pipeline stages ---
216 void buildVFGPre();
217
221
224 BVDataPTAImpl* getMainPTA() const;
225
227 std::set<const SVFStmt*> getVulnerableStmts() const;
228
229 // --- race detection ---
231 std::set<RacePair> detectRacePairsOnSlicedGraph(
233
234 // Lock analysis over the WHOLE ICFG (real control flow, no bridging) for the
235 // final detection's lock signature. The sliced lock analysis walks bridged
236 // edges, which fabricate lock-carrying paths the whole program lacks (a
237 // query-preservation break); lock-span is control-flow-sensitive, so it must
238 // see real edges. Built lazily, cheap (no FSAM/MHP) next to the slicing win.
240
241 // --- pipeline state (owned unless noted) ---
242 SVFIR* svfIr = nullptr;
243 // Main-phase context depth, set by runOnModule; the pre-analysis uses it
244 // to reconcile context-truncation-merged thread instances.
246 std::unique_ptr<TCT> tct;
247 std::unique_ptr<MHP> mhp;
248 std::unique_ptr<LockAnalysis> lockAnalysis;
249 // Inclusion-based Andersen's pre-analysis (a shared singleton, not owned
250 // here -- released once in the destructor). Feeds the TCT / MHP / lock /
251 // race pre-analysis, the thread-aware VFG_pre, and the main FSMPTA.
253 std::unique_ptr<MTASVFGBuilder> vfgPreBuilder; // owns vfgPre
254 SVFG* vfgPre = nullptr;
255 std::unique_ptr<MultiStageSlicer> multiStageSlicer;
256 std::unique_ptr<SingleSlicer> singleSlicer;
257 // -mta-slicing-single: the one unified slice, computed in MTA slicing and reused
258 // (not recomputed) for PTA slicing so both stages share V_Single.
259 std::set<const ICFGNode*> singleSlicedNodes;
260 std::unique_ptr<SlicedSVFIRView> mtaSlicedView;
261 std::unique_ptr<SlicedSVFIRView> ptaSlicedView;
262 std::unique_ptr<SlicedSVFGView> slicedSVFGView;
263 std::unique_ptr<FlowSensitive> mtaFSMPTA;
264 std::unique_ptr<SlicedTCT> slicedTCT;
265 std::unique_ptr<MHP> slicedMhp;
266 std::unique_ptr<LockAnalysis> slicedLockAnalysis;
267 // Whole-ICFG lock analysis for the final detection (see buildFullLockAnalysis).
268 std::unique_ptr<SlicedSVFIRView> fullLockView;
269 std::unique_ptr<SlicedTCT> fullLockTCT;
270 std::unique_ptr<LockAnalysis> fullLockAnalysis;
271 bool hasThreadFunctions = false;
272 std::set<RacePair> racePairs;
273};
274
275} // End namespace SVF
276
277#endif /* MTA_H_ */
Definition MHP.h:57
Definition MTA.h:86
LockAnalysis * getLockAnalysis()
Definition MTA.h:113
virtual LockAnalysis * computeLocksets(TCT *tct)
Compute locksets.
Definition MTA.cpp:114
static std::set< const SVFStmt * > detectRace(SVFIR *svfIr, AndersenBase *pta, MHP *mhp, LockAnalysis *lockAnalysis, CallGraph *callGraph, std::set< RacePair > &outRacePairs)
Definition MTA.cpp:221
ThreadCallGraph * tcg
Definition MTA.h:164
std::unique_ptr< TCT > tct
Definition MTA.h:165
static bool occurrencesRace(MHP *mhp, const RaceOccurrence &first, const RaceOccurrence &second)
Helpers for the equivalence-class race detector.
Definition MTA.cpp:202
virtual ~MTA()
Destructor.
Definition MTA.cpp:63
LockAnalysis * lsa
Definition MTA.h:168
MHP * getMHP()
Definition MTA.h:108
MHP * mhp
Definition MTA.h:167
static PointsTo getGlobalObjectVariables(SVFIR *svfIr)
Escape/points-to helpers for the shared detector.
Definition MTA.cpp:138
virtual MHP * computeMHP(TCT *tct)
Compute MHP.
Definition MTA.cpp:121
MTA()
Constructor.
Definition MTA.cpp:58
static void commitRacePair(std::set< RacePair > &out, const RaceOccurrence &first, const RaceOccurrence &second)
Definition MTA.cpp:210
std::unique_ptr< MTAStat > stat
Definition MTA.h:166
static bool hasThreadFunctions(CallGraph *callGraph)
Definition MTA.cpp:1039
virtual bool runOnModule(SVFIR *module)
We start the pass here.
Definition MTA.cpp:75
virtual void reportRaces()
Run the shared detector and print a race report.
Definition MTA.cpp:385
static PointsTo getPointsToClosure(AndersenBase *pta, const PointsTo &pts)
Definition MTA.cpp:166
u32_t mainCxtDepth
Definition MTA.h:245
std::unique_ptr< LockAnalysis > lockAnalysis
Definition MTA.h:248
void buildVFGPre()
Definition MTA.cpp:508
std::set< RacePair > racePairs
Definition MTA.h:272
std::unique_ptr< SlicedSVFIRView > fullLockView
Definition MTA.h:268
bool hasThreadFunctions
Definition MTA.h:271
SVFIR * svfIr
Definition MTA.h:242
void runOnModule(SVFIR *pag, const ResolveIndirectCalls &resolveIndirectCalls)
Run the slicing pipeline on a pre-built SVFIR.
Definition MTA.cpp:998
std::unique_ptr< FlowSensitive > mtaFSMPTA
Definition MTA.h:263
void runWholeProgramDetection()
Definition MTA.cpp:941
bool runPTASlicingAndAnalysis()
Definition MTA.cpp:751
bool runFinalRaceDetection()
Definition MTA.cpp:872
std::set< const SVFStmt * > getVulnerableStmts() const
Union of both statements of every candidate race pair (the slice targets).
Definition MTA.cpp:492
std::set< RacePair > detectRacePairsOnSlicedGraph(BVDataPTAImpl *slicedPTA, MHP *slicedMHP, LockAnalysis *slicedLockAnalysis)
Re-check the candidate race pairs on the sliced graph using FSAM points-to.
Definition MTA.cpp:1057
std::unique_ptr< LockAnalysis > slicedLockAnalysis
Definition MTA.h:266
std::unique_ptr< LockAnalysis > fullLockAnalysis
Definition MTA.h:270
std::unique_ptr< SlicedSVFIRView > mtaSlicedView
Definition MTA.h:260
std::unique_ptr< SlicedTCT > fullLockTCT
Definition MTA.h:269
bool runMTASlicingAndAnalysis()
Definition MTA.cpp:634
std::unique_ptr< MultiStageSlicer > multiStageSlicer
Definition MTA.h:255
SlicedMTA(const SlicedMTA &)=delete
AndersenWaveDiff * preAnder
Definition MTA.h:252
std::unique_ptr< MHP > slicedMhp
Definition MTA.h:265
std::set< const ICFGNode * > singleSlicedNodes
Definition MTA.h:259
std::unique_ptr< SingleSlicer > singleSlicer
Definition MTA.h:256
SlicedMTA & operator=(const SlicedMTA &)=delete
std::unique_ptr< SlicedSVFIRView > ptaSlicedView
Definition MTA.h:261
std::unique_ptr< TCT > tct
Definition MTA.h:246
SVFG * vfgPre
Definition MTA.h:254
std::unique_ptr< SlicedSVFGView > slicedSVFGView
Definition MTA.h:262
std::function< void(CallGraph *)> ResolveIndirectCalls
Definition MTA.h:194
std::unique_ptr< SlicedTCT > slicedTCT
Definition MTA.h:264
std::unique_ptr< MHP > mhp
Definition MTA.h:247
LockAnalysis * buildFullLockAnalysis()
Definition MTA.cpp:855
bool runPreAnalysis(const ResolveIndirectCalls &resolveIndirectCalls)
Definition MTA.cpp:527
std::unique_ptr< MTASVFGBuilder > vfgPreBuilder
Definition MTA.h:253
BVDataPTAImpl * getMainPTA() const
Definition MTA.cpp:485
for isBitcode
Definition BasicTypes.h:70
u32_t NodeID
Definition GeneralType.h:76
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67
One occurrence of a memory access under one thread instance.
Definition MTA.h:148
const SVFStmt * stmt
Definition MTA.h:149
const ICFGNode * node
Definition MTA.h:150
A race pair: two statements that may race.
Definition MTA.h:120
const SVFStmt * stmt2
Definition MTA.h:122
bool operator<(const RacePair &other) const
Definition MTA.h:124
RacePair(const SVFStmt *s1, const SVFStmt *s2)
Definition MTA.h:123
const SVFStmt * stmt1
Definition MTA.h:121