PseudoSourceValue.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/Compiler.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() :
  42. Value(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext())),
  43. PseudoSourceValueVal) {}
  44. void PseudoSourceValue::dump() const {
  45. print(errs()); errs() << '\n';
  46. }
  47. void PseudoSourceValue::print(raw_ostream &OS) const {
  48. OS << PSVNames[this - *PSVs];
  49. }
  50. namespace {
  51. /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
  52. /// for holding FixedStack values, which must include a frame
  53. /// index.
  54. class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
  55. : public PseudoSourceValue {
  56. const int FI;
  57. public:
  58. explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
  59. virtual bool isConstant(const MachineFrameInfo *MFI) const;
  60. virtual void print(raw_ostream &OS) const {
  61. OS << "FixedStack" << FI;
  62. }
  63. };
  64. }
  65. static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
  66. const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
  67. const PseudoSourceValue *&V = (*FSValues)[FI];
  68. if (!V)
  69. V = new FixedStackPseudoSourceValue(FI);
  70. return V;
  71. }
  72. bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
  73. if (this == getStack())
  74. return false;
  75. if (this == getGOT() ||
  76. this == getConstantPool() ||
  77. this == getJumpTable())
  78. return true;
  79. llvm_unreachable("Unknown PseudoSourceValue!");
  80. return false;
  81. }
  82. bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
  83. return MFI && MFI->isImmutableObjectIndex(FI);
  84. }