• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2014 Connor Abbott
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef NIR_INSTR_SET_H
25 #define NIR_INSTR_SET_H
26 
27 #include "nir.h"
28 
29 /**
30  * This file defines functions for creating, destroying, and manipulating an
31  * "instruction set," which is an abstraction for finding duplicate
32  * instructions using a hash set. Note that the question of whether an
33  * instruction is actually a duplicate (e.g. whether it has any side effects)
34  * is handled transparently. The user can pass any instruction to
35  * nir_instr_set_add_or_rewrite() and nir_instr_set_remove(), and if the
36  * instruction isn't safe to rewrite or isn't supported, it's silently
37  * removed.
38  */
39 
40 /*@{*/
41 
42 /** Creates an instruction set, using a given ralloc mem_ctx */
43 struct set *nir_instr_set_create(void *mem_ctx);
44 
45 /** Destroys an instruction set. */
46 void nir_instr_set_destroy(struct set *instr_set);
47 
48 /**
49  * Adds an instruction to an instruction set if it doesn't exist. If it
50  * does already exist, rewrites all uses of it to point to the other
51  * already-inserted instruction. Returns 'true' if the uses of the instruction
52  * were rewritten. Otherwise, replaces the already-inserted instruction
53  * with the new one.
54  *
55  * If cond_function() is given, only rewrites uses if
56  * cond_function(old_instr, new_instr) returns true.
57  */
58 bool nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr,
59                                   bool (*cond_function)(const nir_instr *a,
60                                                         const nir_instr *b));
61 
62 /**
63  * Removes an instruction from an instruction set, so that other instructions
64  * won't be merged with it.
65  */
66 void nir_instr_set_remove(struct set *instr_set, nir_instr *instr);
67 
68 /*@}*/
69 
70 #endif /* NIR_INSTR_SET_H */
71