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 return !(isGOT() || isConstantPool() || isJumpTable());
56 bool FixedStackPseudoSourceValue::isConstant(
57 const MachineFrameInfo *MFI) const {
58 return MFI && MFI->isImmutableObjectIndex(FI);
61 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
64 return MFI->isAliasedObjectIndex(FI);
67 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
70 // Spill slots will not alias any LLVM IR value.
71 return !MFI->isSpillSlotObjectIndex(FI);
74 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
75 OS << "FixedStack" << FI;
78 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
79 : PseudoSourceValue(Kind) {}
81 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
85 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
89 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
93 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
94 const GlobalValue *GV)
95 : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
97 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
98 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
100 PseudoSourceValueManager::PseudoSourceValueManager()
101 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
102 JumpTablePSV(PseudoSourceValue::JumpTable),
103 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
105 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
109 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
111 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
112 return &ConstantPoolPSV;
115 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
116 return &JumpTablePSV;
119 const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
120 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
122 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
126 const PseudoSourceValue *
127 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
128 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
129 GlobalCallEntries[GV];
131 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
135 const PseudoSourceValue *
136 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
137 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
138 ExternalCallEntries[ES];
140 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);