OpenASIP  2.0
ProgramGraph.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ProgramGraph.cc
26  *
27  * Implementation of ProgramGraph class.
28  *
29  * ProgramGraph represents a program in PDG form.
30  *
31  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
32  * @note rating: red
33  */
34 
35 #include "ProgramGraph.hh"
36 #include "Port.hh"
37 #include "Bus.hh"
38 #include "UniversalMachine.hh"
39 #include "NullProgram.hh"
40 #include "ControlFlowGraph.hh"
42 #include "DataDependenceGraph.hh"
45 #include "SequenceTools.hh"
46 
47 /**
48  * Constructor.
49  *
50  * Creates a new ProgramGraph from Program
51  * @param program Program in POM
52  */
53 
56  : program_(program){
57  try {
58  for (int i = 0; i < program.procedureCount(); i++) {
59  ControlFlowGraph* cfg = NULL;
60  cfg = new ControlFlowGraph(program.procedure(i));
61  cfgs_.push_back(cfg);
62  ControlDependenceGraph* cdg = NULL;
63  try {
64  cdg = new ControlDependenceGraph(*cfg);
65  cdgs_.push_back(cdg);
66  } catch (const InvalidData& e) {
67  delete cdg;
68  continue;
69  }
71  DataDependenceGraph* ddg = NULL;
72  ddg = builder.build(*cfg, DataDependenceGraph::ALL_ANTIDEPS,mach);
73  ddgs_.push_back(ddg);
74  ProgramDependenceGraph* pdg = NULL;
75  pdg = new ProgramDependenceGraph(*cdg, *ddg);
76  pdgs_.push_back(pdg);
77  }
78  } catch (Exception&) {
79  clear();
80  throw;
81  }
82 }
83 
84 /**
85  * Deletes all graphs owned by this.
86  */
92 }
93 
94 /**
95  * Destructor.
96  *
97  * Removes the graphs.
98  */
100  clear();
101 }
102 
103 /**
104  * Convert Program Graph to Program Object Model
105  * and returns POM
106  * @return POM
107  */
110  ///TODO: convert PDG to POM
111  /// this is basically scheduling
113 }
114 
115 /**
116  * Returns MoveNode of program representation corresponding
117  * to Move of POM.
118  * @param move move from POM
119  * @return MoveNode corresponding to move
120  */
121 MoveNode&
123  ///TODO: find a move and return corresponding MoveNode
124  return *(new MoveNode());
125 }
126 
127 /**
128  * Returns number of PDG's in a program graph, equals number of procedures
129  * in program.
130  * @return number of PDG's in a graph
131  */
132 int
134  return pdgs_.size();
135 }
136 
137 /**
138  * Returns a PDG for procedure identified by index.
139  * @param i index of a procedure
140  * @return PDG for given procedure
141  */
144  if (i < 0 || i >= graphCount()){
145  throw InvalidData(__FILE__, __LINE__, __func__, "Trying to access"
146  " graph out of a scope!");
147  }
148  return pdgs_.at(i);
149 }
150 
151 /**
152  * Returns a PDG for procedure identified by procedure name.
153  * @param name name of a procedure
154  * @return PDG for given procedure
155  */
157 ProgramGraph::graph(const std::string name) {
158  for (int i = 0; i < graphCount(); i++) {
159  if (pdgs_.at(i)->name() == name) {
160  return pdgs_.at(i);
161  }
162  }
163  throw InvalidData(__FILE__, __LINE__, __func__, "Can not find graph of "
164  "procedure " + name);
165 }
ProgramGraph::pdgs_
std::vector< ProgramDependenceGraph * > pdgs_
Vector of PDG's for each procedure.
Definition: ProgramGraph.hh:90
TTAProgram::Program
Definition: Program.hh:63
ControlDependenceGraph.hh
SequenceTools.hh
ProgramGraph::nodeOf
MoveNode & nodeOf(const TTAProgram::Move &) const
Definition: ProgramGraph.cc:122
ProgramGraph.hh
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
ProgramGraph::ddgs_
std::vector< DataDependenceGraph * > ddgs_
Vector of DDG's for each procedure.
Definition: ProgramGraph.hh:88
TTAProgram::NullProgram::instance
static NullProgram & instance()
Definition: NullProgram.cc:72
UniversalMachine.hh
Port.hh
DataDependenceGraphBuilder.hh
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
ProgramGraph::cdgs_
std::vector< ControlDependenceGraph * > cdgs_
Vector of CDG's for each procedure.
Definition: ProgramGraph.hh:86
ProgramDependenceGraph.hh
DataDependenceGraph::ALL_ANTIDEPS
@ ALL_ANTIDEPS
Definition: DataDependenceGraph.hh:82
ProgramGraph::graph
ProgramDependenceGraph * graph(const std::string)
Definition: ProgramGraph.cc:157
InvalidData
Definition: Exception.hh:149
ProgramGraph::generateProgram
TTAProgram::Program & generateProgram() const
Definition: ProgramGraph.cc:109
ControlFlowGraph.hh
__func__
#define __func__
Definition: Application.hh:67
ProgramDependenceGraph::ProgramDependenceGraph
ProgramDependenceGraph(ControlDependenceGraph &cdg, DataDependenceGraph &ddg)
Definition: ProgramDependenceGraph.cc:93
ProgramGraph::graphAt
ProgramDependenceGraph * graphAt(int)
Definition: ProgramGraph.cc:143
ProgramDependenceGraph
Definition: ProgramDependenceGraph.hh:51
TTAProgram::Move
Definition: Move.hh:55
Exception
Definition: Exception.hh:54
Bus.hh
ProgramGraph::cfgs_
std::vector< ControlFlowGraph * > cfgs_
Vector of CFG's for each procedure.
Definition: ProgramGraph.hh:84
ProgramGraph::graphCount
int graphCount() const
Definition: ProgramGraph.cc:133
ProgramGraph::ProgramGraph
ProgramGraph(TTAProgram::Program &program, const TTAMachine::Machine &mach)
Definition: ProgramGraph.cc:54
DataDependenceGraphBuilder
Definition: DataDependenceGraphBuilder.hh:70
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
DataDependenceGraphBuilder::build
virtual DataDependenceGraph * build(ControlFlowGraph &cGraph, DataDependenceGraph::AntidependenceLevel antidependenceLevel, const TTAMachine::Machine &mach, const UniversalMachine *um=NULL, bool createMemAndFUDeps=true, bool createDeathInformation=true, llvm::AliasAnalysis *AA=NULL)
Definition: DataDependenceGraphBuilder.cc:2120
ControlDependenceGraph
Definition: ControlDependenceGraph.hh:65
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
ProgramGraph::~ProgramGraph
virtual ~ProgramGraph()
Definition: ProgramGraph.cc:99
BoostGraph< ProgramDependenceNode, ProgramDependenceEdge >::name
virtual const TCEString & name() const
NullProgram.hh
ProgramDependenceGraph::program_
TTAProgram::Program * program_
Original Program object, to get instruction reference manager.
Definition: ProgramDependenceGraph.hh:234
ProgramGraph::clear
void clear()
Definition: ProgramGraph.cc:87
ControlFlowGraph
Definition: ControlFlowGraph.hh:100
TTAMachine::Machine
Definition: Machine.hh:73