OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
RegisterQuantityCheck Class Reference

#include <RegisterQuantityCheck.hh>

Inheritance diagram for RegisterQuantityCheck:
Inheritance graph
Collaboration diagram for RegisterQuantityCheck:
Collaboration graph

Public Member Functions

 RegisterQuantityCheck ()
 
virtual ~RegisterQuantityCheck ()
 
virtual bool check (const TTAMachine::Machine &mach) const
 
virtual bool check (const TTAMachine::Machine &mach, MachineCheckResults &results) const
 
bool checkWithIgnore (const TTAMachine::Machine &mach, const std::set< std::string > &ignoreRFs) const
 
bool checkWithIgnore (const TTAMachine::Machine &mach, MachineCheckResults &results, const std::set< std::string > &ignoreRFs) const
 
bool checkIntRegs (const TTAMachine::Machine &mach) const
 
bool canFixIntRegs (const TTAMachine::Machine &mach) const
 
bool fixIntRegs (TTAMachine::Machine &mach) const
 
- Public Member Functions inherited from MachineCheck
virtual std::string shortDescription () const
 
virtual std::string description () const
 
virtual bool canFix (const TTAMachine::Machine &mach) const
 
virtual std::string fix (TTAMachine::Machine &mach) const
 
virtual ~MachineCheck ()
 

Private Types

typedef std::pair< const TTAMachine::RegisterFile *, int > Register
 

Private Member Functions

void findGuardRegisters (const TTAMachine::Machine &mach, std::set< Register > &registers, const std::set< std::string > &ignoreRFs) const
 
unsigned int countIntRegisters (const TTAMachine::Machine &mach, const std::set< Register > &guardRegs, const std::set< std::string > &ignoreRFs) const
 
bool checkPredRegs (const unsigned int &regCount, MachineCheckResults *results) const
 
unsigned int missingIntRegs (const unsigned int &regCount, MachineCheckResults *results, bool isFullyConnected) const
 

Private Attributes

FullyConnectedCheck fullyConCheck_
 

Additional Inherited Members

- Protected Member Functions inherited from MachineCheck
 MachineCheck (const std::string &shortDesc_)
 

Detailed Description

Definition at line 48 of file RegisterQuantityCheck.hh.

Member Typedef Documentation

◆ Register

typedef std::pair<const TTAMachine::RegisterFile*, int> RegisterQuantityCheck::Register
private

Definition at line 71 of file RegisterQuantityCheck.hh.

Constructor & Destructor Documentation

◆ RegisterQuantityCheck()

RegisterQuantityCheck::RegisterQuantityCheck ( )

Definition at line 47 of file RegisterQuantityCheck.cc.

47 :
48 MachineCheck("Checks that machine has enough registers") {}

◆ ~RegisterQuantityCheck()

RegisterQuantityCheck::~RegisterQuantityCheck ( )
virtual

Definition at line 50 of file RegisterQuantityCheck.cc.

50{}

Member Function Documentation

◆ canFixIntRegs()

bool RegisterQuantityCheck::canFixIntRegs ( const TTAMachine::Machine mach) const

Returns true if an int register file found, meaning int registers can be added.

Returns
True, if int rf found.

Definition at line 380 of file RegisterQuantityCheck.cc.

380 {
383
384 // return true if an int register file was found
385 for (int i = 0; i < regNav.count(); i++) {
386 TTAMachine::RegisterFile* rf = regNav.item(i);
387 if (rf->width() == 32) {
388 return true;
389 }
390 }
391 return false;
392}
virtual int width() const
ComponentType * item(int index) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450

References TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Machine::registerFileNavigator(), and TTAMachine::BaseRegisterFile::width().

Referenced by SimpleICOptimizer::fixIntRegisters().

Here is the call graph for this function:

◆ check() [1/2]

bool RegisterQuantityCheck::check ( const TTAMachine::Machine mach) const
virtual

Checks register quantities, just returns false if problems where found.

Parameters
machMachine to be checked for registers resources.
resultsMachineCheckResults where possible errors are added.
Returns
True if no problems were found during testing, false otherwise.

Definition at line 61 of file RegisterQuantityCheck.cc.

