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