Path: blob/21.2-virgl/src/compiler/nir/nir_instr_set.h
4549 views
/*1* Copyright © 2014 Connor Abbott2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef NIR_INSTR_SET_H24#define NIR_INSTR_SET_H2526#include "nir.h"2728/**29* This file defines functions for creating, destroying, and manipulating an30* "instruction set," which is an abstraction for finding duplicate31* instructions using a hash set. Note that the question of whether an32* instruction is actually a duplicate (e.g. whether it has any side effects)33* is handled transparently. The user can pass any instruction to34* nir_instr_set_add_or_rewrite() and nir_instr_set_remove(), and if the35* instruction isn't safe to rewrite or isn't supported, it's silently36* removed.37*/3839/*@{*/4041/** Creates an instruction set, using a given ralloc mem_ctx */42struct set *nir_instr_set_create(void *mem_ctx);4344/** Destroys an instruction set. */45void nir_instr_set_destroy(struct set *instr_set);4647/**48* Adds an instruction to an instruction set if it doesn't exist. If it49* does already exist, rewrites all uses of it to point to the other50* already-inserted instruction. Returns 'true' if the uses of the instruction51* were rewritten. Otherwise, replaces the already-inserted instruction52* with the new one.53*54* If cond_function() is given, only rewrites uses if55* cond_function(old_instr, new_instr) returns true.56*/57bool nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr,58bool (*cond_function)(const nir_instr *a,59const nir_instr *b));6061/**62* Removes an instruction from an instruction set, so that other instructions63* won't be merged with it.64*/65void nir_instr_set_remove(struct set *instr_set, nir_instr *instr);6667/*@}*/6869#endif /* NIR_INSTR_SET_H */707172