liveness.rs 20.6 KB
Newer Older
1 2
extern crate hprof;

qinsoon's avatar
qinsoon committed
3
use compiler::machine_code::CompiledFunction;
4
use ast::ir::*;
qinsoon's avatar
qinsoon committed
5
use compiler::backend;
6
use utils::LinkedHashSet;
7

qinsoon's avatar
qinsoon committed
8 9
use std::collections::{HashMap, HashSet};

10 11 12
use compiler::backend::reg_alloc::graph_coloring::petgraph;
use compiler::backend::reg_alloc::graph_coloring::petgraph::Graph;
use compiler::backend::reg_alloc::graph_coloring::petgraph::graph::NodeIndex;
qinsoon's avatar
qinsoon committed
13

14 15 16
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GraphNode {
    temp: MuID,
qinsoon's avatar
qinsoon committed
17
    color: Option<MuID>,
18 19
    group: backend::RegGroup,
    spill_cost: f32
qinsoon's avatar
qinsoon committed
20
}
21

qinsoon's avatar
qinsoon committed
22
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
23
pub struct Move{pub from: NodeIndex, pub to: NodeIndex}
24 25

pub struct InterferenceGraph {
26 27
    graph: Graph<GraphNode, (), petgraph::Undirected>,
    nodes: HashMap<MuID, NodeIndex>,
qinsoon's avatar
qinsoon committed
28
    moves: HashSet<Move>,
29 30 31 32
}

impl InterferenceGraph {
    fn new() -> InterferenceGraph {
qinsoon's avatar
qinsoon committed
33
        InterferenceGraph {
34
            graph: Graph::new_undirected(),
qinsoon's avatar
qinsoon committed
35 36 37 38 39
            nodes: HashMap::new(),
            moves: HashSet::new()
        }
    }
    
40
    fn new_node(&mut self, reg_id: MuID, context: &FunctionContext) -> NodeIndex {
qinsoon's avatar
qinsoon committed
41 42 43
        let entry = context.get_value(reg_id).unwrap();
        
        if !self.nodes.contains_key(&reg_id) {
44
            let node = GraphNode {
45
                temp: reg_id,
46 47
                color: None,
                group: backend::RegGroup::get(entry.ty()),
48
                spill_cost: 0.0f32
qinsoon's avatar
qinsoon committed
49
            };
50 51 52 53 54

            let index = self.graph.add_node(node);

            self.nodes.insert(reg_id, index);
        }
55
        
56 57
        let node_index = *self.nodes.get(&reg_id).unwrap();
        let node_mut = self.graph.node_weight_mut(node_index).unwrap();
58 59
        
        // increase node spill cost
60
        node_mut.spill_cost += 1.0f32;
61
        
62
        node_index
qinsoon's avatar
qinsoon committed
63 64
    }
    
65
    pub fn get_node(&self, reg: MuID) -> NodeIndex {
qinsoon's avatar
qinsoon committed
66
        match self.nodes.get(&reg) {
qinsoon's avatar
qinsoon committed
67
            Some(index) => *index,
qinsoon's avatar
qinsoon committed
68
            None => panic!("do not have a node for {}", reg)
qinsoon's avatar
qinsoon committed
69 70 71
        }
    }
    
72 73 74 75 76 77 78 79
    pub fn temps(&self) -> Vec<MuID>{
        let mut ret = vec![];
        for reg in self.nodes.keys() {
            ret.push(*reg);
        }
        ret
    }
    
80
    pub fn nodes(&self) -> Vec<NodeIndex> {
qinsoon's avatar
qinsoon committed
81
        let mut ret = vec![];
82 83
        for index in self.nodes.values() {
            ret.push(*index);
qinsoon's avatar
qinsoon committed
84 85 86 87 88 89 90 91 92 93 94 95
        }
        ret
    }
    
    pub fn moves(&self) -> &HashSet<Move> {
        &self.moves
    }
    
