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