CFG.h revision 1cff132e48e0ccc253c34e5a2fb12718bd4e7d2e
1//===--- CFG.h - Classes for representing and building CFGs------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the CFG and CFGBuilder classes for representing and 11// building Control-Flow Graphs (CFGs) from ASTs. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_CFG_H 16#define LLVM_CLANG_CFG_H 17 18#include "llvm/ADT/PointerIntPair.h" 19#include "llvm/ADT/GraphTraits.h" 20#include "llvm/Support/Allocator.h" 21#include "llvm/Support/Casting.h" 22#include "clang/Analysis/Support/BumpVector.h" 23#include "clang/Basic/SourceLocation.h" 24#include <cassert> 25 26namespace llvm { 27 class raw_ostream; 28} 29 30namespace clang { 31 class Decl; 32 class Stmt; 33 class Expr; 34 class VarDecl; 35 class CXXBaseOrMemberInitializer; 36 class CFG; 37 class PrinterHelper; 38 class LangOptions; 39 class ASTContext; 40 41/// CFGElement - Represents a top-level expression in a basic block. 42class CFGElement { 43public: 44 enum Kind { 45 // main kind 46 Statement, 47 StatementAsLValue, 48 Initializer, 49 Dtor, 50 // dtor kind 51 AutomaticObjectDtor, 52 BaseDtor, 53 MemberDtor, 54 TemporaryDtor, 55 DTOR_BEGIN = AutomaticObjectDtor 56 }; 57 58protected: 59 // The int bits are used to mark the main kind. 60 llvm::PointerIntPair<void *, 2> Data1; 61 // The int bits are used to mark the dtor kind. 62 llvm::PointerIntPair<void *, 2> Data2; 63 64 CFGElement(void *Ptr, unsigned Int) : Data1(Ptr, Int) {} 65 CFGElement(void *Ptr1, unsigned Int1, void *Ptr2, unsigned Int2) 66 : Data1(Ptr1, Int1), Data2(Ptr2, Int2) {} 67 68public: 69 CFGElement() {} 70 71 Kind getKind() const { return static_cast<Kind>(Data1.getInt()); } 72 73 Kind getDtorKind() const { 74 assert(getKind() == Dtor); 75 return static_cast<Kind>(Data2.getInt() + DTOR_BEGIN); 76 } 77 78 bool isValid() const { return Data1.getPointer(); } 79 80 operator bool() const { return isValid(); } 81 82 template<class ElemTy> ElemTy getAs() const { 83 if (llvm::isa<ElemTy>(this)) 84 return *static_cast<const ElemTy*>(this); 85 return ElemTy(); 86 } 87 88 static bool classof(const CFGElement *E) { return true; } 89}; 90 91class CFGStmt : public CFGElement { 92public: 93 CFGStmt() {} 94 CFGStmt(Stmt *S, bool asLValue) : CFGElement(S, asLValue) {} 95 96 Stmt *getStmt() const { return static_cast<Stmt *>(Data1.getPointer()); } 97 98 operator Stmt*() const { return getStmt(); } 99 100 bool asLValue() const { 101 return static_cast<Kind>(Data1.getInt()) == StatementAsLValue; 102 } 103 104 static bool classof(const CFGElement *E) { 105 return E->getKind() == Statement || E->getKind() == StatementAsLValue; 106 } 107}; 108 109/// CFGInitializer - Represents C++ base or member initializer from 110/// constructor's initialization list. 111class CFGInitializer : public CFGElement { 112public: 113 CFGInitializer() {} 114 CFGInitializer(CXXBaseOrMemberInitializer* I) 115 : CFGElement(I, Initializer) {} 116 117 CXXBaseOrMemberInitializer* getInitializer() const { 118 return static_cast<CXXBaseOrMemberInitializer*>(Data1.getPointer()); 119 } 120 operator CXXBaseOrMemberInitializer*() const { return getInitializer(); } 121 122 static bool classof(const CFGElement *E) { 123 return E->getKind() == Initializer; 124 } 125}; 126 127/// CFGImplicitDtor - Represents C++ object destructor imlicitly generated 128/// by compiler on various occasions. 129class CFGImplicitDtor : public CFGElement { 130protected: 131 CFGImplicitDtor(unsigned K, void* P, void* S) 132 : CFGElement(P, Dtor, S, K - DTOR_BEGIN) {} 133 134public: 135 CFGImplicitDtor() {} 136 137 static bool classof(const CFGElement *E) { 138 return E->getKind() == Dtor; 139 } 140}; 141 142/// CFGAutomaticObjDtor - Represents C++ object destructor implicit generated 143/// for automatic object or temporary bound to const reference at the point 144/// of leaving its local scope. 145class CFGAutomaticObjDtor: public CFGImplicitDtor { 146public: 147 CFGAutomaticObjDtor() {} 148 CFGAutomaticObjDtor(VarDecl* VD, Stmt* S) 149 : CFGImplicitDtor(AutomaticObjectDtor, VD, S) {} 150 151 VarDecl* getVarDecl() const { 152 return static_cast<VarDecl*>(Data1.getPointer()); 153 } 154 155 // Get statement end of which triggered the destructor call. 156 Stmt* getTriggerStmt() const { 157 return static_cast<Stmt*>(Data2.getPointer()); 158 } 159 160 static bool classof(const CFGElement *E) { 161 return E->getKind() == Dtor && E->getDtorKind() == AutomaticObjectDtor; 162 } 163}; 164 165class CFGBaseDtor : public CFGImplicitDtor { 166public: 167 static bool classof(const CFGElement *E) { 168 return E->getKind() == Dtor && E->getDtorKind() == BaseDtor; 169 } 170}; 171 172class CFGMemberDtor : public CFGImplicitDtor { 173public: 174 static bool classof(const CFGElement *E) { 175 return E->getKind() == Dtor && E->getDtorKind() == MemberDtor; 176 } 177 178}; 179 180class CFGTemporaryDtor : public CFGImplicitDtor { 181public: 182 static bool classof(const CFGElement *E) { 183 return E->getKind() == Dtor && E->getDtorKind() == TemporaryDtor; 184 } 185}; 186 187/// CFGBlock - Represents a single basic block in a source-level CFG. 188/// It consists of: 189/// 190/// (1) A set of statements/expressions (which may contain subexpressions). 191/// (2) A "terminator" statement (not in the set of statements). 192/// (3) A list of successors and predecessors. 193/// 194/// Terminator: The terminator represents the type of control-flow that occurs 195/// at the end of the basic block. The terminator is a Stmt* referring to an 196/// AST node that has control-flow: if-statements, breaks, loops, etc. 197/// If the control-flow is conditional, the condition expression will appear 198/// within the set of statements in the block (usually the last statement). 199/// 200/// Predecessors: the order in the set of predecessors is arbitrary. 201/// 202/// Successors: the order in the set of successors is NOT arbitrary. We 203/// currently have the following orderings based on the terminator: 204/// 205/// Terminator Successor Ordering 206/// ----------------------------------------------------- 207/// if Then Block; Else Block 208/// ? operator LHS expression; RHS expression 209/// &&, || expression that uses result of && or ||, RHS 210/// 211class CFGBlock { 212 class ElementList { 213 typedef BumpVector<CFGElement> ImplTy; 214 ImplTy Impl; 215 public: 216 ElementList(BumpVectorContext &C) : Impl(C, 4) {} 217 218 typedef std::reverse_iterator<ImplTy::iterator> iterator; 219 typedef std::reverse_iterator<ImplTy::const_iterator> const_iterator; 220 typedef ImplTy::iterator reverse_iterator; 221 typedef ImplTy::const_iterator const_reverse_iterator; 222 223 void push_back(CFGElement e, BumpVectorContext &C) { Impl.push_back(e, C); } 224 CFGElement front() const { return Impl.back(); } 225 CFGElement back() const { return Impl.front(); } 226 227 iterator begin() { return Impl.rbegin(); } 228 iterator end() { return Impl.rend(); } 229 const_iterator begin() const { return Impl.rbegin(); } 230 const_iterator end() const { return Impl.rend(); } 231 reverse_iterator rbegin() { return Impl.begin(); } 232 reverse_iterator rend() { return Impl.end(); } 233 const_reverse_iterator rbegin() const { return Impl.begin(); } 234 const_reverse_iterator rend() const { return Impl.end(); } 235 236 CFGElement operator[](size_t i) const { 237 assert(i < Impl.size()); 238 return Impl[Impl.size() - 1 - i]; 239 } 240 241 size_t size() const { return Impl.size(); } 242 bool empty() const { return Impl.empty(); } 243 }; 244 245 /// Stmts - The set of statements in the basic block. 246 ElementList Elements; 247 248 /// Label - An (optional) label that prefixes the executable 249 /// statements in the block. When this variable is non-NULL, it is 250 /// either an instance of LabelStmt, SwitchCase or CXXCatchStmt. 251 Stmt *Label; 252 253 /// Terminator - The terminator for a basic block that 254 /// indicates the type of control-flow that occurs between a block 255 /// and its successors. 256 Stmt *Terminator; 257 258 /// LoopTarget - Some blocks are used to represent the "loop edge" to 259 /// the start of a loop from within the loop body. This Stmt* will be 260 /// refer to the loop statement for such blocks (and be null otherwise). 261 const Stmt *LoopTarget; 262 263 /// BlockID - A numerical ID assigned to a CFGBlock during construction 264 /// of the CFG. 265 unsigned BlockID; 266 267 /// Predecessors/Successors - Keep track of the predecessor / successor 268 /// CFG blocks. 269 typedef BumpVector<CFGBlock*> AdjacentBlocks; 270 AdjacentBlocks Preds; 271 AdjacentBlocks Succs; 272 273public: 274 explicit CFGBlock(unsigned blockid, BumpVectorContext &C) 275 : Elements(C), Label(NULL), Terminator(NULL), LoopTarget(NULL), 276 BlockID(blockid), Preds(C, 1), Succs(C, 1) {} 277 ~CFGBlock() {} 278 279 // Statement iterators 280 typedef ElementList::iterator iterator; 281 typedef ElementList::const_iterator const_iterator; 282 typedef ElementList::reverse_iterator reverse_iterator; 283 typedef ElementList::const_reverse_iterator const_reverse_iterator; 284 285 CFGElement front() const { return Elements.front(); } 286 CFGElement back() const { return Elements.back(); } 287 288 iterator begin() { return Elements.begin(); } 289 iterator end() { return Elements.end(); } 290 const_iterator begin() const { return Elements.begin(); } 291 const_iterator end() const { return Elements.end(); } 292 293 reverse_iterator rbegin() { return Elements.rbegin(); } 294 reverse_iterator rend() { return Elements.rend(); } 295 const_reverse_iterator rbegin() const { return Elements.rbegin(); } 296 const_reverse_iterator rend() const { return Elements.rend(); } 297 298 unsigned size() const { return Elements.size(); } 299 bool empty() const { return Elements.empty(); } 300 301 CFGElement operator[](size_t i) const { return Elements[i]; } 302 303 // CFG iterators 304 typedef AdjacentBlocks::iterator pred_iterator; 305 typedef AdjacentBlocks::const_iterator const_pred_iterator; 306 typedef AdjacentBlocks::reverse_iterator pred_reverse_iterator; 307 typedef AdjacentBlocks::const_reverse_iterator const_pred_reverse_iterator; 308 309 typedef AdjacentBlocks::iterator succ_iterator; 310 typedef AdjacentBlocks::const_iterator const_succ_iterator; 311 typedef AdjacentBlocks::reverse_iterator succ_reverse_iterator; 312 typedef AdjacentBlocks::const_reverse_iterator const_succ_reverse_iterator; 313 314 pred_iterator pred_begin() { return Preds.begin(); } 315 pred_iterator pred_end() { return Preds.end(); } 316 const_pred_iterator pred_begin() const { return Preds.begin(); } 317 const_pred_iterator pred_end() const { return Preds.end(); } 318 319 pred_reverse_iterator pred_rbegin() { return Preds.rbegin(); } 320 pred_reverse_iterator pred_rend() { return Preds.rend(); } 321 const_pred_reverse_iterator pred_rbegin() const { return Preds.rbegin(); } 322 const_pred_reverse_iterator pred_rend() const { return Preds.rend(); } 323 324 succ_iterator succ_begin() { return Succs.begin(); } 325 succ_iterator succ_end() { return Succs.end(); } 326 const_succ_iterator succ_begin() const { return Succs.begin(); } 327 const_succ_iterator succ_end() const { return Succs.end(); } 328 329 succ_reverse_iterator succ_rbegin() { return Succs.rbegin(); } 330 succ_reverse_iterator succ_rend() { return Succs.rend(); } 331 const_succ_reverse_iterator succ_rbegin() const { return Succs.rbegin(); } 332 const_succ_reverse_iterator succ_rend() const { return Succs.rend(); } 333 334 unsigned succ_size() const { return Succs.size(); } 335 bool succ_empty() const { return Succs.empty(); } 336 337 unsigned pred_size() const { return Preds.size(); } 338 bool pred_empty() const { return Preds.empty(); } 339 340 341 class FilterOptions { 342 public: 343 FilterOptions() { 344 IgnoreDefaultsWithCoveredEnums = 0; 345 } 346 347 unsigned IgnoreDefaultsWithCoveredEnums : 1; 348 }; 349 350 static bool FilterEdge(const FilterOptions &F, const CFGBlock *Src, 351 const CFGBlock *Dst); 352 353 template <typename IMPL, bool IsPred> 354 class FilteredCFGBlockIterator { 355 private: 356 IMPL I, E; 357 const FilterOptions F; 358 const CFGBlock *From; 359 public: 360 explicit FilteredCFGBlockIterator(const IMPL &i, const IMPL &e, 361 const CFGBlock *from, 362 const FilterOptions &f) 363 : I(i), E(e), F(f), From(from) {} 364 365 bool hasMore() const { return I != E; } 366 367 FilteredCFGBlockIterator &operator++() { 368 do { ++I; } while (hasMore() && Filter(*I)); 369 return *this; 370 } 371 372 const CFGBlock *operator*() const { return *I; } 373 private: 374 bool Filter(const CFGBlock *To) { 375 return IsPred ? FilterEdge(F, To, From) : FilterEdge(F, From, To); 376 } 377 }; 378 379 typedef FilteredCFGBlockIterator<const_pred_iterator, true> 380 filtered_pred_iterator; 381 382 typedef FilteredCFGBlockIterator<const_succ_iterator, false> 383 filtered_succ_iterator; 384 385 filtered_pred_iterator filtered_pred_start_end(const FilterOptions &f) const { 386 return filtered_pred_iterator(pred_begin(), pred_end(), this, f); 387 } 388 389 filtered_succ_iterator filtered_succ_start_end(const FilterOptions &f) const { 390 return filtered_succ_iterator(succ_begin(), succ_end(), this, f); 391 } 392 393 // Manipulation of block contents 394 395 void setTerminator(Stmt* Statement) { Terminator = Statement; } 396 void setLabel(Stmt* Statement) { Label = Statement; } 397 void setLoopTarget(const Stmt *loopTarget) { LoopTarget = loopTarget; } 398 399 Stmt* getTerminator() { return Terminator; } 400 const Stmt* getTerminator() const { return Terminator; } 401 402 Stmt* getTerminatorCondition(); 403 404 const Stmt* getTerminatorCondition() const { 405 return const_cast<CFGBlock*>(this)->getTerminatorCondition(); 406 } 407 408 const Stmt *getLoopTarget() const { return LoopTarget; } 409 410 bool hasBinaryBranchTerminator() const; 411 412 Stmt* getLabel() { return Label; } 413 const Stmt* getLabel() const { return Label; } 414 415 unsigned getBlockID() const { return BlockID; } 416 417 void dump(const CFG *cfg, const LangOptions &LO) const; 418 void print(llvm::raw_ostream &OS, const CFG* cfg, const LangOptions &LO) const; 419 void printTerminator(llvm::raw_ostream &OS, const LangOptions &LO) const; 420 421 void addSuccessor(CFGBlock* Block, BumpVectorContext &C) { 422 if (Block) 423 Block->Preds.push_back(this, C); 424 Succs.push_back(Block, C); 425 } 426 427 void appendStmt(Stmt* Statement, BumpVectorContext &C, bool asLValue) { 428 Elements.push_back(CFGStmt(Statement, asLValue), C); 429 } 430}; 431 432/// CFG - Represents a source-level, intra-procedural CFG that represents the 433/// control-flow of a Stmt. The Stmt can represent an entire function body, 434/// or a single expression. A CFG will always contain one empty block that 435/// represents the Exit point of the CFG. A CFG will also contain a designated 436/// Entry block. The CFG solely represents control-flow; it consists of 437/// CFGBlocks which are simply containers of Stmt*'s in the AST the CFG 438/// was constructed from. 439class CFG { 440public: 441 //===--------------------------------------------------------------------===// 442 // CFG Construction & Manipulation. 443 //===--------------------------------------------------------------------===// 444 445 class BuildOptions { 446 public: 447 bool PruneTriviallyFalseEdges:1; 448 bool AddEHEdges:1; 449 bool AddInitializers:1; 450 bool AddImplicitDtors:1; 451 452 BuildOptions() 453 : PruneTriviallyFalseEdges(true) 454 , AddEHEdges(false) 455 , AddInitializers(false) 456 , AddImplicitDtors(false) {} 457 }; 458 459 /// buildCFG - Builds a CFG from an AST. The responsibility to free the 460 /// constructed CFG belongs to the caller. 461 static CFG* buildCFG(const Decl *D, Stmt* AST, ASTContext *C, 462 BuildOptions BO = BuildOptions()); 463 464 /// createBlock - Create a new block in the CFG. The CFG owns the block; 465 /// the caller should not directly free it. 466 CFGBlock* createBlock(); 467 468 /// setEntry - Set the entry block of the CFG. This is typically used 469 /// only during CFG construction. Most CFG clients expect that the 470 /// entry block has no predecessors and contains no statements. 471 void setEntry(CFGBlock *B) { Entry = B; } 472 473 /// setIndirectGotoBlock - Set the block used for indirect goto jumps. 474 /// This is typically used only during CFG construction. 475 void setIndirectGotoBlock(CFGBlock* B) { IndirectGotoBlock = B; } 476 477 //===--------------------------------------------------------------------===// 478 // Block Iterators 479 //===--------------------------------------------------------------------===// 480 481 typedef BumpVector<CFGBlock*> CFGBlockListTy; 482 typedef CFGBlockListTy::iterator iterator; 483 typedef CFGBlockListTy::const_iterator const_iterator; 484 typedef std::reverse_iterator<iterator> reverse_iterator; 485 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 486 487 CFGBlock& front() { return *Blocks.front(); } 488 CFGBlock& back() { return *Blocks.back(); } 489 490 iterator begin() { return Blocks.begin(); } 491 iterator end() { return Blocks.end(); } 492 const_iterator begin() const { return Blocks.begin(); } 493 const_iterator end() const { return Blocks.end(); } 494 495 reverse_iterator rbegin() { return Blocks.rbegin(); } 496 reverse_iterator rend() { return Blocks.rend(); } 497 const_reverse_iterator rbegin() const { return Blocks.rbegin(); } 498 const_reverse_iterator rend() const { return Blocks.rend(); } 499 500 CFGBlock& getEntry() { return *Entry; } 501 const CFGBlock& getEntry() const { return *Entry; } 502 CFGBlock& getExit() { return *Exit; } 503 const CFGBlock& getExit() const { return *Exit; } 504 505 CFGBlock* getIndirectGotoBlock() { return IndirectGotoBlock; } 506 const CFGBlock* getIndirectGotoBlock() const { return IndirectGotoBlock; } 507 508 //===--------------------------------------------------------------------===// 509 // Member templates useful for various batch operations over CFGs. 510 //===--------------------------------------------------------------------===// 511 512 template <typename CALLBACK> 513 void VisitBlockStmts(CALLBACK& O) const { 514 for (const_iterator I=begin(), E=end(); I != E; ++I) 515 for (CFGBlock::const_iterator BI=(*I)->begin(), BE=(*I)->end(); 516 BI != BE; ++BI) { 517 if (CFGStmt S = BI->getAs<CFGStmt>()) 518 O(S); 519 } 520 } 521 522 //===--------------------------------------------------------------------===// 523 // CFG Introspection. 524 //===--------------------------------------------------------------------===// 525 526 struct BlkExprNumTy { 527 const signed Idx; 528 explicit BlkExprNumTy(signed idx) : Idx(idx) {} 529 explicit BlkExprNumTy() : Idx(-1) {} 530 operator bool() const { return Idx >= 0; } 531 operator unsigned() const { assert(Idx >=0); return (unsigned) Idx; } 532 }; 533 534 bool isBlkExpr(const Stmt* S) { return getBlkExprNum(S); } 535 BlkExprNumTy getBlkExprNum(const Stmt* S); 536 unsigned getNumBlkExprs(); 537 538 /// getNumBlockIDs - Returns the total number of BlockIDs allocated (which 539 /// start at 0). 540 unsigned getNumBlockIDs() const { return NumBlockIDs; } 541 542 //===--------------------------------------------------------------------===// 543 // CFG Debugging: Pretty-Printing and Visualization. 544 //===--------------------------------------------------------------------===// 545 546 void viewCFG(const LangOptions &LO) const; 547 void print(llvm::raw_ostream& OS, const LangOptions &LO) const; 548 void dump(const LangOptions &LO) const; 549 550 //===--------------------------------------------------------------------===// 551 // Internal: constructors and data. 552 //===--------------------------------------------------------------------===// 553 554 CFG() : Entry(NULL), Exit(NULL), IndirectGotoBlock(NULL), NumBlockIDs(0), 555 BlkExprMap(NULL), Blocks(BlkBVC, 10) {} 556 557 ~CFG(); 558 559 llvm::BumpPtrAllocator& getAllocator() { 560 return BlkBVC.getAllocator(); 561 } 562 563 BumpVectorContext &getBumpVectorContext() { 564 return BlkBVC; 565 } 566 567private: 568 CFGBlock* Entry; 569 CFGBlock* Exit; 570 CFGBlock* IndirectGotoBlock; // Special block to contain collective dispatch 571 // for indirect gotos 572 unsigned NumBlockIDs; 573 574 // BlkExprMap - An opaque pointer to prevent inclusion of DenseMap.h. 575 // It represents a map from Expr* to integers to record the set of 576 // block-level expressions and their "statement number" in the CFG. 577 void* BlkExprMap; 578 579 BumpVectorContext BlkBVC; 580 581 CFGBlockListTy Blocks; 582 583}; 584} // end namespace clang 585 586//===----------------------------------------------------------------------===// 587// GraphTraits specializations for CFG basic block graphs (source-level CFGs) 588//===----------------------------------------------------------------------===// 589 590namespace llvm { 591 592// Traits for: CFGBlock 593 594template <> struct GraphTraits< ::clang::CFGBlock* > { 595 typedef ::clang::CFGBlock NodeType; 596 typedef ::clang::CFGBlock::succ_iterator ChildIteratorType; 597 598 static NodeType* getEntryNode(::clang::CFGBlock* BB) 599 { return BB; } 600 601 static inline ChildIteratorType child_begin(NodeType* N) 602 { return N->succ_begin(); } 603 604 static inline ChildIteratorType child_end(NodeType* N) 605 { return N->succ_end(); } 606}; 607 608template <> struct GraphTraits< const ::clang::CFGBlock* > { 609 typedef const ::clang::CFGBlock NodeType; 610 typedef ::clang::CFGBlock::const_succ_iterator ChildIteratorType; 611 612 static NodeType* getEntryNode(const clang::CFGBlock* BB) 613 { return BB; } 614 615 static inline ChildIteratorType child_begin(NodeType* N) 616 { return N->succ_begin(); } 617 618 static inline ChildIteratorType child_end(NodeType* N) 619 { return N->succ_end(); } 620}; 621 622template <> struct GraphTraits<Inverse<const ::clang::CFGBlock*> > { 623 typedef const ::clang::CFGBlock NodeType; 624 typedef ::clang::CFGBlock::const_pred_iterator ChildIteratorType; 625 626 static NodeType *getEntryNode(Inverse<const ::clang::CFGBlock*> G) 627 { return G.Graph; } 628 629 static inline ChildIteratorType child_begin(NodeType* N) 630 { return N->pred_begin(); } 631 632 static inline ChildIteratorType child_end(NodeType* N) 633 { return N->pred_end(); } 634}; 635 636// Traits for: CFG 637 638template <> struct GraphTraits< ::clang::CFG* > 639 : public GraphTraits< ::clang::CFGBlock* > { 640 641 typedef ::clang::CFG::iterator nodes_iterator; 642 643 static NodeType *getEntryNode(::clang::CFG* F) { return &F->getEntry(); } 644 static nodes_iterator nodes_begin(::clang::CFG* F) { return F->begin(); } 645 static nodes_iterator nodes_end(::clang::CFG* F) { return F->end(); } 646}; 647 648template <> struct GraphTraits<const ::clang::CFG* > 649 : public GraphTraits<const ::clang::CFGBlock* > { 650 651 typedef ::clang::CFG::const_iterator nodes_iterator; 652 653 static NodeType *getEntryNode( const ::clang::CFG* F) { 654 return &F->getEntry(); 655 } 656 static nodes_iterator nodes_begin( const ::clang::CFG* F) { 657 return F->begin(); 658 } 659 static nodes_iterator nodes_end( const ::clang::CFG* F) { 660 return F->end(); 661 } 662}; 663 664template <> struct GraphTraits<Inverse<const ::clang::CFG*> > 665 : public GraphTraits<Inverse<const ::clang::CFGBlock*> > { 666 667 typedef ::clang::CFG::const_iterator nodes_iterator; 668 669 static NodeType *getEntryNode(const ::clang::CFG* F) { return &F->getExit(); } 670 static nodes_iterator nodes_begin(const ::clang::CFG* F) { return F->begin();} 671 static nodes_iterator nodes_end(const ::clang::CFG* F) { return F->end(); } 672}; 673} // end llvm namespace 674#endif 675