Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/*
2
 * Copyright © 2014 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
 * Authors:
24
 *    Jason Ekstrand (jason@jlekstrand.net)
25
 *
26
 */
27
 
28
#ifndef _NIR_SEARCH_
29
#define _NIR_SEARCH_
30
 
31
#include "nir.h"
32
 
33
#define NIR_SEARCH_MAX_VARIABLES 16
34
 
35
typedef enum {
36
   nir_search_value_expression,
37
   nir_search_value_variable,
38
   nir_search_value_constant,
39
} nir_search_value_type;
40
 
41
typedef struct {
42
   nir_search_value_type type;
43
} nir_search_value;
44
 
45
typedef struct {
46
   nir_search_value value;
47
 
48
   /** The variable index;  Must be less than NIR_SEARCH_MAX_VARIABLES */
49
   unsigned variable;
50
 
51
   /** Indicates that the given variable must be a constant
52
    *
53
    * This is only alloed in search expressions and indicates that the
54
    * given variable is only allowed to match constant values.
55
    */
56
   bool is_constant;
57
 
58
   /** Indicates that the given variable must have a certain type
59
    *
60
    * This is only allowed in search expressions and indicates that the
61
    * given variable is only allowed to match values that come from an ALU
62
    * instruction with the given output type.  A type of nir_type_void
63
    * means it can match any type.
64
    *
65
    * Note: A variable that is both constant and has a non-void type will
66
    * never match anything.
67
    */
68
   nir_alu_type type;
69
} nir_search_variable;
70
 
71
typedef struct {
72
   nir_search_value value;
73
 
74
   union {
75
      uint32_t u;
76
      int32_t i;
77
      float f;
78
   } data;
79
} nir_search_constant;
80
 
81
typedef struct {
82
   nir_search_value value;
83
 
84
   nir_op opcode;
85
   const nir_search_value *srcs[4];
86
} nir_search_expression;
87
 
88
NIR_DEFINE_CAST(nir_search_value_as_variable, nir_search_value,
89
                nir_search_variable, value)
90
NIR_DEFINE_CAST(nir_search_value_as_constant, nir_search_value,
91
                nir_search_constant, value)
92
NIR_DEFINE_CAST(nir_search_value_as_expression, nir_search_value,
93
                nir_search_expression, value)
94
 
95
nir_alu_instr *
96
nir_replace_instr(nir_alu_instr *instr, const nir_search_expression *search,
97
                  const nir_search_value *replace, void *mem_ctx);
98
 
99
#endif /* _NIR_SEARCH_ */