b9b35e6152bdf493973ddb22ec53cb573617d0ea
[oota-llvm.git] / include / llvm / CodeGen / MachineMemOperand.h
1 //==- llvm/CodeGen/MachineMemOperand.h - MachineMemOperand class -*- 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 MachineMemOperand class, which is a
11 // description of a memory reference. It is used to help track dependencies
12 // in the backend.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H
17 #define LLVM_CODEGEN_MACHINEMEMOPERAND_H
18
19 #include "llvm/System/DataTypes.h"
20
21 namespace llvm {
22
23 class Value;
24 class FoldingSetNodeID;
25 class raw_ostream;
26
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
30 /// codegen.
31 struct MachinePointerInfo {
32   const Value *V;
33   int64_t Offset;
34   MachinePointerInfo(const Value *v, int64_t offset) : V(v), Offset(offset) {}
35 };
36   
37   
38 //===----------------------------------------------------------------------===//
39 /// MachineMemOperand - A description of a memory reference used in the backend.
40 /// Instead of holding a StoreInst or LoadInst, this class holds the address
41 /// Value of the reference along with a byte size and offset. This allows it
42 /// to describe lowered loads and stores. Also, the special PseudoSourceValue
43 /// objects can be used to represent loads and stores to memory locations
44 /// that aren't explicit in the regular LLVM IR.
45 ///
46 class MachineMemOperand {
47   MachinePointerInfo PtrInfo;
48   uint64_t Size;
49   unsigned Flags;
50
51 public:
52   /// Flags values. These may be or'd together.
53   enum MemOperandFlags {
54     /// The memory access reads data.
55     MOLoad = 1,
56     /// The memory access writes data.
57     MOStore = 2,
58     /// The memory access is volatile.
59     MOVolatile = 4,
60     /// The memory access is non-temporal.
61     MONonTemporal = 8,
62     // This is the number of bits we need to represent flags.
63     MOMaxBits = 4
64   };
65
66   /// MachineMemOperand - Construct an MachineMemOperand object with the
67   /// specified address Value, flags, offset, size, and base alignment.
68   MachineMemOperand(const Value *v, unsigned int f, int64_t o, uint64_t s,
69                     unsigned int base_alignment);
70
71   /// getValue - Return the base address of the memory access. This may either
72   /// be a normal LLVM IR Value, or one of the special values used in CodeGen.
73   /// Special values are those obtained via
74   /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
75   /// other PseudoSourceValue member functions which return objects which stand
76   /// for frame/stack pointer relative references and other special references
77   /// which are not representable in the high-level IR.
78   const Value *getValue() const { return PtrInfo.V; }
79
80   /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
81   unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); }
82
83   /// getOffset - For normal values, this is a byte offset added to the base
84   /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
85   /// number.
86   int64_t getOffset() const { return PtrInfo.Offset; }
87
88   /// getSize - Return the size in bytes of the memory reference.
89   uint64_t getSize() const { return Size; }
90
91   /// getAlignment - Return the minimum known alignment in bytes of the
92   /// actual memory reference.
93   uint64_t getAlignment() const;
94
95   /// getBaseAlignment - Return the minimum known alignment in bytes of the
96   /// base address, without the offset.
97   uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; }
98
99   bool isLoad() const { return Flags & MOLoad; }
100   bool isStore() const { return Flags & MOStore; }
101   bool isVolatile() const { return Flags & MOVolatile; }
102   bool isNonTemporal() const { return Flags & MONonTemporal; }
103
104   /// refineAlignment - Update this MachineMemOperand to reflect the alignment
105   /// of MMO, if it has a greater alignment. This must only be used when the
106   /// new alignment applies to all users of this MachineMemOperand.
107   void refineAlignment(const MachineMemOperand *MMO);
108
109   /// setValue - Change the SourceValue for this MachineMemOperand. This
110   /// should only be used when an object is being relocated and all references
111   /// to it are being updated.
112   void setValue(const Value *NewSV) { PtrInfo.V = NewSV; }
113   void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; }
114
115   /// Profile - Gather unique data for the object.
116   ///
117   void Profile(FoldingSetNodeID &ID) const;
118 };
119
120 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO);
121
122 } // End llvm namespace
123
124 #endif