Skip to content

Commit 13d65a0

Browse files
committed
[CodeGen] Replace of PointerType::get(Type) with opaque version (NFC)
Follow-up to #123569
1 parent 27598ab commit 13d65a0

File tree

7 files changed

+14
-38
lines changed

7 files changed

+14
-38
lines changed

clang/lib/CodeGen/Address.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clang/AST/Type.h"
2020
#include "llvm/ADT/PointerIntPair.h"
2121
#include "llvm/IR/Constants.h"
22+
#include "llvm/IR/DerivedTypes.h"
2223
#include "llvm/Support/MathExtras.h"
2324

2425
namespace clang {
@@ -197,10 +198,9 @@ class Address {
197198

198199
/// Return the type of the pointer value.
199200
llvm::PointerType *getType() const {
200-
return llvm::PointerType::get(
201-
ElementType,
202-
llvm::cast<llvm::PointerType>(Pointer.getPointer()->getType())
203-
->getAddressSpace());
201+
auto AS = llvm::cast<llvm::PointerType>(Pointer.getPointer()->getType())
202+
->getAddressSpace();
203+
return llvm::PointerType::get(ElementType->getContext(), AS);
204204
}
205205

206206
/// 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: 1 addition & 4 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

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void CodeGenFunction::registerGlobalDtorWithAtExit(llvm::Constant *dtorStub) {
347347
// extern "C" int atexit(void (*f)(void));
348348
assert(dtorStub->getType() ==
349349
llvm::PointerType::get(
350-
llvm::FunctionType::get(CGM.VoidTy, false),
350+
CGM.getLLVMContext(),
351351
dtorStub->getType()->getPointerAddressSpace()) &&
352352
"Argument to atexit has a wrong type.");
353353

@@ -374,7 +374,7 @@ CodeGenFunction::unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub) {
374374
// extern "C" int unatexit(void (*f)(void));
375375
assert(dtorStub->getType() ==
376376
llvm::PointerType::get(
377-
llvm::FunctionType::get(CGM.VoidTy, false),
377+
CGM.getLLVMContext(),
378378
dtorStub->getType()->getPointerAddressSpace()) &&
379379
"Argument to unatexit has a wrong type.");
380380

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)