    pub fn n_nodes(&self) -> usize {
        self.nodes.len()
    }
    
96
    fn add_move(&mut self, src: NodeIndex, dst: NodeIndex) {
qinsoon's avatar
qinsoon committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        let src = {
            let temp_src = self.get_temp_of(src);
            if temp_src < MACHINE_ID_END {
                let alias = backend::get_color_for_precolored(self.get_temp_of(src));
                self.get_node(alias)
            } else {
                src
            }
        };


        let dst = {
            let temp_dst = self.get_temp_of(dst);
            if temp_dst < MACHINE_ID_END {
                let alias = backend::get_color_for_precolored(self.get_temp_of(dst));
                self.get_node(alias)
            } else {
                dst
            }
        };

qinsoon's avatar
qinsoon committed
118
        self.moves.insert(Move{from: src, to: dst});
119 120
    }
    
121 122
    pub fn add_interference_edge(&mut self, from: NodeIndex, to: NodeIndex) {
        self.graph.update_edge(from, to, ());
qinsoon's avatar
qinsoon committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

        // if one of the node is machine register, we also add
        // interference edge to its alias
        // e.g. if we have %a, %edi interferenced,
        // we also add %a, %rdi interference

        let from_tmp = self.graph.node_weight(from).unwrap().temp;
        let to_tmp   = self.graph.node_weight(to).unwrap().temp;

        if from_tmp < MACHINE_ID_END || to_tmp < MACHINE_ID_END {
            let from_tmp = if from_tmp < MACHINE_ID_END {
                backend::get_color_for_precolored(from_tmp)
            } else {
                from_tmp
            };

            let to_tmp = if to_tmp < MACHINE_ID_END {
                backend::get_color_for_precolored(to_tmp)
            } else {
                to_tmp
            };

            let from_tmp_node = self.get_node(from_tmp);
            let to_tmp_node   = self.get_node(to_tmp);
            self.graph.update_edge(from_tmp_node, to_tmp_node, ());
        }
qinsoon's avatar
qinsoon committed
149 150
    }

151
    pub fn is_interferenced_with(&self, node1: NodeIndex, node2: NodeIndex) -> bool {
152 153 154
        let edge = self.graph.find_edge(node1, node2);

        edge.is_some()
qinsoon's avatar
qinsoon committed
155 156
    }
    
157 158
    pub fn color_node(&mut self, node: NodeIndex, color: MuID) {
        self.graph.node_weight_mut(node).unwrap().color = Some(color);
qinsoon's avatar
qinsoon committed
159 160
    }
    
161 162
    pub fn is_colored(&self, node: NodeIndex) -> bool {
        self.graph.node_weight(node).unwrap().color.is_some()
qinsoon's avatar
qinsoon committed
163 164
    }
    
165 166
    pub fn get_color_of(&self, node: NodeIndex) -> Option<MuID> {
        self.graph.node_weight(node).unwrap().color
167 168
    }
    
169 170
    pub fn get_group_of(&self, node: NodeIndex) -> backend::RegGroup {
        self.graph.node_weight(node).unwrap().group
qinsoon's avatar
qinsoon committed
171 172
    }
    
173 174
    pub fn get_temp_of(&self, node: NodeIndex) -> MuID {
        self.graph.node_weight(node).unwrap().temp
175 176
    }
    
177 178
    pub fn get_spill_cost(&self, node: NodeIndex) -> f32 {
        self.graph.node_weight(node).unwrap().spill_cost
179 180
    }
    
181
    fn is_same_node(&self, node1: NodeIndex, node2: NodeIndex) -> bool {
qinsoon's avatar
qinsoon committed
182
        node1 == node2
qinsoon's avatar
qinsoon committed
183
    }
184 185 186 187 188 189 190

