LLVM API Documentation
00001 //==- llvm/CodeGen/MachineMemOperand.h - MachineMemOperand class -*- C++ -*-==// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the declaration of the MachineMemOperand class, which is a 00011 // description of a memory reference. It is used to help track dependencies 00012 // in the backend. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H 00017 #define LLVM_CODEGEN_MACHINEMEMOPERAND_H 00018 00019 #include "llvm/Support/DataTypes.h" 00020 00021 namespace llvm { 00022 00023 class Value; 00024 class FoldingSetNodeID; 00025 class MDNode; 00026 class raw_ostream; 00027 00028 /// MachinePointerInfo - This class contains a discriminated union of 00029 /// information about pointers in memory operands, relating them back to LLVM IR 00030 /// or to virtual locations (such as frame indices) that are exposed during 00031 /// codegen. 00032 struct MachinePointerInfo { 00033 /// V - This is the IR pointer value for the access, or it is null if unknown. 00034 /// If this is null, then the access is to a pointer in the default address 00035 /// space. 00036 const Value *V; 00037 00038 /// Offset - This is an offset from the base Value*. 00039 int64_t Offset; 00040 00041 explicit MachinePointerInfo(const Value *v = 0, int64_t offset = 0) 00042 : V(v), Offset(offset) {} 00043 00044 MachinePointerInfo getWithOffset(int64_t O) const { 00045 if (V == 0) return MachinePointerInfo(0, 0); 00046 return MachinePointerInfo(V, Offset+O); 00047 } 00048 00049 /// getAddrSpace - Return the LLVM IR address space number that this pointer 00050 /// points into. 00051 unsigned getAddrSpace() const; 00052 00053 /// getConstantPool - Return a MachinePointerInfo record that refers to the 00054 /// constant pool. 00055 static MachinePointerInfo getConstantPool(); 00056 00057 /// getFixedStack - Return a MachinePointerInfo record that refers to the 00058 /// the specified FrameIndex. 00059 static MachinePointerInfo getFixedStack(int FI, int64_t offset = 0); 00060 00061 /// getJumpTable - Return a MachinePointerInfo record that refers to a 00062 /// jump table entry. 00063 static MachinePointerInfo getJumpTable(); 00064 00065 /// getGOT - Return a MachinePointerInfo record that refers to a 00066 /// GOT entry. 00067 static MachinePointerInfo getGOT(); 00068 00069 /// getStack - stack pointer relative access. 00070 static MachinePointerInfo getStack(int64_t Offset); 00071 }; 00072 00073 00074 //===----------------------------------------------------------------------===// 00075 /// MachineMemOperand - A description of a memory reference used in the backend. 00076 /// Instead of holding a StoreInst or LoadInst, this class holds the address 00077 /// Value of the reference along with a byte size and offset. This allows it 00078 /// to describe lowered loads and stores. Also, the special PseudoSourceValue 00079 /// objects can be used to represent loads and stores to memory locations 00080 /// that aren't explicit in the regular LLVM IR. 00081 /// 00082 class MachineMemOperand { 00083 MachinePointerInfo PtrInfo; 00084 uint64_t Size; 00085 unsigned Flags; 00086 const MDNode *TBAAInfo; 00087 const MDNode *Ranges; 00088 00089 public: 00090 /// Flags values. These may be or'd together. 00091 enum MemOperandFlags { 00092 /// The memory access reads data. 00093 MOLoad = 1, 00094 /// The memory access writes data. 00095 MOStore = 2, 00096 /// The memory access is volatile. 00097 MOVolatile = 4, 00098 /// The memory access is non-temporal. 00099 MONonTemporal = 8, 00100 /// The memory access is invariant. 00101 MOInvariant = 16, 00102 // Target hints allow target passes to annotate memory operations. 00103 MOTargetStartBit = 5, 00104 MOTargetNumBits = 3, 00105 // This is the number of bits we need to represent flags. 00106 MOMaxBits = 8 00107 }; 00108 00109 /// MachineMemOperand - Construct an MachineMemOperand object with the 00110 /// specified PtrInfo, flags, size, and base alignment. 00111 MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s, 00112 unsigned base_alignment, const MDNode *TBAAInfo = 0, 00113 const MDNode *Ranges = 0); 00114 00115 const MachinePointerInfo &getPointerInfo() const { return PtrInfo; } 00116 00117 /// getValue - Return the base address of the memory access. This may either 00118 /// be a normal LLVM IR Value, or one of the special values used in CodeGen. 00119 /// Special values are those obtained via 00120 /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and 00121 /// other PseudoSourceValue member functions which return objects which stand 00122 /// for frame/stack pointer relative references and other special references 00123 /// which are not representable in the high-level IR. 00124 const Value *getValue() const { return PtrInfo.V; } 00125 00126 /// getFlags - Return the raw flags of the source value, \see MemOperandFlags. 00127 unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); } 00128 00129 /// Bitwise OR the current flags with the given flags. 00130 void setFlags(unsigned f) { Flags |= (f & ((1 << MOMaxBits) - 1)); } 00131 00132 /// getOffset - For normal values, this is a byte offset added to the base 00133 /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex 00134 /// number. 00135 int64_t getOffset() const { return PtrInfo.Offset; } 00136 00137 /// getSize - Return the size in bytes of the memory reference. 00138 uint64_t getSize() const { return Size; } 00139 00140 /// getAlignment - Return the minimum known alignment in bytes of the 00141 /// actual memory reference. 00142 uint64_t getAlignment() const; 00143 00144 /// getBaseAlignment - Return the minimum known alignment in bytes of the 00145 /// base address, without the offset. 00146 uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; } 00147 00148 /// getTBAAInfo - Return the TBAA tag for the memory reference. 00149 const MDNode *getTBAAInfo() const { return TBAAInfo; } 00150 00151 /// getRanges - Return the range tag for the memory reference. 00152 const MDNode *getRanges() const { return Ranges; } 00153 00154 bool isLoad() const { return Flags & MOLoad; } 00155 bool isStore() const { return Flags & MOStore; } 00156 bool isVolatile() const { return Flags & MOVolatile; } 00157 bool isNonTemporal() const { return Flags & MONonTemporal; } 00158 bool isInvariant() const { return Flags & MOInvariant; } 00159 00160 /// isUnordered - Returns true if this memory operation doesn't have any 00161 /// ordering constraints other than normal aliasing. Volatile and atomic 00162 /// memory operations can't be reordered. 00163 /// 00164 /// Currently, we don't model the difference between volatile and atomic 00165 /// operations. They should retain their ordering relative to all memory 00166 /// operations. 00167 bool isUnordered() const { return !isVolatile(); } 00168 00169 /// refineAlignment - Update this MachineMemOperand to reflect the alignment 00170 /// of MMO, if it has a greater alignment. This must only be used when the 00171 /// new alignment applies to all users of this MachineMemOperand. 00172 void refineAlignment(const MachineMemOperand *MMO); 00173 00174 /// setValue - Change the SourceValue for this MachineMemOperand. This 00175 /// should only be used when an object is being relocated and all references 00176 /// to it are being updated. 00177 void setValue(const Value *NewSV) { PtrInfo.V = NewSV; } 00178 void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; } 00179 00180 /// Profile - Gather unique data for the object. 00181 /// 00182 void Profile(FoldingSetNodeID &ID) const; 00183 }; 00184 00185 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO); 00186 00187 } // End llvm namespace 00188 00189 #endif