Skip to content

Commit 62205c2

Browse files
committed
[clang] Remove uses of llvm::Type::getPointerTo() (NFC)
* Remove if its sole use is to support an unnecessary ptr-to-ptr bitcast (remove the bitcast as well) * Replace with use of other APIs. NFC opaque pointer cleanup effort.
1 parent 4346aaf commit 62205c2

File tree

3 files changed

+25
-51
lines changed

3 files changed

+25
-51
lines changed

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,9 +1958,8 @@ llvm::Constant *CGObjCMac::getNSConstantStringClassRef() {
19581958

19591959
llvm::Type *PTy = llvm::ArrayType::get(CGM.IntTy, 0);
19601960
auto GV = CGM.CreateRuntimeVariable(PTy, str);
1961-
auto V = llvm::ConstantExpr::getBitCast(GV, CGM.IntTy->getPointerTo());
1962-
ConstantStringClassRef = V;
1963-
return V;
1961+
ConstantStringClassRef = GV;
1962+
return GV;
19641963
}
19651964

19661965
llvm::Constant *CGObjCNonFragileABIMac::getNSConstantStringClassRef() {
@@ -1972,12 +1971,8 @@ llvm::Constant *CGObjCNonFragileABIMac::getNSConstantStringClassRef() {
19721971
StringClass.empty() ? "OBJC_CLASS_$_NSConstantString"
19731972
: "OBJC_CLASS_$_" + StringClass;
19741973
llvm::Constant *GV = GetClassGlobal(str, NotForDefinition);
1975-
1976-
// Make sure the result is of the correct type.
1977-
auto V = llvm::ConstantExpr::getBitCast(GV, CGM.IntTy->getPointerTo());
1978-
1979-
ConstantStringClassRef = V;
1980-
return V;
1974+
ConstantStringClassRef = GV;
1975+
return GV;
19811976
}
19821977

19831978
ConstantAddress
@@ -1996,11 +1991,8 @@ CGObjCCommonMac::GenerateConstantNSString(const StringLiteral *Literal) {
19961991
// If we don't already have it, construct the type for a constant NSString.
19971992
if (!NSConstantStringType) {
19981993
NSConstantStringType =
1999-
llvm::StructType::create({
2000-
CGM.Int32Ty->getPointerTo(),
2001-
CGM.Int8PtrTy,
2002-
CGM.IntTy
2003-
}, "struct.__builtin_NSString");
1994+
llvm::StructType::create({CGM.UnqualPtrTy, CGM.Int8PtrTy, CGM.IntTy},
1995+
"struct.__builtin_NSString");
20041996
}
20051997

20061998
ConstantInitBuilder Builder(CGM);

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,8 +3194,9 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
31943194
if (GV->getAddressSpace() !=
31953195
getDataLayout().getDefaultGlobalsAddressSpace()) {
31963196
GVInGlobalsAS = llvm::ConstantExpr::getAddrSpaceCast(
3197-
GV, GV->getValueType()->getPointerTo(
3198-
getDataLayout().getDefaultGlobalsAddressSpace()));
3197+
GV,
3198+
llvm::PointerType::get(
3199+
GV->getContext(), getDataLayout().getDefaultGlobalsAddressSpace()));
31993200
}
32003201

32013202
// Create the ConstantStruct for the global annotation.
@@ -3445,9 +3446,7 @@ ConstantAddress CodeGenModule::GetAddrOfMSGuidDecl(const MSGuidDecl *GD) {
34453446
}
34463447

34473448
llvm::Type *Ty = getTypes().ConvertTypeForMem(GD->getType());
3448-
llvm::Constant *Addr = llvm::ConstantExpr::getBitCast(
3449-
GV, Ty->getPointerTo(GV->getAddressSpace()));
3450-
return ConstantAddress(Addr, Ty, Alignment);
3449+
return ConstantAddress(GV, Ty, Alignment);
34513450
}
34523451

34533452
ConstantAddress CodeGenModule::GetAddrOfUnnamedGlobalConstantDecl(
@@ -3521,11 +3520,8 @@ ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
35213520

35223521
// See if there is already something with the target's name in the module.
35233522
llvm::GlobalValue *Entry = GetGlobalValue(AA->getAliasee());
3524-
if (Entry) {
3525-
unsigned AS = getTypes().getTargetAddressSpace(VD->getType());
3526-
auto Ptr = llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS));
3527-
return ConstantAddress(Ptr, DeclTy, Alignment);
3528-
}
3523+
if (Entry)
3524+
return ConstantAddress(Entry, DeclTy, Alignment);
35293525

35303526
llvm::Constant *Aliasee;
35313527
if (isa<llvm::FunctionType>(DeclTy))
@@ -4359,8 +4355,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
43594355
// (If function is requested for a definition, we always need to create a new
43604356
// function, not just return a bitcast.)
43614357
if (!IsForDefinition)
4362-
return llvm::ConstantExpr::getBitCast(
4363-
Entry, Ty->getPointerTo(Entry->getAddressSpace()));
4358+
return Entry;
43644359
}
43654360

