OpenASIP  2.0
FUBroker.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2016 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 InputFUBroker.cc
26  *
27  * Implementation of InputFUBroker class.
28  *
29  * @author Heikki Kultala 2016-2020 (heikki.kultala-no.spam-tuni.fi)
30  * @note rating: red
31  */
32 #include "FUBroker.hh"
33 #include "Move.hh"
34 #include "Terminal.hh"
35 #include "FunctionUnit.hh"
36 
37 std::pair<bool, const TTAMachine::FunctionUnit*> FUBroker::findDstFUOfMove(
38  const MoveNode& node, const TTAMachine::FunctionUnit* resFU,
39  DataDependenceGraph::NodeSet& processedInputNodes) const {
40  // already processed this once. do not do it twice
41  if (processedInputNodes.count(const_cast<MoveNode*>(&node))) {
42  return std::make_pair(true, resFU);
43  }
44  processedInputNodes.insert(const_cast<MoveNode*>(&node));
45  const TTAProgram::Move& move = node.move();
46  const TTAProgram::Terminal& dst = move.destination();
47  if (!dst.isFUPort()) {
48  throw InvalidData(
49  __FILE__, __LINE__, __func__,
50  "Output move does not have FU source!");
51  }
52  const TTAMachine::FunctionUnit& fu = dst.functionUnit();
53  if (hasResourceOf(fu)) {
54  if (resFU == NULL) {
55  resFU = &fu;
56  } else {
57  if (resFU != &fu) {
58  return std::make_pair(false, resFU);
59  // illegal/empty
60  }
61  }
62  }
63  for (unsigned int i = 0; i < node.destinationOperationCount(); i++) {
65  auto a = findFUOfPO(po, resFU);
66  if (a.first) {
67  resFU = a.second;
68  } else {
69  return a;
70  }
71  }
72  return std::make_pair(true, resFU);
73 }
74 
75 
76 // first part is if no conflict?
77 std::pair<bool, const TTAMachine::FunctionUnit*> FUBroker::findFUOfPO(
78  ProgramOperation& po, const TTAMachine::FunctionUnit* resFU) const {
79 
80  const TTAMachine::FunctionUnit* fu = po.scheduledFU();
81 
82  // did not find anything. use default or return not found.
83  if (fu == nullptr) {
84  if (resFU && !po.isLegalFU(*resFU)) {
85  return std::make_pair(false, resFU);
86  }
87  return std::make_pair(true, resFU);
88  }
89 
90  // illegal annotations?
91  if (!po.isLegalFU(*fu)) {
92  return std::make_pair(false, resFU);
93  }
94 
95  assert(hasResourceOf(*fu));
96  // did find something, but it's different than default
97  if (fu != resFU) {
98  if (resFU == nullptr) {
99  // default was null, use then one found
100  return std::make_pair(true, fu);
101  } else {
102  // default not null. conflict! return not found.
103  return std::make_pair(false, resFU);
104  }
105  }
106  // fu and resfu are the same? ok!
107  return std::make_pair(true,fu);
108 
109 }
TTAProgram::Terminal::isFUPort
virtual bool isFUPort() const
Definition: Terminal.cc:118
BoostGraph< MoveNode, DataDependenceEdge >::NodeSet
std::set< MoveNode *, typename MoveNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
ProgramOperation
Definition: ProgramOperation.hh:70
MoveNode
Definition: MoveNode.hh:65
Terminal.hh
ResourceBroker::hasResourceOf
bool hasResourceOf(const TTAMachine::MachinePart &mp) const
Definition: ResourceBroker.cc:203
ProgramOperation::isLegalFU
bool isLegalFU(const TTAMachine::FunctionUnit &fu) const
Definition: ProgramOperation.cc:915
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
FUBroker::findFUOfPO
std::pair< bool, const TTAMachine::FunctionUnit * > findFUOfPO(ProgramOperation &po, const TTAMachine::FunctionUnit *resFU) const
Definition: FUBroker.cc:77
InvalidData
Definition: Exception.hh:149
FUBroker.hh
__func__
#define __func__
Definition: Application.hh:67
TTAProgram::Move
Definition: Move.hh:55
MoveNode::destinationOperationCount
unsigned int destinationOperationCount() const
ProgramOperation::scheduledFU
const TTAMachine::FunctionUnit * scheduledFU() const
Definition: ProgramOperation.cc:866
TTAProgram::Terminal::functionUnit
virtual const TTAMachine::FunctionUnit & functionUnit() const
Definition: Terminal.cc:251
MoveNode::destinationOperation
ProgramOperation & destinationOperation(unsigned int index=0) const
MoveNode::move
TTAProgram::Move & move()
TTAProgram::Terminal
Definition: Terminal.hh:60
Move.hh
FUBroker::findDstFUOfMove
std::pair< bool, const TTAMachine::FunctionUnit * > findDstFUOfMove(const MoveNode &node, const TTAMachine::FunctionUnit *resFU, DataDependenceGraph::NodeSet &processedInputNodes) const
Definition: FUBroker.cc:37
FunctionUnit.hh