Skip to content

Commit 45ca24e

Browse files
committed
[clang] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque ptr cleanup effort (NFC).
1 parent 466dc5c commit 45ca24e

File tree

2 files changed

+12
-33
lines changed

2 files changed

+12
-33
lines changed

clang/lib/CodeGen/CGObjCGNU.cpp

+11-25
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
17841784
}
17851785
}
17861786
if (!IsCOFF)
1787-
classFields.add(llvm::ConstantExpr::getBitCast(SuperClass, PtrTy));
1787+
classFields.add(SuperClass);
17881788
else
17891789
classFields.addNullPointer(PtrTy);
17901790
} else
@@ -1959,16 +1959,14 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
19591959
// Resolve the class aliases, if they exist.
19601960
// FIXME: Class pointer aliases shouldn't exist!
19611961
if (ClassPtrAlias) {
1962-
ClassPtrAlias->replaceAllUsesWith(
1963-
llvm::ConstantExpr::getBitCast(classStruct, IdTy));
1962+
ClassPtrAlias->replaceAllUsesWith(classStruct);
19641963
ClassPtrAlias->eraseFromParent();
19651964
ClassPtrAlias = nullptr;
19661965
}
19671966
if (auto Placeholder =
19681967
TheModule.getNamedGlobal(SymbolForClass(className)))
19691968
if (Placeholder != classStruct) {
1970-
Placeholder->replaceAllUsesWith(
1971-
llvm::ConstantExpr::getBitCast(classStruct, Placeholder->getType()));
1969+
Placeholder->replaceAllUsesWith(classStruct);
19721970
Placeholder->eraseFromParent();
19731971
classStruct->setName(SymbolForClass(className));
19741972
}
@@ -2415,7 +2413,7 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
24152413
false,
24162414
llvm::GlobalValue::ExternalLinkage,
24172415
nullptr, "__objc_id_type_info");
2418-
return llvm::ConstantExpr::getBitCast(IDEHType, PtrToInt8Ty);
2416+
return IDEHType;
24192417
}
24202418

24212419
const ObjCObjectPointerType *PT =
@@ -2429,9 +2427,8 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
24292427
std::string typeinfoName = "__objc_eh_typeinfo_" + className;
24302428

24312429
// Return the existing typeinfo if it exists
2432-
llvm::Constant *typeinfo = TheModule.getGlobalVariable(typeinfoName);
2433-
if (typeinfo)
2434-
return llvm::ConstantExpr::getBitCast(typeinfo, PtrToInt8Ty);
2430+
if (llvm::Constant *typeinfo = TheModule.getGlobalVariable(typeinfoName))
2431+
return typeinfo;
24352432

24362433
// Otherwise create it.
24372434

@@ -2495,9 +2492,7 @@ ConstantAddress CGObjCGNU::GenerateConstantString(const StringLiteral *SL) {
24952492
Fields.add(isa);
24962493
Fields.add(MakeConstantString(Str));
24972494
Fields.addInt(IntTy, Str.size());
2498-
llvm::Constant *ObjCStr =
2499-
Fields.finishAndCreateGlobal(".objc_str", Align);
2500-
ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStr, PtrToInt8Ty);
2495+
llvm::Constant *ObjCStr = Fields.finishAndCreateGlobal(".objc_str", Align);
25012496
ObjCStrings[Str] = ObjCStr;
25022497
ConstantStrings.push_back(ObjCStr);
25032498
return ConstantAddress(ObjCStr, Int8Ty, Align);
@@ -3060,8 +3055,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
30603055
Elements.finishAndCreateGlobal(ClassSym, CGM.getPointerAlign(), false,
30613056
llvm::GlobalValue::ExternalLinkage);
30623057
if (ClassRef) {
3063-
ClassRef->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(Class,
3064-
ClassRef->getType()));
3058+
ClassRef->replaceAllUsesWith(Class);
30653059
ClassRef->removeFromParent();
30663060
Class->setName(ClassSym);
30673061
}
@@ -3227,9 +3221,7 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) {
32273221
Elements.add(PropertyList);
32283222
Elements.add(OptionalPropertyList);
32293223
ExistingProtocols[ProtocolName] =
3230-
llvm::ConstantExpr::getBitCast(
3231-
Elements.finishAndCreateGlobal(".objc_protocol", CGM.getPointerAlign()),
3232-
IdTy);
3224+
Elements.finishAndCreateGlobal(".objc_protocol", CGM.getPointerAlign());
32333225
}
32343226
void CGObjCGNU::GenerateProtocolHolderCategory() {
32353227
// Collect information about instance methods
@@ -3263,9 +3255,8 @@ void CGObjCGNU::GenerateProtocolHolderCategory() {
32633255
ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
32643256
CGM.getPointerAlign()),
32653257
PtrTy);
3266-
Categories.push_back(llvm::ConstantExpr::getBitCast(
3267-
Elements.finishAndCreateGlobal("", CGM.getPointerAlign()),
3268-
PtrTy));
3258+
Categories.push_back(
3259+
Elements.finishAndCreateGlobal("", CGM.getPointerAlign()));
32693260
}
32703261

