• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2018 Intel Corporation
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_DEREF_H
25 #define NIR_DEREF_H
26 
27 #include "nir.h"
28 #include "nir_builder.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 typedef struct {
35    /** Short path so we can keep it on the stack most of the time. */
36    nir_deref_instr *_short_path[7];
37 
38    /** A null-terminated array view of a deref chain
39     *
40     * The first element of this array will be the variable dereference
41     * followed by every deref_instr on the path to the final one.  The last
42     * element in the array is a NULL pointer which acts as a terminator.
43     */
44    nir_deref_instr **path;
45 } nir_deref_path;
46 
47 typedef struct {
48    nir_deref_instr *instr;
49    nir_deref_path *_path;
50 } nir_deref_and_path;
51 
52 void nir_deref_path_init(nir_deref_path *path,
53                          nir_deref_instr *deref, void *mem_ctx);
54 void nir_deref_path_finish(nir_deref_path *path);
55 
56 unsigned nir_deref_instr_get_const_offset(nir_deref_instr *deref,
57                                           glsl_type_size_align_func size_align);
58 
59 nir_ssa_def *nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
60                                     glsl_type_size_align_func size_align);
61 
62 nir_deref_path *nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref);
63 
64 typedef enum {
65    nir_derefs_do_not_alias     = 0,
66    nir_derefs_equal_bit        = (1 << 0),
67    nir_derefs_may_alias_bit    = (1 << 1),
68    nir_derefs_a_contains_b_bit = (1 << 2),
69    nir_derefs_b_contains_a_bit = (1 << 3),
70 } nir_deref_compare_result;
71 
72 nir_deref_compare_result nir_compare_deref_paths(nir_deref_path *a_path, nir_deref_path *b_path);
73 nir_deref_compare_result nir_compare_derefs(nir_deref_instr *a, nir_deref_instr *b);
74 nir_deref_compare_result nir_compare_derefs_and_paths(void *mem_ctx,
75                                                       nir_deref_and_path *a,
76                                                       nir_deref_and_path *b);
77 
78 #ifdef __cplusplus
79 } /* extern "C" */
80 #endif
81 
82 #endif /* NIR_DEREF_H */
83