genattrtab: Efficiently build IOR trees for attribute value lists
Optimizes the construction of boolean logic trees for attribute values, reducing build times for complex configurations.
This commit refactors genattrtab’s check_attr_test function to build the disjunctive normal form (IOR tree) for attribute value lists more efficiently. Instead of iteratively adding values to a tree, which previously had a quartic cost, it now directly constructs the tree by keeping unique values and nesting. This significantly speeds up genattrtab for targets with long attribute value lists, such as s390x and ARM.
In Details
The check_attr_test function in genattrtab.cc is responsible for converting attribute tests like (eq_attr "type" "a,b,c") into IOR trees. The previous implementation using insert_right_side led to O(N^4) complexity for lists of N values. This patch directly builds the tree, preserving the first occurrence of each value and nesting, resulting in O(N) construction. This is crucial for complex scheduling descriptions with long value lists.
- genattrtab
- A GCC internal tool that generates attribute tables used by various backends for instruction selection and scheduling.
- IOR tree
- An internal representation of a boolean expression, specifically representing the logical OR operation between different conditions or tests.
- eq_attr
- An internal GCC construct representing an equality test for a specific attribute.