    fn is_same_group(&self, node1: NodeIndex, node2: NodeIndex) -> bool {
        let node1 = self.graph.node_weight(node1).unwrap();
        let node2 = self.graph.node_weight(node2).unwrap();

        node1.group == node2.group
    }
qinsoon's avatar
qinsoon committed
191
    
192 193
    pub fn is_adj(&self, from: NodeIndex, to: NodeIndex) -> bool {
        self.is_interferenced_with(from, to)
qinsoon's avatar
qinsoon committed
194 195
    }
    
196 197
    pub fn outedges_of(&self, node: NodeIndex) -> Vec<NodeIndex> {
        self.graph.neighbors(node).collect()
198 199
    }
    
200 201
    pub fn outdegree_of(&self, node: NodeIndex) -> usize {
        self.outedges_of(node).len()
qinsoon's avatar
qinsoon committed
202 203
    }
    
204 205
    pub fn indegree_of(&self, node: NodeIndex) -> usize {
        self.outdegree_of(node)
qinsoon's avatar
qinsoon committed
206 207
    }
    
208
    pub fn degree_of(&self, node: NodeIndex) -> usize {
qinsoon's avatar
fix  
qinsoon committed
209
        self.outdegree_of(node)
qinsoon's avatar
qinsoon committed
210 211
    }
    
qinsoon's avatar
qinsoon committed
212
    pub fn print(&self, context: &FunctionContext) {
213 214 215
        use compiler::backend::reg_alloc::graph_coloring::petgraph::dot::Dot;
        use compiler::backend::reg_alloc::graph_coloring::petgraph::dot::Config;

qinsoon's avatar
qinsoon committed
216 217
        debug!("");
        debug!("Interference Graph");
218

qinsoon's avatar
qinsoon committed
219
        debug!("nodes:");
qinsoon's avatar
qinsoon committed
220
        for id in self.nodes.keys() {
qinsoon's avatar
qinsoon committed
221
            let val = context.get_value(*id).unwrap().value();
qinsoon's avatar
qinsoon committed
222
            debug!("Reg {} -> {:?}", val, self.nodes.get(&id).unwrap());
qinsoon's avatar
qinsoon committed
223 224
        }

qinsoon's avatar
qinsoon committed
225
        debug!("moves:");
226
        for mov in self.moves.iter() {
qinsoon's avatar
qinsoon committed
227
            debug!("Move {:?} -> {:?}", mov.from, mov.to);
228
        }
qinsoon's avatar
qinsoon committed
229

230
        debug!("graph:");
231
        debug!("\n\n{:?}\n", Dot::with_config(&self.graph, &[Config::EdgeNoLabel]));
qinsoon's avatar
qinsoon committed
232
        debug!("");
233
    }
qinsoon's avatar
qinsoon committed
234 235
}

236 237
const TRACE_BUILD_LIVE_SET : bool = false;

