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