PseudoSourceValue.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
  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. // This file implements the PseudoSourceValue class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/PseudoSourceValue.h"
  14. #include "llvm/ADT/STLExtras.h"
  15. #include "llvm/CodeGen/MachineFrameInfo.h"
  16. #include "llvm/CodeGen/TargetInstrInfo.h"
  17. #include "llvm/IR/DerivedTypes.h"
  18. #include "llvm/IR/LLVMContext.h"
  19. #include "llvm/Support/ErrorHandling.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. using namespace llvm;
  22. static const char *const PSVNames[] = {
  23. "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
  24. "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
  25. PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
  26. : Kind(Kind) {
  27. AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
  28. }
  29. PseudoSourceValue::~PseudoSourceValue() {}
  30. void PseudoSourceValue::printCustom(raw_ostream &O) const {
  31. if (Kind < TargetCustom)
  32. O << PSVNames[Kind];
  33. else
  34. O << "TargetCustom" << Kind;
  35. }
  36. bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
  37. if (isStack())
  38. return false;
  39. if (isGOT() || isConstantPool() || isJumpTable())
  40. return true;
  41. llvm_unreachable("Unknown PseudoSourceValue!");
  42. }
  43. bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
  44. if (isStack() || isGOT() || isConstantPool() || isJumpTable())
  45. return false;
  46. llvm_unreachable("Unknown PseudoSourceValue!");
  47. }
  48. bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
  49. return !(isGOT() || isConstantPool() || isJumpTable());
  50. }
  51. bool FixedStackPseudoSourceValue::isConstant(
  52. const MachineFrameInfo *MFI) const {
  53. return MFI && MFI->isImmutableObjectIndex(FI);
  54. }
  55. bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
  56. if (!MFI)
  57. return true;
  58. return MFI->isAliasedObjectIndex(FI);
  59. }
  60. bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
  61. if (!MFI)
  62. return true;
  63. // Spill slots will not alias any LLVM IR value.
  64. return !MFI->isSpillSlotObjectIndex(FI);
  65. }
  66. void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
  67. OS << "FixedStack" << FI;
  68. }
  69. CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
  70. unsigned Kind, const TargetInstrInfo &TII)
  71. : PseudoSourceValue(Kind, TII) {}
  72. bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
  73. return false;
  74. }
  75. bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
  76. return false;
  77. }
  78. bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
  79. return false;
  80. }
  81. GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
  82. const GlobalValue *GV,
  83. const TargetInstrInfo &TII)
  84. : CallEntryPseudoSourceValue(GlobalValueCallEntry, TII), GV(GV) {}
  85. ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
  86. const char *ES, const TargetInstrInfo &TII)
  87. : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TII), ES(ES) {}
  88. PseudoSourceValueManager::PseudoSourceValueManager(
  89. const TargetInstrInfo &TIInfo)
  90. : TII(TIInfo),
  91. StackPSV(PseudoSourceValue::Stack, TII),
  92. GOTPSV(PseudoSourceValue::GOT, TII),
  93. JumpTablePSV(PseudoSourceValue::JumpTable, TII),
  94. ConstantPoolPSV(PseudoSourceValue::ConstantPool, TII) {}
  95. const PseudoSourceValue *PseudoSourceValueManager::getStack() {
  96. return &StackPSV;
  97. }
  98. const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
  99. const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
  100. return &ConstantPoolPSV;
  101. }
  102. const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
  103. return &JumpTablePSV;
  104. }
  105. const PseudoSourceValue *
  106. PseudoSourceValueManager::getFixedStack(int FI) {
  107. std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
  108. if (!V)
  109. V = llvm::make_unique<FixedStackPseudoSourceValue>(FI, TII);
  110. return V.get();
  111. }
  112. const PseudoSourceValue *
  113. PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
  114. std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
  115. GlobalCallEntries[GV];
  116. if (!E)
  117. E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV, TII);
  118. return E.get();
  119. }
  120. const PseudoSourceValue *
  121. PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
  122. std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
  123. ExternalCallEntries[ES];
  124. if (!E)
  125. E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES, TII);
  126. return E.get();
  127. }