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

#include <UniversalFunctionUnit.hh>

Inheritance diagram for UniversalFunctionUnit:
Inheritance graph
Collaboration diagram for UniversalFunctionUnit:
Collaboration graph

Public Member Functions

 UniversalFunctionUnit (const std::string &name, OperationPool &opPool)
 
virtual ~UniversalFunctionUnit ()
 
virtual bool hasOperation (const std::string &name) const
 
virtual TTAMachine::HWOperationoperation (const std::string &name) const
 
virtual void addPipelineElement (TTAMachine::PipelineElement &element)
 
virtual void loadState (const ObjectState *state)
 
int portCountWithWidth (int width) const
 
TTAMachine::FUPortportWithWidth (int index, int width) const
 
- Public Member Functions inherited from TTAMachine::FunctionUnit
 FunctionUnit (const std::string &name)
 
 FunctionUnit (const ObjectState *state)
 
virtual ~FunctionUnit ()
 
virtual FunctionUnitcopy () const
 
virtual void setName (const std::string &name)
 
virtual BaseFUPortport (const std::string &name) const
 
virtual BaseFUPortport (int index) const
 
virtual int operationPortCount () const
 
virtual bool hasOperationPort (const std::string &name) const
 
virtual FUPortoperationPort (const std::string &name) const
 
virtual FUPortoperationPort (int index) const
 
virtual BaseFUPorttriggerPort () const
 
virtual void addOperation (HWOperation &operation)
 
virtual void deleteOperation (HWOperation &operation)
 
virtual bool hasOperationLowercase (const std::string &name) const
 
virtual HWOperationoperationLowercase (const std::string &name) const
 
virtual HWOperationoperation (int index) const
 
virtual int operationCount () const
 
virtual void operationNames (TCETools::CIStringSet &opNames) const
 
virtual int maxLatency () const
 
virtual void deletePipelineElement (PipelineElement &element)
 
virtual int pipelineElementCount () const
 
virtual PipelineElementpipelineElement (int index) const
 
virtual bool hasPipelineElement (const std::string &name) const
 
virtual PipelineElementpipelineElement (const std::string &name) const
 
virtual AddressSpaceaddressSpace () const
 
virtual void setAddressSpace (AddressSpace *as)
 
virtual bool hasAddressSpace () const
 
virtual void cleanup (const std::string &resource)
 
virtual void unsetMachine ()
 
virtual ObjectStatesaveState () const
 
virtual bool isArchitectureEqual (const FunctionUnit *fu, const bool checkPortWidths=true) const
 
bool needsConflictDetection () const
 
virtual int orderNumber () const
 
virtual void setOrderNumber (int)
 
- Public Member Functions inherited from TTAMachine::Unit
virtual ~Unit ()
 
virtual bool hasPort (const std::string &name) const
 
virtual int portCount () const
 
virtual int outputPortCount (bool countBidir=false) const
 
virtual int inputPortCount (bool countBidir=false) const
 
virtual int bidirPortCount () const
 
virtual void setMachine (Machine &mach)
 
- Public Member Functions inherited from TTAMachine::Component
virtual ~Component ()
 
virtual TCEString name () const
 
virtual Machinemachine () const
 
virtual void ensureRegistration (const Component &component) const
 
virtual bool isRegistered () const
 
- Public Member Functions inherited from Serializable
virtual ~Serializable ()
 

Static Public Member Functions

static bool is32BitOperation (const std::string &opName)
 

Static Public Attributes

static const std::string OC_SETTING_PORT_32 = "OCSetting32"
 Name of the 32 bit wide opcode setting port.
 
static const std::string OC_SETTING_PORT_64 = "OCSetting64"
 Name of the 64 bit wide opcode setting port.
 
- Static Public Attributes inherited from TTAMachine::FunctionUnit
static const std::string OSNAME_FU = "fu"
 ObjectState name for function unit.
 
static const std::string OSKEY_AS = "as"
 ObjectState attribute key for name of the address space.
 
static const std::string OSKEY_ORDER_NUMBER = "order_no"
 ObjectState attribute key for FU order number name.
 
- Static Public Attributes inherited from TTAMachine::Unit
static const std::string OSNAME_UNIT = "unit"
 ObjectState name for Unit.
 
- Static Public Attributes inherited from TTAMachine::Component
static const std::string OSNAME_COMPONENT = "component"
 ObjectState name for component.
 
static const std::string OSKEY_NAME = "name"
 ObjectState attribute key for the name of the component.
 

