2 * Copyright © 2010 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
28 #ifndef REGISTER_ALLOCATE_H
29 #define REGISTER_ALLOCATE_H
32 #include "util/bitset.h"
45 * This should be done once at backend initializaion, as
46 * ra_set_finalize is O(r^2*c^2). The registers may be virtual
47 * registers, such as aligned register pairs that conflict with the
48 * two real registers from which they are composed.
50 struct ra_regs
*ra_alloc_reg_set(void *mem_ctx
, unsigned int count
,
51 bool need_conflict_lists
);
52 void ra_set_allocate_round_robin(struct ra_regs
*regs
);
53 unsigned int ra_alloc_reg_class(struct ra_regs
*regs
);
54 void ra_add_reg_conflict(struct ra_regs
*regs
,
55 unsigned int r1
, unsigned int r2
);
56 void ra_add_transitive_reg_conflict(struct ra_regs
*regs
,
57 unsigned int base_reg
, unsigned int reg
);
60 ra_add_transitive_reg_pair_conflict(struct ra_regs
*regs
,
61 unsigned int base_reg
, unsigned int reg0
, unsigned int reg1
);
63 void ra_make_reg_conflicts_transitive(struct ra_regs
*regs
, unsigned int reg
);
64 void ra_class_add_reg(struct ra_regs
*regs
, unsigned int c
, unsigned int reg
);
65 void ra_set_num_conflicts(struct ra_regs
*regs
, unsigned int class_a
,
66 unsigned int class_b
, unsigned int num_conflicts
);
67 void ra_set_finalize(struct ra_regs
*regs
, unsigned int **conflicts
);
70 /** @{ Interference graph setup.
72 * Each interference graph node is a virtual variable in the IL. It
73 * is up to the user to ra_set_node_class() for the virtual variable,
74 * and compute live ranges and ra_node_interfere() between conflicting
75 * live ranges. Note that an interference *must not* be added between
76 * two nodes if their classes haven't been assigned yet. The user
77 * should set the class of each node before building the interference
80 struct ra_graph
*ra_alloc_interference_graph(struct ra_regs
*regs
,
82 void ra_resize_interference_graph(struct ra_graph
*g
, unsigned int count
);
83 void ra_set_node_class(struct ra_graph
*g
, unsigned int n
, unsigned int c
);
84 unsigned int ra_get_node_class(struct ra_graph
*g
, unsigned int n
);
85 unsigned int ra_add_node(struct ra_graph
*g
, unsigned int c
);
86 void ra_set_select_reg_callback(struct ra_graph
*g
,
87 unsigned int (*callback
)(struct ra_graph
*g
,
91 void ra_add_node_interference(struct ra_graph
*g
,
92 unsigned int n1
, unsigned int n2
);
93 void ra_reset_node_interference(struct ra_graph
*g
, unsigned int n
);
96 /** @{ Graph-coloring register allocation */
97 bool ra_allocate(struct ra_graph
*g
);
99 unsigned int ra_get_node_reg(struct ra_graph
*g
, unsigned int n
);
100 void ra_set_node_reg(struct ra_graph
* g
, unsigned int n
, unsigned int reg
);
101 void ra_set_node_spill_cost(struct ra_graph
*g
, unsigned int n
, float cost
);
102 int ra_get_best_spill_node(struct ra_graph
*g
);
110 #endif /* REGISTER_ALLOCATE_H */