61 {
62 std::set<Register> guardRegs;
63 const std::set<std::string> ignoreRFs; //empty, no ignore
64
65 // find all registers that can be used for guards
66 findGuardRegisters(mach, guardRegs, ignoreRFs);
67
68 // check if enough predicate registers
69 if (!checkPredRegs(guardRegs.size(), NULL)) {
70 return false;
71 }
72
73 // count all integer registers
74 unsigned int intRegs = countIntRegisters(mach, guardRegs, ignoreRFs);
75
76 // check if enough integer registers
77 if (missingIntRegs(intRegs, NULL, fullyConCheck_.check(mach))) {
78 return false;
79 }
80
81 return true;
82}
virtual bool check(const TTAMachine::Machine &mach) const
bool checkPredRegs(const unsigned int &regCount, MachineCheckResults *results) const
FullyConnectedCheck fullyConCheck_
unsigned int missingIntRegs(const unsigned int &regCount, MachineCheckResults *results, bool isFullyConnected) const
unsigned int countIntRegisters(const TTAMachine::Machine &mach, const std::set< Register > &guardRegs, const std::set< std::string > &ignoreRFs) const
void findGuardRegisters(const TTAMachine::Machine &mach, std::set< Register > &registers, const std::set< std::string > &ignoreRFs) const

References FullyConnectedCheck::check(), checkPredRegs(), countIntRegisters(), findGuardRegisters(), fullyConCheck_, and missingIntRegs().

Here is the call graph for this function:

◆ check() [2/2]

bool RegisterQuantityCheck::check ( const TTAMachine::Machine mach,
MachineCheckResults results 
) const
virtual

Checks register quantities.

Stores errors during checking to a MachineCheckResults object given as a parameter.

Parameters
machMachine to be checked for registers resources.
resultsMachineCheckResults where possible errors are added.
Returns
True if no problems were found during testing, false otherwise.

Implements MachineCheck.

Definition at line 96 of file RegisterQuantityCheck.cc.

98 {
99
100 const std::set<std::string> empty;
101 return RegisterQuantityCheck::checkWithIgnore(mach, results, empty);
102}
bool checkWithIgnore(const TTAMachine::Machine &mach, const std::set< std::string > &ignoreRFs) const

References checkWithIgnore().

Here is the call graph for this function:

◆ checkIntRegs()

bool RegisterQuantityCheck::checkIntRegs ( const TTAMachine::Machine mach) const

Check only if enough integer registers.

Parameters
machMachine to be checked for int registers.
Returns
True if enough integer registers found.

Definition at line 186 of file RegisterQuantityCheck.cc.

186 {
187 // find all registers that can be used for guards
188 std::set<Register> guardRegs;
189 const std::set<std::string> ignoreRFs; //empty, no ignore
190 findGuardRegisters(mach, guardRegs, ignoreRFs);
191
192 // count all integer registers
193 unsigned int intRegs = countIntRegisters(mach, guardRegs, ignoreRFs);
194
195 // check if enough integer registers
196 if (missingIntRegs(intRegs, NULL, fullyConCheck_.check(mach))) {
197 return false;
198 }
199 return true;
200}

References FullyConnectedCheck::check(), countIntRegisters(), findGuardRegisters(), fullyConCheck_, and missingIntRegs().

Referenced by SimpleICOptimizer::explore(), and SimpleICOptimizer::fixIntRegisters().

Here is the call graph for this function:

◆ checkPredRegs()

bool RegisterQuantityCheck::checkPredRegs ( const unsigned int &  regCount,
MachineCheckResults results 
) const
private

Checks that there are enough predicate registers.

Outputs errors in MachineCheckResults object if given as a pointer.

Parameters
regCountThe number of predicate registers.
resultsMachineCheckResults where possible errors are added.
Returns
True if the number of predicate registers given was high enough.

Definition at line 288 of file RegisterQuantityCheck.cc.

290 {
291
292 if (regCount < 2) {
293 if (results != NULL) {
294 std::string msg = "too few predicate registers, 2 needed, ";
295 msg += Conversion::toString(regCount);
296 msg += " found";
297 results->addError(*this, msg);
298 }
299 return false;
300 }
301 return true;
302}
static std::string toString(const T &source)
void addError(const MachineCheck &check, const std::string &errorMsg)

References MachineCheckResults::addError(), and Conversion::toString().

Referenced by check(), checkWithIgnore(), and checkWithIgnore().

Here is the call graph for this function:

◆ checkWithIgnore() [1/2]

bool RegisterQuantityCheck::checkWithIgnore ( const TTAMachine::Machine mach,
const std::set< std::string > &  ignoreRFs 
) const

Checks register quantities with an option to ignore some RFs.

Can be passed a list of RFs names that are ignored regarding the test.

Parameters
machMachine to be checked for registers resources.
ignoreRFsA sorted list of RFs to be ignored while checking the needed registers.
Returns
True if no problems were found during testing, false otherwise.

