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", "MipsCallEntry"}; 28 29 PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {} 30 31 PseudoSourceValue::~PseudoSourceValue() {} 32 33 void PseudoSourceValue::printCustom(raw_ostream &O) const { 34 O << PSVNames[Kind]; 35 } 36 37 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { 38 if (isStack()) 39 return false; 40 if (isGOT() || isConstantPool() || isJumpTable()) 41 return true; 42 llvm_unreachable("Unknown PseudoSourceValue!"); 43 } 44 45 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const { 46 if (isStack() || isGOT() || isConstantPool() || isJumpTable()) 47 return false; 48 llvm_unreachable("Unknown PseudoSourceValue!"); 49 } 50 51 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const { 52 if (isGOT() || isConstantPool() || isJumpTable()) 53 return false; 54 return true; 55 } 56 57 bool FixedStackPseudoSourceValue::isConstant( 58 const MachineFrameInfo *MFI) const { 59 return MFI && MFI->isImmutableObjectIndex(FI); 60 } 61 62 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { 63 if (!MFI) 64 return true; 65 return MFI->isAliasedObjectIndex(FI); 66 } 67 68 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const { 69 if (!MFI) 70 return true; 71 // Spill slots will not alias any LLVM IR value. 72 return !MFI->isSpillSlotObjectIndex(FI); 73 } 74 75 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const { 76 OS << "FixedStack" << FI; 77 } 78 79 PseudoSourceValueManager::PseudoSourceValueManager() 80 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT), 81 JumpTablePSV(PseudoSourceValue::JumpTable), 82 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {} 83 84 const PseudoSourceValue *PseudoSourceValueManager::getStack() { 85 return &StackPSV; 86 } 87 88 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; } 89 90 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() { 91 return &ConstantPoolPSV; 92 } 93 94 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() { 95 return &JumpTablePSV; 96 } 97 98 const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) { 99 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI]; 100 if (!V) 101 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI); 102 return V.get(); 103 } 104