PseudoSourceValue.cpp revision 360784
1//===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file implements the PseudoSourceValue class. 10// 11//===----------------------------------------------------------------------===// 12 13#include "llvm/CodeGen/PseudoSourceValue.h" 14#include "llvm/ADT/STLExtras.h" 15#include "llvm/CodeGen/MachineFrameInfo.h" 16#include "llvm/CodeGen/TargetInstrInfo.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" 21using namespace llvm; 22 23static const char *const PSVNames[] = { 24 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack", 25 "GlobalValueCallEntry", "ExternalSymbolCallEntry"}; 26 27PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII) 28 : Kind(Kind) { 29 AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind); 30} 31 32 33PseudoSourceValue::~PseudoSourceValue() {} 34 35void PseudoSourceValue::printCustom(raw_ostream &O) const { 36 if (Kind < TargetCustom) 37 O << PSVNames[Kind]; 38 else 39 O << "TargetCustom" << Kind; 40} 41 42bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { 43 if (isStack()) 44 return false; 45 if (isGOT() || isConstantPool() || isJumpTable()) 46 return true; 47 llvm_unreachable("Unknown PseudoSourceValue!"); 48} 49 50bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const { 51 if (isStack() || isGOT() || isConstantPool() || isJumpTable()) 52 return false; 53 llvm_unreachable("Unknown PseudoSourceValue!"); 54} 55 56bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const { 57 return !(isGOT() || isConstantPool() || isJumpTable()); 58} 59 60bool FixedStackPseudoSourceValue::isConstant( 61 const MachineFrameInfo *MFI) const { 62 return MFI && MFI->isImmutableObjectIndex(FI); 63} 64 65bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { 66 if (!MFI) 67 return true; 68 return MFI->isAliasedObjectIndex(FI); 69} 70 71bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const { 72 if (!MFI) 73 return true; 74 // Spill slots will not alias any LLVM IR value. 75 return !MFI->isSpillSlotObjectIndex(FI); 76} 77 78void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const { 79 OS << "FixedStack" << FI; 80} 81 82CallEntryPseudoSourceValue::CallEntryPseudoSourceValue( 83 unsigned Kind, const TargetInstrInfo &TII) 84 : PseudoSourceValue(Kind, TII) {} 85 86bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const { 87 return false; 88} 89 90bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const { 91 return false; 92} 93 94bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const { 95 return false; 96} 97 98GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue( 99 const GlobalValue *GV, 100 const TargetInstrInfo &TII) 101 : CallEntryPseudoSourceValue(GlobalValueCallEntry, TII), GV(GV) {} 102ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue( 103 const char *ES, const TargetInstrInfo &TII) 104 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TII), ES(ES) {} 105 106PseudoSourceValueManager::PseudoSourceValueManager( 107 const TargetInstrInfo &TIInfo) 108 : TII(TIInfo), 109 StackPSV(PseudoSourceValue::Stack, TII), 110 GOTPSV(PseudoSourceValue::GOT, TII), 111 JumpTablePSV(PseudoSourceValue::JumpTable, TII), 112 ConstantPoolPSV(PseudoSourceValue::ConstantPool, TII) {} 113 114const PseudoSourceValue *PseudoSourceValueManager::getStack() { 115 return &StackPSV; 116} 117 118const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; } 119 120const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() { 121 return &ConstantPoolPSV; 122} 123 124const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() { 125 return &JumpTablePSV; 126} 127 128const PseudoSourceValue * 129PseudoSourceValueManager::getFixedStack(int FI) { 130 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI]; 131 if (!V) 132 V = std::make_unique<FixedStackPseudoSourceValue>(FI, TII); 133 return V.get(); 134} 135 136const PseudoSourceValue * 137PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) { 138 std::unique_ptr<const GlobalValuePseudoSourceValue> &E = 139 GlobalCallEntries[GV]; 140 if (!E) 141 E = std::make_unique<GlobalValuePseudoSourceValue>(GV, TII); 142 return E.get(); 143} 144 145const PseudoSourceValue * 146PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) { 147 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E = 148 ExternalCallEntries[ES]; 149 if (!E) 150 E = std::make_unique<ExternalSymbolPseudoSourceValue>(ES, TII); 151 return E.get(); 152} 153