1 /* 2 * Copyright (C) 2009 Nicolai Haehnle. 3 * Copyright 2010 Tom Stellard <tstellar@gmail.com> 4 * 5 * All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining 8 * a copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sublicense, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice (including the 16 * next paragraph) shall be included in all copies or substantial 17 * portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 23 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 * 27 */ 28 29 #ifndef RADEON_DATAFLOW_H 30 #define RADEON_DATAFLOW_H 31 32 #include "radeon_program_constants.h" 33 34 struct radeon_compiler; 35 struct rc_instruction; 36 struct rc_swizzle_caps; 37 struct rc_src_register; 38 struct rc_pair_instruction_arg; 39 struct rc_pair_instruction_source; 40 struct rc_pair_sub_instruction; 41 struct rc_compiler; 42 43 44 /** 45 * Help analyze and modify the register accesses of instructions. 46 */ 47 /*@{*/ 48 typedef void (*rc_read_write_chan_fn)(void * userdata, struct rc_instruction * inst, 49 rc_register_file file, unsigned int index, unsigned int chan); 50 void rc_for_all_reads_chan(struct rc_instruction * inst, rc_read_write_chan_fn cb, void * userdata); 51 void rc_for_all_writes_chan(struct rc_instruction * inst, rc_read_write_chan_fn cb, void * userdata); 52 53 typedef void (*rc_read_write_mask_fn)(void * userdata, struct rc_instruction * inst, 54 rc_register_file file, unsigned int index, unsigned int mask); 55 void rc_for_all_reads_mask(struct rc_instruction * inst, rc_read_write_mask_fn cb, void * userdata); 56 void rc_for_all_writes_mask(struct rc_instruction * inst, rc_read_write_mask_fn cb, void * userdata); 57 58 typedef void (*rc_read_src_fn)(void * userdata, struct rc_instruction * inst, 59 struct rc_src_register * src); 60 void rc_for_all_reads_src(struct rc_instruction * inst, rc_read_src_fn cb, 61 void * userdata); 62 63 typedef void (*rc_pair_read_arg_fn)(void * userdata, 64 struct rc_instruction * inst, struct rc_pair_instruction_arg * arg, 65 struct rc_pair_instruction_source * src); 66 void rc_pair_for_all_reads_arg(struct rc_instruction * inst, 67 rc_pair_read_arg_fn cb, void * userdata); 68 69 typedef void (*rc_remap_register_fn)(void * userdata, struct rc_instruction * inst, 70 rc_register_file * pfile, unsigned int * pindex); 71 void rc_remap_registers(struct rc_instruction * inst, rc_remap_register_fn cb, void * userdata); 72 /*@}*/ 73 74 struct rc_reader { 75 struct rc_instruction * Inst; 76 unsigned int WriteMask; 77 union { 78 struct { 79 struct rc_src_register * Src; 80 } I; 81 struct { 82 struct rc_pair_instruction_arg * Arg; 83 struct rc_pair_instruction_source * Src; 84 } P; 85 } U; 86 }; 87 88 struct rc_reader_data { 89 struct radeon_compiler * C; 90 91 unsigned int Abort; 92 unsigned int AbortOnRead; 93 unsigned int AbortOnWrite; 94 unsigned int LoopDepth; 95 unsigned int InElse; 96 struct rc_instruction * Writer; 97 98 unsigned int ReaderCount; 99 unsigned int ReadersReserved; 100 struct rc_reader * Readers; 101 102 /* If this flag is enabled, rc_get_readers will exit as soon possible 103 * after the Abort flag is set.*/ 104 unsigned int ExitOnAbort; 105 void * CbData; 106 }; 107 108 void rc_get_readers( 109 struct radeon_compiler * c, 110 struct rc_instruction * writer, 111 struct rc_reader_data * data, 112 rc_read_src_fn read_normal_cb, 113 rc_pair_read_arg_fn read_pair_cb, 114 rc_read_write_mask_fn write_cb); 115 116 void rc_get_readers_sub( 117 struct radeon_compiler * c, 118 struct rc_instruction * writer, 119 struct rc_pair_sub_instruction * sub_writer, 120 struct rc_reader_data * data, 121 rc_read_src_fn read_normal_cb, 122 rc_pair_read_arg_fn read_pair_cb, 123 rc_read_write_mask_fn write_cb); 124 /** 125 * Compiler passes based on dataflow analysis. 126 */ 127 /*@{*/ 128 typedef void (*rc_dataflow_mark_outputs_fn)(void * userdata, void * data, 129 void (*mark_fn)(void * data, unsigned int index, unsigned int mask)); 130 void rc_dataflow_deadcode(struct radeon_compiler * c, void *user); 131 void rc_dataflow_swizzles(struct radeon_compiler * c, void *user); 132 /*@}*/ 133 134 void rc_optimize(struct radeon_compiler * c, void *user); 135 void rc_inline_literals(struct radeon_compiler *c, void *user); 136 137 #endif /* RADEON_DATAFLOW_H */ 138