1 //===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PseudoSourceValue class.
12 //===----------------------------------------------------------------------===//
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"
24 static ManagedStatic
<PseudoSourceValue
[4]> PSVs
;
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]; }
35 static const char *const PSVNames
[] = {
42 PseudoSourceValue::PseudoSourceValue() :
43 Value(PointerType::getUnqual(Type::Int8Ty
), PseudoSourceValueVal
) {}
45 void PseudoSourceValue::dump() const {
46 print(errs()); errs() << '\n';
49 void PseudoSourceValue::print(raw_ostream
&OS
) const {
50 OS
<< PSVNames
[this - *PSVs
];
54 /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
55 /// for holding FixedStack values, which must include a frame
57 class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
58 : public PseudoSourceValue
{
61 explicit FixedStackPseudoSourceValue(int fi
) : FI(fi
) {}
63 virtual bool isConstant(const MachineFrameInfo
*MFI
) const;
65 virtual void print(raw_ostream
&OS
) const {
66 OS
<< "FixedStack" << FI
;
71 static ManagedStatic
<std::map
<int, const PseudoSourceValue
*> > FSValues
;
73 const PseudoSourceValue
*PseudoSourceValue::getFixedStack(int FI
) {
74 const PseudoSourceValue
*&V
= (*FSValues
)[FI
];
76 V
= new FixedStackPseudoSourceValue(FI
);
80 bool PseudoSourceValue::isConstant(const MachineFrameInfo
*) const {
81 if (this == getStack())
83 if (this == getGOT() ||
84 this == getConstantPool() ||
85 this == getJumpTable())
87 llvm_unreachable("Unknown PseudoSourceValue!");
91 bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo
*MFI
) const{
92 return MFI
&& MFI
->isImmutableObjectIndex(FI
);