OpenASIP 2.2
Loading...
Searching...
No Matches
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 "ProgramPass.hh"
34
35#include <boost/format.hpp>
36#include <chrono>
37#include <ctime>
38
39#include "Application.hh"
40#include "InterPassData.hh"
41#include "InterPassDatum.hh"
42#include "POMDisassembler.hh"
43#include "Procedure.hh"
44#include "ProcedurePass.hh"
45#include "Program.hh"
46
47/**
48 * Constructor.
49 */
53
54/**
55 * Destructor.
56 */
59
60/**
61 * Executes the given procedure pass on each procedure of the given
62 * program in the original program order.
63 *
64 * A helper function for implementing most simplest types of program passes.
65 *
66 * @param program The program to handle.
67 * @param machine The target machine if any. (NullMachine::instance() if
68 * target machine is irrelevant).
69 * @param procedurePass The procedure pass to execute.
70 * @exception In case handling is unsuccesful for any reason (cfg might
71 * still get modified).
72 */
73void
75 TTAProgram::Program& program, const TTAMachine::Machine& targetMachine,
76 ProcedurePass& procedurePass) {
77 auto totalTimeStart = std::chrono::steady_clock::now();
78
79 FunctionNameList proceduresToProcess, proceduresToIgnore;
80 if (procedurePass.interPassData().hasDatum("FUNCTIONS_TO_PROCESS")) {
81 proceduresToProcess = dynamic_cast<FunctionNameList&>(
82 procedurePass.interPassData().datum("FUNCTIONS_TO_PROCESS"));
83 } else if (procedurePass.interPassData().hasDatum("FUNCTIONS_TO_IGNORE")) {
84 proceduresToIgnore =
85 dynamic_cast<FunctionNameList&>(
86 procedurePass.interPassData().datum("FUNCTIONS_TO_IGNORE"));
87 }
88
89 std::size_t proceduresDone = 0;
90 // always call procedureCount() again because a pass might have
91 // added a new procedure to the program that needs to be handled
92 for (int procIndex = 0; procIndex < program.procedureCount();
93 ++procIndex) {
94 TTAProgram::Procedure& proc = program.procedure(procIndex);
95
96 if (proceduresToProcess.size() > 0 &&
97 proceduresToProcess.find(proc.name()) ==
98 proceduresToProcess.end())
99 continue;
100
101 if (proceduresToIgnore.size() > 0 &&
102 proceduresToIgnore.find(proc.name()) !=
103 proceduresToIgnore.end())
104 continue;
105
106 auto currentTimeStart = std::chrono::steady_clock::now();
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 long currentElapsed =
128 std::chrono::duration_cast<std::chrono::seconds>(
129 std::chrono::steady_clock::now() - currentTimeStart)
130 .count();
131 long totalElapsed =
132 std::chrono::duration_cast<std::chrono::seconds>(
133 std::chrono::steady_clock::now() - totalTimeStart)
134 .count();
135 long eta = static_cast<long>(
136 (totalElapsed / proceduresDone) *
137 (totalProcedures - proceduresDone));
139 << (boost::format(" %d min %d s. Total %d min %d s. ETA in "
140 "%d min %d s") %
141 (currentElapsed / 60) % (currentElapsed % 60) %
142 (totalElapsed / 60) % (totalElapsed % 60) % (eta / 60) %
143 (eta % 60))
144 .str()
145 << std::endl;
146 }
147 }
148}
149
150void
152 TTAProgram::Program& program, const TTAMachine::Machine& targetMachine) {
153 ProcedurePass* procPass = dynamic_cast<ProcedurePass*>(this);
154 if (procPass != NULL) {
155 executeProcedurePass(program, targetMachine, *procPass);
156 } else {
157 abortWithError("Program pass is not also a procedure pass so you "
158 "must overload handleProgram method!");
159 }
160}
#define abortWithError(message)
find Finds info of the inner loops in the program
static int verboseLevel()
static std::ostream & logStream()
bool hasDatum(const std::string &key) const
InterPassDatum & datum(const std::string &key)
virtual void handleProcedure(TTAProgram::Procedure &procedure, const TTAMachine::Machine &targetMachine)
virtual ~ProgramPass()
ProgramPass(InterPassData &data)
static void executeProcedurePass(TTAProgram::Program &program, const TTAMachine::Machine &targetMachine, ProcedurePass &procedurePass)
virtual void handleProgram(TTAProgram::Program &program, const TTAMachine::Machine &targetMachine)
InterPassData & interPassData()
TCEString name() const
Definition Procedure.hh:66