PseudoSourceValue.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/MachineFrameInfo.h"
  14. #include "llvm/CodeGen/PseudoSourceValue.h"
  15. #include "llvm/DerivedTypes.h"
  16. #include "llvm/Support/ErrorHandling.h"
  17. #include "llvm/Support/ManagedStatic.h"
  18. #include "llvm/Support/raw_ostream.h"
  19. #include <map>
  20. using namespace llvm;
  21. static ManagedStatic<PseudoSourceValue[4]> PSVs;
  22. const PseudoSourceValue *PseudoSourceValue::getStack()
  23. { return &(*PSVs)[0]; }
  24. const PseudoSourceValue *PseudoSourceValue::getGOT()
  25. { return &(*PSVs)[1]; }
  26. const PseudoSourceValue *PseudoSourceValue::getJumpTable()
  27. { return &(*PSVs)[2]; }
  28. const PseudoSourceValue *PseudoSourceValue::getConstantPool()
  29. { return &(*PSVs)[3]; }
  30. static const char *const PSVNames[] = {
  31. "Stack",
  32. "GOT",
  33. "JumpTable",
  34. "ConstantPool"
  35. };
  36. // FIXME: THIS IS A HACK!!!!
  37. // Eventually these should be uniqued on LLVMContext rather than in a managed
  38. // static. For now, we can safely use the global context for the time being to
  39. // squeak by.
  40. PseudoSourceValue::PseudoSourceValue() :
  41. Value(Type::getInt8PtrTy(getGlobalContext()),
  42. PseudoSourceValueVal) {}
  43. void PseudoSourceValue::printCustom(raw_ostream &O) const {
  44. O << PSVNames[this - *PSVs];
  45. }
  46. namespace {
  47. /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
  48. /// for holding FixedStack values, which must include a frame
  49. /// index.
  50. class FixedStackPseudoSourceValue : public PseudoSourceValue {
  51. const int FI;
  52. public:
  53. explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
  54. virtual bool isConstant(const MachineFrameInfo *MFI) const;
  55. virtual bool isAliased(const MachineFrameInfo *MFI) const;
  56. virtual void printCustom(raw_ostream &OS) const {
  57. OS << "FixedStack" << FI;
  58. }
  59. };
  60. }
  61. static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
  62. const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
  63. const PseudoSourceValue *&V = (*FSValues)[FI];
  64. if (!V)
  65. V = new FixedStackPseudoSourceValue(FI);
  66. return V;
  67. }
  68. bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
  69. if (this == getStack())
  70. return false;
  71. if (this == getGOT() ||
  72. this == getConstantPool() ||
  73. this == getJumpTable())
  74. return true;
  75. llvm_unreachable("Unknown PseudoSourceValue!");
  76. return false;
  77. }
  78. bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
  79. if (this == getStack() ||
  80. this == getGOT() ||
  81. this == getConstantPool() ||
  82. this == getJumpTable())
  83. return false;
  84. llvm_unreachable("Unknown PseudoSourceValue!");
  85. return true;
  86. }
  87. bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
  88. return MFI && MFI->isImmutableObjectIndex(FI);
  89. }
  90. bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
  91. // Negative frame indices are used for special things that don't
  92. // appear in LLVM IR. Non-negative indices may be used for things
  93. // like static allocas.
  94. if (!MFI)
  95. return FI >= 0;
  96. // Spill slots should not alias others.
  97. return !MFI->isFixedObjectIndex(FI) && !MFI->isSpillSlotObjectIndex(FI);
  98. }