Private Member Functions

SmartHWOperationaddSupportedOperation (const Operation &operation)
 
void ensureInputPorts (int width, int count)
 
void ensureOutputPorts (int width, int count)
 

Private Attributes

OperationPoolopPool_
 Operation pool from which the operations are searched.
 

Static Private Attributes

static const std::string OPERATIONS_OF_32_BITS []
 Table of names of 32 bit operations.
 

Additional Inherited Members

- Protected Member Functions inherited from TTAMachine::FunctionUnit
void unsetMachineDerived ()
 
- Protected Member Functions inherited from TTAMachine::Unit
 Unit (const std::string &name)
 
 Unit (const ObjectState *state)
 
virtual void removePort (Port &port)
 
- Protected Member Functions inherited from TTAMachine::Component
 Component (const std::string &name)
 
 Component (const ObjectState *state)
 
void internalSetMachine (Machine &machine)
 
void internalUnsetMachine ()
 
- Protected Member Functions inherited from TTAMachine::MachinePart
 MachinePart ()
 
virtual ~MachinePart ()
 

Detailed Description

UniversalFunctionUnit class represents a function unit which has all the operations of an operation pool. The operations are added on demand, not at construction.

Definition at line 50 of file UniversalFunctionUnit.hh.

Constructor & Destructor Documentation

◆ UniversalFunctionUnit()

UniversalFunctionUnit::UniversalFunctionUnit ( const std::string &  name,
OperationPool opPool 
)

The constructor.

Parameters
nameName of the function unit.
opPoolThe operation pool from which the operations are obtained on demand.
Exceptions
InvalidNameIf the given name is not a valid component name.

Definition at line 64 of file UniversalFunctionUnit.cc.

66 : FunctionUnit(name), opPool_(opPool) {}
virtual TCEString name() const
OperationPool & opPool_
Operation pool from which the operations are searched.

◆ ~UniversalFunctionUnit()

UniversalFunctionUnit::~UniversalFunctionUnit ( )
virtual

The destructor.

Definition at line 71 of file UniversalFunctionUnit.cc.

71 {
72}

Member Function Documentation

◆ addPipelineElement()

void UniversalFunctionUnit::addPipelineElement ( TTAMachine::PipelineElement element)
virtual

Aborts the program. It should not be needed to add pipeline elements to universal function unit.

Parameters
elementNever used.
Exceptions
ComponentAlreadyExistsNever thrown.

Reimplemented from TTAMachine::FunctionUnit.

Definition at line 131 of file UniversalFunctionUnit.cc.

131 {
132 const string procName = "UniversalFunctionUnit::addPipelineElement";
133 const string errorMsg =
134 "Tried to add pipeline element to UniversalFunctionUnit!";
135 Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
137}
static void abortProgram() __attribute__((noreturn))
static void writeToErrorLog(const std::string fileName, const int lineNumber, const std::string functionName, const std::string message, const int neededVerbosity=0)

References Application::abortProgram(), and Application::writeToErrorLog().

Here is the call graph for this function:

◆ addSupportedOperation()

SmartHWOperation & UniversalFunctionUnit::addSupportedOperation ( const Operation operation)
private

Adds the given operation to the function unit.

Adds input and/or output ports if there is not enough ports for the operands of the given operation. Operand bindings and pipeline are not created.

Parameters
operationThe operation to be added.
Returns
The added operation.

Definition at line 228 of file UniversalFunctionUnit.cc.

228 {
229
230 int inputCount = operation.numberOfInputs();
231 int outputCount = operation.numberOfOutputs();
232
233 int operandWidth = is32BitOperation(operation.name()) ? 32 : 64;
234
235 ensureInputPorts(operandWidth, inputCount);
236 ensureOutputPorts(operandWidth, outputCount);
237
238 // create the operation
239 SmartHWOperation* hwOper = NULL;
240 try {
241 hwOper = new SmartHWOperation(operation, *this);
242 return *hwOper;
243 } catch (const InvalidName& exception) {
244 const string procName = "UniversalFunctionUnit::addOperation";
245 const string errorMsg =
246 "Operation pool contained an operation with illegal"
247 "name: " + string(operation.name());
248 Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
250 } catch (...) {
251 assert(false);
252 }
253
254 assert(false);
255
256 // dummy return to avoid compilation warning
257 return *hwOper;
258}
#define assert(condition)
const std::string & name() const
virtual TTAMachine::HWOperation * operation(const std::string &name) const
static bool is32BitOperation(const std::string &opName)
void ensureInputPorts(int width, int count)
void ensureOutputPorts(int width, int count)

