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

#include <InstructionBitVector.hh>

Inheritance diagram for InstructionBitVector:
Inheritance graph
Collaboration diagram for InstructionBitVector:
Collaboration graph

Public Member Functions

 InstructionBitVector ()
 
 InstructionBitVector (const InstructionBitVector &toCopy)
 
virtual ~InstructionBitVector ()
 
void pushBack (const InstructionBitVector &bits)
 
void pushBack (const BitVector &bits)
 
InstructionBitVectorsubVector (unsigned int firstIndex, unsigned int lastIndex) const
 
void startSettingInstructionReference (const TTAProgram::Instruction &instruction)
 
void addIndexBoundsForReference (IndexBound bounds)
 
void fixInstructionAddress (const TTAProgram::Instruction &instruction, unsigned int address)
 
void markInstructionStartingPoint (unsigned int position)
 
unsigned int instructionCount () const
 
unsigned int instructionStartingPoint (unsigned int index) const
 
- Public Member Functions inherited from BitVector
 BitVector ()
 
 BitVector (const BitVector &vector, unsigned int firstIndex, unsigned int lastIndex)
 
virtual ~BitVector ()
 
void pushBack (long long unsigned int integer, int size)
 
void pushBack (const BitVector &bits)
 
void pushBack (bool bit)
 
std::string toString () const
 

Private Types

typedef std::vector< IndexBoundIndexBoundTable
 A vector type that stores index bounds.
 
typedef std::set< IndexBoundTable * > IndexBoundSet
 A set type that stores IndexBoundTables.
 
typedef std::map< const TTAProgram::Instruction *, IndexBoundSet * > ReferenceMap
 A map type that maps Instructions to IndexBoundSets.
 
typedef std::vector< unsigned int > BoundaryTable
 A vector type that stores instruction boundaries.
 
typedef std::map< const TTAProgram::Instruction *, unsigned int > InstructionAddressTable
 A map type for instruction addresses.
 

Private Member Functions

IndexBoundSetindexBounds (const TTAProgram::Instruction &instruction)
 
void addIndexBoundTables (const IndexBoundSet &from, IndexBoundSet &to)
 
void fixBits (const IndexBoundTable &indexes, unsigned int value)
 

Static Private Member Functions

static unsigned int availableSize (const IndexBoundTable &indexes)
 

Private Attributes

ReferenceMap references_
 Contains information of the parts of the bit vector that refer to an instruction address.
 
IndexBoundTablecurrentTable_
 IndexBoundTable being under construction.
 
BoundaryTable instructionBoundaries_
 Stores the instruction boundaries.
 
InstructionAddressTable instructionAddresses_
 Addresses of the instructions.
 

Detailed Description

A bit vector class that provides instruction relocation capabilities.

Definition at line 50 of file InstructionBitVector.hh.

Member Typedef Documentation

◆ BoundaryTable

typedef std::vector<unsigned int> InstructionBitVector::BoundaryTable
private

A vector type that stores instruction boundaries.

Definition at line 81 of file InstructionBitVector.hh.

◆ IndexBoundSet

A set type that stores IndexBoundTables.

Definition at line 76 of file InstructionBitVector.hh.

◆ IndexBoundTable

typedef std::vector<IndexBound> InstructionBitVector::IndexBoundTable
private

A vector type that stores index bounds.

Definition at line 74 of file InstructionBitVector.hh.

◆ InstructionAddressTable

typedef std::map<const TTAProgram::Instruction*, unsigned int> InstructionBitVector::InstructionAddressTable
private

A map type for instruction addresses.

Definition at line 84 of file InstructionBitVector.hh.

◆ ReferenceMap

A map type that maps Instructions to IndexBoundSets.

Definition at line 79 of file InstructionBitVector.hh.

Constructor & Destructor Documentation

◆ InstructionBitVector() [1/2]

InstructionBitVector::InstructionBitVector ( )

The constructor.

Definition at line 46 of file InstructionBitVector.cc.

46 :
47 BitVector(), currentTable_(NULL) {
48}
IndexBoundTable * currentTable_
IndexBoundTable being under construction.

◆ InstructionBitVector() [2/2]

