PseudoSourceValue.cpp 4.6 KB

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