Skip to content

Commit

Permalink
[clang][CGObjCGNU] Remove no-op ptr-to-ptr bitcasts (NFC)
Browse files Browse the repository at this point in the history
Opaque ptr cleanup effort (NFC).
  • Loading branch information
JOE1994 committed Nov 7, 2023
1 parent 796d48b commit 0936a71
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions clang/lib/CodeGen/CGObjCGNU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
if (CGM.getTriple().isOSBinFormatCOFF()) {
cast<llvm::GlobalValue>(isa)->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
}
} else if (isa->getType() != PtrToIdTy)
isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy);
}

// struct
// {
Expand Down Expand Up @@ -1108,10 +1107,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
std::pair<llvm::GlobalVariable*, int> v{ObjCStrGV, 0};
EarlyInitList.emplace_back(Sym, v);
}
llvm::Constant *ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStrGV, IdTy);
ObjCStrings[Str] = ObjCStr;
ConstantStrings.push_back(ObjCStr);
return ConstantAddress(ObjCStr, IdElemTy, Align);
ObjCStrings[Str] = ObjCStrGV;
ConstantStrings.push_back(ObjCStrGV);
return ConstantAddress(ObjCStrGV, IdElemTy, Align);
}

void PushProperty(ConstantArrayBuilder &PropertiesArray,
Expand Down Expand Up @@ -1193,9 +1191,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
ReferencedProtocols.end());
SmallVector<llvm::Constant *, 16> Protocols;
for (const auto *PI : RuntimeProtocols)
Protocols.push_back(
llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI),
ProtocolPtrTy));
Protocols.push_back(GenerateProtocolRef(PI));
return GenerateProtocolList(Protocols);
}

Expand Down Expand Up @@ -1305,7 +1301,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
llvm::GlobalValue::ExternalLinkage, nullptr, Name);
GV->setAlignment(CGM.getPointerAlign().getAsAlign());
}
return llvm::ConstantExpr::getBitCast(GV, ProtocolPtrTy);
return GV;
}

/// Existing protocol references.
Expand All @@ -1322,9 +1318,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
std::string RefName = SymbolForProtocolRef(Name);
assert(!TheModule.getGlobalVariable(RefName));
// Emit a reference symbol.
auto GV = new llvm::GlobalVariable(TheModule, ProtocolPtrTy,
false, llvm::GlobalValue::LinkOnceODRLinkage,
llvm::ConstantExpr::getBitCast(Protocol, ProtocolPtrTy), RefName);
auto GV = new llvm::GlobalVariable(TheModule, ProtocolPtrTy, false,
llvm::GlobalValue::LinkOnceODRLinkage,
Protocol, RefName);
GV->setComdat(TheModule.getOrInsertComdat(RefName));
GV->setSection(sectionName<ProtocolReferenceSection>());
GV->setAlignment(CGM.getPointerAlign().getAsAlign());
Expand Down Expand Up @@ -1381,9 +1377,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
auto RuntimeProtocols =
GetRuntimeProtocolList(PD->protocol_begin(), PD->protocol_end());
for (const auto *PI : RuntimeProtocols)
Protocols.push_back(
llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI),
ProtocolPtrTy));
Protocols.push_back(GenerateProtocolRef(PI));
llvm::Constant *ProtocolList = GenerateProtocolList(Protocols);

// Collect information about methods
Expand Down Expand Up @@ -1420,8 +1414,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
GV->setSection(sectionName<ProtocolSection>());
GV->setComdat(TheModule.getOrInsertComdat(SymName));
if (OldGV) {
OldGV->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GV,
OldGV->getType()));
OldGV->replaceAllUsesWith(GV);
OldGV->removeFromParent();
GV->setName(SymName);
}
Expand Down Expand Up @@ -2493,10 +2486,9 @@ ConstantAddress CGObjCGNU::GenerateConstantString(const StringLiteral *SL) {
llvm::Constant *isa = TheModule.getNamedGlobal(Sym);

if (!isa)
isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */false,
llvm::GlobalValue::ExternalWeakLinkage, nullptr, Sym);
else if (isa->getType() != PtrToIdTy)
isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy);
isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */ false,
llvm::GlobalValue::ExternalWeakLinkage,
nullptr, Sym);

ConstantInitBuilder Builder(CGM);
auto Fields = Builder.beginStruct();
Expand Down

0 comments on commit 0936a71

Please sign in to comment.