qinsoon's avatar
[wip]  
qinsoon committed
238 239
fn build_live_set (cf: &mut CompiledFunction, func: &MuFunctionVersion) {
    info!("---start building live set---");
240

qinsoon's avatar
qinsoon committed
241
    let n_insts = cf.mc().number_of_insts();
242 243 244 245

    let mut livein  : Vec<LinkedHashSet<MuID>> = vec![LinkedHashSet::new(); n_insts];
    let mut liveout : Vec<LinkedHashSet<MuID>> = vec![LinkedHashSet::new(); n_insts];

246
    let mut is_changed = true;
247

qinsoon's avatar
[wip]  
qinsoon committed
248
    let mut i = 0;
249
    while is_changed {
250 251 252
        if TRACE_BUILD_LIVE_SET {
            trace!("---iteration {}---", i);
        }
qinsoon's avatar
[wip]  
qinsoon committed
253 254
        i += 1;

255 256
        // reset
        is_changed = false;
257

258
        for n in 0..n_insts {
259 260 261 262 263 264 265 266 267
            let in_set_old = livein[n].clone();
            let out_set_old = liveout[n].clone();

            // in[n] <- use[n] + (out[n] - def[n]);
            {
                let ref mut inset = livein[n];

                inset.clear();

qinsoon's avatar
[wip]  
qinsoon committed
268
                // (1) out[n] - def[n]
269 270 271 272
                inset.add_all(liveout[n].clone());
                for def in cf.mc().get_inst_reg_defines(n) {
                    inset.remove(&def);
                }
qinsoon's avatar
[wip]  
qinsoon committed
273 274
                // (2) in[n] + (out[n] - def[n])
                inset.add_from_vec(cf.mc().get_inst_reg_uses(n));
275
            }
276

277
            // out[n] <- union(in[s] for every successor s of n)
278 279 280 281 282 283 284
            {
                let ref mut outset = liveout[n];
                outset.clear();

                for s in cf.mc().get_succs(n) {
                    outset.add_all(livein[*s].clone());
                }
285
            }
286 287 288 289

            // is in/out changed in this iteration?
            let n_changed = !in_set_old.equals(&livein[n]) || !out_set_old.equals(&liveout[n]);

290 291 292 293 294 295 296
            if TRACE_BUILD_LIVE_SET {
                trace!("inst {}", n);
                trace!("in(old)  = {:?}", in_set_old);
                trace!("in(new)  = {:?}", livein[n]);
                trace!("out(old) = {:?}", out_set_old);
                trace!("out(new) = {:?}", liveout[n]);
            }
qinsoon's avatar
[wip]  
qinsoon committed
297

298 299 300
            is_changed = is_changed || n_changed;
        }
    }
301

qinsoon's avatar
[wip]  
qinsoon committed
302 303
    info!("---finish building live set---");

qinsoon's avatar
qinsoon committed
304
    for block in cf.mc().get_all_blocks().to_vec() {
305
        let start_inst = cf.mc().get_block_range(&block).unwrap().start;
qinsoon's avatar
[wip]  
qinsoon committed
306 307 308 309 310 311
        let livein = livein[start_inst].clone().to_vec();
        {
            let display_array : Vec<String> =  livein.iter().map(|x| func.context.get_temp_display(*x)).collect();
            trace!("livein  for block {}: {:?}", block, display_array);
        }
        cf.mc_mut().set_ir_block_livein(&block, livein);
312

qinsoon's avatar
[wip]  
qinsoon committed
313 314 315 316 317 318 319
        let end_inst = cf.mc().get_block_range(&block).unwrap().end - 1;
        let liveout = liveout[end_inst].clone().to_vec();
        {
            let display_array : Vec<String> = liveout.iter().map(|x| func.context.get_temp_display(*x)).collect();
            trace!("liveout for block {}: {:?}", block, display_array);
        }
        cf.mc_mut().set_ir_block_liveout(&block, liveout);
320
    }
321 322
}

