Skip to content

General system for marking operations as unique per node #1510

Description

@haved

I think it makes sense to define a clear way for operations to mark themselves as "unique per invocation".

This comes up after considering the following:

  • In Improve check in NodeHoisting transformation #1422, @phate requests more precise information about which operations it is safe to hoist
  • Add IOState to MallocOperation #1492 added an IOState to the MallocOperation to prevent hoisting. The same issue technically also applies to AllocaOperation, but I would really like to avoid sequentializing allocas with IO.
  • The AllocaOperation and MallocOperation has hacky implementations of operator ==() to prevent Common Node Elimination from collapsing distinct alloca nodes into a single node.

What I mean by "unique per invocation" is that two instances of the operation produce unique results, even if they take identical inputs. This is what effectively happens with alloca and malloc. Marking an operation as unique would disable Common Node Elimination, and prevent hoisting out of loops (as each iteration has its own invocation of the operation). Hoisting out of gamma nodes is still fine, assuming all regions contain the operation, as the total number of invocations does not change.

The only other way I see to represent this in current RVSDG is to route states through the operations, but this has the downside of also forcing the operations to be sequentialized. The state also needs to come from somewhere, and it should not be the IO state. Routing states also entail special handling when doing Dead Node Elimination, as the state should not be able to keep the operation alive.

What do you think about having such a "trait" on operations, @caleridas? In practice it would be a virtual method on the Operation class.

Is there a name for operations that only have the side-effect of producing a unique result each time, but otherwise being "stateless"?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions