aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorAndres-Salamanca <andrealebarbaritos@gmail.com>2025-06-23 14:58:28 -0500
committerGitHub <noreply@github.com>2025-06-23 14:58:28 -0500
commit66214410c4059be3b60f287d80e2ffc77d2c9ab4 (patch)
tree59c1d9395d7c2b953283e27a80fc99c76b42ced2 /clang/lib
parent5f74d9bb62803b9cffadef68b6068fa89bb30c5e (diff)
downloadllvm-66214410c4059be3b60f287d80e2ffc77d2c9ab4.zip
llvm-66214410c4059be3b60f287d80e2ffc77d2c9ab4.tar.gz
llvm-66214410c4059be3b60f287d80e2ffc77d2c9ab4.tar.bz2
[CIR] Add support for DumpRecordLayouts (#145058)
This PR adds support for the `-fdump-record-layouts` flag.
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenRecordLayout.h2
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp44
2 files changed, 45 insertions, 1 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenRecordLayout.h b/clang/lib/CIR/CodeGen/CIRGenRecordLayout.h
index 3b51ab78..b28afe4 100644
--- a/clang/lib/CIR/CodeGen/CIRGenRecordLayout.h
+++ b/clang/lib/CIR/CodeGen/CIRGenRecordLayout.h
@@ -197,6 +197,8 @@ public:
assert(it != bitFields.end() && "Unable to find bitfield info");
return it->second;
}
+ void print(raw_ostream &os) const;
+ LLVM_DUMP_METHOD void dump() const;
};
} // namespace clang::CIRGen
diff --git a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
index d2fb4b7..faeee88b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
@@ -640,13 +640,55 @@ CIRGenTypes::computeRecordLayout(const RecordDecl *rd, cir::RecordType *ty) {
// Dump the layout, if requested.
if (getASTContext().getLangOpts().DumpRecordLayouts) {
- cgm.errorNYI(rd->getSourceRange(), "computeRecordLayout: dump layout");
+ llvm::outs() << "\n*** Dumping CIRgen Record Layout\n";
+ llvm::outs() << "Record: ";
+ rd->dump(llvm::outs());
+ llvm::outs() << "\nLayout: ";
+ rl->print(llvm::outs());
}
// TODO: implement verification
return rl;
}
+void CIRGenRecordLayout::print(raw_ostream &os) const {
+ os << "<CIRecordLayout\n";
+ os << " CIR Type:" << completeObjectType << "\n";
+ if (baseSubobjectType)
+ os << " NonVirtualBaseCIRType:" << baseSubobjectType << "\n";
+ os << " IsZeroInitializable:" << zeroInitializable << "\n";
+ os << " BitFields:[\n";
+ std::vector<std::pair<unsigned, const CIRGenBitFieldInfo *>> bitInfo;
+ for (auto &[decl, info] : bitFields) {
+ const RecordDecl *rd = decl->getParent();
+ unsigned index = 0;
+ for (RecordDecl::field_iterator it = rd->field_begin(); *it != decl; ++it)
+ ++index;
+ bitInfo.push_back(std::make_pair(index, &info));
+ }
+ llvm::array_pod_sort(bitInfo.begin(), bitInfo.end());
+ for (std::pair<unsigned, const CIRGenBitFieldInfo *> &info : bitInfo) {
+ os.indent(4);
+ info.second->print(os);
+ os << "\n";
+ }
+ os << " ]>\n";
+}
+
+void CIRGenBitFieldInfo::print(raw_ostream &os) const {
+ os << "<CIRBitFieldInfo" << " name:" << name << " offset:" << offset
+ << " size:" << size << " isSigned:" << isSigned
+ << " storageSize:" << storageSize
+ << " storageOffset:" << storageOffset.getQuantity()
+ << " volatileOffset:" << volatileOffset
+ << " volatileStorageSize:" << volatileStorageSize
+ << " volatileStorageOffset:" << volatileStorageOffset.getQuantity() << ">";
+}
+
+void CIRGenRecordLayout::dump() const { print(llvm::errs()); }
+
+void CIRGenBitFieldInfo::dump() const { print(llvm::errs()); }
+
void CIRRecordLowering::lowerUnion() {
CharUnits layoutSize = astRecordLayout.getSize();
mlir::Type storageType = nullptr;