Definition at line 116 of file RegisterQuantityCheck.cc.

118 {
119
120 std::set<Register> guardRegs;
121
122 // find all registers that can be used for guards
123 findGuardRegisters(mach, guardRegs, ignoreRFs);
124
125 // check if enough predicate registers
126 if (!checkPredRegs(guardRegs.size(), NULL)) {
127 return false;
128 }
129
130 // count all integer registers
131 unsigned int intRegs = countIntRegisters(mach, guardRegs, ignoreRFs);
132
133 // check if enough integer registers
134 if (missingIntRegs(intRegs, NULL, fullyConCheck_.check(mach))) {
135 return false;
136 }
137
138 return true;
139}

References FullyConnectedCheck::check(), checkPredRegs(), countIntRegisters(), findGuardRegisters(), fullyConCheck_, and missingIntRegs().

Referenced by check(), and SimpleICOptimizer::removeAllConnections().

Here is the call graph for this function:

◆ checkWithIgnore() [2/2]

bool RegisterQuantityCheck::checkWithIgnore ( const TTAMachine::Machine mach,
MachineCheckResults results,
const std::set< std::string > &  ignoreRFs 
) const

Checks register quantities with an option to ignore some RFs.

Can be passed a list of RFs names that are ignored regarding the test. Stores errors during checking to a MachineCheckResults object given as a parameter.

Parameters
machMachine to be checked for registers resources.
resultsMachineCheckResults where possible errors are added.
ignoreRFsA sorted list of RFs to be ignored while checking the needed registers.
Returns
True if no problems were found during testing, false otherwise.

Definition at line 156 of file RegisterQuantityCheck.cc.

159 {
160
161 std::set<Register> guardRegs;
162
163 // find all registers that can be used for guards
164 findGuardRegisters(mach, guardRegs, ignoreRFs);
165
166 // check if enough predicate registers
167 checkPredRegs(guardRegs.size(), &results);
168
169 // count all integer registers
170 unsigned int intRegs = countIntRegisters(mach, guardRegs, ignoreRFs);
171
172 // check if enough integer registers
173 missingIntRegs(intRegs, &results, fullyConCheck_.check(mach));
174
175 return results.errorCount() == 0;
176}

References FullyConnectedCheck::check(), checkPredRegs(), countIntRegisters(), MachineCheckResults::errorCount(), findGuardRegisters(), fullyConCheck_, and missingIntRegs().

Here is the call graph for this function:

◆ countIntRegisters()

unsigned int RegisterQuantityCheck::countIntRegisters ( const TTAMachine::Machine mach,
const std::set< Register > &  guardRegs,
const std::set< std::string > &  ignoreRFs 
) const
private

Counts integer registers int the given machine.

Doesn't count guard registers given as sorted list of pairs. Can be passed a list of RFs names that are ignored regarding the test.

Parameters
machMachine where integer registers are counted.
guardRegsA sorted list of register file, index pairs.
ignoreRFsA sorted list of RFs to be ignored while counting the registers.
Returns
The number of counted integer registers in them machine.

Definition at line 254 of file RegisterQuantityCheck.cc.

257 {
258
261
262 unsigned int intRegs = 0;
263 for (int i = 0; i < regNav.count(); i++) {
264 const TTAMachine::RegisterFile* rf = regNav.item(i);
265 if (rf->width() == 32 &&
266 ignoreRFs.find(rf->name()) == ignoreRFs.end()) {
267 for (int j = 0; j < rf->size(); j++) {
268 if (!AssocTools::containsKey(guardRegs, Register(rf,j))) {
269 intRegs++;
270 }
271 }
272 }
273 }
274 return intRegs;
275}
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
std::pair< const TTAMachine::RegisterFile *, int > Register
virtual int size() const
virtual TCEString name() const

