1 //===- MemoryLocation.cpp - Memory location descriptions -------------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Analysis/MemoryLocation.h"
11 #include "llvm/IR/BasicBlock.h"
12 #include "llvm/IR/DataLayout.h"
13 #include "llvm/IR/Instructions.h"
14 #include "llvm/IR/IntrinsicInst.h"
15 #include "llvm/IR/LLVMContext.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/IR/Type.h"
20 MemoryLocation MemoryLocation::get(const LoadInst *LI) {
22 LI->getAAMetadata(AATags);
23 const auto &DL = LI->getModule()->getDataLayout();
25 return MemoryLocation(LI->getPointerOperand(),
26 DL.getTypeStoreSize(LI->getType()), AATags);
29 MemoryLocation MemoryLocation::get(const StoreInst *SI) {
31 SI->getAAMetadata(AATags);
32 const auto &DL = SI->getModule()->getDataLayout();
34 return MemoryLocation(SI->getPointerOperand(),
35 DL.getTypeStoreSize(SI->getValueOperand()->getType()),
39 MemoryLocation MemoryLocation::get(const VAArgInst *VI) {
41 VI->getAAMetadata(AATags);
43 return MemoryLocation(VI->getPointerOperand(), UnknownSize, AATags);
46 MemoryLocation MemoryLocation::get(const AtomicCmpXchgInst *CXI) {
48 CXI->getAAMetadata(AATags);
49 const auto &DL = CXI->getModule()->getDataLayout();
51 return MemoryLocation(
52 CXI->getPointerOperand(),
53 DL.getTypeStoreSize(CXI->getCompareOperand()->getType()), AATags);
56 MemoryLocation MemoryLocation::get(const AtomicRMWInst *RMWI) {
58 RMWI->getAAMetadata(AATags);
59 const auto &DL = RMWI->getModule()->getDataLayout();
61 return MemoryLocation(RMWI->getPointerOperand(),
62 DL.getTypeStoreSize(RMWI->getValOperand()->getType()),
66 MemoryLocation MemoryLocation::getForSource(const MemTransferInst *MTI) {
67 uint64_t Size = UnknownSize;
68 if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
69 Size = C->getValue().getZExtValue();
71 // memcpy/memmove can have AA tags. For memcpy, they apply
72 // to both the source and the destination.
74 MTI->getAAMetadata(AATags);
76 return MemoryLocation(MTI->getRawSource(), Size, AATags);
79 MemoryLocation MemoryLocation::getForDest(const MemIntrinsic *MTI) {
80 uint64_t Size = UnknownSize;
81 if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
82 Size = C->getValue().getZExtValue();
84 // memcpy/memmove can have AA tags. For memcpy, they apply
85 // to both the source and the destination.
87 MTI->getAAMetadata(AATags);
89 return MemoryLocation(MTI->getRawDest(), Size, AATags);