1 /* -*- mesa-c++ -*- 2 * 3 * Copyright (c) 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_EXPORTINSTRUCTION_H 28 #define SFN_EXPORTINSTRUCTION_H 29 30 #include "sfn_instruction_base.h" 31 32 namespace r600 { 33 34 class WriteoutInstruction: public Instruction { 35 public: 36 void replace_values(const ValueSet& candidates, PValue new_value) override; gpr()37 const GPRVector& gpr() const {return m_value;} gpr_ptr()38 const GPRVector *gpr_ptr() const {return &m_value;} 39 protected: 40 WriteoutInstruction(instr_type t, const GPRVector& value); 41 private: 42 virtual void replace_values_child(const ValueSet& candidates, PValue new_value); 43 virtual void remap_registers_child(std::vector<rename_reg_pair>& map, 44 ValueMap& values); 45 46 GPRVector m_value; 47 }; 48 49 class ExportInstruction : public WriteoutInstruction { 50 public: 51 enum ExportType { 52 et_pixel, 53 et_pos, 54 et_param 55 }; 56 57 ExportInstruction(unsigned loc, const GPRVector& value, ExportType type); 58 void set_last(); 59 export_type()60 ExportType export_type() const {return m_type;} 61 location()62 unsigned location() const {return m_loc;} is_last_export()63 bool is_last_export() const {return m_is_last;} 64 65 void update_output_map(OutputRegisterMap& map) const; 66 accept(InstructionVisitor & visitor)67 bool accept(InstructionVisitor& visitor) override {return visitor.visit(*this);} accept(ConstInstructionVisitor & visitor)68 bool accept(ConstInstructionVisitor& visitor) const override {return visitor.visit(*this);} 69 70 71 private: 72 bool is_equal_to(const Instruction& lhs) const override; 73 void do_print(std::ostream& os) const override; 74 75 ExportType m_type; 76 unsigned m_loc; 77 bool m_is_last; 78 }; 79 80 class WriteScratchInstruction : public WriteoutInstruction { 81 public: 82 83 WriteScratchInstruction(unsigned loc, const GPRVector& value, int align, 84 int align_offset, int writemask); 85 WriteScratchInstruction(const PValue& address, const GPRVector& value, 86 int align, int align_offset, int writemask, int array_size); location()87 unsigned location() const {return m_loc;} 88 write_mask()89 int write_mask() const { return m_writemask;} address()90 int address() const { assert(m_address); return m_address->sel();} indirect()91 bool indirect() const { return !!m_address;} array_size()92 int array_size() const { return m_array_size;} 93 accept(InstructionVisitor & visitor)94 bool accept(InstructionVisitor& visitor) override {return visitor.visit(*this);} accept(ConstInstructionVisitor & visitor)95 bool accept(ConstInstructionVisitor& visitor) const override {return visitor.visit(*this);} 96 97 private: 98 bool is_equal_to(const Instruction& lhs) const override; 99 void do_print(std::ostream& os) const override; 100 101 void replace_values_child(const ValueSet& candidates, PValue new_value) override; 102 void remap_registers_child(std::vector<rename_reg_pair>& map, 103 ValueMap& values)override; 104 105 unsigned m_loc; 106 PValue m_address; 107 unsigned m_align; 108 unsigned m_align_offset; 109 unsigned m_writemask; 110 int m_array_size; 111 }; 112 113 114 class StreamOutIntruction: public WriteoutInstruction { 115 public: 116 StreamOutIntruction(const GPRVector& value, int num_components, 117 int array_base, int comp_mask, int out_buffer, 118 int stream); element_size()119 int element_size() const { return m_element_size;} burst_count()120 int burst_count() const { return m_burst_count;} array_base()121 int array_base() const { return m_array_base;} array_size()122 int array_size() const { return m_array_size;} comp_mask()123 int comp_mask() const { return m_writemask;} 124 unsigned op() const; 125 accept(InstructionVisitor & visitor)126 bool accept(InstructionVisitor& visitor) override {return visitor.visit(*this);} accept(ConstInstructionVisitor & visitor)127 bool accept(ConstInstructionVisitor& visitor) const override {return visitor.visit(*this);} 128 129 private: 130 bool is_equal_to(const Instruction& lhs) const override; 131 void do_print(std::ostream& os) const override; 132 133 int m_element_size; 134 int m_burst_count; 135 int m_array_base; 136 int m_array_size; 137 int m_writemask; 138 int m_output_buffer; 139 int m_stream; 140 }; 141 142 enum EMemWriteType { 143 mem_write = 0, 144 mem_write_ind = 1, 145 mem_write_ack = 2, 146 mem_write_ind_ack = 3, 147 }; 148 149 class MemRingOutIntruction: public WriteoutInstruction { 150 public: 151 152 MemRingOutIntruction(ECFOpCode ring, EMemWriteType type, 153 const GPRVector& value, unsigned base_addr, 154 unsigned ncomp, PValue m_index); 155 op()156 unsigned op() const{return m_ring_op;} 157 unsigned ncomp() const; addr()158 unsigned addr() const {return m_base_address;} type()159 EMemWriteType type() const {return m_type;} index_reg()160 unsigned index_reg() const {return m_index->sel();} array_base()161 unsigned array_base() const {return m_base_address; } 162 void replace_values_child(const ValueSet& candidates, PValue new_value) override; 163 void remap_registers_child(std::vector<rename_reg_pair>& map, 164 ValueMap& values) override; 165 void patch_ring(int stream, PValue index); 166 accept(InstructionVisitor & visitor)167 bool accept(InstructionVisitor& visitor) override {return visitor.visit(*this);} accept(ConstInstructionVisitor & visitor)168 bool accept(ConstInstructionVisitor& visitor) const override {return visitor.visit(*this);} 169 170 private: 171 bool is_equal_to(const Instruction& lhs) const override; 172 void do_print(std::ostream& os) const override; 173 174 ECFOpCode m_ring_op; 175 EMemWriteType m_type; 176 unsigned m_base_address; 177 unsigned m_num_comp; 178 PValue m_index; 179 180 }; 181 182 } 183 184 185 #endif // SFN_EXPORTINSTRUCTION_H