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