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/CodeGen/PseudoSourceValue.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/CodeGen/MachineFrameInfo.h"
17 #include "llvm/CodeGen/TargetInstrInfo.h"
18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/raw_ostream.h"
22 using namespace llvm;
23
24 static const char *const PSVNames[] = {
25 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
26 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
27
PseudoSourceValue(PSVKind Kind,const TargetInstrInfo & TII)28 PseudoSourceValue::PseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII)
29 : Kind(Kind) {
30 AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
31 }
32
33
~PseudoSourceValue()34 PseudoSourceValue::~PseudoSourceValue() {}
35
printCustom(raw_ostream & O) const36 void PseudoSourceValue::printCustom(raw_ostream &O) const {
37 if (Kind < TargetCustom)
38 O << PSVNames[Kind];
39 else
40 O << "TargetCustom" << Kind;
41 }
42
isConstant(const MachineFrameInfo *) const43 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
44 if (isStack())
45 return false;
46 if (isGOT() || isConstantPool() || isJumpTable())
47 return true;
48 llvm_unreachable("Unknown PseudoSourceValue!");
49 }
50
isAliased(const MachineFrameInfo *) const51 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
52 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
53 return false;
54 llvm_unreachable("Unknown PseudoSourceValue!");
55 }
56
mayAlias(const MachineFrameInfo *) const57 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
58 return !(isGOT() || isConstantPool() || isJumpTable());
59 }
60
isConstant(const MachineFrameInfo * MFI) const61 bool FixedStackPseudoSourceValue::isConstant(
62 const MachineFrameInfo *MFI) const {
63 return MFI && MFI->isImmutableObjectIndex(FI);
64 }
65
isAliased(const MachineFrameInfo * MFI) const66 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
67 if (!MFI)
68 return true;
69 return MFI->isAliasedObjectIndex(FI);
70 }
71
mayAlias(const MachineFrameInfo * MFI) const72 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
73 if (!MFI)
74 return true;
75 // Spill slots will not alias any LLVM IR value.
76 return !MFI->isSpillSlotObjectIndex(FI);
77 }
78
printCustom(raw_ostream & OS) const79 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
80 OS << "FixedStack" << FI;
81 }
82
CallEntryPseudoSourceValue(PSVKind Kind,const TargetInstrInfo & TII)83 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
84 PSVKind Kind, const TargetInstrInfo &TII)
85 : PseudoSourceValue(Kind, TII) {}
86
isConstant(const MachineFrameInfo *) const87 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
88 return false;
89 }
90
isAliased(const MachineFrameInfo *) const91 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
92 return false;
93 }
94
mayAlias(const MachineFrameInfo *) const95 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
96 return false;
97 }
98
GlobalValuePseudoSourceValue(const GlobalValue * GV,const TargetInstrInfo & TII)99 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
100 const GlobalValue *GV,
101 const TargetInstrInfo &TII)
102 : CallEntryPseudoSourceValue(GlobalValueCallEntry, TII), GV(GV) {}
ExternalSymbolPseudoSourceValue(const char * ES,const TargetInstrInfo & TII)103 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
104 const char *ES, const TargetInstrInfo &TII)
105 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TII), ES(ES) {}
106
PseudoSourceValueManager(const TargetInstrInfo & TIInfo)107 PseudoSourceValueManager::PseudoSourceValueManager(
108 const TargetInstrInfo &TIInfo)
109 : TII(TIInfo),
110 StackPSV(PseudoSourceValue::Stack, TII),
111 GOTPSV(PseudoSourceValue::GOT, TII),
112 JumpTablePSV(PseudoSourceValue::JumpTable, TII),
113 ConstantPoolPSV(PseudoSourceValue::ConstantPool, TII) {}
114
getStack()115 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
116 return &StackPSV;
117 }
118
getGOT()119 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
120
getConstantPool()121 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
122 return &ConstantPoolPSV;
123 }
124
getJumpTable()125 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
126 return &JumpTablePSV;
127 }
128
129 const PseudoSourceValue *
getFixedStack(int FI)130 PseudoSourceValueManager::getFixedStack(int FI) {
131 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
132 if (!V)
133 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI, TII);
134 return V.get();
135 }
136
137 const PseudoSourceValue *
getGlobalValueCallEntry(const GlobalValue * GV)138 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
139 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
140 GlobalCallEntries[GV];
141 if (!E)
142 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV, TII);
143 return E.get();
144 }
145
146 const PseudoSourceValue *
getExternalSymbolCallEntry(const char * ES)147 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
148 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
149 ExternalCallEntries[ES];
150 if (!E)
151 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES, TII);
152 return E.get();
153 }
154