clang API Documentation

CFGReachabilityAnalysis.h
Go to the documentation of this file.
00001 //==- CFGReachabilityAnalysis.h - Basic reachability analysis ----*- C++ -*-==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines a flow-sensitive, (mostly) path-insensitive reachability
00011 // analysis based on Clang's CFGs.  Clients can query if a given basic block
00012 // is reachable within the CFG.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_CFGREACHABILITYANALYSIS_H
00017 #define LLVM_CLANG_ANALYSIS_ANALYSES_CFGREACHABILITYANALYSIS_H
00018 
00019 #include "llvm/ADT/BitVector.h"
00020 #include "llvm/ADT/DenseMap.h"
00021 
00022 namespace clang {
00023 
00024 class CFG;
00025 class CFGBlock;
00026   
00027 // A class that performs reachability queries for CFGBlocks. Several internal
00028 // checks in this checker require reachability information. The requests all
00029 // tend to have a common destination, so we lazily do a predecessor search
00030 // from the destination node and cache the results to prevent work
00031 // duplication.
00032 class CFGReverseBlockReachabilityAnalysis {
00033   typedef llvm::BitVector ReachableSet;
00034   typedef llvm::DenseMap<unsigned, ReachableSet> ReachableMap;
00035   ReachableSet analyzed;
00036   ReachableMap reachable;
00037 public:
00038   CFGReverseBlockReachabilityAnalysis(const CFG &cfg);
00039 
00040   /// Returns true if the block 'Dst' can be reached from block 'Src'.
00041   bool isReachable(const CFGBlock *Src, const CFGBlock *Dst);
00042 
00043 private:
00044   void mapReachability(const CFGBlock *Dst);
00045 };
00046   
00047 }
00048 
00049 #endif