PseudoSourceValue.cpp 4.4 KB

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