Skip to content

Better ways to write GlobalISel combine "match" and "apply" functions #92410

@jayfoad

Description

@jayfoad

GlobalISel combines are written as separate "match" and "apply" functions but since #92239 we try to inline those into a single "match+apply" function. The two parts can share information in a couple of ways:

  1. You can declare a matchinfo (aka matchdata) type, an instance of which is populated by the match function and can be used by the apply function. This adds a bit of boilerplate to the tablegen declarations and is slightly less ergonomic than allowing the apply function to refer to the match function's locals directly.

  2. (Really a special case of 1) the match function can set the matchdata to be a lambda which is the real apply function. In tablegen the match function is declared to be Helper.applyBuildFn which is a helper that just invokes the lambda. This has the advantage that the apply function can refer to (captured) locals from the match function directly.

The problem with (2) is that when we try to compile the combined match+apply function, I think the compiler will not be able to see throughHelper.applyBuildFn in order to inline the real apply function.

I would like to find a way to write combines that is as ergonomic and as efficient as possible.

One idea I had was to invent some tablegen syntax that lets you declare a single combined match+apply function that you write explicitly in C++, instead of writing the two parts separately.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions