1 //===--- CFG.h - Classes for representing and building CFGs------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the CFG and CFGBuilder classes for representing and
11 // building Control-Flow Graphs (CFGs) from ASTs.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_CFG_H
16 #define LLVM_CLANG_CFG_H
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"
36 class CXXBaseOrMemberInitializer;
37 class CXXBaseSpecifier;
43 /// CFGElement - Represents a top-level expression in a basic block.
57 DTOR_BEGIN = AutomaticObjectDtor
61 // The int bits are used to mark the main kind.
62 llvm::PointerIntPair<void *, 2> Data1;
63 // The int bits are used to mark the dtor kind.
64 llvm::PointerIntPair<void *, 2> Data2;
66 CFGElement(void *Ptr, unsigned Int) : Data1(Ptr, Int) {}
67 CFGElement(void *Ptr1, unsigned Int1, void *Ptr2, unsigned Int2)
68 : Data1(Ptr1, Int1), Data2(Ptr2, Int2) {}
73 Kind getKind() const { return static_cast<Kind>(Data1.getInt()); }
75 Kind getDtorKind() const {
76 assert(getKind() == Dtor);
77 return static_cast<Kind>(Data2.getInt() + DTOR_BEGIN);
80 bool isValid() const { return Data1.getPointer(); }
82 operator bool() const { return isValid(); }
84 template<class ElemTy> ElemTy getAs() const {
85 if (llvm::isa<ElemTy>(this))
86 return *static_cast<const ElemTy*>(this);
90 static bool classof(const CFGElement *E) { return true; }
93 class CFGStmt : public CFGElement {
96 CFGStmt(Stmt *S, bool asLValue) : CFGElement(S, asLValue) {}
98 Stmt *getStmt() const { return static_cast<Stmt *>(Data1.getPointer()); }
100 operator Stmt*() const { return getStmt(); }
102 bool asLValue() const {
103 return static_cast<Kind>(Data1.getInt()) == StatementAsLValue;
106 static bool classof(const CFGElement *E) {
107 return E->getKind() == Statement || E->getKind() == StatementAsLValue;
111 /// CFGInitializer - Represents C++ base or member initializer from
112 /// constructor's initialization list.
113 class CFGInitializer : public CFGElement {
116 CFGInitializer(CXXBaseOrMemberInitializer* I)
117 : CFGElement(I, Initializer) {}
119 CXXBaseOrMemberInitializer* getInitializer() const {
120 return static_cast<CXXBaseOrMemberInitializer*>(Data1.getPointer());
122 operator CXXBaseOrMemberInitializer*() const { return getInitializer(); }
124 static bool classof(const CFGElement *E) {
125 return E->getKind() == Initializer;
129 /// CFGImplicitDtor - Represents C++ object destructor implicitly generated
130 /// by compiler on various occasions.
131 class CFGImplicitDtor : public CFGElement {
133 CFGImplicitDtor(unsigned K, void* P, void* S)
134 : CFGElement(P, Dtor, S, K - DTOR_BEGIN) {}
139 static bool classof(const CFGElement *E) {
140 return E->getKind() == Dtor;
144 /// CFGAutomaticObjDtor - Represents C++ object destructor implicitly generated
145 /// for automatic object or temporary bound to const reference at the point
146 /// of leaving its local scope.
147 class CFGAutomaticObjDtor: public CFGImplicitDtor {
149 CFGAutomaticObjDtor() {}
150 CFGAutomaticObjDtor(VarDecl* VD, Stmt* S)
151 : CFGImplicitDtor(AutomaticObjectDtor, VD, S) {}
153 VarDecl* getVarDecl() const {
154 return static_cast<VarDecl*>(Data1.getPointer());
157 // Get statement end of which triggered the destructor call.
158 Stmt* getTriggerStmt() const {
159 return static_cast<Stmt*>(Data2.getPointer());
162 static bool classof(const CFGElement *E) {
163 return E->getKind() == Dtor && E->getDtorKind() == AutomaticObjectDtor;
167 /// CFGBaseDtor - Represents C++ object destructor implicitly generated for
168 /// base object in destructor.
169 class CFGBaseDtor : public CFGImplicitDtor {
172 CFGBaseDtor(const CXXBaseSpecifier *BS)
173 : CFGImplicitDtor(BaseDtor, const_cast<CXXBaseSpecifier*>(BS), NULL) {}
175 const CXXBaseSpecifier *getBaseSpecifier() const {
176 return static_cast<const CXXBaseSpecifier*>(Data1.getPointer());
179 static bool classof(const CFGElement *E) {
180 return E->getKind() == Dtor && E->getDtorKind() == BaseDtor;
184 /// CFGMemberDtor - Represents C++ object destructor implicitly generated for
185 /// member object in destructor.
186 class CFGMemberDtor : public CFGImplicitDtor {
189 CFGMemberDtor(FieldDecl *FD)
190 : CFGImplicitDtor(MemberDtor, FD, NULL) {}
192 FieldDecl *getFieldDecl() const {
193 return static_cast<FieldDecl*>(Data1.getPointer());
196 static bool classof(const CFGElement *E) {
197 return E->getKind() == Dtor && E->getDtorKind() == MemberDtor;
201 class CFGTemporaryDtor : public CFGImplicitDtor {
203 static bool classof(const CFGElement *E) {
204 return E->getKind() == Dtor && E->getDtorKind() == TemporaryDtor;
208 /// CFGTerminator - Represents CFGBlock terminator statement.
210 /// TemporaryDtorsBranch bit is set to true if the terminator marks a branch
211 /// in control flow of destructors of temporaries. In this case terminator
212 /// statement is the same statement that branches control flow in evaluation
213 /// of matching full expression.
214 class CFGTerminator {
215 llvm::PointerIntPair<Stmt *, 1> Data;
218 CFGTerminator(Stmt *S, bool TemporaryDtorsBranch = false)
219 : Data(S, TemporaryDtorsBranch) {}
221 Stmt *getStmt() { return Data.getPointer(); }
222 const Stmt *getStmt() const { return Data.getPointer(); }
224 bool isTemporaryDtorsBranch() const { return Data.getInt(); }
226 operator Stmt *() { return getStmt(); }
227 operator const Stmt *() const { return getStmt(); }
229 Stmt *operator->() { return getStmt(); }
230 const Stmt *operator->() const { return getStmt(); }
232 Stmt &operator*() { return *getStmt(); }
233 const Stmt &operator*() const { return *getStmt(); }
235 operator bool() const { return getStmt(); }
238 /// CFGBlock - Represents a single basic block in a source-level CFG.
241 /// (1) A set of statements/expressions (which may contain subexpressions).
242 /// (2) A "terminator" statement (not in the set of statements).
243 /// (3) A list of successors and predecessors.
245 /// Terminator: The terminator represents the type of control-flow that occurs
246 /// at the end of the basic block. The terminator is a Stmt* referring to an
247 /// AST node that has control-flow: if-statements, breaks, loops, etc.
248 /// If the control-flow is conditional, the condition expression will appear
249 /// within the set of statements in the block (usually the last statement).
251 /// Predecessors: the order in the set of predecessors is arbitrary.
253 /// Successors: the order in the set of successors is NOT arbitrary. We
254 /// currently have the following orderings based on the terminator:
256 /// Terminator Successor Ordering
257 /// -----------------------------------------------------
258 /// if Then Block; Else Block
259 /// ? operator LHS expression; RHS expression
260 /// &&, || expression that uses result of && or ||, RHS
264 typedef BumpVector<CFGElement> ImplTy;
267 ElementList(BumpVectorContext &C) : Impl(C, 4) {}
269 typedef std::reverse_iterator<ImplTy::iterator> iterator;
270 typedef std::reverse_iterator<ImplTy::const_iterator> const_iterator;
271 typedef ImplTy::iterator reverse_iterator;
272 typedef ImplTy::const_iterator const_reverse_iterator;
274 void push_back(CFGElement e, BumpVectorContext &C) { Impl.push_back(e, C); }
275 reverse_iterator insert(reverse_iterator I, size_t Cnt, CFGElement E,
276 BumpVectorContext& C) {
277 return Impl.insert(I, Cnt, E, C);
280 CFGElement front() const { return Impl.back(); }
281 CFGElement back() const { return Impl.front(); }
283 iterator begin() { return Impl.rbegin(); }
284 iterator end() { return Impl.rend(); }
285 const_iterator begin() const { return Impl.rbegin(); }
286 const_iterator end() const { return Impl.rend(); }
287 reverse_iterator rbegin() { return Impl.begin(); }
288 reverse_iterator rend() { return Impl.end(); }
289 const_reverse_iterator rbegin() const { return Impl.begin(); }
290 const_reverse_iterator rend() const { return Impl.end(); }
292 CFGElement operator[](size_t i) const {
293 assert(i < Impl.size());
294 return Impl[Impl.size() - 1 - i];
297 size_t size() const { return Impl.size(); }
298 bool empty() const { return Impl.empty(); }
301 /// Stmts - The set of statements in the basic block.
302 ElementList Elements;
304 /// Label - An (optional) label that prefixes the executable
305 /// statements in the block. When this variable is non-NULL, it is
306 /// either an instance of LabelStmt, SwitchCase or CXXCatchStmt.
309 /// Terminator - The terminator for a basic block that
310 /// indicates the type of control-flow that occurs between a block
311 /// and its successors.
312 CFGTerminator Terminator;
314 /// LoopTarget - Some blocks are used to represent the "loop edge" to
315 /// the start of a loop from within the loop body. This Stmt* will be
316 /// refer to the loop statement for such blocks (and be null otherwise).
317 const Stmt *LoopTarget;
319 /// BlockID - A numerical ID assigned to a CFGBlock during construction
323 /// Predecessors/Successors - Keep track of the predecessor / successor
325 typedef BumpVector<CFGBlock*> AdjacentBlocks;
326 AdjacentBlocks Preds;
327 AdjacentBlocks Succs;
330 explicit CFGBlock(unsigned blockid, BumpVectorContext &C)
331 : Elements(C), Label(NULL), Terminator(NULL), LoopTarget(NULL),
332 BlockID(blockid), Preds(C, 1), Succs(C, 1) {}
335 // Statement iterators
336 typedef ElementList::iterator iterator;
337 typedef ElementList::const_iterator const_iterator;
338 typedef ElementList::reverse_iterator reverse_iterator;
339 typedef ElementList::const_reverse_iterator const_reverse_iterator;
341 CFGElement front() const { return Elements.front(); }
342 CFGElement back() const { return Elements.back(); }
344 iterator begin() { return Elements.begin(); }
345 iterator end() { return Elements.end(); }
346 const_iterator begin() const { return Elements.begin(); }
347 const_iterator end() const { return Elements.end(); }
349 reverse_iterator rbegin() { return Elements.rbegin(); }
350 reverse_iterator rend() { return Elements.rend(); }
351 const_reverse_iterator rbegin() const { return Elements.rbegin(); }
352 const_reverse_iterator rend() const { return Elements.rend(); }
354 unsigned size() const { return Elements.size(); }
355 bool empty() const { return Elements.empty(); }
357 CFGElement operator[](size_t i) const { return Elements[i]; }
360 typedef AdjacentBlocks::iterator pred_iterator;
361 typedef AdjacentBlocks::const_iterator const_pred_iterator;
362 typedef AdjacentBlocks::reverse_iterator pred_reverse_iterator;
363 typedef AdjacentBlocks::const_reverse_iterator const_pred_reverse_iterator;
365 typedef AdjacentBlocks::iterator succ_iterator;
366 typedef AdjacentBlocks::const_iterator const_succ_iterator;
367 typedef AdjacentBlocks::reverse_iterator succ_reverse_iterator;
368 typedef AdjacentBlocks::const_reverse_iterator const_succ_reverse_iterator;
370 pred_iterator pred_begin() { return Preds.begin(); }
371 pred_iterator pred_end() { return Preds.end(); }
372 const_pred_iterator pred_begin() const { return Preds.begin(); }
373 const_pred_iterator pred_end() const { return Preds.end(); }
375 pred_reverse_iterator pred_rbegin() { return Preds.rbegin(); }
376 pred_reverse_iterator pred_rend() { return Preds.rend(); }
377 const_pred_reverse_iterator pred_rbegin() const { return Preds.rbegin(); }
378 const_pred_reverse_iterator pred_rend() const { return Preds.rend(); }
380 succ_iterator succ_begin() { return Succs.begin(); }
381 succ_iterator succ_end() { return Succs.end(); }
382 const_succ_iterator succ_begin() const { return Succs.begin(); }
383 const_succ_iterator succ_end() const { return Succs.end(); }
385 succ_reverse_iterator succ_rbegin() { return Succs.rbegin(); }
386 succ_reverse_iterator succ_rend() { return Succs.rend(); }
387 const_succ_reverse_iterator succ_rbegin() const { return Succs.rbegin(); }
388 const_succ_reverse_iterator succ_rend() const { return Succs.rend(); }
390 unsigned succ_size() const { return Succs.size(); }
391 bool succ_empty() const { return Succs.empty(); }
393 unsigned pred_size() const { return Preds.size(); }
394 bool pred_empty() const { return Preds.empty(); }
397 class FilterOptions {
400 IgnoreDefaultsWithCoveredEnums = 0;
403 unsigned IgnoreDefaultsWithCoveredEnums : 1;
406 static bool FilterEdge(const FilterOptions &F, const CFGBlock *Src,
407 const CFGBlock *Dst);
409 template <typename IMPL, bool IsPred>
410 class FilteredCFGBlockIterator {
413 const FilterOptions F;
414 const CFGBlock *From;
416 explicit FilteredCFGBlockIterator(const IMPL &i, const IMPL &e,
417 const CFGBlock *from,
418 const FilterOptions &f)
419 : I(i), E(e), F(f), From(from) {}
421 bool hasMore() const { return I != E; }
423 FilteredCFGBlockIterator &operator++() {
424 do { ++I; } while (hasMore() && Filter(*I));
428 const CFGBlock *operator*() const { return *I; }
430 bool Filter(const CFGBlock *To) {
431 return IsPred ? FilterEdge(F, To, From) : FilterEdge(F, From, To);
435 typedef FilteredCFGBlockIterator<const_pred_iterator, true>
436 filtered_pred_iterator;
438 typedef FilteredCFGBlockIterator<const_succ_iterator, false>
439 filtered_succ_iterator;
441 filtered_pred_iterator filtered_pred_start_end(const FilterOptions &f) const {
442 return filtered_pred_iterator(pred_begin(), pred_end(), this, f);
445 filtered_succ_iterator filtered_succ_start_end(const FilterOptions &f) const {
446 return filtered_succ_iterator(succ_begin(), succ_end(), this, f);
449 // Manipulation of block contents
451 void setTerminator(Stmt* Statement) { Terminator = Statement; }
452 void setLabel(Stmt* Statement) { Label = Statement; }
453 void setLoopTarget(const Stmt *loopTarget) { LoopTarget = loopTarget; }
455 CFGTerminator getTerminator() { return Terminator; }
456 const CFGTerminator getTerminator() const { return Terminator; }
458 Stmt* getTerminatorCondition();
460 const Stmt* getTerminatorCondition() const {
461 return const_cast<CFGBlock*>(this)->getTerminatorCondition();
464 const Stmt *getLoopTarget() const { return LoopTarget; }
466 bool hasBinaryBranchTerminator() const;
468 Stmt* getLabel() { return Label; }
469 const Stmt* getLabel() const { return Label; }
471 unsigned getBlockID() const { return BlockID; }
473 void dump(const CFG *cfg, const LangOptions &LO) const;
474 void print(llvm::raw_ostream &OS, const CFG* cfg, const LangOptions &LO) const;
475 void printTerminator(llvm::raw_ostream &OS, const LangOptions &LO) const;
477 void addSuccessor(CFGBlock* Block, BumpVectorContext &C) {
479 Block->Preds.push_back(this, C);
480 Succs.push_back(Block, C);
483 void appendStmt(Stmt* Statement, BumpVectorContext &C, bool asLValue) {
484 Elements.push_back(CFGStmt(Statement, asLValue), C);
487 void appendInitializer(CXXBaseOrMemberInitializer *I, BumpVectorContext& C) {
488 Elements.push_back(CFGInitializer(I), C);
491 void appendBaseDtor(const CXXBaseSpecifier *BS, BumpVectorContext &C) {
492 Elements.push_back(CFGBaseDtor(BS), C);
495 void appendMemberDtor(FieldDecl *FD, BumpVectorContext &C) {
496 Elements.push_back(CFGMemberDtor(FD), C);
499 // Destructors must be inserted in reversed order. So insertion is in two
500 // steps. First we prepare space for some number of elements, then we insert
501 // the elements beginning at the last position in prepared space.
502 iterator beginAutomaticObjDtorsInsert(iterator I, size_t Cnt,
503 BumpVectorContext& C) {
504 return iterator(Elements.insert(I.base(), Cnt, CFGElement(), C));
506 iterator insertAutomaticObjDtor(iterator I, VarDecl* VD, Stmt* S) {
507 *I = CFGAutomaticObjDtor(VD, S);
512 /// CFG - Represents a source-level, intra-procedural CFG that represents the
513 /// control-flow of a Stmt. The Stmt can represent an entire function body,
514 /// or a single expression. A CFG will always contain one empty block that
515 /// represents the Exit point of the CFG. A CFG will also contain a designated
516 /// Entry block. The CFG solely represents control-flow; it consists of
517 /// CFGBlocks which are simply containers of Stmt*'s in the AST the CFG
518 /// was constructed from.
521 //===--------------------------------------------------------------------===//
522 // CFG Construction & Manipulation.
523 //===--------------------------------------------------------------------===//
527 bool PruneTriviallyFalseEdges:1;
529 bool AddInitializers:1;
530 bool AddImplicitDtors:1;
533 : PruneTriviallyFalseEdges(true)
535 , AddInitializers(false)
536 , AddImplicitDtors(false) {}
539 /// buildCFG - Builds a CFG from an AST. The responsibility to free the
540 /// constructed CFG belongs to the caller.
541 static CFG* buildCFG(const Decl *D, Stmt* AST, ASTContext *C,
542 BuildOptions BO = BuildOptions());
544 /// createBlock - Create a new block in the CFG. The CFG owns the block;
545 /// the caller should not directly free it.
546 CFGBlock* createBlock();
548 /// setEntry - Set the entry block of the CFG. This is typically used
549 /// only during CFG construction. Most CFG clients expect that the
550 /// entry block has no predecessors and contains no statements.
551 void setEntry(CFGBlock *B) { Entry = B; }
553 /// setIndirectGotoBlock - Set the block used for indirect goto jumps.
554 /// This is typically used only during CFG construction.
555 void setIndirectGotoBlock(CFGBlock* B) { IndirectGotoBlock = B; }
557 //===--------------------------------------------------------------------===//
559 //===--------------------------------------------------------------------===//
561 typedef BumpVector<CFGBlock*> CFGBlockListTy;
562 typedef CFGBlockListTy::iterator iterator;
563 typedef CFGBlockListTy::const_iterator const_iterator;
564 typedef std::reverse_iterator<iterator> reverse_iterator;
565 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
567 CFGBlock& front() { return *Blocks.front(); }
568 CFGBlock& back() { return *Blocks.back(); }
570 iterator begin() { return Blocks.begin(); }
571 iterator end() { return Blocks.end(); }
572 const_iterator begin() const { return Blocks.begin(); }
573 const_iterator end() const { return Blocks.end(); }
575 reverse_iterator rbegin() { return Blocks.rbegin(); }
576 reverse_iterator rend() { return Blocks.rend(); }
577 const_reverse_iterator rbegin() const { return Blocks.rbegin(); }
578 const_reverse_iterator rend() const { return Blocks.rend(); }
580 CFGBlock& getEntry() { return *Entry; }
581 const CFGBlock& getEntry() const { return *Entry; }
582 CFGBlock& getExit() { return *Exit; }
583 const CFGBlock& getExit() const { return *Exit; }
585 CFGBlock* getIndirectGotoBlock() { return IndirectGotoBlock; }
586 const CFGBlock* getIndirectGotoBlock() const { return IndirectGotoBlock; }
588 //===--------------------------------------------------------------------===//
589 // Member templates useful for various batch operations over CFGs.
590 //===--------------------------------------------------------------------===//
592 template <typename CALLBACK>
593 void VisitBlockStmts(CALLBACK& O) const {
594 for (const_iterator I=begin(), E=end(); I != E; ++I)
595 for (CFGBlock::const_iterator BI=(*I)->begin(), BE=(*I)->end();
597 if (CFGStmt S = BI->getAs<CFGStmt>())
602 //===--------------------------------------------------------------------===//
603 // CFG Introspection.
604 //===--------------------------------------------------------------------===//
606 struct BlkExprNumTy {
608 explicit BlkExprNumTy(signed idx) : Idx(idx) {}
609 explicit BlkExprNumTy() : Idx(-1) {}
610 operator bool() const { return Idx >= 0; }
611 operator unsigned() const { assert(Idx >=0); return (unsigned) Idx; }
614 bool isBlkExpr(const Stmt* S) { return getBlkExprNum(S); }
615 BlkExprNumTy getBlkExprNum(const Stmt* S);
616 unsigned getNumBlkExprs();
618 /// getNumBlockIDs - Returns the total number of BlockIDs allocated (which
620 unsigned getNumBlockIDs() const { return NumBlockIDs; }
622 //===--------------------------------------------------------------------===//
623 // CFG Debugging: Pretty-Printing and Visualization.
624 //===--------------------------------------------------------------------===//
626 void viewCFG(const LangOptions &LO) const;
627 void print(llvm::raw_ostream& OS, const LangOptions &LO) const;
628 void dump(const LangOptions &LO) const;
630 //===--------------------------------------------------------------------===//
631 // Internal: constructors and data.
632 //===--------------------------------------------------------------------===//
634 CFG() : Entry(NULL), Exit(NULL), IndirectGotoBlock(NULL), NumBlockIDs(0),
635 BlkExprMap(NULL), Blocks(BlkBVC, 10) {}
639 llvm::BumpPtrAllocator& getAllocator() {
640 return BlkBVC.getAllocator();
643 BumpVectorContext &getBumpVectorContext() {
650 CFGBlock* IndirectGotoBlock; // Special block to contain collective dispatch
651 // for indirect gotos
652 unsigned NumBlockIDs;
654 // BlkExprMap - An opaque pointer to prevent inclusion of DenseMap.h.
655 // It represents a map from Expr* to integers to record the set of
656 // block-level expressions and their "statement number" in the CFG.
659 BumpVectorContext BlkBVC;
661 CFGBlockListTy Blocks;
664 } // end namespace clang
666 //===----------------------------------------------------------------------===//
667 // GraphTraits specializations for CFG basic block graphs (source-level CFGs)
668 //===----------------------------------------------------------------------===//
672 /// Implement simplify_type for CFGTerminator, so that we can dyn_cast from
673 /// CFGTerminator to a specific Stmt class.
674 template <> struct simplify_type<const ::clang::CFGTerminator> {
675 typedef const ::clang::Stmt *SimpleType;
676 static SimpleType getSimplifiedValue(const ::clang::CFGTerminator &Val) {
677 return Val.getStmt();
681 template <> struct simplify_type< ::clang::CFGTerminator> {
682 typedef ::clang::Stmt *SimpleType;
683 static SimpleType getSimplifiedValue(const ::clang::CFGTerminator &Val) {
684 return const_cast<SimpleType>(Val.getStmt());
688 // Traits for: CFGBlock
690 template <> struct GraphTraits< ::clang::CFGBlock* > {
691 typedef ::clang::CFGBlock NodeType;
692 typedef ::clang::CFGBlock::succ_iterator ChildIteratorType;
694 static NodeType* getEntryNode(::clang::CFGBlock* BB)
697 static inline ChildIteratorType child_begin(NodeType* N)
698 { return N->succ_begin(); }
700 static inline ChildIteratorType child_end(NodeType* N)
701 { return N->succ_end(); }
704 template <> struct GraphTraits< const ::clang::CFGBlock* > {
705 typedef const ::clang::CFGBlock NodeType;
706 typedef ::clang::CFGBlock::const_succ_iterator ChildIteratorType;
708 static NodeType* getEntryNode(const clang::CFGBlock* BB)
711 static inline ChildIteratorType child_begin(NodeType* N)
712 { return N->succ_begin(); }
714 static inline ChildIteratorType child_end(NodeType* N)
715 { return N->succ_end(); }
718 template <> struct GraphTraits<Inverse<const ::clang::CFGBlock*> > {
719 typedef const ::clang::CFGBlock NodeType;
720 typedef ::clang::CFGBlock::const_pred_iterator ChildIteratorType;
722 static NodeType *getEntryNode(Inverse<const ::clang::CFGBlock*> G)
725 static inline ChildIteratorType child_begin(NodeType* N)
726 { return N->pred_begin(); }
728 static inline ChildIteratorType child_end(NodeType* N)
729 { return N->pred_end(); }
734 template <> struct GraphTraits< ::clang::CFG* >
735 : public GraphTraits< ::clang::CFGBlock* > {
737 typedef ::clang::CFG::iterator nodes_iterator;
739 static NodeType *getEntryNode(::clang::CFG* F) { return &F->getEntry(); }
740 static nodes_iterator nodes_begin(::clang::CFG* F) { return F->begin(); }
741 static nodes_iterator nodes_end(::clang::CFG* F) { return F->end(); }
744 template <> struct GraphTraits<const ::clang::CFG* >
745 : public GraphTraits<const ::clang::CFGBlock* > {
747 typedef ::clang::CFG::const_iterator nodes_iterator;
749 static NodeType *getEntryNode( const ::clang::CFG* F) {
750 return &F->getEntry();
752 static nodes_iterator nodes_begin( const ::clang::CFG* F) {
755 static nodes_iterator nodes_end( const ::clang::CFG* F) {
760 template <> struct GraphTraits<Inverse<const ::clang::CFG*> >
761 : public GraphTraits<Inverse<const ::clang::CFGBlock*> > {
763 typedef ::clang::CFG::const_iterator nodes_iterator;
765 static NodeType *getEntryNode(const ::clang::CFG* F) { return &F->getExit(); }
766 static nodes_iterator nodes_begin(const ::clang::CFG* F) { return F->begin();}
767 static nodes_iterator nodes_end(const ::clang::CFG* F) { return F->end(); }
769 } // end llvm namespace