Skip to content

Commit

Permalink
[clang] Remove ConstantAggregateBuilderBase::addBitCast (NFC)
Browse files Browse the repository at this point in the history
* Replace all existing uses of ConstantAggregateBuilderBase::addBitCast,
  as they involve a no-op ptr-to-ptr bitcast
* Remove method ConstantAggregateBuilderBase::addBitCast

Opaque ptr cleanup effort (NFC)
  • Loading branch information
JOE1994 committed Nov 18, 2023
1 parent 4259198 commit 695662b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
5 changes: 0 additions & 5 deletions clang/include/clang/CodeGen/ConstantInitBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ class ConstantAggregateBuilderBase {
add(llvm::ConstantPointerNull::get(ptrTy));
}

/// Add a bitcast of a value to a specific type.
void addBitCast(llvm::Constant *value, llvm::Type *type) {
add(llvm::ConstantExpr::getBitCast(value, type));
}

/// Add a bunch of new values to this initializer.
void addAll(llvm::ArrayRef<llvm::Constant *> values) {
assert(!Finished && "cannot add more values after finishing builder");
Expand Down
54 changes: 24 additions & 30 deletions clang/lib/CodeGen/CGObjCGNU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,9 +1725,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
SmallVector<ObjCMethodDecl*, 16> ClassMethods;
ClassMethods.insert(ClassMethods.begin(), OID->classmeth_begin(),
OID->classmeth_end());
metaclassFields.addBitCast(
GenerateMethodList(className, "", ClassMethods, true),
PtrTy);
metaclassFields.add(
GenerateMethodList(className, "", ClassMethods, true));
}
// void *dtable;
metaclassFields.addNullPointer(PtrTy);
Expand Down Expand Up @@ -1894,9 +1893,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
if (InstanceMethods.size() == 0)
classFields.addNullPointer(PtrTy);
else
classFields.addBitCast(
GenerateMethodList(className, "", InstanceMethods, false),
PtrTy);
classFields.add(
GenerateMethodList(className, "", InstanceMethods, false));

// void *dtable;
classFields.addNullPointer(PtrTy);
// IMP cxx_construct;
Expand Down Expand Up @@ -2887,14 +2886,14 @@ GenerateMethodList(StringRef ClassName,
assert(FnPtr && "Can't generate metadata for method that doesn't exist");
auto Method = MethodArray.beginStruct(ObjCMethodTy);
if (isV2ABI) {
Method.addBitCast(FnPtr, IMPTy);
Method.add(FnPtr);
Method.add(GetConstantSelector(OMD->getSelector(),
Context.getObjCEncodingForMethodDecl(OMD)));
Method.add(MakeConstantString(Context.getObjCEncodingForMethodDecl(OMD, true)));
} else {
Method.add(MakeConstantString(OMD->getSelector().getAsString()));
Method.add(MakeConstantString(Context.getObjCEncodingForMethodDecl(OMD)));
Method.addBitCast(FnPtr, IMPTy);
Method.add(FnPtr);
}
Method.finishAndAddTo(MethodArray);
}
Expand Down Expand Up @@ -2993,7 +2992,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
// Fill in the structure

// isa
Elements.addBitCast(MetaClass, PtrToInt8Ty);
Elements.add(MetaClass);
// super_class
Elements.add(SuperClass);
// name
Expand Down Expand Up @@ -3022,7 +3021,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
// sibling_class
Elements.add(NULLPtr);
// protocols
Elements.addBitCast(Protocols, PtrTy);
Elements.add(Protocols);
// gc_object_type
Elements.add(NULLPtr);
// abi_version
Expand Down Expand Up @@ -3094,7 +3093,7 @@ CGObjCGNU::GenerateProtocolList(ArrayRef<std::string> Protocols) {
} else {
protocol = value->getValue();
}
Elements.addBitCast(protocol, PtrToInt8Ty);
Elements.add(protocol);
}
Elements.finishAndAddTo(ProtocolList);
return ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
Expand Down Expand Up @@ -3224,11 +3223,9 @@ void CGObjCGNU::GenerateProtocolHolderCategory() {
Elements.add(MakeConstantString(CategoryName));
Elements.add(MakeConstantString(ClassName));
// Instance method list
Elements.addBitCast(GenerateMethodList(
ClassName, CategoryName, {}, false), PtrTy);
Elements.add(GenerateMethodList(ClassName, CategoryName, {}, false));
// Class method list
Elements.addBitCast(GenerateMethodList(
ClassName, CategoryName, {}, true), PtrTy);
Elements.add(GenerateMethodList(ClassName, CategoryName, {}, true));

// Protocol list
ConstantInitBuilder ProtocolListBuilder(CGM);
Expand All @@ -3238,13 +3235,11 @@ void CGObjCGNU::GenerateProtocolHolderCategory() {
auto ProtocolElements = ProtocolList.beginArray(PtrTy);
for (auto iter = ExistingProtocols.begin(), endIter = ExistingProtocols.end();
iter != endIter ; iter++) {
ProtocolElements.addBitCast(iter->getValue(), PtrTy);
ProtocolElements.add(iter->getValue());
}
ProtocolElements.finishAndAddTo(ProtocolList);
Elements.addBitCast(
ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
CGM.getPointerAlign()),
PtrTy);
Elements.add(ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
CGM.getPointerAlign()));
Categories.push_back(
Elements.finishAndCreateGlobal("", CGM.getPointerAlign()));
}
Expand Down Expand Up @@ -3321,27 +3316,26 @@ void CGObjCGNU::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
SmallVector<ObjCMethodDecl*, 16> InstanceMethods;
InstanceMethods.insert(InstanceMethods.begin(), OCD->instmeth_begin(),
OCD->instmeth_end());
Elements.addBitCast(
GenerateMethodList(ClassName, CategoryName, InstanceMethods, false),
PtrTy);
Elements.add(
GenerateMethodList(ClassName, CategoryName, InstanceMethods, false));

// Class method list

SmallVector<ObjCMethodDecl*, 16> ClassMethods;
ClassMethods.insert(ClassMethods.begin(), OCD->classmeth_begin(),
OCD->classmeth_end());
Elements.addBitCast(
GenerateMethodList(ClassName, CategoryName, ClassMethods, true),
PtrTy);
Elements.add(GenerateMethodList(ClassName, CategoryName, ClassMethods, true));

// Protocol list
Elements.addBitCast(GenerateCategoryProtocolList(CatDecl), PtrTy);
Elements.add(GenerateCategoryProtocolList(CatDecl));
if (isRuntime(ObjCRuntime::GNUstep, 2)) {
const ObjCCategoryDecl *Category =
Class->FindCategoryDeclaration(OCD->getIdentifier());
if (Category) {
// Instance properties
Elements.addBitCast(GeneratePropertyList(OCD, Category, false), PtrTy);
Elements.add(GeneratePropertyList(OCD, Category, false));
// Class properties
Elements.addBitCast(GeneratePropertyList(OCD, Category, true), PtrTy);
Elements.add(GeneratePropertyList(OCD, Category, true));
} else {
Elements.addNullPointer(PtrTy);
Elements.addNullPointer(PtrTy);
Expand Down Expand Up @@ -3785,7 +3779,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
// Number of static selectors
symtab.addInt(LongTy, selectorCount);

symtab.addBitCast(selectorList, selStructPtrTy);
symtab.add(selectorList);

// Number of classes defined.
symtab.addInt(CGM.Int16Ty, Classes.size());
Expand Down

0 comments on commit 695662b

Please sign in to comment.