[clang] [llvm] [llvm:ir] Add support for constant data exceeding 4GiB (PR #126481)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 10 00:01:44 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-clang
Author: None (pzzp)
<details>
<summary>Changes</summary>
The test file is over 4GiB, which is too big, so I didn’t submit it. 😄
---
Full diff: https://github.com/llvm/llvm-project/pull/126481.diff
5 Files Affected:
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+2-2)
- (modified) llvm/include/llvm/IR/Constants.h (+1-1)
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+3-3)
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+3-3)
- (modified) llvm/lib/IR/Constants.cpp (+1-1)
``````````diff
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index ef11798869d3b13..7d57c71e7e61b98 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -364,13 +364,13 @@ bool ConstantAggregateBuilder::split(size_t Index, CharUnits Hint) {
// FIXME: If possible, split into two ConstantDataSequentials at Hint.
CharUnits ElemSize = getSize(CDS->getElementType());
replace(Elems, Index, Index + 1,
- llvm::map_range(llvm::seq(0u, CDS->getNumElements()),
+ llvm::map_range(llvm::seq(0ul, CDS->getNumElements()),
[&](unsigned Elem) {
return CDS->getElementAsConstant(Elem);
}));
replace(Offsets, Index, Index + 1,
llvm::map_range(
- llvm::seq(0u, CDS->getNumElements()),
+ llvm::seq(0ul, CDS->getNumElements()),
[&](unsigned Elem) { return Offset + Elem * ElemSize; }));
return true;
}
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index 15b90589b7e2b55..d2ca214e781ee04 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -644,7 +644,7 @@ class ConstantDataSequential : public ConstantData {
Type *getElementType() const;
/// Return the number of elements in the array or vector.
- unsigned getNumElements() const;
+ uint64_t getNumElements() const;
/// Return the size (in bytes) of each element in the array/vector.
/// The size of the elements is known to be a multiple of one byte.
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 7ca63c2c7251ded..f8968116dcc5319 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -2773,7 +2773,7 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
cast<ConstantDataSequential>(C)->isString()) {
const ConstantDataSequential *Str = cast<ConstantDataSequential>(C);
// Emit constant strings specially.
- unsigned NumElts = Str->getNumElements();
+ uint64_t NumElts = Str->getNumElements();
// If this is a null-terminated string, use the denser CSTRING encoding.
if (Str->isCString()) {
Code = bitc::CST_CODE_CSTRING;
@@ -2801,10 +2801,10 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
Code = bitc::CST_CODE_DATA;
Type *EltTy = CDS->getElementType();
if (isa<IntegerType>(EltTy)) {
- for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
+ for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
Record.push_back(CDS->getElementAsInteger(i));
} else {
- for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
+ for (uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
Record.push_back(
CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 44b10c3ef997267..34ea45ad8d14541 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3628,9 +3628,9 @@ static void emitGlobalConstantDataSequential(
return AP.OutStreamer->emitBytes(CDS->getAsString());
// Otherwise, emit the values in successive locations.
- unsigned ElementByteSize = CDS->getElementByteSize();
+ uint64_t ElementByteSize = CDS->getElementByteSize();
if (isa<IntegerType>(CDS->getElementType())) {
- for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
+ for (uint64_t I = 0, E = CDS->getNumElements(); I != E; ++I) {
emitGlobalAliasInline(AP, ElementByteSize * I, AliasList);
if (AP.isVerbose())
AP.OutStreamer->getCommentOS()
@@ -3640,7 +3640,7 @@ static void emitGlobalConstantDataSequential(
}
} else {
Type *ET = CDS->getElementType();
- for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
+ for (uint64_t I = 0, E = CDS->getNumElements(); I != E; ++I) {
emitGlobalAliasInline(AP, ElementByteSize * I, AliasList);
emitGlobalConstantFP(CDS->getElementAsAPFloat(I), ET, AP);
}
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 33f4dc78c6d3f9b..9c3f28a3faa6807 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2855,7 +2855,7 @@ bool ConstantDataSequential::isElementTypeCompatible(Type *Ty) {
return false;
}
-unsigned ConstantDataSequential::getNumElements() const {
+uint64_t ConstantDataSequential::getNumElements() const {
if (ArrayType *AT = dyn_cast<ArrayType>(getType()))
return AT->getNumElements();
return cast<FixedVectorType>(getType())->getNumElements();
``````````
</details>
https://github.com/llvm/llvm-project/pull/126481
More information about the llvm-commits
mailing list