]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/CodeGen/PseudoSourceValue.cpp
Vendor import of llvm trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / lib / CodeGen / PseudoSourceValue.cpp
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
28 PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
29     : Kind(Kind) {
30   AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
31 }
32
33
34 PseudoSourceValue::~PseudoSourceValue() {}
35
36 void PseudoSourceValue::printCustom(raw_ostream &O) const {
37   if (Kind < TargetCustom)
38     O << PSVNames[Kind];
39   else
40     O << "TargetCustom" << Kind;
41 }
42
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!");
49 }
50
51 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
52   if (isStack() || isGOT() || isConstantPool() || isJumpTable())
53     return false;
54   llvm_unreachable("Unknown PseudoSourceValue!");
55 }
56
57 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
58   return !(isGOT() || isConstantPool() || isJumpTable());
59 }
60
61 bool FixedStackPseudoSourceValue::isConstant(
62     const MachineFrameInfo *MFI) const {
63   return MFI && MFI->isImmutableObjectIndex(FI);
64 }
65
66 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
67   if (!MFI)
68     return true;
69   return MFI->isAliasedObjectIndex(FI);
70 }
71
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);
77 }
78
79 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
80   OS << "FixedStack" << FI;
81 }
82
83 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
84     unsigned Kind, const TargetInstrInfo &TII)
85     : PseudoSourceValue(Kind, TII) {}
86
87 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
88   return false;
89 }
90
91 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
92   return false;
93 }
94
95 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
96   return false;
97 }
98
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) {}
106
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
115 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
116   return &StackPSV;
117 }
118
119 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
120
121 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
122   return &ConstantPoolPSV;
123 }
124
125 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
126   return &JumpTablePSV;
127 }
128
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();
135 }
136
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();
144 }
145
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();
153 }