GPUOcelot

ProgramStructureGraph.h

Go to the documentation of this file.
00001 
00007 #pragma once
00008 
00009 // Ocelot Includes
00010 #include <ocelot/ir/interface/ControlFlowGraph.h>
00011 
00012 namespace analysis
00013 {
00014 
00021 class ProgramStructureGraph
00022 {
00023 public:
00024   class Block
00025   {
00026   public:
00027     typedef ir::ControlFlowGraph           CFG;
00028     typedef ir::BasicBlock                 BB;
00029     typedef BB::instruction_iterator       instruction_iterator;
00030     typedef CFG::pointer_iterator          basic_block_iterator;
00031     typedef BB::const_instruction_iterator const_instruction_iterator;
00032     typedef CFG::const_pointer_iterator    const_basic_block_iterator;
00033 
00034     // Forward Declarations
00035     class const_iterator;
00036     
00038     class block_iterator
00039     {
00040     public:
00041       typedef block_iterator self;
00042       typedef ir::BasicBlock value_type;
00043       typedef value_type&    reference;
00044       typedef value_type*    pointer;
00045     
00046     public:       
00047       block_iterator();
00048       block_iterator(const block_iterator&);
00049       explicit block_iterator(const basic_block_iterator& i,
00050         const basic_block_iterator& begin,
00051         const basic_block_iterator& end);
00052 
00053     public:
00054       reference operator*() const;
00055       pointer operator->() const;
00056       self& operator++();
00057       self operator++(int);
00058       self& operator--();
00059       self operator--(int);
00060       
00061       bool operator==(const self&) const;
00062       bool operator!=(const self&) const; 
00063     
00064       bool begin() const;
00065       bool end() const;
00066     
00067     private:
00068       basic_block_iterator _iterator; 
00069       basic_block_iterator _begin;
00070       basic_block_iterator _end;
00071 
00072       friend class const_block_iterator;
00073       friend class Block;
00074     };
00075 
00077     class const_block_iterator
00078     {
00079     public:
00080       typedef const_block_iterator self;
00081       typedef ir::BasicBlock       value_type;
00082       typedef const value_type&    reference;
00083       typedef const value_type*    pointer;
00084     
00085     public:
00086       const_block_iterator();
00087       const_block_iterator(const const_block_iterator&);
00088       const_block_iterator(const block_iterator&);
00089       explicit const_block_iterator(const const_basic_block_iterator& i,
00090         const const_basic_block_iterator& begin,
00091         const const_basic_block_iterator& end);
00092 
00093     public:
00094       reference operator*() const;
00095       pointer operator->() const;
00096       self& operator++();
00097       self operator++(int);
00098       self& operator--();
00099       self operator--(int);
00100       
00101       bool operator==(const self&) const;
00102       bool operator!=(const self&) const; 
00103       
00104       bool begin() const;
00105       bool end() const;
00106       
00107     private:
00108       const_basic_block_iterator _iterator; 
00109       const_basic_block_iterator _begin;
00110       const_basic_block_iterator _end;
00111     };
00112 
00115     class iterator
00116     {
00117     public:
00118       typedef iterator                         self;
00119       typedef instruction_iterator::value_type value_type;
00120       typedef value_type&                      reference;
00121       typedef value_type*                      pointer;
00122 
00123     public:       
00124       iterator();
00125       explicit iterator(const block_iterator&,
00126         const instruction_iterator&);
00127     public:
00128       reference operator*() const;
00129       pointer operator->() const;
00130       self& operator++();
00131       self operator++(int);
00132       self& operator--();
00133       self operator--(int);
00134       
00135       bool operator==(const self&) const;
00136       bool operator!=(const self&) const; 
00137 
00138     private:
00139       instruction_iterator _instruction;
00140       block_iterator       _basicBlock;
00141     
00142       friend class const_iterator;
00143       friend class Block;
00144 
00145     };
00146     
00148     class const_iterator
00149     {
00150     public:
00151       typedef const_iterator                   self;
00152       typedef instruction_iterator::value_type value_type;
00153       typedef value_type&                      reference;
00154       typedef value_type*                      pointer;
00155     
00156     public:       
00157       const_iterator();
00158       const_iterator(const iterator&);
00159       const_iterator(const const_iterator&);
00160       explicit const_iterator(const const_block_iterator&,
00161         const const_instruction_iterator&);
00162     public:
00163       reference operator*() const;
00164       pointer operator->() const;
00165       self& operator++();
00166       self operator++(int);
00167       self& operator--();
00168       self operator--(int);
00169       
00170       bool operator==(const self&) const;
00171       bool operator!=(const self&) const; 
00172     
00173     private:
00174       const_instruction_iterator _instruction;
00175       const_block_iterator       _basicBlock;   
00176     };
00177     
00178     class const_successor_iterator;
00179     
00181     class successor_iterator
00182     {
00183     public:
00184       typedef successor_iterator self;
00185       typedef ir::BasicBlock     value_type;
00186       typedef value_type&        reference;
00187       typedef value_type*        pointer;
00188     
00189     public:       
00190       successor_iterator();
00191       successor_iterator(const successor_iterator&);
00192       explicit successor_iterator(const block_iterator&,
00193         const basic_block_iterator&);
00194     public:
00195       reference operator*() const;
00196       pointer operator->() const;
00197       self& operator++();
00198       self operator++(int);
00199       self& operator--();
00200       self operator--(int);
00201             
00202       bool operator==(const self&) const;
00203       bool operator!=(const self&) const; 
00204     
00205     private:
00206       block_iterator         _block;
00207       basic_block_iterator _successor;    
00208     
00209       friend class const_successor_iterator;
00210     };
00211     
00213     class const_successor_iterator
00214     {
00215     public:
00216       typedef const_successor_iterator self;
00217       typedef ir::BasicBlock           value_type;
00218       typedef const value_type&        reference;
00219       typedef const value_type*        pointer;
00220     
00221     public:
00222       const_successor_iterator();
00223       const_successor_iterator(const const_successor_iterator&);
00224       const_successor_iterator(const successor_iterator&);
00225       explicit const_successor_iterator(const const_block_iterator&,
00226         const const_basic_block_iterator&);
00227 
00228     public:
00229       reference operator*() const;
00230       pointer operator->() const;
00231       self& operator++();
00232       self operator++(int);
00233       self& operator--();
00234       self operator--(int);
00235             
00236       bool operator==(const self&) const;
00237       bool operator!=(const self&) const; 
00238     
00239     private:
00240       const_block_iterator       _block;
00241       const_basic_block_iterator _successor;    
00242     };
00243     
00244     class const_predecessor_iterator;
00245     
00247     class predecessor_iterator
00248     {
00249     public:
00250       typedef predecessor_iterator     self;
00251       typedef ir::BasicBlock           value_type;
00252       typedef value_type&              reference;
00253       typedef value_type*              pointer;
00254     
00255     public:       
00256       predecessor_iterator();
00257       predecessor_iterator(const predecessor_iterator&);
00258       explicit predecessor_iterator(const block_iterator&,
00259         const basic_block_iterator&);
00260     public:
00261       reference operator*() const;
00262       pointer operator->() const;
00263       self& operator++();
00264       self operator++(int);
00265       self& operator--();
00266       self operator--(int);
00267       
00268       bool operator==(const self&) const;
00269       bool operator!=(const self&) const; 
00270     
00271     private:
00272       block_iterator       _block;
00273       basic_block_iterator _predecessor;  
00274     
00275       friend class const_predecessor_iterator;
00276     };
00277     
00279     class const_predecessor_iterator
00280     {
00281     public:
00282       typedef const_predecessor_iterator self;
00283       typedef ir::BasicBlock             value_type;
00284       typedef const value_type&          reference;
00285       typedef const value_type*          pointer;
00286     
00287     public:       
00288       const_predecessor_iterator();
00289       const_predecessor_iterator(const const_predecessor_iterator&);
00290       const_predecessor_iterator(const predecessor_iterator&);
00291       explicit const_predecessor_iterator(const const_block_iterator&,
00292         const const_basic_block_iterator&);
00293     public:
00294       reference operator*() const;
00295       pointer operator->() const;
00296       self& operator++();
00297       self operator++(int);
00298       self& operator--();
00299       self operator--(int);
00300       
00301       bool operator==(const self&) const;
00302       bool operator!=(const self&) const; 
00303     
00304     private:
00305       const_block_iterator       _block;
00306       const_basic_block_iterator _predecessor;  
00307     };
00308     
00309   public:
00311     iterator begin();
00313     iterator end();
00314     
00316     const_iterator begin() const;
00318     const_iterator end() const;
00319     
00320   public:
00322     block_iterator block_begin();
00324     block_iterator block_end();
00325     
00327     const_block_iterator block_begin() const;
00329     const_block_iterator block_end() const;
00330 
00331   public:
00333     successor_iterator successors_begin();
00335     successor_iterator successors_end();
00336     
00338     const_successor_iterator successors_begin() const;
00340     const_successor_iterator successors_end() const;
00341 
00342   public:
00344     predecessor_iterator predecessors_begin();
00346     predecessor_iterator predecessors_end();
00347     
00349     const_predecessor_iterator predecessors_begin() const;
00351     const_predecessor_iterator predecessors_end() const;
00352 
00353   public:
00355     block_iterator insert(ir::ControlFlowGraph::iterator block,
00356       block_iterator position);
00358     block_iterator insert(ir::ControlFlowGraph::iterator block);
00359 
00360   public:
00362     iterator insert(ir::Instruction* instruction, iterator position);
00364     iterator insert(ir::Instruction* instruction);
00365     
00366   public:
00368     bool empty() const;
00370     size_t instructions() const;
00372     size_t basicBlocks() const;
00373     
00374   private:
00375     typedef ir::ControlFlowGraph::BlockPointerVector BlockPointerVector;
00376     
00377   private:
00378     BlockPointerVector _blocks;
00379   };
00380 
00381 public:
00382   typedef std::vector<Block>          BlockVector;
00383   typedef BlockVector::iterator       iterator;
00384   typedef BlockVector::const_iterator const_iterator;
00385 
00386 public:
00388   iterator begin();
00390   iterator end();
00391   
00393   const_iterator begin() const;
00395   const_iterator end() const;
00396 
00397 public:
00399   size_t size() const;
00401   bool empty() const;
00402   
00403 protected:
00404   BlockVector _blocks;
00405 };
00406 
00407 }
00408 
00409 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines