| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H |
| 16 |
#define LLVM_CODEGEN_MACHINEMEMOPERAND_H |
| 17 |
|
| 18 |
#include "llvm/ADT/BitmaskEnum.h" |
| 19 |
#include "llvm/ADT/PointerUnion.h" |
| 20 |
#include "llvm/CodeGen/PseudoSourceValue.h" |
| 21 |
#include "llvm/IR/DerivedTypes.h" |
| 22 |
#include "llvm/IR/Value.h" |
| 23 |
#include "llvm/Support/AtomicOrdering.h" |
| 24 |
#include "llvm/Support/DataTypes.h" |
| 25 |
#include "llvm/Support/LowLevelTypeImpl.h" |
| 26 |
|
| 27 |
namespace llvm { |
| 28 |
|
| 29 |
class FoldingSetNodeID; |
| 30 |
class MDNode; |
| 31 |
class raw_ostream; |
| 32 |
class MachineFunction; |
| 33 |
class ModuleSlotTracker; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
struct MachinePointerInfo { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
PointerUnion<const Value *, const PseudoSourceValue *> V; |
| 43 |
|
| 44 |
|
| 45 |
int64_t Offset; |
| 46 |
|
| 47 |
unsigned AddrSpace = 0; |
| 48 |
|
| 49 |
uint8_t StackID; |
| 50 |
|
| 51 |
explicit MachinePointerInfo(const Value *v, int64_t offset = 0, |
| 52 |
uint8_t ID = 0) |
| 53 |
: V(v), Offset(offset), StackID(ID) { |
| 54 |
AddrSpace = v ? v->getType()->getPointerAddressSpace() : 0; |
| 55 |
} |
| 56 |
|
| 57 |
explicit MachinePointerInfo(const PseudoSourceValue *v, int64_t offset = 0, |
| 58 |
uint8_t ID = 0) |
| 59 |
: V(v), Offset(offset), StackID(ID) { |
| 60 |
AddrSpace = v ? v->getAddressSpace() : 0; |
| 61 |
} |
| 62 |
|
| 63 |
explicit MachinePointerInfo(unsigned AddressSpace = 0, int64_t offset = 0) |
| 64 |
: V((const Value *)nullptr), Offset(offset), AddrSpace(AddressSpace), |
| 65 |
StackID(0) {} |
| 66 |
|
| 67 |
explicit MachinePointerInfo( |
| 68 |
PointerUnion<const Value *, const PseudoSourceValue *> v, |
| 69 |
int64_t offset = 0, |
| 70 |
uint8_t ID = 0) |
| 71 |
: V(v), Offset(offset), StackID(ID) { |
| 72 |
if (V) { |
| 73 |
if (const auto *ValPtr = V.dyn_cast<const Value*>()) |
| 74 |
AddrSpace = ValPtr->getType()->getPointerAddressSpace(); |
| 75 |
else |
| 76 |
AddrSpace = V.get<const PseudoSourceValue*>()->getAddressSpace(); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
MachinePointerInfo getWithOffset(int64_t O) const { |
| 81 |
if (V.isNull()) |
| 82 |
return MachinePointerInfo(AddrSpace, Offset + O); |
| 83 |
if (V.is<const Value*>()) |
| 84 |
return MachinePointerInfo(V.get<const Value*>(), Offset + O, StackID); |
| 85 |
return MachinePointerInfo(V.get<const PseudoSourceValue*>(), Offset + O, |
| 86 |
StackID); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
bool isDereferenceable(unsigned Size, LLVMContext &C, |
| 92 |
const DataLayout &DL) const; |
| 93 |
|
| 94 |
|
| 95 |
unsigned getAddrSpace() const; |
| 96 |
|
| 97 |
|
| 98 |
static MachinePointerInfo getConstantPool(MachineFunction &MF); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, |
| 103 |
int64_t Offset = 0); |
| 104 |
|
| 105 |
|
| 106 |
static MachinePointerInfo getJumpTable(MachineFunction &MF); |
| 107 |
|
| 108 |
|
| 109 |
static MachinePointerInfo getGOT(MachineFunction &MF); |
| 110 |
|
| 111 |
|
| 112 |
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, |
| 113 |
uint8_t ID = 0); |
| 114 |
|
| 115 |
|
| 116 |
static MachinePointerInfo getUnknownStack(MachineFunction &MF); |
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
class MachineMemOperand { |
| 129 |
public: |
| 130 |
|
| 131 |
enum Flags : uint16_t { |
| 132 |
|
| 133 |
MONone = 0, |
| 134 |
|
| 135 |
MOLoad = 1u << 0, |
| 136 |
|
| 137 |
MOStore = 1u << 1, |
| 138 |
|
| 139 |
MOVolatile = 1u << 2, |
| 140 |
|
| 141 |
MONonTemporal = 1u << 3, |
| 142 |
|
| 143 |
MODereferenceable = 1u << 4, |
| 144 |
|
| 145 |
MOInvariant = 1u << 5, |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
MOTargetFlag1 = 1u << 6, |
| 152 |
MOTargetFlag2 = 1u << 7, |
| 153 |
MOTargetFlag3 = 1u << 8, |
| 154 |
|
| 155 |
LLVM_MARK_AS_BITMASK_ENUM( MOTargetFlag3) |
| 156 |
}; |
| 157 |
|
| 158 |
private: |
| 159 |
|
| 160 |
struct MachineAtomicInfo { |
| 161 |
|
| 162 |
unsigned SSID : 8; |
| 163 |
|
| 164 |
|
| 165 |
unsigned Ordering : 4; |
| 166 |
|
| 167 |
|
| 168 |
unsigned FailureOrdering : 4; |
| 169 |
}; |
| 170 |
|
| 171 |
MachinePointerInfo PtrInfo; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
LLT MemoryType; |
| 176 |
|
| 177 |
Flags FlagVals; |
| 178 |
Align BaseAlign; |
| 179 |
MachineAtomicInfo AtomicInfo; |
| 180 |
AAMDNodes AAInfo; |
| 181 |
const MDNode *Ranges; |
| 182 |
|
| 183 |
public: |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
MachineMemOperand(MachinePointerInfo PtrInfo, Flags flags, uint64_t s, |
| 190 |
Align a, const AAMDNodes &AAInfo = AAMDNodes(), |
| 191 |
const MDNode *Ranges = nullptr, |
| 192 |
SyncScope::ID SSID = SyncScope::System, |
| 193 |
AtomicOrdering Ordering = AtomicOrdering::NotAtomic, |
| 194 |
AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic); |
| 195 |
MachineMemOperand(MachinePointerInfo PtrInfo, Flags flags, LLT type, Align a, |
| 196 |
const AAMDNodes &AAInfo = AAMDNodes(), |
| 197 |
const MDNode *Ranges = nullptr, |
| 198 |
SyncScope::ID SSID = SyncScope::System, |
| 199 |
AtomicOrdering Ordering = AtomicOrdering::NotAtomic, |
| 200 |
AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic); |
| 201 |
|
| 202 |
const MachinePointerInfo &getPointerInfo() const { return PtrInfo; } |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
const Value *getValue() const { return PtrInfo.V.dyn_cast<const Value*>(); } |
| 212 |
|
| 213 |
const PseudoSourceValue *getPseudoValue() const { |
| 214 |
return PtrInfo.V.dyn_cast<const PseudoSourceValue*>(); |
| 215 |
} |
| 216 |
|
| 217 |
const void *getOpaqueValue() const { return PtrInfo.V.getOpaqueValue(); } |
| 218 |
|
| 219 |
|
| 220 |
Flags getFlags() const { return FlagVals; } |
| 221 |
|
| 222 |
|
| 223 |
void setFlags(Flags f) { FlagVals |= f; } |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
int64_t getOffset() const { return PtrInfo.Offset; } |
| 228 |
|
| 229 |
unsigned getAddrSpace() const { return PtrInfo.getAddrSpace(); } |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
LLT getMemoryType() const { return MemoryType; } |
| 234 |
|
| 235 |
|
| 236 |
uint64_t getSize() const { |
| 237 |
return MemoryType.isValid() ? MemoryType.getSizeInBytes() : ~UINT64_C(0); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
uint64_t getSizeInBits() const { |
| 242 |
return MemoryType.isValid() ? MemoryType.getSizeInBits() : ~UINT64_C(0); |
| 243 |
} |
| 244 |
|
| 245 |
LLT getType() const { |
| 246 |
return MemoryType; |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
Align getAlign() const; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
Align getBaseAlign() const { return BaseAlign; } |
| 256 |
|
| 257 |
|
| 258 |
AAMDNodes getAAInfo() const { return AAInfo; } |
| 259 |
|
| 260 |
|
| 261 |
const MDNode *getRanges() const { return Ranges; } |
| 262 |
|
| 263 |
|
| 264 |
SyncScope::ID getSyncScopeID() const { |
| 265 |
return static_cast<SyncScope::ID>(AtomicInfo.SSID); |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
AtomicOrdering getSuccessOrdering() const { |
| 272 |
return static_cast<AtomicOrdering>(AtomicInfo.Ordering); |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
AtomicOrdering getFailureOrdering() const { |
| 278 |
return static_cast<AtomicOrdering>(AtomicInfo.FailureOrdering); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
AtomicOrdering getMergedOrdering() const { |
| 285 |
return getMergedAtomicOrdering(getSuccessOrdering(), getFailureOrdering()); |
| 286 |
} |
| 287 |
|
| 288 |
bool isLoad() const { return FlagVals & MOLoad; } |
| 289 |
bool isStore() const { return FlagVals & MOStore; } |
| 290 |
bool isVolatile() const { return FlagVals & MOVolatile; } |
| 291 |
bool isNonTemporal() const { return FlagVals & MONonTemporal; } |
| 292 |
bool isDereferenceable() const { return FlagVals & MODereferenceable; } |
| 293 |
bool isInvariant() const { return FlagVals & MOInvariant; } |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
bool isAtomic() const { |
| 298 |
return getSuccessOrdering() != AtomicOrdering::NotAtomic; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
bool isUnordered() const { |
| 305 |
return (getSuccessOrdering() == AtomicOrdering::NotAtomic || |
| 306 |
getSuccessOrdering() == AtomicOrdering::Unordered) && |
| 307 |
!isVolatile(); |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
void refineAlignment(const MachineMemOperand *MMO); |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
void setValue(const Value *NewSV) { PtrInfo.V = NewSV; } |
| 319 |
void setValue(const PseudoSourceValue *NewSV) { PtrInfo.V = NewSV; } |
| 320 |
void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; } |
| 321 |
|
| 322 |
|
| 323 |
void setType(LLT NewTy) { |
| 324 |
MemoryType = NewTy; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
void Profile(FoldingSetNodeID &ID) const; |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
void print(raw_ostream &OS, ModuleSlotTracker &MST, |
| 334 |
SmallVectorImpl<StringRef> &SSNs, const LLVMContext &Context, |
| 335 |
const MachineFrameInfo *MFI, const TargetInstrInfo *TII) const; |
| 336 |
|
| 337 |
|
| 338 |
friend bool operator==(const MachineMemOperand &LHS, |
| 339 |
const MachineMemOperand &RHS) { |
| 340 |
return LHS.getValue() == RHS.getValue() && |
| 341 |
LHS.getPseudoValue() == RHS.getPseudoValue() && |
| 342 |
LHS.getSize() == RHS.getSize() && |
| 343 |
LHS.getOffset() == RHS.getOffset() && |
| 344 |
LHS.getFlags() == RHS.getFlags() && |
| 345 |
LHS.getAAInfo() == RHS.getAAInfo() && |
| 346 |
LHS.getRanges() == RHS.getRanges() && |
| 347 |
LHS.getAlign() == RHS.getAlign() && |
| 348 |
LHS.getAddrSpace() == RHS.getAddrSpace(); |
| 349 |
} |
| 350 |
|
| 351 |
friend bool operator!=(const MachineMemOperand &LHS, |
| 352 |
const MachineMemOperand &RHS) { |
| 353 |
return !(LHS == RHS); |
| 354 |
} |
| 355 |
}; |
| 356 |
|
| 357 |
} |
| 358 |
|
| 359 |
#endif |