[flang-commits] [flang] [mlir] [mlir] Align num elements type to LLVM ArrayType (PR #93230)
Mehdi Amini via flang-commits
flang-commits at lists.llvm.org
Fri May 24 08:17:11 PDT 2024
================
@@ -632,8 +632,12 @@ llvm::Constant *mlir::LLVM::detail::getLLVMConstant(
llvm::ElementCount::get(numElements, /*Scalable=*/isScalable), child);
if (llvmType->isArrayTy()) {
auto *arrayType = llvm::ArrayType::get(elementType, numElements);
- SmallVector<llvm::Constant *, 8> constants(numElements, child);
- return llvm::ConstantArray::get(arrayType, constants);
+ if (child->isZeroValue()) {
+ return llvm::ConstantAggregateZero::get(arrayType);
+ } else {
+ std::vector<llvm::Constant *> constants(numElements, child);
----------------
joker-eph wrote:
I pasted the documentation of small vector in this PR already: https://github.com/llvm/llvm-project/pull/93230#discussion_r1612337183
Pasting here:
```
/// The template parameter specifies the type which should be used to hold the
/// Size and Capacity of the SmallVector, so it can be adjusted.
/// Using 32 bit size is desirable to shrink the size of the SmallVector.
/// Using 64 bit size is desirable for cases like SmallVector<char>, where a
/// 32 bit size would limit the vector to ~4GB. SmallVectors are used for
/// buffering bitcode output - which can exceed 4GB.
```
And the size is picked with:
```
template <class T>
using SmallVectorSizeType =
std::conditional_t<sizeof(T) < 4 && sizeof(void *) >= 8, uint64_t,
uint32_t>;
```
https://github.com/llvm/llvm-project/pull/93230
More information about the flang-commits
mailing list