OpenASIP  2.0
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"
50 #include "SpecialRegisterPort.hh"
51 #include "SequentialScheduler.hh"
52 #include "InterPassData.hh"
53 //#include "PreBypassBasicBlockScheduler.hh"
54 //#include "LLVMTCEDataDependenceGraphBuilder.hh"
55 #include "FUPort.hh"
56 
57 namespace llvm {
58 
59 static cl::opt<bool>
61  "parallelize-moves",
62  cl::desc("Parallelize the TTA moves as efficiently as possible."),
63  cl::init(false), cl::Hidden);
64 
65 char LLVMTCEPOMBuilder::ID = 0;
66 
68  LLVMTCEBuilder(ID) {
69 }
70 
71 unsigned
73  return 1000000; // ;)
74 }
75 
76 unsigned
78  return 1000001; // ;D
79 }
80 
82 LLVMTCEPOMBuilder::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 
89 int
90 LLVMTCEPOMBuilder::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. */
109  TTAProgram::Terminal* src =
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 
125 TCEString
126 LLVMTCEPOMBuilder::operationName(const MachineInstr&) const {
127  return "MOVE";
128 }
129 
131 LLVMTCEPOMBuilder::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
161  mach_->functionUnitNavigator().item(fuName);
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 
179 extern "C" MachineFunctionPass* createLLVMTCEPOMBuilderPass() {
180  return new llvm::LLVMTCEPOMBuilder();
181 }
182 
183 bool
185  mach_ = TTAMachine::Machine::loadFromADF("tta/4bus_minimal.adf");
187 }
188 
189 bool
191 
194 
195  return true;
196 }
197 
198 
199 }
llvm
Definition: InlineAsmParser.hh:49
TTAProgram::Instruction::addMove
void addMove(std::shared_ptr< Move > move)
Definition: Instruction.cc:147
llvm::LLVMTCEBuilder::doFinalization
bool doFinalization(Module &M)
Definition: LLVMTCEBuilder.cc:1090
llvm::LLVMTCEBuilder::prog_
TTAProgram::Program * prog_
Current program being built.
Definition: LLVMTCEBuilder.hh:250
llvm::ParallelizeMoves
static cl::opt< bool > ParallelizeMoves("parallelize-moves", cl::desc("Parallelize the TTA moves as efficiently as possible."), cl::init(false), cl::Hidden)
TCEString::split
std::vector< TCEString > split(const std::string &delim) const
Definition: TCEString.cc:114
llvm::LLVMTCEBuilder::result
TTAProgram::Program * result()
Definition: LLVMTCEBuilder.cc:3713
llvm::LLVMTCEBuilder::emitMove
virtual TTAProgram::Instruction * emitMove(const MachineInstr *mi, TTAProgram::CodeSnippet *proc, bool conditional=false, bool trueGuard=true)
Definition: LLVMTCEBuilder.cc:2418
TTAMachine::HWOperation
Definition: HWOperation.hh:52
SequentialScheduler.hh
UniversalMachine::universalBus
TTAMachine::Bus & universalBus() const
Definition: UniversalMachine.cc:306
TTAProgram::Instruction
Definition: Instruction.hh:57
Procedure.hh
TTAMachine::Bus
Definition: Bus.hh:53
TTAMachine::FunctionUnit::port
virtual BaseFUPort * port(const std::string &name) const
Definition: FunctionUnit.cc:145
llvm::LLVMTCEBuilder::mach_
TTAMachine::Machine * mach_
Machine for building the program.
Definition: LLVMTCEBuilder.hh:242
TTAMachine::FUPort::isTriggering
virtual bool isTriggering() const
Definition: FUPort.cc:182
llvm::LLVMTCEBuilder::createTerminal
TTAProgram::Terminal * createTerminal(const MachineOperand &mo, int bitLimit=0)
Definition: LLVMTCEBuilder.cc:2149
llvm::LLVMTCEPOMBuilder::spDRegNum
virtual unsigned spDRegNum() const
Definition: LLVMTCEPOMBuilder.cc:72
llvm::LLVMTCEPOMBuilder::LLVMTCEPOMBuilder
LLVMTCEPOMBuilder()
Definition: LLVMTCEPOMBuilder.cc:67
POMDisassembler.hh
llvm::LLVMTCEPOMBuilder::doInitialization
bool doInitialization(Module &M)
Definition: LLVMTCEPOMBuilder.cc:184
TCEString.hh
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
UniversalMachine.hh
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::HWOperation::io
int io(const FUPort &port) const
Definition: HWOperation.cc:364
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
HWOperation.hh
llvm::createLLVMTCEPOMBuilderPass
MachineFunctionPass * createLLVMTCEPOMBuilderPass()
Definition: LLVMTCEPOMBuilder.cc:179
Instruction.hh
TTAProgram::CodeSnippet::add
virtual void add(Instruction *ins)
Definition: CodeSnippet.cc:432
Conversion.hh
llvm::LLVMTCEPOMBuilder
Definition: LLVMTCEPOMBuilder.hh:81
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
llvm::LLVMTCEPOMBuilder::ID
static char ID
Definition: LLVMTCEPOMBuilder.hh:83
LLVMTCEPOMBuilder.hh
TerminalFUPort.hh
Machine.hh
Exception
Definition: Exception.hh:54
TTAProgram::Program::universalMachine
UniversalMachine & universalMachine() const
Definition: Program.cc:104
llvm::LLVMTCEPOMBuilder::registerFileName
virtual TCEString registerFileName(unsigned llvmRegNum) const
Definition: LLVMTCEPOMBuilder.cc:82
TTAProgram::CodeSnippet
Definition: CodeSnippet.hh:59
TTAProgram::TerminalFUPort
Definition: TerminalFUPort.hh:56
llvm::LLVMTCEBuilder::doInitialization
bool doInitialization(Module &M)
Definition: LLVMTCEBuilder.cc:429
Program.hh
InterPassData.hh
llvm::LLVMTCEPOMBuilder::createFUTerminal
virtual TTAProgram::Terminal * createFUTerminal(const MachineOperand &) const
Definition: LLVMTCEPOMBuilder.cc:131
TCEString
Definition: TCEString.hh:53
FUPort.hh
ControlUnit.hh
llvm::LLVMTCEPOMBuilder::operationName
virtual TCEString operationName(const MachineInstr &mi) const
Definition: LLVMTCEPOMBuilder.cc:126
SpecialRegisterPort.hh
llvm::LLVMTCEPOMBuilder::registerIndex
virtual int registerIndex(unsigned llvmRegNum) const
Definition: LLVMTCEPOMBuilder.cc:90
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
Conversion::toInt
static int toInt(const T &source)
llvm::LLVMTCEBuilder
Definition: LLVMTCEBuilder.hh:102
llvm::LLVMTCEBuilder::targetMachine
const TargetMachine & targetMachine() const
Definition: LLVMTCEBuilder.hh:157
TTAProgram::Program::convertSymbolRefsToInsRefs
void convertSymbolRefsToInsRefs(bool ignoreUnfoundSymbols=false)
Definition: Program.cc:1264
llvm::LLVMTCEPOMBuilder::raPortDRegNum
virtual unsigned raPortDRegNum() const
Definition: LLVMTCEPOMBuilder.cc:77
llvm::LLVMTCEPOMBuilder::doFinalization
bool doFinalization(Module &m)
Definition: LLVMTCEPOMBuilder.cc:190
llvm::LLVMTCEPOMBuilder::emitMove
TTAProgram::Instruction * emitMove(const MachineInstr *mi, TTAProgram::CodeSnippet *proc, bool conditional=false, bool trueGuard=true)
Definition: LLVMTCEPOMBuilder.cc:98
llvm::LLVMTCEBuilder::createMove
std::shared_ptr< TTAProgram::Move > createMove(const MachineOperand &src, const MachineOperand &dst, TTAProgram::MoveGuard *guard)
Definition: LLVMTCEBuilder.cc:2389
TTAMachine::Machine::loadFromADF
static Machine * loadFromADF(const std::string &adfFileName)
Definition: Machine.cc:905