32713262
/// Libobjc2 uses a bitfield representation where small(ish) bitfields are
@@ -3736,7 +3727,6 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
37363727

37373728
statics = allStaticsArray.finishAndCreateGlobal(".objc_statics_ptr",
37383729
CGM.getPointerAlign());
3739-
statics = llvm::ConstantExpr::getBitCast(statics, PtrTy);
37403730
}
37413731

37423732
// Array of classes, categories, and constant objects.
@@ -3799,9 +3789,6 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
37993789
// FIXME: We're generating redundant loads and stores here!
38003790
llvm::Constant *selPtr = llvm::ConstantExpr::getGetElementPtr(
38013791
selectorList->getValueType(), selectorList, idxs);
3802-
// If selectors are defined as an opaque type, cast the pointer to this
3803-
// type.
3804-
selPtr = llvm::ConstantExpr::getBitCast(selPtr, SelectorTy);
38053792
selectorAliases[i]->replaceAllUsesWith(selPtr);
38063793
selectorAliases[i]->eraseFromParent();
38073794
}
@@ -3922,7 +3909,6 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
39223909
llvm::Constant *TheClass =
39233910
TheModule.getGlobalVariable("_OBJC_CLASS_" + iter->first, true);
39243911
if (TheClass) {
3925-
TheClass = llvm::ConstantExpr::getBitCast(TheClass, PtrTy);
39263912
Builder.CreateCall(RegisterAlias,
39273913
{TheClass, MakeConstantString(iter->second)});
39283914
}

clang/lib/CodeGen/CGVTables.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,6 @@ void CodeGenFunction::generateThunk(llvm::Function *Fn,
465465

466466
llvm::Constant *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true);
467467

468-
// Fix up the function type for an unprototyped musttail call.
469-
if (IsUnprototyped)
470-
Callee = llvm::ConstantExpr::getBitCast(Callee, Fn->getType());
471-
472468
// Make the call and return the result.
473469
EmitCallAndReturnForThunk(llvm::FunctionCallee(Fn->getFunctionType(), Callee),
474470
&Thunk, IsUnprototyped);
@@ -537,11 +533,8 @@ llvm::Constant *CodeGenVTables::maybeEmitThunk(GlobalDecl GD,
537533
Name.str(), &CGM.getModule());
538534
CGM.SetLLVMFunctionAttributes(MD, FnInfo, ThunkFn, /*IsThunk=*/false);
539535

540-
// If needed, replace the old thunk with a bitcast.
541536
if (!OldThunkFn->use_empty()) {
542-
llvm::Constant *NewPtrForOldDecl =
543-
llvm::ConstantExpr::getBitCast(ThunkFn, OldThunkFn->getType());
544-
OldThunkFn->replaceAllUsesWith(NewPtrForOldDecl);
537+
OldThunkFn->replaceAllUsesWith(ThunkFn);
545538
}
546539

547540
// Remove the old thunk.

0 commit comments

Comments
 (0)