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"
19 #include "llvm/Support/raw_ostream.h"
23 static ManagedStatic
<PseudoSourceValue
[4]> PSVs
;
25 const PseudoSourceValue
*PseudoSourceValue::getStack()
26 { return &(*PSVs
)[0]; }
27 const PseudoSourceValue
*PseudoSourceValue::getGOT()
28 { return &(*PSVs
)[1]; }
29 const PseudoSourceValue
*PseudoSourceValue::getJumpTable()
30 { return &(*PSVs
)[2]; }
31 const PseudoSourceValue
*PseudoSourceValue::getConstantPool()
32 { return &(*PSVs
)[3]; }
34 static const char *const PSVNames
[] = {
41 PseudoSourceValue::PseudoSourceValue() :
42 Value(PointerType::getUnqual(Type::Int8Ty
), PseudoSourceValueVal
) {}
44 void PseudoSourceValue::dump() const {
45 print(errs()); errs() << '\n';
48 void PseudoSourceValue::print(raw_ostream
&OS
) const {
49 OS
<< PSVNames
[this - *PSVs
];
53 /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
54 /// for holding FixedStack values, which must include a frame
56 class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
57 : public PseudoSourceValue
{
60 explicit FixedStackPseudoSourceValue(int fi
) : FI(fi
) {}
62 virtual bool isConstant(const MachineFrameInfo
*MFI
) const;
64 virtual void print(raw_ostream
&OS
) const {
65 OS
<< "FixedStack" << FI
;
70 static ManagedStatic
<std::map
<int, const PseudoSourceValue
*> > FSValues
;
72 const PseudoSourceValue
*PseudoSourceValue::getFixedStack(int FI
) {
73 const PseudoSourceValue
*&V
= (*FSValues
)[FI
];
75 V
= new FixedStackPseudoSourceValue(FI
);
79 bool PseudoSourceValue::isConstant(const MachineFrameInfo
*) const {
80 if (this == getStack())
82 if (this == getGOT() ||
83 this == getConstantPool() ||
84 this == getJumpTable())
86 assert(0 && "Unknown PseudoSourceValue!");
90 bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo
*MFI
) const{
91 return MFI
&& MFI
->isImmutableObjectIndex(FI
);