Skip to content

Commit

Permalink
[NFC] Replace uses of Type::getPointerTo
Browse files Browse the repository at this point in the history
Replace some uses of `Type::getPointerTo` via 2 ways
* Remove entirely if it's only used to support an unnecessary bitcast
  (remove the bitcast as well).
* Replace with `PointerType::get`/`PointerType::getUnqual`

NFC opaque pointer clean-up effort.
  • Loading branch information
JOE1994 committed Sep 30, 2023
1 parent b6e568d commit 2048836
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 29 deletions.
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,9 @@ void CGRecordLowering::computeVolatileBitfields() {

void CGRecordLowering::accumulateVPtrs() {
if (Layout.hasOwnVFPtr())
Members.push_back(MemberInfo(CharUnits::Zero(), MemberInfo::VFPtr,
llvm::FunctionType::get(getIntNType(32), /*isVarArg=*/true)->
getPointerTo()->getPointerTo()));
Members.push_back(
MemberInfo(CharUnits::Zero(), MemberInfo::VFPtr,
llvm::PointerType::getUnqual(Types.getLLVMContext())));
if (Layout.hasOwnVBPtr())
Members.push_back(
MemberInfo(Layout.getVBPtrOffset(), MemberInfo::VBPtr,
Expand Down
22 changes: 1 addition & 21 deletions clang/lib/CodeGen/MicrosoftCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,6 @@ void MicrosoftCXXABI::initializeHiddenVirtualInheritanceMembers(
Builder.CreateInBoundsGEP(CGF.Int8Ty, Int8This, VBaseOffset);
// vtorDisp is always the 32-bits before the vbase in the class layout.
VtorDispPtr = Builder.CreateConstGEP1_32(CGF.Int8Ty, VtorDispPtr, -4);
VtorDispPtr = Builder.CreateBitCast(
VtorDispPtr, CGF.Int32Ty->getPointerTo(AS), "vtordisp.ptr");

Builder.CreateAlignedStore(VtorDispValue, VtorDispPtr,
CharUnits::fromQuantity(4));
Expand Down Expand Up @@ -1568,14 +1566,9 @@ void MicrosoftCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
if (!CGF.CurFuncIsThunk && MD->isVirtual()) {
CharUnits Adjustment = getVirtualFunctionPrologueThisAdjustment(CGF.CurGD);
if (!Adjustment.isZero()) {
unsigned AS = cast<llvm::PointerType>(This->getType())->getAddressSpace();
llvm::Type *charPtrTy = CGF.Int8Ty->getPointerTo(AS),
*thisTy = This->getType();
This = CGF.Builder.CreateBitCast(This, charPtrTy);
assert(Adjustment.isPositive());
This = CGF.Builder.CreateConstInBoundsGEP1_32(CGF.Int8Ty, This,
-Adjustment.getQuantity());
This = CGF.Builder.CreateBitCast(This, thisTy, "this.adjusted");
}
}
setCXXABIThisValue(CGF, This);
Expand Down Expand Up @@ -2511,9 +2504,6 @@ LValue MicrosoftCXXABI::EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
llvm::Value *V = CGF.CGM.GetAddrOfGlobalVar(VD);
llvm::Type *RealVarTy = CGF.getTypes().ConvertTypeForMem(VD->getType());

unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace();
V = CGF.Builder.CreateBitCast(V, RealVarTy->getPointerTo(AS));

CharUnits Alignment = CGF.getContext().getDeclAlign(VD);
Address Addr(V, RealVarTy, Alignment);

Expand Down Expand Up @@ -3226,9 +3216,6 @@ llvm::Value *MicrosoftCXXABI::EmitMemberDataPointerAddress(
CodeGenFunction &CGF, const Expr *E, Address Base, llvm::Value *MemPtr,
const MemberPointerType *MPT) {
assert(MPT->isMemberDataPointer());
unsigned AS = Base.getAddressSpace();
llvm::Type *PType =
CGF.ConvertTypeForMem(MPT->getPointeeType())->getPointerTo(AS);
CGBuilderTy &Builder = CGF.Builder;
const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
MSInheritanceModel Inheritance = RD->getMSInheritanceModel();
Expand Down Expand Up @@ -3256,16 +3243,9 @@ llvm::Value *MicrosoftCXXABI::EmitMemberDataPointerAddress(
Addr = Base.getPointer();
}

// Cast to char*.
Addr = Builder.CreateBitCast(Addr, CGF.Int8Ty->getPointerTo(AS));

// Apply the offset, which we assume is non-null.
Addr = Builder.CreateInBoundsGEP(CGF.Int8Ty, Addr, FieldOffset,
return Builder.CreateInBoundsGEP(CGF.Int8Ty, Addr, FieldOffset,
"memptr.offset");

// Cast the address to the appropriate pointer type, adopting the address
// space of the base pointer.
return Builder.CreateBitCast(Addr, PType);
}

llvm::Value *
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@ void CallLowering::insertSRetLoads(MachineIRBuilder &MIRBuilder, Type *RetTy,

unsigned NumValues = SplitVTs.size();
Align BaseAlign = DL.getPrefTypeAlign(RetTy);
Type *RetPtrTy = RetTy->getPointerTo(DL.getAllocaAddrSpace());
Type *RetPtrTy =
PointerType::get(RetTy->getContext(), DL.getAllocaAddrSpace());
LLT OffsetLLTy = getLLTForType(*DL.getIndexType(RetPtrTy), DL);

MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(MF, FI);
Expand Down
7 changes: 3 additions & 4 deletions mlir/lib/ExecutionEngine/ExecutionEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ static void packFunctionArguments(Module *module) {

// Given a function `foo(<...>)`, define the interface function
// `mlir_foo(i8**)`.
auto *newType = llvm::FunctionType::get(
builder.getVoidTy(), builder.getInt8PtrTy()->getPointerTo(),
/*isVarArg=*/false);
auto *newType =
llvm::FunctionType::get(builder.getVoidTy(), builder.getPtrTy(),
/*isVarArg=*/false);
auto newName = makePackedFunctionName(func.getName());
auto funcCst = module->getOrInsertFunction(newName, newType);
llvm::Function *interfaceFunc = cast<llvm::Function>(funcCst.getCallee());
Expand All @@ -179,7 +179,6 @@ static void packFunctionArguments(Module *module) {
llvm::Value *argPtr =
builder.CreateLoad(builder.getInt8PtrTy(), argPtrPtr);
llvm::Type *argTy = arg.getType();
argPtr = builder.CreateBitCast(argPtr, argTy->getPointerTo());
llvm::Value *load = builder.CreateLoad(argTy, argPtr);
args.push_back(load);
}
Expand Down

0 comments on commit 2048836

Please sign in to comment.