Skip to content
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
37 changes: 35 additions & 2 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5369,9 +5369,42 @@ void SemaSYCL::copyDeviceKernelAttrs(CXXMethodDecl *CallOperator) {
}
}

static std::unique_ptr<MangleContext>
createSYCLCrossABIMangleContext(ASTContext &Ctx) {
// For SYCL offload compilation with cross-ABI scenarios (e.g., Microsoft
// host + Itanium device on Windows+CUDA), use device mangling context to
// ensure consistent kernel name mangling between host and device.
const TargetInfo *AuxTarget = Ctx.getAuxTargetInfo();

// DEBUG: Log target information
llvm::errs() << "DEBUG createSYCLCrossABIMangleContext (FIXED LOGIC - SHOULD PASS):\n";
llvm::errs() << " Primary Target ABI: " << Ctx.getTargetInfo().getCXXABI().getKind() << "\n";
llvm::errs() << " Primary Target Triple: " << Ctx.getTargetInfo().getTriple().str() << "\n";
if (AuxTarget) {
llvm::errs() << " Aux Target ABI: " << AuxTarget->getCXXABI().getKind() << "\n";
llvm::errs() << " Aux Target Triple: " << AuxTarget->getTriple().str() << "\n";
} else {
llvm::errs() << " Aux Target: nullptr\n";
}
llvm::errs() << " Aux isMicrosoft: " << (AuxTarget ? AuxTarget->getCXXABI().isMicrosoft() : 0) << "\n";
llvm::errs() << " Primary isItaniumFamily: " << Ctx.getTargetInfo().getCXXABI().isItaniumFamily() << "\n";

// FIXED LOGIC: During device compilation, Primary = device (Itanium), Aux = host (Microsoft on Windows)
// Check if aux target (host) is Microsoft ABI and primary target (device) is Itanium
if (AuxTarget && AuxTarget->getCXXABI().isMicrosoft() &&
Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) {
llvm::errs() << " -> Using device mangling context (cross-ABI scenario)\n";
return std::unique_ptr<MangleContext>(
Ctx.createDeviceMangleContext(*AuxTarget));
}
// Same ABI or no offload target: use standard mangling
llvm::errs() << " -> Using standard mangling context\n";
return std::unique_ptr<MangleContext>(Ctx.createMangleContext());
}

void SemaSYCL::SetSYCLKernelNames() {
std::unique_ptr<MangleContext> MangleCtx(
getASTContext().createMangleContext());
createSYCLCrossABIMangleContext(getASTContext()));
// We assume the list of KernelDescs is the complete list of kernels needing
// to be rewritten.
for (const std::pair<const FunctionDecl *, FunctionDecl *> &Pair :
Expand Down Expand Up @@ -5890,7 +5923,7 @@ void SemaSYCL::finalizeFreeFunctionKernels() {
KernelObjVisitor Visitor{*this};
Visitor.VisitFunctionParameters(kernel, IntHeader);
std::unique_ptr<MangleContext> MangleCtx(
getASTContext().createMangleContext());
createSYCLCrossABIMangleContext(getASTContext()));
std::string Name, MangledName;
std::tie(Name, MangledName) =
constructFreeFunctionKernelName(kernel, *MangleCtx);
Expand Down
2 changes: 0 additions & 2 deletions sycl/test-e2e/Printf/mixed-address-space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for constant and generic address space can be used in the same module.
//
// UNSUPPORTED: target-amd
// XFAIL: cuda && windows
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/14733
// FIXME: Drop the test once generic AS support is considered stable and the
// dedicated constant AS overload of printf is removed from the library.
//
Expand Down
2 changes: 0 additions & 2 deletions sycl/test-e2e/Printf/percent-symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// [1]: https://en.cppreference.com/w/cpp/io/c/fprintf
//
// UNSUPPORTED: target-amd
// XFAIL: cuda && windows
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/14733
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out | FileCheck %s
// FIXME: Remove dedicated constant address space testing once generic AS
Expand Down
Loading