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
16namespace llvm {
17
18class GlobalValue;
19class MachineFrameInfo;
20class MachineMemOperand;
21class MIRFormatter;
22class PseudoSourceValue;
23class raw_ostream;
24class TargetMachine;
25
26raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
27
28/// Special value supplied for machine level alias analysis. It indicates that
29/// a memory access references the functions stack frame (e.g., a spill slot),
30/// below the stack frame (e.g., argument space), or constant pool.
31class PseudoSourceValue {
32public:
33 enum PSVKind : unsigned {
34 Stack,
35 GOT,
36 JumpTable,
37 ConstantPool,
38 FixedStack,
39 GlobalValueCallEntry,
40 ExternalSymbolCallEntry,
41 TargetCustom
42 };
43
44private:
45 unsigned Kind;
46 unsigned AddressSpace;
47 friend raw_ostream &llvm::operator<<(raw_ostream &OS,
48 const PseudoSourceValue* PSV);
49
50 friend class MachineMemOperand; // For printCustom().
51 friend class MIRFormatter; // For printCustom().
52
53 /// Implement printing for PseudoSourceValue. This is called from
54 /// Value::print or Value's operator<<.
55 virtual void printCustom(raw_ostream &O) const;
56
57public:
58 explicit PseudoSourceValue(unsigned Kind, const TargetMachine &TM);
59
60 virtual ~PseudoSourceValue();
61
62 unsigned kind() const { return Kind; }
63
64 bool isStack() const { return Kind == Stack; }
65 bool isGOT() const { return Kind == GOT; }
66 bool isConstantPool() const { return Kind == ConstantPool; }
67 bool isJumpTable() const { return Kind == JumpTable; }
68
69 unsigned getAddressSpace() const { return AddressSpace; }
70
71 unsigned getTargetCustom() const {
72 return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0;
73 }
74
75 /// Test whether the memory pointed to by this PseudoSourceValue has a
76 /// constant value.
77 virtual bool isConstant(const MachineFrameInfo *) const;
78
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;
82
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;
86};
87
88/// A specialized PseudoSourceValue for holding FixedStack values, which must
89/// include a frame index.
90class FixedStackPseudoSourceValue : public PseudoSourceValue {
91 const int FI;
92
93public:
94 explicit FixedStackPseudoSourceValue(int FI, const TargetMachine &TM)
95 : PseudoSourceValue(FixedStack, TM), FI(FI) {}
96
97 static bool classof(const PseudoSourceValue *V) {
98 return V->kind() == FixedStack;
99 }
100
101 bool isConstant(const MachineFrameInfo *MFI) const override;
102
103 bool isAliased(const MachineFrameInfo *MFI) const override;
104
105 bool mayAlias(const MachineFrameInfo *) const override;
106
107 void printCustom(raw_ostream &OS) const override;
108
109 int getFrameIndex() const { return FI; }
110};
111
112class CallEntryPseudoSourceValue : public PseudoSourceValue {
113protected:
114 CallEntryPseudoSourceValue(unsigned Kind, const TargetMachine &TM);
115
116public:
117 bool isConstant(const MachineFrameInfo *) const override;
118 bool isAliased(const MachineFrameInfo *) const override;
119 bool mayAlias(const MachineFrameInfo *) const override;
120};
121
122/// A specialized pseudo source value for holding GlobalValue values.
123class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue {
124 const GlobalValue *GV;
125
126public:
127 GlobalValuePseudoSourceValue(const GlobalValue *GV, const TargetMachine &TM);
128
129 static bool classof(const PseudoSourceValue *V) {
130 return V->kind() == GlobalValueCallEntry;
131 }
132
133 const GlobalValue *getValue() const { return GV; }
134};
135
136/// A specialized pseudo source value for holding external symbol values.
137class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue {
138 const char *ES;
139
140public:
141 ExternalSymbolPseudoSourceValue(const char *ES, const TargetMachine &TM);
142
143 static bool classof(const PseudoSourceValue *V) {
144 return V->kind() == ExternalSymbolCallEntry;
145 }
146
147 const char *getSymbol() const { return ES; }
148};
149
150} // end namespace llvm
151
152#endif
153

source code of llvm/include/llvm/CodeGen/PseudoSourceValue.h