зеркало из https://github.com/microsoft/clang-1.git
IRgen: Factor out ComputeBitFieldInfo.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101066 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
01e56aecb7
Коммит
9b28daf9b6
|
@ -104,7 +104,6 @@ private:
|
||||||
void AppendTailPadding(uint64_t RecordSize);
|
void AppendTailPadding(uint64_t RecordSize);
|
||||||
|
|
||||||
unsigned getTypeAlignment(const llvm::Type *Ty) const;
|
unsigned getTypeAlignment(const llvm::Type *Ty) const;
|
||||||
uint64_t getTypeSizeInBytes(const llvm::Type *Ty) const;
|
|
||||||
|
|
||||||
/// CheckForPointerToDataMember - Check if the given type contains a pointer
|
/// CheckForPointerToDataMember - Check if the given type contains a pointer
|
||||||
/// to data member.
|
/// to data member.
|
||||||
|
@ -146,6 +145,20 @@ void CGRecordLayoutBuilder::Layout(const RecordDecl *D) {
|
||||||
LayoutFields(D);
|
LayoutFields(D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CGBitFieldInfo ComputeBitFieldInfo(CodeGenTypes &Types,
|
||||||
|
const FieldDecl *FD,
|
||||||
|
uint64_t FieldOffset,
|
||||||
|
uint64_t FieldSize) {
|
||||||
|
const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(FD->getType());
|
||||||
|
uint64_t TypeSizeInBits = Types.getTargetData().getTypeAllocSize(Ty) * 8;
|
||||||
|
|
||||||
|
bool IsSigned = FD->getType()->isSignedIntegerType();
|
||||||
|
CGBitFieldInfo BFI(Ty, FieldOffset / TypeSizeInBits,
|
||||||
|
FieldOffset % TypeSizeInBits, FieldSize, IsSigned);
|
||||||
|
|
||||||
|
return BFI;
|
||||||
|
}
|
||||||
|
|
||||||
void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D,
|
void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D,
|
||||||
uint64_t FieldOffset) {
|
uint64_t FieldOffset) {
|
||||||
uint64_t FieldSize =
|
uint64_t FieldSize =
|
||||||
|
@ -176,14 +189,9 @@ void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D,
|
||||||
assert(NumBytesToAppend && "No bytes to append!");
|
assert(NumBytesToAppend && "No bytes to append!");
|
||||||
}
|
}
|
||||||
|
|
||||||
const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType());
|
// Add the bit field info.
|
||||||
uint64_t TypeSizeInBits = getTypeSizeInBytes(Ty) * 8;
|
LLVMBitFields.push_back(
|
||||||
|
LLVMBitFieldInfo(D, ComputeBitFieldInfo(Types, D, FieldOffset, FieldSize)));
|
||||||
bool IsSigned = D->getType()->isSignedIntegerType();
|
|
||||||
LLVMBitFields.push_back(LLVMBitFieldInfo(
|
|
||||||
D, CGBitFieldInfo(Ty, FieldOffset / TypeSizeInBits,
|
|
||||||
FieldOffset % TypeSizeInBits,
|
|
||||||
FieldSize, IsSigned)));
|
|
||||||
|
|
||||||
AppendBytes(NumBytesToAppend);
|
AppendBytes(NumBytesToAppend);
|
||||||
|
|
||||||
|
@ -283,10 +291,9 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Add the bit field info.
|
// Add the bit field info.
|
||||||
bool IsSigned = Field->getType()->isSignedIntegerType();
|
LLVMBitFields.push_back(
|
||||||
LLVMBitFields.push_back(LLVMBitFieldInfo(
|
LLVMBitFieldInfo(*Field, ComputeBitFieldInfo(Types, *Field,
|
||||||
*Field, CGBitFieldInfo(FieldTy, 0, 0, FieldSize,
|
0, FieldSize)));
|
||||||
IsSigned)));
|
|
||||||
} else {
|
} else {
|
||||||
LLVMFields.push_back(LLVMFieldInfo(*Field, 0));
|
LLVMFields.push_back(LLVMFieldInfo(*Field, 0));
|
||||||
}
|
}
|
||||||
|
@ -389,7 +396,7 @@ void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes,
|
||||||
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct,
|
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct,
|
||||||
getTypeAlignment(FieldTy));
|
getTypeAlignment(FieldTy));
|
||||||
|
|
||||||
uint64_t FieldSizeInBytes = getTypeSizeInBytes(FieldTy);
|
uint64_t FieldSizeInBytes = Types.getTargetData().getTypeAllocSize(FieldTy);
|
||||||
|
|
||||||
FieldTypes.push_back(FieldTy);
|
FieldTypes.push_back(FieldTy);
|
||||||
|
|
||||||
|
@ -440,10 +447,6 @@ unsigned CGRecordLayoutBuilder::getTypeAlignment(const llvm::Type *Ty) const {
|
||||||
return Types.getTargetData().getABITypeAlignment(Ty);
|
return Types.getTargetData().getABITypeAlignment(Ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t CGRecordLayoutBuilder::getTypeSizeInBytes(const llvm::Type *Ty) const {
|
|
||||||
return Types.getTargetData().getTypeAllocSize(Ty);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGRecordLayoutBuilder::CheckForPointerToDataMember(QualType T) {
|
void CGRecordLayoutBuilder::CheckForPointerToDataMember(QualType T) {
|
||||||
// This record already contains a member pointer.
|
// This record already contains a member pointer.
|
||||||
if (ContainsPointerToDataMember)
|
if (ContainsPointerToDataMember)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче