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