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);
30 class PseudoSourceValue;
31 raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
33 /// Special value supplied for machine level alias analysis. It indicates that
34 /// a memory access references the functions stack frame (e.g., a spill slot),
35 /// below the stack frame (e.g., argument space), or constant pool.
36 class PseudoSourceValue {
45 ExternalSymbolCallEntry
50 friend raw_ostream &llvm::operator<<(raw_ostream &OS,
51 const PseudoSourceValue* PSV);
53 friend class MachineMemOperand; // For printCustom().
55 /// Implement printing for PseudoSourceValue. This is called from
56 /// Value::print or Value's operator<<.
57 virtual void printCustom(raw_ostream &O) const;
60 explicit PseudoSourceValue(PSVKind Kind);
62 virtual ~PseudoSourceValue();
64 PSVKind kind() const { return Kind; }
66 bool isStack() const { return Kind == Stack; }
67 bool isGOT() const { return Kind == GOT; }
68 bool isConstantPool() const { return Kind == ConstantPool; }
69 bool isJumpTable() const { return Kind == JumpTable; }
71 /// Test whether the memory pointed to by this PseudoSourceValue has a
73 virtual bool isConstant(const MachineFrameInfo *) const;
75 /// Test whether the memory pointed to by this PseudoSourceValue may also be
76 /// pointed to by an LLVM IR Value.
77 virtual bool isAliased(const MachineFrameInfo *) const;
79 /// Return true if the memory pointed to by this PseudoSourceValue can ever
80 /// alias an LLVM IR Value.
81 virtual bool mayAlias(const MachineFrameInfo *) const;
84 /// A specialized PseudoSourceValue for holding FixedStack values, which must
85 /// include a frame index.
86 class FixedStackPseudoSourceValue : public PseudoSourceValue {
90 explicit FixedStackPseudoSourceValue(int FI)
91 : PseudoSourceValue(FixedStack), FI(FI) {}
93 static inline bool classof(const PseudoSourceValue *V) {
94 return V->kind() == FixedStack;
97 bool isConstant(const MachineFrameInfo *MFI) const override;
99 bool isAliased(const MachineFrameInfo *MFI) const override;
101 bool mayAlias(const MachineFrameInfo *) const override;
103 void printCustom(raw_ostream &OS) const override;
105 int getFrameIndex() const { return FI; }
108 class CallEntryPseudoSourceValue : public PseudoSourceValue {
110 CallEntryPseudoSourceValue(PSVKind Kind);
113 bool isConstant(const MachineFrameInfo *) const override;
114 bool isAliased(const MachineFrameInfo *) const override;
115 bool mayAlias(const MachineFrameInfo *) const override;
118 /// A specialized pseudo soruce value for holding GlobalValue values.
119 class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue {
120 const GlobalValue *GV;
123 GlobalValuePseudoSourceValue(const GlobalValue *GV);
125 static inline bool classof(const PseudoSourceValue *V) {
126 return V->kind() == GlobalValueCallEntry;
129 const GlobalValue *getValue() const { return GV; }
132 /// A specialized pseudo source value for holding external symbol values.
133 class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue {
137 ExternalSymbolPseudoSourceValue(const char *ES);
139 static inline bool classof(const PseudoSourceValue *V) {
140 return V->kind() == ExternalSymbolCallEntry;
143 const char *getSymbol() const { return ES; }
146 /// Manages creation of pseudo source values.
147 class PseudoSourceValueManager {
148 const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
149 std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
150 StringMap<std::unique_ptr<const ExternalSymbolPseudoSourceValue>>
152 ValueMap<const GlobalValue *,
153 std::unique_ptr<const GlobalValuePseudoSourceValue>>
157 PseudoSourceValueManager();
159 /// Return a pseudo source value referencing the area below the stack frame of
160 /// a function, e.g., the argument space.
161 const PseudoSourceValue *getStack();
163 /// Return a pseudo source value referencing the global offset table
164 /// (or something the like).
165 const PseudoSourceValue *getGOT();
167 /// Return a pseudo source value referencing the constant pool. Since constant
168 /// pools are constant, this doesn't need to identify a specific constant
170 const PseudoSourceValue *getConstantPool();
172 /// Return a pseudo source value referencing a jump table. Since jump tables
173 /// are constant, this doesn't need to identify a specific jump table.
174 const PseudoSourceValue *getJumpTable();
176 /// Return a pseudo source value referencing a fixed stack frame entry,
177 /// e.g., a spill slot.
178 const PseudoSourceValue *getFixedStack(int FI);
180 const PseudoSourceValue *getGlobalValueCallEntry(const GlobalValue *GV);
182 const PseudoSourceValue *getExternalSymbolCallEntry(const char *ES);
185 } // end namespace llvm