References AssocTools::containsKey(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::name(), TTAMachine::Machine::registerFileNavigator(), TTAMachine::BaseRegisterFile::size(), and TTAMachine::BaseRegisterFile::width().

Referenced by check(), checkIntRegs(), checkWithIgnore(), checkWithIgnore(), and fixIntRegs().

Here is the call graph for this function:

◆ findGuardRegisters()

void RegisterQuantityCheck::findGuardRegisters ( const TTAMachine::Machine mach,
std::set< Register > &  guardRegs,
const std::set< std::string > &  ignoreRFs 
) const
private

Checks register quantities with an option to ignore some RFs.

Can be passed a list of RFs names that are ignored regarding the test.

Parameters
machMachine to be checked for registers resources.
guardRegsCounts registers that can be used as guards in the given machine.
ignoreRFsA sorted list of RFs to be ignored while checking the needed registers.
Returns
True if no problems were found during testing, false otherwise.

Definition at line 216 of file RegisterQuantityCheck.cc.

219 {
220
221 // find all registers that can be used for guards
223 for (int i = 0; i < busNav.count(); i++) {
224 TTAMachine::Bus* bus = busNav.item(i);
225 for (int j = 0; j < bus->guardCount(); j++) {
226 const TTAMachine::RegisterGuard* regGuard =
227 dynamic_cast<TTAMachine::RegisterGuard*>(bus->guard(j));
228 if (regGuard != NULL) {
229 if(ignoreRFs.find(regGuard->registerFile()->name()) ==
230 ignoreRFs.end()) {
231 guardRegs.insert(
232 Register(
233 regGuard->registerFile(), regGuard->registerIndex()));
234 }
235 }
236 }
237 }
238}
Guard * guard(int index) const
Definition Bus.cc:456
int guardCount() const
Definition Bus.cc:441
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
const RegisterFile * registerFile() const

References TTAMachine::Machine::busNavigator(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::name(), TTAMachine::RegisterGuard::registerFile(), and TTAMachine::RegisterGuard::registerIndex().

Referenced by check(), checkIntRegs(), checkWithIgnore(), checkWithIgnore(), and fixIntRegs().

Here is the call graph for this function:

◆ fixIntRegs()

bool RegisterQuantityCheck::fixIntRegs ( TTAMachine::Machine mach) const

Adds integer registers to an int rf so that requirements are met.

Parameters
machineMachine where integer registers are to be added if needed.
Returns
True if something was done to the machine, false otherwise.

Definition at line 340 of file RegisterQuantityCheck.cc.

340 {
341 // find all guard registers, which are ignored
342 std::set<Register> guardRegs;
343 const std::set<std::string> ignoreRFs; //empty, no ignore
344 findGuardRegisters(mach, guardRegs, ignoreRFs);
345
346 // count all integer registers
347 unsigned int intRegs = countIntRegisters(mach, guardRegs, ignoreRFs);
348
349 unsigned int missingRegs =
350 missingIntRegs(intRegs, NULL, fullyConCheck_.check(mach));
351
352 if (!missingRegs) {
353 return true;
354 }
355
358
359 // find an int rf to add registers
360 for (int i = 0; i < regNav.count(); i++) {
361 TTAMachine::RegisterFile* rf = regNav.item(i);
362 if (rf->width() == 32) {
363 rf->setNumberOfRegisters(rf->size() + missingRegs);
364 return true;
365 }
366 }
367
368 // no int rf found
369 return false;
370}
virtual void setNumberOfRegisters(int registers)

References FullyConnectedCheck::check(), TTAMachine::Machine::Navigator< ComponentType >::count(), countIntRegisters(), findGuardRegisters(), fullyConCheck_, TTAMachine::Machine::Navigator< ComponentType >::item(), missingIntRegs(), TTAMachine::Machine::registerFileNavigator(), TTAMachine::RegisterFile::setNumberOfRegisters(), TTAMachine::BaseRegisterFile::size(), and TTAMachine::BaseRegisterFile::width().

Referenced by SimpleICOptimizer::fixIntRegisters().

Here is the call graph for this function:

◆ missingIntRegs()

unsigned int RegisterQuantityCheck::missingIntRegs ( const unsigned int &  regCount,
MachineCheckResults results,
bool  isFullyConnected 
) const
private

Checks that there are enough integer registers.

Outputs errors in MachineCheckResults object if given as a pointer.

Parameters
regCountThe number of integer registers.
resultsMachineCheckResults where possible errors are added.
Returns
number of missing registers, 0 if none missing.

Definition at line 315 of file RegisterQuantityCheck.cc.

318 {
319
320 unsigned int neededIntRegs = isFullyConnected ? 5 : 6;
321 unsigned int missingRegisters = 0;
322
323 if (regCount < neededIntRegs) {
324 missingRegisters = neededIntRegs - regCount;
325 if (results != NULL) {
326 results->addError(*this, "too few integer registers");
327 }
328 }
329 return missingRegisters;
330}

References MachineCheckResults::addError().

Referenced by check(), checkIntRegs(), checkWithIgnore(), checkWithIgnore(), and fixIntRegs().

Here is the call graph for this function:

Member Data Documentation

◆ fullyConCheck_

FullyConnectedCheck RegisterQuantityCheck::fullyConCheck_
private

The documentation for this class was generated from the following files: