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,
51 friend raw_ostream &llvm::operator<<(raw_ostream &OS,
52 const PseudoSourceValue* PSV);
54 friend class MachineMemOperand; // For printCustom().
56 /// Implement printing for PseudoSourceValue. This is called from
57 /// Value::print or Value's operator<<.
58 virtual void printCustom(raw_ostream &O) const;
61 explicit PseudoSourceValue(PSVKind Kind);
63 virtual ~PseudoSourceValue();
65 PSVKind kind() const { return Kind; }
67 bool isStack() const { return Kind == Stack; }
68 bool isGOT() const { return Kind == GOT; }
69 bool isConstantPool() const { return Kind == ConstantPool; }
70 bool isJumpTable() const { return Kind == JumpTable; }
71 unsigned getTargetCustom() const {
72 return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0;
75 /// Test whether the memory pointed to by this PseudoSourceValue has a
77 virtual bool isConstant(const MachineFrameInfo *) const;
79 /// Test whether the memory pointed to by this PseudoSourceValue may also be
80 /// pointed to by an LLVM IR Value.
81 virtual bool isAliased(const MachineFrameInfo *) const;
83 /// Return true if the memory pointed to by this PseudoSourceValue can ever
84 /// alias an LLVM IR Value.
85 virtual bool mayAlias(const MachineFrameInfo *) const;
88 /// A specialized PseudoSourceValue for holding FixedStack values, which must
89 /// include a frame index.
90 class FixedStackPseudoSourceValue : public PseudoSourceValue {
94 explicit FixedStackPseudoSourceValue(int FI)
95 : PseudoSourceValue(FixedStack), FI(FI) {}
97 static bool classof(const PseudoSourceValue *V) {
98 return V->kind() == FixedStack;
101 bool isConstant(const MachineFrameInfo *MFI) const override;
103 bool isAliased(const MachineFrameInfo *MFI) const override;
105 bool mayAlias(const MachineFrameInfo *) const override;
107 void printCustom(raw_ostream &OS) const override;
109 int getFrameIndex() const { return FI; }
112 class CallEntryPseudoSourceValue : public PseudoSourceValue {
114 CallEntryPseudoSourceValue(PSVKind Kind);
117 bool isConstant(const MachineFrameInfo *) const override;
118 bool isAliased(const MachineFrameInfo *) const override;
119 bool mayAlias(const MachineFrameInfo *) const override;
122 /// A specialized pseudo soruce value for holding GlobalValue values.
123 class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue {
124 const GlobalValue *GV;
127 GlobalValuePseudoSourceValue(const GlobalValue *GV);
129 static bool classof(const PseudoSourceValue *V) {
130 return V->kind() == GlobalValueCallEntry;
133 const GlobalValue *getValue() const { return GV; }
136 /// A specialized pseudo source value for holding external symbol values.
137 class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue {
141 ExternalSymbolPseudoSourceValue(const char *ES);
143 static bool classof(const PseudoSourceValue *V) {
144 return V->kind() == ExternalSymbolCallEntry;
147 const char *getSymbol() const { return ES; }
150 /// Manages creation of pseudo source values.
151 class PseudoSourceValueManager {
152 const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
153 std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
154 StringMap<std::unique_ptr<const ExternalSymbolPseudoSourceValue>>
156 ValueMap<const GlobalValue *,
157 std::unique_ptr<const GlobalValuePseudoSourceValue>>
161 PseudoSourceValueManager();
163 /// Return a pseudo source value referencing the area below the stack frame of
164 /// a function, e.g., the argument space.
165 const PseudoSourceValue *getStack();
167 /// Return a pseudo source value referencing the global offset table
168 /// (or something the like).
169 const PseudoSourceValue *getGOT();
171 /// Return a pseudo source value referencing the constant pool. Since constant
172 /// pools are constant, this doesn't need to identify a specific constant
174 const PseudoSourceValue *getConstantPool();
176 /// Return a pseudo source value referencing a jump table. Since jump tables
177 /// are constant, this doesn't need to identify a specific jump table.
178 const PseudoSourceValue *getJumpTable();
180 /// Return a pseudo source value referencing a fixed stack frame entry,
181 /// e.g., a spill slot.
182 const PseudoSourceValue *getFixedStack(int FI);
184 const PseudoSourceValue *getGlobalValueCallEntry(const GlobalValue *GV);
186 const PseudoSourceValue *getExternalSymbolCallEntry(const char *ES);
189 } // end namespace llvm