PseudoSourceValue.cpp 4.7 KB

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