InstructionBitVector::InstructionBitVector ( const InstructionBitVector toCopy)

The copy constructor.

Parameters
toCopyBit vector to copy.

Definition at line 56 of file InstructionBitVector.cc.

57 :
58 BitVector(toCopy), currentTable_(NULL),
61
62 // copy reference map
63 for (ReferenceMap::const_iterator iter = toCopy.references_.begin();
64 iter != toCopy.references_.end(); iter++) {
65 const Instruction* instruction = (*iter).first;
66 IndexBoundSet* indexBounds = (*iter).second;
67 IndexBoundSet* newSet = new IndexBoundSet;
68 for (IndexBoundSet::const_iterator iter = indexBounds->begin();
69 iter != indexBounds->end(); iter++) {
70 IndexBoundTable* table = *iter;
71 IndexBoundTable* newTable = new IndexBoundTable(*table);
72 newSet->insert(newTable);
73 if (toCopy.currentTable_ == table) {
74 currentTable_ = newTable;
75 }
76 }
77 references_.insert(
78 std::pair<const Instruction*, IndexBoundSet*>(
79 instruction, newSet));
80 }
81}
InstructionAddressTable instructionAddresses_
Addresses of the instructions.
IndexBoundSet & indexBounds(const TTAProgram::Instruction &instruction)
BoundaryTable instructionBoundaries_
Stores the instruction boundaries.
std::set< IndexBoundTable * > IndexBoundSet
A set type that stores IndexBoundTables.
ReferenceMap references_
Contains information of the parts of the bit vector that refer to an instruction address.
std::vector< IndexBound > IndexBoundTable
A vector type that stores index bounds.

References currentTable_, indexBounds(), and references_.

Here is the call graph for this function:

◆ ~InstructionBitVector()

InstructionBitVector::~InstructionBitVector ( )
virtual

The destructor.

Definition at line 87 of file InstructionBitVector.cc.

87 {
88}

Member Function Documentation

◆ addIndexBoundsForReference()

void InstructionBitVector::addIndexBoundsForReference ( IndexBound  bounds)

Adds a pair of indexes that bound a part of the bit vector that refer to address of another instruction (given in startSettingInstructionReference).

Parameters
startThe start index (included in the boundary).
endThe end index (included in the boundary).

Definition at line 179 of file InstructionBitVector.cc.

179 {
180
181 assert(currentTable_ != NULL);
182 assert(bounds.slotStartIndex() <= bounds.slotEndIndex());
183 currentTable_->push_back(bounds);
184}
#define assert(condition)
unsigned int slotEndIndex() const
Definition IndexBound.cc:81
unsigned int slotStartIndex() const
Definition IndexBound.cc:70

References assert, currentTable_, IndexBound::slotEndIndex(), and IndexBound::slotStartIndex().

Referenced by CodeCompressorPlugin::bemInstructionBits(), and CodeCompressorPlugin::encodeImmediateTerminal().

Here is the call graph for this function:

◆ addIndexBoundTables()

void InstructionBitVector::addIndexBoundTables ( const IndexBoundSet from,
IndexBoundSet to 
)
private

Adds the IndexBoundTables from the given IndexBoundSet to the given IndexBoundSet.

Parameters
fromThe IndexBoundSet from which the tables are copied.
toThe IndexBoundSet to which the tables are added.

Definition at line 308 of file InstructionBitVector.cc.

310 {
311
312 for (IndexBoundSet::const_iterator iter = from.begin();
313 iter != from.end(); iter++) {
314
315 const IndexBoundTable* fromTable = *iter;
316 IndexBoundTable* newTable = new IndexBoundTable(*fromTable);
317
318 for (IndexBoundTable::iterator iter = newTable->begin();
319 iter != newTable->end(); iter++) {
320 (*iter).incrStartIndex(size());
321 (*iter).incrEndIndex(size());
322 }
323
324 to.insert(newTable);
325 }
326}

Referenced by pushBack().

◆ availableSize()

unsigned int InstructionBitVector::availableSize ( const IndexBoundTable indexes)
staticprivate

Returns the number of bits available in the given IndexBoundTable.

