Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM-16: Add macOS support #1

Draft
wants to merge 2 commits into
base: chipStar-llvm-16
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions clang/lib/CodeGen/CGCUDANV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,12 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
llvm::Constant *FatBinStr;
unsigned FatMagic;
if (IsHIP) {
FatbinConstantName = ".hip_fatbin";
FatbinSectionName = ".hipFatBinSegment";
FatbinConstantName = CGM.getTriple().isMacOSX()
? "__HIP,__hip_fatbin"
: ".hip_fatbin";
FatbinSectionName = CGM.getTriple().isMacOSX()
? "__HIP,__fatbin"
: ".hipFatBinSegment";
Copy link
Author

Choose a reason for hiding this comment

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

These changes are mimicking the existing CUDA ternary operators / names. However, I'm not sure if this works already and if the names are good.
I'm not really sure how segments / sections work on macOS (although I'm quite familar with ELF and COFF).


ModuleIDSectionName = "__hip_module_id";
ModuleIDPrefix = "__hip_";
Expand Down Expand Up @@ -835,7 +839,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
Linkage,
/*Initializer=*/llvm::ConstantPointerNull::get(VoidPtrPtrTy),
"__hip_gpubin_handle");
if (Linkage == llvm::GlobalValue::LinkOnceAnyLinkage)
if (CGM.supportsCOMDAT() && (Linkage == llvm::GlobalValue::LinkOnceAnyLinkage))
Copy link
Author

Choose a reason for hiding this comment

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

This is what other code also does: Skip it if not supported. However, I'm not sure about the implications or if this breaks anything.

GpuBinaryHandle->setComdat(
CGM.getModule().getOrInsertComdat(GpuBinaryHandle->getName()));
GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign());
Expand Down
6 changes: 4 additions & 2 deletions clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ GlobalVariable *createFatbinDesc(Module &M, ArrayRef<char> Image, bool IsHIP) {

// Create the global string containing the fatbinary.
StringRef FatbinConstantSection =
IsHIP ? ".hip_fatbin"
IsHIP ? (Triple.isMacOSX() ? "__HIP,__hip_fatbin" : ".hip_fatbin")
: (Triple.isMacOSX() ? "__NV_CUDA,__nv_fatbin" : ".nv_fatbin");
auto *Data = ConstantDataArray::get(C, Image);
auto *Fatbin = new GlobalVariable(M, Data->getType(), /*isConstant*/ true,
Expand All @@ -308,7 +308,9 @@ GlobalVariable *createFatbinDesc(Module &M, ArrayRef<char> Image, bool IsHIP) {
Fatbin->setSection(FatbinConstantSection);

// Create the fatbinary wrapper
StringRef FatbinWrapperSection = IsHIP ? ".hipFatBinSegment"
StringRef FatbinWrapperSection = IsHIP
? Triple.isMacOSX() ? "__HIP,__fatbin"
: ".hipFatBinSegment"
: Triple.isMacOSX() ? "__NV_CUDA,__fatbin"
: ".nvFatBinSegment";
Constant *FatbinWrapper[] = {
Expand Down