Skip to content

Conversation

maksimsab
Copy link
Contributor

@maksimsab maksimsab commented Jul 24, 2025

This patch fixes a handling of compile/link options encoded in images.
Also the patch fixes a redirection to backend compiler and offload
wrapper depending on the Triple (AOT or JIT).

This functionality is important for the support of the following clang
command line options in the New Offload Model:

  • -ftarget-compile-fast
  • -ftarget-export-symbols
  • -ftarget-register-alloc-mode

This patch fixes a handling of compile/link options encoded in images.
Also the patch fixes a redirection to backend compiler and offload
wrapper depending on the Triple (AOT or JIT).

This functionality is important for the support of the following clang
command line options in the New Offload Model:
* -ftarget-compile-fast
* -ftarget-export-symbols
* -ftarget-register-alloc-mode
@maksimsab maksimsab marked this pull request as ready for review July 31, 2025 11:54
@maksimsab maksimsab requested review from a team as code owners July 31, 2025 11:54
@maksimsab maksimsab requested a review from asudarsa July 31, 2025 11:54
@maksimsab
Copy link
Contributor Author

@asudarsa Friendly reminder :)

Failed tests aren't related to the patch. They will be fixed after rebasing.

StringRef CompileOptions = OB.getString("compile-opts");
StringRef LinkOptions = OB.getString("link-opts");
if (!CompileOptions.empty())
SYCLCompileOptionsFromImage = CompileOptions.str();
Copy link
Contributor

Choose a reason for hiding this comment

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

What if different files have different compile options? They will be overwritten, won't they? Is this possible?

if (!CompileOptions.empty())
SYCLCompileOptionsFromImage = CompileOptions.str();
if (!LinkOptions.empty())
SYCLLinkOptionsFromImage = LinkOptions.str();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same than compile options.

StringRef OptC = SYCLCompileOptionsFromImage;
OptC.split(CmdArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
OptC = Args.getLastArgValue(
OPT_sycl_backend_compile_options_EQ); // TODO: test this.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
OPT_sycl_backend_compile_options_EQ); // TODO: test this.
OPT_sycl_backend_compile_options_EQ); // TODO: test this.

Is the TODO still necessary?

if (Target.empty())
return createStringError(
inconvertibleErrorCode(),
"can't wrap SYCL image. -triple argument is missed.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"can't wrap SYCL image. -triple argument is missed.");
"can't wrap SYCL image. -triple argument is missing.");

@@ -0,0 +1,49 @@
// Test checks that compile options are transfared to backend in the New
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Test checks that compile options are transfared to backend in the New
// Test checks that compile options are transferred to backend in the New

// RUN: env SYCL_UR_TRACE=2 %{run} %t_with.out 2>&1 | FileCheck --check-prefix=CHECK-INTEL-GPU-WITH %s

// CHECK-INTEL-GPU-WITH: <--- urProgramBuild
// CHECK-INTEL-GPU-WITH-SAME: -igc_opts 'PartitionUnit=1,SubroutineThreshold=50000'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand this check. Can you explain why we expect this?

@@ -158,6 +158,10 @@ static SYCLBIN::BundleState SYCLBINState = SYCLBIN::BundleState::Input;

static SmallString<128> OffloadImageDumpDir;

static std::string SYCLCompileOptionsFromImage;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any specific reason why this is a std::string and not a StringRef?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Data-owning containers are more reliable against use-after-free bugs.

llvm::Triple T(Target);
bool isJIT = !(T.getSubArch() == llvm::Triple::SPIRSubArch_gen ||
T.getSubArch() == llvm::Triple::SPIRSubArch_x86_64);
SmallString<0> CompileOptions;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason this is not a StringRef instead, given that you are assigning a StringRef value in L1077?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mentioned StringRef refers to a temporary string and the data should be stored in a data-owning container.
In fact, my code contains the bug use-after-free and it should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants