Array element size does not match array size but array is not a bitfield.
[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/LLVMContext.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 bool mayAlias(const MachineFrameInfo *) const;
68
69     virtual void printCustom(raw_ostream &OS) const {
70       OS << "FixedStack" << FI;
71     }
72   };
73 }
74
75 static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
76
77 const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
78   const PseudoSourceValue *&V = (*FSValues)[FI];
79   if (!V)
80     V = new FixedStackPseudoSourceValue(FI);
81   return V;
82 }
83
84 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
85   if (this == getStack())
86     return false;
87   if (this == getGOT() ||
88       this == getConstantPool() ||
89       this == getJumpTable())
90     return true;
91   llvm_unreachable("Unknown PseudoSourceValue!");
92   return false;
93 }
94
95 bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
96   if (this == getStack() ||
97       this == getGOT() ||
98       this == getConstantPool() ||
99       this == getJumpTable())
100     return false;
101   llvm_unreachable("Unknown PseudoSourceValue!");
102   return true;
103 }
104
105 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
106   if (this == getGOT() ||
107       this == getConstantPool() ||
108       this == getJumpTable())
109     return false;
110   return true;
111 }
112
113 bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
114   return MFI && MFI->isImmutableObjectIndex(FI);
115 }
116
117 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
118   // Negative frame indices are used for special things that don't
119   // appear in LLVM IR. Non-negative indices may be used for things
120   // like static allocas.
121   if (!MFI)
122     return FI >= 0;
123   // Spill slots should not alias others.
124   return !MFI->isFixedObjectIndex(FI) && !MFI->isSpillSlotObjectIndex(FI);
125 }
126
127 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
128   if (!MFI)
129     return true;
130   // Spill slots will not alias any LLVM IR value.
131   return !MFI->isSpillSlotObjectIndex(FI);
132 }