Merge commit mesa-public/master into vulkan
[mesa.git] / src / compiler / nir / nir_instr_set.h
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 #pragma once
25
26 #include "nir.h"
27
28 /**
29 * This file defines functions for creating, destroying, and manipulating an
30 * "instruction set," which is an abstraction for finding duplicate
31 * instructions using a hash set. Note that the question of whether an
32 * instruction is actually a duplicate (e.g. whether it has any side effects)
33 * is handled transparently. The user can pass any instruction to
34 * nir_instr_set_add_or_rewrite() and nir_instr_set_remove(), and if the
35 * instruction isn't safe to rewrite or isn't supported, it's silently
36 * removed.
37 */
38
39 /*@{*/
40
41 /** Creates an instruction set, using a given ralloc mem_ctx */
42 struct set *nir_instr_set_create(void *mem_ctx);
43
44 /** Destroys an instruction set. */
45 void nir_instr_set_destroy(struct set *instr_set);
46
47 /**
48 * Adds an instruction to an instruction set if it doesn't exist, or if it
49 * does already exist, rewrites all uses of it to point to the other
50 * already-inserted instruction. Returns 'true' if the uses of the instruction
51 * were rewritten.
52 */
53 bool nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr);
54
55 /**
56 * Removes an instruction from an instruction set, so that other instructions
57 * won't be merged with it.
58 */
59 void nir_instr_set_remove(struct set *instr_set, nir_instr *instr);
60
61 /*@}*/
62