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/CodeGen/PseudoSourceValue.h"
15 #include "llvm/ADT/STLExtras.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/raw_ostream.h"
23 static const char *const PSVNames[] = {
24 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
25 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
27 PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {}
29 PseudoSourceValue::~PseudoSourceValue() {}
31 void PseudoSourceValue::printCustom(raw_ostream &O) const {
35 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
38 if (isGOT() || isConstantPool() || isJumpTable())
40 llvm_unreachable("Unknown PseudoSourceValue!");
43 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
44 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
46 llvm_unreachable("Unknown PseudoSourceValue!");
49 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
50 return !(isGOT() || isConstantPool() || isJumpTable());
53 bool FixedStackPseudoSourceValue::isConstant(
54 const MachineFrameInfo *MFI) const {
55 return MFI && MFI->isImmutableObjectIndex(FI);
58 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
61 return MFI->isAliasedObjectIndex(FI);
64 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
67 // Spill slots will not alias any LLVM IR value.
68 return !MFI->isSpillSlotObjectIndex(FI);
71 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
72 OS << "FixedStack" << FI;
75 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
76 : PseudoSourceValue(Kind) {}
78 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
82 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
86 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
90 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
91 const GlobalValue *GV)
92 : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
94 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
95 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
97 PseudoSourceValueManager::PseudoSourceValueManager()
98 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
99 JumpTablePSV(PseudoSourceValue::JumpTable),
100 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
102 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
106 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
108 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
109 return &ConstantPoolPSV;
112 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
113 return &JumpTablePSV;
116 const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
117 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
119 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
123 const PseudoSourceValue *
124 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
125 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
126 GlobalCallEntries[GV];
128 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
132 const PseudoSourceValue *
133 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
134 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
135 ExternalCallEntries[ES];
137 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);