blob: b8b0aaca18429d623c61c54e5376a79797c84e28 [file] [log] [blame]
Ted Kremenek11de5cb2007-09-20 21:42:55 +00001//=- LiveVariables.cpp - Live Variable Analysis for Source CFGs -*- C++ --*-==//
Ted Kremeneke4e63342007-09-06 00:17:54 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremeneke4e63342007-09-06 00:17:54 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements Live Variables analysis for source-level CFGs.
11//
12//===----------------------------------------------------------------------===//
13
Ted Kremenekcf6e41b2007-12-21 21:42:19 +000014#include "clang/Analysis/Analyses/LiveVariables.h"
Ted Kremenek27b07c52007-09-06 21:26:58 +000015#include "clang/Basic/SourceManager.h"
Ted Kremeneke0dbda12008-12-09 00:14:14 +000016#include "clang/AST/ASTContext.h"
Ted Kremeneke4e63342007-09-06 00:17:54 +000017#include "clang/AST/Expr.h"
18#include "clang/AST/CFG.h"
Ted Kremenekfdd225e2007-09-25 04:31:27 +000019#include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h"
Ted Kremenek1de632b2007-09-25 21:00:24 +000020#include "clang/Analysis/FlowSensitive/DataflowSolver.h"
Ted Kremeneke4e63342007-09-06 00:17:54 +000021#include "llvm/ADT/SmallPtrSet.h"
Ted Kremenek7deed0c2008-04-15 18:35:30 +000022#include "llvm/ADT/SmallVector.h"
Ted Kremenekc2b51d82008-01-08 18:19:08 +000023#include "llvm/Support/Compiler.h"
Ted Kremeneke4e63342007-09-06 00:17:54 +000024
Ted Kremenek27b07c52007-09-06 21:26:58 +000025#include <string.h>
26#include <stdio.h>
Ted Kremeneke4e63342007-09-06 00:17:54 +000027
28using namespace clang;
29
30//===----------------------------------------------------------------------===//
Ted Kremenek7deed0c2008-04-15 18:35:30 +000031// Useful constants.
32//===----------------------------------------------------------------------===//
33
34static const bool Alive = true;
35static const bool Dead = false;
36
37//===----------------------------------------------------------------------===//
Ted Kremenekfdd225e2007-09-25 04:31:27 +000038// Dataflow initialization logic.
39//===----------------------------------------------------------------------===//
Ted Kremeneke4e63342007-09-06 00:17:54 +000040
41namespace {
Ted Kremenekc2b51d82008-01-08 18:19:08 +000042class VISIBILITY_HIDDEN RegisterDecls
43 : public CFGRecStmtDeclVisitor<RegisterDecls> {
44
Ted Kremenekfdd225e2007-09-25 04:31:27 +000045 LiveVariables::AnalysisDataTy& AD;
Ted Kremenek7deed0c2008-04-15 18:35:30 +000046
47 typedef llvm::SmallVector<VarDecl*, 20> AlwaysLiveTy;
48 AlwaysLiveTy AlwaysLive;
49
50
Ted Kremenekf63aa452007-09-28 20:38:59 +000051public:
Ted Kremenek7deed0c2008-04-15 18:35:30 +000052 RegisterDecls(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
53
54 ~RegisterDecls() {
55
56 AD.AlwaysLive.resetValues(AD);
57
58 for (AlwaysLiveTy::iterator I = AlwaysLive.begin(), E = AlwaysLive.end();
59 I != E; ++ I)
60 AD.AlwaysLive(*I, AD) = Alive;
61 }
62
Chris Lattner41110242008-06-17 18:05:57 +000063 void VisitImplicitParamDecl(ImplicitParamDecl* IPD) {
64 // Register the VarDecl for tracking.
65 AD.Register(IPD);
66 }
67
Ted Kremenek7deed0c2008-04-15 18:35:30 +000068 void VisitVarDecl(VarDecl* VD) {
69 // Register the VarDecl for tracking.
70 AD.Register(VD);
71
72 // Does the variable have global storage? If so, it is always live.
73 if (VD->hasGlobalStorage())
74 AlwaysLive.push_back(VD);
75 }
76
77 void VisitUnaryOperator(UnaryOperator* U) {
78 // Check for '&'. Any VarDecl whose value has its address-taken we
79 // treat as always being live (flow-insensitive).
80
81 Expr* E = U->getSubExpr()->IgnoreParenCasts();
82
83 if (U->getOpcode() == UnaryOperator::AddrOf)
84 if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(E))
85 if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl())) {
86 AD.Register(VD);
87 AlwaysLive.push_back(VD);
88 return;
89 }
90
91 Visit(E);
92 }
93
Ted Kremenek9f9141c2007-11-20 03:01:58 +000094 CFG& getCFG() { return AD.getCFG(); }
Ted Kremenek11e72182007-10-01 20:33:52 +000095};
Ted Kremeneke4e63342007-09-06 00:17:54 +000096} // end anonymous namespace
97
Ted Kremenekbffaa832008-01-29 05:13:23 +000098
Ted Kremeneke0dbda12008-12-09 00:14:14 +000099LiveVariables::LiveVariables(ASTContext& Ctx, CFG& cfg) {
Ted Kremenek7cb15932008-03-13 16:55:07 +0000100 // Register all referenced VarDecls.
Ted Kremeneke0dbda12008-12-09 00:14:14 +0000101 getAnalysisData().setCFG(cfg);
102 getAnalysisData().setContext(Ctx);
103
Ted Kremenek11e72182007-10-01 20:33:52 +0000104 RegisterDecls R(getAnalysisData());
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000105 cfg.VisitBlockStmts(R);
106}
Ted Kremeneke4e63342007-09-06 00:17:54 +0000107
108//===----------------------------------------------------------------------===//
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000109// Transfer functions.
110//===----------------------------------------------------------------------===//
Ted Kremeneke4e63342007-09-06 00:17:54 +0000111
112namespace {
Ted Kremenekf63aa452007-09-28 20:38:59 +0000113
Ted Kremenekc2b51d82008-01-08 18:19:08 +0000114class VISIBILITY_HIDDEN TransferFuncs : public CFGRecStmtVisitor<TransferFuncs>{
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000115 LiveVariables::AnalysisDataTy& AD;
Ted Kremenekf63aa452007-09-28 20:38:59 +0000116 LiveVariables::ValTy LiveState;
Ted Kremeneke4e63342007-09-06 00:17:54 +0000117public:
Ted Kremenek11e72182007-10-01 20:33:52 +0000118 TransferFuncs(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000119
Ted Kremenekf63aa452007-09-28 20:38:59 +0000120 LiveVariables::ValTy& getVal() { return LiveState; }
Ted Kremenek9f9141c2007-11-20 03:01:58 +0000121 CFG& getCFG() { return AD.getCFG(); }
Ted Kremenekf1758052007-09-12 19:10:52 +0000122
Ted Kremeneke4e63342007-09-06 00:17:54 +0000123 void VisitDeclRefExpr(DeclRefExpr* DR);
124 void VisitBinaryOperator(BinaryOperator* B);
125 void VisitAssign(BinaryOperator* B);
Ted Kremenek27b07c52007-09-06 21:26:58 +0000126 void VisitDeclStmt(DeclStmt* DS);
Ted Kremenekbfcb7122008-11-12 21:58:46 +0000127 void BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt* S);
Ted Kremenek27b07c52007-09-06 21:26:58 +0000128 void VisitUnaryOperator(UnaryOperator* U);
Ted Kremenek8f5aab62008-11-11 17:42:10 +0000129 void Visit(Stmt *S);
Ted Kremenek411cdee2008-04-16 21:10:48 +0000130 void VisitTerminator(CFGBlock* B);
Ted Kremenek7deed0c2008-04-15 18:35:30 +0000131
132 void SetTopValue(LiveVariables::ValTy& V) {
Ted Kremenekbf98c992009-01-30 21:35:30 +0000133 V = AD.AlwaysLive;
Ted Kremenek7deed0c2008-04-15 18:35:30 +0000134 }
135
Ted Kremeneke4e63342007-09-06 00:17:54 +0000136};
Ted Kremenek11e72182007-10-01 20:33:52 +0000137
Ted Kremenek11e72182007-10-01 20:33:52 +0000138void TransferFuncs::Visit(Stmt *S) {
Ted Kremenekf63aa452007-09-28 20:38:59 +0000139
Ted Kremenek86946742008-01-17 20:48:37 +0000140 if (S == getCurrentBlkStmt()) {
Ted Kremenek03648652008-07-03 22:25:27 +0000141
142 if (AD.Observer)
143 AD.Observer->ObserveStmt(S,AD,LiveState);
144
Ted Kremenek1aa9a582008-03-05 19:26:46 +0000145 if (getCFG().isBlkExpr(S)) LiveState(S,AD) = Dead;
Ted Kremenek2a9da9c2008-01-18 00:40:21 +0000146 StmtVisitor<TransferFuncs,void>::Visit(S);
Ted Kremenek86946742008-01-17 20:48:37 +0000147 }
Ted Kremenek03648652008-07-03 22:25:27 +0000148 else if (!getCFG().isBlkExpr(S)) {
149
150 if (AD.Observer)
151 AD.Observer->ObserveStmt(S,AD,LiveState);
152
Ted Kremenek86946742008-01-17 20:48:37 +0000153 StmtVisitor<TransferFuncs,void>::Visit(S);
Ted Kremenek03648652008-07-03 22:25:27 +0000154
155 }
Ted Kremenek86946742008-01-17 20:48:37 +0000156 else
157 // For block-level expressions, mark that they are live.
158 LiveState(S,AD) = Alive;
Ted Kremenek11e72182007-10-01 20:33:52 +0000159}
Ted Kremenek37622082008-04-15 04:39:08 +0000160
Ted Kremenek411cdee2008-04-16 21:10:48 +0000161void TransferFuncs::VisitTerminator(CFGBlock* B) {
162
Ted Kremenek8ded8d82008-11-12 21:12:18 +0000163 const Stmt* E = B->getTerminatorCondition();
Ted Kremenek411cdee2008-04-16 21:10:48 +0000164
Ted Kremenek5cd24382008-04-16 17:07:59 +0000165 if (!E)
166 return;
167
Ted Kremenek5cd24382008-04-16 17:07:59 +0000168 assert (getCFG().isBlkExpr(E));
169 LiveState(E, AD) = Alive;
Ted Kremenek37622082008-04-15 04:39:08 +0000170}
171
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000172void TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
173 if (VarDecl* V = dyn_cast<VarDecl>(DR->getDecl()))
Ted Kremenekf63aa452007-09-28 20:38:59 +0000174 LiveState(V,AD) = Alive;
Ted Kremeneke4e63342007-09-06 00:17:54 +0000175}
Ted Kremeneke4e63342007-09-06 00:17:54 +0000176
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000177void TransferFuncs::VisitBinaryOperator(BinaryOperator* B) {
Ted Kremenekf1758052007-09-12 19:10:52 +0000178 if (B->isAssignmentOp()) VisitAssign(B);
179 else VisitStmt(B);
Ted Kremeneke4e63342007-09-06 00:17:54 +0000180}
181
Ted Kremenekbfcb7122008-11-12 21:58:46 +0000182void
183TransferFuncs::BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) {
184
Ted Kremenek06529ae2008-11-14 21:07:14 +0000185 // This is a block-level expression. Its value is 'dead' before this point.
186 LiveState(S, AD) = Dead;
187
Ted Kremeneke97d9db2008-11-11 19:40:47 +0000188 // This represents a 'use' of the collection.
189 Visit(S->getCollection());
Ted Kremenek8f5aab62008-11-11 17:42:10 +0000190
191 // This represents a 'kill' for the variable.
Ted Kremeneke97d9db2008-11-11 19:40:47 +0000192 Stmt* Element = S->getElement();
Ted Kremenek8f646002008-11-14 01:58:12 +0000193 DeclRefExpr* DR = 0;
Ted Kremeneke97d9db2008-11-11 19:40:47 +0000194 VarDecl* VD = 0;
195
196 if (DeclStmt* DS = dyn_cast<DeclStmt>(Element))
Chris Lattner7e24e822009-03-28 06:33:19 +0000197 VD = cast<VarDecl>(DS->getSingleDecl());
Ted Kremeneke97d9db2008-11-11 19:40:47 +0000198 else {
Ted Kremenek8f646002008-11-14 01:58:12 +0000199 Expr* ElemExpr = cast<Expr>(Element)->IgnoreParens();
200 if ((DR = dyn_cast<DeclRefExpr>(ElemExpr)))
201 VD = cast<VarDecl>(DR->getDecl());
Ted Kremenek06529ae2008-11-14 21:07:14 +0000202 else {
203 Visit(ElemExpr);
204 return;
205 }
Ted Kremeneke97d9db2008-11-11 19:40:47 +0000206 }
207
Ted Kremenek8f646002008-11-14 01:58:12 +0000208 if (VD) {
209 LiveState(VD, AD) = Dead;
210 if (AD.Observer && DR) { AD.Observer->ObserverKill(DR); }
211 }
Ted Kremenek8f5aab62008-11-11 17:42:10 +0000212}
213
214
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000215void TransferFuncs::VisitUnaryOperator(UnaryOperator* U) {
Ted Kremenek5e2b6092008-01-17 17:50:49 +0000216 Expr *E = U->getSubExpr();
Ted Kremenekbcb07d52007-09-28 21:29:33 +0000217
Ted Kremenek27b07c52007-09-06 21:26:58 +0000218 switch (U->getOpcode()) {
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000219 case UnaryOperator::PostInc:
220 case UnaryOperator::PostDec:
221 case UnaryOperator::PreInc:
222 case UnaryOperator::PreDec:
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000223 // Walk through the subexpressions, blasting through ParenExprs
224 // until we either find a DeclRefExpr or some non-DeclRefExpr
225 // expression.
Ted Kremenek56206312008-02-22 00:34:10 +0000226 if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(E->IgnoreParens()))
Ted Kremenekdace4c92008-04-15 04:08:54 +0000227 if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl())) {
228 // Treat the --/++ operator as a kill.
Ted Kremenek56206312008-02-22 00:34:10 +0000229 if (AD.Observer) { AD.Observer->ObserverKill(DR); }
Ted Kremenekdace4c92008-04-15 04:08:54 +0000230 LiveState(VD, AD) = Alive;
Ted Kremenek56206312008-02-22 00:34:10 +0000231 return VisitDeclRefExpr(DR);
232 }
Ted Kremenekbcb07d52007-09-28 21:29:33 +0000233
234 // Fall-through.
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000235
236 default:
Ted Kremenek5e2b6092008-01-17 17:50:49 +0000237 return Visit(E);
Ted Kremenek27b07c52007-09-06 21:26:58 +0000238 }
239}
Ted Kremenekbcb07d52007-09-28 21:29:33 +0000240
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000241void TransferFuncs::VisitAssign(BinaryOperator* B) {
Ted Kremenek5e2b6092008-01-17 17:50:49 +0000242 Expr* LHS = B->getLHS();
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000243
Ted Kremenekbcb07d52007-09-28 21:29:33 +0000244 // Assigning to a variable?
Ted Kremenek5e2b6092008-01-17 17:50:49 +0000245 if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(LHS->IgnoreParens())) {
Ted Kremenek7deed0c2008-04-15 18:35:30 +0000246
247 // Update liveness inforamtion.
248 unsigned bit = AD.getIdx(DR->getDecl());
249 LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
250
Ted Kremenekf63aa452007-09-28 20:38:59 +0000251 if (AD.Observer) { AD.Observer->ObserverKill(DR); }
252
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000253 // Handle things like +=, etc., which also generate "uses"
254 // of a variable. Do this just by visiting the subexpression.
Ted Kremenekbcb07d52007-09-28 21:29:33 +0000255 if (B->getOpcode() != BinaryOperator::Assign)
256 VisitDeclRefExpr(DR);
Ted Kremeneke4e63342007-09-06 00:17:54 +0000257 }
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000258 else // Not assigning to a variable. Process LHS as usual.
Ted Kremenek27b07c52007-09-06 21:26:58 +0000259 Visit(LHS);
Ted Kremeneke4e63342007-09-06 00:17:54 +0000260
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000261 Visit(B->getRHS());
Ted Kremeneke4e63342007-09-06 00:17:54 +0000262}
263
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000264void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
265 // Declarations effectively "kill" a variable since they cannot
266 // possibly be live before they are declared.
Ted Kremenek14f8b4f2008-08-05 20:46:55 +0000267 for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE = DS->decl_end();
268 DI != DE; ++DI)
269 if (VarDecl* VD = dyn_cast<VarDecl>(*DI)) {
Ted Kremenek84fa6b92008-09-26 05:52:45 +0000270 // The initializer is evaluated after the variable comes into scope.
271 // Since this is a reverse dataflow analysis, we must evaluate the
272 // transfer function for this expression first.
Ted Kremenek2bca5e42008-02-07 02:38:55 +0000273 if (Expr* Init = VD->getInit())
274 Visit(Init);
Ted Kremenek84fa6b92008-09-26 05:52:45 +0000275
Ted Kremeneke0dbda12008-12-09 00:14:14 +0000276 if (const VariableArrayType* VT =
277 AD.getContext().getAsVariableArrayType(VD->getType())) {
278 StmtIterator I(const_cast<VariableArrayType*>(VT));
279 StmtIterator E;
280 for (; I != E; ++I) Visit(*I);
281 }
282
Ted Kremenek84fa6b92008-09-26 05:52:45 +0000283 // Update liveness information by killing the VarDecl.
284 unsigned bit = AD.getIdx(VD);
285 LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
Ted Kremenekdcc48102008-02-25 22:28:54 +0000286 }
Ted Kremenek27b07c52007-09-06 21:26:58 +0000287}
Ted Kremenekf63aa452007-09-28 20:38:59 +0000288
Ted Kremeneke4e63342007-09-06 00:17:54 +0000289} // end anonymous namespace
290
Ted Kremenekf63aa452007-09-28 20:38:59 +0000291//===----------------------------------------------------------------------===//
292// Merge operator: if something is live on any successor block, it is live
293// in the current block (a set union).
294//===----------------------------------------------------------------------===//
Ted Kremeneke4e63342007-09-06 00:17:54 +0000295
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000296namespace {
Ted Kremenekfa59f1f2008-03-20 21:46:49 +0000297
298struct Merge {
Ted Kremenek8d798c72008-11-14 01:14:18 +0000299 typedef StmtDeclBitVector_Types::ValTy ValTy;
Ted Kremenekfa59f1f2008-03-20 21:46:49 +0000300
301 void operator()(ValTy& Dst, const ValTy& Src) {
302 Dst.OrDeclBits(Src);
Ted Kremenekbf98c992009-01-30 21:35:30 +0000303 Dst.OrBlkExprBits(Src);
Ted Kremenekfa59f1f2008-03-20 21:46:49 +0000304 }
305};
306
307typedef DataflowSolver<LiveVariables, TransferFuncs, Merge> Solver;
Ted Kremenekf63aa452007-09-28 20:38:59 +0000308} // end anonymous namespace
309
310//===----------------------------------------------------------------------===//
311// External interface to run Liveness analysis.
312//===----------------------------------------------------------------------===//
Ted Kremeneke4e63342007-09-06 00:17:54 +0000313
Ted Kremenek83c01da2008-01-11 00:40:29 +0000314void LiveVariables::runOnCFG(CFG& cfg) {
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000315 Solver S(*this);
316 S.runOnCFG(cfg);
317}
Ted Kremenek27b07c52007-09-06 21:26:58 +0000318
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000319void LiveVariables::runOnAllBlocks(const CFG& cfg,
Ted Kremenek79649df2008-01-17 18:25:22 +0000320 LiveVariables::ObserverTy* Obs,
321 bool recordStmtValues) {
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000322 Solver S(*this);
323 ObserverTy* OldObserver = getAnalysisData().Observer;
Ted Kremenek79649df2008-01-17 18:25:22 +0000324 getAnalysisData().Observer = Obs;
325 S.runOnAllBlocks(cfg, recordStmtValues);
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000326 getAnalysisData().Observer = OldObserver;
Ted Kremenek27b07c52007-09-06 21:26:58 +0000327}
328
329//===----------------------------------------------------------------------===//
330// liveness queries
331//
332
Ted Kremenekc0576ca2007-09-10 17:36:42 +0000333bool LiveVariables::isLive(const CFGBlock* B, const VarDecl* D) const {
Ted Kremenek7cb15932008-03-13 16:55:07 +0000334 DeclBitVector_Types::Idx i = getAnalysisData().getIdx(D);
335 return i.isValid() ? getBlockData(B).getBit(i) : false;
Ted Kremenek27b07c52007-09-06 21:26:58 +0000336}
337
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000338bool LiveVariables::isLive(const ValTy& Live, const VarDecl* D) const {
Ted Kremenek7cb15932008-03-13 16:55:07 +0000339 DeclBitVector_Types::Idx i = getAnalysisData().getIdx(D);
340 return i.isValid() ? Live.getBit(i) : false;
Ted Kremenek055c2752007-09-06 23:00:42 +0000341}
342
Ted Kremenek86946742008-01-17 20:48:37 +0000343bool LiveVariables::isLive(const Stmt* Loc, const Stmt* StmtVal) const {
344 return getStmtData(Loc)(StmtVal,getAnalysisData());
345}
346
Ted Kremenek2a9da9c2008-01-18 00:40:21 +0000347bool LiveVariables::isLive(const Stmt* Loc, const VarDecl* D) const {
348 return getStmtData(Loc)(D,getAnalysisData());
349}
350
Ted Kremenek055c2752007-09-06 23:00:42 +0000351//===----------------------------------------------------------------------===//
Ted Kremeneke4e63342007-09-06 00:17:54 +0000352// printing liveness state for debugging
353//
354
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000355void LiveVariables::dumpLiveness(const ValTy& V, SourceManager& SM) const {
356 const AnalysisDataTy& AD = getAnalysisData();
357
Ted Kremenekf63aa452007-09-28 20:38:59 +0000358 for (AnalysisDataTy::decl_iterator I = AD.begin_decl(),
359 E = AD.end_decl(); I!=E; ++I)
360 if (V.getDeclBit(I->second)) {
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000361 fprintf(stderr, " %s <", I->first->getIdentifier()->getName());
362 I->first->getLocation().dump(SM);
363 fprintf(stderr, ">\n");
Ted Kremeneke4e63342007-09-06 00:17:54 +0000364 }
Ted Kremeneke4e63342007-09-06 00:17:54 +0000365}
366
Ted Kremenek27b07c52007-09-06 21:26:58 +0000367void LiveVariables::dumpBlockLiveness(SourceManager& M) const {
Ted Kremenekfdd225e2007-09-25 04:31:27 +0000368 for (BlockDataMapTy::iterator I = getBlockDataMap().begin(),
369 E = getBlockDataMap().end(); I!=E; ++I) {
370 fprintf(stderr, "\n[ B%d (live variables at block exit) ]\n",
Ted Kremenek27b07c52007-09-06 21:26:58 +0000371 I->first->getBlockID());
372
373 dumpLiveness(I->second,M);
374 }
Ted Kremenekc0576ca2007-09-10 17:36:42 +0000375
376 fprintf(stderr,"\n");
377}