Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "clang/AST/Type.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/Support/MathExtras.h"

namespace clang {
Expand Down Expand Up @@ -197,10 +198,9 @@ class Address {

/// Return the type of the pointer value.
llvm::PointerType *getType() const {
return llvm::PointerType::get(
ElementType,
llvm::cast<llvm::PointerType>(Pointer.getPointer()->getType())
->getAddressSpace());
auto AS = llvm::cast<llvm::PointerType>(Pointer.getPointer()->getType())
->getAddressSpace();
return llvm::PointerType::get(ElementType->getContext(), AS);
}

/// Return the type of the values stored in this address.
Expand Down
23 changes: 1 addition & 22 deletions clang/lib/CodeGen/CGBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,31 +1097,10 @@ llvm::Type *CodeGenModule::getBlockDescriptorType() {
if (BlockDescriptorType)
return BlockDescriptorType;

llvm::Type *UnsignedLongTy =
getTypes().ConvertType(getContext().UnsignedLongTy);

// struct __block_descriptor {
// unsigned long reserved;
// unsigned long block_size;
//
// // later, the following will be added
//
// struct {
// void (*copyHelper)();
// void (*copyHelper)();
// } helpers; // !!! optional
//
// const char *signature; // the block signature
// const char *layout; // reserved
// };
Comment on lines -1100 to -1116
Copy link
Member Author

@junlarsen junlarsen Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do feel a bit guilty about removing this comment. However, I'm not experienced enough to know if it's significant and something we'd like to keep?

Perhaps move it somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to drop it, essentially the same comment also exists on buildBlockDescriptor.

BlockDescriptorType = llvm::StructType::create(
"struct.__block_descriptor", UnsignedLongTy, UnsignedLongTy);

// Now form a pointer to that.
unsigned AddrSpace = 0;
if (getLangOpts().OpenCL)
AddrSpace = getContext().getTargetAddressSpace(LangAS::opencl_constant);
BlockDescriptorType = llvm::PointerType::get(BlockDescriptorType, AddrSpace);
BlockDescriptorType = llvm::PointerType::get(getLLVMContext(), AddrSpace);
return BlockDescriptorType;
}

Expand Down
8 changes: 2 additions & 6 deletions clang/lib/CodeGen/CGDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2870,15 +2870,12 @@ void CodeGenModule::EmitOMPAllocateDecl(const OMPAllocateDecl *D) {

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

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

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

Entry->mutateType(PTy);
llvm::Constant *NewPtrForOldDecl =
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
Entry, DummyGV->getType());
llvm::ConstantExpr::getAddrSpaceCast(Entry, DummyGV->getType());

// Now we have a casted version of the changed global, the dummy can be
// replaced and deleted.
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void CodeGenFunction::registerGlobalDtorWithAtExit(llvm::Constant *dtorStub) {
// extern "C" int atexit(void (*f)(void));
assert(dtorStub->getType() ==
llvm::PointerType::get(
llvm::FunctionType::get(CGM.VoidTy, false),
CGM.getLLVMContext(),
dtorStub->getType()->getPointerAddressSpace()) &&
"Argument to atexit has a wrong type.");

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

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
llvm::Value *TypeHash =
llvm::ConstantInt::get(Int64Ty, xxh3_64bits(Out.str()));

llvm::Type *VPtrTy = llvm::PointerType::get(IntPtrTy, 0);
llvm::Type *VPtrTy = llvm::PointerType::get(getLLVMContext(), 0);
Address VPtrAddr(Ptr, IntPtrTy, getPointerAlign());
llvm::Value *VPtrVal = GetVTablePtr(VPtrAddr, VPtrTy,
Ty->getAsCXXRecordDecl(),
Expand Down Expand Up @@ -3054,7 +3054,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
getContext().getDeclAlign(VD));
llvm::Type *VarTy = getTypes().ConvertTypeForMem(VD->getType());
auto *PTy = llvm::PointerType::get(
VarTy, getTypes().getTargetAddressSpace(VD->getType()));
getLLVMContext(), getTypes().getTargetAddressSpace(VD->getType()));
Addr = Builder.CreatePointerBitCastOrAddrSpaceCast(Addr, PTy, VarTy);
Copy link
Member Author

@junlarsen junlarsen Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the below cast be replaced with an AddrSpaceCast only? i.e CGBuilder::CreateAddrSpaceCast? I'm not too sure how the Clang codegen Address code behaves.

} else {
// Should we be using the alignment of the constant pointer we emitted?
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGObjCMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5717,7 +5717,7 @@ ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
IntTy = CGM.IntTy;
LongTy = cast<llvm::IntegerType>(Types.ConvertType(Ctx.LongTy));
Int8PtrTy = CGM.Int8PtrTy;
Int8PtrProgramASTy = llvm::PointerType::get(CGM.Int8Ty, ProgramAS);
Int8PtrProgramASTy = llvm::PointerType::get(CGM.getLLVMContext(), ProgramAS);
Int8PtrPtrTy = CGM.Int8PtrPtrTy;

// arm64 targets use "int" ivar offset variables. All others,
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4432,7 +4432,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
GlobalDecl ResolverGD;
if (getTarget().supportsIFunc()) {
ResolverType = llvm::FunctionType::get(
llvm::PointerType::get(DeclTy,
llvm::PointerType::get(getLLVMContext(),
getTypes().getTargetAddressSpace(FD->getType())),
false);
}
Expand Down Expand Up @@ -4604,8 +4604,8 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
// cpu_dispatch will be emitted in this translation unit.
if (ShouldReturnIFunc) {
unsigned AS = getTypes().getTargetAddressSpace(FD->getType());
llvm::Type *ResolverType =
llvm::FunctionType::get(llvm::PointerType::get(DeclTy, AS), false);
llvm::Type *ResolverType = llvm::FunctionType::get(
llvm::PointerType::get(getLLVMContext(), AS), false);
llvm::Constant *Resolver = GetOrCreateLLVMFunction(
MangledName + ".resolver", ResolverType, GlobalDecl{},
/*ForVTable=*/false);
Expand Down