Skip to content

LLVM-16: Add macOS support #1

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

Draft
wants to merge 4 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
14 changes: 8 additions & 6 deletions clang/lib/Driver/ToolChains/HIPSPV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(
}

// Emit SPIR-V binary.

llvm::opt::ArgStringList TrArgs{"--spirv-max-version=1.1",
// We need 1.2 when using warp-level primitivies via sub group extensions.
// Strictly put we'd need 1.3 for the standard non-extension shuffle
// operations, but it's not supported by any target yet.
llvm::opt::ArgStringList TrArgs{"--spirv-max-version=1.2",
"--spirv-ext=+all"};
InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile, "");
SPIRV::constructTranslateCommand(C, *this, JA, Output, TrInput, TrArgs);
Expand Down Expand Up @@ -285,8 +287,8 @@ VersionTuple HIPSPVToolChain::computeMSVCVersion(const Driver *D,
void HIPSPVToolChain::adjustDebugInfoKind(
codegenoptions::DebugInfoKind &DebugInfoKind,
const llvm::opt::ArgList &Args) const {
// Debug info generation is disabled for SPIRV-LLVM-Translator
// which currently aborts on the presence of DW_OP_LLVM_convert.
// TODO: Enable debug info when the SPIR-V backend arrives.
DebugInfoKind = codegenoptions::NoDebugInfo;

// Restrict the debug info to a kind compatible with llvm-spirv.
if (DebugInfoKind > codegenoptions::DebugLineTablesOnly)
DebugInfoKind = codegenoptions::DebugLineTablesOnly;
}
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