diff options
| author | JOE1994 <joseph942010@gmail.com> | 2023-09-30 08:02:28 -0400 |
|---|---|---|
| committer | JOE1994 <joseph942010@gmail.com> | 2023-09-30 08:05:46 -0400 |
| commit | 62205c2e60e375f1af7a498be370dd64ff6d8b2a (patch) | |
| tree | 5444dbbea14cfc9e42fd1f0b0c0f68684a53f6ea /clang/lib/CodeGen/CodeGenModule.cpp | |
| parent | 4346aaf05b66a204a7c21fad8e7673860e0270eb (diff) | |
[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.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6073a2749449..c96523c52562 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); |
