1 //===-- llvm/CodeGen/PseudoSourceValue.h ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the PseudoSourceValue class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
15 #define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
17 #include "llvm/IR/Value.h"
22 class MachineFrameInfo;
23 class MachineMemOperand;
26 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO);
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 {
33 enum PSVKind { Stack, GOT, JumpTable, ConstantPool, FixedStack, MipsPSV };
38 friend class MachineMemOperand; // For printCustom().
40 /// Implement printing for PseudoSourceValue. This is called from
41 /// Value::print or Value's operator<<.
42 virtual void printCustom(raw_ostream &O) const;
45 explicit PseudoSourceValue(PSVKind Kind);
47 virtual ~PseudoSourceValue();
49 PSVKind kind() const { return Kind; }
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; }
56 /// Test whether the memory pointed to by this PseudoSourceValue has a
58 virtual bool isConstant(const MachineFrameInfo *) const;
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;
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;
69 /// A specialized PseudoSourceValue for holding FixedStack values, which must
70 /// include a frame index.
71 class FixedStackPseudoSourceValue : public PseudoSourceValue {
75 explicit FixedStackPseudoSourceValue(int FI)
76 : PseudoSourceValue(FixedStack), FI(FI) {}
78 static inline bool classof(const PseudoSourceValue *V) {
79 return V->kind() == FixedStack;
82 bool isConstant(const MachineFrameInfo *MFI) const override;
84 bool isAliased(const MachineFrameInfo *MFI) const override;
86 bool mayAlias(const MachineFrameInfo *) const override;
88 void printCustom(raw_ostream &OS) const override;
90 int getFrameIndex() const { return FI; }
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;
99 PseudoSourceValueManager();
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();
105 /// Return a pseudo source value referencing the global offset table
106 /// (or something the like).
107 const PseudoSourceValue *getGOT();
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
112 const PseudoSourceValue *getConstantPool();
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();
118 /// Return a pseudo source value referencing a fixed stack frame entry,
119 /// e.g., a spill slot.
120 const PseudoSourceValue *getFixedStack(int FI);
123 } // end namespace llvm