Skip to content

Commit

Permalink
[clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (#6…
Browse files Browse the repository at this point in the history
…8277)

With opaque pointers, `CreatePointerBitCastOrAddrSpaceCast` can be replaced with `CreateAddrSpaceCast`.
Replace or remove uses of `CreatePointerBitCastOrAddrSpaceCast`.

Opaque pointer cleanup effort.
  • Loading branch information
JOE1994 committed Nov 11, 2023
1 parent 167b598 commit 5c91b28
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ static void CreateCoercedStore(llvm::Value *Src,
llvm::PointerType *DstPtrTy = llvm::dyn_cast<llvm::PointerType>(DstTy);
if (SrcPtrTy && DstPtrTy &&
SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy);
Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy);
CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
return;
}
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,11 +1121,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
Address(&*AI, ConvertType(RetTy),
CurFnInfo->getReturnInfo().getIndirectAlign(), KnownNonNull);
if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
ReturnValuePointer =
CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
ReturnValue.getPointer(), Int8PtrTy),
ReturnValuePointer);
ReturnValuePointer = CreateDefaultAlignTempAlloca(
ReturnValue.getPointer()->getType(), "result.ptr");
Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer);
}
} else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
!hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/CodeGen/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3095,9 +3095,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
CharUnits Align = CGM.getContext().getDeclAlign(VD);
Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
}
if (Val->getType() != Wrapper->getReturnType())
Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
Val, Wrapper->getReturnType(), "");

Builder.CreateRet(Val);
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
if (auto *C = dyn_cast<llvm::Constant>(Src))
return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
// Try to preserve the source's name to make IR more readable.
return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
return CGF.Builder.CreateAddrSpaceCast(
Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
}

Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/IR/IRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,9 @@ class IRBuilderBase {
return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
}

// With opaque pointers enabled, this can be substituted with
// CreateAddrSpaceCast.
// TODO: Replace uses of this method and remove the method itself.
Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
const Twine &Name = "") {
if (V->getType() == DestTy)
Expand Down

0 comments on commit 5c91b28

Please sign in to comment.