Create a new class, MemOperand, for describing memory references
[oota-llvm.git] / include / llvm / CodeGen / MemOperand.h
1 //===-- llvm/CodeGen/MemOperand.h - MemOperand 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 MemOperand 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 namespace llvm {
20
21 class Value;
22
23 //===----------------------------------------------------------------------===//
24 /// MemOperand - A description of a memory reference used in the backend.
25 /// Instead of holding a StoreInst or LoadInst, this class holds the address
26 /// Value of the reference along with a byte size and offset. This allows it
27 /// to describe lowered loads and stores. Also, the special PseudoSourceValue
28 /// objects can be used to represent loads and stores to memory locations
29 /// that aren't explicit in the regular LLVM IR.
30 ///
31 class MemOperand {
32   const Value *V;
33   unsigned int Flags;
34   int Offset;
35   int Size;
36   unsigned int Alignment;
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   /// MemOperand - Construct an MemOperand object with the specified
50   /// address Value, flags, offset, size, and alignment.
51   MemOperand(const Value *v, unsigned int f, int o, int s, unsigned int a)
52     : V(v), Flags(f), Offset(o), Size(s), Alignment(a) {}
53
54   /// getValue - Return the base address of the memory access.
55   /// Special values are PseudoSourceValue::FPRel, PseudoSourceValue::SPRel,
56   /// and the other PseudoSourceValue members which indicate references to
57   /// frame/stack pointer relative references and other special references.
58   const Value *getValue() const { return V; }
59
60   /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
61   unsigned int getFlags() const { return Flags; }
62
63   /// getOffset - For normal values, this is a byte offset added to the base
64   /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
65   /// number.
66   int getOffset() const { return Offset; }
67
68   /// getSize - Return the size in bytes of the memory reference.
69   int getSize() const { return Size; }
70
71   /// getAlignment - Return the minimum known alignment in bytes of the
72   /// memory reference.
73   unsigned int getAlignment() const { return Alignment; }
74
75   bool isLoad() const { return Flags & MOLoad; }
76   bool isStore() const { return Flags & MOStore; }
77   bool isVolatile() const { return Flags & MOVolatile; }
78 };
79
80 } // End llvm namespace
81
82 #endif