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

#include <OperationDAGSelector.hh>

Collaboration diagram for OperationDAGSelector:
Collaboration graph

Classes

struct  CaseInsensitiveCmp
 
class  OperationDAGList
 

Public Types

typedef TCETools::CIStringSet OperationSet
 

Static Public Member Functions

static OperationDAGList findDags (const std::string &opName, OperationSet opSet, const ImmInfo *immInfo=nullptr)
 
static OperationDAGcreateExpandedDAG (const Operation &op, OperationSet &opSet)
 

Private Member Functions

 OperationDAGSelector ()
 
virtual ~OperationDAGSelector ()
 

Static Private Member Functions

static int countUnknownOperations (OperationDAG &dag, OperationSet &opSet)
 

Detailed Description

Class that search DAGs from operation set.

Definition at line 50 of file OperationDAGSelector.hh.

Member Typedef Documentation

◆ OperationSet

Definition at line 88 of file OperationDAGSelector.hh.

Constructor & Destructor Documentation

◆ OperationDAGSelector()

OperationDAGSelector::OperationDAGSelector ( )
private

◆ ~OperationDAGSelector()

virtual OperationDAGSelector::~OperationDAGSelector ( )
privatevirtual

Member Function Documentation

◆ countUnknownOperations()

int OperationDAGSelector::countUnknownOperations ( OperationDAG dag,
OperationSet opSet 
)
staticprivate

Returns number of operations that DAG contains which are not in given opset.

Currently does not check recursively, but only one level used operations.

Parameters
dagDAG which is checked.
opSetOperations that are found.
Returns
Number of operations that DAG contains that did not exist in opset.

Definition at line 130 of file OperationDAGSelector.cc.

131 {
132
133 int strangeOpCount = 0;
134
135 for (int i = 0; i < dag.nodeCount(); i++) {
136 OperationNode* node = dynamic_cast<OperationNode*>(&dag.node(i));
137
138 // check if operation was found from opset
139 if (node != NULL) {
140 Operation& refOp = node->referencedOperation();
141
142 if (opSet.find(refOp.name()) == opSet.end()) {
143 strangeOpCount++;
144 }
145 }
146 }
147
148 return strangeOpCount;
149}
int nodeCount() const
Node & node(const int index) const
Operation & referencedOperation() const
virtual TCEString name() const
Definition Operation.cc:93

References Operation::name(), BoostGraph< GraphNode, GraphEdge >::node(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), and OperationNode::referencedOperation().

Referenced by createExpandedDAG(), and findDags().

Here is the call graph for this function:

◆ createExpandedDAG()

OperationDAG * OperationDAGSelector::createExpandedDAG ( const Operation op,
OperationSet opSet 
)
static

Tries to find simplest graph that is expanded with given opset.

Todo:
Implement function when neccessary. Right now returns DAG for operation that has smallest number of operations that are not found in given opset.
Parameters
opOperation whose expanded dag is requested.
opSetOperation names which are allowed to use for expanding.
Returns
Dynamically allocated DAG for operation expanded with given opset. OperationDAG::null if there is no dag for operation.

Definition at line 164 of file OperationDAGSelector.cc.

165 {
166
167 OperationDAGList foundDags;
168 int lastUnknownOperations = INT_MAX;
169
170 // find DAG that has lowest cont of operations that are not in opset
171 for (int i = 0; i < op.dagCount(); i++) {
172 OperationDAG& currDag = op.dag(i);
173 int strangeCount = countUnknownOperations(currDag, opSet);
174
175 if (strangeCount <= lastUnknownOperations) {
176
177 if (strangeCount < lastUnknownOperations) {
178 lastUnknownOperations = strangeCount;
179 foundDags.clear();
180 }
181
182 foundDags.push_back(&currDag);
183 }
184 }
185
186 OperationDAG& selectedDag = foundDags.smallestNodeCount();
187
188 if (selectedDag.isNull()) {
189 return &selectedDag;
190 } else {
191 return new OperationDAG(selectedDag);
192 }
193}
static int countUnknownOperations(OperationDAG &dag, OperationSet &opSet)
bool isNull() const
virtual OperationDAG & dag(int index) const
Definition Operation.cc:148
virtual int dagCount() const
Definition Operation.cc:134