Parameters
indexesThe IndexBoundTable.
Returns
The number of bits.

Definition at line 387 of file InstructionBitVector.cc.

387 {
388
389 unsigned int size(0);
390 for (IndexBoundTable::const_iterator iter = indexes.begin();
391 iter != indexes.end(); iter++) {
392 size += (*iter).slotEndIndex() - (*iter).slotStartIndex() + 1;
393 }
394 return size;
395}

Referenced by fixBits().

◆ fixBits()

void InstructionBitVector::fixBits ( const IndexBoundTable indexes,
unsigned int  value 
)
private

Fixes the sections given in the IndexBoundTable of the bit vector with the given value.

Parameters
indexesThe table of section being fixed.
valueThe value.
Exceptions
OutOfRangeIf the value is too large to fit to the boundary.

Definition at line 338 of file InstructionBitVector.cc.

339 {
340 int requiredSize = MathTools::requiredBits(value);
341 int availableSize = this->availableSize(indexes);
342 if (requiredSize > availableSize) {
343 string errorMsg = "Unable to fix instruction reference with the "
344 "correct instruction address due to insuffient space reserved "
345 "for the immediate.";
346 throw OutOfRange(__FILE__, __LINE__, __func__, errorMsg);
347 }
348
349 int currentBit = 0;
350 int stopBit = requiredSize;
351
352 for (IndexBoundTable::const_reverse_iterator iter = indexes.rbegin();
353 iter != indexes.rend(); iter++) {
354
355 const IndexBound& iBound = *iter;
356
357 unsigned int startIndex = iBound.slotStartIndex();
358 unsigned int endIndex = iBound.slotEndIndex();
359
360 if ((*iter).isLimmEncoded()) {
361 // Check limm slice indices and update iteration boundaries.
362 // LIMM is written from LSB to MSB. Start from the rightmost bit
363 // of *this* limm slot.
364 currentBit = iBound.limmRightIndex();
365 stopBit = iBound.limmLeftIndex();
366 assert((stopBit-currentBit) == (iBound.limmWidth()-1));
367 }
368 for (unsigned int index = endIndex; index >= startIndex; index--) {
369 // Rewrite with new value required bits, zero the higher ones
370 if (currentBit <= stopBit) {
371 operator[](index) = MathTools::bit(value, currentBit);
372 } else {
373 operator[](index) = false;
374 }
375 currentBit++;
376 }
377 }
378}
#define __func__
int limmWidth() const
int limmRightIndex() const
int limmLeftIndex() const
static unsigned int availableSize(const IndexBoundTable &indexes)
static int requiredBits(unsigned long int number)
static bool bit(ULongWord integer, unsigned int index)

References __func__, assert, availableSize(), MathTools::bit(), IndexBound::limmLeftIndex(), IndexBound::limmRightIndex(), IndexBound::limmWidth(), MathTools::requiredBits(), IndexBound::slotEndIndex(), and IndexBound::slotStartIndex().

Referenced by fixInstructionAddress(), and pushBack().

Here is the call graph for this function:

◆ fixInstructionAddress()

void InstructionBitVector::fixInstructionAddress ( const TTAProgram::Instruction instruction,
unsigned int  address 
)

Fixes the address of the given instruction.

When this is called, all the references to the given instruction are fixed with the given value of the address.

Parameters
instructionThe instruction.
addressThe address of the instruction.
Exceptions
OutOfRangeIf the given value is too large to fit to a boundary that refers to the instruction.

Definition at line 199 of file InstructionBitVector.cc.

200 {
202 std::pair<const Instruction*, unsigned int>(&instruction, address));
203 if (!MapTools::containsKey(references_, &instruction)) {
204 return;
205 } else {
206 IndexBoundSet& setForInstruction = indexBounds(instruction);
207 for (IndexBoundSet::const_iterator iter = setForInstruction.begin();
208 iter != setForInstruction.end(); iter++) {
209 IndexBoundTable* table = *iter;
210 fixBits(*table, address);
211 }
212 }
213}
void fixBits(const IndexBoundTable &indexes, unsigned int value)
static bool containsKey(const MapType &aMap, const KeyType &aKey)

