This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Enable multiple instructions in patterns
Needs ReviewPublic

Authored by tmatheson on Jul 11 2023, 3:47 AM.

Details

Summary

Tablegen patterns for instrucion selection can generate multiple
instructions, but only if there is a data dependency between them so
that they can be expressed as a DAG. For example, something like:

(store (load %src), %dst)

For some patterns, we might want to generate a sequence of instructions
which do not have a data dependency. For example on AArch64 some atomic
instructions are implemented like this:

LDP %ptr
DMB ISH

Currently, sequences like this can not be selected with tablegen
patterns. To work around this we need to do custom selection, which has
several disadvantages compared to using patterns, such as needing
separate implementations for SelectionDAG and GlobalISel.

This patch adds basic support for tablegen Patterns which have a list
of output instructions. Pattern already has the ability to express this
but it looks like it was never implemented.

Multiple result instructions in an output pattern will be chained
together.

The GlobalISel pattern importer will skip these patterns for now. I
intend to implement this soon.

There are still some problems processing existing patterns for a few
backends. I am looking into these but don't expect them to require
major changes, and I would like feedback on the general approach of
this patch in the meantime.

Diff Detail

Event Timeline

tmatheson created this revision.Jul 11 2023, 3:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 3:47 AM
tmatheson requested review of this revision.Jul 11 2023, 3:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 3:47 AM
craig.topper added inline comments.Jul 11 2023, 10:17 AM
llvm/utils/TableGen/CodeGenDAGPatterns.cpp
3766

Add blank line between functions

4309

You can avoid the loop with something like

const std::vector<TypeSetByHwMode> Types = OutTree->getExtTypes();
FlatOutTypes.insert(FlatOutTypes.end(), Types.begin(), Types.end());
llvm/utils/TableGen/CodeGenDAGPatterns.h
926

const std::vector<TreePatternNodePtr> &

llvm/utils/TableGen/DAGISelEmitter.cpp
40

Can these changes be pre-committed?

71

Can the changes to this function be pre-commited?

llvm/utils/TableGen/DAGISelMatcherGen.cpp
796

Can you capitalize the variable namings per the coding standards?

945

Capitalize

1107

Drop curly braces