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_instructionvisitor.h" 31 #include "sfn_value_gpr.h" 32 #include "sfn_defines.h" 33 34 #include "gallium/drivers/r600/r600_isa.h" 35 #include <iostream> 36 #include <memory> 37 #include <vector> 38 #include <set> 39 40 namespace r600 { 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_atomic, 81 lds_read, 82 lds_write, 83 loop_begin, 84 loop_end, 85 loop_break, 86 loop_continue, 87 phi, 88 streamout, 89 ring, 90 emit_vtx, 91 mem_wr_scratch, 92 gds, 93 rat, 94 tf_write, 95 block, 96 unknown 97 }; 98 99 typedef std::shared_ptr<Instruction> Pointer; 100 101 friend bool operator == (const Instruction& lhs, const Instruction& rhs); 102 103 Instruction(instr_type t); 104 105 virtual ~Instruction(); 106 type()107 instr_type type() const { return m_type;} 108 109 void print(std::ostream& os) const; 110 111 virtual void replace_values(const ValueSet& candidates, PValue new_value); 112 113 void evalue_liveness(LiverangeEvaluator& eval) const; 114 115 void remap_registers(ValueRemapper& map); 116 117 virtual bool accept(InstructionVisitor& visitor) = 0; 118 virtual bool accept(ConstInstructionVisitor& visitor) const = 0; 119 120 protected: 121 122 void add_remappable_src_value(PValue *v); 123 void add_remappable_src_value(GPRVector *v); 124 void add_remappable_dst_value(PValue *v); 125 void add_remappable_dst_value(GPRVector *v); 126 127 private: 128 129 virtual void do_evalue_liveness(LiverangeEvaluator& eval) const; 130 131 virtual bool is_equal_to(const Instruction& lhs) const = 0; 132 133 instr_type m_type; 134 135 virtual void do_print(std::ostream& os) const = 0; 136 137 std::vector<PValue*> m_mappable_src_registers; 138 std::vector<GPRVector*> m_mappable_src_vectors; 139 std::vector<PValue*> m_mappable_dst_registers; 140 std::vector<GPRVector*> m_mappable_dst_vectors; 141 }; 142 143 using PInstruction=Instruction::Pointer; 144 145 inline std::ostream& operator << (std::ostream& os, const Instruction& instr) 146 { 147 instr.print(os); 148 return os; 149 } 150 151 bool operator == (const Instruction& lhs, const Instruction& rhs); 152 153 } 154 155 #endif 156