• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright © 2024 Igalia S.L.
2# SPDX-License-Identifier: MIT
3
4
5import argparse
6import sys
7
8
9# Inverse DeMorgan's laws to facilitate folding iand/ior into braa/brao. Only
10# apply if the inot is only used by branch conditions. Otherwise, it would just
11# end-up generating more instructions.
12cond_lowering = [
13    (('inot(is_only_used_by_if)', ('iand', 'a', 'b')),
14     ('ior', ('inot', 'a'), ('inot', 'b'))),
15    (('inot(is_only_used_by_if)', ('ior', 'a', 'b')),
16     ('iand', ('inot', 'a'), ('inot', 'b'))),
17]
18
19
20def main():
21    parser = argparse.ArgumentParser()
22    parser.add_argument('-p', '--import-path', required=True)
23    args = parser.parse_args()
24    sys.path.insert(0, args.import_path)
25    run()
26
27
28def run():
29    import nir_algebraic  # pylint: disable=import-error
30
31    print('#include "ir3_nir.h"')
32    print(nir_algebraic.AlgebraicPass("ir3_nir_opt_branch_and_or_not",
33                                      cond_lowering).render())
34
35
36if __name__ == '__main__':
37    main()
38