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/ManagedStatic.h"
22 static ManagedStatic<PseudoSourceValue[4]> PSVs;
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]; }
33 static const char *const PSVNames[] = {
40 PseudoSourceValue::PseudoSourceValue() :
41 Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {}
43 void PseudoSourceValue::print(std::ostream &OS) const {
44 OS << PSVNames[this - *PSVs];
47 /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
48 /// for holding FixedStack values, which must include a frame
50 class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
51 : public PseudoSourceValue {
54 explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
56 virtual bool isConstant(const MachineFrameInfo *MFI) const;
58 virtual void print(std::ostream &OS) const {
59 OS << "FixedStack" << FI;
63 static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
65 const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
66 const PseudoSourceValue *&V = (*FSValues)[FI];
68 V = new FixedStackPseudoSourceValue(FI);
72 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
73 if (this == getStack())
75 if (this == getGOT() ||
76 this == getConstantPool() ||
77 this == getJumpTable())
79 assert(0 && "Unknown PseudoSourceValue!");
84 FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const {
85 return MFI && MFI->isImmutableObjectIndex(FI);