[clang] 34ee69b - [clang][CGObjCMac] Remove no-op ptr-to-ptr bitcasts (NFC)
Youngsuk Kim via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 6 08:22:08 PST 2023
Author: Youngsuk Kim
Date: 2023-11-06T10:19:48-06:00
New Revision: 34ee69b4ce66280ccc65acc1799a5863de2f2aa6
URL: https://github.com/llvm/llvm-project/commit/34ee69b4ce66280ccc65acc1799a5863de2f2aa6
DIFF: https://github.com/llvm/llvm-project/commit/34ee69b4ce66280ccc65acc1799a5863de2f2aa6.diff
LOG: [clang][CGObjCMac] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque ptr cleanup effort (NFC).
Added:
Modified:
clang/lib/CodeGen/CGObjCMac.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 6dd7ca64e5221bd..4ac8c4dc9a38745 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2961,8 +2961,7 @@ llvm::Value *CGObjCMac::GenerateProtocolRef(CodeGenFunction &CGF,
// resolved. Investigate. Its also wasteful to look this up over and over.
LazySymbols.insert(&CGM.getContext().Idents.get("Protocol"));
- return llvm::ConstantExpr::getBitCast(GetProtocolRef(PD),
- ObjCTypes.getExternalProtocolPtrTy());
+ return GetProtocolRef(PD);
}
void CGObjCCommonMac::GenerateProtocol(const ObjCProtocolDecl *PD) {
@@ -3182,7 +3181,7 @@ CGObjCMac::EmitProtocolList(Twine name,
llvm::GlobalVariable *GV =
CreateMetadataVar(name, values, section, CGM.getPointerAlign(), false);
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListPtrTy);
+ return GV;
}
static void
@@ -3290,7 +3289,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
llvm::GlobalVariable *GV =
CreateMetadataVar(Name, values, Section, CGM.getPointerAlign(), true);
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.PropertyListPtrTy);
+ return GV;
}
llvm::Constant *
@@ -3311,7 +3310,7 @@ CGObjCCommonMac::EmitProtocolMethodTypes(Twine Name,
llvm::GlobalVariable *GV =
CreateMetadataVar(Name, Init, Section, CGM.getPointerAlign(), true);
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.Int8PtrPtrTy);
+ return GV;
}
/*
@@ -3804,7 +3803,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID,
GV = CreateMetadataVar("OBJC_INSTANCE_VARIABLES_" + ID->getName(), ivarList,
"__OBJC,__instance_vars,regular,no_dead_strip",
CGM.getPointerAlign(), true);
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListPtrTy);
+ return GV;
}
/// Build a struct objc_method_description constant for the given method.
@@ -3923,8 +3922,7 @@ llvm::Constant *CGObjCMac::emitMethodList(Twine name, MethodListType MLT,
llvm::GlobalVariable *GV = CreateMetadataVar(prefix + name, values, section,
CGM.getPointerAlign(), true);
- return llvm::ConstantExpr::getBitCast(GV,
- ObjCTypes.MethodDescriptionListPtrTy);
+ return GV;
}
// Otherwise, it's an objc_method_list.
@@ -3941,7 +3939,7 @@ llvm::Constant *CGObjCMac::emitMethodList(Twine name, MethodListType MLT,
llvm::GlobalVariable *GV = CreateMetadataVar(prefix + name, values, section,
CGM.getPointerAlign(), true);
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodListPtrTy);
+ return GV;
}
llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD,
@@ -3996,8 +3994,7 @@ CGObjCCommonMac::GenerateDirectMethod(const ObjCMethodDecl *OMD,
Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
"", &CGM.getModule());
Fn->takeName(OldFn);
- OldFn->replaceAllUsesWith(
- llvm::ConstantExpr::getBitCast(Fn, OldFn->getType()));
+ OldFn->replaceAllUsesWith(Fn);
OldFn->eraseFromParent();
// Replace the cached function in the map.
@@ -5204,7 +5201,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() {
llvm::GlobalVariable *GV = CreateMetadataVar(
"OBJC_SYMBOLS", values, "__OBJC,__symbols,regular,no_dead_strip",
CGM.getPointerAlign(), true);
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.SymtabPtrTy);
+ return GV;
}
llvm::Value *CGObjCMac::EmitClassRefFromId(CodeGenFunction &CGF,
@@ -5214,13 +5211,10 @@ llvm::Value *CGObjCMac::EmitClassRefFromId(CodeGenFunction &CGF,
llvm::GlobalVariable *&Entry = ClassReferences[II];
if (!Entry) {
- llvm::Constant *Casted =
- llvm::ConstantExpr::getBitCast(GetClassName(II->getName()),
- ObjCTypes.ClassPtrTy);
- Entry = CreateMetadataVar(
- "OBJC_CLASS_REFERENCES_", Casted,
- "__OBJC,__cls_refs,literal_pointers,no_dead_strip",
- CGM.getPointerAlign(), true);
+ Entry =
+ CreateMetadataVar("OBJC_CLASS_REFERENCES_", GetClassName(II->getName()),
+ "__OBJC,__cls_refs,literal_pointers,no_dead_strip",
+ CGM.getPointerAlign(), true);
}
return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry,
@@ -5253,11 +5247,8 @@ Address CGObjCMac::EmitSelectorAddr(Selector Sel) {
llvm::GlobalVariable *&Entry = SelectorReferences[Sel];
if (!Entry) {
- llvm::Constant *Casted =
- llvm::ConstantExpr::getBitCast(GetMethodVarName(Sel),
- ObjCTypes.SelectorPtrTy);
Entry = CreateMetadataVar(
- "OBJC_SELECTOR_REFERENCES_", Casted,
+ "OBJC_SELECTOR_REFERENCES_", GetMethodVarName(Sel),
"__OBJC,__message_refs,literal_pointers,no_dead_strip", Align, true);
Entry->setExternallyInitialized(true);
}
@@ -6166,8 +6157,8 @@ void CGObjCNonFragileABIMac::AddModuleClassList(
SmallVector<llvm::Constant*, 8> Symbols(NumClasses);
for (unsigned i=0; i<NumClasses; i++)
- Symbols[i] = llvm::ConstantExpr::getBitCast(Container[i],
- ObjCTypes.Int8PtrTy);
+ Symbols[i] = Container[i];
+
llvm::Constant *Init =
llvm::ConstantArray::get(llvm::ArrayType::get(ObjCTypes.Int8PtrTy,
Symbols.size()),
@@ -6603,9 +6594,7 @@ llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF,
// of protocol's meta-data (not a reference to it!)
assert(!PD->isNonRuntimeProtocol() &&
"attempting to get a protocol ref to a static protocol.");
- llvm::Constant *Init =
- llvm::ConstantExpr::getBitCast(GetOrEmitProtocol(PD),
- ObjCTypes.getExternalProtocolPtrTy());
+ llvm::Constant *Init = GetOrEmitProtocol(PD);
std::string ProtocolName("_OBJC_PROTOCOL_REFERENCE_$_");
ProtocolName += PD->getObjCRuntimeNameAsString();
@@ -6830,7 +6819,7 @@ CGObjCNonFragileABIMac::emitMethodList(Twine name, MethodListType kind,
llvm::GlobalVariable *GV = finishAndCreateGlobal(values, prefix + name, CGM);
CGM.addCompilerUsedGlobal(GV);
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodListnfABIPtrTy);
+ return GV;
}
/// ObjCIvarOffsetVariable - Returns the ivar offset variable for
@@ -6972,7 +6961,7 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
llvm::GlobalVariable *GV = finishAndCreateGlobal(
ivarList, Prefix + OID->getObjCRuntimeNameAsString(), CGM);
CGM.addCompilerUsedGlobal(GV);
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListnfABIPtrTy);
+ return GV;
}
llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocolRef(
@@ -7146,7 +7135,7 @@ CGObjCNonFragileABIMac::EmitProtocolList(Twine Name,
llvm::GlobalVariable *GV =
CGM.getModule().getGlobalVariable(TmpName.str(), true);
if (GV)
- return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListnfABIPtrTy);
+ return GV;
ConstantInitBuilder builder(CGM);
auto values = builder.beginStruct();
@@ -7164,8 +7153,7 @@ CGObjCNonFragileABIMac::EmitProtocolList(Twine Name,
GV = finishAndCreateGlobal(values, Name, CGM);
CGM.addCompilerUsedGlobal(GV);
- return llvm::ConstantExpr::getBitCast(GV,
- ObjCTypes.ProtocolListnfABIPtrTy);
+ return GV;
}
/// EmitObjCValueForIvar - Code Gen for nonfragile ivar reference.
@@ -7399,8 +7387,7 @@ CGObjCNonFragileABIMac::GetClassGlobal(StringRef Name,
NewGV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
if (GV) {
- GV->replaceAllUsesWith(
- llvm::ConstantExpr::getBitCast(NewGV, GV->getType()));
+ GV->replaceAllUsesWith(NewGV);
GV->eraseFromParent();
}
GV = NewGV;
@@ -7611,14 +7598,11 @@ Address CGObjCNonFragileABIMac::EmitSelectorAddr(Selector Sel) {
llvm::GlobalVariable *&Entry = SelectorReferences[Sel];
CharUnits Align = CGM.getPointerAlign();
if (!Entry) {
- llvm::Constant *Casted =
- llvm::ConstantExpr::getBitCast(GetMethodVarName(Sel),
- ObjCTypes.SelectorPtrTy);
std::string SectionName =
GetSectionName("__objc_selrefs", "literal_pointers,no_dead_strip");
Entry = new llvm::GlobalVariable(
CGM.getModule(), ObjCTypes.SelectorPtrTy, false,
- getLinkageTypeForObjCMetadata(CGM, SectionName), Casted,
+ getLinkageTypeForObjCMetadata(CGM, SectionName), GetMethodVarName(Sel),
"OBJC_SELECTOR_REFERENCES_");
Entry->setExternallyInitialized(true);
Entry->setSection(SectionName);
More information about the cfe-commits
mailing list