[CallSite removal] Port `IndirectCallSiteVisitor` to use `CallBase` and
[llvm-complete.git] / lib / CodeGen / PseudoSourceValue.cpp
blob6ca8d86e3f8e12d6875189fce124139ced1d1633
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.
12 //===----------------------------------------------------------------------===//
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;
24 static const char *const PSVNames[] = {
25 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
26 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
28 PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
29 : Kind(Kind) {
30 AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
34 PseudoSourceValue::~PseudoSourceValue() {}
36 void PseudoSourceValue::printCustom(raw_ostream &O) const {
37 if (Kind < TargetCustom)
38 O << PSVNames[Kind];
39 else
40 O << "TargetCustom" << Kind;
43 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!");
51 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
52 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
53 return false;
54 llvm_unreachable("Unknown PseudoSourceValue!");
57 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
58 return !(isGOT() || isConstantPool() || isJumpTable());
61 bool FixedStackPseudoSourceValue::isConstant(
62 const MachineFrameInfo *MFI) const {
63 return MFI && MFI->isImmutableObjectIndex(FI);
66 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
67 if (!MFI)
68 return true;
69 return MFI->isAliasedObjectIndex(FI);
72 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);
79 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
80 OS << "FixedStack" << FI;
83 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
84 unsigned Kind, const TargetInstrInfo &TII)
85 : PseudoSourceValue(Kind, TII) {}
87 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
88 return false;
91 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
92 return false;
95 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
96 return false;
99 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
100 const GlobalValue *GV,
101 const TargetInstrInfo &TII)
102 : CallEntryPseudoSourceValue(GlobalValueCallEntry, TII), GV(GV) {}
103 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
104 const char *ES, const TargetInstrInfo &TII)
105 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TII), ES(ES) {}
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) {}
115 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
116 return &StackPSV;
119 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
121 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
122 return &ConstantPoolPSV;
125 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
126 return &JumpTablePSV;
129 const PseudoSourceValue *
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();
137 const PseudoSourceValue *
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();
146 const PseudoSourceValue *
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();