LLVM  9.0.0svn
PseudoSourceValue.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/PseudoSourceValue.h ------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the declaration of the PseudoSourceValue class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
14 #define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
15 
16 #include "llvm/ADT/StringMap.h"
17 #include "llvm/IR/GlobalValue.h"
18 #include "llvm/IR/Value.h"
19 #include "llvm/IR/ValueMap.h"
20 #include <map>
21 
22 namespace llvm {
23 
24 class MachineFrameInfo;
25 class MachineMemOperand;
26 class raw_ostream;
27 class TargetInstrInfo;
28 
29 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO);
30 class PseudoSourceValue;
31 raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
32 
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.
37 public:
38  enum PSVKind : unsigned {
40  GOT,
47  };
48 
49 private:
50  unsigned Kind;
51  unsigned AddressSpace;
53  const PseudoSourceValue* PSV);
54 
55  friend class MachineMemOperand; // For printCustom().
56 
57  /// Implement printing for PseudoSourceValue. This is called from
58  /// Value::print or Value's operator<<.
59  virtual void printCustom(raw_ostream &O) const;
60 
61 public:
62  explicit PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
63 
64  virtual ~PseudoSourceValue();
65 
66  unsigned kind() const { return Kind; }
67 
68  bool isStack() const { return Kind == Stack; }
69  bool isGOT() const { return Kind == GOT; }
70  bool isConstantPool() const { return Kind == ConstantPool; }
71  bool isJumpTable() const { return Kind == JumpTable; }
72 
73  unsigned getAddressSpace() const { return AddressSpace; }
74 
75  unsigned getTargetCustom() const {
76  return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0;
77  }
78 
79  /// Test whether the memory pointed to by this PseudoSourceValue has a
80  /// constant value.
81  virtual bool isConstant(const MachineFrameInfo *) const;
82 
83  /// Test whether the memory pointed to by this PseudoSourceValue may also be
84  /// pointed to by an LLVM IR Value.
85  virtual bool isAliased(const MachineFrameInfo *) const;
86 
87  /// Return true if the memory pointed to by this PseudoSourceValue can ever
88  /// alias an LLVM IR Value.
89  virtual bool mayAlias(const MachineFrameInfo *) const;
90 };
91 
92 /// A specialized PseudoSourceValue for holding FixedStack values, which must
93 /// include a frame index.
95  const int FI;
96 
97 public:
99  : PseudoSourceValue(FixedStack, TII), FI(FI) {}
100 
101  static bool classof(const PseudoSourceValue *V) {
102  return V->kind() == FixedStack;
103  }
104 
105  bool isConstant(const MachineFrameInfo *MFI) const override;
106 
107  bool isAliased(const MachineFrameInfo *MFI) const override;
108 
109  bool mayAlias(const MachineFrameInfo *) const override;
110 
111  void printCustom(raw_ostream &OS) const override;
112 
113  int getFrameIndex() const { return FI; }
114 };
115 
117 protected:
118  CallEntryPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
119 
120 public:
121  bool isConstant(const MachineFrameInfo *) const override;
122  bool isAliased(const MachineFrameInfo *) const override;
123  bool mayAlias(const MachineFrameInfo *) const override;
124 };
125 
126 /// A specialized pseudo soruce value for holding GlobalValue values.
128  const GlobalValue *GV;
129 
130 public:
132  const TargetInstrInfo &TII);
133 
134  static bool classof(const PseudoSourceValue *V) {
135  return V->kind() == GlobalValueCallEntry;
136  }
137 
138  const GlobalValue *getValue() const { return GV; }
139 };
140 
141 /// A specialized pseudo source value for holding external symbol values.
143  const char *ES;
144 
145 public:
146  ExternalSymbolPseudoSourceValue(const char *ES, const TargetInstrInfo &TII);
147 
148  static bool classof(const PseudoSourceValue *V) {
149  return V->kind() == ExternalSymbolCallEntry;
150  }
151 
152  const char *getSymbol() const { return ES; }
153 };
154 
155 /// Manages creation of pseudo source values.
157  const TargetInstrInfo &TII;
158  const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
159  std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
161  ExternalCallEntries;
162  ValueMap<const GlobalValue *,
163  std::unique_ptr<const GlobalValuePseudoSourceValue>>
164  GlobalCallEntries;
165 
166 public:
168 
169  /// Return a pseudo source value referencing the area below the stack frame of
170  /// a function, e.g., the argument space.
171  const PseudoSourceValue *getStack();
172 
173  /// Return a pseudo source value referencing the global offset table
174  /// (or something the like).
175  const PseudoSourceValue *getGOT();
176 
177  /// Return a pseudo source value referencing the constant pool. Since constant
178  /// pools are constant, this doesn't need to identify a specific constant
179  /// pool entry.
180  const PseudoSourceValue *getConstantPool();
181 
182  /// Return a pseudo source value referencing a jump table. Since jump tables
183  /// are constant, this doesn't need to identify a specific jump table.
184  const PseudoSourceValue *getJumpTable();
185 
186  /// Return a pseudo source value referencing a fixed stack frame entry,
187  /// e.g., a spill slot.
188  const PseudoSourceValue *getFixedStack(int FI);
189 
190  const PseudoSourceValue *getGlobalValueCallEntry(const GlobalValue *GV);
191 
192  const PseudoSourceValue *getExternalSymbolCallEntry(const char *ES);
193 };
194 
195 } // end namespace llvm
196 
197 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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:85
AddressSpace
Definition: NVPTXBaseInfo.h:21
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:219
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:2038
const unsigned Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
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:40