1 //==- llvm/CodeGen/MachineMemOperand.h - MachineMemOperand class -*- 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 MachineMemOperand class, which is a
11 // description of a memory reference. It is used to help track dependencies
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H
17 #define LLVM_CODEGEN_MACHINEMEMOPERAND_H
19 #include "llvm/System/DataTypes.h"
24 class FoldingSetNodeID;
27 /// MachinePointerInfo - This class contains a discriminated union of
28 /// information about pointers in memory operands, relating them back to LLVM IR
29 /// or to virtual locations (such as frame indices) that are exposed during
31 struct MachinePointerInfo {
32 /// V - This is the IR pointer value for the access, or it is null if unknown.
33 /// If this is null, then the access is to a pointer in the default address
37 /// Offset - This is an offset from the base Value*.
40 explicit MachinePointerInfo(const Value *v = 0, int64_t offset = 0)
41 : V(v), Offset(offset) {}
43 MachinePointerInfo getWithOffset(int64_t O) const {
44 if (V == 0) return MachinePointerInfo(0, 0);
45 return MachinePointerInfo(V, Offset+O);
48 /// getAddrSpace - Return the LLVM IR address space number that this pointer
50 unsigned getAddrSpace() const;
52 /// getConstantPool - Return a MachinePointerInfo record that refers to the
54 static MachinePointerInfo getConstantPool();
56 /// getFixedStack - Return a MachinePointerInfo record that refers to the
57 /// the specified FrameIndex.
58 static MachinePointerInfo getFixedStack(int FI, int64_t offset = 0);
62 //===----------------------------------------------------------------------===//
63 /// MachineMemOperand - A description of a memory reference used in the backend.
64 /// Instead of holding a StoreInst or LoadInst, this class holds the address
65 /// Value of the reference along with a byte size and offset. This allows it
66 /// to describe lowered loads and stores. Also, the special PseudoSourceValue
67 /// objects can be used to represent loads and stores to memory locations
68 /// that aren't explicit in the regular LLVM IR.
70 class MachineMemOperand {
71 MachinePointerInfo PtrInfo;
76 /// Flags values. These may be or'd together.
77 enum MemOperandFlags {
78 /// The memory access reads data.
80 /// The memory access writes data.
82 /// The memory access is volatile.
84 /// The memory access is non-temporal.
86 // This is the number of bits we need to represent flags.
90 /// MachineMemOperand - Construct an MachineMemOperand object with the
91 /// specified PtrInfo, flags, size, and base alignment.
92 MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s,
93 unsigned base_alignment);
95 const MachinePointerInfo &getPointerInfo() const { return PtrInfo; }
97 /// getValue - Return the base address of the memory access. This may either
98 /// be a normal LLVM IR Value, or one of the special values used in CodeGen.
99 /// Special values are those obtained via
100 /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
101 /// other PseudoSourceValue member functions which return objects which stand
102 /// for frame/stack pointer relative references and other special references
103 /// which are not representable in the high-level IR.
104 const Value *getValue() const { return PtrInfo.V; }
106 /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
107 unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); }
109 /// getOffset - For normal values, this is a byte offset added to the base
110 /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
112 int64_t getOffset() const { return PtrInfo.Offset; }
114 /// getSize - Return the size in bytes of the memory reference.
115 uint64_t getSize() const { return Size; }
117 /// getAlignment - Return the minimum known alignment in bytes of the
118 /// actual memory reference.
119 uint64_t getAlignment() const;
121 /// getBaseAlignment - Return the minimum known alignment in bytes of the
122 /// base address, without the offset.
123 uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; }
125 bool isLoad() const { return Flags & MOLoad; }
126 bool isStore() const { return Flags & MOStore; }
127 bool isVolatile() const { return Flags & MOVolatile; }
128 bool isNonTemporal() const { return Flags & MONonTemporal; }
130 /// refineAlignment - Update this MachineMemOperand to reflect the alignment
131 /// of MMO, if it has a greater alignment. This must only be used when the
132 /// new alignment applies to all users of this MachineMemOperand.
133 void refineAlignment(const MachineMemOperand *MMO);
135 /// setValue - Change the SourceValue for this MachineMemOperand. This
136 /// should only be used when an object is being relocated and all references
137 /// to it are being updated.
138 void setValue(const Value *NewSV) { PtrInfo.V = NewSV; }
139 void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; }
141 /// Profile - Gather unique data for the object.
143 void Profile(FoldingSetNodeID &ID) const;
146 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO);
148 } // End llvm namespace