PseudoSourceValue: Replace global manager with a manager in a machine function.
[oota-llvm.git] / include / llvm / CodeGen / PseudoSourceValue.h
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/IR/Value.h"
18 #include <map>
19
20 namespace llvm {
21
22 class MachineFrameInfo;
23 class MachineMemOperand;
24 class raw_ostream;
25
26 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO);
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.
31 class PseudoSourceValue {
32 public:
33   enum PSVKind { Stack, GOT, JumpTable, ConstantPool, FixedStack, MipsPSV };
34
35 private:
36   PSVKind Kind;
37
38   friend class MachineMemOperand; // For printCustom().
39
40   /// Implement printing for PseudoSourceValue. This is called from
41   /// Value::print or Value's operator<<.
42   virtual void printCustom(raw_ostream &O) const;
43
44 public:
45   explicit PseudoSourceValue(PSVKind Kind);
46
47   virtual ~PseudoSourceValue();
48
49   PSVKind kind() const { return Kind; }
50
51   bool isStack() const { return Kind == Stack; }
52   bool isGOT() const { return Kind == GOT; }
53   bool isConstantPool() const { return Kind == ConstantPool; }
54   bool isJumpTable() const { return Kind == JumpTable; }
55
56   /// Test whether the memory pointed to by this PseudoSourceValue has a
57   /// constant value.
58   virtual bool isConstant(const MachineFrameInfo *) const;
59
60   /// Test whether the memory pointed to by this PseudoSourceValue may also be
61   /// pointed to by an LLVM IR Value.
62   virtual bool isAliased(const MachineFrameInfo *) const;
63
64   /// Return true if the memory pointed to by this PseudoSourceValue can ever
65   /// alias an LLVM IR Value.
66   virtual bool mayAlias(const MachineFrameInfo *) const;
67 };
68
69 /// A specialized PseudoSourceValue for holding FixedStack values, which must
70 /// include a frame index.
71 class FixedStackPseudoSourceValue : public PseudoSourceValue {
72   const int FI;
73
74 public:
75   explicit FixedStackPseudoSourceValue(int FI)
76       : PseudoSourceValue(FixedStack), FI(FI) {}
77
78   static inline bool classof(const PseudoSourceValue *V) {
79     return V->kind() == FixedStack;
80   }
81
82   bool isConstant(const MachineFrameInfo *MFI) const override;
83
84   bool isAliased(const MachineFrameInfo *MFI) const override;
85
86   bool mayAlias(const MachineFrameInfo *) const override;
87
88   void printCustom(raw_ostream &OS) const override;
89
90   int getFrameIndex() const { return FI; }
91 };
92
93 /// Manages creation of pseudo source values.
94 class PseudoSourceValueManager {
95   const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
96   std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
97
98 public:
99   PseudoSourceValueManager();
100
101   /// Return a pseudo source value referencing the area below the stack frame of
102   /// a function, e.g., the argument space.
103   const PseudoSourceValue *getStack();
104
105   /// Return a pseudo source value referencing the global offset table
106   /// (or something the like).
107   const PseudoSourceValue *getGOT();
108
109   /// Return a pseudo source value referencing the constant pool. Since constant
110   /// pools are constant, this doesn't need to identify a specific constant
111   /// pool entry.
112   const PseudoSourceValue *getConstantPool();
113
114   /// Return a pseudo source value referencing a jump table. Since jump tables
115   /// are constant, this doesn't need to identify a specific jump table.
116   const PseudoSourceValue *getJumpTable();
117
118   /// Return a pseudo source value referencing a fixed stack frame entry,
119   /// e.g., a spill slot.
120   const PseudoSourceValue *getFixedStack(int FI);
121 };
122
123 } // end namespace llvm
124
125 #endif