1*61046927SAndroid Build Coastguard Worker /* 2*61046927SAndroid Build Coastguard Worker * Copyright (C) 2019 Collabora, Ltd. 3*61046927SAndroid Build Coastguard Worker * 4*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a 5*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"), 6*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation 7*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the 9*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions: 10*61046927SAndroid Build Coastguard Worker * 11*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next 12*61046927SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the 13*61046927SAndroid Build Coastguard Worker * Software. 14*61046927SAndroid Build Coastguard Worker * 15*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16*61046927SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19*61046927SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20*61046927SAndroid Build Coastguard Worker * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21*61046927SAndroid Build Coastguard Worker * SOFTWARE. 22*61046927SAndroid Build Coastguard Worker * 23*61046927SAndroid Build Coastguard Worker * Authors (Collabora): 24*61046927SAndroid Build Coastguard Worker * Alyssa Rosenzweig <[email protected]> 25*61046927SAndroid Build Coastguard Worker */ 26*61046927SAndroid Build Coastguard Worker 27*61046927SAndroid Build Coastguard Worker #ifndef __LCRA_H 28*61046927SAndroid Build Coastguard Worker #define __LCRA_H 29*61046927SAndroid Build Coastguard Worker 30*61046927SAndroid Build Coastguard Worker #include <stdbool.h> 31*61046927SAndroid Build Coastguard Worker #include <stdint.h> 32*61046927SAndroid Build Coastguard Worker 33*61046927SAndroid Build Coastguard Worker struct lcra_state { 34*61046927SAndroid Build Coastguard Worker unsigned node_count; 35*61046927SAndroid Build Coastguard Worker 36*61046927SAndroid Build Coastguard Worker /* Alignment for node in log2(bytes)+1. Since alignment must be 37*61046927SAndroid Build Coastguard Worker * non-negative power-of-two, the elements are strictly positive 38*61046927SAndroid Build Coastguard Worker * integers. Zero is the sentinel for a missing node. In upper word, 39*61046927SAndroid Build Coastguard Worker * bound. */ 40*61046927SAndroid Build Coastguard Worker unsigned *alignment; 41*61046927SAndroid Build Coastguard Worker 42*61046927SAndroid Build Coastguard Worker /* Linear constraints imposed. Nested array sized upfront, organized as 43*61046927SAndroid Build Coastguard Worker * linear[node_left][node_right]. That is, calculate indices as: 44*61046927SAndroid Build Coastguard Worker * 45*61046927SAndroid Build Coastguard Worker * Each element is itself a bit field denoting whether (c_j - c_i) bias 46*61046927SAndroid Build Coastguard Worker * is present or not, including negative biases. 47*61046927SAndroid Build Coastguard Worker * 48*61046927SAndroid Build Coastguard Worker * Note for Midgard, there are 16 components so the bias is in range 49*61046927SAndroid Build Coastguard Worker * [-15, 15] so encoded by 32-bit field. */ 50*61046927SAndroid Build Coastguard Worker 51*61046927SAndroid Build Coastguard Worker uint32_t *linear; 52*61046927SAndroid Build Coastguard Worker 53*61046927SAndroid Build Coastguard Worker /* Per node max modulus constraints */ 54*61046927SAndroid Build Coastguard Worker uint8_t *modulus; 55*61046927SAndroid Build Coastguard Worker 56*61046927SAndroid Build Coastguard Worker /* Classes allow nodes to be partitioned with a starting register. 57*61046927SAndroid Build Coastguard Worker * Classes cannot interfere; that is, they are true partitions in the 58*61046927SAndroid Build Coastguard Worker * usual sense of the word. class_count is the number of classes. 59*61046927SAndroid Build Coastguard Worker * class[] is indexed by a node to get the mapped class. class_start is 60*61046927SAndroid Build Coastguard Worker * biased to all solutions in the class. */ 61*61046927SAndroid Build Coastguard Worker 62*61046927SAndroid Build Coastguard Worker unsigned class_count; 63*61046927SAndroid Build Coastguard Worker unsigned *class; 64*61046927SAndroid Build Coastguard Worker unsigned *class_start; 65*61046927SAndroid Build Coastguard Worker unsigned *class_size; 66*61046927SAndroid Build Coastguard Worker bool *class_disjoint; 67*61046927SAndroid Build Coastguard Worker 68*61046927SAndroid Build Coastguard Worker /* Before solving, forced registers; after solving, solutions. */ 69*61046927SAndroid Build Coastguard Worker unsigned *solutions; 70*61046927SAndroid Build Coastguard Worker 71*61046927SAndroid Build Coastguard Worker /* For register spilling, the costs to spill nodes (as set by the user) 72*61046927SAndroid Build Coastguard Worker * are in spill_cost[], negative if a node is unspillable. Internally, 73*61046927SAndroid Build Coastguard Worker * spill_class specifies which class to spill (whichever class failed 74*61046927SAndroid Build Coastguard Worker * to allocate) */ 75*61046927SAndroid Build Coastguard Worker 76*61046927SAndroid Build Coastguard Worker signed *spill_cost; 77*61046927SAndroid Build Coastguard Worker unsigned spill_class; 78*61046927SAndroid Build Coastguard Worker }; 79*61046927SAndroid Build Coastguard Worker 80*61046927SAndroid Build Coastguard Worker struct lcra_state *lcra_alloc_equations(unsigned node_count, 81*61046927SAndroid Build Coastguard Worker unsigned class_count); 82*61046927SAndroid Build Coastguard Worker 83*61046927SAndroid Build Coastguard Worker void lcra_free(struct lcra_state *l); 84*61046927SAndroid Build Coastguard Worker 85*61046927SAndroid Build Coastguard Worker void lcra_set_disjoint_class(struct lcra_state *l, unsigned c1, unsigned c2); 86*61046927SAndroid Build Coastguard Worker 87*61046927SAndroid Build Coastguard Worker void lcra_set_alignment(struct lcra_state *l, unsigned node, 88*61046927SAndroid Build Coastguard Worker unsigned align_log2, unsigned bound); 89*61046927SAndroid Build Coastguard Worker 90*61046927SAndroid Build Coastguard Worker void lcra_restrict_range(struct lcra_state *l, unsigned node, unsigned len); 91*61046927SAndroid Build Coastguard Worker 92*61046927SAndroid Build Coastguard Worker void lcra_add_node_interference(struct lcra_state *l, unsigned i, 93*61046927SAndroid Build Coastguard Worker unsigned cmask_i, unsigned j, unsigned cmask_j); 94*61046927SAndroid Build Coastguard Worker 95*61046927SAndroid Build Coastguard Worker bool lcra_solve(struct lcra_state *l); 96*61046927SAndroid Build Coastguard Worker 97*61046927SAndroid Build Coastguard Worker void lcra_set_node_spill_cost(struct lcra_state *l, unsigned node, signed cost); 98*61046927SAndroid Build Coastguard Worker 99*61046927SAndroid Build Coastguard Worker signed lcra_get_best_spill_node(struct lcra_state *l); 100*61046927SAndroid Build Coastguard Worker 101*61046927SAndroid Build Coastguard Worker #endif 102