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 StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
29 sys::Mutex Lock; // Guards FSValues, but not the values inside it.
30 std::map<int, const PseudoSourceValue *> FSValues;
33 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
34 JumpTablePSV(PseudoSourceValue::JumpTable),
35 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
37 for (std::map<int, const PseudoSourceValue *>::iterator
46 static ManagedStatic<PSVGlobalsTy> PSVGlobals;
48 } // anonymous namespace
50 const PseudoSourceValue *PseudoSourceValue::getStack() {
51 return &PSVGlobals->StackPSV;
53 const PseudoSourceValue *PseudoSourceValue::getGOT() {
54 return &PSVGlobals->GOTPSV;
56 const PseudoSourceValue *PseudoSourceValue::getJumpTable() {
57 return &PSVGlobals->JumpTablePSV;
59 const PseudoSourceValue *PseudoSourceValue::getConstantPool() {
60 return &PSVGlobals->ConstantPoolPSV;
63 static const char *const PSVNames[] = {
64 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack", "MipsCallEntry"};
66 PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {}
68 PseudoSourceValue::~PseudoSourceValue() {}
70 void PseudoSourceValue::printCustom(raw_ostream &O) const {
74 const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
75 PSVGlobalsTy &PG = *PSVGlobals;
76 sys::ScopedLock locked(PG.Lock);
77 const PseudoSourceValue *&V = PG.FSValues[FI];
79 V = new FixedStackPseudoSourceValue(FI);
83 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
86 if (isGOT() || isConstantPool() || isJumpTable())
88 llvm_unreachable("Unknown PseudoSourceValue!");
91 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
92 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
94 llvm_unreachable("Unknown PseudoSourceValue!");
97 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
98 if (isGOT() || isConstantPool() || isJumpTable())
103 bool FixedStackPseudoSourceValue::isConstant(
104 const MachineFrameInfo *MFI) const {
105 return MFI && MFI->isImmutableObjectIndex(FI);
108 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
111 return MFI->isAliasedObjectIndex(FI);
114 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
117 // Spill slots will not alias any LLVM IR value.
118 return !MFI->isSpillSlotObjectIndex(FI);
121 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
122 OS << "FixedStack" << FI;