PseudoSourceValue.cpp revision c23197a26f34f559ea9797de51e187087c039c42
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
14#include "llvm/CodeGen/MachineFrameInfo.h"
15#include "llvm/CodeGen/PseudoSourceValue.h"
16#include "llvm/DerivedTypes.h"
17#include "llvm/Support/Compiler.h"
18#include "llvm/Support/ErrorHandling.h"
19#include "llvm/Support/ManagedStatic.h"
20#include "llvm/Support/raw_ostream.h"
21#include <map>
22using namespace llvm;
23
24static ManagedStatic<PseudoSourceValue[4]> PSVs;
25
26const PseudoSourceValue *PseudoSourceValue::getStack()
27{ return &(*PSVs)[0]; }
28const PseudoSourceValue *PseudoSourceValue::getGOT()
29{ return &(*PSVs)[1]; }
30const PseudoSourceValue *PseudoSourceValue::getJumpTable()
31{ return &(*PSVs)[2]; }
32const PseudoSourceValue *PseudoSourceValue::getConstantPool()
33{ return &(*PSVs)[3]; }
34
35static const char *const PSVNames[] = {
36  "Stack",
37  "GOT",
38  "JumpTable",
39  "ConstantPool"
40};
41
42PseudoSourceValue::PseudoSourceValue() :
43  Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {}
44
45void PseudoSourceValue::dump() const {
46  print(errs()); errs() << '\n';
47}
48
49void PseudoSourceValue::print(raw_ostream &OS) const {
50  OS << PSVNames[this - *PSVs];
51}
52
53namespace {
54  /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
55  /// for holding FixedStack values, which must include a frame
56  /// index.
57  class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
58    : public PseudoSourceValue {
59    const int FI;
60  public:
61    explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
62
63    virtual bool isConstant(const MachineFrameInfo *MFI) const;
64
65    virtual void print(raw_ostream &OS) const {
66      OS << "FixedStack" << FI;
67    }
68  };
69}
70
71static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
72
73const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
74  const PseudoSourceValue *&V = (*FSValues)[FI];
75  if (!V)
76    V = new FixedStackPseudoSourceValue(FI);
77  return V;
78}
79
80bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
81  if (this == getStack())
82    return false;
83  if (this == getGOT() ||
84      this == getConstantPool() ||
85      this == getJumpTable())
86    return true;
87  llvm_unreachable("Unknown PseudoSourceValue!");
88  return false;
89}
90
91bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
92  return MFI && MFI->isImmutableObjectIndex(FI);
93}
94