Page MenuHomePhabricator

[MLIR][SPIRVToLLVM] Enhanced conversion for entry point ops

Authored by georgemitenkov on Oct 22 2020, 3:08 PM.



This patch introduces a new conversion pattern for spv.EntryPoint
and spv.ExecutionMode. Before, these ops were just erased. Now, an
approach is to encode the information from these ops in a global struct
variable of the following form:

struct {
  int32_t; // specify execution model
  int32_t; // specify execution mode
  // TODO: interface vars & mode's values

At the moment, no interface variables info is passed to the global, as
well as execution mode's optional value. This is a work in progress.

Diff Detail

Event Timeline

georgemitenkov created this revision.Oct 22 2020, 3:08 PM
georgemitenkov requested review of this revision.Oct 22 2020, 3:08 PM
mravishankar requested changes to this revision.Oct 26 2020, 10:25 AM

Curious what you need this information for?


This logic seems fairly involved. Probably doesnt need to be. You should be able to

  • get the current return value which is in the terminator, this is previousStruct
  • update the entry point as you have done here to get newStruct, except that setEntryPointInfo collects all the operations that uses previousStruct, say validUses
  • and then do previousStruct->replaceAllUsesExcept(newStruct, validUses).
This revision now requires changes to proceed.Oct 26 2020, 10:25 AM

Execution Mode ops may contain important information about the entry point, which we may want to preserve. An example can be LocalSize which indicates the work-group size. This can be reused when handling multi-threaded code conversion.

This patch is more of a skeleton to relate to during the discussion. Maybe it will be better to also have a post on the discourse to see what other people think. What do you think?

I will also address comments, thanks for the feedback!

mravishankar added inline comments.Nov 1 2020, 9:16 PM

COuldnt this all be simplified with setInsertionPoint(terminator)?

georgemitenkov marked 2 inline comments as done.

After some more thinking and further reading, I realise that entry point information is not really needed. However, it is important to keep execution mode info. This changes the conversion pattern as follows:

  • spv.EntryPoint is simply removed
  • Info from spv.ExecutionMode is used to create a global variable, which now looks like:
struct {
   int32_t executionMode;
   int32_t values[];          // optional values

This is a better approach in my opinion since we

  • Remove unnecessary complexity compared to previous version of the patch
  • Handle actually useful info - e.g. local sizes, etc.
  • We have a 1-to-1 op mapping: spv.ExecutionMode ->

Fixed a different global naming when the parent module does not have a name.

mravishankar accepted this revision.Mon, Nov 9, 1:05 PM

Seems like this changed to rely on having a single execution mode op per function. I think that is true. Approving this for landing.


nit : add '_' between {0} and {1}

This revision is now accepted and ready to land.Mon, Nov 9, 1:05 PM
This revision was automatically updated to reflect the committed changes.
georgemitenkov marked an inline comment as done.