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 //===----------------------------------------------------------------------===//
28 /// MachineMemOperand - A description of a memory reference used in the backend.
29 /// Instead of holding a StoreInst or LoadInst, this class holds the address
30 /// Value of the reference along with a byte size and offset. This allows it
31 /// to describe lowered loads and stores. Also, the special PseudoSourceValue
32 /// objects can be used to represent loads and stores to memory locations
33 /// that aren't explicit in the regular LLVM IR.
35 class MachineMemOperand {
42 /// Flags values. These may be or'd together.
43 enum MemOperandFlags {
44 /// The memory access reads data.
46 /// The memory access writes data.
48 /// The memory access is volatile.
52 /// MachineMemOperand - Construct an MachineMemOperand object with the
53 /// specified address Value, flags, offset, size, and base alignment.
54 MachineMemOperand(const Value *v, unsigned int f, int64_t o, uint64_t s,
55 unsigned int base_alignment);
57 /// getValue - Return the base address of the memory access. This may either
58 /// be a normal LLVM IR Value, or one of the special values used in CodeGen.
59 /// Special values are those obtained via
60 /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
61 /// other PseudoSourceValue member functions which return objects which stand
62 /// for frame/stack pointer relative references and other special references
63 /// which are not representable in the high-level IR.
64 const Value *getValue() const { return V; }
66 /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
67 unsigned int getFlags() const { return Flags & 7; }
69 /// getOffset - For normal values, this is a byte offset added to the base
70 /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
72 int64_t getOffset() const { return Offset; }
74 /// getSize - Return the size in bytes of the memory reference.
75 uint64_t getSize() const { return Size; }
77 /// getAlignment - Return the minimum known alignment in bytes of the
78 /// actual memory reference.
79 uint64_t getAlignment() const;
81 /// getBaseAlignment - Return the minimum known alignment in bytes of the
82 /// base address, without the offset.
83 uint64_t getBaseAlignment() const { return (1u << (Flags >> 3)) >> 1; }
85 bool isLoad() const { return Flags & MOLoad; }
86 bool isStore() const { return Flags & MOStore; }
87 bool isVolatile() const { return Flags & MOVolatile; }
89 /// refineAlignment - Update this MachineMemOperand to reflect the alignment
90 /// of MMO, if it has a greater alignment. This must only be used when the
91 /// new alignment applies to all users of this MachineMemOperand.
92 void refineAlignment(const MachineMemOperand *MMO);
94 /// setValue - Change the SourceValue for this MachineMemOperand. This
95 /// should only be used when an object is being relocated and all references
96 /// to it are being updated.
97 void setValue(const Value *NewSV) { V = NewSV; }
99 /// Profile - Gather unique data for the object.
101 void Profile(FoldingSetNodeID &ID) const;
104 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO);
106 } // End llvm namespace