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, or 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. 53 */ 54 bool nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr); 55 56 /** 57 * Removes an instruction from an instruction set, so that other instructions 58 * won't be merged with it. 59 */ 60 void nir_instr_set_remove(struct set *instr_set, nir_instr *instr); 61 62 /*@}*/ 63 64 #endif /* NIR_INSTR_SET_H */ 65