References MapTools::containsKey(), fixBits(), indexBounds(), instructionAddresses_, and references_.

Referenced by CodeCompressorPlugin::addInstruction().

Here is the call graph for this function:

◆ indexBounds()

InstructionBitVector::IndexBoundSet & InstructionBitVector::indexBounds ( const TTAProgram::Instruction instruction)
private

Returns the set of index bounds that refer to the given instruction.

Parameters
instructionThe instruction.

Definition at line 284 of file InstructionBitVector.cc.

285 {
286
287 if (!MapTools::containsKey(references_, &instruction)) {
288 IndexBoundSet* newSet = new IndexBoundSet;
289 std::pair<const Instruction*, IndexBoundSet*> newPair(
290 &instruction, newSet);
291 references_.insert(newPair);
292 return *newSet;
293 } else {
295 references_, &instruction);
296 }
297}
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)

References MapTools::containsKey(), MapTools::keyForValue(), and references_.

Referenced by fixInstructionAddress(), InstructionBitVector(), and startSettingInstructionReference().

Here is the call graph for this function:

◆ instructionCount()

unsigned int InstructionBitVector::instructionCount ( ) const

Returns the number of instructions in the vector.

The count is determined by means of the number of instruction boundaries.

Returns
The number of instructions.

Definition at line 254 of file InstructionBitVector.cc.

254 {
255 return instructionBoundaries_.size();
256}

References instructionBoundaries_.

Referenced by ArrayProgramImageWriter::writeImage(), AsciiProgramImageWriter::writeImage(), and Bin2nProgramImageWriter::writeImage().

◆ instructionStartingPoint()

unsigned int InstructionBitVector::instructionStartingPoint ( unsigned int  index) const

Returns the instruction starting point at the given position.

The boundaries are returned in the correct order, that is, if parameter 0 is given, the starting point of the first instruction is returned.

Returns
The instruction starting point at the given position.
Exceptions
OutOfRangeIf the given index is too large.

Definition at line 269 of file InstructionBitVector.cc.

269 {
270 if (index >= instructionBoundaries_.size()) {
271 const string procName = "InstructionBitVector::instructionBoundary";
272 throw OutOfRange(__FILE__, __LINE__, procName);
273 } else {
274 return instructionBoundaries_[index];
275 }
276}

References instructionBoundaries_.

Referenced by ArrayProgramImageWriter::writeImage(), AsciiProgramImageWriter::writeImage(), and Bin2nProgramImageWriter::writeImage().

◆ markInstructionStartingPoint()

void InstructionBitVector::markInstructionStartingPoint ( unsigned int  position)

Marks the instruction starting point.

The instruction starting point should be marked to the position of the first bit (the smallest index in the vector) of instruction.

Parameters
positionThe position of the starting point.

Definition at line 224 of file InstructionBitVector.cc.

224 {
225 if (instructionBoundaries_.size() == 0) {
226 instructionBoundaries_.push_back(position);
227 } else {
228 if (instructionBoundaries_.back() < position) {
229 instructionBoundaries_.push_back(position);
230 } else {
231 for (BoundaryTable::iterator iter = instructionBoundaries_.begin();
232 iter != instructionBoundaries_.end(); iter++) {
233 if (*iter > position) {
234 instructionBoundaries_.insert(iter, position);
235 return;
236 } else if (*iter == position) {
237 return;
238 }
239 }
240 assert(false);
241 }
242 }
243}

References assert, and instructionBoundaries_.

Referenced by CodeCompressorPlugin::addInstruction().

◆ pushBack() [1/2]

void InstructionBitVector::pushBack ( const BitVector bits)

Concatenates the given bit vector to this vector.

Parameters
bitsThe bit vector to be concatenated to this vector.

Definition at line 149 of file InstructionBitVector.cc.

149 {
151}
void pushBack(long long unsigned int integer, int size)
Definition BitVector.cc:94

References BitVector::pushBack().

Here is the call graph for this function:

◆ pushBack() [2/2]

void InstructionBitVector::pushBack ( const InstructionBitVector bits)

Concatenates the given instruction bit vector to this vector.

Fixes the instruction references of the given bit vector with the known instruction addresses.

