-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Use different memory layout type for _BitInt(N) in LLVM IR #91364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
bbc1ff9
[clang] Lower long _BitInt(129+) to a different type in LLVM IR
Fznamznon fc6f90c
Add load and store type, update more places
Fznamznon e7fa9ad
Merge branch 'main' into long-bitint-align
Fznamznon 15f680f
Cleanup
Fznamznon 0ee57a3
Address some comments
Fznamznon 87bed2e
Move constant folding into AppendBitField
Fznamznon ff209c2
Merge branch 'main' into long-bitint-align
Fznamznon 08482d8
EmitStoreOfScalar when emitting return value
Fznamznon 956eeb6
Rename LLVMTypeLayoutMatchesAST
Fznamznon 4243bc4
Remove additional check in EmitToMemory
Fznamznon 934c659
Extend the constant to load/store type before split
Fznamznon c59d3e6
Address remaining comments
Fznamznon 6ff7436
Add comment for convertTypeForLoadStore
Fznamznon 13cdeb8
Make the comments right
Fznamznon dade1bb
Fix format
Fznamznon 3bcda80
Merge branch 'main' into long-bitint-align
Fznamznon 28e120e
Check VecTy first
Fznamznon d00b81a
Use whole number of bytes to represent _BitInt
Fznamznon fcd8be0
Fix remaining tests
Fznamznon f43ac1c
Update clang/lib/CodeGen/CodeGenTypes.cpp
Fznamznon 0ec1be5
Add the comment.
Fznamznon 58846f4
Merge branch 'long-bitint-align' of https://github.com/Fznamznon/llvm…
Fznamznon 97e1ef0
Merge branch 'main' into long-bitint-align
Fznamznon c00be8b
Attempt to fix HIP test
Fznamznon 7956e64
Update clang/lib/CodeGen/CGExprConstant.cpp
Fznamznon 5c4b58b
Fix format
Fznamznon cd83d6b
Merge branch 'main' into long-bitint-align
Fznamznon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,14 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD, | |
/// ConvertType in that it is used to convert to the memory representation for | ||
/// a type. For example, the scalar representation for _Bool is i1, but the | ||
/// memory representation is usually i8 or i32, depending on the target. | ||
Fznamznon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T, bool ForBitField) { | ||
/// | ||
/// We generally assume that the alloc size of this type under the LLVM | ||
/// data layout is the same as the size of the AST type. The alignment | ||
/// does not have to match: Clang should always use explicit alignments | ||
/// and packed structs as necessary to produce the layout it needs. | ||
/// But the size does need to be exactly right or else things like struct | ||
/// layout will break. | ||
llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) { | ||
if (T->isConstantMatrixType()) { | ||
const Type *Ty = Context.getCanonicalType(T).getTypePtr(); | ||
const ConstantMatrixType *MT = cast<ConstantMatrixType>(Ty); | ||
|
@@ -107,17 +114,65 @@ llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T, bool ForBitField) { | |
return llvm::IntegerType::get(FixedVT->getContext(), BytePadded); | ||
} | ||
|
||
// If this is a bool type, or a bit-precise integer type in a bitfield | ||
// representation, map this integer to the target-specified size. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep this comment; we just need to update it a little:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added, thanks. |
||
if ((ForBitField && T->isBitIntType()) || | ||
(!T->isBitIntType() && R->isIntegerTy(1))) | ||
// If T is _Bool or a _BitInt type, ConvertType will produce an IR type | ||
// with the exact semantic bit-width of the AST type; for example, | ||
// _BitInt(17) will turn into i17. In memory, however, we need to store | ||
// such values extended to their full storage size as decided by AST | ||
// layout; this is an ABI requirement. Ideally, we would always use an | ||
// integer type that's just the bit-size of the AST type; for example, if | ||
// sizeof(_BitInt(17)) == 4, _BitInt(17) would turn into i32. That is what's | ||
// returned by convertTypeForLoadStore. However, that type does not | ||
// always satisfy the size requirement on memory representation types | ||
// describe above. For example, a 32-bit platform might reasonably set | ||
// sizeof(_BitInt(65)) == 12, but i96 is likely to have to have an alloc size | ||
// of 16 bytes in the LLVM data layout. In these cases, we simply return | ||
// a byte array of the appropriate size. | ||
if (T->isBitIntType()) { | ||
if (typeRequiresSplitIntoByteArray(T, R)) | ||
return llvm::ArrayType::get(CGM.Int8Ty, | ||
Context.getTypeSizeInChars(T).getQuantity()); | ||
return llvm::IntegerType::get(getLLVMContext(), | ||
(unsigned)Context.getTypeSize(T)); | ||
} | ||
|
||
if (R->isIntegerTy(1)) | ||
return llvm::IntegerType::get(getLLVMContext(), | ||
(unsigned)Context.getTypeSize(T)); | ||
|
||
// Else, don't map it. | ||
return R; | ||
} | ||
|
||
bool CodeGenTypes::typeRequiresSplitIntoByteArray(QualType ASTTy, | ||
llvm::Type *LLVMTy) { | ||
if (!LLVMTy) | ||
LLVMTy = ConvertType(ASTTy); | ||
|
||
CharUnits ASTSize = Context.getTypeSizeInChars(ASTTy); | ||
CharUnits LLVMSize = | ||
CharUnits::fromQuantity(getDataLayout().getTypeAllocSize(LLVMTy)); | ||
return ASTSize != LLVMSize; | ||
} | ||
|
||
llvm::Type *CodeGenTypes::convertTypeForLoadStore(QualType T, | ||
llvm::Type *LLVMTy) { | ||
if (!LLVMTy) | ||
LLVMTy = ConvertType(T); | ||
|
||
if (T->isBitIntType()) | ||
return llvm::Type::getIntNTy( | ||
getLLVMContext(), Context.getTypeSizeInChars(T).getQuantity() * 8); | ||
|
||
if (LLVMTy->isIntegerTy(1)) | ||
return llvm::IntegerType::get(getLLVMContext(), | ||
(unsigned)Context.getTypeSize(T)); | ||
|
||
if (T->isExtVectorBoolType()) | ||
return ConvertTypeForMem(T); | ||
|
||
return LLVMTy; | ||
} | ||
|
||
/// isRecordLayoutComplete - Return true if the specified type is already | ||
/// completely laid out. | ||
bool CodeGenTypes::isRecordLayoutComplete(const Type *Ty) const { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.