Eric Anholt | 9ff90b7 | 2010-09-27 12:34:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | * |
| 26 | */ |
| 27 | |
Brian Paul | f4435da | 2014-03-18 11:55:50 -0600 | [diff] [blame] | 28 | #include <stdbool.h> |
| 29 | |
Eric Anholt | 9ff90b7 | 2010-09-27 12:34:33 -0700 | [diff] [blame] | 30 | struct ra_class; |
| 31 | struct ra_regs; |
| 32 | |
| 33 | /* @{ |
| 34 | * Register set setup. |
| 35 | * |
| 36 | * This should be done once at backend initializaion, as |
| 37 | * ra_set_finalize is O(r^2*c^2). The registers may be virtual |
| 38 | * registers, such as aligned register pairs that conflict with the |
| 39 | * two real registers from which they are composed. |
| 40 | */ |
Eric Anholt | b972744 | 2012-01-12 12:51:34 -0800 | [diff] [blame] | 41 | struct ra_regs *ra_alloc_reg_set(void *mem_ctx, unsigned int count); |
Eric Anholt | b6e9b54 | 2012-11-30 16:34:09 -0800 | [diff] [blame] | 42 | void ra_set_allocate_round_robin(struct ra_regs *regs); |
Eric Anholt | 9ff90b7 | 2010-09-27 12:34:33 -0700 | [diff] [blame] | 43 | unsigned int ra_alloc_reg_class(struct ra_regs *regs); |
| 44 | void ra_add_reg_conflict(struct ra_regs *regs, |
| 45 | unsigned int r1, unsigned int r2); |
Eric Anholt | fa43477 | 2011-05-04 13:27:33 -0700 | [diff] [blame] | 46 | void ra_add_transitive_reg_conflict(struct ra_regs *regs, |
| 47 | unsigned int base_reg, unsigned int reg); |
Eric Anholt | 9ff90b7 | 2010-09-27 12:34:33 -0700 | [diff] [blame] | 48 | void ra_class_add_reg(struct ra_regs *regs, unsigned int c, unsigned int reg); |
Tom Stellard | e0f64a8 | 2012-09-03 10:43:45 -0400 | [diff] [blame] | 49 | void ra_set_num_conflicts(struct ra_regs *regs, unsigned int class_a, |
| 50 | unsigned int class_b, unsigned int num_conflicts); |
| 51 | void ra_set_finalize(struct ra_regs *regs, unsigned int **conflicts); |
Eric Anholt | 9ff90b7 | 2010-09-27 12:34:33 -0700 | [diff] [blame] | 52 | /** @} */ |
| 53 | |
| 54 | /** @{ Interference graph setup. |
| 55 | * |
| 56 | * Each interference graph node is a virtual variable in the IL. It |
| 57 | * is up to the user to ra_set_node_class() for the virtual variable, |
| 58 | * and compute live ranges and ra_node_interfere() between conflicting |
Connor Abbott | ec046bc | 2014-09-05 20:59:31 -0400 | [diff] [blame] | 59 | * live ranges. Note that an interference *must not* be added between |
| 60 | * two nodes if their classes haven't been assigned yet. The user |
| 61 | * should set the class of each node before building the interference |
| 62 | * graph. |
Eric Anholt | 9ff90b7 | 2010-09-27 12:34:33 -0700 | [diff] [blame] | 63 | */ |
| 64 | struct ra_graph *ra_alloc_interference_graph(struct ra_regs *regs, |
| 65 | unsigned int count); |
| 66 | void ra_set_node_class(struct ra_graph *g, unsigned int n, unsigned int c); |
| 67 | void ra_add_node_interference(struct ra_graph *g, |
| 68 | unsigned int n1, unsigned int n2); |
| 69 | /** @} */ |
| 70 | |
| 71 | /** @{ Graph-coloring register allocation */ |
Connor Abbott | 9a0b52e | 2014-07-31 18:57:20 -0700 | [diff] [blame] | 72 | bool ra_allocate(struct ra_graph *g); |
Eric Anholt | 9ff90b7 | 2010-09-27 12:34:33 -0700 | [diff] [blame] | 73 | |
| 74 | unsigned int ra_get_node_reg(struct ra_graph *g, unsigned int n); |
Tom Stellard | e4a765a | 2011-03-26 22:56:08 -0700 | [diff] [blame] | 75 | void ra_set_node_reg(struct ra_graph * g, unsigned int n, unsigned int reg); |
Eric Anholt | 99b2c85 | 2010-10-19 09:25:51 -0700 | [diff] [blame] | 76 | void ra_set_node_spill_cost(struct ra_graph *g, unsigned int n, float cost); |
| 77 | int ra_get_best_spill_node(struct ra_graph *g); |
Eric Anholt | 9ff90b7 | 2010-09-27 12:34:33 -0700 | [diff] [blame] | 78 | /** @} */ |
| 79 | |