r600/sfn: rework getting a vector and uniforms from the value pool
[mesa.git] / src / gallium / drivers / r600 / sfn / sfn_instruction_base.h
1 /* -*- mesa-c++ -*-
2 *
3 * Copyright (c) 2018-2019 Collabora LTD
4 *
5 * Author: Gert Wollny <gert.wollny@collabora.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 #ifndef sfn_r600_instr_h
28 #define sfn_r600_instr_h
29
30 #include "sfn_value_gpr.h"
31 #include "sfn_defines.h"
32
33 #include "gallium/drivers/r600/r600_isa.h"
34 #include <iostream>
35 #include <memory>
36 #include <vector>
37 #include <set>
38
39 namespace r600 {
40
41
42 struct rename_reg_pair {
43 bool valid;
44 bool used;
45 int new_reg;
46 };
47
48 class LiverangeEvaluator;
49 class ValueMap;
50
51
52 class ValueRemapper {
53 public:
54 ValueRemapper(std::vector<rename_reg_pair>& m,
55 ValueMap& values);
56
57 void remap(PValue& v);
58 void remap(GPRVector& v);
59 private:
60 PValue remap_one_registers(PValue& reg);
61
62 std::vector<rename_reg_pair>& m_map;
63 ValueMap& m_values;
64 };
65
66
67 using OutputRegisterMap = std::map<unsigned, const GPRVector *>;
68
69 class Instruction {
70 public:
71 enum instr_type {
72 alu,
73 exprt,
74 tex,
75 vtx,
76 wait_ack,
77 cond_if,
78 cond_else,
79 cond_endif,
80 lds_read,
81 lds_write,
82 loop_begin,
83 loop_end,
84 loop_break,
85 loop_continue,
86 phi,
87 streamout,
88 ring,
89 emit_vtx,
90 mem_wr_scratch,
91 gds,
92 rat,
93 tf_write,
94 block,
95 unknown
96 };
97
98 typedef std::shared_ptr<Instruction> Pointer;
99
100 friend bool operator == (const Instruction& lhs, const Instruction& rhs);
101
102 Instruction(instr_type t);
103
104 virtual ~Instruction();
105
106 instr_type type() const { return m_type;}
107
108 void print(std::ostream& os) const;
109
110 virtual void replace_values(const ValueSet& candiates, PValue new_value);
111
112 void evalue_liveness(LiverangeEvaluator& eval) const;
113
114 void remap_registers(ValueRemapper& map);
115
116 protected:
117
118 void add_remappable_src_value(PValue *v);
119 void add_remappable_src_value(GPRVector *v);
120 void add_remappable_dst_value(PValue *v);
121 void add_remappable_dst_value(GPRVector *v);
122
123 private:
124
125 virtual void do_evalue_liveness(LiverangeEvaluator& eval) const;
126
127 virtual bool is_equal_to(const Instruction& lhs) const = 0;
128
129 instr_type m_type;
130
131 virtual void do_print(std::ostream& os) const = 0;
132
133 std::vector<PValue*> m_mappable_src_registers;
134 std::vector<GPRVector*> m_mappable_src_vectors;
135 std::vector<PValue*> m_mappable_dst_registers;
136 std::vector<GPRVector*> m_mappable_dst_vectors;
137 };
138
139 using PInstruction=Instruction::Pointer;
140
141 inline std::ostream& operator << (std::ostream& os, const Instruction& instr)
142 {
143 instr.print(os);
144 return os;
145 }
146
147 bool operator == (const Instruction& lhs, const Instruction& rhs);
148
149 }
150
151 #endif