OpenASIP  2.0
ImmediateAnalyzer.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 ImmediateAnalyzer.cc
26  *
27  * Implementation of ImmediateAnalyzer class.
28  *
29  * Created on: 8.3.2016
30  * @author Henry Linjamäki 2016 (henry.linjamaki-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "ImmediateAnalyzer.hh"
35 
36 #include <memory>
37 #include <utility>
38 #include <set>
39 
40 #include "ImmInfo.hh"
41 
42 #include "Machine.hh"
43 #include "FunctionUnit.hh"
44 #include "ControlUnit.hh"
45 #include "HWOperation.hh"
47 #include "FUPort.hh"
48 
49 #include "TCEString.hh"
50 
51 using namespace TTAMachine;
52 
53 
54 /**
55  * Collects short immediate capabilities of the machine.
56  *
57  * @param mach The machine.
58  */
59 ImmInfo*
61  std::unique_ptr<ImmInfo> result(new ImmInfo);
62 
63  for (const FunctionUnit* fu : mach.functionUnitNavigator()) {
64  analyzeImmediateCapabilitiesForFU(*fu, *result);
65  }
66 
67  analyzeImmediateCapabilitiesForFU(*mach.controlUnit(), *result);
68  // ^ todo: fix this. operations of CU are not getting included in analysis.
69 
70  //todo: remove duplicates (entries with identical (key, value pairs)).
71 
72 
73  return result.release();
74 }
75 
76 
77 /**
78  * Collects short immediate capabilities for each operation in the FU.
79  *
80  * @param fu The function unit.
81  * @param result The short immediate analysis result object where the
82  * capabilities are inserted into.
83  */
84 void
86  const TTAMachine::FunctionUnit& fu, ImmInfo& result) {
87 
88  for (int i = 0; i < fu.operationCount(); i++) {
89  HWOperation& hwop = *fu.operation(i);
90  analyzeImmediateCapabilitiesForOperation(hwop, result);
91  }
92 }
93 
94 
95 /**
96  * Collects immediate transport capabilities for the operation.
97  *
98  * @param hwop The operation.
99  * @param result The short immediate analysis result object where the
100  * capabilities are inserted into.
101  */
102 void
104  const TTAMachine::HWOperation& hwop, ImmInfo& result) {
105 
106  using std::make_pair;
107 
108  for (int i = 0; i < hwop.operandCount(); i++) {
109  assert(hwop.port(i+1) != nullptr);
110  const FUPort& boundPort = *hwop.port(i+1);
111  const Machine& mach = *boundPort.parentUnit()->machine();
112  std::set<const TTAMachine::Bus*> connectedBuses =
114  for (const Bus* bus : connectedBuses) {
115  if (bus->immediateWidth() < 1) {
116  continue;
117  }
118  result.insert(
119  make_pair(
120  make_pair(TCEString::toUpper(hwop.name()), i+1),
121  ImmInfoValue(bus->immediateWidth(), bus->signExtends())));
122  }
123 
124  for (const ImmediateUnit* iu : mach.immediateUnitNavigator()) {
125  if (MachineConnectivityCheck::isConnected(*iu, boundPort)) {
126  for (auto& it : mach.instructionTemplateNavigator()) {
127  int supportedWidth = it->supportedWidth(*iu);
128  if (supportedWidth < 1) {
129  continue;
130  }
131 
132  result.insert(
133  make_pair(
134  make_pair(TCEString::toUpper(hwop.name()), i+1),
135  ImmInfoValue(supportedWidth, iu->signExtends())));
136  }
137  }
138  }
139  }
140 }
141 
142 
143 
ImmediateAnalyzer.hh
MachineConnectivityCheck.hh
TTAMachine::HWOperation
Definition: HWOperation.hh:52
TTAMachine::BaseFUPort::parentUnit
FunctionUnit * parentUnit() const
Definition: BaseFUPort.cc:96
ImmediateAnalyzer::analyzeImmediateCapabilitiesForOperation
static void analyzeImmediateCapabilitiesForOperation(const TTAMachine::HWOperation &hwop, ImmInfo &result)
Definition: ImmediateAnalyzer.cc:103
ImmInfoValue
Definition: ImmInfo.hh:58
TTAMachine::Bus
Definition: Bus.hh:53
TCEString.hh
ImmInfo.hh
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::HWOperation::port
virtual FUPort * port(int operand) const
Definition: HWOperation.cc:320
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
HWOperation.hh
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
TTAMachine::Machine::immediateUnitNavigator
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition: Machine.cc:416
MachineConnectivityCheck::isConnected
static bool isConnected(const TTAMachine::Port &sourcePort, const TTAMachine::Port &destinationPort, const TTAMachine::Guard *guard=NULL)
Definition: MachineConnectivityCheck.cc:128
ImmediateAnalyzer::analyze
static ImmInfo * analyze(const TTAMachine::Machine &mach)
Definition: ImmediateAnalyzer.cc:60
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
Machine.hh
TTAMachine::HWOperation::operandCount
int operandCount() const
Definition: HWOperation.cc:306
TTAMachine::Component::machine
virtual Machine * machine() const
FUPort.hh
ControlUnit.hh
MachineConnectivityCheck::connectedSourceBuses
static std::set< const TTAMachine::Bus * > connectedSourceBuses(const TTAMachine::Port &port)
Definition: MachineConnectivityCheck.cc:769
ImmediateAnalyzer::analyzeImmediateCapabilitiesForFU
static void analyzeImmediateCapabilitiesForFU(const TTAMachine::FunctionUnit &fu, ImmInfo &result)
Definition: ImmediateAnalyzer.cc:85
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
TTAMachine
Definition: Assembler.hh:48
TCEString::toUpper
static TCEString toUpper(const TCEString &str, const std::locale &loc=std::locale())
Definition: TCEString.cc:156
TTAMachine::Machine::instructionTemplateNavigator
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition: Machine.cc:428
ImmInfo
Definition: ImmInfo.hh:82
TTAMachine::Machine
Definition: Machine.hh:73
FunctionUnit.hh
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50