OpenASIP  2.0
ProgramPass.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 ProgramPass.cc
26  *
27  * Definition of ProgramPass class.
28  *
29  * @author Pekka Jääskeläinen 2007 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <boost/timer.hpp>
34 #include <boost/format.hpp>
35 
36 #include "ProgramPass.hh"
37 #include "Program.hh"
38 #include "ProcedurePass.hh"
39 #include "Application.hh"
40 #include "Procedure.hh"
41 #include "POMDisassembler.hh"
42 #include "InterPassDatum.hh"
43 #include "InterPassData.hh"
44 
45 /**
46  * Constructor.
47  */
49  SchedulerPass(data) {
50 }
51 
52 /**
53  * Destructor.
54  */
56 }
57 
58 /**
59  * Executes the given procedure pass on each procedure of the given
60  * program in the original program order.
61  *
62  * A helper function for implementing most simplest types of program passes.
63  *
64  * @param program The program to handle.
65  * @param machine The target machine if any. (NullMachine::instance() if
66  * target machine is irrelevant).
67  * @param procedurePass The procedure pass to execute.
68  * @exception In case handling is unsuccesful for any reason (cfg might
69  * still get modified).
70  */
71 void
73  TTAProgram::Program& program, const TTAMachine::Machine& targetMachine,
74  ProcedurePass& procedurePass) {
75  boost::timer totalTime;
76 
77  FunctionNameList proceduresToProcess, proceduresToIgnore;
78  if (procedurePass.interPassData().hasDatum("FUNCTIONS_TO_PROCESS")) {
79  proceduresToProcess =
80  dynamic_cast<FunctionNameList&>(
81  procedurePass.interPassData().datum("FUNCTIONS_TO_PROCESS"));
82  } else if (procedurePass.interPassData().hasDatum("FUNCTIONS_TO_IGNORE")) {
83  proceduresToIgnore =
84  dynamic_cast<FunctionNameList&>(
85  procedurePass.interPassData().datum("FUNCTIONS_TO_IGNORE"));
86  }
87 
88  std::size_t proceduresDone = 0;
89  // always call procedureCount() again because a pass might have
90  // added a new procedure to the program that needs to be handled
91  for (int procIndex = 0; procIndex < program.procedureCount();
92  ++procIndex) {
93  TTAProgram::Procedure& proc = program.procedure(procIndex);
94 
95  if (proceduresToProcess.size() > 0 &&
96  proceduresToProcess.find(proc.name()) ==
97  proceduresToProcess.end())
98  continue;
99 
100  if (proceduresToIgnore.size() > 0 &&
101  proceduresToIgnore.find(proc.name()) !=
102  proceduresToIgnore.end())
103  continue;
104 
105 
106  boost::timer currentTime;
107  std::size_t totalProcedures = 0;
108  if (Application::verboseLevel() > 0) {
109 
110  if (proceduresToProcess.size() > 0) {
111  totalProcedures = proceduresToProcess.size();
112  } else {
113  totalProcedures = program.procedureCount();
114  }
115 
116  totalProcedures -= proceduresToIgnore.size();
118  << std::endl
119  << "procedure: " << proc.name()
120  << (boost::format(" (%d/%d)")
121  % (proceduresDone + 1) % totalProcedures).str();
122  }
123  procedurePass.handleProcedure(proc, targetMachine);
124  ++proceduresDone;
125 
126  if (Application::verboseLevel() > 0) {
127  double cur = currentTime.elapsed();
128  double tot = totalTime.elapsed();
129  long currentElapsed = static_cast<long>(cur);
130  long totalElapsed = static_cast<long>(tot);
131  long eta =
132  static_cast<long>(
133  (tot / proceduresDone) *
134  (totalProcedures - proceduresDone));
136  << (boost::format(
137  " %d min %d s. Total %d min %d s. ETA in %d min %d s")
138  % (currentElapsed / 60) % (currentElapsed % 60)
139  % (totalElapsed / 60) % (totalElapsed % 60)
140  % (eta / 60) % (eta % 60)).str()
141  << std::endl;
142  }
143  }
144 }
145 
146 void
148  TTAProgram::Program& program, const TTAMachine::Machine& targetMachine) {
149  ProcedurePass* procPass = dynamic_cast<ProcedurePass*>(this);
150  if (procPass != NULL) {
151  executeProcedurePass(program, targetMachine, *procPass);
152  } else {
153  abortWithError("Program pass is not also a procedure pass so you "
154  "must overload handleProgram method!");
155  }
156 }
ProcedurePass
Definition: ProcedurePass.hh:53
SimpleInterPassDatum
Definition: InterPassDatum.hh:64
ProgramPass::~ProgramPass
virtual ~ProgramPass()
Definition: ProgramPass.cc:55
TTAProgram::Program
Definition: Program.hh:63
SchedulerPass
Definition: SchedulerPass.hh:43
ProgramPass::handleProgram
virtual void handleProgram(TTAProgram::Program &program, const TTAMachine::Machine &targetMachine)
Definition: ProgramPass.cc:147
Procedure.hh
ProgramPass::ProgramPass
ProgramPass(InterPassData &data)
Definition: ProgramPass.cc:48
Application::verboseLevel
static int verboseLevel()
Definition: Application.hh:176
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
POMDisassembler.hh
ProcedurePass::handleProcedure
virtual void handleProcedure(TTAProgram::Procedure &procedure, const TTAMachine::Machine &targetMachine)
Definition: ProcedurePass.cc:73
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
ProgramPass.hh
InterPassDatum.hh
ProcedurePass.hh
Application.hh
InterPassData
Definition: InterPassData.hh:48
InterPassData::hasDatum
bool hasDatum(const std::string &key) const
Definition: InterPassData.cc:75
SchedulerPass::interPassData
InterPassData & interPassData()
Definition: SchedulerPass.cc:53
Program.hh
InterPassData.hh
TTAProgram::Procedure::name
TCEString name() const
Definition: Procedure.hh:66
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
InterPassData::datum
InterPassDatum & datum(const std::string &key)
Definition: InterPassData.cc:62
TTAProgram::Procedure
Definition: Procedure.hh:55
ProgramPass::executeProcedurePass
static void executeProcedurePass(TTAProgram::Program &program, const TTAMachine::Machine &targetMachine, ProcedurePass &procedurePass)
Definition: ProgramPass.cc:72
TTAMachine::Machine
Definition: Machine.hh:73