OpenASIP 2.2
Loading...
Searching...
No Matches
TCETargetMachine.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 TCETargetMachine.h
26 *
27 * Declaration of TCETargetMachine class.
28 *
29 * @author Veli-Pekka J��skel�inen 2007 (vjaaskel-no.spam-cs.tut.fi)
30 * @author Mikael Lepist� 2009 (mikael.lepisto-no.spam-tut.fi)
31 */
32
33#ifndef TCE_TARGET_MACHINE_H
34#define TCE_TARGET_MACHINE_H
35
36#include <set>
37
38#include "tce_config.h"
39#include "CompilerWarnings.hh"
40
41IGNORE_COMPILER_WARNING("-Wunused-parameter")
42
43#include "llvm/CodeGen/TargetLowering.h"
44#include "llvm/CodeGen/TargetFrameLowering.h"
45#include "llvm/Analysis/TargetTransformInfo.h"
46#include "llvm/Target/TargetMachine.h"
47#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
48
49#include "llvm/IR/PassManager.h"
50//#include "TCESubtarget.hh"
51
54// tce_config.h defines these. this undef to avoid warning.
55// TODO: how to do this in tce_config.h???
56#ifdef LLVM_LIBDIR
57#undef LLVM_LIBDIR
58#endif
59
60
61#include "llvm/CodeGen/Passes.h"
62#include "llvm/IR/DataLayout.h"
63
64#include "llvm/CodeGen/TargetPassConfig.h"
65
67
68namespace TTAMachine {
69 class Machine;
70}
71
72class PipelineableLoopFinder;
73
74class PluginTools;
75
76
77// just to be able to manually register tce target if needed.
78extern "C" void LLVMInitializeTCETarget();
79
80namespace llvm {
81 class TCEPassConfig : public TargetPassConfig {
82 public:
84 LLVMTargetMachine* tm,
85 PassManagerBase& pm,
86 TCETargetMachinePlugin* plugin) :
87 TargetPassConfig(*tm, pm),
88plugin_(plugin) {
89 assert(plugin_ != NULL);
90 }
91
92 virtual bool addPreISel();
93 virtual bool addInstSelector();
94
95 virtual void addPreRegAlloc();
96 virtual void addPreSched2();
97
99 };
100
101 class Module;
102
103 /**
104 * TCE Universal machine target description.
105 */
107
108 public:
110 const Target &T, const Triple& TTriple,
111 const llvm::StringRef& CPU, const llvm::StringRef& FS,
112 const TargetOptions &Options,
113 #ifdef LLVM_OLDER_THAN_16
114 Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
115 #else
116 std::optional<Reloc::Model> RM, std::optional<CodeModel::Model> CM,
117 #endif
118 CodeGenOpt::Level OL, bool isLittle);
119
120 virtual ~TCETargetMachine();
121
122 virtual void setTargetMachinePlugin(
124 virtual TCETargetMachinePlugin& targetPlugin() const { return *plugin_; }
125
126 /**
127 * These two parameter passing should be rethought... maybe TTAMach can be avoided
128 * by changing pass to use plugin_ instead.
129 */
131 virtual void setEmulationModule(Module* mod) {
132 emulationModule_ = mod;
133 }
134
135 virtual void setTTAMach(
136 const TTAMachine::Machine* mach) override {
139 }
140
141 virtual const TTAMachine::Machine& ttaMachine() const {
142 return *ttaMach_;
143 }
144
145
146 // This method is only in llvm < 3.7, but keep this here to
147 // allow calling this ourselves.
148 virtual const TCESubtarget* getSubtargetImpl() const {
149 // compiler does not know it's derived without the plugin,
150 // but this class cannow include the plugin.
151 return reinterpret_cast<const TCESubtarget*>(plugin_->getSubtarget());
152 }
153
154 virtual const TargetSubtargetInfo* getSubtargetImpl(const Function&) const override {
155 return plugin_->getSubtarget();
156 }
157
158 virtual const TargetInstrInfo* getInstrInfo() const {
159 return plugin_->getInstrInfo();
160 }
161
162 virtual const TargetRegisterInfo* getRegisterInfo() const {
163 return plugin_->getRegisterInfo();
164 }
165
166 virtual const DataLayout* getDataLayout() const {
167 return plugin_->getDataLayout();
168 }
169
170 virtual const TargetFrameLowering* getFrameLowering() const {
171 return plugin_->getFrameLowering();
172 }
173 virtual TargetLowering* getTargetLowering() const {
174 return plugin_->getTargetLowering();
175 }
176
177 virtual TargetPassConfig *createPassConfig(
178 PassManagerBase &PM) override;
179
180 #ifdef LLVM_OLDER_THAN_15
181 TargetTransformInfo
182 getTargetTransformInfo(const Function& F) override {
184 }
185 #else
186 TargetTransformInfo
187 getTargetTransformInfo(const Function& F) const override {
189 }
190 #endif
191
192 std::string operationName(unsigned opc) const {
193 return plugin_->operationName(opc);
194 }
195
196 /**
197 * Returns true if LLVM opcode if valid for stack variable accesses.
198 *
199 */
200 bool validStackAccessOperation(const std::string& opName) const {
201 return plugin_->validStackAccessOperation(opName);
202 }
203
207
208 std::string rfName(unsigned dwarfRegNum) const {
209 return plugin_->rfName(dwarfRegNum);
210 }
211
212 unsigned registerIndex(unsigned dwarfRegNum) const {
213 return plugin_->registerIndex(dwarfRegNum);
214 }
215
216 /**
217 * Returns full name of the register.
218 *
219 */
220 std::string registerName(unsigned dwarfRegNum) const {
221 return rfName(dwarfRegNum) + "."
222 + std::to_string(registerIndex(dwarfRegNum));
223 }
224
225 unsigned llvmRegisterId(const TCEString& ttaRegister) {
226 return plugin_->llvmRegisterId(ttaRegister);
227 }
228
230
231 std::string dataASName() {
232 return plugin_->dataASName();
233 }
234
235 unsigned raPortDRegNum() const {
236 return plugin_->raPortDRegNum();
237 }
238
240
241 unsigned spDRegNum() const {
242 return plugin_->spDRegNum();
243 }
244
247 }
248
249 int getMinOpcode(llvm::SDNode* n) {
250 return plugin_->getMinOpcode(n);
251 }
252
253 int getMinuOpcode(llvm::SDNode* n) {
254 return plugin_->getMinuOpcode(n);
255 }
256
257 int getMaxOpcode(llvm::SDNode* n) {
258 return plugin_->getMaxOpcode(n);
259 }
260
261 int getMaxuOpcode(llvm::SDNode* n) {
262 return plugin_->getMaxuOpcode(n);
263 }
264
265 int getAddOpcode(const llvm::EVT& vt) const {
266 return plugin_->getAddOpcode(vt);
267 }
268
269 int getShlOpcode(const llvm::EVT& vt) const {
270 return plugin_->getShlOpcode(vt);
271 }
272
273 int getIorOpcode(const llvm::EVT& vt) const {
274 return plugin_->getIorOpcode(vt);
275 }
276
277 void setStackAlignment(unsigned align) {
278 stackAlignment_ = align;
279 }
280
281 unsigned stackAlignment() const {
282 if (stackAlignment_ == 0) {
283 std::cerr << "ZERO STACK ALIGN\n";
284 abort();
285 }
287 return stackAlignment_;
288 }
289
290 bool has8bitLoads() const {
291 return plugin_->has8bitLoads();
292 }
293
294 bool has16bitLoads() const {
295 return plugin_->has16bitLoads();
296 }
297
298 int bitness() const {
299 return plugin_->is64bit() ? 64 : 32;
300 }
301
302 const std::set<
303 std::pair<unsigned,
304 llvm::MVT::SimpleValueType> >* missingOperations();
305
306 const std::set<
307 std::pair<unsigned,
308 llvm::MVT::SimpleValueType> >* promotedOperations();
309
310 const std::set<
311 std::pair<unsigned,
312 llvm::MVT::SimpleValueType> >* customLegalizedOperations();
313
314 int64_t smallestImmValue() const {
315 assert(ttaMach_ && "setTargetMachinePlugin() was not called");
316 return smallestImm_;
317 }
318 uint64_t largestImmValue() const {
319 assert(ttaMach_ && "setTargetMachinePlugin() was not called");
320 return largestImm_;
321 }
322 bool canEncodeAsMOVI(const llvm::MVT& vt, int64_t val) const;
323 bool canEncodeAsMOVF(const llvm::APFloat& fp) const;
324
325 bool canMaterializeConstant(const ConstantInt& ci) const {
327 }
328
329 int getLoadOpcode(int asid, int align, const llvm::EVT& vt) const;
330
331 private:
332 /* more or less llvm naming convention to make it easier to track llvm changes */
333
336 /// llvm::ISD opcode list of operations that have to be expanded.
337 std::set<std::pair<unsigned, llvm::MVT::SimpleValueType> > missingOps_;
338 std::set<std::pair<unsigned, llvm::MVT::SimpleValueType> > promotedOps_;
339 std::set<std::pair<unsigned, llvm::MVT::SimpleValueType> > customLegalizedOps_;
340
342
343 int64_t smallestImm_ = std::numeric_limits<int64_t>::max();
344 uint64_t largestImm_ = std::numeric_limits<int64_t>::min();
345 int SupportedFPImmWidth_ = std::numeric_limits<int>::min();
346 // The stack alignment. Note: this should be overridden per
347 // generated Module if the Module requires a larger one.
349 };
350}
351
352#endif
#define assert(condition)
#define IGNORE_COMPILER_WARNING(X)
#define POP_COMPILER_DIAGS
void LLVMInitializeTCETarget()
const TTAMachine::Machine * ttaMach_
virtual void setTTAMach(const TTAMachine::Machine *mach)
TCEPassConfig(LLVMTargetMachine *tm, PassManagerBase &pm, TCETargetMachinePlugin *plugin)
TCETargetMachinePlugin * plugin_
virtual void addPreSched2()
virtual bool addInstSelector()
virtual bool addPreISel()
virtual void addPreRegAlloc()
virtual int getMinuOpcode(llvm::SDNode *n) const =0
virtual bool validStackAccessOperation(const std::string &opName) const =0
Returns true if OSAL operation is valid for stack accesses.
virtual const TargetFrameLowering * getFrameLowering() const =0
virtual TargetLowering * getTargetLowering() const =0
virtual int getMaxOpcode(llvm::SDNode *n) const =0
virtual bool is64bit() const =0
virtual bool has16bitLoads() const =0
virtual const TargetRegisterInfo * getRegisterInfo() const =0
virtual std::string dataASName()=0
Returns name of the data address space.
virtual const TargetInstrInfo * getInstrInfo() const =0
virtual unsigned opcode(TCEString operationName) const =0
Returns the opcode for the given osal operation, undefined if not found.
virtual bool canMaterializeConstant(const ConstantInt &ci) const =0
virtual std::string operationName(unsigned opc) const =0
Returns operation name corresponding to llvm target opcode.
virtual int getAddOpcode(const llvm::EVT &vt) const =0
virtual std::string rfName(unsigned dwarfRegNum)=0
Returns name of the physical register file corresponding to a generated register ID.
virtual int getShlOpcode(const llvm::EVT &vt) const =0
virtual const TargetSubtargetInfo * getSubtarget() const =0
virtual const DataLayout * getDataLayout() const
virtual int getMinOpcode(llvm::SDNode *n) const =0
virtual unsigned registerIndex(unsigned dwarfRegNum)=0
Returns name of the physical register index corresponding to a generated register ID.
virtual bool hasOperation(TCEString operationName) const =0
Returns true in case the target supports the given osal operation.
virtual bool has8bitLoads() const =0
virtual TargetTransformInfo getTargetTransformInfo(const Function &F) const =0
virtual unsigned raPortDRegNum()=0
Returns ID number of the return address register.
virtual unsigned llvmRegisterId(const TCEString &ttaRegister)=0
virtual unsigned spDRegNum()=0
Returns ID number of the stack pointer register.
virtual int getIorOpcode(const llvm::EVT &vt) const =0
virtual int getMaxuOpcode(llvm::SDNode *n) const =0
virtual const TCESubtarget * getSubtargetImpl() const
bool canMaterializeConstant(const ConstantInt &ci) const
const std::set< std::pair< unsigned, llvm::MVT::SimpleValueType > > * customLegalizedOperations()
std::string operationName(unsigned opc) const
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
virtual const TargetFrameLowering * getFrameLowering() const
virtual TargetLowering * getTargetLowering() const
virtual const DataLayout * getDataLayout() const
int getAddOpcode(const llvm::EVT &vt) const
virtual const TTAMachine::Machine & ttaMachine() const
virtual TCETargetMachinePlugin & targetPlugin() const
const std::set< std::pair< unsigned, llvm::MVT::SimpleValueType > > * missingOperations()
virtual void setEmulationModule(Module *mod)
unsigned raPortDRegNum() const
bool validStackAccessOperation(const std::string &opName) const
int getMaxOpcode(llvm::SDNode *n)
void setStackAlignment(unsigned align)
virtual void setTTAMach(const TTAMachine::Machine *mach) override
virtual TargetPassConfig * createPassConfig(PassManagerBase &PM) override
TTAMachine::Machine * createMachine()
int getMinuOpcode(llvm::SDNode *n)
int getIorOpcode(const llvm::EVT &vt) const
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const override
bool canEncodeAsMOVI(const llvm::MVT &vt, int64_t val) const
int getLoadOpcode(int asid, int align, const llvm::EVT &vt) const
int getMinOpcode(llvm::SDNode *n)
virtual const TargetRegisterInfo * getRegisterInfo() const
int64_t smallestImmValue() const
unsigned llvmRegisterId(const TCEString &ttaRegister)
std::set< std::pair< unsigned, llvm::MVT::SimpleValueType > > promotedOps_
std::string registerName(unsigned dwarfRegNum) const
std::string rfName(unsigned dwarfRegNum) const
int getShlOpcode(const llvm::EVT &vt) const
int getMaxuOpcode(llvm::SDNode *n)
bool canEncodeAsMOVF(const llvm::APFloat &fp) const
bool hasOperation(TCEString operationName) const
virtual void setTargetMachinePlugin(TCETargetMachinePlugin &plugin, TTAMachine::Machine &target)
unsigned opcode(TCEString operationName) const
std::set< std::pair< unsigned, llvm::MVT::SimpleValueType > > customLegalizedOps_
TCETargetMachinePlugin * plugin_
std::set< std::pair< unsigned, llvm::MVT::SimpleValueType > > missingOps_
llvm::ISD opcode list of operations that have to be expanded.
unsigned registerIndex(unsigned dwarfRegNum) const
const std::set< std::pair< unsigned, llvm::MVT::SimpleValueType > > * promotedOperations()
unsigned stackAlignment() const
uint64_t largestImmValue() const
virtual const TargetInstrInfo * getInstrInfo() const