323
// from Tailoring Graph-coloring Register Allocation For Runtime Compilation, Figure 4
324
pub fn build_chaitin_briggs (cf: &mut CompiledFunction, func: &MuFunctionVersion) -> InterferenceGraph {
325
    let _p = hprof::enter("regalloc: build live set");
qinsoon's avatar
[wip]  
qinsoon committed
326
    build_live_set(cf, func);
327 328 329
    drop(_p);

    let _p = hprof::enter("regalloc: build interference graph");
qinsoon's avatar
[wip]  
qinsoon committed
330 331

    info!("---start building interference graph---");
332
    
333 334 335
    let mut ig = InterferenceGraph::new();
    
    // precolor machine register nodes
336
    for reg in backend::all_regs().values() {
337 338
        let reg_id = reg.extract_ssa_id().unwrap();
        let node = ig.new_node(reg_id, &func.context);
qinsoon's avatar
qinsoon committed
339

qinsoon's avatar
qinsoon committed
340
        let precolor = backend::get_color_for_precolored(reg_id);
qinsoon's avatar
qinsoon committed
341 342

        ig.color_node(node, precolor);
343 344 345
    }
    
    // Initialize and creates nodes for all the involved temps/regs
qinsoon's avatar
qinsoon committed
346 347
    for i in 0..cf.mc().number_of_insts() {
        for reg_id in cf.mc().get_inst_reg_defines(i) {
348 349 350
            ig.new_node(reg_id, &func.context);
        }
        
qinsoon's avatar
qinsoon committed
351
        for reg_id in cf.mc().get_inst_reg_uses(i) {
352 353 354 355
            ig.new_node(reg_id, &func.context);
        }
    }
    
qinsoon's avatar
qinsoon committed
356
    for block in cf.mc().get_all_blocks() {
357
        // Current_Live(B) = LiveOut(B)
qinsoon's avatar
qinsoon committed
358
        let mut current_live = LinkedHashSet::from_vec(match cf.mc().get_ir_block_liveout(&block) {
359 360 361
            Some(liveout) => liveout.to_vec(),
            None => panic!("cannot find liveout for block {}", block)
        });
qinsoon's avatar
qinsoon committed
362 363 364 365 366 367
        if cfg!(debug_assertions) {
            trace!("Block{}: live out", block);
            for ele in current_live.iter() {
                trace!("{}", func.context.get_temp_display(*ele));
            }
        }
368
        
qinsoon's avatar
qinsoon committed
369
        let range = cf.mc().get_block_range(&block);
370
        if range.is_none() {
qinsoon's avatar
qinsoon committed
371
            warn!("Block{}: has no range (no instructions?)", block);
372 373
            continue;
        }
qinsoon's avatar
qinsoon committed
374
        trace!("Block{}: range = {:?}", block, range.as_ref().unwrap());
375 376 377
        
        // for every inst I in reverse order
        for i in range.unwrap().rev() {
qinsoon's avatar
qinsoon committed
378
            if cfg!(debug_assertions) {
qinsoon's avatar
[wip]  
qinsoon committed
379 380 381
                trace!("Block{}: Inst{}", block, i);
                cf.mc().trace_inst(i);
                trace!("current live: ");
qinsoon's avatar
qinsoon committed
382 383 384 385 386
                for ele in current_live.iter() {
                    trace!("{}", func.context.get_temp_display(*ele));
                }
            }

387
            let src : Option<MuID> = {
qinsoon's avatar
qinsoon committed
388 389 390
                if cf.mc().is_move(i) {
                    let src = cf.mc().get_inst_reg_uses(i);
                    let dst = cf.mc().get_inst_reg_defines(i);
391
                    
qinsoon's avatar
qinsoon committed
392 393 394
                    // src:  reg/imm/mem
                    // dest: reg/mem
                    // we dont care if src/dest is mem
qinsoon's avatar
qinsoon committed
395
                    if cf.mc().is_using_mem_op(i) {
396
                        None
qinsoon's avatar
qinsoon committed
397 398 399 400
                    } else {
                        if src.len() == 1 {
                            let node1 = ig.get_node(src[0]);
                            let node2 = ig.get_node(dst[0]);
qinsoon's avatar
qinsoon committed
401 402 403
                            trace!("add move between {} and {}",
                                   func.context.get_temp_display(src[0]),
                                   func.context.get_temp_display(dst[0]));
qinsoon's avatar
qinsoon committed
404 405 406 407 408 409
                            ig.add_move(node1, node2);
                            
                            Some(src[0])
                        } else {
                            None
                        }
410 411 412 413 414
                    }
                } else {
                    None
                }
            };
qinsoon's avatar
qinsoon committed
415
            trace!("Block{}: Inst{}: src={:?}", block, i, src);
416 417
            
            // for every definition D in I
qinsoon's avatar
qinsoon committed
418
            for d in cf.mc().get_inst_reg_defines(i) {
qinsoon's avatar
qinsoon committed
419
                trace!("Block{}: Inst{}: for definition {}", block, i, func.context.get_temp_display(d));
420 421 422
                // add an interference from D to every element E in Current_Live - {D}
                // creating nodes if necessary
                for e in current_live.iter() {
qinsoon's avatar
qinsoon committed
423 424 425
                    trace!("Block{}: Inst{}: for each live {}",
                           block, i,
                           func.context.get_temp_display(*e));
426
                    if src.is_none() || (src.is_some() && *e != src.unwrap()) {
qinsoon's avatar
qinsoon committed
427
                        let from = ig.get_node(d);
428 429
                        let to = ig.get_node(*e);
                        
qinsoon's avatar
qinsoon committed
430
                        if !ig.is_same_node(from, to) &&ig.is_same_group(from, to) && !ig.is_adj(from, to) {
431
                            if !ig.is_colored(from) {
qinsoon's avatar
qinsoon committed
432 433 434 435
                                trace!("Block{}: Inst{}: add interference between {} and {}",
                                       block, i,
                                       func.context.get_temp_display(d),
                                       func.context.get_temp_display(*e));
436 437 438
                                ig.add_interference_edge(from, to);
                            }
                            if !ig.is_colored(to) {
qinsoon's avatar
qinsoon committed
439 440 441 442
                                trace!("Block{}: Inst{}: add interference between {} and {}",
                                       block, i,
                                       func.context.get_temp_display(*e),
                                       func.context.get_temp_display(d));
443 444 445 446 447 448 449 450
                                ig.add_interference_edge(to, from);
                            }
                        }
                    }
                }
            }
            
            // for every definition D in I
qinsoon's avatar
qinsoon committed
451
            for d in cf.mc().get_inst_reg_defines(i) {
qinsoon's avatar
qinsoon committed
452 453 454
                trace!("Block{}: Inst{}: remove define {} from current_live",
                       block, i,
                       func.context.get_temp_display(d));
455
                // remove D from Current_Live
qinsoon's avatar
qinsoon committed
456
                current_live.remove(&d);
457 458 459
            }
            
            // for every use U in I
qinsoon's avatar
qinsoon committed
460
            for u in cf.mc().get_inst_reg_uses(i) {
qinsoon's avatar
qinsoon committed
461 462 463
                trace!("Block{}: Inst{}: add use {} to current_live",
                       block, i,
                       func.context.get_temp_display(u));
464
                // add U to Current_live
qinsoon's avatar
qinsoon committed
465
                current_live.insert(u);
466
            }
qinsoon's avatar
qinsoon committed
467 468 469 470 471 472 473

            if cfg!(debug_assertions) {
                trace!("Block{}: Inst{}: done. current_live:", block, i);
                for ele in current_live.iter() {
                    trace!("{}", func.context.get_temp_display(*ele));
                }
            }
474 475
        }
    }
qinsoon's avatar
[wip]  
qinsoon committed
476

477
    drop(_p);
qinsoon's avatar
[wip]  
qinsoon committed
478
    info!("---finish building interference graph---");
479 480 481
    ig
}

