1 //===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the PseudoSourceValue class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/CodeGen/PseudoSourceValue.h"
16 #include "llvm/CodeGen/MachineFrameInfo.h"
17 #include "llvm/IR/DerivedTypes.h"
18 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/ManagedStatic.h"
21 #include "llvm/Support/Mutex.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include <map>
24 using namespace llvm;
25
26 static const char *const PSVNames[] = {
27 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
28 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
29
PseudoSourceValue(PSVKind Kind)30 PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {}
31
~PseudoSourceValue()32 PseudoSourceValue::~PseudoSourceValue() {}
33
printCustom(raw_ostream & O) const34 void PseudoSourceValue::printCustom(raw_ostream &O) const {
35 O << PSVNames[Kind];
36 }
37
isConstant(const MachineFrameInfo *) const38 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
39 if (isStack())
40 return false;
41 if (isGOT() || isConstantPool() || isJumpTable())
42 return true;
43 llvm_unreachable("Unknown PseudoSourceValue!");
44 }
45
isAliased(const MachineFrameInfo *) const46 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
47 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
48 return false;
49 llvm_unreachable("Unknown PseudoSourceValue!");
50 }
51
mayAlias(const MachineFrameInfo *) const52 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
53 return !(isGOT() || isConstantPool() || isJumpTable());
54 }
55
isConstant(const MachineFrameInfo * MFI) const56 bool FixedStackPseudoSourceValue::isConstant(
57 const MachineFrameInfo *MFI) const {
58 return MFI && MFI->isImmutableObjectIndex(FI);
59 }
60
isAliased(const MachineFrameInfo * MFI) const61 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
62 if (!MFI)
63 return true;
64 return MFI->isAliasedObjectIndex(FI);
65 }
66
mayAlias(const MachineFrameInfo * MFI) const67 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
68 if (!MFI)
69 return true;
70 // Spill slots will not alias any LLVM IR value.
71 return !MFI->isSpillSlotObjectIndex(FI);
72 }
73
printCustom(raw_ostream & OS) const74 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
75 OS << "FixedStack" << FI;
76 }
77
CallEntryPseudoSourceValue(PSVKind Kind)78 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
79 : PseudoSourceValue(Kind) {}
80
isConstant(const MachineFrameInfo *) const81 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
82 return false;
83 }
84
isAliased(const MachineFrameInfo *) const85 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
86 return false;
87 }
88
mayAlias(const MachineFrameInfo *) const89 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
90 return false;
91 }
92
GlobalValuePseudoSourceValue(const GlobalValue * GV)93 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
94 const GlobalValue *GV)
95 : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
96
ExternalSymbolPseudoSourceValue(const char * ES)97 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
98 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
99
PseudoSourceValueManager()100 PseudoSourceValueManager::PseudoSourceValueManager()
101 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
102 JumpTablePSV(PseudoSourceValue::JumpTable),
103 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
104
getStack()105 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
106 return &StackPSV;
107 }
108
getGOT()109 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
110
getConstantPool()111 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
112 return &ConstantPoolPSV;
113 }
114
getJumpTable()115 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
116 return &JumpTablePSV;
117 }
118
getFixedStack(int FI)119 const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
120 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
121 if (!V)
122 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
123 return V.get();
124 }
125
126 const PseudoSourceValue *
getGlobalValueCallEntry(const GlobalValue * GV)127 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
128 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
129 GlobalCallEntries[GV];
130 if (!E)
131 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
132 return E.get();
133 }
134
135 const PseudoSourceValue *
getExternalSymbolCallEntry(const char * ES)136 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
137 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
138 ExternalCallEntries[ES];
139 if (!E)
140 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);
141 return E.get();
142 }
143