References countUnknownOperations(), Operation::dag(), Operation::dagCount(), OperationDAG::isNull(), and OperationDAGSelector::OperationDAGList::smallestNodeCount().

Here is the call graph for this function:

◆ findDags()

OperationDAGSelector::OperationDAGList OperationDAGSelector::findDags ( const std::string &  opName,
OperationSet  opSet,
const ImmInfo immInfo = nullptr 
)
static

Returns a list of dags of an operation, which use only given set of operations.

Additionally, immediate info can be provided to this function. The info describes immediate transport capabilities to the operands of the (known) operations. ImmInfo discards dags that have constant values bound to operand that can not have the immediate transported to.

Parameters
opNameName of operation whose DAGs are requested.
opSetSet of operations that are allowed to be referred by the returned DAGs.
immInfoThe immediate info.
Returns
List of DAGs which comply the search parameters.

Definition at line 57 of file OperationDAGSelector.cc.

60 {
61
62 OperationDAGList retDags;
63 OperationPool opPool;
64 Operation& op = opPool.operation(opName.c_str());
65
66 for (int i = 0; i < op.dagCount(); i++) {
67 OperationDAG& currDag = op.dag(i);
68
69 if (op.dagError(i) != "") {
70 throw IllegalParameters(__FILE__,__LINE__,__func__,
71 TCEString("Operation:") + op.name()
72 + " has invalid dag, index: " + Conversion::toString(i)
73 + "\n\tError: " + op.dagError(i));
74 }
75
76 if (countUnknownOperations(currDag, opSet) != 0) {
77 continue; // Discard the dag with unsupported operations
78 }
79
80 if (immInfo) {
81 bool discardDag = false;
82 for (int i = 0; i < currDag.nodeCount(); i++) {
83 const ConstantNode* cNode =
84 dynamic_cast<ConstantNode*>(&currDag.node(i));
85 if (cNode == nullptr) continue;
86
87 for (auto& edge : currDag.outEdges(*cNode)) {
88 const OperationNode* opNode = dynamic_cast<OperationNode*>(
89 &currDag.headNode(*edge));
90 assert(opNode &&
91 "Operation DAG node is other than OperationNode.");
92
93 if (immInfo->count(
94 opNode->referencedOperation(),
95 edge->dstOperand())) {
96 // TODO check if constant can be encoded as short
97 // immediate.
98
99 // TODO: should check if the operand can be swapped.
100 // If so, alter the dag to get the better immediate
101 // transport support.
102 } else {
103 discardDag = true;
104 break;
105 }
106 }
107 if (discardDag) break;
108 }
109 if (discardDag) {
110 continue;
111 }
112 }
113 retDags.push_back(&currDag);
114 }
115
116 return retDags;
117}
#define __func__
#define assert(condition)
virtual Node & headNode(const Edge &edge) const
static std::string toString(const T &source)
size_t count(const ImmInfoKey &key) const
Definition ImmInfo.hh:87
Operation & operation(const char *name)
virtual TCEString dagError(int index) const
Definition Operation.cc:182

References __func__, assert, ImmInfo::count(), countUnknownOperations(), Operation::dag(), Operation::dagCount(), Operation::dagError(), BoostGraph< GraphNode, GraphEdge >::headNode(), Operation::name(), BoostGraph< GraphNode, GraphEdge >::node(), BoostGraph< GraphNode, GraphEdge >::nodeCount(), OperationPool::operation(), BoostGraph< GraphNode, GraphEdge >::outEdges(), OperationNode::referencedOperation(), and Conversion::toString().

Referenced by TDGen::writeInstrInfo().

Here is the call graph for this function:

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