OpenASIP 2.2
Loading...
Searching...
No Matches
LLVMTCEPOMBuilder.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2011 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 LLVMTCEPOMBuilder.cc
26 *
27 * Implementation of LLVMTCEPOMBuilder class.
28 *
29 * @author Pekka Jääskeläinen 2010-2012
30 * @note rating: red
31 */
32#include "LLVMTCEPOMBuilder.hh"
33
34#include <iostream>
35#include <string>
36
37#include "llvm/Support/CommandLine.h"
38
39#include "POMDisassembler.hh"
40#include "UniversalMachine.hh"
41#include "TerminalFUPort.hh"
42#include "Machine.hh"
43#include "HWOperation.hh"
44#include "Program.hh"
45#include "Procedure.hh"
46#include "Instruction.hh"
47#include "TCEString.hh"
48#include "Conversion.hh"
49#include "ControlUnit.hh"
52#include "InterPassData.hh"
53//#include "PreBypassBasicBlockScheduler.hh"
54//#include "LLVMTCEDataDependenceGraphBuilder.hh"
55#include "FUPort.hh"
56
57namespace llvm {
58
59static cl::opt<bool>
61 "parallelize-moves",
62 cl::desc("Parallelize the TTA moves as efficiently as possible."),
63 cl::init(false), cl::Hidden);
64
66
70
71unsigned
73 return 1000000; // ;)
74}
75
76unsigned
78 return 1000001; // ;D
79}
80
82LLVMTCEPOMBuilder::registerFileName(unsigned llvmRegNum) const {
83
84 if (llvmRegNum == 1000000)
85 return "RF"; /* temp hack, always assume SP is the RF.4 */
86 abortWithError("Unimplemented.");
87}
88
89int
90LLVMTCEPOMBuilder::registerIndex(unsigned llvmRegNum) const {
91
92 if (llvmRegNum == 1000000)
93 return 4; /* temp hack, always assume SP is the RF.4 */
94 abortWithError("Unimplemented.");
95}
96
99 const MachineInstr* mi, TTAProgram::CodeSnippet* proc,
100 bool, bool) {
101 TCEString opName(targetMachine().getSubtargetImpl(
102 mi->getParent()->getParent()->getFunction())->
103 getInstrInfo()->getName(mi->getOpcode()).str());
104 /* Non-trigger move. */
105 if (opName == "MOVE")
106 return LLVMTCEBuilder::emitMove(mi, proc);
107
108 /* A trigger move. The source is the 2nd last argument. */
110 createTerminal(mi->getOperand(mi->getNumOperands() - 2));
111 TTAProgram::Terminal* dst = /* defined as implicit def */
112 createTerminal(mi->getOperand(mi->getNumOperands() - 1));
113
115 auto move = createMove(src, dst, bus);
116
118
119 instr->addMove(move);
120 proc->add(instr);
121 return instr;
122}
123
124
126LLVMTCEPOMBuilder::operationName(const MachineInstr&) const {
127 return "MOVE";
128}
129
131LLVMTCEPOMBuilder::createFUTerminal(const MachineOperand& mo) const {
132 TCEString regName(
133 targetMachine().getSubtargetImpl(
134 mo.getParent()->getParent()->getParent()->getFunction())->
135 getRegisterInfo()->getName(mo.getReg()));
136
137 // test for _number which indicates a RF access
138 std::vector<TCEString> pieces = regName.split("_");
139 if (pieces.size() == 2) {
140 TCEString indexStr = pieces.at(1);
141 try {
142 Conversion::toInt(indexStr);
143 return NULL;
144 } catch (Exception&) {
145 }
146 }
147
148 assert(pieces.size() > 0);
149
150 TCEString fuName = pieces.at(0);
151 TCEString portName = pieces.at(1);
153 if (pieces.size() == 3) {
154 // FU_triggerport_OP
155 operationName = pieces.at(2);
156 }
157
158 // always assume it's the ALU of minimal.adf for now
159 // should be parsed from the regName
162
163 assert(fu != NULL);
164
165 TTAMachine::FUPort* fuPort =
166 dynamic_cast<TTAMachine::FUPort*>(fu->port(portName));
167 assert(fuPort != NULL);
168 if (operationName != "") {
169 assert(fuPort->isTriggering());
171 return new TTAProgram::TerminalFUPort(hwOp, hwOp.io(*fuPort));
172 } else {
174 new TTAProgram::TerminalFUPort(*fuPort);
175 return term;
176 }
177}
178
179extern "C" MachineFunctionPass* createLLVMTCEPOMBuilderPass() {
180 return new llvm::LLVMTCEPOMBuilder();
181}
182
183bool
188
189bool
197
198
199}
#define abortWithError(message)
#define assert(condition)
static int toInt(const T &source)
std::vector< TCEString > split(const std::string &delim) const
Definition TCEString.cc:114
virtual bool isTriggering() const
Definition FUPort.cc:182
virtual HWOperation * operation(const std::string &name) const
virtual BaseFUPort * port(const std::string &name) const
int io(const FUPort &port) const
ComponentType * item(int index) const
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899
virtual void add(Instruction *ins)
void addMove(std::shared_ptr< Move > move)
UniversalMachine & universalMachine() const
Definition Program.cc:104
void convertSymbolRefsToInsRefs(bool ignoreUnfoundSymbols=false)
Definition Program.cc:1264
TTAMachine::Bus & universalBus() const
TTAProgram::Program * result()
TTAMachine::Machine * mach_
Machine for building the program.
std::shared_ptr< TTAProgram::Move > createMove(const MachineOperand &src, const MachineOperand &dst, TTAProgram::MoveGuard *guard)
TTAProgram::Terminal * createTerminal(const MachineOperand &mo, int bitLimit=0)
TTAProgram::Program * prog_
Current program being built.
const TargetMachine & targetMachine() const
bool doFinalization(Module &M)
virtual TTAProgram::Instruction * emitMove(const MachineInstr *mi, TTAProgram::CodeSnippet *proc, bool conditional=false, bool trueGuard=true)
bool doInitialization(Module &M)
virtual TCEString registerFileName(unsigned llvmRegNum) const
virtual unsigned spDRegNum() const
virtual TTAProgram::Terminal * createFUTerminal(const MachineOperand &) const
virtual int registerIndex(unsigned llvmRegNum) const
TTAProgram::Instruction * emitMove(const MachineInstr *mi, TTAProgram::CodeSnippet *proc, bool conditional=false, bool trueGuard=true)
virtual unsigned raPortDRegNum() const
virtual TCEString operationName(const MachineInstr &mi) const
static cl::opt< bool > ParallelizeMoves("parallelize-moves", cl::desc("Parallelize the TTA moves as efficiently as possible."), cl::init(false), cl::Hidden)
MachineFunctionPass * createLLVMTCEPOMBuilderPass()