PseudoSourceValue.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/CodeGen/MachineFrameInfo.h"
  15. #include "llvm/IR/DerivedTypes.h"
  16. #include "llvm/IR/LLVMContext.h"
  17. #include "llvm/Support/ErrorHandling.h"
  18. #include "llvm/Support/ManagedStatic.h"
  19. #include "llvm/Support/Mutex.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. #include <map>
  22. using namespace llvm;
  23. namespace {
  24. struct PSVGlobalsTy {
  25. // PseudoSourceValues are immutable so don't need locking.
  26. const PseudoSourceValue PSVs[4];
  27. sys::Mutex Lock; // Guards FSValues, but not the values inside it.
  28. std::map<int, const PseudoSourceValue *> FSValues;
  29. PSVGlobalsTy() : PSVs() {}
  30. ~PSVGlobalsTy() {
  31. for (std::map<int, const PseudoSourceValue *>::iterator
  32. I = FSValues.begin(), E = FSValues.end(); I != E; ++I) {
  33. delete I->second;
  34. }
  35. }
  36. };
  37. static ManagedStatic<PSVGlobalsTy> PSVGlobals;
  38. } // anonymous namespace
  39. const PseudoSourceValue *PseudoSourceValue::getStack()
  40. { return &PSVGlobals->PSVs[0]; }
  41. const PseudoSourceValue *PseudoSourceValue::getGOT()
  42. { return &PSVGlobals->PSVs[1]; }
  43. const PseudoSourceValue *PseudoSourceValue::getJumpTable()
  44. { return &PSVGlobals->PSVs[2]; }
  45. const PseudoSourceValue *PseudoSourceValue::getConstantPool()
  46. { return &PSVGlobals->PSVs[3]; }
  47. static const char *const PSVNames[] = {
  48. "Stack",
  49. "GOT",
  50. "JumpTable",
  51. "ConstantPool"
  52. };
  53. PseudoSourceValue::PseudoSourceValue(bool isFixed) : isFixed(isFixed) {}
  54. PseudoSourceValue::~PseudoSourceValue() {}
  55. void PseudoSourceValue::printCustom(raw_ostream &O) const {
  56. O << PSVNames[this - PSVGlobals->PSVs];
  57. }
  58. const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
  59. PSVGlobalsTy &PG = *PSVGlobals;
  60. sys::ScopedLock locked(PG.Lock);
  61. const PseudoSourceValue *&V = PG.FSValues[FI];
  62. if (!V)
  63. V = new FixedStackPseudoSourceValue(FI);
  64. return V;
  65. }
  66. bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
  67. if (this == getStack())
  68. return false;
  69. if (this == getGOT() ||
  70. this == getConstantPool() ||
  71. this == getJumpTable())
  72. return true;
  73. llvm_unreachable("Unknown PseudoSourceValue!");
  74. }
  75. bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
  76. if (this == getStack() ||
  77. this == getGOT() ||
  78. this == getConstantPool() ||
  79. this == getJumpTable())
  80. return false;
  81. llvm_unreachable("Unknown PseudoSourceValue!");
  82. }
  83. bool PseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
  84. if (this == getGOT() ||
  85. this == getConstantPool() ||
  86. this == getJumpTable())
  87. return false;
  88. return true;
  89. }
  90. bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
  91. return MFI && MFI->isImmutableObjectIndex(FI);
  92. }
  93. bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
  94. if (!MFI)
  95. return true;
  96. return MFI->isAliasedObjectIndex(FI);
  97. }
  98. bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
  99. if (!MFI)
  100. return true;
  101. // Spill slots will not alias any LLVM IR value.
  102. return !MFI->isSpillSlotObjectIndex(FI);
  103. }
  104. void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
  105. OS << "FixedStack" << FI;
  106. }