OpenASIP  2.0
CostEstimates.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 CostEstimates.cc
26  *
27  * Implementation of CostEstimates class.
28  *
29  * @author Jari Mäntyneva 2006 (jari.mantyneva-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <map>
34 #include "CostEstimates.hh"
35 #include "Program.hh"
36 
37 using std::map;
38 
39 /**
40  * The contstructor.
41  */
43  area_(0), longestPathDelay_(0) {
44 }
45 
46 /**
47  * The destructor.
48  */
50 }
51 
52 /**
53  * Sets the area estimate (in gates).
54  *
55  * @param area Area estimate value (in gates).
56  */
57 void
58 CostEstimates::setArea(double area) {
59 
60  area_ = area;
61 }
62 
63 /**
64  * Sets the longest path delay estimate (in nano seconds).
65  *
66  * @param delay Longest path delay estimte value (in nano seconds).
67  */
68 void
70 
71  longestPathDelay_ = delay;
72 }
73 
74 /**
75  * Sets new energy estimate for the given program.
76  *
77  * If there was an old energy value for the given key it is removed first.
78  *
79  * @param program Program that is used as a key.
80  * @param energy Energy consumed while running the program (in milli joules).
81  */
82 void
84  const TTAProgram::Program& program, double energy) {
85 
86  map<const TTAProgram::Program*, double>::iterator iter =
87  energyMap_.find(&program);
88  if (iter != energyMap_.end()) {
89  energyMap_.erase(iter);
90  }
91  energyMap_.insert(
92  std::pair<const TTAProgram::Program*, double>(&program, energy));
93 }
94 
95 /**
96  * Returns the area estimate (in gates).
97  *
98  * @return Returns the area estimate (in gates).
99  */
100 double
102 
103  return area_;
104 }
105 
106 /**
107  * Returns the longest path delay estimate (in nano seconds).
108  *
109  * @return Returns the longest path delay estimate (in nano seconds).
110  */
111 double
113 
114  return longestPathDelay_;
115 }
116 
117 /**
118  * Returns the number of different energy estimates (one for each program)
119  * in the cost estimation data.
120  *
121  * @return Returns the number of stored energy estimates.
122  */
123 int
125 
126  return energyMap_.size();
127 }
128 
129 /**
130  * Returns the energy value from the given index.
131  *
132  * @param index The index.
133  * @return The energy value in the given index.
134  * @exception OutOfRange If the given index is less than 0 or greater or
135  * equal to the number of energies.
136  */
137 double
138 CostEstimates::energy(int index) const {
139  if (index < 0 || index >= energies()) {
140  throw OutOfRange(__FILE__, __LINE__, __func__);
141  }
142  map<const TTAProgram::Program*, double>::const_iterator iter =
143  energyMap_.begin();
144  while (index > 0) {
145  iter++;
146  index--;
147  }
148  return (*iter).second;
149 }
150 
151 /**
152  * Returns the energy value corresponding to the Program.
153  *
154  * @param program Program of which energy is returned.
155  * @return The energy of the Program.
156  * @exception KeyNotFound Is thrown if program has no energy set.
157  */
158 double
160  map<const TTAProgram::Program*, double>::const_iterator iter =
161  energyMap_.find(&program);
162  if (iter == energyMap_.end()) {
163  throw KeyNotFound(__FILE__, __LINE__, __func__);
164  }
165  return (*iter).second;
166 }
TTAProgram::Program
Definition: Program.hh:63
CostEstimates::setLongestPathDelay
void setLongestPathDelay(double delay)
Definition: CostEstimates.cc:69
CostEstimates::setEnergy
void setEnergy(const TTAProgram::Program &program, double energy)
Definition: CostEstimates.cc:83
OutOfRange
Definition: Exception.hh:320
CostEstimates::energy
double energy(int index) const
Definition: CostEstimates.cc:138
CostEstimates::energyMap_
std::map< const TTAProgram::Program *, double > energyMap_
Map containing programs and energies consumed in running the programs.
Definition: CostEstimates.hh:74
CostEstimates::energies
int energies() const
Definition: CostEstimates.cc:124
CostEstimates::longestPathDelay
double longestPathDelay() const
Definition: CostEstimates.cc:112
CostEstimates::~CostEstimates
virtual ~CostEstimates()
Definition: CostEstimates.cc:49
CostEstimates.hh
__func__
#define __func__
Definition: Application.hh:67
CostEstimates::area_
double area_
Area estimation value (in gates).
Definition: CostEstimates.hh:76
CostEstimates::CostEstimates
CostEstimates()
Definition: CostEstimates.cc:42
CostEstimates::area
double area() const
Definition: CostEstimates.cc:101
CostEstimates::longestPathDelay_
double longestPathDelay_
Longest path delay estimation value (in nano seconds).
Definition: CostEstimates.hh:78
Program.hh
CostEstimates::setArea
void setArea(double area)
Definition: CostEstimates.cc:58
KeyNotFound
Definition: Exception.hh:285
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80