OpenASIP  2.0
LLVMBackend.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2021 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 LLVMBackend.cc
26  *
27  * TCE runtime retargeting compiler backend.
28  *
29  * @author Veli-Pekka Jääskeläinen 2008 (vjaaskel-no.spam-cs.tut.fi)
30  * @author Mikael Lepistö 2009 (mikael.lepisto-no.spam-tut.fi)
31  * @author Pekka Jääskeläinen 2009-2021
32  * @note rating: red
33  */
34 
35 #ifdef NDEBUG
36 #undef NDEBUG
37 #endif
38 #include "CompilerWarnings.hh"
39 IGNORE_COMPILER_WARNING("-Wunused-parameter")
40 IGNORE_COMPILER_WARNING("-Wcomment")
41 
42 #include <llvm/Analysis/LoopInfo.h>
43 #include <llvm/Analysis/LoopPass.h>
44 
45 #include "tce_config.h"
46 #include <llvm/IR/Dominators.h>
47 
48 #include <llvm/Analysis/AliasAnalysis.h>
49 #include <llvm/IR/LegacyPassManager.h>
50 #include <llvm/Pass.h>
51 
52 #include <llvm/CodeGen/AsmPrinter.h>
53 #include <llvm/CodeGen/Passes.h>
54 
55 #include <llvm/Target/TargetMachine.h>
56 #include <llvm/Target/TargetOptions.h>
57 
58 #include <llvm/Transforms/IPO.h>
59 #include <llvm/Transforms/Scalar.h>
60 
61 #include <llvm/Support/CommandLine.h>
62 #include <llvm/Support/FormattedStream.h>
63 #include <llvm/Support/MemoryBuffer.h>
64 #include <llvm/Support/Debug.h>
65 #include <llvm/CodeGen/RegAllocRegistry.h>
66 #include "Application.hh"
67 #include <llvm/IR/Module.h>
68 #include <llvm/IR/LLVMContext.h>
69 
70 #include <llvm/Bitcode/BitcodeReader.h>
71 
72 #include <llvm/IR/Verifier.h>
73 
74 #include <llvm/IR/GCStrategy.h>
75 
76 #include <llvm-c/Core.h> // LLVMGetGlobalContext()
77 
78 // tce_config.h defines these. this undef to avoid warning.
79 // TODO: how to do this in tce_config.h???
80 #ifdef LLVM_LIBDIR
81 #undef LLVM_LIBDIR
82 #endif
83 #include "tce_config.h" // to get llvm version
84 
85 #include "llvm/MC/TargetRegistry.h"
86 
87 #include "llvm/Support/FileSystem.h"
88 
89 #include <llvm/InitializePasses.h>
90 
91 // cheat llvm's multi-include-protection
92 #define CONFIG_H
93 
94 #include <cstdlib> // system()
95 #include <fstream>
96 
97 #include "LLVMBackend.hh"
98 #include "LLVMTCECmdLineOptions.hh"
99 #include "TDGen.hh"
100 
101 #include "passes/InnerLoopFinder.hh"
102 #include "Environment.hh"
103 #include "Conversion.hh"
104 #include "FileSystem.hh"
105 #include "TCETargetMachine.hh"
106 #include "TCEStubTargetMachine.hh"
107 #include "TCETargetMachinePlugin.hh"
108 #include "LLVMPOMBuilder.hh"
109 #include "Program.hh"
110 #include "ADFSerializer.hh"
111 #include "MachineValidator.hh"
113 #include "Instruction.hh"
114 #include "ProgramAnnotation.hh"
115 #include "TCEString.hh"
116 #include "InterPassData.hh"
117 #include "InterPassDatum.hh"
118 #include "LLVMTCEIRBuilder.hh"
119 #include "Machine.hh"
120 #include "MachineInfo.hh"
121 #include "ConstantTransformer.hh"
122 //#define DEBUG_TDGEN
123 
124 #define DS TCEString(FileSystem::DIRECTORY_SEPARATOR)
125 
126 using namespace llvm;
127 
128 #include <llvm/IR/IRPrintingPasses.h>
129 
130 #include "llvm/IR/DataLayout.h"
131 typedef llvm::DataLayout TargetData;
132 
134 
135 const std::string LLVMBackend::TBLGEN_INCLUDES = "";
136 const std::string LLVMBackend::PLUGIN_PREFIX = "tcecc-";
137 const std::string LLVMBackend::PLUGIN_SUFFIX = ".so";
138 const TCEString LLVMBackend::CXX0X_FLAG = "-std=c++0x";
139 const TCEString LLVMBackend::CXX11_FLAG = "-std=c++11";
140 const TCEString LLVMBackend::CXX14_FLAG = "-std=c++14";
141 
143 
144 /**
145  * Returns minimum opset that is required by llvm.
146  *
147  * @return Minimumn opset that is required for llvm.
148  */
150 LLVMBackend::llvmRequiredOpset(bool includeFloatOps, bool littleEndian, bool bits64) {
152 
153  if (littleEndian) {
154  requiredOps.insert("LD32");
155  requiredOps.insert("LD16");
156  requiredOps.insert("LDU16");
157  requiredOps.insert("LD8");
158  requiredOps.insert("LDU8");
159  requiredOps.insert("ST32");
160  requiredOps.insert("ST16");
161  requiredOps.insert("ST8");
162  } else {
163  requiredOps.insert("LDW");
164  requiredOps.insert("LDH");
165  requiredOps.insert("LDHU");
166  requiredOps.insert("LDQ");
167  requiredOps.insert("LDQU");
168  requiredOps.insert("STW");
169  requiredOps.insert("STH");
170  requiredOps.insert("STQ");
171  }
172 
173  // -- Floating point operations --
174  if (includeFloatOps) {
175  requiredOps.insert("ADDF");
176  requiredOps.insert("SUBF");
177  requiredOps.insert("MULF");
178  requiredOps.insert("DIVF");
179  requiredOps.insert("NEGF");
180  requiredOps.insert("SQRTF");
181 
182  requiredOps.insert("CFI");
183  requiredOps.insert("CFIU");
184  requiredOps.insert("CIF");
185  requiredOps.insert("CIFU");
186 
187  // Ordered FP comparison operations
188  requiredOps.insert("EQF");
189  requiredOps.insert("NEF");
190  requiredOps.insert("LTF");
191  requiredOps.insert("LEF");
192  requiredOps.insert("GTF");
193  requiredOps.insert("GEF");
194 
195  // Unordered FP comparison operations
196  requiredOps.insert("EQUF");
197  requiredOps.insert("NEUF");
198  requiredOps.insert("LTUF");
199  requiredOps.insert("LEUF");
200  requiredOps.insert("GTUF");
201  requiredOps.insert("GEUF");
202 
203  // Ordered/unordered operations
204  requiredOps.insert("ORDF");
205  requiredOps.insert("UORDF");
206 
207  if (bits64) {
208  requiredOps.insert("ADDD");
209  requiredOps.insert("SUBD");
210  requiredOps.insert("MULD");
211  requiredOps.insert("DIVD");
212  requiredOps.insert("NEGD");
213  requiredOps.insert("SQRTD");
214 
215  requiredOps.insert("CDL");
216  requiredOps.insert("CDLU");
217  requiredOps.insert("CLD");
218  requiredOps.insert("CLDU");
219 
220  requiredOps.insert("CFD");
221  requiredOps.insert("CDF");
222 
223  // Ordered FP comparison operations
224  requiredOps.insert("EQD");
225  requiredOps.insert("NED");
226  requiredOps.insert("LTD");
227  requiredOps.insert("LED");
228  requiredOps.insert("GTD");
229  requiredOps.insert("GED");
230 
231  // Unordered FP comparison operations
232  requiredOps.insert("EQUD");
233  requiredOps.insert("NEUD");
234  requiredOps.insert("LTUD");
235  requiredOps.insert("LEUD");
236  requiredOps.insert("GTUD");
237  requiredOps.insert("GEUD");
238 
239  // Ordered/unordered operations
240  requiredOps.insert("ORDD");
241  requiredOps.insert("UORDD");
242  }
243  }
244 
245  if (bits64) {
246  requiredOps.insert("LDU32"); // TODO not really needed?
247  requiredOps.insert("LD64");
248  requiredOps.insert("ST64");
249 
250  requiredOps.insert("ADD64");
251  requiredOps.insert("SUB64");
252  requiredOps.insert("MUL64");
253  requiredOps.insert("DIV64");
254  requiredOps.insert("DIVU64");
255  requiredOps.insert("DIV64");
256  requiredOps.insert("MOD64");
257  requiredOps.insert("MODU64");
258 
259  requiredOps.insert("SXH64");
260  requiredOps.insert("SXQ64");
261 
262  requiredOps.insert("AND64");
263  requiredOps.insert("XOR64");
264  requiredOps.insert("IOR64");
265 
266  requiredOps.insert("SHL64");
267  requiredOps.insert("SHR64");
268  requiredOps.insert("SHRU64");
269 
270  requiredOps.insert("EQ64");
271  requiredOps.insert("NE64");
272  requiredOps.insert("LT64");
273  requiredOps.insert("LTU64");
274  requiredOps.insert("LE64");
275  requiredOps.insert("LEU64");
276  requiredOps.insert("GT64");
277  requiredOps.insert("GTU64");
278  requiredOps.insert("GE64");
279  requiredOps.insert("GEU64");
280 
281  return requiredOps;
282  } else {
283  requiredOps.insert("ADD");
284  requiredOps.insert("SUB");
285  requiredOps.insert("MUL");
286  requiredOps.insert("DIV");
287  requiredOps.insert("DIVU");
288  requiredOps.insert("DIV");
289  requiredOps.insert("MOD");
290  requiredOps.insert("MODU");
291 
292  requiredOps.insert("SXHW");
293  requiredOps.insert("SXQW");
294 
295  requiredOps.insert("AND");
296  requiredOps.insert("XOR");
297  requiredOps.insert("IOR");
298 
299  requiredOps.insert("SHL");
300  requiredOps.insert("SHR");
301  requiredOps.insert("SHRU");
302 
303  requiredOps.insert("EQ");
304  requiredOps.insert("NE");
305  requiredOps.insert("LT");
306  requiredOps.insert("LTU");
307  requiredOps.insert("LE");
308  requiredOps.insert("LEU");
309  requiredOps.insert("GT");
310  requiredOps.insert("GTU");
311  requiredOps.insert("GE");
312  requiredOps.insert("GEU");
313  }
314  return requiredOps;
315 }
316 /**
317  * Constructor.
318  *
319  * @param useInstalledVersion Should be true in case we are running an
320  * installed TCE (not from the source/build tree).
321  * @param tempDir An existing directory where to store temporary files.
322  * The directory should be removed by the caller after use.
323  */
324 LLVMBackend::LLVMBackend(bool useInstalledVersion, TCEString tempDir) :
325  useInstalledVersion_(useInstalledVersion), tempDir_(tempDir) {
326 
328 
329  options_ =
331 
332  if (options_ != NULL)
334 
335  PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
336  llvm::initializeCore(Registry);
337  llvm::initializeScalarOpts(Registry);
338  llvm::initializeIPO(Registry);
339  llvm::initializeAnalysis(Registry);
340  llvm::initializeTransformUtils(Registry);
341  llvm::initializeInstCombine(Registry);
342  llvm::initializeTarget(Registry);
343 }
344 
345 /**
346  * Destructor.
347  */
349 }
350 
351 /**
352  * Compiles bytecode for the given target machine.
353  *
354  * @param bytecodeFile Full path to the llvm bytecode file to compile.
355  * @param target Target machine to compile the bytecode for.
356  * @param optLevel Optimization level.
357  * @param debug If true, enable LLVM debug printing.
358  */
361  const std::string& bytecodeFile, const std::string& emulationBytecodeFile,
362  TTAMachine::Machine& target, int optLevel, bool debug,
363  InterPassData* ipData) {
364  // Check target machine
365  MachineValidator validator(target);
366  std::set<MachineValidator::ErrorCode> checks;
367  checks.insert(MachineValidator::GCU_MISSING);
368  checks.insert(MachineValidator::GCU_AS_MISSING);
370  checks.insert(MachineValidator::PC_PORT_MISSING);
371  checks.insert(MachineValidator::RA_PORT_MISSING);
372  checks.insert(MachineValidator::FU_PORT_MISSING);
373  MachineValidatorResults* res = validator.validate(checks);
374 
375  if (res->errorCount() > 0) {
376  std::string msg;
377  for (int i = 0; i < res->errorCount(); i++) {
378  msg += res->error(i).second + "\n";
379  }
380  delete res; res = NULL;
381  throw CompileError(__FILE__, __LINE__, __func__, msg);
382  }
383 
384  // Load bytecode file.
385  std::string errMsgParse;
386  LLVMContext context;
387 
388  std::unique_ptr<llvm::Module> m;
389 
390  ErrorOr<std::unique_ptr<MemoryBuffer>> bufferPtr =
391  MemoryBuffer::getFileOrSTDIN(bytecodeFile.c_str());
392 
393  if (std::error_code ec = bufferPtr.getError()) {
394  std::string msg = "Error reading bytecode file: " + bytecodeFile +
395  "\n" + ec.message();
396  throw CompileError(__FILE__, __LINE__, __func__, msg);
397  }
398 
399  // todo: what are these buffers..
400  std::unique_ptr<MemoryBuffer> buffer = std::move(bufferPtr.get());
401  Expected<std::unique_ptr<llvm::Module> > module =
402  parseBitcodeFile(buffer.get()->getMemBufferRef(), context);
403  if (Error E = module.takeError()) {
404  THROW_EXCEPTION(CompileError, "Error parsing bytecode file: "
405  + bytecodeFile);
406  }
407 
408  // TODO: why does this work? it should not?
409 // m.reset(module.get().get());
410  m = std::move(module.get());
411 
412  if (m.get() == 0) {
413  std::string msg = "Error parsing bytecode file: " + bytecodeFile +
414  "\n" + errMsgParse;
415  throw CompileError(__FILE__, __LINE__, __func__, msg);
416  }
417 
418  std::unique_ptr<Module> emuM;
419 
420  if (!emulationBytecodeFile.empty()) {
421  ErrorOr<std::unique_ptr<MemoryBuffer>> emuBufferPtr =
422  MemoryBuffer::getFileOrSTDIN(emulationBytecodeFile.c_str());
423 
424  if (std::error_code ec = emuBufferPtr.getError()) {
425  std::string msg = "Error reading bytecode file: " +
426  emulationBytecodeFile +
427  " of emulation library:\n" + ec.message();
428  throw CompileError(__FILE__, __LINE__, __func__, msg);
429  }
430 
431  std::unique_ptr<MemoryBuffer> emuBuffer =
432  std::move(emuBufferPtr.get());
433  Expected<std::unique_ptr<Module> > module =
434  parseBitcodeFile(emuBuffer.get()->getMemBufferRef(), context);
435  if (Error E = module.takeError()) {
436  THROW_EXCEPTION(CompileError, "Error parsing bytecode file: " +
437  emulationBytecodeFile + " of emulation library \n"
438  + errMsgParse);
439  }
440 
441  emuM = std::move(module.get());
442  if (emuM.get() == 0) {
443  std::string msg = "Error parsing bytecode file: " +
444  emulationBytecodeFile + " of emulation library \n"
445  + errMsgParse;
446  throw CompileError(__FILE__, __LINE__, __func__, msg);
447  }
448  }
449 
450  // Create target machine plugin.
451 #if (!defined(HAVE_CXX11) && !defined(HAVE_CXX0X))
452  std::auto_ptr<TCETargetMachinePlugin> plugin(createPlugin(target));
453 #else
454  std::unique_ptr<TCETargetMachinePlugin> plugin(createPlugin(target));
455 #endif
456 
457  TTAProgram::Program* result = NULL;
458  try {
459  // Compile.
460  result =
461  compile(*m.release(), emuM.release(), *plugin, target, optLevel,
462  debug, ipData);
463  } catch (...) {
464  // delete the backend plugin if we don't want to save it
465  // Let's hope this doesn't crash as the plugin is loaded to the
466  // current process. TCETargetMachinePlugin dtor should unload it.
467  if (!options_->saveBackendPlugin()) {
468  TCEString pluginPath =
469  cachePath_ + DS + pluginFilename(target);
471  }
472  delete res; res = NULL;
473 
474  throw;
475  }
476 
477  // delete the backend plugin if we don't want to save it
478  // Let's hope this doesn't crash as the plugin is loaded to the
479  // current process. TCETargetMachinePlugin dtor should unload it.
480  if (!options_->saveBackendPlugin()) {
481  TCEString pluginPath =
482  cachePath_ + DS + pluginFilename(target);
484  }
485  delete res; res = NULL;
486 
487  return result;
488 }
489 
490 /**
491  * Ripped from LLVMTargetMachine.cpp
492 
493 static void printAndVerify(PassManagerBase &PM,
494  bool allowDoubleDefs = false,
495  bool printMF = false) {
496  if (printMF) {
497  PM.add(createMachineFunctionPrinterPass(cerr));
498  }
499  PM.add(createMachineVerifierPass(allowDoubleDefs));
500 }
501 */
502 
503 /**
504  * Finds the maximum alignment of an alloca in the module.
505  *
506  * Used to align the stack for the program image.
507  */
508 unsigned
509 LLVMBackend::maxAllocaAlignment(const llvm::Module& mod) const {
510  unsigned maxAlignment = 4;
511  for (llvm::Module::const_iterator f = mod.begin(),
512  fe = mod.end(); f != fe; ++f) {
513  for (llvm::Function::const_iterator bb = f->begin(), be = f->end();
514  bb != be; ++bb) {
515  const llvm::BasicBlock* basicBlock = &(*bb);
516  for (llvm::BasicBlock::const_iterator i = basicBlock->begin(),
517  ie = basicBlock->end(); i != ie; ++i) {
518  if (!isa<const llvm::AllocaInst>(i)) continue;
519  const llvm::AllocaInst* alloca =
520  dyn_cast<const llvm::AllocaInst>(i);
521  #ifdef LLVM_OLDER_THAN_15
522  maxAlignment = std::max(maxAlignment,
523  (unsigned)alloca->getAlign().value());
524  maxAlignment = std::max(maxAlignment,
525  (unsigned)alloca->getAlignment());
526  #else
527  maxAlignment = std::max(maxAlignment,
528  (unsigned)alloca->getAlign().value());
529  maxAlignment = std::max(maxAlignment,
530  (unsigned)alloca->getAlign().value());
531  #endif
532 
533  }
534  }
535  }
536  return maxAlignment;
537 }
538 
539 static MCRegisterInfo*
540 createTCEMCRegisterInfo(const Triple& TT) {
541  MCRegisterInfo* X = new MCRegisterInfo();
542  return X;
543 }
544 
545 static MCInstrInfo*
547  MCInstrInfo* X = new MCInstrInfo();
548  return X;
549 }
550 
551 static MCSubtargetInfo*
552 createTCEMCSubtargetInfo(const Triple& TT, StringRef CPU, StringRef FS) {
553  const MCWriteProcResEntry WPR[] = {{0, 0}};
554  const MCWriteLatencyEntry WL[] = {{0, 0}};
555  const MCReadAdvanceEntry RA[] = {{0, 0, 0}};
556  ArrayRef<SubtargetFeatureKV> PF;
557  ArrayRef<SubtargetSubTypeKV> PD;
558 
559  MCSubtargetInfo* X = new MCSubtargetInfo(
560  TT, CPU, /*TuneCPU*/ "", FS, PF, PD, WPR, WL, RA, nullptr, nullptr,
561  nullptr);
562 
563  return X;
564 }
565 
566 /**
567  * Compiles given llvm program module for target machine using the given
568  * target machine plugin.
569  *
570  * @param module LLVM module to compile.
571  * @param plugin Target architecture compiler plugin.
572  * @param target Target architecture as Machine object.
573  * @param optLevel Optimization level.
574  * @param debug If true, enable LLVM debug printing.
575  * @return Module compiled to program for the target architecture.
576  */
579  llvm::Module& module, llvm::Module* emulationModule,
580  TCETargetMachinePlugin& plugin, TTAMachine::Machine& target, int optLevel,
581  bool /*debug*/, InterPassData* ipData) {
582  ipData_ = ipData;
583  // TODO: fixme
584  std::string targetStr = "tce-llvm";
585  if (target.isLittleEndian()) {
586  if (target.is64bit()) {
587  targetStr = "tcele64-llvm";
588  } else {
589  targetStr = "tcele-llvm";
590  }
591  }
592 
593  std::string errorStr;
594 
595  std::string featureString ="";
596 
597  // run registering code, which should have been done by LLVM
598 
599  // Initialize targets first. needs
600  // #include <llvm/Target/TargetSelecty.h>,
601  // whose defines collide with tce_config.h
602 
603  //InitializeAllTargets();
604  //InitializeAllAsmPrinters();
605 
606  // Register target to llvm for using lookupTarget
609 
610  // get registered target machine and set plugin.
611  const Target* tceTarget =
612  TargetRegistry::lookupTarget(targetStr, errorStr);
613  Target* nonconst_target = const_cast<Target*>(tceTarget);
614 
615  if (!tceTarget) {
616  errs() << errorStr << "\n";
617  return NULL;
618  }
619 
620  TargetRegistry::RegisterMCRegInfo(
621  *nonconst_target, createTCEMCRegisterInfo);
622  TargetRegistry::RegisterMCInstrInfo(
623  *nonconst_target, createTCEMCInstrInfo);
624  TargetRegistry::RegisterMCSubtargetInfo(
625  *nonconst_target, createTCEMCSubtargetInfo);
626 
627  std::string cpuStr = "tce";
628 
629  TargetOptions Options;
630  Options.UnsafeFPMath = false; //EnableUnsafeFPMath;
631  Options.NoInfsFPMath = false; //EnableNoInfsFPMath;
632  Options.NoNaNsFPMath = false; //EnableNoNaNsFPMath;
633  Options.HonorSignDependentRoundingFPMathOption = false;
634  // the stack alignment depends on the widest aligned
635  // memory operations supported by the machine and
636  // on the maximum alignment of any stack object in
637  // the program, recompute this now as the llvm::Module has
638  // been loaded
639  unsigned maxMachineAlignment = (unsigned)MachineInfo::maxMemoryAlignment(target);
640  module.setOverrideStackAlignment(maxMachineAlignment);
642 
643  if (maxAllocaAlignment(module) > maxMachineAlignment) {
645  "Alloca object requires larger stack alignment than widest "
646  "memory operation. "
647  "We were hoping this wouldn't happen, because now stack "
648  "alignment cannot be "
649  "figured out just from adf-file. ATM (5/20) this assumption is "
650  "made here, "
651  "at tcecc::getStackAlignment and at CodeGenerator.cc "
652  "constructor.");
653  }
654  } else {
655  module.setOverrideStackAlignment(
656  std::max(maxMachineAlignment, maxAllocaAlignment(module)));
657  }
658  Options.GuaranteedTailCallOpt = true; //EnableGuaranteedTailCallOpt;
659 
660  TCETargetMachine* targetMachine =
661  static_cast<TCETargetMachine*>(
662  tceTarget->createTargetMachine(
663  targetStr, cpuStr, featureString, Options,
664  Reloc::Model::Static));
665 
666  if (!targetMachine) {
667  errs() << "Could not create tce target machine" << "\n";
668  return NULL;
669  }
670  // The way to override the stack alignment was
671  // changed in LLVM commit 787ee457173c. It's easiest
672  // we just pass it through TCETargetMachine for now
673  // even though it's really module specific.
674  targetMachine->setStackAlignment(
675  std::max((unsigned)(target.is64bit() ? 8 : 4),
676  module.getOverrideStackAlignment()));
677 
678  // This hack must be cleaned up before adding TCE target to llvm upstream
679  // these are needed by TCETargetMachine::addInstSelector passes
680  targetMachine->setTargetMachinePlugin(plugin, target);
681  targetMachine->setEmulationModule(emulationModule);
682 
683  /**
684  * This is quite straight copy how llc actually creates passes for target.
685  */
686 
687  llvm::legacy::PassManager Passes;
688 #define addPass(P) Passes.add(P)
689 
690  llvm::raw_fd_ostream sos(STDOUT_FILENO, false);
691 
692  targetMachine->addPassesToEmitFile(
693  Passes, sos, nullptr, CGFT_AssemblyFile);
694 
695 
696  // Add alias analysis pass that is distributed with pocl library.
698  ImmutablePass* (*creator)();
699  std::string file = options_->workItemAAFile();
700  bool foundAA = true;
701  try {
703  "create_workitem_aa_plugin", creator, file);
704  } catch(Exception& e) {
705  std::string msg = std::string() +
706  "Unable to load plugin file '" +
707  file + "'. Error: " + e.errorMessageStack();
708  if (Application::verboseLevel() > 0) {
710  << msg << std::endl;
712  "Most likely too old version of POCL. \
713  TCE will continue without work item alias analysis." <<
714  std::endl;
715  }
716  foundAA = false;
717  }
718  if (foundAA)
719  addPass(creator());
720  }
721  if (ipData_ != NULL) {
722  // Stack pointer datum.
723  RegDatum* spReg = new RegDatum;
724  spReg->first = plugin.rfName(plugin.spDRegNum());
725  spReg->second = plugin.registerIndex(plugin.spDRegNum());
726  ipData_->setDatum("STACK_POINTER", spReg);
727 
728  // FP register datum.
729  RegDatum* fpReg = new RegDatum;
730  fpReg->first = plugin.rfName(plugin.fpDRegNum());
731  fpReg->second = plugin.registerIndex(plugin.fpDRegNum());
732  ipData_->setDatum("FRAME_POINTER", fpReg);
733 
734  // Return value register datum.
735  RegDatum* rvReg = new RegDatum;
736  rvReg->first = plugin.rfName(plugin.rvDRegNum());
737  rvReg->second = plugin.registerIndex(plugin.rvDRegNum());
738  ipData_->setDatum("RV_REGISTER", rvReg);
739 
740  std::vector<unsigned> paramRegs = plugin.getParamDRegNums();
741  for (unsigned int i = 0; i < paramRegs.size(); i++) {
742  RegDatum* p = new RegDatum;
743  p->first = plugin.rfName(paramRegs[i]);
744  p->second = plugin.registerIndex(paramRegs[i]);
745  TCEString datumName = "IPARAM";
746  datumName << i+2;
747  ipData_->setDatum(datumName, p);
748  }
749 
750  std::vector<unsigned> vectorRVRegs = plugin.getVectorRVDRegNums();
751  for (unsigned int i = 0; i < vectorRVRegs.size(); i++) {
752  RegDatum* p = new RegDatum;
753  p->first = plugin.rfName(vectorRVRegs[i]);
754  p->second = plugin.registerIndex(vectorRVRegs[i]);
755  TCEString datumName = "VRV_REGISTER";
756  datumName << i;
757  ipData_->setDatum(datumName, p);
758  }
759 
760  // TODO: add datums for vector RV registers.
761  }
762 
763  // Find the inner loops. Must be executed with a separate
764  // PassManager as mixing module passes and loop passes does
765  // not seem to magically work.
766  // TODO: is it safe to trust the llvm::BasicBlock pointers are
767  // intact until we run the actual code generation? The loop info
768  // is stored using those as indices.
769  llvm::legacy::PassManager FPasses;
770  InnerLoopFinder* loopFinder = new InnerLoopFinder();
771  FPasses.add(loopFinder);
772  FPasses.run(module);
773 
774  LLVMTCEBuilder* builder = NULL;
775 
776  // This is not actuall LLVM pass so we can not get actual AA.
777  // It will be picked later, for now just passing NULL.
778  // When LLVMTCEIRBuilder is called from TCEScheduler it will require
779  // AA parameter.
780  AliasAnalysis* AA = NULL;
781  LLVMTCEIRBuilder* b =
782  new LLVMTCEIRBuilder(*targetMachine, &target, *ipData, AA);
783  b->setInnerLoopFinder(loopFinder);
784  builder = b;
785 
786  if (options_ != NULL && options_->isInitialStackPointerValueSet()) {
789  }
790  addPass(new ConstantTransformer(target));
791  addPass(builder);
792  Passes.run(module);
793 
794  if (ipData_ != NULL) {
795  if (builder->isProgramUsingRestrictedPointers()) {
796  ipData_->setDatum("RESTRICTED_POINTERS_FOUND", NULL);
797  }
798  }
799  builder->deleteDeadProcedures();
800  return builder->result();
801 }
802 
803 /**
804  * Creates TCETargetMachinePlugin for target architecture.
805  *
806  * @param target Target machine to build plugin for.
807  */
810  std::string pluginFile = pluginFilename(target);
811  std::string pluginFileName;
812  std::string tempPluginFileName;
813 
814  // Create cache directory if it doesn't exist.
817  }
818 
819  pluginFileName = cachePath_ + DS + pluginFile;
820  tempPluginFileName = cachePath_ + DS + pluginFile + ".%%_%%_%%_%%";
821 
822  llvm::SmallString<128> ResultPath;
823  llvm::sys::fs::createUniqueFile(llvm::Twine(tempPluginFileName), ResultPath);
824  tempPluginFileName = ResultPath.str().str();
825 
826  // Static plugin source files path.
827  std::string srcsPath = "";
828  std::string pluginIncludeFlags = "";
829  if (useInstalledVersion_) {
830  srcsPath = Application::installationDir() + DS + "include" + DS;
831  pluginIncludeFlags = " -I" + srcsPath;
832  } else {
833  srcsPath = std::string(TCE_SRC_ROOT) + DS +
834  "src" + DS + "applibs" + DS + "LLVMBackend" + DS + "plugin" + DS;
835 
836  pluginIncludeFlags =
837  " -I" + srcsPath +
838  " -I" + std::string(TCE_SRC_ROOT) + DS + " " +
839  " -I" + std::string(TCE_SRC_ROOT) + DS + "src" + DS + "tools" +
840  " -I" + std::string(TCE_SRC_ROOT) + DS + "src" + DS + "base" +
841  DS + "mach"
842  " -I" + std::string(TCE_SRC_ROOT) + DS + "src" + DS +
843  "applibs" + DS + "LLVMBackend" + DS + " " +
844 
845  " -I" + std::string(TCE_SRC_ROOT) + DS + "src" + DS +
846  "applibs" + DS + "mach" + " " +
847 
848  " -I" + std::string(TCE_SRC_ROOT) + DS + "src" + DS +
849  "applibs" + DS + "Scheduler" + DS + " " +
850 
851  " -I" + std::string(TCE_SRC_ROOT) + DS + "src" + DS +
852  "applibs" + DS + "Scheduler" + DS + "Algorithms" + " " +
853 
854  " -I`" LLVM_CONFIG " --includedir`" + DS + "llvm" + DS +
855  "Target" + DS;
856 
857  }
858 
859 
860  if (FileSystem::fileExists(pluginFileName) &&
861  FileSystem::fileIsReadable(pluginFileName)) {
862 
863  try {
865  pluginTool_.registerModule(pluginFile);
866  TCETargetMachinePlugin* (*creator)();
868  "create_tce_backend_plugin", creator, pluginFile);
869 
870  return creator();
871  } catch(Exception& e) {
872  if (Application::verboseLevel() > 0) {
874  << "Unable to load plugin file " << pluginFileName
875  << ": " << e.errorMessage() << ", "
876  << "regenerating..." << std::endl;
877  }
878  }
879  }
880 
881  if (!options_->useOldBackendSources()) {
882  // Create target instruction and register definitions in .td files.
883  TDGen* pluginGenPtr = new TDGen(target);
884 
885  try {
886  pluginGenPtr->generateBackend(tempDir_);
887  delete pluginGenPtr;
888  } catch(Exception& e) {
889  std::string msg =
890  "Failed to build compiler plugin for target architecture: ";
891  msg += e.errorMessage();
892  CompileError ne(__FILE__, __LINE__, __func__, msg);
893  ne.setCause(e);
894  throw ne;
895  }
896  }
897  std::string tblgenbin = "llvm-tblgen";
898 
899  // Generate TCEGenRegisterNames.inc
900  std::string tblgenCmd;
901 
902  if (useInstalledVersion_) {
903  // This is quite ugly. LLVM include dir is determined by
904  // executing llvm-config in the commandline. This doesn't
905  // work if llvm-config is not found in path.
906  // First check that llvm-config is found in path.
907  if (system(LLVM_CONFIG " --version")) {
908  std::string msg = "Unable to determine llvm include dir. "
909  LLVM_CONFIG " not found in path";
910 
911  throw CompileError(__FILE__, __LINE__, __func__, msg);
912  }
913  // /usr/include needs to be last in case there is old llvm installation
914  // from packages
915  tblgenCmd = tblgenbin + " " + TBLGEN_INCLUDES +
916  pluginIncludeFlags +
917  " -I" + tempDir_ +
918  " -I`" LLVM_CONFIG " --includedir`" +
919  " -I`" LLVM_CONFIG " --includedir`/Target" +
920  " -I`" LLVM_CONFIG " --includedir`/llvm/Target" +
921  " -I/usr/include ";
922  } else {
923  tblgenCmd = tblgenbin + " " + TBLGEN_INCLUDES +
924  pluginIncludeFlags +
925  " -I" + tempDir_ +
926  " -I" + LLVM_INCLUDE_DIR +
927  " -I" + LLVM_INCLUDE_DIR + "/Target" +
928  " -I" + LLVM_INCLUDE_DIR + "/llvm/Target";
929  }
930 
931  tblgenCmd += " " + tempDir_ + FileSystem::DIRECTORY_SEPARATOR + "TCE.td";
932 
933  // Generate TCEGenRegisterInfo.inc
934  std::string cmd = tblgenCmd +
935  " -gen-register-info" +
937  "TCEGenRegisterInfo.inc";
938 
939  if (Application::verboseLevel() > 0) {
940  Application::logStream() << "LLVMBackend: " << cmd << std::endl;
941  }
942  int ret = system(cmd.c_str());
943  if (ret) {
944  std::string msg = std::string() +
945  "Failed to build compiler plugin for target architecture.\n" +
946  "Failed command was: " + cmd;
947 
948  throw CompileError(__FILE__, __LINE__, __func__, msg);
949  }
950 
951  // Generate TCEGenInstrInfo.inc
952  cmd = tblgenCmd +
953  " -gen-instr-info" +
955  "TCEGenInstrInfo.inc";
956 
957  ret = system(cmd.c_str());
958  if (ret) {
959  std::string msg = std::string() +
960  "Failed to build compiler plugin for target architecture.\n" +
961  "Failed command was: " + cmd;
962 
963  throw CompileError(__FILE__, __LINE__, __func__, msg);
964  }
965 
966  // Generate TCEGenDAGISel.inc
967  cmd = tblgenCmd +
968  " -gen-dag-isel" +
970  "TCEGenDAGISel.inc";
971 
972  ret = system(cmd.c_str());
973  if (ret) {
974  std::string msg = std::string() +
975  "Failed to build compiler plugin for target architecture.\n" +
976  "Failed command was: " + cmd;
977 
978  throw CompileError(__FILE__, __LINE__, __func__, msg);
979  }
980 
981 
982  // Generate TCEGenCallingConv.inc
983  cmd = tblgenCmd +
984  " -gen-callingconv" +
986  "TCEGenCallingConv.inc";
987 
988  ret = system(cmd.c_str());
989  if (ret) {
990  std::string msg = std::string() +
991  "Failed to build compiler plugin for target architecture.\n" +
992  "Failed command was: " + cmd;
993 
994  throw CompileError(__FILE__, __LINE__, __func__, msg);
995  }
996 
997  // Generate TCESuBTargetInfo.inc
998  cmd = tblgenCmd +
999  " -gen-subtarget" +
1001  "TCEGenSubTargetInfo.inc";
1002 
1003  ret = system(cmd.c_str());
1004  if (ret) {
1005  std::string msg =
1006  std::string() +
1007  "Failed to build compiler plugin for target architecture.\n" +
1008  "Failed command was: " + cmd;
1009 
1010  throw CompileError(__FILE__, __LINE__, __func__, msg);
1011  }
1012 
1013  // Generate TCEDFAPacketizer.inc
1014  cmd = tblgenCmd + " -gen-dfa-packetizer" + " -o " + tempDir_ +
1015  FileSystem::DIRECTORY_SEPARATOR + "TCEGenDFAPacketizer.inc";
1016 
1017  ret = system(cmd.c_str());
1018  if (ret) {
1019  std::string msg =
1020  std::string() +
1021  "Failed to build compiler plugin for target architecture.\n" +
1022  "Failed command was: " + cmd;
1023 
1024  throw CompileError(__FILE__, __LINE__, __func__, msg);
1025  }
1026 
1027  // NOTE: this could be get from Makefile.am
1028  TCEString pluginSources = srcsPath + "PluginCompileWrapper.cc ";
1029 
1030  TCEString endianOption = target.isLittleEndian() ?
1031  "-DLITTLE_ENDIAN_TARGET" : "";
1032 
1033  TCEString bitnessOption = target.is64bit() ? "-DTARGET64BIT" : "";
1034  // Compile plugin to cache.
1035  // CXX and SHARED_CXX_FLAGS defined in tce_config.h
1036  cmd = std::string(CXX) +
1037  " -I" + tempDir_ +
1038  pluginIncludeFlags +
1039  " " + SHARED_CXX_FLAGS +
1040  " " + LLVM_CPPFLAGS;
1041 
1043  cmd += " -I`" LLVM_CONFIG " --includedir`";
1044 
1045  cmd +=
1046  " " + CXX14_FLAG +
1047  " " + endianOption +
1048  " " + bitnessOption +
1049  " " + pluginSources +
1050  " -o " + tempPluginFileName;
1051 
1052  if (Application::verboseLevel() > 0) {
1053  Application::logStream() << "LLVMBackend: " << cmd << std::endl;
1054  }
1055  ret = system(cmd.c_str());
1056  if (ret) {
1057  std::string msg = std::string() +
1058  "Failed to build compiler plugin for target architecture.\n" +
1059  "Failed command was: " + cmd;
1060 
1061  throw CompileError(__FILE__, __LINE__, __func__, msg);
1062  }
1063 
1064  // move plugin to final location
1065  llvm::sys::fs::rename(llvm::Twine(tempPluginFileName), llvm::Twine(pluginFileName));
1066 
1067  // Load plugin.
1068  TCETargetMachinePlugin* (*creator)();
1069  try {
1071  pluginTool_.registerModule(pluginFile);
1073  "create_tce_backend_plugin", creator, pluginFile);
1074  } catch(Exception& e) {
1075  std::string msg = std::string() +
1076  "Unable to load plugin file '" +
1077  pluginFileName + "'. Error: " + e.errorMessage();
1078 
1079  IOException ne(__FILE__, __LINE__, __func__, msg);
1080  throw ne;
1081  }
1082 
1083  return creator();
1084 }
1085 
1086 /**
1087  * Returns (hopefully) unique plugin filename for target architecture.
1088  *
1089  * The filename includes also the TCE version string to avoid problems with
1090  * incompatible backend plugins between TCE revisions.
1091  * The filename is used for cached plugins.
1092  *
1093  * @param target Target architecture.
1094  * @return Filename for the target architecture.
1095  */
1096 std::string
1098  const TTAMachine::Machine& target) {
1099  TCEString fileName = target.hash();
1100  fileName += "-" + Application::TCEVersionString();
1101  fileName += PLUGIN_SUFFIX;
1102 
1103  return fileName;
1104 }
llvm::TCETargetMachinePlugin::registerIndex
virtual unsigned registerIndex(unsigned dwarfRegNum)=0
Returns name of the physical register index corresponding to a generated register ID.
SimpleInterPassDatum
Definition: InterPassDatum.hh:64
LLVMBackend::cachePath_
TCEString cachePath_
Path to the cache where precompiled plugins are stored.
Definition: LLVMBackend.hh:101
llvm
Definition: InlineAsmParser.hh:49
TTAProgram::Program
Definition: Program.hh:63
Options
Definition: Options.hh:51
MachineInfo::maxMemoryAlignment
static int maxMemoryAlignment(const TTAMachine::Machine &mach)
Definition: MachineInfo.cc:261
llvm::TCETargetMachinePlugin::fpDRegNum
virtual unsigned fpDRegNum()=0
Returns ID number of the frame pointer register.
FileSystem.hh
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
TCETargetMachinePlugin.hh
FileSystem::createDirectory
static bool createDirectory(const std::string &path)
Definition: FileSystem.cc:400
llvm::LLVMTCEBuilder::result
TTAProgram::Program * result()
Definition: LLVMTCEBuilder.cc:3713
TDGen.hh
RegDatum
SimpleInterPassDatum< std::pair< TCEString, unsigned int > > RegDatum
Datum type for transferring register name as a data. Stack pointer register is saved with key STACK_P...
Definition: InterPassDatum.hh:87
LLVMBackend::PLUGIN_SUFFIX
static const std::string PLUGIN_SUFFIX
Definition: LLVMBackend.hh:111
MachineValidator::GCU_MISSING
@ GCU_MISSING
GCU missing in machine.
Definition: MachineValidator.hh:57
LLVMBackend::PLUGIN_PREFIX
static const std::string PLUGIN_PREFIX
Definition: LLVMBackend.hh:110
LLVMBackend::pluginTool_
PluginTools pluginTool_
Plugin tool for loading target machine plugin.
Definition: LLVMBackend.hh:99
LLVMTCECmdLineOptions::saveBackendPlugin
bool saveBackendPlugin() const
Definition: LLVMTCECmdLineOptions.cc:369
LLVMBackend::compile
TTAProgram::Program * compile(const std::string &bytecodeFile, const std::string &emulationBytecodeFile, TTAMachine::Machine &target, int optLevel, bool debug=false, InterPassData *ipData=NULL)
Definition: LLVMBackend.cc:360
MachineValidator.hh
TTAMachine::Machine::is64bit
bool is64bit() const
Definition: Machine.hh:260
MachineInfo.hh
Exception::setCause
void setCause(const Exception &cause)
Definition: Exception.cc:75
MachineValidator::USED_IO_NOT_BOUND
@ USED_IO_NOT_BOUND
Pipeline uses an IO which is not bound.
Definition: MachineValidator.hh:61
MachineValidatorResults.hh
CompileError
Definition: Exception.hh:1019
Application::verboseLevel
static int verboseLevel()
Definition: Application.hh:176
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
LLVMTCECmdLineOptions::workItemAAFile
std::string workItemAAFile() const
Definition: LLVMTCECmdLineOptions.cc:409
MachineValidator::PC_PORT_MISSING
@ PC_PORT_MISSING
PC port missing in GCU.
Definition: MachineValidator.hh:65
MachineValidatorResults
Definition: MachineValidatorResults.hh:45
llvm::TCETargetMachine::setTargetMachinePlugin
virtual void setTargetMachinePlugin(TCETargetMachinePlugin &plugin, TTAMachine::Machine &target)
Definition: TCETargetMachine.cc:167
TTAMachine::Machine::hash
TCEString hash() const
Definition: Machine.cc:932
TDGen
Definition: TDGen.hh:77
LLVMBackend::ipData_
InterPassData * ipData_
Definition: LLVMBackend.hh:107
TDGen::generateBackend
void generateBackend(std::string &path)
Definition: TDGen.cc:388
llvm::TCETargetMachine::setStackAlignment
void setStackAlignment(unsigned align)
Definition: TCETargetMachine.hh:273
MachineValidator
Definition: MachineValidator.hh:52
TTAMachine::Machine::isLittleEndian
bool isLittleEndian() const
Definition: Machine.hh:258
TCEString.hh
LLVMBackend::CXX0X_FLAG
static const TCEString CXX0X_FLAG
Definition: LLVMBackend.hh:112
createTCEMCRegisterInfo
static MCRegisterInfo * createTCEMCRegisterInfo(const Triple &TT)
Definition: LLVMBackend.cc:540
InnerLoopFinder.hh
llvm::TCETargetMachinePlugin::spDRegNum
virtual unsigned spDRegNum()=0
Returns ID number of the stack pointer register.
FileSystem::fileIsDirectory
static bool fileIsDirectory(const std::string fileName)
LLVMBackend::tempDir_
TCEString tempDir_
Directory to store temporary files.
Definition: LLVMBackend.hh:103
InnerLoopFinder
Definition: InnerLoopFinder.hh:28
addPass
#define addPass(P)
MachineValidator::FU_PORT_MISSING
@ FU_PORT_MISSING
FU is missing ports.
Definition: MachineValidator.hh:75
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
MachineValidator::GCU_AS_MISSING
@ GCU_AS_MISSING
Address space missing in GCU.
Definition: MachineValidator.hh:59
LLVMBackend::options_
LLVMTCECmdLineOptions * options_
Definition: LLVMBackend.hh:105
PluginTools::importSymbol
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
Instruction.hh
THROW_EXCEPTION
#define THROW_EXCEPTION(exceptionType, message)
Exception wrapper macro that automatically includes file name, line number and function name where th...
Definition: Exception.hh:39
InterPassDatum.hh
Conversion.hh
LLVMInitializeTCETarget
void LLVMInitializeTCETarget()
Definition: TCETargetMachine.cc:117
LLVMTCECmdLineOptions.hh
TCETargetMachine.hh
Application.hh
Application::cmdLineOptions
static CmdLineOptions * cmdLineOptions()
Definition: Application.cc:397
__func__
#define __func__
Definition: Application.hh:67
PluginTools::registerModule
void registerModule(const std::string &module)
Definition: PluginTools.cc:138
LLVMBackend::createPlugin
llvm::TCETargetMachinePlugin * createPlugin(const TTAMachine::Machine &target)
Definition: LLVMBackend.cc:809
llvm::TCETargetMachinePlugin::getParamDRegNums
virtual std::vector< unsigned > getParamDRegNums() const =0
createTCEMCInstrInfo
static MCInstrInfo * createTCEMCInstrInfo()
Definition: LLVMBackend.cc:546
llvm::LLVMTCEIRBuilder
Definition: LLVMTCEIRBuilder.hh:60
createWorkItemAliasAnalysisPass
Pass * createWorkItemAliasAnalysisPass()
InterPassData
Definition: InterPassData.hh:48
Exception::errorMessageStack
std::string errorMessageStack(bool messagesOnly=false) const
Definition: Exception.cc:138
Environment.hh
LLVMBackend::TBLGEN_INCLUDES
static const std::string TBLGEN_INCLUDES
Definition: LLVMBackend.hh:109
LLVMPOMBuilder.hh
MachineValidatorResults::errorCount
int errorCount() const
Definition: MachineValidatorResults.cc:56
Machine.hh
OperationDAGSelector::OperationSet
TCETools::CIStringSet OperationSet
Definition: OperationDAGSelector.hh:88
Exception
Definition: Exception.hh:54
ConstantTransformer
Definition: ConstantTransformer.hh:43
LLVMTCECmdLineOptions::backendCacheDir
std::string backendCacheDir() const
Definition: LLVMTCECmdLineOptions.cc:419
LLVMTCECmdLineOptions::useOldBackendSources
bool useOldBackendSources() const
Definition: LLVMTCECmdLineOptions.cc:389
LLVMTCECmdLineOptions
Definition: LLVMTCECmdLineOptions.hh:48
LLVMTCECmdLineOptions::assumeADFStackAlignment
bool assumeADFStackAlignment() const
Definition: LLVMTCECmdLineOptions.cc:463
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.
LLVMTCEIRBuilder.hh
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
createTCEMCSubtargetInfo
static MCSubtargetInfo * createTCEMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Definition: LLVMBackend.cc:552
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
llvm::LLVMTCEIRBuilder::setInnerLoopFinder
void setInnerLoopFinder(InnerLoopFinder *loopFinder)
Definition: LLVMTCEIRBuilder.hh:84
llvm::TCETargetMachinePlugin
Definition: TCETargetMachinePlugin.hh:109
LLVMTCECmdLineOptions::isInitialStackPointerValueSet
bool isInitialStackPointerValueSet() const
Definition: LLVMTCECmdLineOptions.cc:426
MachineValidator::RA_PORT_MISSING
@ RA_PORT_MISSING
RA port missing in GCU.
Definition: MachineValidator.hh:67
LLVMBackend::~LLVMBackend
virtual ~LLVMBackend()
Definition: LLVMBackend.cc:348
X
static llvm::RegisterPass< InnerLoopFinder > X("find-innerloops-test", "Finds inner loops test.", false, true)
llvm::LLVMTCEBuilder::isProgramUsingRestrictedPointers
bool isProgramUsingRestrictedPointers() const
Definition: LLVMTCEBuilder.hh:123
IGNORE_COMPILER_WARNING
#define IGNORE_COMPILER_WARNING(X)
Definition: CompilerWarnings.hh:51
ADFSerializer.hh
Program.hh
RA
#define RA()
Definition: POMGenMacros.hh:393
PluginTools::addSearchPath
void addSearchPath(const std::string &searchPath)
Definition: PluginTools.cc:95
InterPassData.hh
Environment::llvmtceCachePath
static std::string llvmtceCachePath()
Definition: Environment.cc:1087
FileSystem::fileExists
static bool fileExists(const std::string fileName)
MachineValidator::validate
MachineValidatorResults * validate(const std::set< ErrorCode > &errorsToCheck) const
Definition: MachineValidator.cc:81
LLVMBackend::maxAllocaAlignment
unsigned maxAllocaAlignment(const llvm::Module &mod) const
Definition: LLVMBackend.cc:509
Application::installationDir
static std::string installationDir()
Definition: Application.cc:537
TCEStubTargetMachine.hh
TCEString
Definition: TCEString.hh:53
LLVMInitializeTCETargetInfo
void LLVMInitializeTCETargetInfo()
Definition: TCEStubTargetMachine.cc:67
LLVMBackend::LLVMBackend
LLVMBackend(bool useInstalledVersion, TCEString tempDir)
Definition: LLVMBackend.cc:324
POP_COMPILER_DIAGS
#define POP_COMPILER_DIAGS
Definition: CompilerWarnings.hh:68
llvm::TCETargetMachine
Definition: TCETargetMachine.hh:106
LLVMBackend::CXX11_FLAG
static const TCEString CXX11_FLAG
Definition: LLVMBackend.hh:113
llvm::LLVMTCEBuilder::setInitialStackPointerValue
void setInitialStackPointerValue(unsigned value)
Definition: LLVMTCEBuilder.cc:1240
LLVMTCECmdLineOptions::isWorkItemAAFileDefined
bool isWorkItemAAFileDefined() const
Definition: LLVMTCECmdLineOptions.cc:404
TargetData
llvm::DataLayout TargetData
Definition: LLVMBackend.cc:131
IOException
Definition: Exception.hh:130
LLVMBackend::pluginFilename
std::string pluginFilename(const TTAMachine::Machine &target)
Definition: LLVMBackend.cc:1097
InterPassData::setDatum
void setDatum(const std::string &key, InterPassDatum *datum)
Definition: InterPassData.cc:89
llvm::TCETargetMachinePlugin::getVectorRVDRegNums
virtual std::vector< unsigned > getVectorRVDRegNums() const =0
DS
#define DS
Definition: LLVMBackend.cc:124
FileSystem::fileIsReadable
static bool fileIsReadable(const std::string fileName)
LLVMBackend::llvmRequiredOpset
static OperationDAGSelector::OperationSet llvmRequiredOpset(bool includeFloatOps, bool isLittleEndian, bool bits64)
Definition: LLVMBackend.cc:150
LLVMBackend::useInstalledVersion_
bool useInstalledVersion_
Assume we are running an installed TCE version.
Definition: LLVMBackend.hh:96
llvm::TCETargetMachine::setEmulationModule
virtual void setEmulationModule(Module *mod)
Definition: TCETargetMachine.hh:127
Application::TCEVersionString
static std::string TCEVersionString()
Definition: Application.cc:510
ProgramAnnotation.hh
llvm::LLVMTCEBuilder
Definition: LLVMTCEBuilder.hh:102
llvm::LLVMTCEBuilder::deleteDeadProcedures
void deleteDeadProcedures()
Definition: LLVMTCEBuilder.cc:1197
llvm::AliasAnalysis
AAResults AliasAnalysis
Definition: DataDependenceGraphBuilder.hh:45
CompilerWarnings.hh
LLVMBackend::CXX14_FLAG
static const TCEString CXX14_FLAG
Definition: LLVMBackend.hh:114
TTAMachine::Machine
Definition: Machine.hh:73
LLVMTCECmdLineOptions::initialStackPointerValue
uint64_t initialStackPointerValue() const
Definition: LLVMTCECmdLineOptions.cc:431
MachineValidatorResults::error
Error error(int index) const
Definition: MachineValidatorResults.cc:70
ConstantTransformer.hh
LLVMBackend.hh