1//===-- llvm/CodeGen/PseudoSourceValue.h ------------------------*- 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 contains the declaration of the PseudoSourceValue class. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H 15#define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H 16 17#include "llvm/ADT/StringMap.h" 18#include "llvm/IR/GlobalValue.h" 19#include "llvm/IR/Value.h" 20#include "llvm/IR/ValueMap.h" 21#include <map> 22 23namespace llvm { 24 25class MachineFrameInfo; 26class MachineMemOperand; 27class raw_ostream; 28class TargetInstrInfo; 29 30raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO); 31class PseudoSourceValue; 32raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV); 33 34/// Special value supplied for machine level alias analysis. It indicates that 35/// a memory access references the functions stack frame (e.g., a spill slot), 36/// below the stack frame (e.g., argument space), or constant pool. 37class PseudoSourceValue { 38public: 39 enum PSVKind { 40 Stack, 41 GOT, 42 JumpTable, 43 ConstantPool, 44 FixedStack, 45 GlobalValueCallEntry, 46 ExternalSymbolCallEntry, 47 TargetCustom 48 }; 49 50private: 51 PSVKind Kind; 52 unsigned AddressSpace; 53 friend raw_ostream &llvm::operator<<(raw_ostream &OS, 54 const PseudoSourceValue* PSV); 55 56 friend class MachineMemOperand; // For printCustom(). 57 58 /// Implement printing for PseudoSourceValue. This is called from 59 /// Value::print or Value's operator<<. 60 virtual void printCustom(raw_ostream &O) const; 61 62public: 63 explicit PseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII); 64 65 virtual ~PseudoSourceValue(); 66 67 PSVKind kind() const { return Kind; } 68 69 bool isStack() const { return Kind == Stack; } 70 bool isGOT() const { return Kind == GOT; } 71 bool isConstantPool() const { return Kind == ConstantPool; } 72 bool isJumpTable() const { return Kind == JumpTable; } 73 74 unsigned getAddressSpace() const { return AddressSpace; } 75 76 unsigned getTargetCustom() const { 77 return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0; 78 } 79 80 /// Test whether the memory pointed to by this PseudoSourceValue has a 81 /// constant value. 82 virtual bool isConstant(const MachineFrameInfo *) const; 83 84 /// Test whether the memory pointed to by this PseudoSourceValue may also be 85 /// pointed to by an LLVM IR Value. 86 virtual bool isAliased(const MachineFrameInfo *) const; 87 88 /// Return true if the memory pointed to by this PseudoSourceValue can ever 89 /// alias an LLVM IR Value. 90 virtual bool mayAlias(const MachineFrameInfo *) const; 91}; 92 93/// A specialized PseudoSourceValue for holding FixedStack values, which must 94/// include a frame index. 95class FixedStackPseudoSourceValue : public PseudoSourceValue { 96 const int FI; 97 98public: 99 explicit FixedStackPseudoSourceValue(int FI, const TargetInstrInfo &TII) 100 : PseudoSourceValue(FixedStack, TII), FI(FI) {} 101 102 static bool classof(const PseudoSourceValue *V) { 103 return V->kind() == FixedStack; 104 } 105 106 bool isConstant(const MachineFrameInfo *MFI) const override; 107 108 bool isAliased(const MachineFrameInfo *MFI) const override; 109 110 bool mayAlias(const MachineFrameInfo *) const override; 111 112 void printCustom(raw_ostream &OS) const override; 113 114 int getFrameIndex() const { return FI; } 115}; 116 117class CallEntryPseudoSourceValue : public PseudoSourceValue { 118protected: 119 CallEntryPseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII); 120 121public: 122 bool isConstant(const MachineFrameInfo *) const override; 123 bool isAliased(const MachineFrameInfo *) const override; 124 bool mayAlias(const MachineFrameInfo *) const override; 125}; 126 127/// A specialized pseudo soruce value for holding GlobalValue values. 128class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue { 129 const GlobalValue *GV; 130 131public: 132 GlobalValuePseudoSourceValue(const GlobalValue *GV, 133 const TargetInstrInfo &TII); 134 135 static bool classof(const PseudoSourceValue *V) { 136 return V->kind() == GlobalValueCallEntry; 137 } 138 139 const GlobalValue *getValue() const { return GV; } 140}; 141 142/// A specialized pseudo source value for holding external symbol values. 143class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue { 144 const char *ES; 145 146public: 147 ExternalSymbolPseudoSourceValue(const char *ES, const TargetInstrInfo &TII); 148 149 static bool classof(const PseudoSourceValue *V) { 150 return V->kind() == ExternalSymbolCallEntry; 151 } 152 153 const char *getSymbol() const { return ES; } 154}; 155 156/// Manages creation of pseudo source values. 157class PseudoSourceValueManager { 158 const TargetInstrInfo &TII; 159 const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV; 160 std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues; 161 StringMap<std::unique_ptr<const ExternalSymbolPseudoSourceValue>> 162 ExternalCallEntries; 163 ValueMap<const GlobalValue *, 164 std::unique_ptr<const GlobalValuePseudoSourceValue>> 165 GlobalCallEntries; 166 167public: 168 PseudoSourceValueManager(const TargetInstrInfo &TII); 169 170 /// Return a pseudo source value referencing the area below the stack frame of 171 /// a function, e.g., the argument space. 172 const PseudoSourceValue *getStack(); 173 174 /// Return a pseudo source value referencing the global offset table 175 /// (or something the like). 176 const PseudoSourceValue *getGOT(); 177 178 /// Return a pseudo source value referencing the constant pool. Since constant 179 /// pools are constant, this doesn't need to identify a specific constant 180 /// pool entry. 181 const PseudoSourceValue *getConstantPool(); 182 183 /// Return a pseudo source value referencing a jump table. Since jump tables 184 /// are constant, this doesn't need to identify a specific jump table. 185 const PseudoSourceValue *getJumpTable(); 186 187 /// Return a pseudo source value referencing a fixed stack frame entry, 188 /// e.g., a spill slot. 189 const PseudoSourceValue *getFixedStack(int FI); 190 191 const PseudoSourceValue *getGlobalValueCallEntry(const GlobalValue *GV); 192 193 const PseudoSourceValue *getExternalSymbolCallEntry(const char *ES); 194}; 195 196} // end namespace llvm 197 198#endif 199