1 //===-- llvm/CodeGen/PseudoSourceValue.h ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the PseudoSourceValue class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
15 #define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/IR/GlobalValue.h"
19 #include "llvm/IR/Value.h"
20 #include "llvm/IR/ValueMap.h"
25 class MachineFrameInfo;
26 class MachineMemOperand;
29 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO);
31 /// Special value supplied for machine level alias analysis. It indicates that
32 /// a memory access references the functions stack frame (e.g., a spill slot),
33 /// below the stack frame (e.g., argument space), or constant pool.
34 class PseudoSourceValue {
43 ExternalSymbolCallEntry
49 friend class MachineMemOperand; // For printCustom().
51 /// Implement printing for PseudoSourceValue. This is called from
52 /// Value::print or Value's operator<<.
53 virtual void printCustom(raw_ostream &O) const;
56 explicit PseudoSourceValue(PSVKind Kind);
58 virtual ~PseudoSourceValue();
60 PSVKind kind() const { return Kind; }
62 bool isStack() const { return Kind == Stack; }
63 bool isGOT() const { return Kind == GOT; }
64 bool isConstantPool() const { return Kind == ConstantPool; }
65 bool isJumpTable() const { return Kind == JumpTable; }
67 /// Test whether the memory pointed to by this PseudoSourceValue has a
69 virtual bool isConstant(const MachineFrameInfo *) const;
71 /// Test whether the memory pointed to by this PseudoSourceValue may also be
72 /// pointed to by an LLVM IR Value.
73 virtual bool isAliased(const MachineFrameInfo *) const;
75 /// Return true if the memory pointed to by this PseudoSourceValue can ever
76 /// alias an LLVM IR Value.
77 virtual bool mayAlias(const MachineFrameInfo *) const;
80 /// A specialized PseudoSourceValue for holding FixedStack values, which must
81 /// include a frame index.
82 class FixedStackPseudoSourceValue : public PseudoSourceValue {
86 explicit FixedStackPseudoSourceValue(int FI)
87 : PseudoSourceValue(FixedStack), FI(FI) {}
89 static inline bool classof(const PseudoSourceValue *V) {
90 return V->kind() == FixedStack;
93 bool isConstant(const MachineFrameInfo *MFI) const override;
95 bool isAliased(const MachineFrameInfo *MFI) const override;
97 bool mayAlias(const MachineFrameInfo *) const override;
99 void printCustom(raw_ostream &OS) const override;
101 int getFrameIndex() const { return FI; }
104 class CallEntryPseudoSourceValue : public PseudoSourceValue {
106 CallEntryPseudoSourceValue(PSVKind Kind);
109 bool isConstant(const MachineFrameInfo *) const override;
110 bool isAliased(const MachineFrameInfo *) const override;
111 bool mayAlias(const MachineFrameInfo *) const override;
114 /// A specialized pseudo soruce value for holding GlobalValue values.
115 class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue {
116 const GlobalValue *GV;
119 GlobalValuePseudoSourceValue(const GlobalValue *GV);
121 static inline bool classof(const PseudoSourceValue *V) {
122 return V->kind() == GlobalValueCallEntry;
125 const GlobalValue *getValue() const { return GV; }
128 /// A specialized pseudo source value for holding external symbol values.
129 class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue {
133 ExternalSymbolPseudoSourceValue(const char *ES);
135 static inline bool classof(const PseudoSourceValue *V) {
136 return V->kind() == ExternalSymbolCallEntry;
139 const char *getSymbol() const { return ES; }
142 /// Manages creation of pseudo source values.
143 class PseudoSourceValueManager {
144 const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
145 std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
146 StringMap<std::unique_ptr<const ExternalSymbolPseudoSourceValue>>
148 ValueMap<const GlobalValue *,
149 std::unique_ptr<const GlobalValuePseudoSourceValue>>
153 PseudoSourceValueManager();
155 /// Return a pseudo source value referencing the area below the stack frame of
156 /// a function, e.g., the argument space.
157 const PseudoSourceValue *getStack();
159 /// Return a pseudo source value referencing the global offset table
160 /// (or something the like).
161 const PseudoSourceValue *getGOT();
163 /// Return a pseudo source value referencing the constant pool. Since constant
164 /// pools are constant, this doesn't need to identify a specific constant
166 const PseudoSourceValue *getConstantPool();
168 /// Return a pseudo source value referencing a jump table. Since jump tables
169 /// are constant, this doesn't need to identify a specific jump table.
170 const PseudoSourceValue *getJumpTable();
172 /// Return a pseudo source value referencing a fixed stack frame entry,
173 /// e.g., a spill slot.
174 const PseudoSourceValue *getFixedStack(int FI);
176 const PseudoSourceValue *getGlobalValueCallEntry(const GlobalValue *GV);
178 const PseudoSourceValue *getExternalSymbolCallEntry(const char *ES);
181 } // end namespace llvm