References Application::abortProgram(), assert, ensureInputPorts(), ensureOutputPorts(), is32BitOperation(), TTAMachine::HWOperation::name(), TTAMachine::HWOperation::numberOfInputs(), TTAMachine::HWOperation::numberOfOutputs(), operation(), and Application::writeToErrorLog().

Referenced by operation().

Here is the call graph for this function:

◆ ensureInputPorts()

void UniversalFunctionUnit::ensureInputPorts ( int  width,
int  count 
)
private

Ensures that there is at least the given number of input ports of the given width.

Adds input ports if there is not enough ports.

Parameters
widthBit width of the ports to be ensured.
countThe number of ports to be ensured.

Definition at line 271 of file UniversalFunctionUnit.cc.

271 {
272
273 assert(width == 32 || width == 64);
274
275 Socket* inputSocket = machine()->socketNavigator().item(
277
278 int portCount = this->portCountWithWidth(width);
279
280 // create opcode setting port if there are no ports at all
281 if (count > 0 && portCount == 0) {
282 string portName =
284 FUPort* ocPort = new UniversalFUPort(
285 portName, width, *this, true, true);
286 portCount++;
287 ocPort->attachSocket(*inputSocket);
288 }
289
290 // check the amount of matches
291 int matches(1);
292 for (int i = 1; i < portCount; i++) {
293 FUPort& port = this->portWithWidth(i, width);
294 assert(port.width() == width);
295 if (port.inputSocket() != NULL) {
296 matches++;
297 }
298 }
299
300 // create new ports as necessary
301 while (matches < count) {
302 string portName = "i" + Conversion::toString(width) + "_" +
303 Conversion::toString(matches);
304 FUPort* newPort = new UniversalFUPort(
305 portName, width, *this, false, false);
306 newPort->attachSocket(*inputSocket);
307 matches++;
308 }
309}
#define UM_INPUT_SOCKET_NAME
static std::string toString(const T &source)
virtual int width() const
virtual Machine * machine() const
virtual BaseFUPort * port(const std::string &name) const
ComponentType * item(int index) const
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
virtual void attachSocket(Socket &socket)
Definition Port.cc:191
virtual Socket * inputSocket() const
Definition Port.cc:261
virtual int portCount() const
Definition Unit.cc:135
int portCountWithWidth(int width) const
static const std::string OC_SETTING_PORT_64
Name of the 64 bit wide opcode setting port.
static const std::string OC_SETTING_PORT_32
Name of the 32 bit wide opcode setting port.
TTAMachine::FUPort & portWithWidth(int index, int width) const

References assert, TTAMachine::Port::attachSocket(), TTAMachine::Port::inputSocket(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), OC_SETTING_PORT_32, OC_SETTING_PORT_64, TTAMachine::FunctionUnit::port(), TTAMachine::Unit::portCount(), portCountWithWidth(), portWithWidth(), TTAMachine::Machine::socketNavigator(), Conversion::toString(), UM_INPUT_SOCKET_NAME, and TTAMachine::BaseFUPort::width().

Referenced by addSupportedOperation().

Here is the call graph for this function:

◆ ensureOutputPorts()

void UniversalFunctionUnit::ensureOutputPorts ( int  width,
int  count 
)
private

Ensures that there is at least the given number of output ports of the given width.

Adds output ports if there is not enough ports.

Parameters
widthBit width of the ports to be ensured.
countThe number of ports to be ensured.

Definition at line 322 of file UniversalFunctionUnit.cc.

322 {
323
324 Socket* outputSocket =
326
327 // check the amount of matches
328 int matches(0);
329 for (int i = 0; i < portCountWithWidth(width); i++) {
330 FUPort& port = this->portWithWidth(i, width);
331 assert(port.width() == width);
332 if (port.outputSocket() != NULL) {
333 matches++;
334 }
335 }
336
337 // create new ports as necessary
338 while (matches < count) {
339 string portName = "output" + Conversion::toString(width) + "_" +
340 Conversion::toString(matches + 1);
341 FUPort* newPort = new UniversalFUPort(
342 portName, width, *this, false, false);
343 newPort->attachSocket(*outputSocket);
344 matches++;
345 }
346}
#define UM_OUTPUT_SOCKET_NAME
virtual Socket * outputSocket() const
Definition Port.cc:281

References assert, TTAMachine::Port::attachSocket(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), TTAMachine::Port::outputSocket(), TTAMachine::FunctionUnit::port(), portCountWithWidth(), portWithWidth(), TTAMachine::Machine::socketNavigator(), Conversion::toString(), UM_OUTPUT_SOCKET_NAME, and TTAMachine::BaseFUPort::width().

Referenced by addSupportedOperation().

Here is the call graph for this function:

◆ hasOperation()

bool UniversalFunctionUnit::hasOperation ( const std::string &  name) const
virtual

Tells whether the universal function unit has an operation of the given name.

Returns true even if the operation is not loaded yet but it exists in the operation pool.

Parameters
nameName of the operation.

Reimplemented from TTAMachine::FunctionUnit.

Definition at line 85 of file UniversalFunctionUnit.cc.

85 {
86 return &opPool_.operation(name.c_str()) != &NullOperation::instance();
87}
static NullOperation & instance()
Operation & operation(const char *name)

References NullOperation::instance(), TTAMachine::Component::name(), OperationPool::operation(), and opPool_.

Referenced by llvm::LLVMTCEBuilder::emitOperationMacro().

Here is the call graph for this function:

◆ is32BitOperation()

bool UniversalFunctionUnit::is32BitOperation ( const std::string &  opName)
static

Tells whether operation of the given name has 32 bits wide operands and return value.

Parameters
opNameName of the operation.
Returns
True if the operation has 32 bits wide operands and return value, otherwise false.

Definition at line 358 of file UniversalFunctionUnit.cc.

358 {
359 int numberOfElements = sizeof(OPERATIONS_OF_32_BITS) / sizeof(string);
360 for (int i = 0; i < numberOfElements; i++) {
361 if (OPERATIONS_OF_32_BITS[i] == opName) {
362 return true;
363 }
364 }
365 return false;
366}
static const std::string OPERATIONS_OF_32_BITS[]
Table of names of 32 bit operations.

References OPERATIONS_OF_32_BITS.

Referenced by addSupportedOperation(), and SmartHWOperation::SmartHWOperation().

◆ loadState()

void UniversalFunctionUnit::loadState ( const ObjectState state)
virtual

Aborts the program. It is not allowed to load UniversalFunctionUnit from an ObjectState instance. DO NOT CALL THIS METHOD!

Parameters
stateNever used.
Exceptions
ObjectStateLoadingExceptionNever thrown.

Reimplemented from TTAMachine::FunctionUnit.

Definition at line 147 of file UniversalFunctionUnit.cc.

147 {
148 const string procName = "UniversalFunctionUnit::loadState";
149 const string errorMsg =
150 "Tried to load state of UniversalFunctionUnit from an ObjectState "
151 "tree!";
152 Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
154}

References Application::abortProgram(), and Application::writeToErrorLog().

Here is the call graph for this function:

◆ operation()

TTAMachine::HWOperation * UniversalFunctionUnit::operation ( const std::string &  name) const
virtual

Returns an operation by the given name.

Adds the operation to the function unit if it doen't exist yet but exist in the operation pool.

Parameters
nameName of the operation.
Exceptions
InstanceNotFoundIf an operation by the given name does not exist in the operation pool.
Returns
The operation.

Reimplemented from TTAMachine::FunctionUnit.

Definition at line 102 of file UniversalFunctionUnit.cc.

102 {
103 const string procName = "UniversalFunctionUnit::operation";
104
107 } else {
108 Operation& oper = opPool_.operation(name.c_str());
109
110 if (&oper == &NullOperation::instance()) {
111 throw InstanceNotFound(__FILE__, __LINE__, procName);
112 } else {
113 // need to take non-const pointer of this FU to call non-const
114 // method addOperation
115 UniversalFunctionUnit* thisFU =
116 const_cast<UniversalFunctionUnit*>(this);
117 SmartHWOperation& hwOper = thisFU->addSupportedOperation(oper);
118 return &hwOper;
119 }
120 }
121}
virtual HWOperation * operation(const std::string &name) const
virtual bool hasOperation(const std::string &name) const
SmartHWOperation & addSupportedOperation(const Operation &operation)

