2007-09-21 05:42:55 +08:00
|
|
|
//=- LiveVariables.cpp - Live Variable Analysis for Source CFGs -*- C++ --*-==//
|
2007-09-06 08:17:54 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-09-06 08:17:54 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements Live Variables analysis for source-level CFGs.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-12-22 05:42:19 +08:00
|
|
|
#include "clang/Analysis/Analyses/LiveVariables.h"
|
2007-09-07 05:26:58 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2008-12-09 08:14:14 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2007-09-06 08:17:54 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
#include "clang/AST/CFG.h"
|
2007-09-25 12:31:27 +08:00
|
|
|
#include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h"
|
2007-09-26 05:00:24 +08:00
|
|
|
#include "clang/Analysis/FlowSensitive/DataflowSolver.h"
|
2007-09-06 08:17:54 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2008-04-16 02:35:30 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2008-01-09 02:19:08 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2007-09-06 08:17:54 +08:00
|
|
|
|
2007-09-07 05:26:58 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2007-09-06 08:17:54 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2008-04-16 02:35:30 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Useful constants.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static const bool Alive = true;
|
|
|
|
static const bool Dead = false;
|
|
|
|
|
2007-09-06 08:17:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-09-25 12:31:27 +08:00
|
|
|
// Dataflow initialization logic.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-09-06 08:17:54 +08:00
|
|
|
|
|
|
|
namespace {
|
2008-01-09 02:19:08 +08:00
|
|
|
class VISIBILITY_HIDDEN RegisterDecls
|
|
|
|
: public CFGRecStmtDeclVisitor<RegisterDecls> {
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
LiveVariables::AnalysisDataTy& AD;
|
2008-04-16 02:35:30 +08:00
|
|
|
|
|
|
|
typedef llvm::SmallVector<VarDecl*, 20> AlwaysLiveTy;
|
|
|
|
AlwaysLiveTy AlwaysLive;
|
|
|
|
|
|
|
|
|
2007-09-29 04:38:59 +08:00
|
|
|
public:
|
2008-04-16 02:35:30 +08:00
|
|
|
RegisterDecls(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
|
|
|
|
|
|
|
|
~RegisterDecls() {
|
|
|
|
|
|
|
|
AD.AlwaysLive.resetValues(AD);
|
|
|
|
|
|
|
|
for (AlwaysLiveTy::iterator I = AlwaysLive.begin(), E = AlwaysLive.end();
|
|
|
|
I != E; ++ I)
|
|
|
|
AD.AlwaysLive(*I, AD) = Alive;
|
|
|
|
}
|
|
|
|
|
2008-06-18 02:05:57 +08:00
|
|
|
void VisitImplicitParamDecl(ImplicitParamDecl* IPD) {
|
|
|
|
// Register the VarDecl for tracking.
|
|
|
|
AD.Register(IPD);
|
|
|
|
}
|
|
|
|
|
2008-04-16 02:35:30 +08:00
|
|
|
void VisitVarDecl(VarDecl* VD) {
|
|
|
|
// Register the VarDecl for tracking.
|
|
|
|
AD.Register(VD);
|
|
|
|
|
|
|
|
// Does the variable have global storage? If so, it is always live.
|
|
|
|
if (VD->hasGlobalStorage())
|
|
|
|
AlwaysLive.push_back(VD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisitUnaryOperator(UnaryOperator* U) {
|
|
|
|
// Check for '&'. Any VarDecl whose value has its address-taken we
|
|
|
|
// treat as always being live (flow-insensitive).
|
|
|
|
|
|
|
|
Expr* E = U->getSubExpr()->IgnoreParenCasts();
|
|
|
|
|
|
|
|
if (U->getOpcode() == UnaryOperator::AddrOf)
|
|
|
|
if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(E))
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl())) {
|
|
|
|
AD.Register(VD);
|
|
|
|
AlwaysLive.push_back(VD);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Visit(E);
|
|
|
|
}
|
|
|
|
|
2007-11-20 11:01:58 +08:00
|
|
|
CFG& getCFG() { return AD.getCFG(); }
|
2007-10-02 04:33:52 +08:00
|
|
|
};
|
2007-09-25 12:31:27 +08:00
|
|
|
} // end anonymous namespace
|
2007-09-06 08:17:54 +08:00
|
|
|
|
2008-01-29 13:13:23 +08:00
|
|
|
|
2008-12-09 08:14:14 +08:00
|
|
|
LiveVariables::LiveVariables(ASTContext& Ctx, CFG& cfg) {
|
2008-03-14 00:55:07 +08:00
|
|
|
// Register all referenced VarDecls.
|
2008-12-09 08:14:14 +08:00
|
|
|
getAnalysisData().setCFG(cfg);
|
|
|
|
getAnalysisData().setContext(Ctx);
|
|
|
|
|
2007-10-02 04:33:52 +08:00
|
|
|
RegisterDecls R(getAnalysisData());
|
2007-09-25 12:31:27 +08:00
|
|
|
cfg.VisitBlockStmts(R);
|
2007-09-06 08:17:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-09-25 12:31:27 +08:00
|
|
|
// Transfer functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-09-06 08:17:54 +08:00
|
|
|
|
|
|
|
namespace {
|
2007-09-29 04:38:59 +08:00
|
|
|
|
2008-01-09 02:19:08 +08:00
|
|
|
class VISIBILITY_HIDDEN TransferFuncs : public CFGRecStmtVisitor<TransferFuncs>{
|
2007-09-25 12:31:27 +08:00
|
|
|
LiveVariables::AnalysisDataTy& AD;
|
2007-09-29 04:38:59 +08:00
|
|
|
LiveVariables::ValTy LiveState;
|
2007-09-06 08:17:54 +08:00
|
|
|
public:
|
2007-10-02 04:33:52 +08:00
|
|
|
TransferFuncs(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
|
2007-09-06 08:17:54 +08:00
|
|
|
|
2007-09-29 04:38:59 +08:00
|
|
|
LiveVariables::ValTy& getVal() { return LiveState; }
|
2007-11-20 11:01:58 +08:00
|
|
|
CFG& getCFG() { return AD.getCFG(); }
|
2007-09-13 03:10:52 +08:00
|
|
|
|
2007-09-06 08:17:54 +08:00
|
|
|
void VisitDeclRefExpr(DeclRefExpr* DR);
|
|
|
|
void VisitBinaryOperator(BinaryOperator* B);
|
|
|
|
void VisitAssign(BinaryOperator* B);
|
2007-09-07 05:26:58 +08:00
|
|
|
void VisitDeclStmt(DeclStmt* DS);
|
2008-11-13 05:58:46 +08:00
|
|
|
void BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt* S);
|
2007-09-07 05:26:58 +08:00
|
|
|
void VisitUnaryOperator(UnaryOperator* U);
|
2008-11-12 01:42:10 +08:00
|
|
|
void Visit(Stmt *S);
|
2008-04-17 05:10:48 +08:00
|
|
|
void VisitTerminator(CFGBlock* B);
|
2008-04-16 02:35:30 +08:00
|
|
|
|
|
|
|
void SetTopValue(LiveVariables::ValTy& V) {
|
2009-01-31 05:35:30 +08:00
|
|
|
V = AD.AlwaysLive;
|
2008-04-16 02:35:30 +08:00
|
|
|
}
|
|
|
|
|
2007-09-06 08:17:54 +08:00
|
|
|
};
|
2007-10-02 04:33:52 +08:00
|
|
|
|
|
|
|
void TransferFuncs::Visit(Stmt *S) {
|
2007-09-29 04:38:59 +08:00
|
|
|
|
2008-01-18 04:48:37 +08:00
|
|
|
if (S == getCurrentBlkStmt()) {
|
2008-07-04 06:25:27 +08:00
|
|
|
|
|
|
|
if (AD.Observer)
|
|
|
|
AD.Observer->ObserveStmt(S,AD,LiveState);
|
|
|
|
|
2008-03-06 03:26:46 +08:00
|
|
|
if (getCFG().isBlkExpr(S)) LiveState(S,AD) = Dead;
|
2008-01-18 08:40:21 +08:00
|
|
|
StmtVisitor<TransferFuncs,void>::Visit(S);
|
2008-01-18 04:48:37 +08:00
|
|
|
}
|
2008-07-04 06:25:27 +08:00
|
|
|
else if (!getCFG().isBlkExpr(S)) {
|
|
|
|
|
|
|
|
if (AD.Observer)
|
|
|
|
AD.Observer->ObserveStmt(S,AD,LiveState);
|
|
|
|
|
2008-01-18 04:48:37 +08:00
|
|
|
StmtVisitor<TransferFuncs,void>::Visit(S);
|
2008-07-04 06:25:27 +08:00
|
|
|
|
|
|
|
}
|
2008-01-18 04:48:37 +08:00
|
|
|
else
|
|
|
|
// For block-level expressions, mark that they are live.
|
|
|
|
LiveState(S,AD) = Alive;
|
2007-10-02 04:33:52 +08:00
|
|
|
}
|
2008-04-15 12:39:08 +08:00
|
|
|
|
2008-04-17 05:10:48 +08:00
|
|
|
void TransferFuncs::VisitTerminator(CFGBlock* B) {
|
|
|
|
|
2008-11-13 05:12:18 +08:00
|
|
|
const Stmt* E = B->getTerminatorCondition();
|
2008-04-17 05:10:48 +08:00
|
|
|
|
2008-04-17 01:07:59 +08:00
|
|
|
if (!E)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert (getCFG().isBlkExpr(E));
|
|
|
|
LiveState(E, AD) = Alive;
|
2008-04-15 12:39:08 +08:00
|
|
|
}
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
void TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
|
|
|
|
if (VarDecl* V = dyn_cast<VarDecl>(DR->getDecl()))
|
2007-09-29 04:38:59 +08:00
|
|
|
LiveState(V,AD) = Alive;
|
2007-09-06 08:17:54 +08:00
|
|
|
}
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
void TransferFuncs::VisitBinaryOperator(BinaryOperator* B) {
|
2007-09-13 03:10:52 +08:00
|
|
|
if (B->isAssignmentOp()) VisitAssign(B);
|
|
|
|
else VisitStmt(B);
|
2007-09-06 08:17:54 +08:00
|
|
|
}
|
|
|
|
|
2008-11-13 05:58:46 +08:00
|
|
|
void
|
|
|
|
TransferFuncs::BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) {
|
|
|
|
|
2008-11-15 05:07:14 +08:00
|
|
|
// This is a block-level expression. Its value is 'dead' before this point.
|
|
|
|
LiveState(S, AD) = Dead;
|
|
|
|
|
2008-11-12 03:40:47 +08:00
|
|
|
// This represents a 'use' of the collection.
|
|
|
|
Visit(S->getCollection());
|
|
|
|
|
|
|
|
// This represents a 'kill' for the variable.
|
2008-11-12 01:42:10 +08:00
|
|
|
Stmt* Element = S->getElement();
|
2008-11-14 09:58:12 +08:00
|
|
|
DeclRefExpr* DR = 0;
|
2008-11-12 03:40:47 +08:00
|
|
|
VarDecl* VD = 0;
|
2008-11-12 01:42:10 +08:00
|
|
|
|
2008-11-12 03:40:47 +08:00
|
|
|
if (DeclStmt* DS = dyn_cast<DeclStmt>(Element))
|
|
|
|
VD = cast<VarDecl>(DS->getSolitaryDecl());
|
|
|
|
else {
|
2008-11-14 09:58:12 +08:00
|
|
|
Expr* ElemExpr = cast<Expr>(Element)->IgnoreParens();
|
|
|
|
if ((DR = dyn_cast<DeclRefExpr>(ElemExpr)))
|
|
|
|
VD = cast<VarDecl>(DR->getDecl());
|
2008-11-15 05:07:14 +08:00
|
|
|
else {
|
|
|
|
Visit(ElemExpr);
|
|
|
|
return;
|
|
|
|
}
|
2008-11-12 01:42:10 +08:00
|
|
|
}
|
2008-11-12 03:40:47 +08:00
|
|
|
|
2008-11-14 09:58:12 +08:00
|
|
|
if (VD) {
|
|
|
|
LiveState(VD, AD) = Dead;
|
|
|
|
if (AD.Observer && DR) { AD.Observer->ObserverKill(DR); }
|
|
|
|
}
|
2008-11-12 01:42:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
void TransferFuncs::VisitUnaryOperator(UnaryOperator* U) {
|
2008-01-18 01:50:49 +08:00
|
|
|
Expr *E = U->getSubExpr();
|
2007-09-29 05:29:33 +08:00
|
|
|
|
2007-09-07 05:26:58 +08:00
|
|
|
switch (U->getOpcode()) {
|
2007-09-25 12:31:27 +08:00
|
|
|
case UnaryOperator::PostInc:
|
|
|
|
case UnaryOperator::PostDec:
|
|
|
|
case UnaryOperator::PreInc:
|
|
|
|
case UnaryOperator::PreDec:
|
|
|
|
// Walk through the subexpressions, blasting through ParenExprs
|
|
|
|
// until we either find a DeclRefExpr or some non-DeclRefExpr
|
|
|
|
// expression.
|
2008-02-22 08:34:10 +08:00
|
|
|
if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(E->IgnoreParens()))
|
2008-04-15 12:08:54 +08:00
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl())) {
|
|
|
|
// Treat the --/++ operator as a kill.
|
2008-02-22 08:34:10 +08:00
|
|
|
if (AD.Observer) { AD.Observer->ObserverKill(DR); }
|
2008-04-15 12:08:54 +08:00
|
|
|
LiveState(VD, AD) = Alive;
|
2008-02-22 08:34:10 +08:00
|
|
|
return VisitDeclRefExpr(DR);
|
|
|
|
}
|
2007-09-29 05:29:33 +08:00
|
|
|
|
|
|
|
// Fall-through.
|
2007-09-25 12:31:27 +08:00
|
|
|
|
|
|
|
default:
|
2008-01-18 01:50:49 +08:00
|
|
|
return Visit(E);
|
2007-09-07 05:26:58 +08:00
|
|
|
}
|
|
|
|
}
|
2007-09-29 05:29:33 +08:00
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
void TransferFuncs::VisitAssign(BinaryOperator* B) {
|
2008-01-18 01:50:49 +08:00
|
|
|
Expr* LHS = B->getLHS();
|
2007-09-25 12:31:27 +08:00
|
|
|
|
2007-09-29 05:29:33 +08:00
|
|
|
// Assigning to a variable?
|
2008-01-18 01:50:49 +08:00
|
|
|
if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(LHS->IgnoreParens())) {
|
2008-04-16 02:35:30 +08:00
|
|
|
|
|
|
|
// Update liveness inforamtion.
|
|
|
|
unsigned bit = AD.getIdx(DR->getDecl());
|
|
|
|
LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
|
|
|
|
|
2007-09-29 04:38:59 +08:00
|
|
|
if (AD.Observer) { AD.Observer->ObserverKill(DR); }
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
// Handle things like +=, etc., which also generate "uses"
|
|
|
|
// of a variable. Do this just by visiting the subexpression.
|
2007-09-29 05:29:33 +08:00
|
|
|
if (B->getOpcode() != BinaryOperator::Assign)
|
|
|
|
VisitDeclRefExpr(DR);
|
2007-09-06 08:17:54 +08:00
|
|
|
}
|
2007-09-25 12:31:27 +08:00
|
|
|
else // Not assigning to a variable. Process LHS as usual.
|
2007-09-07 05:26:58 +08:00
|
|
|
Visit(LHS);
|
2007-09-06 08:17:54 +08:00
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
Visit(B->getRHS());
|
2007-09-06 08:17:54 +08:00
|
|
|
}
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
|
|
|
|
// Declarations effectively "kill" a variable since they cannot
|
|
|
|
// possibly be live before they are declared.
|
2008-08-06 04:46:55 +08:00
|
|
|
for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE = DS->decl_end();
|
|
|
|
DI != DE; ++DI)
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(*DI)) {
|
2008-09-26 13:52:45 +08:00
|
|
|
// The initializer is evaluated after the variable comes into scope.
|
|
|
|
// Since this is a reverse dataflow analysis, we must evaluate the
|
|
|
|
// transfer function for this expression first.
|
|
|
|
if (Expr* Init = VD->getInit())
|
|
|
|
Visit(Init);
|
2008-04-16 02:35:30 +08:00
|
|
|
|
2008-12-09 08:14:14 +08:00
|
|
|
if (const VariableArrayType* VT =
|
|
|
|
AD.getContext().getAsVariableArrayType(VD->getType())) {
|
|
|
|
StmtIterator I(const_cast<VariableArrayType*>(VT));
|
|
|
|
StmtIterator E;
|
|
|
|
for (; I != E; ++I) Visit(*I);
|
|
|
|
}
|
|
|
|
|
2008-09-26 13:52:45 +08:00
|
|
|
// Update liveness information by killing the VarDecl.
|
2008-04-16 02:35:30 +08:00
|
|
|
unsigned bit = AD.getIdx(VD);
|
|
|
|
LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
|
2008-02-26 06:28:54 +08:00
|
|
|
}
|
2007-09-29 04:38:59 +08:00
|
|
|
}
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
} // end anonymous namespace
|
2007-09-06 08:17:54 +08:00
|
|
|
|
2007-09-29 04:38:59 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Merge operator: if something is live on any successor block, it is live
|
|
|
|
// in the current block (a set union).
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-09-06 08:17:54 +08:00
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
namespace {
|
2008-03-21 05:46:49 +08:00
|
|
|
|
|
|
|
struct Merge {
|
2008-11-14 09:14:18 +08:00
|
|
|
typedef StmtDeclBitVector_Types::ValTy ValTy;
|
2008-03-21 05:46:49 +08:00
|
|
|
|
|
|
|
void operator()(ValTy& Dst, const ValTy& Src) {
|
|
|
|
Dst.OrDeclBits(Src);
|
2009-01-31 05:35:30 +08:00
|
|
|
Dst.OrBlkExprBits(Src);
|
2008-03-21 05:46:49 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef DataflowSolver<LiveVariables, TransferFuncs, Merge> Solver;
|
2007-09-29 04:38:59 +08:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// External interface to run Liveness analysis.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-09-06 08:17:54 +08:00
|
|
|
|
2008-01-11 08:40:29 +08:00
|
|
|
void LiveVariables::runOnCFG(CFG& cfg) {
|
2007-09-25 12:31:27 +08:00
|
|
|
Solver S(*this);
|
|
|
|
S.runOnCFG(cfg);
|
|
|
|
}
|
2007-09-07 05:26:58 +08:00
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
void LiveVariables::runOnAllBlocks(const CFG& cfg,
|
2008-01-18 02:25:22 +08:00
|
|
|
LiveVariables::ObserverTy* Obs,
|
|
|
|
bool recordStmtValues) {
|
2007-09-25 12:31:27 +08:00
|
|
|
Solver S(*this);
|
|
|
|
ObserverTy* OldObserver = getAnalysisData().Observer;
|
2008-01-18 02:25:22 +08:00
|
|
|
getAnalysisData().Observer = Obs;
|
|
|
|
S.runOnAllBlocks(cfg, recordStmtValues);
|
2007-09-25 12:31:27 +08:00
|
|
|
getAnalysisData().Observer = OldObserver;
|
2007-09-07 05:26:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// liveness queries
|
|
|
|
//
|
|
|
|
|
2007-09-11 01:36:42 +08:00
|
|
|
bool LiveVariables::isLive(const CFGBlock* B, const VarDecl* D) const {
|
2008-03-14 00:55:07 +08:00
|
|
|
DeclBitVector_Types::Idx i = getAnalysisData().getIdx(D);
|
|
|
|
return i.isValid() ? getBlockData(B).getBit(i) : false;
|
2007-09-07 05:26:58 +08:00
|
|
|
}
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
bool LiveVariables::isLive(const ValTy& Live, const VarDecl* D) const {
|
2008-03-14 00:55:07 +08:00
|
|
|
DeclBitVector_Types::Idx i = getAnalysisData().getIdx(D);
|
|
|
|
return i.isValid() ? Live.getBit(i) : false;
|
2007-09-07 07:00:42 +08:00
|
|
|
}
|
|
|
|
|
2008-01-18 04:48:37 +08:00
|
|
|
bool LiveVariables::isLive(const Stmt* Loc, const Stmt* StmtVal) const {
|
|
|
|
return getStmtData(Loc)(StmtVal,getAnalysisData());
|
|
|
|
}
|
|
|
|
|
2008-01-18 08:40:21 +08:00
|
|
|
bool LiveVariables::isLive(const Stmt* Loc, const VarDecl* D) const {
|
|
|
|
return getStmtData(Loc)(D,getAnalysisData());
|
|
|
|
}
|
|
|
|
|
2007-09-07 07:00:42 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-09-06 08:17:54 +08:00
|
|
|
// printing liveness state for debugging
|
|
|
|
//
|
|
|
|
|
2007-09-25 12:31:27 +08:00
|
|
|
void LiveVariables::dumpLiveness(const ValTy& V, SourceManager& SM) const {
|
|
|
|
const AnalysisDataTy& AD = getAnalysisData();
|
|
|
|
|
2007-09-29 04:38:59 +08:00
|
|
|
for (AnalysisDataTy::decl_iterator I = AD.begin_decl(),
|
|
|
|
E = AD.end_decl(); I!=E; ++I)
|
|
|
|
if (V.getDeclBit(I->second)) {
|
2009-01-27 15:57:44 +08:00
|
|
|
fprintf(stderr, " %s <", I->first->getIdentifier()->getName());
|
|
|
|
I->first->getLocation().dump(SM);
|
|
|
|
fprintf(stderr, ">\n");
|
2007-09-06 08:17:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-07 05:26:58 +08:00
|
|
|
void LiveVariables::dumpBlockLiveness(SourceManager& M) const {
|
2007-09-25 12:31:27 +08:00
|
|
|
for (BlockDataMapTy::iterator I = getBlockDataMap().begin(),
|
|
|
|
E = getBlockDataMap().end(); I!=E; ++I) {
|
|
|
|
fprintf(stderr, "\n[ B%d (live variables at block exit) ]\n",
|
2007-09-07 05:26:58 +08:00
|
|
|
I->first->getBlockID());
|
|
|
|
|
|
|
|
dumpLiveness(I->second,M);
|
|
|
|
}
|
2007-09-11 01:36:42 +08:00
|
|
|
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
}
|