482
// from tony's code src/RegAlloc/Liveness.java
483
// this function is no longer used
qinsoon's avatar
qinsoon committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
//#[allow(dead_code)]
//pub fn build (cf: &CompiledFunction, func: &MuFunctionVersion) -> InterferenceGraph {
//    let mut ig = InterferenceGraph::new();
//
//    // precolor machine register nodes
//    for reg in backend::all_regs().values() {
//        let reg_id = reg.extract_ssa_id().unwrap();
//        let node = ig.new_node(reg_id, &func.context);
//        ig.color_node(node, reg_id);
//    }
//
//    // Liveness Analysis
//    let n_insts = cf.mc().number_of_insts();
//    let mut live_in : Vec<Vec<MuID>> = vec![vec![]; n_insts];
//    let mut live_out : Vec<Vec<MuID>> = vec![vec![]; n_insts];
//    let mut work_list : LinkedList<usize> = LinkedList::new();
//
//    // Initialize 'in' sets for each node in the flow graph
//    // and creates nodes for all the involved temps/regs
//    for i in 0..n_insts {
//        let ref mut in_set = live_in[i];
//
//        for reg_id in cf.mc().get_inst_reg_defines(i) {
//            ig.new_node(reg_id, &func.context);
//        }
//
//        for reg_id in cf.mc().get_inst_reg_uses(i) {
//            ig.new_node(reg_id, &func.context);
//
//            in_set.push(reg_id);
//        }
//
//        work_list.push_front(i);
//    }
//
//    // all nodes has been added, we init graph (create adjacency matrix)
//    ig.init_graph();
//
//    // compute liveIn and liveOut iteratively
//    trace!("build live outs");
//    while !work_list.is_empty() {
//        let n = work_list.pop_front().unwrap();
//        trace!("build liveout for #{}", n);
//        let ref mut out_set = live_out[n];
//
//        // out = union(in[succ]) for all succs
//        for succ in cf.mc().get_succs(n) {
//            trace!("add successor's livein {:?} to #{}", &live_in[*succ], n);
//            vec_utils::add_all(out_set, &live_in[*succ]);
//        }
//
//        // in = use(i.e. live_in) + (out - def)
//        let mut diff = out_set.clone();
//        for def in cf.mc().get_inst_reg_defines(n) {
//            vec_utils::remove_value(&mut diff, def);
//            trace!("removing def: {}", def);
//            trace!("diff = {:?}", diff);
//        }
//        trace!("out - def = {:?}", diff);
//
//        if !diff.is_empty() {
//            let ref mut in_set = live_in[n];
//            trace!("in = (use) {:?}", in_set);
//
//            if vec_utils::add_all(in_set, &diff) {
//                for p in cf.mc().get_preds(n) {
//                    work_list.push_front(*p);
//                }
//            }
//        }
//        trace!("in = use + (out - def) = {:?}", live_in[n]);
//    }
//
//    // debug live-outs
//    if cfg!(debug_assertions) {
//        trace!("check live-outs");
//        for n in 0..n_insts {
//            let ref mut live = live_out[n];
//            trace!("#{}\t{:?}", n, live);
//        }
//    }
//
//    // build interference graph
//    for n in 0..n_insts {
//        let ref mut live = live_out[n];
//
//        let src : Option<MuID> = {
//            if cf.mc().is_move(n) {
//                let src = cf.mc().get_inst_reg_uses(n);
//                let dst = cf.mc().get_inst_reg_defines(n);
//
//                // src may be an immediate number
//                // but dest is definitly a register
//                debug_assert!(dst.len() == 1);
//
//                if src.len() == 1 {
//                    let node1 = ig.get_node(src[0]);
//                    let node2 = ig.get_node(dst[0]);
//                    ig.add_move(node1, node2);
//
//                    Some(src[0])
//                } else {
//                    None
//                }
//            } else {
//                None
//            }
//        };
//
//        for d in cf.mc().get_inst_reg_defines(n) {
//            for t in live.iter() {
//                if src.is_none() || (src.is_some() && *t != src.unwrap()) {
//                    let from = ig.get_node(d);
//                    let to = ig.get_node(*t);
//
//                    if !ig.is_same_node(from, to) && !ig.is_adj(from, to) {
//                        if !ig.is_colored(from) {
//                            ig.add_interference_edge(from, to);
//                        }
//                        if !ig.is_colored(to) {
//                            ig.add_interference_edge(to, from);
//                        }
//                    }
//                }
//            }
//        }
//
//        for d in cf.mc().get_inst_reg_defines(n) {
//            vec_utils::remove_value(live, d);
//        }
//
//        for u in cf.mc().get_inst_reg_uses(n) {
//            live.push(u);
//        }
//    }
//
//    ig
//}