References addSupportedOperation(), TTAMachine::FunctionUnit::hasOperation(), NullOperation::instance(), TTAMachine::Component::name(), OperationPool::operation(), TTAMachine::FunctionUnit::operation(), and opPool_.

Referenced by addSupportedOperation(), TTAProgram::CodeGenerator::createBreakOperation(), TTAProgram::CodeGenerator::createForLoopBufferInit(), TTAProgram::CodeGenerator::createTerminalFUPort(), TTAProgram::CodeGenerator::createWhileLoopBufferInit(), llvm::LLVMTCEBuilder::emitOperationMacro(), and CopyingDelaySlotFiller::getMove().

Here is the call graph for this function:

◆ portCountWithWidth()

int UniversalFunctionUnit::portCountWithWidth ( int  width) const

Returns the number of ports of the given bit width.

Parameters
widthThe bit width.
Returns
The number of ports of the given bit width.
Exceptions
OutOfRangeIf the given bit width is out of range.

Definition at line 164 of file UniversalFunctionUnit.cc.

164 {
165 if (width < 1) {
166 const string procName = "UniversalFunctionUnit::portCount";
167 throw OutOfRange(__FILE__, __LINE__, procName);
168 }
169
170 int count(0);
171
172 for (int i = 0; i < FunctionUnit::portCount(); i++) {
173 if (FunctionUnit::port(i)->width() == width) {
174 count++;
175 }
176 }
177
178 return count;
179}

