/*1* Copyright (C) 2019 Collabora, Ltd.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors (Collabora):23* Alyssa Rosenzweig <[email protected]>24*/2526#ifndef __LCRA_H27#define __LCRA_H2829#include <stdbool.h>30#include <stdint.h>3132struct lcra_state {33unsigned node_count;3435/* Alignment for node in log2(bytes)+1. Since alignment must be36* non-negative power-of-two, the elements are strictly positive37* integers. Zero is the sentinel for a missing node. In upper word,38* bound. */39unsigned *alignment;4041/* Linear constraints imposed. Nested array sized upfront, organized as42* linear[node_left][node_right]. That is, calculate indices as:43*44* Each element is itself a bit field denoting whether (c_j - c_i) bias45* is present or not, including negative biases.46*47* Note for Midgard, there are 16 components so the bias is in range48* [-15, 15] so encoded by 32-bit field. */4950uint32_t *linear;5152/* Per node max modulus constraints */53uint8_t *modulus;5455/* Classes allow nodes to be partitioned with a starting register.56* Classes cannot interfere; that is, they are true partitions in the57* usual sense of the word. class_count is the number of classes.58* class[] is indexed by a node to get the mapped class. class_start is59* biased to all solutions in the class. */6061unsigned class_count;62unsigned *class;63unsigned *class_start;64unsigned *class_size;65bool *class_disjoint;6667/* Before solving, forced registers; after solving, solutions. */68unsigned *solutions;6970/* For register spilling, the costs to spill nodes (as set by the user)71* are in spill_cost[], negative if a node is unspillable. Internally,72* spill_class specifies which class to spill (whichever class failed73* to allocate) */7475signed *spill_cost;76unsigned spill_class;77};7879struct lcra_state *80lcra_alloc_equations(81unsigned node_count, unsigned class_count);8283void84lcra_free(struct lcra_state *l);8586void87lcra_set_disjoint_class(struct lcra_state *l, unsigned c1, unsigned c2);8889void90lcra_set_alignment(struct lcra_state *l, unsigned node, unsigned align_log2, unsigned bound);9192void93lcra_restrict_range(struct lcra_state *l, unsigned node, unsigned len);9495void96lcra_add_node_interference(struct lcra_state *l, unsigned i, unsigned cmask_i, unsigned j, unsigned cmask_j);9798bool99lcra_solve(struct lcra_state *l);100101void102lcra_set_node_spill_cost(struct lcra_state *l, unsigned node, signed cost);103104signed105lcra_get_best_spill_node(struct lcra_state *l);106107#endif108109110