AlphaTargetMachine.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
  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. //
  11. //===----------------------------------------------------------------------===//
  12. #include "Alpha.h"
  13. #include "AlphaJITInfo.h"
  14. #include "AlphaTargetAsmInfo.h"
  15. #include "AlphaTargetMachine.h"
  16. #include "llvm/Module.h"
  17. #include "llvm/PassManager.h"
  18. #include "llvm/Target/TargetMachineRegistry.h"
  19. #include "llvm/Support/raw_ostream.h"
  20. using namespace llvm;
  21. /// AlphaTargetMachineModule - Note that this is used on hosts that cannot link
  22. /// in a library unless there are references into the library. In particular,
  23. /// it seems that it is not possible to get things to work on Win32 without
  24. /// this. Though it is unused, do not remove it.
  25. extern "C" int AlphaTargetMachineModule;
  26. int AlphaTargetMachineModule = 0;
  27. // Register the targets
  28. static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
  29. const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
  30. return new AlphaTargetAsmInfo(*this);
  31. }
  32. unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
  33. // We strongly match "alpha*".
  34. std::string TT = M.getTargetTriple();
  35. if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
  36. TT[3] == 'h' && TT[4] == 'a')
  37. return 20;
  38. // If the target triple is something non-alpha, we don't match.
  39. if (!TT.empty()) return 0;
  40. if (M.getEndianness() == Module::LittleEndian &&
  41. M.getPointerSize() == Module::Pointer64)
  42. return 10; // Weak match
  43. else if (M.getEndianness() != Module::AnyEndianness ||
  44. M.getPointerSize() != Module::AnyPointerSize)
  45. return 0; // Match for some other target
  46. return getJITMatchQuality()/2;
  47. }
  48. unsigned AlphaTargetMachine::getJITMatchQuality() {
  49. #ifdef __alpha
  50. return 10;
  51. #else
  52. return 0;
  53. #endif
  54. }
  55. AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
  56. : DataLayout("e-f128:128:128"),
  57. FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
  58. JITInfo(*this),
  59. Subtarget(M, FS),
  60. TLInfo(*this) {
  61. setRelocationModel(Reloc::PIC_);
  62. }
  63. //===----------------------------------------------------------------------===//
  64. // Pass Pipeline Configuration
  65. //===----------------------------------------------------------------------===//
  66. bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
  67. PM.add(createAlphaISelDag(*this));
  68. return false;
  69. }
  70. bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
  71. // Must run branch selection immediately preceding the asm printer
  72. PM.add(createAlphaBranchSelectionPass());
  73. return false;
  74. }
  75. bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
  76. bool Verbose,
  77. raw_ostream &Out) {
  78. PM.add(createAlphaLLRPPass(*this));
  79. PM.add(createAlphaCodePrinterPass(Out, *this, Fast, Verbose));
  80. return false;
  81. }
  82. bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
  83. bool DumpAsm, MachineCodeEmitter &MCE) {
  84. PM.add(createAlphaCodeEmitterPass(*this, MCE));
  85. if (DumpAsm)
  86. PM.add(createAlphaCodePrinterPass(errs(), *this, Fast, true));
  87. return false;
  88. }
  89. bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
  90. bool Fast, bool DumpAsm,
  91. MachineCodeEmitter &MCE) {
  92. return addCodeEmitter(PM, Fast, DumpAsm, MCE);
  93. }