1193323Sed//==- llvm/CodeGen/MachineMemOperand.h - MachineMemOperand class -*- C++ -*-==// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file contains the declaration of the MachineMemOperand class, which is a 11193323Sed// description of a memory reference. It is used to help track dependencies 12193323Sed// in the backend. 13193323Sed// 14193323Sed//===----------------------------------------------------------------------===// 15193323Sed 16193323Sed#ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H 17193323Sed#define LLVM_CODEGEN_MACHINEMEMOPERAND_H 18193323Sed 19218893Sdim#include "llvm/Support/DataTypes.h" 20199481Srdivacky 21193323Sednamespace llvm { 22193323Sed 23193323Sedclass Value; 24193323Sedclass FoldingSetNodeID; 25234353Sdimclass MDNode; 26198090Srdivackyclass raw_ostream; 27193323Sed 28218893Sdim/// MachinePointerInfo - This class contains a discriminated union of 29218893Sdim/// information about pointers in memory operands, relating them back to LLVM IR 30218893Sdim/// or to virtual locations (such as frame indices) that are exposed during 31218893Sdim/// codegen. 32218893Sdimstruct MachinePointerInfo { 33218893Sdim /// V - This is the IR pointer value for the access, or it is null if unknown. 34218893Sdim /// If this is null, then the access is to a pointer in the default address 35218893Sdim /// space. 36218893Sdim const Value *V; 37251662Sdim 38218893Sdim /// Offset - This is an offset from the base Value*. 39218893Sdim int64_t Offset; 40251662Sdim 41218893Sdim explicit MachinePointerInfo(const Value *v = 0, int64_t offset = 0) 42218893Sdim : V(v), Offset(offset) {} 43251662Sdim 44218893Sdim MachinePointerInfo getWithOffset(int64_t O) const { 45218893Sdim if (V == 0) return MachinePointerInfo(0, 0); 46218893Sdim return MachinePointerInfo(V, Offset+O); 47218893Sdim } 48251662Sdim 49218893Sdim /// getAddrSpace - Return the LLVM IR address space number that this pointer 50218893Sdim /// points into. 51218893Sdim unsigned getAddrSpace() const; 52251662Sdim 53218893Sdim /// getConstantPool - Return a MachinePointerInfo record that refers to the 54218893Sdim /// constant pool. 55218893Sdim static MachinePointerInfo getConstantPool(); 56218893Sdim 57218893Sdim /// getFixedStack - Return a MachinePointerInfo record that refers to the 58218893Sdim /// the specified FrameIndex. 59218893Sdim static MachinePointerInfo getFixedStack(int FI, int64_t offset = 0); 60251662Sdim 61218893Sdim /// getJumpTable - Return a MachinePointerInfo record that refers to a 62218893Sdim /// jump table entry. 63218893Sdim static MachinePointerInfo getJumpTable(); 64251662Sdim 65218893Sdim /// getGOT - Return a MachinePointerInfo record that refers to a 66218893Sdim /// GOT entry. 67218893Sdim static MachinePointerInfo getGOT(); 68251662Sdim 69218893Sdim /// getStack - stack pointer relative access. 70218893Sdim static MachinePointerInfo getStack(int64_t Offset); 71218893Sdim}; 72251662Sdim 73251662Sdim 74193323Sed//===----------------------------------------------------------------------===// 75193323Sed/// MachineMemOperand - A description of a memory reference used in the backend. 76193323Sed/// Instead of holding a StoreInst or LoadInst, this class holds the address 77193323Sed/// Value of the reference along with a byte size and offset. This allows it 78193323Sed/// to describe lowered loads and stores. Also, the special PseudoSourceValue 79193323Sed/// objects can be used to represent loads and stores to memory locations 80193323Sed/// that aren't explicit in the regular LLVM IR. 81193323Sed/// 82193323Sedclass MachineMemOperand { 83218893Sdim MachinePointerInfo PtrInfo; 84193323Sed uint64_t Size; 85218893Sdim unsigned Flags; 86218893Sdim const MDNode *TBAAInfo; 87234353Sdim const MDNode *Ranges; 88193323Sed 89193323Sedpublic: 90193323Sed /// Flags values. These may be or'd together. 91193323Sed enum MemOperandFlags { 92193323Sed /// The memory access reads data. 93193323Sed MOLoad = 1, 94193323Sed /// The memory access writes data. 95193323Sed MOStore = 2, 96193323Sed /// The memory access is volatile. 97203954Srdivacky MOVolatile = 4, 98203954Srdivacky /// The memory access is non-temporal. 99203954Srdivacky MONonTemporal = 8, 100234353Sdim /// The memory access is invariant. 101234353Sdim MOInvariant = 16, 102251662Sdim // Target hints allow target passes to annotate memory operations. 103251662Sdim MOTargetStartBit = 5, 104251662Sdim MOTargetNumBits = 3, 105203954Srdivacky // This is the number of bits we need to represent flags. 106251662Sdim MOMaxBits = 8 107193323Sed }; 108193323Sed 109193323Sed /// MachineMemOperand - Construct an MachineMemOperand object with the 110218893Sdim /// specified PtrInfo, flags, size, and base alignment. 111218893Sdim MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s, 112234353Sdim unsigned base_alignment, const MDNode *TBAAInfo = 0, 113234353Sdim const MDNode *Ranges = 0); 114193323Sed 115218893Sdim const MachinePointerInfo &getPointerInfo() const { return PtrInfo; } 116251662Sdim 117198090Srdivacky /// getValue - Return the base address of the memory access. This may either 118198090Srdivacky /// be a normal LLVM IR Value, or one of the special values used in CodeGen. 119198090Srdivacky /// Special values are those obtained via 120198090Srdivacky /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and 121198090Srdivacky /// other PseudoSourceValue member functions which return objects which stand 122198090Srdivacky /// for frame/stack pointer relative references and other special references 123198090Srdivacky /// which are not representable in the high-level IR. 124218893Sdim const Value *getValue() const { return PtrInfo.V; } 125193323Sed 126193323Sed /// getFlags - Return the raw flags of the source value, \see MemOperandFlags. 127203954Srdivacky unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); } 128193323Sed 129251662Sdim /// Bitwise OR the current flags with the given flags. 130251662Sdim void setFlags(unsigned f) { Flags |= (f & ((1 << MOMaxBits) - 1)); } 131251662Sdim 132193323Sed /// getOffset - For normal values, this is a byte offset added to the base 133193323Sed /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex 134193323Sed /// number. 135218893Sdim int64_t getOffset() const { return PtrInfo.Offset; } 136193323Sed 137193323Sed /// getSize - Return the size in bytes of the memory reference. 138193323Sed uint64_t getSize() const { return Size; } 139193323Sed 140193323Sed /// getAlignment - Return the minimum known alignment in bytes of the 141198090Srdivacky /// actual memory reference. 142198090Srdivacky uint64_t getAlignment() const; 143193323Sed 144198090Srdivacky /// getBaseAlignment - Return the minimum known alignment in bytes of the 145198090Srdivacky /// base address, without the offset. 146203954Srdivacky uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; } 147198090Srdivacky 148218893Sdim /// getTBAAInfo - Return the TBAA tag for the memory reference. 149218893Sdim const MDNode *getTBAAInfo() const { return TBAAInfo; } 150218893Sdim 151234353Sdim /// getRanges - Return the range tag for the memory reference. 152234353Sdim const MDNode *getRanges() const { return Ranges; } 153234353Sdim 154193323Sed bool isLoad() const { return Flags & MOLoad; } 155193323Sed bool isStore() const { return Flags & MOStore; } 156193323Sed bool isVolatile() const { return Flags & MOVolatile; } 157203954Srdivacky bool isNonTemporal() const { return Flags & MONonTemporal; } 158234353Sdim bool isInvariant() const { return Flags & MOInvariant; } 159193323Sed 160243830Sdim /// isUnordered - Returns true if this memory operation doesn't have any 161243830Sdim /// ordering constraints other than normal aliasing. Volatile and atomic 162243830Sdim /// memory operations can't be reordered. 163243830Sdim /// 164243830Sdim /// Currently, we don't model the difference between volatile and atomic 165243830Sdim /// operations. They should retain their ordering relative to all memory 166243830Sdim /// operations. 167243830Sdim bool isUnordered() const { return !isVolatile(); } 168243830Sdim 169198090Srdivacky /// refineAlignment - Update this MachineMemOperand to reflect the alignment 170198090Srdivacky /// of MMO, if it has a greater alignment. This must only be used when the 171198090Srdivacky /// new alignment applies to all users of this MachineMemOperand. 172198090Srdivacky void refineAlignment(const MachineMemOperand *MMO); 173198090Srdivacky 174198090Srdivacky /// setValue - Change the SourceValue for this MachineMemOperand. This 175198090Srdivacky /// should only be used when an object is being relocated and all references 176198090Srdivacky /// to it are being updated. 177218893Sdim void setValue(const Value *NewSV) { PtrInfo.V = NewSV; } 178218893Sdim void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; } 179198090Srdivacky 180193323Sed /// Profile - Gather unique data for the object. 181193323Sed /// 182193323Sed void Profile(FoldingSetNodeID &ID) const; 183193323Sed}; 184193323Sed 185198090Srdivackyraw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO); 186198090Srdivacky 187193323Sed} // End llvm namespace 188193323Sed 189193323Sed#endif 190