diff options
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 58d377c47f6..e0ad0d1ea1f 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -45,6 +45,22 @@ using namespace llvm; //===----------------------------------------------------------------------===// +// AllocaInst Class +//===----------------------------------------------------------------------===// + +Optional<uint64_t> +AllocaInst::getAllocationSizeInBits(const DataLayout &DL) const { + uint64_t Size = DL.getTypeAllocSizeInBits(getAllocatedType()); + if (isArrayAllocation()) { + auto C = dyn_cast<ConstantInt>(getArraySize()); + if (!C) + return None; + Size *= C->getZExtValue(); + } + return Size; +} + +//===----------------------------------------------------------------------===// // CallSite Class //===----------------------------------------------------------------------===// |