2009-06-02 17:58:47 +00:00
|
|
|
//=- LiveVariables.cpp - Live Variable Analysis for Source CFGs -*- C++ --*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements Live Variables analysis for source-level CFGs.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Analysis/Analyses/LiveVariables.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Expr.h"
|
2009-10-14 18:03:49 +00:00
|
|
|
#include "clang/Analysis/CFG.h"
|
2009-06-02 17:58:47 +00:00
|
|
|
#include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h"
|
|
|
|
#include "clang/Analysis/FlowSensitive/DataflowSolver.h"
|
2009-11-18 14:59:57 +00:00
|
|
|
#include "clang/Analysis/Support/SaveAndRestore.h"
|
2010-02-16 09:31:36 +00:00
|
|
|
#include "clang/Analysis/AnalysisContext.h"
|
2009-06-02 17:58:47 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-10-23 14:22:18 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Useful constants.
|
2009-10-14 18:03:49 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
static const bool Alive = true;
|
2009-10-14 18:03:49 +00:00
|
|
|
static const bool Dead = false;
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Dataflow initialization logic.
|
2009-10-14 18:03:49 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
namespace {
|
2009-12-01 11:08:04 +00:00
|
|
|
class RegisterDecls
|
2009-06-02 17:58:47 +00:00
|
|
|
: public CFGRecStmtDeclVisitor<RegisterDecls> {
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
LiveVariables::AnalysisDataTy& AD;
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
typedef llvm::SmallVector<VarDecl*, 20> AlwaysLiveTy;
|
|
|
|
AlwaysLiveTy AlwaysLive;
|
|
|
|
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
public:
|
|
|
|
RegisterDecls(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
|
|
|
|
|
|
|
|
~RegisterDecls() {
|
|
|
|
|
|
|
|
AD.AlwaysLive.resetValues(AD);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
for (AlwaysLiveTy::iterator I = AlwaysLive.begin(), E = AlwaysLive.end();
|
2009-10-14 18:03:49 +00:00
|
|
|
I != E; ++ I)
|
|
|
|
AD.AlwaysLive(*I, AD) = Alive;
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisitImplicitParamDecl(ImplicitParamDecl* IPD) {
|
|
|
|
// Register the VarDecl for tracking.
|
|
|
|
AD.Register(IPD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisitVarDecl(VarDecl* VD) {
|
|
|
|
// Register the VarDecl for tracking.
|
|
|
|
AD.Register(VD);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
// Does the variable have global storage? If so, it is always live.
|
|
|
|
if (VD->hasGlobalStorage())
|
2009-10-14 18:03:49 +00:00
|
|
|
AlwaysLive.push_back(VD);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
CFG& getCFG() { return AD.getCFG(); }
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2010-09-17 15:54:40 +00:00
|
|
|
LiveVariables::LiveVariables(AnalysisContext &AC, bool killAtAssign) {
|
2009-06-02 17:58:47 +00:00
|
|
|
// Register all referenced VarDecls.
|
2009-12-01 11:08:04 +00:00
|
|
|
CFG &cfg = *AC.getCFG();
|
2009-06-02 17:58:47 +00:00
|
|
|
getAnalysisData().setCFG(cfg);
|
2009-12-01 11:08:04 +00:00
|
|
|
getAnalysisData().setContext(AC.getASTContext());
|
|
|
|
getAnalysisData().AC = &AC;
|
2010-09-17 15:54:40 +00:00
|
|
|
getAnalysisData().killAtAssign = killAtAssign;
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
RegisterDecls R(getAnalysisData());
|
|
|
|
cfg.VisitBlockStmts(R);
|
2010-03-03 17:28:16 +00:00
|
|
|
|
|
|
|
// Register all parameters even if they didn't occur in the function body.
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(AC.getDecl()))
|
|
|
|
for (FunctionDecl::param_const_iterator PI = FD->param_begin(),
|
|
|
|
PE = FD->param_end(); PI != PE; ++PI)
|
|
|
|
getAnalysisData().Register(*PI);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transfer functions.
|
2009-10-14 18:03:49 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-12-01 11:08:04 +00:00
|
|
|
class TransferFuncs : public CFGRecStmtVisitor<TransferFuncs>{
|
2009-06-02 17:58:47 +00:00
|
|
|
LiveVariables::AnalysisDataTy& AD;
|
|
|
|
LiveVariables::ValTy LiveState;
|
|
|
|
public:
|
|
|
|
TransferFuncs(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
|
|
|
|
|
|
|
|
LiveVariables::ValTy& getVal() { return LiveState; }
|
|
|
|
CFG& getCFG() { return AD.getCFG(); }
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
void VisitDeclRefExpr(DeclRefExpr* DR);
|
|
|
|
void VisitBinaryOperator(BinaryOperator* B);
|
2009-12-01 11:08:04 +00:00
|
|
|
void VisitBlockExpr(BlockExpr *B);
|
2009-06-02 17:58:47 +00:00
|
|
|
void VisitAssign(BinaryOperator* B);
|
|
|
|
void VisitDeclStmt(DeclStmt* DS);
|
|
|
|
void BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt* S);
|
|
|
|
void VisitUnaryOperator(UnaryOperator* U);
|
2009-10-14 18:03:49 +00:00
|
|
|
void Visit(Stmt *S);
|
|
|
|
void VisitTerminator(CFGBlock* B);
|
2010-01-01 10:34:51 +00:00
|
|
|
|
|
|
|
/// VisitConditionVariableInit - Handle the initialization of condition
|
|
|
|
/// variables at branches. Valid statements include IfStmt, ForStmt,
|
|
|
|
/// WhileStmt, and SwitchStmt.
|
|
|
|
void VisitConditionVariableInit(Stmt *S);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
void SetTopValue(LiveVariables::ValTy& V) {
|
|
|
|
V = AD.AlwaysLive;
|
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
};
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
void TransferFuncs::Visit(Stmt *S) {
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
if (S == getCurrentBlkStmt()) {
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
if (AD.Observer)
|
|
|
|
AD.Observer->ObserveStmt(S,AD,LiveState);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2010-01-01 10:34:51 +00:00
|
|
|
if (getCFG().isBlkExpr(S))
|
|
|
|
LiveState(S, AD) = Dead;
|
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
StmtVisitor<TransferFuncs,void>::Visit(S);
|
|
|
|
}
|
|
|
|
else if (!getCFG().isBlkExpr(S)) {
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
if (AD.Observer)
|
|
|
|
AD.Observer->ObserveStmt(S,AD,LiveState);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
StmtVisitor<TransferFuncs,void>::Visit(S);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2009-07-04 13:58:54 +00:00
|
|
|
else {
|
2009-06-02 17:58:47 +00:00
|
|
|
// For block-level expressions, mark that they are live.
|
|
|
|
LiveState(S,AD) = Alive;
|
2009-07-04 13:58:54 +00:00
|
|
|
}
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2010-01-01 10:34:51 +00:00
|
|
|
|
|
|
|
void TransferFuncs::VisitConditionVariableInit(Stmt *S) {
|
|
|
|
assert(!getCFG().isBlkExpr(S));
|
|
|
|
CFGRecStmtVisitor<TransferFuncs>::VisitConditionVariableInit(S);
|
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
void TransferFuncs::VisitTerminator(CFGBlock* B) {
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
const Stmt* E = B->getTerminatorCondition();
|
|
|
|
|
|
|
|
if (!E)
|
|
|
|
return;
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
assert (getCFG().isBlkExpr(E));
|
|
|
|
LiveState(E, AD) = Alive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
|
2009-10-14 18:03:49 +00:00
|
|
|
if (VarDecl* V = dyn_cast<VarDecl>(DR->getDecl()))
|
2009-12-01 11:08:04 +00:00
|
|
|
LiveState(V, AD) = Alive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferFuncs::VisitBlockExpr(BlockExpr *BE) {
|
|
|
|
AnalysisContext::referenced_decls_iterator I, E;
|
|
|
|
llvm::tie(I, E) = AD.AC->getReferencedBlockVars(BE->getBlockDecl());
|
|
|
|
for ( ; I != E ; ++I) {
|
|
|
|
DeclBitVector_Types::Idx i = AD.getIdx(*I);
|
|
|
|
if (i.isValid())
|
|
|
|
LiveState.getBit(i) = Alive;
|
|
|
|
}
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
|
|
|
void TransferFuncs::VisitBinaryOperator(BinaryOperator* B) {
|
2009-06-02 17:58:47 +00:00
|
|
|
if (B->isAssignmentOp()) VisitAssign(B);
|
|
|
|
else VisitStmt(B);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TransferFuncs::BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) {
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
// This is a block-level expression. Its value is 'dead' before this point.
|
|
|
|
LiveState(S, AD) = Dead;
|
|
|
|
|
|
|
|
// This represents a 'use' of the collection.
|
|
|
|
Visit(S->getCollection());
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
// This represents a 'kill' for the variable.
|
|
|
|
Stmt* Element = S->getElement();
|
|
|
|
DeclRefExpr* DR = 0;
|
|
|
|
VarDecl* VD = 0;
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
if (DeclStmt* DS = dyn_cast<DeclStmt>(Element))
|
|
|
|
VD = cast<VarDecl>(DS->getSingleDecl());
|
|
|
|
else {
|
2009-10-14 18:03:49 +00:00
|
|
|
Expr* ElemExpr = cast<Expr>(Element)->IgnoreParens();
|
2009-06-02 17:58:47 +00:00
|
|
|
if ((DR = dyn_cast<DeclRefExpr>(ElemExpr)))
|
|
|
|
VD = cast<VarDecl>(DR->getDecl());
|
|
|
|
else {
|
|
|
|
Visit(ElemExpr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VD) {
|
|
|
|
LiveState(VD, AD) = Dead;
|
|
|
|
if (AD.Observer && DR) { AD.Observer->ObserverKill(DR); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
void TransferFuncs::VisitUnaryOperator(UnaryOperator* U) {
|
|
|
|
Expr *E = U->getSubExpr();
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
switch (U->getOpcode()) {
|
2010-09-17 15:54:40 +00:00
|
|
|
case UO_PostInc:
|
|
|
|
case UO_PostDec:
|
|
|
|
case UO_PreInc:
|
|
|
|
case UO_PreDec:
|
2009-06-02 17:58:47 +00:00
|
|
|
// Walk through the subexpressions, blasting through ParenExprs
|
|
|
|
// until we either find a DeclRefExpr or some non-DeclRefExpr
|
|
|
|
// expression.
|
2009-10-14 18:03:49 +00:00
|
|
|
if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(E->IgnoreParens()))
|
2009-06-02 17:58:47 +00:00
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl())) {
|
|
|
|
// Treat the --/++ operator as a kill.
|
|
|
|
if (AD.Observer) { AD.Observer->ObserverKill(DR); }
|
|
|
|
LiveState(VD, AD) = Alive;
|
|
|
|
return VisitDeclRefExpr(DR);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall-through.
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
default:
|
|
|
|
return Visit(E);
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
|
|
|
void TransferFuncs::VisitAssign(BinaryOperator* B) {
|
2009-06-02 17:58:47 +00:00
|
|
|
Expr* LHS = B->getLHS();
|
|
|
|
|
|
|
|
// Assigning to a variable?
|
|
|
|
if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(LHS->IgnoreParens())) {
|
2010-07-13 17:21:42 +00:00
|
|
|
// Assignments to references don't kill the ref's address
|
|
|
|
if (DR->getDecl()->getType()->isReferenceType()) {
|
|
|
|
VisitDeclRefExpr(DR);
|
|
|
|
} else {
|
2010-09-17 15:54:40 +00:00
|
|
|
if (AD.killAtAssign) {
|
|
|
|
// Update liveness inforamtion.
|
|
|
|
unsigned bit = AD.getIdx(DR->getDecl());
|
|
|
|
LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2010-09-17 15:54:40 +00:00
|
|
|
if (AD.Observer) { AD.Observer->ObserverKill(DR); }
|
|
|
|
}
|
2010-07-13 17:21:42 +00:00
|
|
|
// Handle things like +=, etc., which also generate "uses"
|
|
|
|
// of a variable. Do this just by visiting the subexpression.
|
2010-09-17 15:54:40 +00:00
|
|
|
if (B->getOpcode() != BO_Assign)
|
2010-07-13 17:21:42 +00:00
|
|
|
VisitDeclRefExpr(DR);
|
|
|
|
}
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
else // Not assigning to a variable. Process LHS as usual.
|
|
|
|
Visit(LHS);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
Visit(B->getRHS());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
|
|
|
|
// Declarations effectively "kill" a variable since they cannot
|
|
|
|
// possibly be live before they are declared.
|
|
|
|
for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE = DS->decl_end();
|
|
|
|
DI != DE; ++DI)
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(*DI)) {
|
2010-03-03 17:28:16 +00:00
|
|
|
// Update liveness information by killing the VarDecl.
|
|
|
|
unsigned bit = AD.getIdx(VD);
|
|
|
|
LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
|
|
|
|
|
|
|
|
// The initializer is evaluated after the variable comes into scope, but
|
|
|
|
// before the DeclStmt (which binds the value to the variable).
|
2009-06-02 17:58:47 +00:00
|
|
|
// Since this is a reverse dataflow analysis, we must evaluate the
|
2010-03-03 17:28:16 +00:00
|
|
|
// transfer function for this expression after the DeclStmt. If the
|
|
|
|
// initializer references the variable (which is bad) then we extend
|
|
|
|
// its liveness.
|
2009-06-02 17:58:47 +00:00
|
|
|
if (Expr* Init = VD->getInit())
|
|
|
|
Visit(Init);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
if (const VariableArrayType* VT =
|
|
|
|
AD.getContext().getAsVariableArrayType(VD->getType())) {
|
|
|
|
StmtIterator I(const_cast<VariableArrayType*>(VT));
|
2009-10-14 18:03:49 +00:00
|
|
|
StmtIterator E;
|
2009-06-02 17:58:47 +00:00
|
|
|
for (; I != E; ++I) Visit(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Merge operator: if something is live on any successor block, it is live
|
|
|
|
// in the current block (a set union).
|
2009-10-14 18:03:49 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
namespace {
|
2010-01-01 10:34:51 +00:00
|
|
|
typedef StmtDeclBitVector_Types::Union Merge;
|
|
|
|
typedef DataflowSolver<LiveVariables, TransferFuncs, Merge> Solver;
|
2009-06-02 17:58:47 +00:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// External interface to run Liveness analysis.
|
2009-10-14 18:03:49 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
void LiveVariables::runOnCFG(CFG& cfg) {
|
|
|
|
Solver S(*this);
|
|
|
|
S.runOnCFG(cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LiveVariables::runOnAllBlocks(const CFG& cfg,
|
|
|
|
LiveVariables::ObserverTy* Obs,
|
|
|
|
bool recordStmtValues) {
|
|
|
|
Solver S(*this);
|
2009-11-18 14:59:57 +00:00
|
|
|
SaveAndRestore<LiveVariables::ObserverTy*> SRObs(getAnalysisData().Observer,
|
|
|
|
Obs);
|
2009-06-02 17:58:47 +00:00
|
|
|
S.runOnAllBlocks(cfg, recordStmtValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// liveness queries
|
|
|
|
//
|
|
|
|
|
|
|
|
bool LiveVariables::isLive(const CFGBlock* B, const VarDecl* D) const {
|
|
|
|
DeclBitVector_Types::Idx i = getAnalysisData().getIdx(D);
|
|
|
|
return i.isValid() ? getBlockData(B).getBit(i) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LiveVariables::isLive(const ValTy& Live, const VarDecl* D) const {
|
|
|
|
DeclBitVector_Types::Idx i = getAnalysisData().getIdx(D);
|
|
|
|
return i.isValid() ? Live.getBit(i) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LiveVariables::isLive(const Stmt* Loc, const Stmt* StmtVal) const {
|
|
|
|
return getStmtData(Loc)(StmtVal,getAnalysisData());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LiveVariables::isLive(const Stmt* Loc, const VarDecl* D) const {
|
|
|
|
return getStmtData(Loc)(D,getAnalysisData());
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// printing liveness state for debugging
|
|
|
|
//
|
|
|
|
|
2009-11-18 14:59:57 +00:00
|
|
|
void LiveVariables::dumpLiveness(const ValTy& V, const SourceManager& SM) const {
|
2009-06-02 17:58:47 +00:00
|
|
|
const AnalysisDataTy& AD = getAnalysisData();
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
for (AnalysisDataTy::decl_iterator I = AD.begin_decl(),
|
|
|
|
E = AD.end_decl(); I!=E; ++I)
|
2009-10-14 18:03:49 +00:00
|
|
|
if (V.getDeclBit(I->second)) {
|
2009-10-23 14:22:18 +00:00
|
|
|
llvm::errs() << " " << I->first->getIdentifier()->getName() << " <";
|
2009-06-02 17:58:47 +00:00
|
|
|
I->first->getLocation().dump(SM);
|
2009-10-23 14:22:18 +00:00
|
|
|
llvm::errs() << ">\n";
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
}
|
2009-06-02 17:58:47 +00:00
|
|
|
|
2009-11-18 14:59:57 +00:00
|
|
|
void LiveVariables::dumpBlockLiveness(const SourceManager& M) const {
|
|
|
|
for (BlockDataMapTy::const_iterator I = getBlockDataMap().begin(),
|
2009-06-02 17:58:47 +00:00
|
|
|
E = getBlockDataMap().end(); I!=E; ++I) {
|
2009-10-23 14:22:18 +00:00
|
|
|
llvm::errs() << "\n[ B" << I->first->getBlockID()
|
|
|
|
<< " (live variables at block exit) ]\n";
|
2009-06-02 17:58:47 +00:00
|
|
|
dumpLiveness(I->second,M);
|
|
|
|
}
|
|
|
|
|
2009-10-23 14:22:18 +00:00
|
|
|
llvm::errs() << "\n";
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|