rename_map.hh revision 2292
12810SN/A/*
22810SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
32810SN/A * All rights reserved.
42810SN/A *
52810SN/A * Redistribution and use in source and binary forms, with or without
62810SN/A * modification, are permitted provided that the following conditions are
72810SN/A * met: redistributions of source code must retain the above copyright
82810SN/A * notice, this list of conditions and the following disclaimer;
92810SN/A * redistributions in binary form must reproduce the above copyright
102810SN/A * notice, this list of conditions and the following disclaimer in the
112810SN/A * documentation and/or other materials provided with the distribution;
122810SN/A * neither the name of the copyright holders nor the names of its
132810SN/A * contributors may be used to endorse or promote products derived from
142810SN/A * this software without specific prior written permission.
152810SN/A *
162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272810SN/A */
282810SN/A
292810SN/A// Todo:  Create destructor.
302810SN/A// Have it so that there's a more meaningful name given to the variable
312810SN/A// that marks the beginning of the FP registers.
322810SN/A
332810SN/A#ifndef __CPU_O3_RENAME_MAP_HH__
342810SN/A#define __CPU_O3_RENAME_MAP_HH__
352810SN/A
363348SN/A#include <iostream>
373348SN/A#include <utility>
388232Snate@binkert.org#include <vector>
395338Sstever@gmail.com
405338Sstever@gmail.com#include "cpu/o3/free_list.hh"
412810SN/A//For RegIndex
422810SN/A#include "arch/isa_traits.hh"
432810SN/A
444965SN/Aclass SimpleRenameMap
456122SSteve.Reinhardt@amd.com{
465314SN/A  protected:
475314SN/A    typedef TheISA::RegIndex RegIndex;
486122SSteve.Reinhardt@amd.com  public:
492810SN/A    /**
504475SN/A     * Pair of a logical register and a physical register.  Tells the
514475SN/A     * previous mapping of a logical register to a physical register.
524475SN/A     * Used to roll back the rename map to a previous state.
535034SN/A     */
545034SN/A    typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo;
555314SN/A
565314SN/A    /**
574628SN/A     * Pair of a physical register and a physical register.  Used to
585034SN/A     * return the physical register that a logical register has been
595034SN/A     * renamed to, and the previous physical register that the same
605034SN/A     * logical register was previously mapped to.
616122SSteve.Reinhardt@amd.com     */
628134SAli.Saidi@ARM.com    typedef std::pair<PhysRegIndex, PhysRegIndex> RenameInfo;
634626SN/A
644626SN/A  public:
655034SN/A    //Constructor
666122SSteve.Reinhardt@amd.com     SimpleRenameMap() {};
676978SLisa.Hsu@amd.com
686978SLisa.Hsu@amd.com    /** Destructor. */
694458SN/A    ~SimpleRenameMap();
702810SN/A
712810SN/A    void init(unsigned _numLogicalIntRegs,
722811SN/A              unsigned _numPhysicalIntRegs,
732810SN/A              PhysRegIndex &_int_reg_start,
742810SN/A
754458SN/A              unsigned _numLogicalFloatRegs,
764458SN/A              unsigned _numPhysicalFloatRegs,
774458SN/A              PhysRegIndex &_float_reg_start,
782810SN/A
792810SN/A              unsigned _numMiscRegs,
805314SN/A
815314SN/A              RegIndex _intZeroReg,
825314SN/A              RegIndex _floatZeroReg,
835314SN/A
845314SN/A              int id,
855314SN/A              bool bindRegs);
865314SN/A
875314SN/A    void setFreeList(SimpleFreeList *fl_ptr);
885314SN/A
895314SN/A    //Tell rename map to get a free physical register for a given
905314SN/A    //architected register.  Not sure it should have a return value,
916227Snate@binkert.org    //but perhaps it should have some sort of fault in case there are
926227Snate@binkert.org    //no free registers.
932810SN/A    RenameInfo rename(RegIndex arch_reg);
942810SN/A
952810SN/A    PhysRegIndex lookup(RegIndex phys_reg);
962810SN/A
973606SN/A    /**
984458SN/A     * Marks the given register as ready, meaning that its value has been
994458SN/A     * calculated and written to the register file.
1003013SN/A     * @param ready_reg The index of the physical register that is now ready.
1013236SN/A     */
1024458SN/A    void setEntry(RegIndex arch_reg, PhysRegIndex renamed_reg);
1034458SN/A
1044458SN/A    void squash(std::vector<RegIndex> freed_regs,
1053246SN/A                std::vector<UnmapInfo> unmaps);
1063309SN/A
1073013SN/A    int numFreeEntries();
1082810SN/A
1092810SN/A  private:
1103013SN/A    /** Rename Map ID  */
1113013SN/A    int id;
1122810SN/A
1133013SN/A    /** Number of logical integer registers. */
1143013SN/A    int numLogicalIntRegs;
1152810SN/A
1162810SN/A    /** Number of physical integer registers. */
1172810SN/A    int numPhysicalIntRegs;
1182810SN/A
1192810SN/A    /** Number of logical floating point registers. */
1203013SN/A    int numLogicalFloatRegs;
1213013SN/A
1223013SN/A    /** Number of physical floating point registers. */
1232897SN/A    int numPhysicalFloatRegs;
1242897SN/A
1253013SN/A    /** Number of miscellaneous registers. */
1262897SN/A    int numMiscRegs;
1274666SN/A
1284666SN/A    /** Number of logical integer + float registers. */
1297823Ssteve.reinhardt@amd.com    int numLogicalRegs;
1302897SN/A
1312810SN/A    /** Number of physical integer + float registers. */
1322810SN/A    int numPhysicalRegs;
1332844SN/A
1342810SN/A    /** The integer zero register.  This implementation assumes it is always
1352858SN/A     *  zero and never can be anything else.
1362858SN/A     */
1372858SN/A    RegIndex intZeroReg;
1382858SN/A
1392858SN/A    /** The floating point zero register.  This implementation assumes it is
1402858SN/A     *  always zero and never can be anything else.
1412858SN/A     */
1424628SN/A    RegIndex floatZeroReg;
1432858SN/A
1442810SN/A    class RenameEntry
1452810SN/A    {
1462810SN/A      public:
1472810SN/A        PhysRegIndex physical_reg;
1482810SN/A        bool valid;
1494022SN/A
1504022SN/A        RenameEntry()
1514022SN/A            : physical_reg(0), valid(false)
1522810SN/A        { }
1532810SN/A    };
1546978SLisa.Hsu@amd.com
1556978SLisa.Hsu@amd.com    //Change this to private
1566978SLisa.Hsu@amd.com  public:
1576978SLisa.Hsu@amd.com    /** Integer rename map. */
1586978SLisa.Hsu@amd.com    std::vector<RenameEntry> intRenameMap;
1592810SN/A
1602810SN/A    /** Floating point rename map. */
1612810SN/A    std::vector<RenameEntry> floatRenameMap;
1622810SN/A
1632810SN/A  private:
1642810SN/A    /** Free list interface. */
1654871SN/A    SimpleFreeList *freeList;
1664871SN/A};
1674871SN/A
1684871SN/A#endif //__CPU_O3_RENAME_MAP_HH__
1694871SN/A