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