1 //===-- llvm/CodeGen/PseudoSourceValue.h ------------------------*- 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 contains the declaration of the PseudoSourceValue class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H 14 #define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H 15 16 #include "llvm/Support/Compiler.h" 17 18 namespace llvm { 19 20 class GlobalValue; 21 class MachineFrameInfo; 22 class MachineMemOperand; 23 class MIRFormatter; 24 class PseudoSourceValue; 25 class raw_ostream; 26 class TargetMachine; 27 28 LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue *PSV); 29 30 /// Special value supplied for machine level alias analysis. It indicates that 31 /// a memory access references the functions stack frame (e.g., a spill slot), 32 /// below the stack frame (e.g., argument space), or constant pool. 33 class LLVM_ABI PseudoSourceValue { 34 public: 35 enum PSVKind : unsigned { 36 Stack, 37 GOT, 38 JumpTable, 39 ConstantPool, 40 FixedStack, 41 GlobalValueCallEntry, 42 ExternalSymbolCallEntry, 43 TargetCustom 44 }; 45 46 private: 47 unsigned Kind; 48 unsigned AddressSpace; 49 LLVM_ABI friend raw_ostream &llvm::operator<<(raw_ostream &OS, 50 const PseudoSourceValue *PSV); 51 52 friend class MachineMemOperand; // For printCustom(). 53 friend class MIRFormatter; // For printCustom(). 54 55 /// Implement printing for PseudoSourceValue. This is called from 56 /// Value::print or Value's operator<<. 57 virtual void printCustom(raw_ostream &O) const; 58 59 public: 60 explicit PseudoSourceValue(unsigned Kind, const TargetMachine &TM); 61 62 virtual ~PseudoSourceValue(); 63 kind()64 unsigned kind() const { return Kind; } 65 isStack()66 bool isStack() const { return Kind == Stack; } isGOT()67 bool isGOT() const { return Kind == GOT; } isConstantPool()68 bool isConstantPool() const { return Kind == ConstantPool; } isJumpTable()69 bool isJumpTable() const { return Kind == JumpTable; } 70 getAddressSpace()71 unsigned getAddressSpace() const { return AddressSpace; } 72 getTargetCustom()73 unsigned getTargetCustom() const { 74 return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0; 75 } 76 77 /// Test whether the memory pointed to by this PseudoSourceValue has a 78 /// constant value. 79 virtual bool isConstant(const MachineFrameInfo *) const; 80 81 /// Test whether the memory pointed to by this PseudoSourceValue may also be 82 /// pointed to by an LLVM IR Value. 83 virtual bool isAliased(const MachineFrameInfo *) const; 84 85 /// Return true if the memory pointed to by this PseudoSourceValue can ever 86 /// alias an LLVM IR Value. 87 virtual bool mayAlias(const MachineFrameInfo *) const; 88 }; 89 90 /// A specialized PseudoSourceValue for holding FixedStack values, which must 91 /// include a frame index. 92 class LLVM_ABI FixedStackPseudoSourceValue : public PseudoSourceValue { 93 const int FI; 94 95 public: FixedStackPseudoSourceValue(int FI,const TargetMachine & TM)96 explicit FixedStackPseudoSourceValue(int FI, const TargetMachine &TM) 97 : PseudoSourceValue(FixedStack, TM), FI(FI) {} 98 classof(const PseudoSourceValue * V)99 static bool classof(const PseudoSourceValue *V) { 100 return V->kind() == FixedStack; 101 } 102 103 bool isConstant(const MachineFrameInfo *MFI) const override; 104 105 bool isAliased(const MachineFrameInfo *MFI) const override; 106 107 bool mayAlias(const MachineFrameInfo *) const override; 108 109 void printCustom(raw_ostream &OS) const override; 110 getFrameIndex()111 int getFrameIndex() const { return FI; } 112 }; 113 114 class LLVM_ABI CallEntryPseudoSourceValue : public PseudoSourceValue { 115 protected: 116 CallEntryPseudoSourceValue(unsigned Kind, const TargetMachine &TM); 117 118 public: 119 bool isConstant(const MachineFrameInfo *) const override; 120 bool isAliased(const MachineFrameInfo *) const override; 121 bool mayAlias(const MachineFrameInfo *) const override; 122 }; 123 124 /// A specialized pseudo source value for holding GlobalValue values. 125 class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue { 126 const GlobalValue *GV; 127 128 public: 129 LLVM_ABI GlobalValuePseudoSourceValue(const GlobalValue *GV, 130 const TargetMachine &TM); 131 classof(const PseudoSourceValue * V)132 static bool classof(const PseudoSourceValue *V) { 133 return V->kind() == GlobalValueCallEntry; 134 } 135 getValue()136 const GlobalValue *getValue() const { return GV; } 137 }; 138 139 /// A specialized pseudo source value for holding external symbol values. 140 class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue { 141 const char *ES; 142 143 public: 144 LLVM_ABI ExternalSymbolPseudoSourceValue(const char *ES, 145 const TargetMachine &TM); 146 classof(const PseudoSourceValue * V)147 static bool classof(const PseudoSourceValue *V) { 148 return V->kind() == ExternalSymbolCallEntry; 149 } 150 getSymbol()151 const char *getSymbol() const { return ES; } 152 }; 153 154 } // end namespace llvm 155 156 #endif 157