OpenASIP  2.0
ProgramOperation.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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 ProgramOperation.hh
26  *
27  * Declaration of ProgramOperation class.
28  *
29  * @author Heikki Kultala 2006 (hkultala-no.spam-cs.tut.fi)
30  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #ifndef TCE_PROGRAM_OPERATION_HH
35 #define TCE_PROGRAM_OPERATION_HH
36 
37 #include <string>
38 #include <map>
39 #include <vector>
40 #include <memory>
41 
42 #include "Exception.hh"
43 
44 class MoveNode;
45 class MoveNodeSet;
46 class Operation;
47 class ProgramOperation;
48 
49 namespace llvm {
50  class MachineInstr;
51 }
52 namespace TTAProgram {
53  class Move;
54 }
55 
56 namespace TTAMachine {
57  class Unit;
58  class PortGuard;
59  class FunctionUnit;
60  class HWOperation;
61 }
62 
63 // use this smart_ptr type to point to POs to allow more safe sharing of
64 // POs between POM and DDG, etc.
65 typedef std::shared_ptr<ProgramOperation> ProgramOperationPtr;
66 
67 /**
68  * Represents a single execution of an operation in a program.
69  */
71 public:
73  const Operation &operation,
74  const llvm::MachineInstr* instr=NULL);
77 
78  void addNode(MoveNode& node);
79  void addInputNode(MoveNode& node);
80  void addOutputNode(MoveNode& node, int outputIndex);
81  void addOutputNode(MoveNode& node);
82  void addGuardOutputNode(MoveNode& node);
83 
84  int outputIndexFromGuardOfMove(const MoveNode& node) const;
85  int outputIndexFromGuard(const TTAMachine::PortGuard& pg) const;
86 
87  static int outputIndexFromGuard(
88  const TTAMachine::PortGuard& pg, const Operation& op);
89 
90  int outputIndexOfMove(const MoveNode& mn) const;
93  const MoveNode& outputNode) const;
94 
96  const MoveNode& outputNode) const;
97 
98  void removeOutputNode(MoveNode& node, int outputIndex);
99  void removeOutputNode(MoveNode& node);
100  void removeGuardOutputNode(MoveNode& node);
101  void removeInputNode(MoveNode& node);
102 
103  bool isComplete();
104  bool isReady();
105  bool isMultinode();
106  bool isAssigned();
107  bool isAnyNodeAssigned();
108  bool isAnyInputAssigned();
109  bool isAnyOutputAssigned();
110  bool areInputsAssigned();
111  bool areOutputsAssigned();
112 
114  MoveNodeSet& inputNode(int in) const;
115  MoveNodeSet& outputNode(int out) const;
116 
117  bool hasOutputNode(int out) const;
118  bool hasInputNode(int in) const;
119 
120  const Operation& operation() const;
121  void setOperation(const Operation& op);
122 
123  int inputMoveCount() const;
124  int outputMoveCount() const;
125 
126  bool hasMoveNodeForMove(const TTAProgram::Move& move) const;
127  MoveNode& moveNode(const TTAProgram::Move& move) const;
128  MoveNode& inputMove(int index) const;
129  MoveNode& outputMove(int index) const;
130 
131  MoveNode* triggeringMove() const;
132 
133  MoveNode* findTriggerFromUnit(const TTAMachine::Unit& unit) const;
134  bool isLegalFU(const TTAMachine::FunctionUnit& fu) const;
135 
136  const llvm::MachineInstr* machineInstr() const { return mInstr_; }
137 
138  void switchInputs(int idx1 = 1, int idx2 = 2);
139 
140  std::string toString() const;
141 
142  unsigned int poId() const;
143 
144  bool hasConstantOperand() const;
145  // Comparator for maps and sets
146 
147  bool operator==(const ProgramOperation& po) { return poId() == po.poId(); }
148  class Comparator {
149  public:
150  bool operator()(
151  const ProgramOperation* po1, const ProgramOperation* po2) const;
152  bool operator()(
153  const ProgramOperationPtr &po1, const ProgramOperationPtr &po2) const;
154 
155  };
156 
157 private:
158  typedef std::vector<MoveNode*> MoveVector;
159  // copying forbidden
161  // assignment forbidden
163  // OSAL Operation this program operation is executing.
165  // map from operand index to MoveNodeSet
166  std::map<int,MoveNodeSet*> inputMoves_;
167  // map from operand index to MoveNodeSet
168  std::map<int,MoveNodeSet*> outputMoves_;
169  // all input moves
171  // all output moves
173  unsigned int poId_;
174  static unsigned int idCounter;
175  // Reference to original LLVM MachineInstruction
176  const llvm::MachineInstr* mInstr_;
177 };
178 
180 public:
182  const ProgramOperationPtr po1, const ProgramOperationPtr po2) const {
183  return ProgramOperation::Comparator()(po1.get(), po2.get());
184  }
185 };
186 
187 
188 #endif
ProgramOperation::operation
const Operation & operation() const
Definition: ProgramOperation.cc:590
ProgramOperation::MoveVector
std::vector< MoveNode * > MoveVector
Definition: ProgramOperation.hh:158
TTAProgram
Definition: Estimator.hh:65
ProgramOperation::outputIndexFromGuardOfMove
int outputIndexFromGuardOfMove(const MoveNode &node) const
Definition: ProgramOperation.cc:256
llvm
Definition: InlineAsmParser.hh:49
ProgramOperationPtrComparator::operator()
bool operator()(const ProgramOperationPtr po1, const ProgramOperationPtr po2) const
Definition: ProgramOperation.hh:181
ProgramOperation::operator==
bool operator==(const ProgramOperation &po)
Definition: ProgramOperation.hh:147
ProgramOperation::addGuardOutputNode
void addGuardOutputNode(MoveNode &node)
Definition: ProgramOperation.cc:201
ProgramOperation::removeInputNode
void removeInputNode(MoveNode &node)
Definition: ProgramOperation.cc:289
ProgramOperation::hasOutputNode
bool hasOutputNode(int out) const
Definition: ProgramOperation.cc:576
TTAMachine::HWOperation
Definition: HWOperation.hh:52
Exception.hh
ProgramOperationPtr
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition: ProgramOperation.hh:65
ProgramOperation::outputNode
MoveNodeSet & outputNode(int out) const
Definition: ProgramOperation.cc:535
ProgramOperation::isAnyOutputAssigned
bool isAnyOutputAssigned()
Definition: ProgramOperation.cc:451
ProgramOperationPtrComparator
Definition: ProgramOperation.hh:179
ProgramOperation::fuFromOutMove
const TTAMachine::FunctionUnit * fuFromOutMove(const MoveNode &outputNode) const
Definition: ProgramOperation.cc:844
ProgramOperation::areInputsAssigned
bool areInputsAssigned()
Definition: ProgramOperation.cc:435
ProgramOperation::switchInputs
void switchInputs(int idx1=1, int idx2=2)
Definition: ProgramOperation.cc:795
ProgramOperation
Definition: ProgramOperation.hh:70
MoveNode
Definition: MoveNode.hh:65
ProgramOperation::machineInstr
const llvm::MachineInstr * machineInstr() const
Definition: ProgramOperation.hh:136
ProgramOperation::addNode
void addNode(MoveNode &node)
Definition: ProgramOperation.cc:119
ProgramOperation::outputMoves_
std::map< int, MoveNodeSet * > outputMoves_
Definition: ProgramOperation.hh:168
ProgramOperation::opcodeSettingNode
MoveNode & opcodeSettingNode()
Definition: ProgramOperation.cc:487
ProgramOperation::outputIndexFromGuard
int outputIndexFromGuard(const TTAMachine::PortGuard &pg) const
Definition: ProgramOperation.cc:266
ProgramOperation::Comparator
Definition: ProgramOperation.hh:148
ProgramOperation::isLegalFU
bool isLegalFU(const TTAMachine::FunctionUnit &fu) const
Definition: ProgramOperation.cc:915
ProgramOperation::triggeringMove
MoveNode * triggeringMove() const
Definition: ProgramOperation.cc:643
ProgramOperation::poId_
unsigned int poId_
Definition: ProgramOperation.hh:173
ProgramOperationPtr
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition: MoveNode.hh:52
ProgramOperation::addOutputNode
void addOutputNode(MoveNode &node, int outputIndex)
Definition: ProgramOperation.cc:167
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
ProgramOperation::isComplete
bool isComplete()
Definition: ProgramOperation.cc:315
TTAMachine::Unit
Definition: Unit.hh:51
ProgramOperation::idCounter
static unsigned int idCounter
Definition: ProgramOperation.hh:174
ProgramOperation::allOutputMoves_
MoveVector allOutputMoves_
Definition: ProgramOperation.hh:172
ProgramOperation::inputMoves_
std::map< int, MoveNodeSet * > inputMoves_
Definition: ProgramOperation.hh:166
ProgramOperation::mInstr_
const llvm::MachineInstr * mInstr_
Definition: ProgramOperation.hh:176
ProgramOperation::ProgramOperation
ProgramOperation()
TODO: this better go, just for testing with empty operation...
Definition: ProgramOperation.cc:79
ProgramOperation::hwopFromOutMove
const TTAMachine::HWOperation * hwopFromOutMove(const MoveNode &outputNode) const
Definition: ProgramOperation.cc:895
ProgramOperation::hasConstantOperand
bool hasConstantOperand() const
Definition: ProgramOperation.cc:831
ProgramOperation::allInputMoves_
MoveVector allInputMoves_
Definition: ProgramOperation.hh:170
ProgramOperation::isAnyNodeAssigned
bool isAnyNodeAssigned()
Definition: ProgramOperation.cc:398
TTAProgram::Move
Definition: Move.hh:55
ProgramOperation::removeGuardOutputNode
void removeGuardOutputNode(MoveNode &node)
Definition: ProgramOperation.cc:249
MoveNodeSet
Definition: MoveNodeSet.hh:41
ProgramOperation::inputMoveCount
int inputMoveCount() const
Definition: ProgramOperation.cc:600
ProgramOperation::isAssigned
bool isAssigned()
Definition: ProgramOperation.cc:377
ProgramOperation::findTriggerFromUnit
MoveNode * findTriggerFromUnit(const TTAMachine::Unit &unit) const
Definition: ProgramOperation.cc:677
Operation
Definition: Operation.hh:59
ProgramOperation::scheduledFU
const TTAMachine::FunctionUnit * scheduledFU() const
Definition: ProgramOperation.cc:866
ProgramOperation::outputMoveCount
int outputMoveCount() const
Definition: ProgramOperation.cc:610
ProgramOperation::addInputNode
void addInputNode(MoveNode &node)
Definition: ProgramOperation.cc:144
ProgramOperation::isMultinode
bool isMultinode()
Definition: ProgramOperation.cc:352
ProgramOperation::toString
std::string toString() const
Definition: ProgramOperation.cc:746
ProgramOperation::moveNode
MoveNode & moveNode(const TTAProgram::Move &move) const
Definition: ProgramOperation.cc:706
ProgramOperation::isReady
bool isReady()
Definition: ProgramOperation.cc:336
ProgramOperation::setOperation
void setOperation(const Operation &op)
Definition: ProgramOperation.cc:941
ProgramOperation::inputNode
MoveNodeSet & inputNode(int in) const
Definition: ProgramOperation.cc:513
ProgramOperation::hasInputNode
bool hasInputNode(int in) const
Definition: ProgramOperation.cc:560
ProgramOperation::areOutputsAssigned
bool areOutputsAssigned()
Definition: ProgramOperation.cc:467
ProgramOperation::hasMoveNodeForMove
bool hasMoveNodeForMove(const TTAProgram::Move &move) const
Definition: ProgramOperation.cc:723
ProgramOperation::poId
unsigned int poId() const
Definition: ProgramOperation.cc:765
TTAMachine::PortGuard
Definition: Guard.hh:99
ProgramOperation::Comparator::operator()
bool operator()(const ProgramOperation *po1, const ProgramOperation *po2) const
Definition: ProgramOperation.cc:773
ProgramOperation::~ProgramOperation
~ProgramOperation()
Definition: ProgramOperation.cc:90
TTAMachine
Definition: Assembler.hh:48
ProgramOperation::operator=
ProgramOperation & operator=(const ProgramOperation &)
ProgramOperation::operation_
const Operation * operation_
Definition: ProgramOperation.hh:164
ProgramOperation::outputMove
MoveNode & outputMove(int index) const
Definition: ProgramOperation.cc:632
ProgramOperation::outputIndexOfMove
int outputIndexOfMove(const MoveNode &mn) const
Definition: ProgramOperation.cc:886
ProgramOperation::isAnyInputAssigned
bool isAnyInputAssigned()
Definition: ProgramOperation.cc:419
ProgramOperation::removeOutputNode
void removeOutputNode(MoveNode &node, int outputIndex)
Definition: ProgramOperation.cc:214
ProgramOperation::inputMove
MoveNode & inputMove(int index) const
Definition: ProgramOperation.cc:621