LLVM  8.0.1
PseudoSourceValue.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/PseudoSourceValue.h ------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the PseudoSourceValue class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
15 #define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
16 
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/IR/GlobalValue.h"
19 #include "llvm/IR/Value.h"
20 #include "llvm/IR/ValueMap.h"
21 #include <map>
22 
23 namespace llvm {
24 
25 class MachineFrameInfo;
26 class MachineMemOperand;
27 class raw_ostream;
28 class TargetInstrInfo;
29 
30 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO);
31 class PseudoSourceValue;
32 raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
33 
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.
38 public:
39  enum PSVKind : unsigned {
41  GOT,
48  };
49 
50 private:
51  unsigned Kind;
52  unsigned AddressSpace;
54  const PseudoSourceValue* PSV);
55 
56  friend class MachineMemOperand; // For printCustom().
57 
58  /// Implement printing for PseudoSourceValue. This is called from
59  /// Value::print or Value's operator<<.
60  virtual void printCustom(raw_ostream &O) const;
61 
62 public:
63  explicit PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
64 
65  virtual ~PseudoSourceValue();
66 
67  unsigned kind() const { return Kind; }
68 
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; }
73 
74  unsigned getAddressSpace() const { return AddressSpace; }
75 
76  unsigned getTargetCustom() const {
77  return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0;
78  }
79 
80  /// Test whether the memory pointed to by this PseudoSourceValue has a
81  /// constant value.
82  virtual bool isConstant(const MachineFrameInfo *) const;
83 
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;
87 
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;
91 };
92 
93 /// A specialized PseudoSourceValue for holding FixedStack values, which must
94 /// include a frame index.
96  const int FI;
97 
98 public:
100  : PseudoSourceValue(FixedStack, TII), FI(FI) {}
101 
102  static bool classof(const PseudoSourceValue *V) {
103  return V->kind() == FixedStack;
104  }
105 
106  bool isConstant(const MachineFrameInfo *MFI) const override;
107 
108  bool isAliased(const MachineFrameInfo *MFI) const override;
109 
110  bool mayAlias(const MachineFrameInfo *) const override;
111 
112  void printCustom(raw_ostream &OS) const override;
113 
114  int getFrameIndex() const { return FI; }
115 };
116 
118 protected:
119  CallEntryPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
120 
121 public:
122  bool isConstant(const MachineFrameInfo *) const override;
123  bool isAliased(const MachineFrameInfo *) const override;
124  bool mayAlias(const MachineFrameInfo *) const override;
125 };
126 
127 /// A specialized pseudo soruce value for holding GlobalValue values.
129  const GlobalValue *GV;
130 
131 public:
133  const TargetInstrInfo &TII);
134 
135  static bool classof(const PseudoSourceValue *V) {
136  return V->kind() == GlobalValueCallEntry;
137  }
138 
139  const GlobalValue *getValue() const { return GV; }
140 };
141 
142 /// A specialized pseudo source value for holding external symbol values.
144  const char *ES;
145 
146 public:
147  ExternalSymbolPseudoSourceValue(const char *ES, const TargetInstrInfo &TII);
148 
149  static bool classof(const PseudoSourceValue *V) {
150  return V->kind() == ExternalSymbolCallEntry;
151  }
152 
153  const char *getSymbol() const { return ES; }
154 };
155 
156 /// Manages creation of pseudo source values.
158  const TargetInstrInfo &TII;
159  const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
160  std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
162  ExternalCallEntries;
163  ValueMap<const GlobalValue *,
164  std::unique_ptr<const GlobalValuePseudoSourceValue>>
165  GlobalCallEntries;
166 
167 public:
169 
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();
173 
174  /// Return a pseudo source value referencing the global offset table
175  /// (or something the like).
176  const PseudoSourceValue *getGOT();
177 
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
180  /// pool entry.
181  const PseudoSourceValue *getConstantPool();
182 
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();
186 
187  /// Return a pseudo source value referencing a fixed stack frame entry,
188  /// e.g., a spill slot.
189  const PseudoSourceValue *getFixedStack(int FI);
190 
191  const PseudoSourceValue *getGlobalValueCallEntry(const GlobalValue *GV);
192 
193  const PseudoSourceValue *getExternalSymbolCallEntry(const char *ES);
194 };
195 
196 } // end namespace llvm
197 
198 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:24
virtual bool mayAlias(const MachineFrameInfo *) const
Return true if the memory pointed to by this PseudoSourceValue can ever alias an LLVM IR Value...
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...
virtual bool isConstant(const MachineFrameInfo *) const
Test whether the memory pointed to by this PseudoSourceValue has a constant value.
A description of a memory reference used in the backend.
const HexagonInstrInfo * TII
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getTargetCustom() const
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getAddressSpace() const
static bool classof(const PseudoSourceValue *V)
FixedStackPseudoSourceValue(int FI, const TargetInstrInfo &TII)
See the file comment.
Definition: ValueMap.h:86
AddressSpace
Definition: NVPTXBaseInfo.h:22
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
A specialized pseudo source value for holding external symbol values.
Special value supplied for machine level alias analysis.
A specialized pseudo soruce value for holding GlobalValue values.
static bool classof(const PseudoSourceValue *V)
const GlobalValue * getValue() const
static bool classof(const PseudoSourceValue *V)
PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2039
const unsigned Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
Manages creation of pseudo source values.
A specialized PseudoSourceValue for holding FixedStack values, which must include a frame index...
AddressSpace
An integer that identifies all of the supported AVR address spaces.
Definition: AVR.h:41