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/PseudoSourceValue.h"
15 #include "llvm/CodeGen/MachineFrameInfo.h"
16 #include "llvm/IR/DerivedTypes.h"
17 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/ManagedStatic.h"
20 #include "llvm/Support/Mutex.h"
21 #include "llvm/Support/raw_ostream.h"
27 // PseudoSourceValues are immutable so don't need locking.
28 const PseudoSourceValue PSVs[4];
29 sys::Mutex Lock; // Guards FSValues, but not the values inside it.
30 std::map<int, const PseudoSourceValue *> FSValues;
32 PSVGlobalsTy() : PSVs() {}
34 for (std::map<int, const PseudoSourceValue *>::iterator
35 I = FSValues.begin(), E = FSValues.end(); I != E; ++I) {
41 static ManagedStatic<PSVGlobalsTy> PSVGlobals;
43 } // anonymous namespace
45 const PseudoSourceValue *PseudoSourceValue::getStack()
46 { return &PSVGlobals->PSVs[0]; }
47 const PseudoSourceValue *PseudoSourceValue::getGOT()
48 { return &PSVGlobals->PSVs[1]; }
49 const PseudoSourceValue *PseudoSourceValue::getJumpTable()
50 { return &PSVGlobals->PSVs[2]; }
51 const PseudoSourceValue *PseudoSourceValue::getConstantPool()
52 { return &PSVGlobals->PSVs[3]; }
54 static const char *const PSVNames[] = {
61 // FIXME: THIS IS A HACK!!!!
62 // Eventually these should be uniqued on LLVMContext rather than in a managed
63 // static. For now, we can safely use the global context for the time being to
65 PseudoSourceValue::PseudoSourceValue(enum ValueTy Subclass) :
66 Value(Type::getInt8PtrTy(getGlobalContext()),
69 void PseudoSourceValue::printCustom(raw_ostream &O) const {
70 O << PSVNames[this - PSVGlobals->PSVs];
73 const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
74 PSVGlobalsTy &PG = *PSVGlobals;
75 sys::ScopedLock locked(PG.Lock);
76 const PseudoSourceValue *&V = PG.FSValues[FI];
78 V = new FixedStackPseudoSourceValue(FI);
82 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
83 if (this == getStack())
85 if (this == getGOT() ||
86 this == getConstantPool() ||
87 this == getJumpTable())
89 llvm_unreachable("Unknown PseudoSourceValue!");
92 bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
93 if (this == getStack() ||
95 this == getConstantPool() ||
96 this == getJumpTable())
98 llvm_unreachable("Unknown PseudoSourceValue!");
101 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
102 if (this == getGOT() ||
103 this == getConstantPool() ||
104 this == getJumpTable())
109 bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
110 return MFI && MFI->isImmutableObjectIndex(FI);
113 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
114 // Negative frame indices are used for special things that don't
115 // appear in LLVM IR. Non-negative indices may be used for things
116 // like static allocas.
119 // Spill slots should not alias others.
120 return !MFI->isFixedObjectIndex(FI) && !MFI->isSpillSlotObjectIndex(FI);
123 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
126 // Spill slots will not alias any LLVM IR value.
127 return !MFI->isSpillSlotObjectIndex(FI);
130 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
131 OS << "FixedStack" << FI;