References TTAMachine::FunctionUnit::port(), and TTAMachine::BaseFUPort::width().

Referenced by ensureInputPorts(), ensureOutputPorts(), SmartHWOperation::port(), and portWithWidth().

Here is the call graph for this function:

◆ portWithWidth()

FUPort & UniversalFunctionUnit::portWithWidth ( int  index,
int  width 
) const

By the given index, returns a port which has the given bit width.

Parameters
indexThe index.
widthThe bit width.
Returns
A port of the given bit width.
Exceptions
OutOfRangeIf the given bit width or index is out of range.

Definition at line 190 of file UniversalFunctionUnit.cc.

190 {
191 if (width < 1 || index >= portCountWithWidth(width)) {
192 const string procName = "UniversalFunctionUnit::port";
193 throw OutOfRange(__FILE__, __LINE__, procName);
194 }
195
196 int count(0);
197 int portC = portCount();
198 for (int i = 0; i < portC; i++) {
199 auto p = port(i);
201 dynamic_cast<FUPort*>(p);
202 if (p != nullptr && port->width() == width) {
203 count++;
204 if (count > index) {
205 return *port;
206 }
207 }
208 }
209
210 assert(false);
211
212 // dummy return to avoid compilation warning
213 FUPort* port = NULL;
214 return *port;
215}

References assert, TTAMachine::FunctionUnit::port(), TTAMachine::Unit::portCount(), portCountWithWidth(), and TTAMachine::BaseFUPort::width().

Referenced by ensureInputPorts(), ensureOutputPorts(), and SmartHWOperation::port().

Here is the call graph for this function:

Member Data Documentation

◆ OC_SETTING_PORT_32

const string UniversalFunctionUnit::OC_SETTING_PORT_32 = "OCSetting32"
static

Name of the 32 bit wide opcode setting port.

Definition at line 66 of file UniversalFunctionUnit.hh.

Referenced by ensureInputPorts(), and SmartHWOperation::port().

◆ OC_SETTING_PORT_64

const string UniversalFunctionUnit::OC_SETTING_PORT_64 = "OCSetting64"
static

Name of the 64 bit wide opcode setting port.

Definition at line 68 of file UniversalFunctionUnit.hh.

Referenced by ensureInputPorts(), and SmartHWOperation::port().

◆ OPERATIONS_OF_32_BITS

const string UniversalFunctionUnit::OPERATIONS_OF_32_BITS
staticprivate
Initial value:
= {
"ADD", "SUB", "LDW", "LDQ", "LDH", "STW", "STQ", "STH", "EQ", "GT",
"GTU", "SHL", "SHR", "SHRU", "AND", "IOR", "XOR", "SYS", "JUMP", "CALL",
"MIN", "MAX", "MINU", "MAXU", "SXQW", "SXHW", "NEG", "MUL", "DIV",
"DIVU", "CFI", "CIF", "ROTL", "ROTR", "ABS", "LDQU", "LDHU"}

Table of names of 32 bit operations.

Definition at line 49 of file UniversalFunctionUnit.hh.

51public:
52 UniversalFunctionUnit(const std::string& name, OperationPool& opPool);
53 virtual ~UniversalFunctionUnit();

Referenced by is32BitOperation().

◆ opPool_

OperationPool& UniversalFunctionUnit::opPool_
private

Operation pool from which the operations are searched.

Definition at line 76 of file UniversalFunctionUnit.hh.

Referenced by hasOperation(), and operation().


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