PseudoSourceValue.cpp 3.5 KB

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