1 //===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PseudoSourceValue class.
12 //===----------------------------------------------------------------------===//
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"
26 static const char *const PSVNames[] = {
27 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
28 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
30 PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {}
32 PseudoSourceValue::~PseudoSourceValue() {}
34 void PseudoSourceValue::printCustom(raw_ostream &O) const {
38 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
41 if (isGOT() || isConstantPool() || isJumpTable())
43 llvm_unreachable("Unknown PseudoSourceValue!");
46 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
47 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
49 llvm_unreachable("Unknown PseudoSourceValue!");
52 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
53 if (isGOT() || isConstantPool() || isJumpTable())
58 bool FixedStackPseudoSourceValue::isConstant(
59 const MachineFrameInfo *MFI) const {
60 return MFI && MFI->isImmutableObjectIndex(FI);
63 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
66 return MFI->isAliasedObjectIndex(FI);
69 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
72 // Spill slots will not alias any LLVM IR value.
73 return !MFI->isSpillSlotObjectIndex(FI);
76 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
77 OS << "FixedStack" << FI;
80 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
81 : PseudoSourceValue(Kind) {}
83 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
87 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
91 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
95 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
96 const GlobalValue *GV)
97 : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
99 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
100 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
102 PseudoSourceValueManager::PseudoSourceValueManager()
103 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
104 JumpTablePSV(PseudoSourceValue::JumpTable),
105 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
107 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
111 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
113 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
114 return &ConstantPoolPSV;
117 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
118 return &JumpTablePSV;
121 const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
122 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
124 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
128 const PseudoSourceValue *
129 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
130 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
131 GlobalCallEntries[GV];
133 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
137 const PseudoSourceValue *
138 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
139 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
140 ExternalCallEntries[ES];
142 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);