[llvm] [GlobalISel] Optimized MatchData Handling (PR #92115)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue May 14 08:35:59 PDT 2024


jayfoad wrote:

> > One related thing I have never understood is, why is every combine split into a "match" function and an "apply" function? Aren't they always effectively called in tandem like this:
> > ```
> >   if (matchFunc(MatchData))
> >     applyFunc(MatchData);
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > ? Is there a use case for calling "match" without "apply"?
> 
> Matchers can fail/reject after doing further analysis (e.g. calling KnowBits), so the matcher is like an analysis part and the apply is the actual transform.

Right, but why not always compile the match+apply as a single C++ function like:
```
  bool matchAndApply(MI) {
    // match part goes here

    if (analysis failed)
      return false;

    // apply part goes here
    return true;
  }
```
Then you don't have to worry about managing the lifetime of matchdata objects outside of this function.

https://github.com/llvm/llvm-project/pull/92115


More information about the llvm-commits mailing list