de238e48d10a84000e6917ce18f625f21c7e473b
[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 namespace llvm {
20
21 class Value;
22 class FoldingSetNodeID;
23
24 //===----------------------------------------------------------------------===//
25 /// MachineMemOperand - A description of a memory reference used in the backend.
26 /// Instead of holding a StoreInst or LoadInst, this class holds the address
27 /// Value of the reference along with a byte size and offset. This allows it
28 /// to describe lowered loads and stores. Also, the special PseudoSourceValue
29 /// objects can be used to represent loads and stores to memory locations
30 /// that aren't explicit in the regular LLVM IR.
31 ///
32 class MachineMemOperand {
33   int64_t Offset;
34   uint64_t Size;
35   const Value *V;
36   unsigned int Flags;
37
38 public:
39   /// Flags values. These may be or'd together.
40   enum MemOperandFlags {
41     /// The memory access reads data.
42     MOLoad = 1,
43     /// The memory access writes data.
44     MOStore = 2,
45     /// The memory access is volatile.
46     MOVolatile = 4
47   };
48
49   /// MachineMemOperand - Construct an MachineMemOperand object with the
50   /// specified address Value, flags, offset, size, and alignment.
51   MachineMemOperand(const Value *v, unsigned int f, int64_t o, uint64_t s,
52                     unsigned int a);
53
54   /// getValue - Return the base address of the memory access. This may either
55   /// be a normal LLVM IR Value, or one of the special values used in CodeGen.
56   /// Special values are those obtained via
57   /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
58   /// other PseudoSourceValue member functions which return objects which stand
59   /// for frame/stack pointer relative references and other special references
60   /// which are not representable in the high-level IR.
61   const Value *getValue() const { return V; }
62
63   /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
64   unsigned int getFlags() const { return Flags & 7; }
65
66   /// getOffset - For normal values, this is a byte offset added to the base
67   /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
68   /// number.
69   int64_t getOffset() const { return Offset; }
70
71   /// getSize - Return the size in bytes of the memory reference.
72   uint64_t getSize() const { return Size; }
73
74   /// getAlignment - Return the minimum known alignment in bytes of the
75   /// memory reference.
76   unsigned int getAlignment() const { return (1u << (Flags >> 3)) >> 1; }
77
78   bool isLoad() const { return Flags & MOLoad; }
79   bool isStore() const { return Flags & MOStore; }
80   bool isVolatile() const { return Flags & MOVolatile; }
81
82   /// Profile - Gather unique data for the object.
83   ///
84   void Profile(FoldingSetNodeID &ID) const;
85 };
86
87 } // End llvm namespace
88
89 #endif