#line 171 "liveness.h.nw"
/* file "bvd/liveness.h" -- Liveness analyzer */

#line 5 "doc-end.nw"
/*
    Copyright (c) 2000 The President and Fellows of Harvard College

    All rights reserved.

    This software is provided under the terms described in
    the "machine/copyright.h" include file.
*/

#line 175 "liveness.h.nw"
#ifndef BVD_LIVENESS_H
#define BVD_LIVENESS_H

#include <machine/copyright.h>

#ifndef SUPPRESS_PRAGMA_INTERFACE
#pragma interface "bvd/liveness.h"
#endif

#include <machine/machine.h>
#include <cfg/cfg.h>

#include <bvd/solve.h>


#line 132 "liveness.h.nw"
class DefUseAnalyzer {
  public:
    DefUseAnalyzer(OpndCatalog *catalog) : _catalog(catalog) { }
    virtual ~DefUseAnalyzer() { }

    virtual void analyze(Instr *mi);

    NatSetIter defs_iter() const	      { return _defs.iter(); }
    NatSetIter uses_iter() const	      { return _uses.iter(); }

    const NatSet *defs_set() const	      { return &_defs; }
    const NatSet *uses_set() const	      { return &_uses; }

  protected:
    OpndCatalog *catalog()		      { return _catalog; }
    NatSet *defs()			      { return &_defs; }
    NatSet *uses()			      { return &_uses; }

  private:
    OpndCatalog *_catalog;
    NatSetSparse _defs;
    NatSetSparse _uses;
};

#line 21 "liveness.h.nw"
class Liveness : public Bvd {
  public:
    Liveness(Cfg *graph, OpndCatalog *catalog, DefUseAnalyzer *analyzer)
	: Bvd(graph, backward, any_path)
    {
	_catalog = catalog;

	if (analyzer) {
	    _analyzer_own = NULL; _analyzer = analyzer;
	} else
	    _analyzer_own = _analyzer = new DefUseAnalyzer(catalog);

	solve();
    }

    virtual ~Liveness()			      { delete _analyzer_own; }

    virtual void find_kill_and_gen(Instr *mi)
	{ _analyzer->analyze(mi); }

    virtual const NatSet* kill_set() const    { return _analyzer->defs_set(); }
    virtual const NatSet* gen_set()  const    { return _analyzer->uses_set(); }

    virtual int num_slots() const	      { return _catalog->num_slots(); }

  protected:
    OpndCatalog* catalog()		      { return _catalog; }
    DefUseAnalyzer* analyzer()		      { return _analyzer; }

  private:
    OpndCatalog *_catalog;
    DefUseAnalyzer *_analyzer;
    DefUseAnalyzer *_analyzer_own;	      // default analyzer
};

#line 194 "liveness.h.nw"
#endif /* BVD_LIVENESS_H */
