beifg: Factorise code to count interference components.
[libfirm] / ir / be / beinsn.c
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       A data structure to treat nodes and node-proj collections uniformly.
9  * @author      Sebastian Hack
10  */
11 #include "config.h"
12
13 #include "irgraph_t.h"
14 #include "irmode_t.h"
15 #include "irnode_t.h"
16 #include "iredges.h"
17
18 #include "bechordal_t.h"
19 #include "besched.h"
20 #include "beinsn_t.h"
21 #include "beabi.h"
22 #include "raw_bitset.h"
23
24 be_insn_t *be_scan_insn(be_chordal_env_t *const env, ir_node *const irn)
25 {
26         struct obstack *const obst = &env->obst;
27         be_operand_t o;
28
29         be_insn_t *insn = OALLOCZ(obst, be_insn_t);
30
31         bool has_constraints = false;
32
33         const arch_register_class_t *cls = env->cls;
34         insn->irn = irn;
35         be_foreach_definition(irn, cls, p, req,
36                 /* found a def: create a new operand */
37                 if (arch_register_req_is(req, limited)) {
38                         o.regs          = req->limited;
39                         has_constraints = true;
40                 } else {
41                         o.regs           = env->allocatable_regs->data;
42                         has_constraints |= req->width > 1;
43                 }
44                 o.carrier = p;
45                 o.partner = NULL;
46                 obstack_grow(obst, &o, sizeof(o));
47                 insn->n_ops++;
48         );
49
50         insn->use_start = insn->n_ops;
51
52         /* now collect the uses for this node */
53         be_foreach_use(irn, cls, in_req, op, op_req,
54                 /* found a register use, create an operand */
55                 if (arch_register_req_is(in_req, limited)) {
56                         o.regs          = in_req->limited;
57                         has_constraints = true;
58                 } else {
59                         o.regs = env->allocatable_regs->data;
60                 }
61                 o.carrier = op;
62                 o.partner = NULL;
63                 obstack_grow(obst, &o, sizeof(o));
64                 insn->n_ops++;
65         );
66
67         if (!has_constraints)
68                 return NULL;
69
70         insn->ops = (be_operand_t*)obstack_finish(obst);
71         return insn;
72 }