Skip to content

Commit e0fee55

Browse files
authored
[CodeGen] Replace of PointerType::get(Type) with opaque version (NFC) (#124771)
Follow-up to #123569
1 parent 6ff8a06 commit e0fee55

File tree

7 files changed

+12
-46
lines changed

7 files changed

+12
-46
lines changed

clang/lib/CodeGen/Address.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ class Address {
197197

198198
/// Return the type of the pointer value.
199199
llvm::PointerType *getType() const {
200-
return llvm::PointerType::get(
201-
ElementType,
202-
llvm::cast<llvm::PointerType>(Pointer.getPointer()->getType())
203-
->getAddressSpace());
200+
return llvm::cast<llvm::PointerType>(Pointer.getPointer()->getType());
204201
}
205202

206203
/// Return the type of the values stored in this address.

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,31 +1097,10 @@ llvm::Type *CodeGenModule::getBlockDescriptorType() {
10971097
if (BlockDescriptorType)
10981098
return BlockDescriptorType;
10991099

1100-
llvm::Type *UnsignedLongTy =
1101-
getTypes().ConvertType(getContext().UnsignedLongTy);
1102-
1103-
// struct __block_descriptor {
1104-
// unsigned long reserved;
1105-
// unsigned long block_size;
1106-
//
1107-
// // later, the following will be added
1108-
//
1109-
// struct {
1110-
// void (*copyHelper)();
1111-
// void (*copyHelper)();
1112-
// } helpers; // !!! optional
1113-
//
1114-
// const char *signature; // the block signature
1115-
// const char *layout; // reserved
1116-
// };
1117-
BlockDescriptorType = llvm::StructType::create(
1118-
"struct.__block_descriptor", UnsignedLongTy, UnsignedLongTy);
1119-
1120-
// Now form a pointer to that.
11211100
unsigned AddrSpace = 0;
11221101
if (getLangOpts().OpenCL)
11231102
AddrSpace = getContext().getTargetAddressSpace(LangAS::opencl_constant);
1124-
BlockDescriptorType = llvm::PointerType::get(BlockDescriptorType, AddrSpace);
1103+
BlockDescriptorType = llvm::PointerType::get(getLLVMContext(), AddrSpace);
11251104
return BlockDescriptorType;
11261105
}
11271106

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,15 +2870,12 @@ void CodeGenModule::EmitOMPAllocateDecl(const OMPAllocateDecl *D) {
28702870

28712871
// We can also keep the existing global if the address space is what we
28722872
// expect it to be, if not, it is replaced.
2873-
QualType ASTTy = VD->getType();
28742873
clang::LangAS GVAS = GetGlobalVarAddressSpace(VD);
28752874
auto TargetAS = getContext().getTargetAddressSpace(GVAS);
28762875
if (Entry->getType()->getAddressSpace() == TargetAS)
28772876
continue;
28782877

2879-
// Make a new global with the correct type / address space.
2880-
llvm::Type *Ty = getTypes().ConvertTypeForMem(ASTTy);
2881-
llvm::PointerType *PTy = llvm::PointerType::get(Ty, TargetAS);
2878+
llvm::PointerType *PTy = llvm::PointerType::get(getLLVMContext(), TargetAS);
28822879

28832880
// Replace all uses of the old global with a cast. Since we mutate the type
28842881
// in place we neeed an intermediate that takes the spot of the old entry
@@ -2891,8 +2888,7 @@ void CodeGenModule::EmitOMPAllocateDecl(const OMPAllocateDecl *D) {
28912888

28922889
Entry->mutateType(PTy);
28932890
llvm::Constant *NewPtrForOldDecl =
2894-
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
2895-
Entry, DummyGV->getType());
2891+
llvm::ConstantExpr::getAddrSpaceCast(Entry, DummyGV->getType());
28962892

28972893
// Now we have a casted version of the changed global, the dummy can be
28982894
// replaced and deleted.

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,7 @@ void CodeGenFunction::registerGlobalDtorWithLLVM(const VarDecl &VD,
345345

346346
void CodeGenFunction::registerGlobalDtorWithAtExit(llvm::Constant *dtorStub) {
347347
// extern "C" int atexit(void (*f)(void));
348-
assert(dtorStub->getType() ==
349-
llvm::PointerType::get(
350-
llvm::FunctionType::get(CGM.VoidTy, false),
351-
dtorStub->getType()->getPointerAddressSpace()) &&
348+
assert(dtorStub->getType()->isPointerTy() &&
352349
"Argument to atexit has a wrong type.");
353350

354351
llvm::FunctionType *atexitTy =
@@ -372,10 +369,7 @@ CodeGenFunction::unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub) {
372369
// value is returned.
373370
//
374371
// extern "C" int unatexit(void (*f)(void));
375-
assert(dtorStub->getType() ==
376-
llvm::PointerType::get(
377-
llvm::FunctionType::get(CGM.VoidTy, false),
378-
dtorStub->getType()->getPointerAddressSpace()) &&
372+
assert(dtorStub->getType()->isPointerTy() &&
379373
"Argument to unatexit has a wrong type.");
380374

381375
llvm::FunctionType *unatexitTy =

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
872872
llvm::Value *TypeHash =
873873
llvm::ConstantInt::get(Int64Ty, xxh3_64bits(Out.str()));
874874

875-
llvm::Type *VPtrTy = llvm::PointerType::get(IntPtrTy, 0);
875+
llvm::Type *VPtrTy = llvm::PointerType::get(getLLVMContext(), 0);
876876
Address VPtrAddr(Ptr, IntPtrTy, getPointerAlign());
877877
llvm::Value *VPtrVal = GetVTablePtr(VPtrAddr, VPtrTy,
878878
Ty->getAsCXXRecordDecl(),
@@ -3054,7 +3054,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
30543054
getContext().getDeclAlign(VD));
30553055
llvm::Type *VarTy = getTypes().ConvertTypeForMem(VD->getType());
30563056
auto *PTy = llvm::PointerType::get(
3057-
VarTy, getTypes().getTargetAddressSpace(VD->getType()));
3057+
getLLVMContext(), getTypes().getTargetAddressSpace(VD->getType()));
30583058
Addr = Builder.CreatePointerBitCastOrAddrSpaceCast(Addr, PTy, VarTy);
30593059
} else {
30603060
// Should we be using the alignment of the constant pointer we emitted?

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5717,7 +5717,7 @@ ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
57175717
IntTy = CGM.IntTy;
57185718
LongTy = cast<llvm::IntegerType>(Types.ConvertType(Ctx.LongTy));
57195719
Int8PtrTy = CGM.Int8PtrTy;
5720-
Int8PtrProgramASTy = llvm::PointerType::get(CGM.Int8Ty, ProgramAS);
5720+
Int8PtrProgramASTy = llvm::PointerType::get(CGM.getLLVMContext(), ProgramAS);
57215721
Int8PtrPtrTy = CGM.Int8PtrPtrTy;
57225722

57235723
// arm64 targets use "int" ivar offset variables. All others,

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,7 +4432,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
44324432
GlobalDecl ResolverGD;
44334433
if (getTarget().supportsIFunc()) {
44344434
ResolverType = llvm::FunctionType::get(
4435-
llvm::PointerType::get(DeclTy,
4435+
llvm::PointerType::get(getLLVMContext(),
44364436
getTypes().getTargetAddressSpace(FD->getType())),
44374437
false);
44384438
}
@@ -4604,8 +4604,8 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
46044604
// cpu_dispatch will be emitted in this translation unit.
46054605
if (ShouldReturnIFunc) {
46064606
unsigned AS = getTypes().getTargetAddressSpace(FD->getType());
4607-
llvm::Type *ResolverType =
4608-
llvm::FunctionType::get(llvm::PointerType::get(DeclTy, AS), false);
4607+
llvm::Type *ResolverType = llvm::FunctionType::get(
4608+
llvm::PointerType::get(getLLVMContext(), AS), false);
46094609
llvm::Constant *Resolver = GetOrCreateLLVMFunction(
46104610
MangledName + ".resolver", ResolverType, GlobalDecl{},
46114611
/*ForVTable=*/false);

0 commit comments

Comments
 (0)