Parameters
bitsThe bit vector to be concatenated to this vector.
Exceptions
OutOfRangeIf some of the instruction references cannot be fixed due to insufficient bit width.

Definition at line 102 of file InstructionBitVector.cc.

102 {
103 for (ReferenceMap::const_iterator iter = bits.references_.begin();
104 iter != bits.references_.end(); iter++) {
105 const Instruction* instruction = (*iter).first;
106 IndexBoundSet* indexBoundSet = (*iter).second;
107 if (!MapTools::containsKey(references_, instruction)) {
108 IndexBoundSet* newSet = new IndexBoundSet;
109 addIndexBoundTables(*indexBoundSet, *newSet);
110 references_.insert(
111 std::pair<const Instruction*, IndexBoundSet*>(
112 instruction, newSet));
113 } else {
115 references_, instruction);
116 addIndexBoundTables(*indexBoundSet, *oldSet);
117 }
118 }
119
120 InstructionBitVector bitsCopy(bits);
121
122 // fix the instruction references of the given bit vector
123 for (ReferenceMap::const_iterator iter = bits.references_.begin();
124 iter != bits.references_.end(); iter++) {
125 const Instruction* instruction = iter->first;
126 IndexBoundSet* indexBoundSet = iter->second;
128 for (IndexBoundSet::const_iterator setIter =
129 indexBoundSet->begin();
130 setIter != indexBoundSet->end(); setIter++) {
131 IndexBoundTable* table = *setIter;
132 bitsCopy.fixBits(
133 *table,
135 instructionAddresses_, instruction));
136 }
137 }
138 }
139
140 insert(end(), bitsCopy.begin(), bitsCopy.end());
141}
void addIndexBoundTables(const IndexBoundSet &from, IndexBoundSet &to)

References addIndexBoundTables(), MapTools::containsKey(), fixBits(), instructionAddresses_, MapTools::keyForValue(), and references_.

Referenced by CodeCompressorPlugin::addInstruction(), CodeCompressorPlugin::bemBits(), and CodeCompressorPlugin::encodeImmediateTerminal().

Here is the call graph for this function:

◆ startSettingInstructionReference()

void InstructionBitVector::startSettingInstructionReference ( const TTAProgram::Instruction instruction)

Starts setting an instruction reference.

Parameters
instructionThe instruction being referenced.

Definition at line 160 of file InstructionBitVector.cc.

161 {
162
163 IndexBoundSet& setForInstruction = indexBounds(instruction);
164 IndexBoundTable* newTable = new IndexBoundTable;
165 currentTable_ = newTable;
166 setForInstruction.insert(newTable);
167}

References currentTable_, and indexBounds().

Referenced by CodeCompressorPlugin::bemInstructionBits(), and CodeCompressorPlugin::encodeImmediateTerminal().

Here is the call graph for this function:

◆ subVector()

InstructionBitVector * InstructionBitVector::subVector ( unsigned int  firstIndex,
unsigned int  lastIndex 
) const

Member Data Documentation

◆ currentTable_

IndexBoundTable* InstructionBitVector::currentTable_
private

IndexBoundTable being under construction.

Definition at line 96 of file InstructionBitVector.hh.

Referenced by addIndexBoundsForReference(), InstructionBitVector(), and startSettingInstructionReference().

◆ instructionAddresses_

InstructionAddressTable InstructionBitVector::instructionAddresses_
private

Addresses of the instructions.

Definition at line 100 of file InstructionBitVector.hh.

Referenced by fixInstructionAddress(), and pushBack().

◆ instructionBoundaries_

BoundaryTable InstructionBitVector::instructionBoundaries_
private

Stores the instruction boundaries.

Definition at line 98 of file InstructionBitVector.hh.

Referenced by instructionCount(), instructionStartingPoint(), and markInstructionStartingPoint().

◆ references_

ReferenceMap InstructionBitVector::references_
private

Contains information of the parts of the bit vector that refer to an instruction address.

Definition at line 94 of file InstructionBitVector.hh.

Referenced by fixInstructionAddress(), indexBounds(), InstructionBitVector(), and pushBack().


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