Author: JOE1994 Date: 2023-09-30T08:05:46-04:00 New Revision: 62205c2e60e375f1af7a498be370dd64ff6d8b2a
URL: https://github.com/llvm/llvm-project/commit/62205c2e60e375f1af7a498be370dd64ff6d8b2a DIFF: https://github.com/llvm/llvm-project/commit/62205c2e60e375f1af7a498be370dd64ff6d8b2a.diff LOG: [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. Added: Modified: clang/lib/CodeGen/CGObjCMac.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index f55759581fa78ec..b7aa3a4cb6373c3 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -1958,9 +1958,8 @@ llvm::Constant *CGObjCMac::getNSConstantStringClassRef() { llvm::Type *PTy = llvm::ArrayType::get(CGM.IntTy, 0); auto GV = CGM.CreateRuntimeVariable(PTy, str); - auto V = llvm::ConstantExpr::getBitCast(GV, CGM.IntTy->getPointerTo()); - ConstantStringClassRef = V; - return V; + ConstantStringClassRef = GV; + return GV; } llvm::Constant *CGObjCNonFragileABIMac::getNSConstantStringClassRef() { @@ -1972,12 +1971,8 @@ llvm::Constant *CGObjCNonFragileABIMac::getNSConstantStringClassRef() { StringClass.empty() ? "OBJC_CLASS_$_NSConstantString" : "OBJC_CLASS_$_" + StringClass; llvm::Constant *GV = GetClassGlobal(str, NotForDefinition); - - // Make sure the result is of the correct type. - auto V = llvm::ConstantExpr::getBitCast(GV, CGM.IntTy->getPointerTo()); - - ConstantStringClassRef = V; - return V; + ConstantStringClassRef = GV; + return GV; } ConstantAddress @@ -1996,11 +1991,8 @@ CGObjCCommonMac::GenerateConstantNSString(const StringLiteral *Literal) { // If we don't already have it, construct the type for a constant NSString. if (!NSConstantStringType) { NSConstantStringType = - llvm::StructType::create({ - CGM.Int32Ty->getPointerTo(), - CGM.Int8PtrTy, - CGM.IntTy - }, "struct.__builtin_NSString"); + llvm::StructType::create({CGM.UnqualPtrTy, CGM.Int8PtrTy, CGM.IntTy}, + "struct.__builtin_NSString"); } ConstantInitBuilder Builder(CGM); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6073a2749449a6d..c96523c52562582 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3194,8 +3194,9 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV, if (GV->getAddressSpace() != getDataLayout().getDefaultGlobalsAddressSpace()) { GVInGlobalsAS = llvm::ConstantExpr::getAddrSpaceCast( - GV, GV->getValueType()->getPointerTo( - getDataLayout().getDefaultGlobalsAddressSpace())); + GV, + llvm::PointerType::get( + GV->getContext(), getDataLayout().getDefaultGlobalsAddressSpace())); } // Create the ConstantStruct for the global annotation. @@ -3445,9 +3446,7 @@ ConstantAddress CodeGenModule::GetAddrOfMSGuidDecl(const MSGuidDecl *GD) { } llvm::Type *Ty = getTypes().ConvertTypeForMem(GD->getType()); - llvm::Constant *Addr = llvm::ConstantExpr::getBitCast( - GV, Ty->getPointerTo(GV->getAddressSpace())); - return ConstantAddress(Addr, Ty, Alignment); + return ConstantAddress(GV, Ty, Alignment); } ConstantAddress CodeGenModule::GetAddrOfUnnamedGlobalConstantDecl( @@ -3521,11 +3520,8 @@ ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) { // See if there is already something with the target's name in the module. llvm::GlobalValue *Entry = GetGlobalValue(AA->getAliasee()); - if (Entry) { - unsigned AS = getTypes().getTargetAddressSpace(VD->getType()); - auto Ptr = llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS)); - return ConstantAddress(Ptr, DeclTy, Alignment); - } + if (Entry) + return ConstantAddress(Entry, DeclTy, Alignment); llvm::Constant *Aliasee; if (isa<llvm::FunctionType>(DeclTy)) @@ -4359,8 +4355,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction( // (If function is requested for a definition, we always need to create a new // function, not just return a bitcast.) if (!IsForDefinition) - return llvm::ConstantExpr::getBitCast( - Entry, Ty->getPointerTo(Entry->getAddressSpace())); + return Entry; } // This function doesn't have a complete type (for example, the return @@ -4400,9 +4395,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction( Entry->removeDeadConstantUsers(); } - llvm::Constant *BC = llvm::ConstantExpr::getBitCast( - F, Entry->getValueType()->getPointerTo(Entry->getAddressSpace())); - addGlobalValReplacement(Entry, BC); + addGlobalValReplacement(Entry, F); } assert(F->getName() == MangledName && "name was uniqued!"); @@ -4464,8 +4457,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction( return F; } - return llvm::ConstantExpr::getBitCast(F, - Ty->getPointerTo(F->getAddressSpace())); + return F; } /// GetAddrOfFunction - Return the address of the given function. If Ty is @@ -4502,7 +4494,7 @@ CodeGenModule::GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty, bool ForVTable, cast<llvm::Function>(F->stripPointerCasts()), GD); if (IsForDefinition) return F; - return llvm::ConstantExpr::getBitCast(Handle, Ty->getPointerTo()); + return Handle; } return F; } @@ -4650,15 +4642,14 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty, } // Make sure the result is of the correct type. - if (Entry->getType()->getAddressSpace() != TargetAS) { - return llvm::ConstantExpr::getAddrSpaceCast(Entry, - Ty->getPointerTo(TargetAS)); - } + if (Entry->getType()->getAddressSpace() != TargetAS) + return llvm::ConstantExpr::getAddrSpaceCast( + Entry, llvm::PointerType::get(Ty->getContext(), TargetAS)); // (If global is requested for a definition, we always need to create a new // global, not just return a bitcast.) if (!IsForDefinition) - return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo(TargetAS)); + return Entry; } auto DAddrSpace = GetGlobalVarAddressSpace(D); diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index adb5eb850b5546d..d623f8f63ae56c4 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1235,7 +1235,6 @@ void MicrosoftCXXABI::initializeHiddenVirtualInheritanceMembers( const VBOffsets &VBaseMap = Layout.getVBaseOffsetsMap(); CGBuilderTy &Builder = CGF.Builder; - unsigned AS = getThisAddress(CGF).getAddressSpace(); llvm::Value *Int8This = nullptr; // Initialize lazily. for (const CXXBaseSpecifier &S : RD->vbases()) { @@ -1256,8 +1255,8 @@ void MicrosoftCXXABI::initializeHiddenVirtualInheritanceMembers( VtorDispValue = Builder.CreateTruncOrBitCast(VtorDispValue, CGF.Int32Ty); if (!Int8This) - Int8This = Builder.CreateBitCast(getThisValue(CGF), - CGF.Int8Ty->getPointerTo(AS)); + Int8This = getThisValue(CGF); + llvm::Value *VtorDispPtr = Builder.CreateInBoundsGEP(CGF.Int8Ty, Int8This, VBaseOffset); // vtorDisp is always the 32-bits before the vbase in the class layout. @@ -3502,8 +3501,6 @@ CGCallee MicrosoftCXXABI::EmitLoadOfMemberFunctionPointer( const FunctionProtoType *FPT = MPT->getPointeeType()->castAs<FunctionProtoType>(); const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl(); - llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType( - CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr)); CGBuilderTy &Builder = CGF.Builder; MSInheritanceModel Inheritance = RD->getMSInheritanceModel(); @@ -3533,16 +3530,10 @@ CGCallee MicrosoftCXXABI::EmitLoadOfMemberFunctionPointer( ThisPtrForCall = This.getPointer(); } - if (NonVirtualBaseAdjustment) { - // Apply the adjustment and cast back to the original struct type. - llvm::Value *Ptr = Builder.CreateBitCast(ThisPtrForCall, CGF.Int8PtrTy); - Ptr = Builder.CreateInBoundsGEP(CGF.Int8Ty, Ptr, NonVirtualBaseAdjustment); - ThisPtrForCall = Builder.CreateBitCast(Ptr, ThisPtrForCall->getType(), - "this.adjusted"); - } + if (NonVirtualBaseAdjustment) + ThisPtrForCall = Builder.CreateInBoundsGEP(CGF.Int8Ty, ThisPtrForCall, + NonVirtualBaseAdjustment); - FunctionPointer = - Builder.CreateBitCast(FunctionPointer, FTy->getPointerTo()); CGCallee Callee(FPT, FunctionPointer); return Callee; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits