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;
28 class TargetInstrInfo;
30 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO);
31 class PseudoSourceValue;
32 raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
34 /// Special value supplied for machine level alias analysis. It indicates that
35 /// a memory access references the functions stack frame (e.g., a spill slot),
36 /// below the stack frame (e.g., argument space), or constant pool.
37 class PseudoSourceValue {
39 enum PSVKind : unsigned {
46 ExternalSymbolCallEntry,
52 unsigned AddressSpace;
53 friend raw_ostream &llvm::operator<<(raw_ostream &OS,
54 const PseudoSourceValue* PSV);
56 friend class MachineMemOperand; // For printCustom().
58 /// Implement printing for PseudoSourceValue. This is called from
59 /// Value::print or Value's operator<<.
60 virtual void printCustom(raw_ostream &O) const;
63 explicit PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
65 virtual ~PseudoSourceValue();
67 unsigned kind() const { return Kind; }
69 bool isStack() const { return Kind == Stack; }
70 bool isGOT() const { return Kind == GOT; }
71 bool isConstantPool() const { return Kind == ConstantPool; }
72 bool isJumpTable() const { return Kind == JumpTable; }
74 unsigned getAddressSpace() const { return AddressSpace; }
76 unsigned getTargetCustom() const {
77 return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0;
80 /// Test whether the memory pointed to by this PseudoSourceValue has a
82 virtual bool isConstant(const MachineFrameInfo *) const;
84 /// Test whether the memory pointed to by this PseudoSourceValue may also be
85 /// pointed to by an LLVM IR Value.
86 virtual bool isAliased(const MachineFrameInfo *) const;
88 /// Return true if the memory pointed to by this PseudoSourceValue can ever
89 /// alias an LLVM IR Value.
90 virtual bool mayAlias(const MachineFrameInfo *) const;
93 /// A specialized PseudoSourceValue for holding FixedStack values, which must
94 /// include a frame index.
95 class FixedStackPseudoSourceValue : public PseudoSourceValue {
99 explicit FixedStackPseudoSourceValue(int FI, const TargetInstrInfo &TII)
100 : PseudoSourceValue(FixedStack, TII), FI(FI) {}
102 static bool classof(const PseudoSourceValue *V) {
103 return V->kind() == FixedStack;
106 bool isConstant(const MachineFrameInfo *MFI) const override;
108 bool isAliased(const MachineFrameInfo *MFI) const override;
110 bool mayAlias(const MachineFrameInfo *) const override;
112 void printCustom(raw_ostream &OS) const override;
114 int getFrameIndex() const { return FI; }
117 class CallEntryPseudoSourceValue : public PseudoSourceValue {
119 CallEntryPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
122 bool isConstant(const MachineFrameInfo *) const override;
123 bool isAliased(const MachineFrameInfo *) const override;
124 bool mayAlias(const MachineFrameInfo *) const override;
127 /// A specialized pseudo soruce value for holding GlobalValue values.
128 class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue {
129 const GlobalValue *GV;
132 GlobalValuePseudoSourceValue(const GlobalValue *GV,
133 const TargetInstrInfo &TII);
135 static bool classof(const PseudoSourceValue *V) {
136 return V->kind() == GlobalValueCallEntry;
139 const GlobalValue *getValue() const { return GV; }
142 /// A specialized pseudo source value for holding external symbol values.
143 class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue {
147 ExternalSymbolPseudoSourceValue(const char *ES, const TargetInstrInfo &TII);
149 static bool classof(const PseudoSourceValue *V) {
150 return V->kind() == ExternalSymbolCallEntry;
153 const char *getSymbol() const { return ES; }
156 /// Manages creation of pseudo source values.
157 class PseudoSourceValueManager {
158 const TargetInstrInfo &TII;
159 const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
160 std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
161 StringMap<std::unique_ptr<const ExternalSymbolPseudoSourceValue>>
163 ValueMap<const GlobalValue *,
164 std::unique_ptr<const GlobalValuePseudoSourceValue>>
168 PseudoSourceValueManager(const TargetInstrInfo &TII);
170 /// Return a pseudo source value referencing the area below the stack frame of
171 /// a function, e.g., the argument space.
172 const PseudoSourceValue *getStack();
174 /// Return a pseudo source value referencing the global offset table
175 /// (or something the like).
176 const PseudoSourceValue *getGOT();
178 /// Return a pseudo source value referencing the constant pool. Since constant
179 /// pools are constant, this doesn't need to identify a specific constant
181 const PseudoSourceValue *getConstantPool();
183 /// Return a pseudo source value referencing a jump table. Since jump tables
184 /// are constant, this doesn't need to identify a specific jump table.
185 const PseudoSourceValue *getJumpTable();
187 /// Return a pseudo source value referencing a fixed stack frame entry,
188 /// e.g., a spill slot.
189 const PseudoSourceValue *getFixedStack(int FI);
191 const PseudoSourceValue *getGlobalValueCallEntry(const GlobalValue *GV);
193 const PseudoSourceValue *getExternalSymbolCallEntry(const char *ES);
196 } // end namespace llvm