001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.jikesrvm.compilers.opt.regalloc;
014
015import org.jikesrvm.compilers.opt.ir.IR;
016import org.jikesrvm.compilers.opt.ir.Register;
017
018/**
019 * This class helps manage register preferences for coalescing and
020 * register allocation.
021 */
022public abstract class GenericRegisterPreferences {
023  /**
024   * The main backing data structure;
025   */
026  private final CoalesceGraph graph = new CoalesceGraph();
027
028  /**
029   * Adds a affinity of weight w between two registers.
030   *
031   * @param w the affinity
032   * @param r1 the first register
033   * @param r2 the second register
034   */
035  protected void addAffinity(int w, Register r1, Register r2) {
036    graph.addAffinity(w, r1, r2);
037  }
038
039  /**
040   * Sets up register preferences for an IR. This is machine-dependent.
041   *
042   * @param ir the IR
043   */
044  public abstract void initialize(IR ir);
045
046  /**
047   * @return the backing graph holding the preferences.
048   */
049  public CoalesceGraph getGraph() {
050    return graph;
051  }
052}