OpenASIP  2.0
FUGen.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2017-2019 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 FUGen.hh
26 *
27 * @author Lasse Lehtonen 2017 (lasse.lehtonen-no.spam-tut.fi)
28 */
29 #pragma once
30 
31 #include "FUGenerated.hh"
32 #include "HDBManager.hh"
33 #include "HDLGenerator.hh"
34 #include "LHSValue.hh"
35 #include "Machine.hh"
36 #include "NetlistBlock.hh"
37 #include "ProGeOptions.hh"
38 #include "StringTools.hh"
39 #include "MathTools.hh"
40 #include "OperationDAG.hh"
41 #include "OperationNode.hh"
42 #include "ConstantNode.hh"
43 #include <string>
44 #include <vector>
45 
46 #include "Exception.hh"
48 #include "HDBTypes.hh"
49 #include "ProGeTypes.hh"
51 #include "TCEString.hh"
52 #include "ProGeOptions.hh"
53 
54 namespace ProGe{
55  class Signal;
56 }
57 
58 class FUGen {
59 public:
60  FUGen() = delete;
61  FUGen(const FUGen&) = delete;
62  FUGen& operator=(const FUGen&) = delete;
64  std::vector<std::string> globalOptions, IDF::FUGenerated& fug,
67  globalOptions_(globalOptions),
68  fug_(fug),
69  core_(core),
70  fu_(StringTools::stringToLower("fu_" + fug.name())),
71  adfFU_(machine.functionUnitNavigator().item(fug.name())),
72  operations_(),
73  opcodeWidth_(MathTools::requiredBits(adfFU_->operationCount()-1)),
74  moduleName_("fu_" + fug_.name()) {
75 
76  // Find the netlistblock
77  for (size_t i = 0; i < core_->subBlockCount(); ++i) {
78  std::string name = core_->subBlock(i).moduleName();
81  break;
82  }
83  }
84 
85  if (adfFU_->hasAddressSpace()) {
86  auto as = adfFU_->addressSpace();
88  }
89  }
90 
91  static void implement(const ProGeOptions& options,
92  std::vector<std::string> globalOptions,
93  const std::vector<IDF::FUGenerated>& generatetFUs,
95 
96 private:
97 
98  typedef std::pair<std::string, std::string> Replace;
99 
101  int id;
104  std::string signalName;
105  bool isOutput;
106  };
107 
113  std::string operation;
114  };
115 
117  std::string baseOp;
118  std::string sensitiveOpcode;
121  std::vector<OperandConnection> operands;
122  std::set<int> results;
123  std::map<std::string, int> resourceOffsets;
124  std::vector<std::string> subOperations;
125  };
126 
127  struct BaseOperation {
128  std::string name;
129  int latency;
130  std::vector<HDB::Variable> variables;
131  std::vector<HDB::Variable> globalsignals;
132  std::vector<HDB::OperationImplementationResource> resources;
133  std::deque<std::string> implementation;
134  std::deque<std::string> initial;
135  std::deque<std::string> postOp;
136  };
137 
138  struct DAGConstant {
139  std::string operation;
140  long int value;
141  int id;
142  };
143 
144  void createOutputPipeline();
145 
146  void addRegisterIfMissing(std::string name, int width,
149 
150  std::string findAbsolutePath(std::string file);
151 
152  void createFUHeaderComment();
153  void createMandatoryPorts();
154  void checkForValidity();
155  void createExternalInterfaces(bool genIntegrator);
157  void buildOperations();
158  void finalizeHDL();
160  void copyImplementation(std::string file, std::string format,
161  bool isSynthesizable);
162  void parseOperations();
163  void scheduleOperations();
164  void createPortPipeline();
165  void createShadowRegisters();
166 
168  bool isOutput);
169  int DAGNodeOperandWidth(OperationDAGNode& node, int id, OperationDAG* dag);
170 
171  void readImplementation(std::string filename, std::string opName,
172  std::deque<std::string>& sink);
173  void prepareSnippet(std::string name,
174  std::deque<std::string> statements,
176  std::set<std::string>& addedStatements);
177  std::deque<std::string> readFile(std::string filename);
178 
179  std::vector<Replace> buildReplaces(std::string opName);
180  std::string replaceToken(std::string line, Replace replace);
181  bool hasToken(std::string line, std::string token);
182 
184 
185  // Functions which construct pipelined signal names
186  std::string opcodeSignal(int stage);
187  std::string triggerSignal(int stage);
188  std::string opcodeConstant(std::string operation);
189  std::string operandSignal(std::string operation, int id);
190  std::string operandPlaceholder(int id);
191  std::string pipelineName(std::string port, int cycle);
192  std::string pipelineValid(std::string port, int cycle);
193  std::string subOpName(OperationNode* node);
194  std::string constantName(ConstantNode* node, OperationDAG* dag);
195  std::string constantName(DAGConstant dag);
196 
197  bool isLSUDataPort(const std::string& portName);
198  ProGe::Signal inferLSUSignal(const std::string& portName) const;
199 
200  // parseOperation results
203 
205  std::vector<std::string> globalOptions_;
206 
209 
212 
213  std::vector<std::string> operations_;
215 
216  std::string moduleName_;
218 
219  // key = operation name
220  std::unordered_map<std::string, BaseOperation> baseOperations_;
221  std::unordered_map<std::string, OperationSchedule> scheduledOperations_;
222  std::unordered_map<std::string, std::vector<Replace>> replacesPerOp_;
223  std::unordered_map<std::string, int> operationCycles_;
224  std::unordered_map<std::string, int> implLatency_;
225  std::unordered_map<std::string, OperationDAG*> implementapleDAGs_;
226  std::unordered_map<std::string, int> subOpCount_;
227  std::unordered_map<std::string, int> dagConstantCount_;
228 
229  // key = resource name
230  std::unordered_map<std::string, int> resourceCount_;
231 
232  // key = port name
233  std::unordered_map<std::string, int> pipelineLength_;
234  std::unordered_map<std::string, ProGe::Direction> portDirection_;
235  std::unordered_multimap<std::string, OutputConnection> portInputs_;
236 
237  // key = node id
238  std::unordered_map<int, int> nodeImplementations_;
239  std::unordered_map<int, DAGConstant> dagConstants_;
240 
241  std::vector<std::string> resourceInputs_;
242  std::vector<std::string> resourceOutputs_;
243 
244  std::unordered_set<std::string> extIfaces_;
245  std::set<std::pair<std::string, std::string>> extOutputs_;
246  std::unordered_set<std::string> extInputs_;
247 
248  std::vector<HDB::Variable> renamedVariables_;
249  std::vector<HDB::Variable> renamedGlobalSignals_;
250  std::string triggerPort_;
251 
252  std::vector<std::string> registers_;
253 
254  bool useGlockRequest_ = false;
255  bool useGlock_ = false;
257  bool frontRegistered_ = false;
258  bool middleRegistered_ = false;
259  bool backRegistered_ = false;
260  int addressWidth_ = 0;
261  bool isLSU_ = false;
262 };
FUGen::parseOperations
void parseOperations()
Definition: FUGen.cc:906
FUGen::isLSU_
bool isLSU_
Definition: FUGen.hh:261
FUGen::BaseOperation::latency
int latency
Definition: FUGen.hh:129
FUGen::adfFU_
TTAMachine::FunctionUnit * adfFU_
Definition: FUGen.hh:211
RFImplementationLocation.hh
FUGen::renamedGlobalSignals_
std::vector< HDB::Variable > renamedGlobalSignals_
Definition: FUGen.hh:249
HDBTypes.hh
FUGen::createShadowRegisters
void createShadowRegisters()
Definition: FUGen.cc:1243
FUGen::pipelineValid
std::string pipelineValid(std::string port, int cycle)
Definition: FUGen.cc:155
FUGen::BaseOperation::resources
std::vector< HDB::OperationImplementationResource > resources
Definition: FUGen.hh:132
FUGen::fu_
HDLGenerator::Module fu_
Definition: FUGen.hh:210
FUGen::options_
const ProGeOptions & options_
Definition: FUGen.hh:204
FUGen::findAbsolutePath
std::string findAbsolutePath(std::string file)
Definition: FUGen.cc:101
FUGen::OutputConnection::operandID
int operandID
Definition: FUGen.hh:110
FUGen::resourceInputs_
std::vector< std::string > resourceInputs_
Definition: FUGen.hh:241
FUGen::OperandConnection::portWidth
int portWidth
Definition: FUGen.hh:102
HDLGenerator::CodeBlock
Definition: HDLGenerator.hh:876
FUGen::selectedLanguage
HDLGenerator::Language selectedLanguage()
Definition: FUGen.cc:73
FUGen::globalOptions_
std::vector< std::string > globalOptions_
Definition: FUGen.hh:205
FUGen::triggerSignal
std::string triggerSignal(int stage)
Definition: FUGen.cc:122
FUGen::OutputConnection::sourceCycle
int sourceCycle
Definition: FUGen.hh:111
ProGe::NetlistBlock
Definition: NetlistBlock.hh:61
FUGen::replaceToken
std::string replaceToken(std::string line, Replace replace)
Definition: FUGen.cc:67
FUGen::extInputs_
std::unordered_set< std::string > extInputs_
Definition: FUGen.hh:246
FUGen::BaseOperation::globalsignals
std::vector< HDB::Variable > globalsignals
Definition: FUGen.hh:131
FUGen::BaseOperation
Definition: FUGen.hh:127
FUGen::OperationSchedule::subOperations
std::vector< std::string > subOperations
Definition: FUGen.hh:124
TTAMachine::FunctionUnit::hasAddressSpace
virtual bool hasAddressSpace() const
Definition: FunctionUnit.cc:608
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
FUGen::finalizeHDL
void finalizeHDL()
Definition: FUGen.cc:889
Exception.hh
FUGen::checkForValidity
void checkForValidity()
Definition: FUGen.cc:365
FUGen::hasToken
bool hasToken(std::string line, std::string token)
Definition: FUGen.cc:61
FUGen::subOpName
std::string subOpName(OperationNode *node)
Definition: FUGen.cc:160
FUGen::replacesPerOp_
std::unordered_map< std::string, std::vector< Replace > > replacesPerOp_
Definition: FUGen.hh:222
FUGen::subOpCount_
std::unordered_map< std::string, int > subOpCount_
Definition: FUGen.hh:226
FUGen::BaseOperation::initial
std::deque< std::string > initial
Definition: FUGen.hh:134
MathTools
Definition: MathTools.hh:42
FUGen::extOutputs_
std::set< std::pair< std::string, std::string > > extOutputs_
Definition: FUGen.hh:245
FUGen::portDirection_
std::unordered_map< std::string, ProGe::Direction > portDirection_
Definition: FUGen.hh:234
FUGen::resourceOutputs_
std::vector< std::string > resourceOutputs_
Definition: FUGen.hh:242
FUGen::frontRegistered_
bool frontRegistered_
Definition: FUGen.hh:257
FUGen::BaseOperation::postOp
std::deque< std::string > postOp
Definition: FUGen.hh:135
FUGen::OperandConnection::id
int id
Definition: FUGen.hh:101
FUGen::dagConstantCount_
std::unordered_map< std::string, int > dagConstantCount_
Definition: FUGen.hh:227
FUGen::addressWidth_
int addressWidth_
Definition: FUGen.hh:260
HDLGenerator::Module
Definition: HDLGenerator.hh:1163
ProGeOptions
Definition: ProGeOptions.hh:41
HDLGenerator::Behaviour
Definition: HDLGenerator.hh:1110
FUGen::portInputs_
std::unordered_multimap< std::string, OutputConnection > portInputs_
Definition: FUGen.hh:235
FUGen::createOperationResources
void createOperationResources()
Definition: FUGen.cc:634
FUGen::OperationSchedule::resourceOffsets
std::map< std::string, int > resourceOffsets
Definition: FUGen.hh:123
LHSValue.hh
FUGen::baseOperations_
std::unordered_map< std::string, BaseOperation > baseOperations_
Definition: FUGen.hh:220
FUGen::createOutputPipeline
void createOutputPipeline()
Definition: FUGen.cc:1385
FUGen::DAGConstant
Definition: FUGen.hh:138
FUGenerated.hh
FUGen::BaseOperation::name
std::string name
Definition: FUGen.hh:128
TTAMachine::FunctionUnit::addressSpace
virtual AddressSpace * addressSpace() const
Definition: FunctionUnit.cc:580
FUGen::createMandatoryPorts
void createMandatoryPorts()
Definition: FUGen.cc:327
FUGen::OutputConnection
Definition: FUGen.hh:108
FUGen::operator=
FUGen & operator=(const FUGen &)=delete
FUGen::extIfaces_
std::unordered_set< std::string > extIfaces_
Definition: FUGen.hh:244
OperationNode
Definition: OperationNode.hh:47
FUGen::scheduleOperations
void scheduleOperations()
Definition: FUGen.cc:1064
OperationDAGEdge
Definition: OperationDAGEdge.hh:38
FUGen::fug_
IDF::FUGenerated & fug_
Definition: FUGen.hh:207
FUGen::implement
static void implement(const ProGeOptions &options, std::vector< std::string > globalOptions, const std::vector< IDF::FUGenerated > &generatetFUs, const TTAMachine::Machine &machine, ProGe::NetlistBlock *core)
Definition: FUGen.cc:1515
FUGen::DAGConstant::operation
std::string operation
Definition: FUGen.hh:139
FUGen::useGlock_
bool useGlock_
Definition: FUGen.hh:255
FUGen::BaseOperation::implementation
std::deque< std::string > implementation
Definition: FUGen.hh:133
FUGen::registers_
std::vector< std::string > registers_
Definition: FUGen.hh:252
FUGen::dagConstants_
std::unordered_map< int, DAGConstant > dagConstants_
Definition: FUGen.hh:239
TCEString.hh
StringTools.hh
FUGen::operations_
std::vector< std::string > operations_
Definition: FUGen.hh:213
FUGen::renamedVariables_
std::vector< HDB::Variable > renamedVariables_
Definition: FUGen.hh:248
FUGen::middleRegistered_
bool middleRegistered_
Definition: FUGen.hh:258
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
FUGen::readFile
std::deque< std::string > readFile(std::string filename)
Definition: FUGen.cc:82
FUGen::OperationSchedule::operands
std::vector< OperandConnection > operands
Definition: FUGen.hh:121
FUGen::OutputConnection::operandWidth
int operandWidth
Definition: FUGen.hh:109
FUGen::OperationSchedule::results
std::set< int > results
Definition: FUGen.hh:122
FUGen::OperationSchedule::sensitiveOpcode
std::string sensitiveOpcode
Definition: FUGen.hh:118
FUGen::nodeImplementations_
std::unordered_map< int, int > nodeImplementations_
Definition: FUGen.hh:238
FUGen::createFUHeaderComment
void createFUHeaderComment()
Definition: FUGen.cc:228
IDF::FUGenerated
Definition: FUGenerated.hh:41
FUGen::triggerPort_
std::string triggerPort_
Definition: FUGen.hh:250
OperationDAGNode
Definition: OperationDAGNode.hh:45
FUGen::opcodeWidth_
int opcodeWidth_
Definition: FUGen.hh:214
FUGen::createExternalInterfaces
void createExternalInterfaces(bool genIntegrator)
Definition: FUGen.cc:568
FUGen::Replace
std::pair< std::string, std::string > Replace
Definition: FUGen.hh:98
FUGen::core_
ProGe::NetlistBlock * core_
Definition: FUGen.hh:208
FUGen::netlistBlock_
ProGe::NetlistBlock * netlistBlock_
Definition: FUGen.hh:217
OperationDAG.hh
HDLGenerator::WireType
WireType
Definition: HWGenTools.hh:34
OperationDAG
Definition: OperationDAG.hh:43
FUGen::behaviour_
HDLGenerator::Behaviour behaviour_
Definition: FUGen.hh:256
FUGen::OperandConnection::operandWidth
int operandWidth
Definition: FUGen.hh:103
FUGen::DAGNodeOperandWidth
int DAGNodeOperandWidth(OperationDAGNode &node, int id, OperationDAG *dag)
Definition: FUGen.cc:201
FUGen::OperationSchedule
Definition: FUGen.hh:116
ConstantNode
Definition: ConstantNode.hh:43
FUGen::pipelineLength_
std::unordered_map< std::string, int > pipelineLength_
Definition: FUGen.hh:233
NetlistBlock.hh
FUGen::resourceCount_
std::unordered_map< std::string, int > resourceCount_
Definition: FUGen.hh:230
FUGen::operandPlaceholder
std::string operandPlaceholder(int id)
Definition: FUGen.cc:141
FUImplementationLocation.hh
FUGen::addRegisterIfMissing
void addRegisterIfMissing(std::string name, int width, HDLGenerator::WireType wt=HDLGenerator::WireType::Auto)
Definition: FUGen.cc:1377
FUGen::useGlockRequest_
bool useGlockRequest_
Definition: FUGen.hh:254
MathTools::requiredBits
static int requiredBits(unsigned long int number)
FUGen::buildOperations
void buildOperations()
Definition: FUGen.cc:672
StringTools
Definition: StringTools.hh:44
FUGen::opcodeConstant
std::string opcodeConstant(std::string operation)
Definition: FUGen.cc:131
FUGen::backRegistered_
bool backRegistered_
Definition: FUGen.hh:259
Machine.hh
ProGeTypes.hh
FUGen::constantName
std::string constantName(ConstantNode *node, OperationDAG *dag)
Definition: FUGen.cc:178
HDLGenerator::Language
Language
Definition: HWGenTools.hh:33
FUGen::OperandConnection::signalName
std::string signalName
Definition: FUGen.hh:104
FUGen::OutputConnection::pipelineStage
int pipelineStage
Definition: FUGen.hh:112
FUGen::opcodeSignal
std::string opcodeSignal(int stage)
Definition: FUGen.cc:113
FUGen::OperationSchedule::baseOp
std::string baseOp
Definition: FUGen.hh:117
FUGen::operationCycles_
std::unordered_map< std::string, int > operationCycles_
Definition: FUGen.hh:223
HDLGenerator.hh
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
FUGen::operandSignal
std::string operandSignal(std::string operation, int id)
Definition: FUGen.cc:136
FUGen
Definition: FUGen.hh:58
FUGen::FUGen
FUGen(const ProGeOptions &options, std::vector< std::string > globalOptions, IDF::FUGenerated &fug, const TTAMachine::Machine &machine, ProGe::NetlistBlock *core)
Definition: FUGen.hh:63
FUGen::minLatency_
int minLatency_
Definition: FUGen.hh:202
FUGen::readImplementation
void readImplementation(std::string filename, std::string opName, std::deque< std::string > &sink)
Definition: FUGen.cc:492
ProGe
Definition: FUGen.hh:54
FUGen::buildReplaces
std::vector< Replace > buildReplaces(std::string opName)
Definition: FUGen.cc:395
FUGen::DAGConstant::value
long int value
Definition: FUGen.hh:140
FUGen::DAGConstant::id
int id
Definition: FUGen.hh:141
FUGen::FUGen
FUGen()=delete
FUGen::OperandConnection::isOutput
bool isOutput
Definition: FUGen.hh:105
FUGen::moduleName_
std::string moduleName_
Definition: FUGen.hh:216
FUGen::isLSUDataPort
bool isLSUDataPort(const std::string &portName)
Definition: FUGen.cc:516
FUGen::OperandConnection
Definition: FUGen.hh:100
HDLGenerator::WireType::Auto
@ Auto
FUGen::BaseOperation::variables
std::vector< HDB::Variable > variables
Definition: FUGen.hh:130
ProGe::BaseNetlistBlock::moduleName
const std::string & moduleName() const
Definition: BaseNetlistBlock.cc:140
ConstantNode.hh
FUGen::scheduledOperations_
std::unordered_map< std::string, OperationSchedule > scheduledOperations_
Definition: FUGen.hh:221
OperationNode.hh
MathTools.hh
FUGen::implementapleDAGs_
std::unordered_map< std::string, OperationDAG * > implementapleDAGs_
Definition: FUGen.hh:225
FUGen::createImplementationFiles
void createImplementationFiles()
Definition: FUGen.cc:290
HDBManager.hh
ProGe::NetlistBlock::subBlockCount
virtual size_t subBlockCount() const
Definition: BaseNetlistBlock.cc:150
FUGen::implLatency_
std::unordered_map< std::string, int > implLatency_
Definition: FUGen.hh:224
ProGe::NetlistBlock::subBlock
NetlistBlock & subBlock(size_t index) override
Definition: NetlistBlock.cc:110
ProGe::Signal
Definition: Signal.hh:46
FUGen::maxLatency_
int maxLatency_
Definition: FUGen.hh:201
FUGen::copyImplementation
void copyImplementation(std::string file, std::string format, bool isSynthesizable)
Definition: FUGen.cc:267
ProGeOptions.hh
FUGen::createPortPipeline
void createPortPipeline()
Definition: FUGen.cc:1317
FUGen::subOpConnection
OperandConnection subOpConnection(OperationDAG *dag, OperationDAGEdge *edge, bool isOutput)
Definition: FUGen.cc:1024
FUGen::OutputConnection::operation
std::string operation
Definition: FUGen.hh:113
FUGen::pipelineName
std::string pipelineName(std::string port, int cycle)
Definition: FUGen.cc:146
FUGen::OperationSchedule::initialCycle
int initialCycle
Definition: FUGen.hh:119
FUGen::prepareSnippet
void prepareSnippet(std::string name, std::deque< std::string > statements, HDLGenerator::CodeBlock &sink, std::set< std::string > &addedStatements)
Definition: FUGen.cc:854
FUGen::inferLSUSignal
ProGe::Signal inferLSUSignal(const std::string &portName) const
Definition: FUGen.cc:542
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160
FUGen::OperationSchedule::finalCycle
int finalCycle
Definition: FUGen.hh:120
TTAMachine::Machine
Definition: Machine.hh:73