OpenASIP  2.0
TCETargetMachinePlugin.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2015 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 TCETargetMachinePlugin.hh
26  *
27  * Declaration of TCETargetMachinePlugin class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2007 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TCE_TARGET_MACHINE_PLUGIN_HH
34 #define TCE_TARGET_MACHINE_PLUGIN_HH
35 
36 #include <iostream>
37 
38 #include "tce_config.h"
39 
40 #define TCELE64DLString \
41  "E-p:64:64:64" \
42  "-a0:0:64" \
43  "-i1:8:8" \
44  "-i8:8:64" \
45  "-i16:16:64" \
46  "-i32:32:64" \
47  "-i64:64:64" \
48  "-f16:16:64" \
49  "-f32:32:64" \
50  "-f64:64:64" \
51  "-v64:64:64" \
52  "-v128:128:128" \
53  "-v256:256:256" \
54  "-v512:512:512" \
55  "-v1024:1024:1024" \
56  "-v2048:2048:2048" \
57  "-v4096:4096:4096"
58 
59 #define TCEBEDLString \
60  "E-p:32:32:32" \
61  "-a0:0:32" \
62  "-i1:8:8" \
63  "-i8:8:32" \
64  "-i16:16:32" \
65  "-i32:32:32" \
66  "-i64:32:32" \
67  "-f16:16:16" \
68  "-f32:32:32" \
69  "-f64:32:64" \
70  "-v64:32:64" \
71  "-v128:32:128" \
72  "-v512:32:512" \
73  "-v1024:32:1024"
74 
75 #include <llvm/IR/DataLayout.h>
76 #include <llvm/CodeGen/SelectionDAGTargetInfo.h>
77 
78 typedef llvm::DataLayout TargetData;
79 
80 #include "TCEString.hh"
81 
82 namespace llvm {
83  class MachineOperand;
84 }
85 
86 namespace TTAMachine {
87  class Machine;
88 }
89 
90 /**
91  * TCE target machine plugin interface.
92  */
93 namespace llvm {
94  class TargetInstrInfo;
95  class TCEInstrInfo;
96  class TargetLowering;
97  class TargetRegisterInfo;
98  class TargetFrameLowering;
99  class TargetSubtargetInfo;
100  class TargetTransformInfo;
101  class TCESubtarget;
102  class FunctionPass;
103  class TCETargetMachine;
104  class TargetRegisterClass;
105  class MachineInstr;
106  class SDNode;
107  struct EVT;
108 
110  public:
111  // TODO: why is here this default??
113  dl_(TCELE64DLString) {};
114  // this is overwritten anyway later
115 
117 
118  virtual const TargetInstrInfo* getInstrInfo() const = 0;
119  virtual const TargetRegisterInfo* getRegisterInfo() const = 0;
120  virtual const TargetFrameLowering* getFrameLowering() const = 0;
121  virtual TargetLowering* getTargetLowering() const = 0;
122  virtual const TargetSubtargetInfo* getSubtarget() const = 0;
123  virtual TargetTransformInfo getTargetTransformInfo(
124  const Function& F) const = 0;
125 
126  virtual FunctionPass* createISelPass(TCETargetMachine* tm) = 0;
127 
128  /// Returns name of the physical register file corresponding
129  /// to a generated register ID.
130  virtual std::string rfName(unsigned dwarfRegNum) = 0;
131 
132  /// Returns name of the physical register index corresponding
133  /// to a generated register ID.
134  virtual unsigned registerIndex(unsigned dwarfRegNum) = 0;
135 
136  /** Returns LLVM register ID corresponding to TTA register name.
137  *
138  * @param ttaRegister The name of the TTA register. For example "RF.5".
139  * @returns The register number if it exists in the target.
140  * Otherwise, returns TCE::NoRegister.
141  */
142  virtual unsigned llvmRegisterId(const TCEString& ttaRegister) = 0;
143 
144  /// Returns operation name corresponding to llvm target opcode.
145  virtual std::string operationName(unsigned opc) const = 0;
146  /// Returns true if OSAL operation is valid for stack accesses.
147  virtual bool validStackAccessOperation(
148  const std::string& opName) const = 0;
149  /// Returns true in case the target supports the given osal operation
150  virtual bool hasOperation(TCEString operationName) const = 0;
151  /// Returns the opcode for the given osal operation, undefined if not found.
152  virtual unsigned opcode(TCEString operationName) const = 0;
153  virtual unsigned int extractElementLane(const MachineInstr& mi) const = 0;
154 
155  virtual int getTruePredicateOpcode(unsigned opc) const = 0;
156  virtual int getFalsePredicateOpcode(unsigned opc) const = 0;
157 
158  /// Returns pointer to xml string of the target machine .adf
159  virtual const std::string* adfXML() = 0;
160  /// Returns name of the data address space.
161  virtual std::string dataASName() = 0;
162  /// Returns ID number of the return address register.
163  virtual unsigned raPortDRegNum() = 0;
164  /// Returns ID number of the stack pointer register.
165  virtual unsigned spDRegNum() = 0;
166  /// Returns ID number of the frame pointer register.
167  virtual unsigned fpDRegNum() = 0;
168 
169  virtual unsigned rvDRegNum() = 0;
170 
171  virtual unsigned rvHighDRegNum() = 0;
172 
173  virtual std::vector<unsigned> getParamDRegNums() const = 0;
174 
175  virtual std::vector<unsigned> getVectorRVDRegNums() const = 0;
176 
177  virtual bool hasUDIV() const = 0;
178  virtual bool hasSDIV() const = 0;
179  virtual bool hasUREM() const = 0;
180  virtual bool hasSREM() const = 0;
181  virtual bool hasMUL() const = 0;
182  virtual bool hasROTL() const = 0;
183  virtual bool hasROTR() const = 0;
184  virtual bool hasSXHW() const = 0;
185  virtual bool hasSXQW() const = 0;
186  virtual bool hasSQRTF() const = 0;
187  virtual bool hasSHR() const = 0;
188  virtual bool hasSHL() const = 0;
189  virtual bool hasSHRU() const = 0;
190 
191  virtual bool has8bitLoads() const = 0;
192  virtual bool has16bitLoads() const = 0;
193 
194  virtual int maxVectorSize() const = 0;
195  /// Plugin needs target machine for TragetLowering generation
196  virtual void registerTargetMachine(TCETargetMachine &tm) = 0;
197  // if not found, return -1;
198  virtual int getMinOpcode(llvm::SDNode* n) const = 0;
199  virtual int getMaxOpcode(llvm::SDNode* n) const = 0;
200  virtual int getMinuOpcode(llvm::SDNode* n) const = 0;
201  virtual int getMaxuOpcode(llvm::SDNode* n) const = 0;
202 
203  virtual int getLoad(const TargetRegisterClass *rc) const = 0;
204  virtual int getStore(const TargetRegisterClass *rc) const = 0;
205 
206  virtual int getLoadOpcode(const llvm::EVT& vt) const = 0;
207  // -1 or add opcode. Implementation generated to Backend.inc
208  virtual int getAddOpcode(const llvm::EVT& vt) const = 0;
209  // -1 or shl opcode. Implementation generated to Backend.inc
210  virtual int getShlOpcode(const llvm::EVT& vt) const = 0;
211  // -1 or ior opcode. Implementation generated to Backend.inc
212  virtual int getIorOpcode(const llvm::EVT& vt) const = 0;
213 
214  /// Clustered-TTA-subtemplate related methods.
215  virtual const llvm::TargetRegisterClass* extrasRegClass(
216  const llvm::TargetRegisterClass* current) const = 0;
217  virtual const llvm::TargetRegisterClass* nodeRegClass(
218  unsigned nodeId, const llvm::TargetRegisterClass* current) const = 0;
219 
220  virtual bool isLittleEndian() const = 0;
221  virtual bool is64bit() const = 0;
222 
223  virtual const DataLayout* getDataLayout() const {
224  return &dl_;
225  }
226 
227  virtual DataLayout* getDataLayout() {
228  return &dl_;
229  }
230 
232  return tm_;
233  }
234  virtual const TCETargetMachine* getCurrentTargetMachine() const {
235  return tm_;
236  }
237 
238  virtual bool analyzeCCBranch(
239  llvm::MachineInstr& i,
240  llvm::SmallVectorImpl<llvm::MachineOperand>& cond) const {
241  return true;
242  }
243 
244  virtual const SelectionDAGTargetInfo* getSelectionDAGInfo() const {
245  return &tsInfo_;
246  }
247 
248  // Implementation generated to Backend.inc
249  virtual bool canMaterializeConstant(const ConstantInt& ci) const = 0;
250 
251  virtual std::tuple<int, int> getPointerAdjustment(
252  int offset) const = 0;
253 
254  virtual MVT::SimpleValueType getDefaultType() const = 0;
255  protected:
256  /// Target machine instruction info for the llvm framework.
258  TargetLowering* lowering_;
259  TargetFrameLowering* frameInfo_;
262  DataLayout dl_; // Calculates type size & alignment
263  SelectionDAGTargetInfo tsInfo_;
264  };
265 
266 }
267 #endif
llvm::TCETargetMachinePlugin::registerIndex
virtual unsigned registerIndex(unsigned dwarfRegNum)=0
Returns name of the physical register index corresponding to a generated register ID.
llvm::TCETargetMachinePlugin::getStore
virtual int getStore(const TargetRegisterClass *rc) const =0
llvm::TCETargetMachinePlugin::getMaxuOpcode
virtual int getMaxuOpcode(llvm::SDNode *n) const =0
llvm
Definition: InlineAsmParser.hh:49
llvm::TCETargetMachinePlugin::subTarget_
TCESubtarget * subTarget_
Definition: TCETargetMachinePlugin.hh:261
llvm::TCETargetMachinePlugin::fpDRegNum
virtual unsigned fpDRegNum()=0
Returns ID number of the frame pointer register.
llvm::TCETargetMachinePlugin::hasSXHW
virtual bool hasSXHW() const =0
llvm::TCETargetMachinePlugin::extrasRegClass
virtual const llvm::TargetRegisterClass * extrasRegClass(const llvm::TargetRegisterClass *current) const =0
Clustered-TTA-subtemplate related methods.
llvm::TCETargetMachinePlugin::getMinuOpcode
virtual int getMinuOpcode(llvm::SDNode *n) const =0
llvm::TCETargetMachinePlugin::has8bitLoads
virtual bool has8bitLoads() const =0
llvm::TCETargetMachinePlugin::has16bitLoads
virtual bool has16bitLoads() const =0
llvm::TCETargetMachinePlugin::getLoadOpcode
virtual int getLoadOpcode(const llvm::EVT &vt) const =0
llvm::TCEInstrInfo
Definition: TCEInstrInfo.hh:57
llvm::TCETargetMachinePlugin::hasSQRTF
virtual bool hasSQRTF() const =0
llvm::TCETargetMachinePlugin::getFrameLowering
virtual const TargetFrameLowering * getFrameLowering() const =0
llvm::TCETargetMachinePlugin::extractElementLane
virtual unsigned int extractElementLane(const MachineInstr &mi) const =0
llvm::TCESubtarget
Definition: TCESubtarget.hh:56
llvm::TCETargetMachinePlugin::analyzeCCBranch
virtual bool analyzeCCBranch(llvm::MachineInstr &i, llvm::SmallVectorImpl< llvm::MachineOperand > &cond) const
Definition: TCETargetMachinePlugin.hh:238
llvm::TCETargetMachinePlugin::hasUREM
virtual bool hasUREM() const =0
llvm::TCETargetMachinePlugin::hasROTR
virtual bool hasROTR() const =0
llvm::TCETargetMachinePlugin::getMinOpcode
virtual int getMinOpcode(llvm::SDNode *n) const =0
llvm::TCETargetMachinePlugin::validStackAccessOperation
virtual bool validStackAccessOperation(const std::string &opName) const =0
Returns true if OSAL operation is valid for stack accesses.
llvm::TCETargetMachinePlugin::getSelectionDAGInfo
virtual const SelectionDAGTargetInfo * getSelectionDAGInfo() const
Definition: TCETargetMachinePlugin.hh:244
llvm::TCETargetMachinePlugin::getIorOpcode
virtual int getIorOpcode(const llvm::EVT &vt) const =0
llvm::TCETargetMachinePlugin::getMaxOpcode
virtual int getMaxOpcode(llvm::SDNode *n) const =0
llvm::TCETargetMachinePlugin::getTargetTransformInfo
virtual TargetTransformInfo getTargetTransformInfo(const Function &F) const =0
llvm::TCETargetMachinePlugin::tm_
TCETargetMachine * tm_
Definition: TCETargetMachinePlugin.hh:260
llvm::TCETargetMachinePlugin::nodeRegClass
virtual const llvm::TargetRegisterClass * nodeRegClass(unsigned nodeId, const llvm::TargetRegisterClass *current) const =0
llvm::TCETargetMachinePlugin::getSubtarget
virtual const TargetSubtargetInfo * getSubtarget() const =0
llvm::TCETargetMachinePlugin::registerTargetMachine
virtual void registerTargetMachine(TCETargetMachine &tm)=0
Plugin needs target machine for TragetLowering generation.
llvm::TCETargetMachinePlugin::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const =0
llvm::TCETargetMachinePlugin::hasUDIV
virtual bool hasUDIV() const =0
llvm::TCETargetMachinePlugin::getTargetLowering
virtual TargetLowering * getTargetLowering() const =0
llvm::TCETargetMachinePlugin::adfXML
virtual const std::string * adfXML()=0
Returns pointer to xml string of the target machine .adf.
llvm::TCETargetMachinePlugin::isLittleEndian
virtual bool isLittleEndian() const =0
TCEString.hh
llvm::TCETargetMachinePlugin::hasROTL
virtual bool hasROTL() const =0
llvm::TCETargetMachinePlugin::~TCETargetMachinePlugin
virtual ~TCETargetMachinePlugin()
Definition: TCETargetMachinePlugin.hh:116
TCELE64DLString
#define TCELE64DLString
Definition: TCETargetMachinePlugin.hh:40
llvm::TCETargetMachinePlugin::spDRegNum
virtual unsigned spDRegNum()=0
Returns ID number of the stack pointer register.
llvm::TCETargetMachinePlugin::hasSREM
virtual bool hasSREM() const =0
llvm::TCETargetMachinePlugin::hasSHL
virtual bool hasSHL() const =0
llvm::TCETargetMachinePlugin::getFalsePredicateOpcode
virtual int getFalsePredicateOpcode(unsigned opc) const =0
llvm::TCETargetMachinePlugin::raPortDRegNum
virtual unsigned raPortDRegNum()=0
Returns ID number of the return address register.
llvm::TCETargetMachinePlugin::is64bit
virtual bool is64bit() const =0
llvm::TCETargetMachinePlugin::dl_
DataLayout dl_
Definition: TCETargetMachinePlugin.hh:262
llvm::TCETargetMachinePlugin::getCurrentTargetMachine
virtual const TCETargetMachine * getCurrentTargetMachine() const
Definition: TCETargetMachinePlugin.hh:234
llvm::TCETargetMachinePlugin::opcode
virtual unsigned opcode(TCEString operationName) const =0
Returns the opcode for the given osal operation, undefined if not found.
llvm::TCETargetMachinePlugin::frameInfo_
TargetFrameLowering * frameInfo_
Definition: TCETargetMachinePlugin.hh:259
llvm::TCETargetMachinePlugin::tsInfo_
SelectionDAGTargetInfo tsInfo_
Definition: TCETargetMachinePlugin.hh:263
llvm::TCETargetMachinePlugin::getParamDRegNums
virtual std::vector< unsigned > getParamDRegNums() const =0
llvm::TCETargetMachinePlugin::hasSXQW
virtual bool hasSXQW() const =0
llvm::TCETargetMachinePlugin::TCETargetMachinePlugin
TCETargetMachinePlugin()
Definition: TCETargetMachinePlugin.hh:112
llvm::TCETargetMachinePlugin::hasSHRU
virtual bool hasSHRU() const =0
llvm::TCETargetMachinePlugin::hasSDIV
virtual bool hasSDIV() const =0
llvm::TCETargetMachinePlugin::getAddOpcode
virtual int getAddOpcode(const llvm::EVT &vt) const =0
llvm::TCETargetMachinePlugin::maxVectorSize
virtual int maxVectorSize() const =0
llvm::TCETargetMachinePlugin::getLoad
virtual int getLoad(const TargetRegisterClass *rc) const =0
llvm::TCETargetMachinePlugin::rvDRegNum
virtual unsigned rvDRegNum()=0
llvm::TCETargetMachinePlugin::rfName
virtual std::string rfName(unsigned dwarfRegNum)=0
Returns name of the physical register file corresponding to a generated register ID.
llvm::TCETargetMachinePlugin::hasOperation
virtual bool hasOperation(TCEString operationName) const =0
Returns true in case the target supports the given osal operation.
llvm::TCETargetMachinePlugin::lowering_
TargetLowering * lowering_
Definition: TCETargetMachinePlugin.hh:258
llvm::TCETargetMachinePlugin
Definition: TCETargetMachinePlugin.hh:109
llvm::TCETargetMachinePlugin::getDataLayout
virtual const DataLayout * getDataLayout() const
Definition: TCETargetMachinePlugin.hh:223
llvm::TCETargetMachinePlugin::rvHighDRegNum
virtual unsigned rvHighDRegNum()=0
llvm::TCETargetMachinePlugin::getPointerAdjustment
virtual std::tuple< int, int > getPointerAdjustment(int offset) const =0
llvm::TCETargetMachinePlugin::getCurrentTargetMachine
virtual TCETargetMachine * getCurrentTargetMachine()
Definition: TCETargetMachinePlugin.hh:231
llvm::TCETargetMachinePlugin::getDefaultType
virtual MVT::SimpleValueType getDefaultType() const =0
llvm::TCETargetMachinePlugin::canMaterializeConstant
virtual bool canMaterializeConstant(const ConstantInt &ci) const =0
llvm::TCETargetMachinePlugin::getShlOpcode
virtual int getShlOpcode(const llvm::EVT &vt) const =0
llvm::TCETargetMachinePlugin::getTruePredicateOpcode
virtual int getTruePredicateOpcode(unsigned opc) const =0
TCEString
Definition: TCEString.hh:53
llvm::TCETargetMachinePlugin::hasMUL
virtual bool hasMUL() const =0
llvm::TCETargetMachinePlugin::hasSHR
virtual bool hasSHR() const =0
llvm::TCETargetMachine
Definition: TCETargetMachine.hh:106
TTAMachine
Definition: Assembler.hh:48
llvm::TCETargetMachinePlugin::getVectorRVDRegNums
virtual std::vector< unsigned > getVectorRVDRegNums() const =0
TargetData
llvm::DataLayout TargetData
Definition: TCETargetMachinePlugin.hh:78
llvm::TCETargetMachinePlugin::operationName
virtual std::string operationName(unsigned opc) const =0
Returns operation name corresponding to llvm target opcode.
llvm::TCETargetMachinePlugin::createISelPass
virtual FunctionPass * createISelPass(TCETargetMachine *tm)=0
llvm::TCETargetMachinePlugin::dataASName
virtual std::string dataASName()=0
Returns name of the data address space.
llvm::TCETargetMachinePlugin::instrInfo_
TCEInstrInfo * instrInfo_
Target machine instruction info for the llvm framework.
Definition: TCETargetMachinePlugin.hh:257
llvm::TCETargetMachinePlugin::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const =0
llvm::TCETargetMachinePlugin::getDataLayout
virtual DataLayout * getDataLayout()
Definition: TCETargetMachinePlugin.hh:227
llvm::TCETargetMachinePlugin::llvmRegisterId
virtual unsigned llvmRegisterId(const TCEString &ttaRegister)=0