Handle overlapping delayed operator sets in genmatch.
Genmatch now correctly handles overlapping operator sets in named matches, preventing duplicate case labels and ensuring generated code is valid.
The genmatch tool, which generates decision trees for pattern matching, previously mishandled overlapping sets of delayed operators, leading to duplicate case labels in generated code. This change partitions expression and function nodes into connected groups that share concrete switch cases, emitting each group’s cases only once and guarding matchers for partial overlaps. This resolves duplicate labels and slightly increases generated source size.
In Details
The genmatch tool processes .pd files to generate C code for the instruction scheduler's pattern matching. This commit addresses an issue where named matches using delayed operator iterators (e.g., (for cmp (ge gt) (match overlap (cmp:c @0 @1)))) could lead to duplicated case labels in the generated output if their operator sets partially overlapped. The fix involves partitioning sibling expression and function nodes into connected components based on shared concrete switch cases. Each component's cases are emitted once, and matchers are guarded if they only cover a subset of the comp…
- genmatch
- A GCC internal tool that translates pattern description files (
.pd) into C code used for instruction scheduling and pattern matching within the compiler backend. - operator iterators
- In
genmatch, these represent sets of operations that a match can apply to. 'Delayed' iterators are expanded later in the process. - decision tree
- A control flow structure used in compilers to efficiently select the best code pattern or instruction for a given intermediate representation.
genmatchgenerates C code implementing these trees. - switch cases
- Labels within a C
switchstatement that correspond to specific values. In the context ofgenmatch, these often represent different instruction or expression types. - GIMPLE
- GCC's internal three-address code representation, used after the GENERIC stage and before or during optimization passes.
- GENERIC
- GCC's internal representation of code after parsing, before GIMPLE. It's a higher-level, more structured representation than GIMPLE.