[PM/AA] Hoist ScopedNoAliasAA's interface into a header and move the
[oota-llvm.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/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
30 PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {}
31
32 PseudoSourceValue::~PseudoSourceValue() {}
33
34 void PseudoSourceValue::printCustom(raw_ostream &O) const {
35   O << PSVNames[Kind];
36 }
37
38 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
46 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
47   if (isStack() || isGOT() || isConstantPool() || isJumpTable())
48     return false;
49   llvm_unreachable("Unknown PseudoSourceValue!");
50 }
51
52 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
53   if (isGOT() || isConstantPool() || isJumpTable())
54     return false;
55   return true;
56 }
57
58 bool FixedStackPseudoSourceValue::isConstant(
59     const MachineFrameInfo *MFI) const {
60   return MFI && MFI->isImmutableObjectIndex(FI);
61 }
62
63 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
64   if (!MFI)
65     return true;
66   return MFI->isAliasedObjectIndex(FI);
67 }
68
69 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
70   if (!MFI)
71     return true;
72   // Spill slots will not alias any LLVM IR value.
73   return !MFI->isSpillSlotObjectIndex(FI);
74 }
75
76 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
77   OS << "FixedStack" << FI;
78 }
79
80 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
81     : PseudoSourceValue(Kind) {}
82
83 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
84   return false;
85 }
86
87 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
88   return false;
89 }
90
91 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
92   return false;
93 }
94
95 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
96     const GlobalValue *GV)
97     : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
98
99 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
100     : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
101
102 PseudoSourceValueManager::PseudoSourceValueManager()
103     : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
104       JumpTablePSV(PseudoSourceValue::JumpTable),
105       ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
106
107 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
108   return &StackPSV;
109 }
110
111 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
112
113 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
114   return &ConstantPoolPSV;
115 }
116
117 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
118   return &JumpTablePSV;
119 }
120
121 const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
122   std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
123   if (!V)
124     V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
125   return V.get();
126 }
127
128 const PseudoSourceValue *
129 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
130   std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
131       GlobalCallEntries[GV];
132   if (!E)
133     E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
134   return E.get();
135 }
136
137 const PseudoSourceValue *
138 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
139   std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
140       ExternalCallEntries[ES];
141   if (!E)
142     E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);
143   return E.get();
144 }