[clang] [clang] Remove some uses of llvm::StructType::setBody. NFC. (PR #113691)
Jay Foad via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 25 07:16:00 PDT 2024
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/113691
It is simple to create the struct body up front, now that we have
transitioned to opaque pointers.
>From 0fea81c2996a5476fec5681856191d55841e9f0f Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Fri, 25 Oct 2024 14:05:54 +0100
Subject: [PATCH] [clang] Remove some uses of llvm::StructType::setBody. NFC.
It is simple to create the struct body up front, now that we have
transitioned to opaque pointers.
---
clang/lib/CodeGen/CGBlocks.cpp | 8 ++--
clang/lib/CodeGen/CGObjCGNU.cpp | 4 +-
clang/lib/CodeGen/CGObjCMac.cpp | 57 +++++++++++++--------------
clang/lib/CodeGen/MicrosoftCXXABI.cpp | 12 +++---
4 files changed, 37 insertions(+), 44 deletions(-)
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 41bb8d19d161eb..bfa9b0a2f836bc 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -2590,10 +2590,6 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
if (it != BlockByrefInfos.end())
return it->second;
- llvm::StructType *byrefType =
- llvm::StructType::create(getLLVMContext(),
- "struct.__block_byref_" + D->getNameAsString());
-
QualType Ty = D->getType();
CharUnits size;
@@ -2658,7 +2654,9 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
}
types.push_back(varTy);
- byrefType->setBody(types, packed);
+ llvm::StructType *byrefType = llvm::StructType::create(
+ getLLVMContext(), types, "struct.__block_byref_" + D->getNameAsString(),
+ packed);
BlockByrefInfo info;
info.Type = byrefType;
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 7a07284f8a8aa5..d6f5f2a43cf51b 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1509,8 +1509,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
GetSectionBounds(StringRef Section) {
if (CGM.getTriple().isOSBinFormatCOFF()) {
if (emptyStruct == nullptr) {
- emptyStruct = llvm::StructType::create(VMContext, ".objc_section_sentinel");
- emptyStruct->setBody({}, /*isPacked*/true);
+ emptyStruct = llvm::StructType::create(
+ VMContext, {}, ".objc_section_sentinel", /*isPacked=*/true);
}
auto ZeroInit = llvm::Constant::getNullValue(emptyStruct);
auto Sym = [&](StringRef Prefix, StringRef SecSuffix) {
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 1c16d273a55357..47ea636c756438 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -5835,15 +5835,7 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
// struct _objc_protocol_extension *
ProtocolExtensionPtrTy = llvm::PointerType::getUnqual(ProtocolExtensionTy);
- // Handle recursive construction of Protocol and ProtocolList types
-
- ProtocolTy =
- llvm::StructType::create(VMContext, "struct._objc_protocol");
-
- ProtocolListTy =
- llvm::StructType::create(VMContext, "struct._objc_protocol_list");
- ProtocolListTy->setBody(llvm::PointerType::getUnqual(ProtocolListTy), LongTy,
- llvm::ArrayType::get(ProtocolTy, 0));
+ // Handle construction of Protocol and ProtocolList types
// struct _objc_protocol {
// struct _objc_protocol_extension *isa;
@@ -5852,9 +5844,16 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
// struct _objc_method_description_list *instance_methods;
// struct _objc_method_description_list *class_methods;
// }
- ProtocolTy->setBody(ProtocolExtensionPtrTy, Int8PtrTy,
- llvm::PointerType::getUnqual(ProtocolListTy),
- MethodDescriptionListPtrTy, MethodDescriptionListPtrTy);
+ ProtocolTy = llvm::StructType::create(
+ {ProtocolExtensionPtrTy, Int8PtrTy,
+ llvm::PointerType::getUnqual(VMContext), MethodDescriptionListPtrTy,
+ MethodDescriptionListPtrTy},
+ "struct._objc_protocol");
+
+ ProtocolListTy =
+ llvm::StructType::create({llvm::PointerType::getUnqual(VMContext), LongTy,
+ llvm::ArrayType::get(ProtocolTy, 0)},
+ "struct._objc_protocol_list");
// struct _objc_protocol_list *
ProtocolListPtrTy = llvm::PointerType::getUnqual(ProtocolListTy);
@@ -5886,8 +5885,6 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
"struct._objc_class_extension", IntTy, Int8PtrTy, PropertyListPtrTy);
ClassExtensionPtrTy = llvm::PointerType::getUnqual(ClassExtensionTy);
- ClassTy = llvm::StructType::create(VMContext, "struct._objc_class");
-
// struct _objc_class {
// Class isa;
// Class super_class;
@@ -5902,10 +5899,12 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
// char *ivar_layout;
// struct _objc_class_ext *ext;
// };
- ClassTy->setBody(llvm::PointerType::getUnqual(ClassTy),
- llvm::PointerType::getUnqual(ClassTy), Int8PtrTy, LongTy,
- LongTy, LongTy, IvarListPtrTy, MethodListPtrTy, CachePtrTy,
- ProtocolListPtrTy, Int8PtrTy, ClassExtensionPtrTy);
+ ClassTy = llvm::StructType::create(
+ {llvm::PointerType::getUnqual(VMContext),
+ llvm::PointerType::getUnqual(VMContext), Int8PtrTy, LongTy, LongTy,
+ LongTy, IvarListPtrTy, MethodListPtrTy, CachePtrTy, ProtocolListPtrTy,
+ Int8PtrTy, ClassExtensionPtrTy},
+ "struct._objc_class");
ClassPtrTy = llvm::PointerType::getUnqual(ClassTy);
@@ -5988,13 +5987,9 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
// const struct _prop_list_t * class_properties;
// }
- // Holder for struct _protocol_list_t *
- ProtocolListnfABITy =
- llvm::StructType::create(VMContext, "struct._objc_protocol_list");
-
ProtocolnfABITy = llvm::StructType::create(
"struct._protocol_t", ObjectPtrTy, Int8PtrTy,
- llvm::PointerType::getUnqual(ProtocolListnfABITy), MethodListnfABIPtrTy,
+ llvm::PointerType::getUnqual(VMContext), MethodListnfABIPtrTy,
MethodListnfABIPtrTy, MethodListnfABIPtrTy, MethodListnfABIPtrTy,
PropertyListPtrTy, IntTy, IntTy, Int8PtrPtrTy, Int8PtrTy,
PropertyListPtrTy);
@@ -6006,8 +6001,9 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
// long protocol_count; // Note, this is 32/64 bit
// struct _protocol_t *[protocol_count];
// }
- ProtocolListnfABITy->setBody(LongTy,
- llvm::ArrayType::get(ProtocolnfABIPtrTy, 0));
+ ProtocolListnfABITy = llvm::StructType::create(
+ {LongTy, llvm::ArrayType::get(ProtocolnfABIPtrTy, 0)},
+ "struct._objc_protocol_list");
// struct _objc_protocol_list*
ProtocolListnfABIPtrTy = llvm::PointerType::getUnqual(ProtocolListnfABITy);
@@ -6067,11 +6063,12 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
// struct class_ro_t *ro;
// }
- ClassnfABITy = llvm::StructType::create(VMContext, "struct._class_t");
- ClassnfABITy->setBody(llvm::PointerType::getUnqual(ClassnfABITy),
- llvm::PointerType::getUnqual(ClassnfABITy), CachePtrTy,
- llvm::PointerType::getUnqual(ImpnfABITy),
- llvm::PointerType::getUnqual(ClassRonfABITy));
+ ClassnfABITy = llvm::StructType::create(
+ {llvm::PointerType::getUnqual(VMContext),
+ llvm::PointerType::getUnqual(VMContext), CachePtrTy,
+ llvm::PointerType::getUnqual(ImpnfABITy),
+ llvm::PointerType::getUnqual(ClassRonfABITy)},
+ "struct._class_t");
// LLVM for struct _class_t *
ClassnfABIPtrTy = llvm::PointerType::getUnqual(ClassnfABITy);
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 0b0b45ffead92f..3802dc8bcafc49 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -529,31 +529,29 @@ class MicrosoftCXXABI : public CGCXXABI {
if (ClassHierarchyDescriptorType)
return ClassHierarchyDescriptorType;
// Forward-declare RTTIClassHierarchyDescriptor to break a cycle.
- ClassHierarchyDescriptorType = llvm::StructType::create(
- CGM.getLLVMContext(), "rtti.ClassHierarchyDescriptor");
llvm::Type *FieldTypes[] = {CGM.IntTy, CGM.IntTy, CGM.IntTy,
getImageRelativeType(CGM.UnqualPtrTy)};
- ClassHierarchyDescriptorType->setBody(FieldTypes);
+ ClassHierarchyDescriptorType =
+ llvm::StructType::create(FieldTypes, "rtti.ClassHierarchyDescriptor");
return ClassHierarchyDescriptorType;
}
llvm::StructType *getCompleteObjectLocatorType() {
if (CompleteObjectLocatorType)
return CompleteObjectLocatorType;
- CompleteObjectLocatorType = llvm::StructType::create(
- CGM.getLLVMContext(), "rtti.CompleteObjectLocator");
llvm::Type *FieldTypes[] = {
CGM.IntTy,
CGM.IntTy,
CGM.IntTy,
getImageRelativeType(CGM.Int8PtrTy),
getImageRelativeType(CGM.UnqualPtrTy),
- getImageRelativeType(CompleteObjectLocatorType),
+ getImageRelativeType(CGM.VoidTy),
};
llvm::ArrayRef<llvm::Type *> FieldTypesRef(FieldTypes);
if (!isImageRelative())
FieldTypesRef = FieldTypesRef.drop_back();
- CompleteObjectLocatorType->setBody(FieldTypesRef);
+ CompleteObjectLocatorType =
+ llvm::StructType::create(FieldTypesRef, "rtti.CompleteObjectLocator");
return CompleteObjectLocatorType;
}
More information about the cfe-commits
mailing list