19ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt/*
29ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * Copyright © 2010 Intel Corporation
39ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt *
49ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
59ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * copy of this software and associated documentation files (the "Software"),
69ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * to deal in the Software without restriction, including without limitation
79ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * and/or sell copies of the Software, and to permit persons to whom the
99ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * Software is furnished to do so, subject to the following conditions:
109ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt *
119ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * The above copyright notice and this permission notice (including the next
129ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * paragraph) shall be included in all copies or substantial portions of the
139ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * Software.
149ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt *
159ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
169ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
179ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
189ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
199ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
209ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
219ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * IN THE SOFTWARE.
229ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt *
239ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * Authors:
249ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt *    Eric Anholt <eric@anholt.net>
259ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt *
269ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt */
279ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt
289ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtstruct ra_class;
299ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtstruct ra_regs;
309ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt
319ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt/* @{
329ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * Register set setup.
339ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt *
349ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * This should be done once at backend initializaion, as
359ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * ra_set_finalize is O(r^2*c^2).  The registers may be virtual
369ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * registers, such as aligned register pairs that conflict with the
379ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * two real registers from which they are composed.
389ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt */
39b972744c78e45928876ea781b9eeef09b3baf083Eric Anholtstruct ra_regs *ra_alloc_reg_set(void *mem_ctx, unsigned int count);
409ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtunsigned int ra_alloc_reg_class(struct ra_regs *regs);
419ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtvoid ra_add_reg_conflict(struct ra_regs *regs,
429ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt			 unsigned int r1, unsigned int r2);
43fa43477fa33c068915283d511b64e3d6470ccd73Eric Anholtvoid ra_add_transitive_reg_conflict(struct ra_regs *regs,
44fa43477fa33c068915283d511b64e3d6470ccd73Eric Anholt				    unsigned int base_reg, unsigned int reg);
459ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtvoid ra_class_add_reg(struct ra_regs *regs, unsigned int c, unsigned int reg);
469ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtvoid ra_set_finalize(struct ra_regs *regs);
479ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt/** @} */
489ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt
499ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt/** @{ Interference graph setup.
509ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt *
519ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * Each interference graph node is a virtual variable in the IL.  It
529ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * is up to the user to ra_set_node_class() for the virtual variable,
539ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * and compute live ranges and ra_node_interfere() between conflicting
549ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt * live ranges.
559ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt */
569ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtstruct ra_graph *ra_alloc_interference_graph(struct ra_regs *regs,
579ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt					     unsigned int count);
589ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtvoid ra_set_node_class(struct ra_graph *g, unsigned int n, unsigned int c);
599ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtvoid ra_add_node_interference(struct ra_graph *g,
609ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt			      unsigned int n1, unsigned int n2);
619ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt/** @} */
629ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt
639ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt/** @{ Graph-coloring register allocation */
649ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric AnholtGLboolean ra_simplify(struct ra_graph *g);
659ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtvoid ra_optimistic_color(struct ra_graph *g);
669ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric AnholtGLboolean ra_select(struct ra_graph *g);
679ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric AnholtGLboolean ra_allocate_no_spills(struct ra_graph *g);
689ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt
699ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholtunsigned int ra_get_node_reg(struct ra_graph *g, unsigned int n);
70e4a765ae2de21dada2e1206baf6b17a381193b42Tom Stellardvoid ra_set_node_reg(struct ra_graph * g, unsigned int n, unsigned int reg);
7199b2c8570ea6f46c6564681631f0e0750a0641ccEric Anholtvoid ra_set_node_spill_cost(struct ra_graph *g, unsigned int n, float cost);
7299b2c8570ea6f46c6564681631f0e0750a0641ccEric Anholtint ra_get_best_spill_node(struct ra_graph *g);
739ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt/** @} */
749ff90b7230cceb362c7e0fe1c3d5029b8cbfe6bdEric Anholt
75