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