diff options
author | Nikita Popov <npopov@redhat.com> | 2023-01-06 15:33:39 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-01-06 15:36:16 +0100 |
commit | a6a526ec5465d712db11fdbf5ed5fce8da0722cf (patch) | |
tree | d9f839d7467e15d6d85d0394ccb86448f65666b3 /llvm/lib/IR/Instructions.cpp | |
parent | bf82070ea465969e9ae86a31dfcbf94c2a7b4c4c (diff) | |
download | llvm-a6a526ec5465d712db11fdbf5ed5fce8da0722cf.zip llvm-a6a526ec5465d712db11fdbf5ed5fce8da0722cf.tar.gz llvm-a6a526ec5465d712db11fdbf5ed5fce8da0722cf.tar.bz2 |
[IR] Add AllocaInst::getAllocationSize() (NFC)
When fetching allocation sizes, we almost always want to have the
size in bytes, but we were only providing an InBits API. Also add
the corresponding byte-based conjugate to save some *8 and /8
juggling everywhere.
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index cdd2770..d1d7e14 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -56,8 +56,8 @@ static cl::opt<bool> DisableI2pP2iOpt( //===----------------------------------------------------------------------===// std::optional<TypeSize> -AllocaInst::getAllocationSizeInBits(const DataLayout &DL) const { - TypeSize Size = DL.getTypeAllocSizeInBits(getAllocatedType()); +AllocaInst::getAllocationSize(const DataLayout &DL) const { + TypeSize Size = DL.getTypeAllocSize(getAllocatedType()); if (isArrayAllocation()) { auto *C = dyn_cast<ConstantInt>(getArraySize()); if (!C) @@ -68,6 +68,14 @@ AllocaInst::getAllocationSizeInBits(const DataLayout &DL) const { return Size; } +std::optional<TypeSize> +AllocaInst::getAllocationSizeInBits(const DataLayout &DL) const { + std::optional<TypeSize> Size = getAllocationSize(DL); + if (Size) + return *Size * 8; + return std::nullopt; +} + //===----------------------------------------------------------------------===// // SelectInst Class //===----------------------------------------------------------------------===// |