43664361
// This function doesn't have a complete type (for example, the return
@@ -4400,9 +4395,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
44004395
Entry->removeDeadConstantUsers();
44014396
}
44024397

4403-
llvm::Constant *BC = llvm::ConstantExpr::getBitCast(
4404-
F, Entry->getValueType()->getPointerTo(Entry->getAddressSpace()));
4405-
addGlobalValReplacement(Entry, BC);
4398+
addGlobalValReplacement(Entry, F);
44064399
}
44074400

44084401
assert(F->getName() == MangledName && "name was uniqued!");
@@ -4464,8 +4457,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
44644457
return F;
44654458
}
44664459

4467-
return llvm::ConstantExpr::getBitCast(F,
4468-
Ty->getPointerTo(F->getAddressSpace()));
4460+
return F;
44694461
}
44704462

44714463
/// GetAddrOfFunction - Return the address of the given function. If Ty is
@@ -4502,7 +4494,7 @@ CodeGenModule::GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty, bool ForVTable,
45024494
cast<llvm::Function>(F->stripPointerCasts()), GD);
45034495
if (IsForDefinition)
45044496
return F;
4505-
return llvm::ConstantExpr::getBitCast(Handle, Ty->getPointerTo());
4497+
return Handle;
45064498
}
45074499
return F;
45084500
}
@@ -4650,15 +4642,14 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
46504642
}
46514643

46524644
// Make sure the result is of the correct type.
4653-
if (Entry->getType()->getAddressSpace() != TargetAS) {
4654-
return llvm::ConstantExpr::getAddrSpaceCast(Entry,
4655-
Ty->getPointerTo(TargetAS));
4656-
}
4645+
if (Entry->getType()->getAddressSpace() != TargetAS)
4646+
return llvm::ConstantExpr::getAddrSpaceCast(
4647+
Entry, llvm::PointerType::get(Ty->getContext(), TargetAS));
46574648

46584649
// (If global is requested for a definition, we always need to create a new
46594650
// global, not just return a bitcast.)
46604651
if (!IsForDefinition)
4661-
return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo(TargetAS));
4652+
return Entry;
46624653
}
46634654

46644655
auto DAddrSpace = GetGlobalVarAddressSpace(D);

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,6 @@ void MicrosoftCXXABI::initializeHiddenVirtualInheritanceMembers(
12351235
const VBOffsets &VBaseMap = Layout.getVBaseOffsetsMap();
12361236
CGBuilderTy &Builder = CGF.Builder;
12371237

1238-
unsigned AS = getThisAddress(CGF).getAddressSpace();
12391238
llvm::Value *Int8This = nullptr; // Initialize lazily.
12401239

12411240
for (const CXXBaseSpecifier &S : RD->vbases()) {
@@ -1256,8 +1255,8 @@ void MicrosoftCXXABI::initializeHiddenVirtualInheritanceMembers(
12561255
VtorDispValue = Builder.CreateTruncOrBitCast(VtorDispValue, CGF.Int32Ty);
12571256

12581257
if (!Int8This)
1259-
Int8This = Builder.CreateBitCast(getThisValue(CGF),
1260-
CGF.Int8Ty->getPointerTo(AS));
1258+
Int8This = getThisValue(CGF);
1259+
12611260
llvm::Value *VtorDispPtr =
12621261
Builder.CreateInBoundsGEP(CGF.Int8Ty, Int8This, VBaseOffset);
12631262
// vtorDisp is always the 32-bits before the vbase in the class layout.
@@ -3502,8 +3501,6 @@ CGCallee MicrosoftCXXABI::EmitLoadOfMemberFunctionPointer(
35023501
const FunctionProtoType *FPT =
35033502
MPT->getPointeeType()->castAs<FunctionProtoType>();
35043503
const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
3505-
llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(
3506-
CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr));
35073504
CGBuilderTy &Builder = CGF.Builder;
35083505

35093506
MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
@@ -3533,16 +3530,10 @@ CGCallee MicrosoftCXXABI::EmitLoadOfMemberFunctionPointer(
35333530
ThisPtrForCall = This.getPointer();
35343531
}
35353532

3536-
if (NonVirtualBaseAdjustment) {
3537-
// Apply the adjustment and cast back to the original struct type.
3538-
llvm::Value *Ptr = Builder.CreateBitCast(ThisPtrForCall, CGF.Int8PtrTy);
3539-
Ptr = Builder.CreateInBoundsGEP(CGF.Int8Ty, Ptr, NonVirtualBaseAdjustment);
3540-
ThisPtrForCall = Builder.CreateBitCast(Ptr, ThisPtrForCall->getType(),
3541-
"this.adjusted");
3542-
}
3533+
if (NonVirtualBaseAdjustment)
3534+
ThisPtrForCall = Builder.CreateInBoundsGEP(CGF.Int8Ty, ThisPtrForCall,
3535+
NonVirtualBaseAdjustment);
35433536

3544-
FunctionPointer =
3545-
Builder.CreateBitCast(FunctionPointer, FTy->getPointerTo());
35463537
CGCallee Callee(FPT, FunctionPointer);
35473538
return Callee;
35483539
}

0 commit comments

Comments
 (0)