Skip to content

Conversation

maksimsab
Copy link
Contributor

This change allows later reuse of specialization constant's processing in the New Offloading Model and sycl-jit.

…st-link to SYCLPostLink library.

This change allows later reuse in the New Offloading Model and sycl-jit.
@maksimsab maksimsab requested a review from a team as a code owner June 17, 2025 12:25
@maksimsab
Copy link
Contributor Author

The interface of a functionhandleSpecializationConstants is controversial. It allows to invoke the function in the following manner if you don't need to generate new modules with spec constants replaced by default values:

SmallVector<ModuleDesc> MDs;
Modified |= handleSpecializationConstants(MDs, Mode);

If you have a better alternative for the function's interface let me know.

Copy link
Contributor

@maarquitos14 maarquitos14 left a comment

Choose a reason for hiding this comment

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

Looks good overall, just a few nits.

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

Overall looks good. Minor changes requested.

Thanks

@maksimsab
Copy link
Contributor Author

Hi @intel/dpcpp-tools-reviewers

Could, please, someone take a look at this PR?


std::optional<SpecConstantsPass::HandlingMode> SCMode;
if (SpecConstLower.getNumOccurrences() > 0)
SCMode = SpecConstLower == SC_NATIVE_MODE
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a default value we can use instead of having it being optional? maybe like not_specified or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be better to have not_specified value? We will have to check that value and return errors deeper in lowering.

Copy link
Contributor

Choose a reason for hiding this comment

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

personally i would prefer that

Copy link
Contributor Author

@maksimsab maksimsab Oct 6, 2025

Choose a reason for hiding this comment

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

What is the expected behaviour in the following snippet then would be?

  ModulePassManager MPM;
  ModuleAnalysisManager MAM;
  SpecConstantsPass SCP(SpecConstantsPass::HandlingMode::not_specified);
  MAM.registerPass([&] { return PassInstrumentationAnalysis(); });
  MPM.addPass(std::move(SCP));

  PreservedAnalyses Res = MPM.run(NewMD->getModule(), MAM);

Copy link
Contributor

Choose a reason for hiding this comment

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

@sarnex , @maksimsab , I guess the answer to Nick's question in this thread is: there is no default value currently that can be used instead of having SCMode to be optional.

This PR is about extracting existing spec const processing to a library. Updating SpecConstantsPass and introducing new HandlingMode is out of scope of this PR. We can consider it as a future refactoring, but it should not hold this PR from merging.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's not worth blocking the PR over, but i'm not sure i understand, the old code does not seem to use optional for the handling mode, so im wondering why we need it in this NFC change

Copy link
Contributor

Choose a reason for hiding this comment

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

That is a good question! The reason is how logic was split between sycl-post-link and SYCLPostLink library.

The info about spec const mode comes from cl::opt option in sycl-post-link tool, which is:
cl::opt<SpecConstLowerMode> SpecConstLower and is cl::Optional.

Since in the old code SpecConstLower is global for that file and the logic which depends on its optionality is in the same file, we did not need additional optional variable. So there is code like:

if (SpecConstLower.getNumOccurrences() == 0)
    return false;

So, semantically, old code used optional, just not std::optional.

In the new code, we need to keep optional behavior and pass this information somehow to the library function. It seems using std::optional is the closest way to keep the original semantics.

The alternative (to keep the code as close to the original as possible) that I see is to pass cl::opt<SpecConstLowerMode> SpecConstLower as parameter, instead of std::optional<SpecConstantsPass::HandlingMode> Mode.
That doesn't look better to me...

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating SpecConstantsPass and introducing new HandlingMode is out of scope of this PR.

That is correct. Introducing default value would lead to many changes in SpecConstsPass which worth a separate patch.

Copy link
Contributor

@sarnex sarnex Oct 7, 2025

Choose a reason for hiding this comment

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

i agree that calling getNumOccurences() == 0 is similar to checking if the optional is empty. so yeah feel free to merge the pr and address this in a follow up

Copy link
Contributor

@maarquitos14 maarquitos14 left a comment

Choose a reason for hiding this comment

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

Is this already covered by current testing or should we add new testing?

@maksimsab
Copy link
Contributor Author

@maarquitos14 Yes, we have plenty of sycl-post-link's testing. Later this testing should be migrated for New Offloading Model's tools.

Copy link
Contributor

github-actions bot commented Oct 6, 2025

@intel/llvm-gatekeepers please consider merging

Copy link
Contributor

@YuriPlyakhin YuriPlyakhin left a comment

Choose a reason for hiding this comment

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

LGTM

@maksimsab
Copy link
Contributor Author

@intel/llvm-gatekeepers Can we merge that please?

@uditagarwal97 uditagarwal97 merged commit a3132c1 into intel:sycl Oct 9, 2025
29 checks passed
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.

6 participants