SPUTargetMachine.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //===-- SPUTargetMachine.cpp - Define TargetMachine for Cell SPU ----------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // Top-level implementation for the Cell SPU target.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "SPU.h"
  14. #include "SPURegisterNames.h"
  15. #include "SPUTargetAsmInfo.h"
  16. #include "SPUTargetMachine.h"
  17. #include "llvm/Module.h"
  18. #include "llvm/PassManager.h"
  19. #include "llvm/Target/TargetMachineRegistry.h"
  20. using namespace llvm;
  21. namespace {
  22. // Register the targets
  23. RegisterTarget<SPUTargetMachine>
  24. CELLSPU("cellspu", " STI CBEA Cell SPU");
  25. }
  26. const std::pair<unsigned, int> *
  27. SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
  28. NumEntries = 1;
  29. return &LR[0];
  30. }
  31. const TargetAsmInfo *
  32. SPUTargetMachine::createTargetAsmInfo() const
  33. {
  34. return new SPUTargetAsmInfo(*this);
  35. }
  36. unsigned
  37. SPUTargetMachine::getModuleMatchQuality(const Module &M)
  38. {
  39. // We strongly match "spu-*" or "cellspu-*".
  40. std::string TT = M.getTargetTriple();
  41. if ((TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "spu")
  42. || (TT.size() == 7 && std::string(TT.begin(), TT.begin()+7) == "cellspu")
  43. || (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "spu-")
  44. || (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "cellspu-"))
  45. return 20;
  46. return 0; // No match at all...
  47. }
  48. SPUTargetMachine::SPUTargetMachine(const Module &M, const std::string &FS)
  49. : Subtarget(*this, M, FS),
  50. DataLayout(Subtarget.getTargetDataString()),
  51. InstrInfo(*this),
  52. FrameInfo(*this),
  53. TLInfo(*this),
  54. InstrItins(Subtarget.getInstrItineraryData())
  55. {
  56. // For the time being, use static relocations, since there's really no
  57. // support for PIC yet.
  58. setRelocationModel(Reloc::Static);
  59. }
  60. //===----------------------------------------------------------------------===//
  61. // Pass Pipeline Configuration
  62. //===----------------------------------------------------------------------===//
  63. bool
  64. SPUTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast)
  65. {
  66. // Install an instruction selector.
  67. PM.add(createSPUISelDag(*this));
  68. return false;
  69. }
  70. bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
  71. raw_ostream &Out) {
  72. PM.add(createSPUAsmPrinterPass(Out, *this));
  73. return false;
  74. }