Chandler Carruth | 70c61c1 | 2015-06-04 02:03:15 +0000 | [diff] [blame^] | 1 | //===- MemoryLocation.cpp - Memory location descriptions -------------------==// |
| 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 | #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" |
| 18 | using namespace llvm; |
| 19 | |
| 20 | MemoryLocation MemoryLocation::get(const LoadInst *LI) { |
| 21 | AAMDNodes AATags; |
| 22 | LI->getAAMetadata(AATags); |
| 23 | const auto &DL = LI->getModule()->getDataLayout(); |
| 24 | |
| 25 | return MemoryLocation(LI->getPointerOperand(), |
| 26 | DL.getTypeStoreSize(LI->getType()), AATags); |
| 27 | } |
| 28 | |
| 29 | MemoryLocation MemoryLocation::get(const StoreInst *SI) { |
| 30 | AAMDNodes AATags; |
| 31 | SI->getAAMetadata(AATags); |
| 32 | const auto &DL = SI->getModule()->getDataLayout(); |
| 33 | |
| 34 | return MemoryLocation(SI->getPointerOperand(), |
| 35 | DL.getTypeStoreSize(SI->getValueOperand()->getType()), |
| 36 | AATags); |
| 37 | } |
| 38 | |
| 39 | MemoryLocation MemoryLocation::get(const VAArgInst *VI) { |
| 40 | AAMDNodes AATags; |
| 41 | VI->getAAMetadata(AATags); |
| 42 | |
| 43 | return MemoryLocation(VI->getPointerOperand(), UnknownSize, AATags); |
| 44 | } |
| 45 | |
| 46 | MemoryLocation MemoryLocation::get(const AtomicCmpXchgInst *CXI) { |
| 47 | AAMDNodes AATags; |
| 48 | CXI->getAAMetadata(AATags); |
| 49 | const auto &DL = CXI->getModule()->getDataLayout(); |
| 50 | |
| 51 | return MemoryLocation( |
| 52 | CXI->getPointerOperand(), |
| 53 | DL.getTypeStoreSize(CXI->getCompareOperand()->getType()), AATags); |
| 54 | } |
| 55 | |
| 56 | MemoryLocation MemoryLocation::get(const AtomicRMWInst *RMWI) { |
| 57 | AAMDNodes AATags; |
| 58 | RMWI->getAAMetadata(AATags); |
| 59 | const auto &DL = RMWI->getModule()->getDataLayout(); |
| 60 | |
| 61 | return MemoryLocation(RMWI->getPointerOperand(), |
| 62 | DL.getTypeStoreSize(RMWI->getValOperand()->getType()), |
| 63 | AATags); |
| 64 | } |
| 65 | |
| 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(); |
| 70 | |
| 71 | // memcpy/memmove can have AA tags. For memcpy, they apply |
| 72 | // to both the source and the destination. |
| 73 | AAMDNodes AATags; |
| 74 | MTI->getAAMetadata(AATags); |
| 75 | |
| 76 | return MemoryLocation(MTI->getRawSource(), Size, AATags); |
| 77 | } |
| 78 | |
| 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(); |
| 83 | |
| 84 | // memcpy/memmove can have AA tags. For memcpy, they apply |
| 85 | // to both the source and the destination. |
| 86 | AAMDNodes AATags; |
| 87 | MTI->getAAMetadata(AATags); |
| 88 | |
| 89 | return MemoryLocation(MTI->getRawDest(), Size, AATags); |
| 90 | } |