inst_queue_impl.hh revision 12109
11689SN/A/*
210333Smitch.hayenga@arm.com * Copyright (c) 2011-2014 ARM Limited
39920Syasuko.eckert@amd.com * Copyright (c) 2013 Advanced Micro Devices, Inc.
47944SGiacomo.Gabrielli@arm.com * All rights reserved.
57944SGiacomo.Gabrielli@arm.com *
67944SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall
77944SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual
87944SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating
97944SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software
107944SGiacomo.Gabrielli@arm.com * licensed hereunder.  You may use the software subject to the license
117944SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated
127944SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software,
137944SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form.
147944SGiacomo.Gabrielli@arm.com *
152326SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
161689SN/A * All rights reserved.
171689SN/A *
181689SN/A * Redistribution and use in source and binary forms, with or without
191689SN/A * modification, are permitted provided that the following conditions are
201689SN/A * met: redistributions of source code must retain the above copyright
211689SN/A * notice, this list of conditions and the following disclaimer;
221689SN/A * redistributions in binary form must reproduce the above copyright
231689SN/A * notice, this list of conditions and the following disclaimer in the
241689SN/A * documentation and/or other materials provided with the distribution;
251689SN/A * neither the name of the copyright holders nor the names of its
261689SN/A * contributors may be used to endorse or promote products derived from
271689SN/A * this software without specific prior written permission.
281689SN/A *
291689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
301689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
311689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
321689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
331689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
341689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
351689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
361689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
371689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
381689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
391689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402665Ssaidi@eecs.umich.edu *
412665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
422831Sksewell@umich.edu *          Korey Sewell
431689SN/A */
441689SN/A
459944Smatt.horsnell@ARM.com#ifndef __CPU_O3_INST_QUEUE_IMPL_HH__
469944Smatt.horsnell@ARM.com#define __CPU_O3_INST_QUEUE_IMPL_HH__
479944Smatt.horsnell@ARM.com
482064SN/A#include <limits>
491060SN/A#include <vector>
501060SN/A
512292SN/A#include "cpu/o3/fu_pool.hh"
521717SN/A#include "cpu/o3/inst_queue.hh"
538232Snate@binkert.org#include "debug/IQ.hh"
544762Snate@binkert.org#include "enums/OpClass.hh"
556221Snate@binkert.org#include "params/DerivO3CPU.hh"
564762Snate@binkert.org#include "sim/core.hh"
571060SN/A
588737Skoansin.tan@gmail.com// clang complains about std::set being overloaded with Packet::set if
598737Skoansin.tan@gmail.com// we open up the entire namespace std
608737Skoansin.tan@gmail.comusing std::list;
615529Snate@binkert.org
621061SN/Atemplate <class Impl>
632292SN/AInstructionQueue<Impl>::FUCompletion::FUCompletion(DynInstPtr &_inst,
645606Snate@binkert.org    int fu_idx, InstructionQueue<Impl> *iq_ptr)
658581Ssteve.reinhardt@amd.com    : Event(Stat_Event_Pri, AutoDelete),
668581Ssteve.reinhardt@amd.com      inst(_inst), fuIdx(fu_idx), iqPtr(iq_ptr), freeFU(false)
671060SN/A{
682292SN/A}
692292SN/A
702292SN/Atemplate <class Impl>
712292SN/Avoid
722292SN/AInstructionQueue<Impl>::FUCompletion::process()
732292SN/A{
742326SN/A    iqPtr->processFUCompletion(inst, freeFU ? fuIdx : -1);
752292SN/A    inst = NULL;
762292SN/A}
772292SN/A
782292SN/A
792292SN/Atemplate <class Impl>
802292SN/Aconst char *
815336Shines@cs.fsu.eduInstructionQueue<Impl>::FUCompletion::description() const
822292SN/A{
834873Sstever@eecs.umich.edu    return "Functional unit completion";
842292SN/A}
852292SN/A
862292SN/Atemplate <class Impl>
874329Sktlim@umich.eduInstructionQueue<Impl>::InstructionQueue(O3CPU *cpu_ptr, IEW *iew_ptr,
885529Snate@binkert.org                                         DerivO3CPUParams *params)
894329Sktlim@umich.edu    : cpu(cpu_ptr),
904329Sktlim@umich.edu      iewStage(iew_ptr),
914329Sktlim@umich.edu      fuPool(params->fuPool),
922292SN/A      numEntries(params->numIQEntries),
932292SN/A      totalWidth(params->issueWidth),
942292SN/A      commitToIEWDelay(params->commitToIEWDelay)
952292SN/A{
962292SN/A    assert(fuPool);
972292SN/A
985529Snate@binkert.org    numThreads = params->numThreads;
991060SN/A
1009920Syasuko.eckert@amd.com    // Set the number of total physical registers
10112109SRekai.GonzalezAlberquilla@arm.com    // As the vector registers have two addressing modes, they are added twice
1029920Syasuko.eckert@amd.com    numPhysRegs = params->numPhysIntRegs + params->numPhysFloatRegs +
10312109SRekai.GonzalezAlberquilla@arm.com                    params->numPhysVecRegs +
10412109SRekai.GonzalezAlberquilla@arm.com                    params->numPhysVecRegs * TheISA::NumVecElemPerVecReg +
10512109SRekai.GonzalezAlberquilla@arm.com                    params->numPhysCCRegs;
1061060SN/A
1071060SN/A    //Create an entry for each physical register within the
1081060SN/A    //dependency graph.
1092326SN/A    dependGraph.resize(numPhysRegs);
1101060SN/A
1111060SN/A    // Resize the register scoreboard.
1121060SN/A    regScoreboard.resize(numPhysRegs);
1131060SN/A
1142292SN/A    //Initialize Mem Dependence Units
1156221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
1166221Snate@binkert.org        memDepUnit[tid].init(params, tid);
1176221Snate@binkert.org        memDepUnit[tid].setIQ(this);
1181060SN/A    }
1191060SN/A
1202307SN/A    resetState();
1212292SN/A
1222980Sgblack@eecs.umich.edu    std::string policy = params->smtIQPolicy;
1232292SN/A
1242292SN/A    //Convert string to lowercase
1252292SN/A    std::transform(policy.begin(), policy.end(), policy.begin(),
1262292SN/A                   (int(*)(int)) tolower);
1272292SN/A
1282292SN/A    //Figure out resource sharing policy
1292292SN/A    if (policy == "dynamic") {
1302292SN/A        iqPolicy = Dynamic;
1312292SN/A
1322292SN/A        //Set Max Entries to Total ROB Capacity
1336221Snate@binkert.org        for (ThreadID tid = 0; tid < numThreads; tid++) {
1346221Snate@binkert.org            maxEntries[tid] = numEntries;
1352292SN/A        }
1362292SN/A
1372292SN/A    } else if (policy == "partitioned") {
1382292SN/A        iqPolicy = Partitioned;
1392292SN/A
1402292SN/A        //@todo:make work if part_amt doesnt divide evenly.
1412292SN/A        int part_amt = numEntries / numThreads;
1422292SN/A
1432292SN/A        //Divide ROB up evenly
1446221Snate@binkert.org        for (ThreadID tid = 0; tid < numThreads; tid++) {
1456221Snate@binkert.org            maxEntries[tid] = part_amt;
1462292SN/A        }
1472292SN/A
1482831Sksewell@umich.edu        DPRINTF(IQ, "IQ sharing policy set to Partitioned:"
1492292SN/A                "%i entries per thread.\n",part_amt);
1502292SN/A    } else if (policy == "threshold") {
1512292SN/A        iqPolicy = Threshold;
1522292SN/A
1532292SN/A        double threshold =  (double)params->smtIQThreshold / 100;
1542292SN/A
1552292SN/A        int thresholdIQ = (int)((double)threshold * numEntries);
1562292SN/A
1572292SN/A        //Divide up by threshold amount
1586221Snate@binkert.org        for (ThreadID tid = 0; tid < numThreads; tid++) {
1596221Snate@binkert.org            maxEntries[tid] = thresholdIQ;
1602292SN/A        }
1612292SN/A
1622831Sksewell@umich.edu        DPRINTF(IQ, "IQ sharing policy set to Threshold:"
1632292SN/A                "%i entries per thread.\n",thresholdIQ);
1642292SN/A   } else {
1652292SN/A       assert(0 && "Invalid IQ Sharing Policy.Options Are:{Dynamic,"
1662292SN/A              "Partitioned, Threshold}");
1672292SN/A   }
1682292SN/A}
1692292SN/A
1702292SN/Atemplate <class Impl>
1712292SN/AInstructionQueue<Impl>::~InstructionQueue()
1722292SN/A{
1732326SN/A    dependGraph.reset();
1742348SN/A#ifdef DEBUG
1752326SN/A    cprintf("Nodes traversed: %i, removed: %i\n",
1762326SN/A            dependGraph.nodesTraversed, dependGraph.nodesRemoved);
1772348SN/A#endif
1782292SN/A}
1792292SN/A
1802292SN/Atemplate <class Impl>
1812292SN/Astd::string
1822292SN/AInstructionQueue<Impl>::name() const
1832292SN/A{
1842292SN/A    return cpu->name() + ".iq";
1851060SN/A}
1861060SN/A
1871061SN/Atemplate <class Impl>
1881060SN/Avoid
1891062SN/AInstructionQueue<Impl>::regStats()
1901062SN/A{
1912301SN/A    using namespace Stats;
1921062SN/A    iqInstsAdded
1931062SN/A        .name(name() + ".iqInstsAdded")
1941062SN/A        .desc("Number of instructions added to the IQ (excludes non-spec)")
1951062SN/A        .prereq(iqInstsAdded);
1961062SN/A
1971062SN/A    iqNonSpecInstsAdded
1981062SN/A        .name(name() + ".iqNonSpecInstsAdded")
1991062SN/A        .desc("Number of non-speculative instructions added to the IQ")
2001062SN/A        .prereq(iqNonSpecInstsAdded);
2011062SN/A
2022301SN/A    iqInstsIssued
2032301SN/A        .name(name() + ".iqInstsIssued")
2042301SN/A        .desc("Number of instructions issued")
2052301SN/A        .prereq(iqInstsIssued);
2061062SN/A
2071062SN/A    iqIntInstsIssued
2081062SN/A        .name(name() + ".iqIntInstsIssued")
2091062SN/A        .desc("Number of integer instructions issued")
2101062SN/A        .prereq(iqIntInstsIssued);
2111062SN/A
2121062SN/A    iqFloatInstsIssued
2131062SN/A        .name(name() + ".iqFloatInstsIssued")
2141062SN/A        .desc("Number of float instructions issued")
2151062SN/A        .prereq(iqFloatInstsIssued);
2161062SN/A
2171062SN/A    iqBranchInstsIssued
2181062SN/A        .name(name() + ".iqBranchInstsIssued")
2191062SN/A        .desc("Number of branch instructions issued")
2201062SN/A        .prereq(iqBranchInstsIssued);
2211062SN/A
2221062SN/A    iqMemInstsIssued
2231062SN/A        .name(name() + ".iqMemInstsIssued")
2241062SN/A        .desc("Number of memory instructions issued")
2251062SN/A        .prereq(iqMemInstsIssued);
2261062SN/A
2271062SN/A    iqMiscInstsIssued
2281062SN/A        .name(name() + ".iqMiscInstsIssued")
2291062SN/A        .desc("Number of miscellaneous instructions issued")
2301062SN/A        .prereq(iqMiscInstsIssued);
2311062SN/A
2321062SN/A    iqSquashedInstsIssued
2331062SN/A        .name(name() + ".iqSquashedInstsIssued")
2341062SN/A        .desc("Number of squashed instructions issued")
2351062SN/A        .prereq(iqSquashedInstsIssued);
2361062SN/A
2371062SN/A    iqSquashedInstsExamined
2381062SN/A        .name(name() + ".iqSquashedInstsExamined")
2391062SN/A        .desc("Number of squashed instructions iterated over during squash;"
2401062SN/A              " mainly for profiling")
2411062SN/A        .prereq(iqSquashedInstsExamined);
2421062SN/A
2431062SN/A    iqSquashedOperandsExamined
2441062SN/A        .name(name() + ".iqSquashedOperandsExamined")
2451062SN/A        .desc("Number of squashed operands that are examined and possibly "
2461062SN/A              "removed from graph")
2471062SN/A        .prereq(iqSquashedOperandsExamined);
2481062SN/A
2491062SN/A    iqSquashedNonSpecRemoved
2501062SN/A        .name(name() + ".iqSquashedNonSpecRemoved")
2511062SN/A        .desc("Number of squashed non-spec instructions that were removed")
2521062SN/A        .prereq(iqSquashedNonSpecRemoved);
2532361SN/A/*
2542326SN/A    queueResDist
2552301SN/A        .init(Num_OpClasses, 0, 99, 2)
2562301SN/A        .name(name() + ".IQ:residence:")
2572301SN/A        .desc("cycles from dispatch to issue")
2582301SN/A        .flags(total | pdf | cdf )
2592301SN/A        ;
2602301SN/A    for (int i = 0; i < Num_OpClasses; ++i) {
2612326SN/A        queueResDist.subname(i, opClassStrings[i]);
2622301SN/A    }
2632361SN/A*/
2642326SN/A    numIssuedDist
2652307SN/A        .init(0,totalWidth,1)
2668240Snate@binkert.org        .name(name() + ".issued_per_cycle")
2672301SN/A        .desc("Number of insts issued each cycle")
2682307SN/A        .flags(pdf)
2692301SN/A        ;
2702301SN/A/*
2712301SN/A    dist_unissued
2722301SN/A        .init(Num_OpClasses+2)
2738240Snate@binkert.org        .name(name() + ".unissued_cause")
2742301SN/A        .desc("Reason ready instruction not issued")
2752301SN/A        .flags(pdf | dist)
2762301SN/A        ;
2772301SN/A    for (int i=0; i < (Num_OpClasses + 2); ++i) {
2782301SN/A        dist_unissued.subname(i, unissued_names[i]);
2792301SN/A    }
2802301SN/A*/
2812326SN/A    statIssuedInstType
2824762Snate@binkert.org        .init(numThreads,Enums::Num_OpClass)
2838240Snate@binkert.org        .name(name() + ".FU_type")
2842301SN/A        .desc("Type of FU issued")
2852301SN/A        .flags(total | pdf | dist)
2862301SN/A        ;
2874762Snate@binkert.org    statIssuedInstType.ysubnames(Enums::OpClassStrings);
2882301SN/A
2892301SN/A    //
2902301SN/A    //  How long did instructions for a particular FU type wait prior to issue
2912301SN/A    //
2922361SN/A/*
2932326SN/A    issueDelayDist
2942301SN/A        .init(Num_OpClasses,0,99,2)
2958240Snate@binkert.org        .name(name() + ".")
2962301SN/A        .desc("cycles from operands ready to issue")
2972301SN/A        .flags(pdf | cdf)
2982301SN/A        ;
2992301SN/A
3002301SN/A    for (int i=0; i<Num_OpClasses; ++i) {
3012980Sgblack@eecs.umich.edu        std::stringstream subname;
3022301SN/A        subname << opClassStrings[i] << "_delay";
3032326SN/A        issueDelayDist.subname(i, subname.str());
3042301SN/A    }
3052361SN/A*/
3062326SN/A    issueRate
3078240Snate@binkert.org        .name(name() + ".rate")
3082301SN/A        .desc("Inst issue rate")
3092301SN/A        .flags(total)
3102301SN/A        ;
3112326SN/A    issueRate = iqInstsIssued / cpu->numCycles;
3122727Sktlim@umich.edu
3132326SN/A    statFuBusy
3142301SN/A        .init(Num_OpClasses)
3158240Snate@binkert.org        .name(name() + ".fu_full")
3162301SN/A        .desc("attempts to use FU when none available")
3172301SN/A        .flags(pdf | dist)
3182301SN/A        ;
3192301SN/A    for (int i=0; i < Num_OpClasses; ++i) {
3204762Snate@binkert.org        statFuBusy.subname(i, Enums::OpClassStrings[i]);
3212301SN/A    }
3222301SN/A
3232326SN/A    fuBusy
3242301SN/A        .init(numThreads)
3258240Snate@binkert.org        .name(name() + ".fu_busy_cnt")
3262301SN/A        .desc("FU busy when requested")
3272301SN/A        .flags(total)
3282301SN/A        ;
3292301SN/A
3302326SN/A    fuBusyRate
3318240Snate@binkert.org        .name(name() + ".fu_busy_rate")
3322301SN/A        .desc("FU busy rate (busy events/executed inst)")
3332301SN/A        .flags(total)
3342301SN/A        ;
3352326SN/A    fuBusyRate = fuBusy / iqInstsIssued;
3362301SN/A
3376221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
3382292SN/A        // Tell mem dependence unit to reg stats as well.
3396221Snate@binkert.org        memDepUnit[tid].regStats();
3402292SN/A    }
3417897Shestness@cs.utexas.edu
3427897Shestness@cs.utexas.edu    intInstQueueReads
3437897Shestness@cs.utexas.edu        .name(name() + ".int_inst_queue_reads")
3447897Shestness@cs.utexas.edu        .desc("Number of integer instruction queue reads")
3457897Shestness@cs.utexas.edu        .flags(total);
3467897Shestness@cs.utexas.edu
3477897Shestness@cs.utexas.edu    intInstQueueWrites
3487897Shestness@cs.utexas.edu        .name(name() + ".int_inst_queue_writes")
3497897Shestness@cs.utexas.edu        .desc("Number of integer instruction queue writes")
3507897Shestness@cs.utexas.edu        .flags(total);
3517897Shestness@cs.utexas.edu
3527897Shestness@cs.utexas.edu    intInstQueueWakeupAccesses
3537897Shestness@cs.utexas.edu        .name(name() + ".int_inst_queue_wakeup_accesses")
3547897Shestness@cs.utexas.edu        .desc("Number of integer instruction queue wakeup accesses")
3557897Shestness@cs.utexas.edu        .flags(total);
3567897Shestness@cs.utexas.edu
3577897Shestness@cs.utexas.edu    fpInstQueueReads
3587897Shestness@cs.utexas.edu        .name(name() + ".fp_inst_queue_reads")
3597897Shestness@cs.utexas.edu        .desc("Number of floating instruction queue reads")
3607897Shestness@cs.utexas.edu        .flags(total);
3617897Shestness@cs.utexas.edu
3627897Shestness@cs.utexas.edu    fpInstQueueWrites
3637897Shestness@cs.utexas.edu        .name(name() + ".fp_inst_queue_writes")
3647897Shestness@cs.utexas.edu        .desc("Number of floating instruction queue writes")
3657897Shestness@cs.utexas.edu        .flags(total);
3667897Shestness@cs.utexas.edu
3677897Shestness@cs.utexas.edu    fpInstQueueWakeupQccesses
3687897Shestness@cs.utexas.edu        .name(name() + ".fp_inst_queue_wakeup_accesses")
3697897Shestness@cs.utexas.edu        .desc("Number of floating instruction queue wakeup accesses")
3707897Shestness@cs.utexas.edu        .flags(total);
3717897Shestness@cs.utexas.edu
3727897Shestness@cs.utexas.edu    intAluAccesses
3737897Shestness@cs.utexas.edu        .name(name() + ".int_alu_accesses")
3747897Shestness@cs.utexas.edu        .desc("Number of integer alu accesses")
3757897Shestness@cs.utexas.edu        .flags(total);
3767897Shestness@cs.utexas.edu
3777897Shestness@cs.utexas.edu    fpAluAccesses
3787897Shestness@cs.utexas.edu        .name(name() + ".fp_alu_accesses")
3797897Shestness@cs.utexas.edu        .desc("Number of floating point alu accesses")
3807897Shestness@cs.utexas.edu        .flags(total);
3817897Shestness@cs.utexas.edu
3821062SN/A}
3831062SN/A
3841062SN/Atemplate <class Impl>
3851062SN/Avoid
3862307SN/AInstructionQueue<Impl>::resetState()
3871060SN/A{
3882307SN/A    //Initialize thread IQ counts
3896221Snate@binkert.org    for (ThreadID tid = 0; tid <numThreads; tid++) {
3906221Snate@binkert.org        count[tid] = 0;
3916221Snate@binkert.org        instList[tid].clear();
3922307SN/A    }
3931060SN/A
3942307SN/A    // Initialize the number of free IQ entries.
3952307SN/A    freeEntries = numEntries;
3962307SN/A
3972307SN/A    // Note that in actuality, the registers corresponding to the logical
3982307SN/A    // registers start off as ready.  However this doesn't matter for the
3992307SN/A    // IQ as the instruction should have been correctly told if those
4002307SN/A    // registers are ready in rename.  Thus it can all be initialized as
4012307SN/A    // unready.
4022307SN/A    for (int i = 0; i < numPhysRegs; ++i) {
4032307SN/A        regScoreboard[i] = false;
4042307SN/A    }
4052307SN/A
4066221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; ++tid) {
4076221Snate@binkert.org        squashedSeqNum[tid] = 0;
4082307SN/A    }
4092307SN/A
4102307SN/A    for (int i = 0; i < Num_OpClasses; ++i) {
4112307SN/A        while (!readyInsts[i].empty())
4122307SN/A            readyInsts[i].pop();
4132307SN/A        queueOnList[i] = false;
4142307SN/A        readyIt[i] = listOrder.end();
4152307SN/A    }
4162307SN/A    nonSpecInsts.clear();
4172307SN/A    listOrder.clear();
4187944SGiacomo.Gabrielli@arm.com    deferredMemInsts.clear();
41910333Smitch.hayenga@arm.com    blockedMemInsts.clear();
42010333Smitch.hayenga@arm.com    retryMemInsts.clear();
42110511Smitch.hayenga@arm.com    wbOutstanding = 0;
4221060SN/A}
4231060SN/A
4241061SN/Atemplate <class Impl>
4251060SN/Avoid
4266221Snate@binkert.orgInstructionQueue<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
4271060SN/A{
4282292SN/A    activeThreads = at_ptr;
4292064SN/A}
4302064SN/A
4312064SN/Atemplate <class Impl>
4322064SN/Avoid
4332292SN/AInstructionQueue<Impl>::setIssueToExecuteQueue(TimeBuffer<IssueStruct> *i2e_ptr)
4342064SN/A{
4354318Sktlim@umich.edu      issueToExecuteQueue = i2e_ptr;
4361060SN/A}
4371060SN/A
4381061SN/Atemplate <class Impl>
4391060SN/Avoid
4401060SN/AInstructionQueue<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
4411060SN/A{
4421060SN/A    timeBuffer = tb_ptr;
4431060SN/A
4441060SN/A    fromCommit = timeBuffer->getWire(-commitToIEWDelay);
4451060SN/A}
4461060SN/A
4471684SN/Atemplate <class Impl>
44810510Smitch.hayenga@arm.combool
44910510Smitch.hayenga@arm.comInstructionQueue<Impl>::isDrained() const
45010510Smitch.hayenga@arm.com{
45110511Smitch.hayenga@arm.com    bool drained = dependGraph.empty() &&
45210511Smitch.hayenga@arm.com                   instsToExecute.empty() &&
45310511Smitch.hayenga@arm.com                   wbOutstanding == 0;
45410510Smitch.hayenga@arm.com    for (ThreadID tid = 0; tid < numThreads; ++tid)
45510510Smitch.hayenga@arm.com        drained = drained && memDepUnit[tid].isDrained();
45610510Smitch.hayenga@arm.com
45710510Smitch.hayenga@arm.com    return drained;
45810510Smitch.hayenga@arm.com}
45910510Smitch.hayenga@arm.com
46010510Smitch.hayenga@arm.comtemplate <class Impl>
4612307SN/Avoid
4629444SAndreas.Sandberg@ARM.comInstructionQueue<Impl>::drainSanityCheck() const
4632307SN/A{
4649444SAndreas.Sandberg@ARM.com    assert(dependGraph.empty());
4659444SAndreas.Sandberg@ARM.com    assert(instsToExecute.empty());
4669444SAndreas.Sandberg@ARM.com    for (ThreadID tid = 0; tid < numThreads; ++tid)
4679444SAndreas.Sandberg@ARM.com        memDepUnit[tid].drainSanityCheck();
4682307SN/A}
4692307SN/A
4702307SN/Atemplate <class Impl>
4712307SN/Avoid
4722307SN/AInstructionQueue<Impl>::takeOverFrom()
4732307SN/A{
4749444SAndreas.Sandberg@ARM.com    resetState();
4752307SN/A}
4762307SN/A
4772307SN/Atemplate <class Impl>
4782292SN/Aint
4796221Snate@binkert.orgInstructionQueue<Impl>::entryAmount(ThreadID num_threads)
4802292SN/A{
4812292SN/A    if (iqPolicy == Partitioned) {
4822292SN/A        return numEntries / num_threads;
4832292SN/A    } else {
4842292SN/A        return 0;
4852292SN/A    }
4862292SN/A}
4872292SN/A
4882292SN/A
4892292SN/Atemplate <class Impl>
4902292SN/Avoid
4912292SN/AInstructionQueue<Impl>::resetEntries()
4922292SN/A{
4932292SN/A    if (iqPolicy != Dynamic || numThreads > 1) {
4943867Sbinkertn@umich.edu        int active_threads = activeThreads->size();
4952292SN/A
4966221Snate@binkert.org        list<ThreadID>::iterator threads = activeThreads->begin();
4976221Snate@binkert.org        list<ThreadID>::iterator end = activeThreads->end();
4982292SN/A
4993867Sbinkertn@umich.edu        while (threads != end) {
5006221Snate@binkert.org            ThreadID tid = *threads++;
5013867Sbinkertn@umich.edu
5022292SN/A            if (iqPolicy == Partitioned) {
5033867Sbinkertn@umich.edu                maxEntries[tid] = numEntries / active_threads;
50411321Ssteve.reinhardt@amd.com            } else if (iqPolicy == Threshold && active_threads == 1) {
5053867Sbinkertn@umich.edu                maxEntries[tid] = numEntries;
5062292SN/A            }
5072292SN/A        }
5082292SN/A    }
5092292SN/A}
5102292SN/A
5112292SN/Atemplate <class Impl>
5121684SN/Aunsigned
5131684SN/AInstructionQueue<Impl>::numFreeEntries()
5141684SN/A{
5151684SN/A    return freeEntries;
5161684SN/A}
5171684SN/A
5182292SN/Atemplate <class Impl>
5192292SN/Aunsigned
5206221Snate@binkert.orgInstructionQueue<Impl>::numFreeEntries(ThreadID tid)
5212292SN/A{
5222292SN/A    return maxEntries[tid] - count[tid];
5232292SN/A}
5242292SN/A
5251060SN/A// Might want to do something more complex if it knows how many instructions
5261060SN/A// will be issued this cycle.
5271061SN/Atemplate <class Impl>
5281060SN/Abool
5291060SN/AInstructionQueue<Impl>::isFull()
5301060SN/A{
5311060SN/A    if (freeEntries == 0) {
5321060SN/A        return(true);
5331060SN/A    } else {
5341060SN/A        return(false);
5351060SN/A    }
5361060SN/A}
5371060SN/A
5381061SN/Atemplate <class Impl>
5392292SN/Abool
5406221Snate@binkert.orgInstructionQueue<Impl>::isFull(ThreadID tid)
5412292SN/A{
5422292SN/A    if (numFreeEntries(tid) == 0) {
5432292SN/A        return(true);
5442292SN/A    } else {
5452292SN/A        return(false);
5462292SN/A    }
5472292SN/A}
5482292SN/A
5492292SN/Atemplate <class Impl>
5502292SN/Abool
5512292SN/AInstructionQueue<Impl>::hasReadyInsts()
5522292SN/A{
5532292SN/A    if (!listOrder.empty()) {
5542292SN/A        return true;
5552292SN/A    }
5562292SN/A
5572292SN/A    for (int i = 0; i < Num_OpClasses; ++i) {
5582292SN/A        if (!readyInsts[i].empty()) {
5592292SN/A            return true;
5602292SN/A        }
5612292SN/A    }
5622292SN/A
5632292SN/A    return false;
5642292SN/A}
5652292SN/A
5662292SN/Atemplate <class Impl>
5671060SN/Avoid
5681061SN/AInstructionQueue<Impl>::insert(DynInstPtr &new_inst)
5691060SN/A{
5707897Shestness@cs.utexas.edu    new_inst->isFloating() ? fpInstQueueWrites++ : intInstQueueWrites++;
5711060SN/A    // Make sure the instruction is valid
5721060SN/A    assert(new_inst);
5731060SN/A
5747720Sgblack@eecs.umich.edu    DPRINTF(IQ, "Adding instruction [sn:%lli] PC %s to the IQ.\n",
5757720Sgblack@eecs.umich.edu            new_inst->seqNum, new_inst->pcState());
5761060SN/A
5771060SN/A    assert(freeEntries != 0);
5781060SN/A
5792292SN/A    instList[new_inst->threadNumber].push_back(new_inst);
5801060SN/A
5812064SN/A    --freeEntries;
5821060SN/A
5832292SN/A    new_inst->setInIQ();
5841060SN/A
5851060SN/A    // Look through its source registers (physical regs), and mark any
5861060SN/A    // dependencies.
5871060SN/A    addToDependents(new_inst);
5881060SN/A
5891060SN/A    // Have this instruction set itself as the producer of its destination
5901060SN/A    // register(s).
5912326SN/A    addToProducers(new_inst);
5921060SN/A
5931061SN/A    if (new_inst->isMemRef()) {
5942292SN/A        memDepUnit[new_inst->threadNumber].insert(new_inst);
5951062SN/A    } else {
5961062SN/A        addIfReady(new_inst);
5971061SN/A    }
5981061SN/A
5991062SN/A    ++iqInstsAdded;
6001060SN/A
6012292SN/A    count[new_inst->threadNumber]++;
6022292SN/A
6031060SN/A    assert(freeEntries == (numEntries - countInsts()));
6041060SN/A}
6051060SN/A
6061061SN/Atemplate <class Impl>
6071061SN/Avoid
6082292SN/AInstructionQueue<Impl>::insertNonSpec(DynInstPtr &new_inst)
6091061SN/A{
6101061SN/A    // @todo: Clean up this code; can do it by setting inst as unable
6111061SN/A    // to issue, then calling normal insert on the inst.
6127897Shestness@cs.utexas.edu    new_inst->isFloating() ? fpInstQueueWrites++ : intInstQueueWrites++;
6131061SN/A
6142292SN/A    assert(new_inst);
6151061SN/A
6162292SN/A    nonSpecInsts[new_inst->seqNum] = new_inst;
6171061SN/A
6187720Sgblack@eecs.umich.edu    DPRINTF(IQ, "Adding non-speculative instruction [sn:%lli] PC %s "
6192326SN/A            "to the IQ.\n",
6207720Sgblack@eecs.umich.edu            new_inst->seqNum, new_inst->pcState());
6212064SN/A
6221061SN/A    assert(freeEntries != 0);
6231061SN/A
6242292SN/A    instList[new_inst->threadNumber].push_back(new_inst);
6251061SN/A
6262064SN/A    --freeEntries;
6271061SN/A
6282292SN/A    new_inst->setInIQ();
6291061SN/A
6301061SN/A    // Have this instruction set itself as the producer of its destination
6311061SN/A    // register(s).
6322326SN/A    addToProducers(new_inst);
6331061SN/A
6341061SN/A    // If it's a memory instruction, add it to the memory dependency
6351061SN/A    // unit.
6362292SN/A    if (new_inst->isMemRef()) {
6372292SN/A        memDepUnit[new_inst->threadNumber].insertNonSpec(new_inst);
6381061SN/A    }
6391062SN/A
6401062SN/A    ++iqNonSpecInstsAdded;
6412292SN/A
6422292SN/A    count[new_inst->threadNumber]++;
6432292SN/A
6442292SN/A    assert(freeEntries == (numEntries - countInsts()));
6451061SN/A}
6461061SN/A
6471061SN/Atemplate <class Impl>
6481060SN/Avoid
6492292SN/AInstructionQueue<Impl>::insertBarrier(DynInstPtr &barr_inst)
6501060SN/A{
6512292SN/A    memDepUnit[barr_inst->threadNumber].insertBarrier(barr_inst);
6521060SN/A
6532292SN/A    insertNonSpec(barr_inst);
6542292SN/A}
6551060SN/A
6562064SN/Atemplate <class Impl>
6572333SN/Atypename Impl::DynInstPtr
6582333SN/AInstructionQueue<Impl>::getInstToExecute()
6592333SN/A{
6602333SN/A    assert(!instsToExecute.empty());
6612333SN/A    DynInstPtr inst = instsToExecute.front();
6622333SN/A    instsToExecute.pop_front();
6637897Shestness@cs.utexas.edu    if (inst->isFloating()){
6647897Shestness@cs.utexas.edu        fpInstQueueReads++;
6657897Shestness@cs.utexas.edu    } else {
6667897Shestness@cs.utexas.edu        intInstQueueReads++;
6677897Shestness@cs.utexas.edu    }
6682333SN/A    return inst;
6692333SN/A}
6701060SN/A
6712333SN/Atemplate <class Impl>
6722064SN/Avoid
6732292SN/AInstructionQueue<Impl>::addToOrderList(OpClass op_class)
6742292SN/A{
6752292SN/A    assert(!readyInsts[op_class].empty());
6762292SN/A
6772292SN/A    ListOrderEntry queue_entry;
6782292SN/A
6792292SN/A    queue_entry.queueType = op_class;
6802292SN/A
6812292SN/A    queue_entry.oldestInst = readyInsts[op_class].top()->seqNum;
6822292SN/A
6832292SN/A    ListOrderIt list_it = listOrder.begin();
6842292SN/A    ListOrderIt list_end_it = listOrder.end();
6852292SN/A
6862292SN/A    while (list_it != list_end_it) {
6872292SN/A        if ((*list_it).oldestInst > queue_entry.oldestInst) {
6882292SN/A            break;
6892292SN/A        }
6902292SN/A
6912292SN/A        list_it++;
6921060SN/A    }
6931060SN/A
6942292SN/A    readyIt[op_class] = listOrder.insert(list_it, queue_entry);
6952292SN/A    queueOnList[op_class] = true;
6962292SN/A}
6971060SN/A
6982292SN/Atemplate <class Impl>
6992292SN/Avoid
7002292SN/AInstructionQueue<Impl>::moveToYoungerInst(ListOrderIt list_order_it)
7012292SN/A{
7022292SN/A    // Get iterator of next item on the list
7032292SN/A    // Delete the original iterator
7042292SN/A    // Determine if the next item is either the end of the list or younger
7052292SN/A    // than the new instruction.  If so, then add in a new iterator right here.
7062292SN/A    // If not, then move along.
7072292SN/A    ListOrderEntry queue_entry;
7082292SN/A    OpClass op_class = (*list_order_it).queueType;
7092292SN/A    ListOrderIt next_it = list_order_it;
7102292SN/A
7112292SN/A    ++next_it;
7122292SN/A
7132292SN/A    queue_entry.queueType = op_class;
7142292SN/A    queue_entry.oldestInst = readyInsts[op_class].top()->seqNum;
7152292SN/A
7162292SN/A    while (next_it != listOrder.end() &&
7172292SN/A           (*next_it).oldestInst < queue_entry.oldestInst) {
7182292SN/A        ++next_it;
7191060SN/A    }
7201060SN/A
7212292SN/A    readyIt[op_class] = listOrder.insert(next_it, queue_entry);
7221060SN/A}
7231060SN/A
7242292SN/Atemplate <class Impl>
7252292SN/Avoid
7262292SN/AInstructionQueue<Impl>::processFUCompletion(DynInstPtr &inst, int fu_idx)
7272292SN/A{
7282367SN/A    DPRINTF(IQ, "Processing FU completion [sn:%lli]\n", inst->seqNum);
7299444SAndreas.Sandberg@ARM.com    assert(!cpu->switchedOut());
7302292SN/A    // The CPU could have been sleeping until this op completed (*extremely*
7312292SN/A    // long latency op).  Wake it if it was.  This may be overkill.
73210511Smitch.hayenga@arm.com   --wbOutstanding;
7332292SN/A    iewStage->wakeCPU();
7342292SN/A
7352326SN/A    if (fu_idx > -1)
7362326SN/A        fuPool->freeUnitNextCycle(fu_idx);
7372292SN/A
7382326SN/A    // @todo: Ensure that these FU Completions happen at the beginning
7392326SN/A    // of a cycle, otherwise they could add too many instructions to
7402326SN/A    // the queue.
7415327Smengke97@hotmail.com    issueToExecuteQueue->access(-1)->size++;
7422333SN/A    instsToExecute.push_back(inst);
7432292SN/A}
7442292SN/A
7451061SN/A// @todo: Figure out a better way to remove the squashed items from the
7461061SN/A// lists.  Checking the top item of each list to see if it's squashed
7471061SN/A// wastes time and forces jumps.
7481061SN/Atemplate <class Impl>
7491060SN/Avoid
7501060SN/AInstructionQueue<Impl>::scheduleReadyInsts()
7511060SN/A{
7522292SN/A    DPRINTF(IQ, "Attempting to schedule ready instructions from "
7532292SN/A            "the IQ.\n");
7541060SN/A
7551060SN/A    IssueStruct *i2e_info = issueToExecuteQueue->access(0);
7561060SN/A
75710333Smitch.hayenga@arm.com    DynInstPtr mem_inst;
75810333Smitch.hayenga@arm.com    while (mem_inst = getDeferredMemInstToExecute()) {
75910333Smitch.hayenga@arm.com        addReadyMemInst(mem_inst);
76010333Smitch.hayenga@arm.com    }
76110333Smitch.hayenga@arm.com
76210333Smitch.hayenga@arm.com    // See if any cache blocked instructions are able to be executed
76310333Smitch.hayenga@arm.com    while (mem_inst = getBlockedMemInstToExecute()) {
76410333Smitch.hayenga@arm.com        addReadyMemInst(mem_inst);
7657944SGiacomo.Gabrielli@arm.com    }
7667944SGiacomo.Gabrielli@arm.com
7672292SN/A    // Have iterator to head of the list
7682292SN/A    // While I haven't exceeded bandwidth or reached the end of the list,
7692292SN/A    // Try to get a FU that can do what this op needs.
7702292SN/A    // If successful, change the oldestInst to the new top of the list, put
7712292SN/A    // the queue in the proper place in the list.
7722292SN/A    // Increment the iterator.
7732292SN/A    // This will avoid trying to schedule a certain op class if there are no
7742292SN/A    // FUs that handle it.
77510333Smitch.hayenga@arm.com    int total_issued = 0;
7762292SN/A    ListOrderIt order_it = listOrder.begin();
7772292SN/A    ListOrderIt order_end_it = listOrder.end();
7781060SN/A
77910333Smitch.hayenga@arm.com    while (total_issued < totalWidth && order_it != order_end_it) {
7802292SN/A        OpClass op_class = (*order_it).queueType;
7811060SN/A
7822292SN/A        assert(!readyInsts[op_class].empty());
7831060SN/A
7842292SN/A        DynInstPtr issuing_inst = readyInsts[op_class].top();
7851060SN/A
7867897Shestness@cs.utexas.edu        issuing_inst->isFloating() ? fpInstQueueReads++ : intInstQueueReads++;
7877897Shestness@cs.utexas.edu
7882292SN/A        assert(issuing_inst->seqNum == (*order_it).oldestInst);
7891060SN/A
7902292SN/A        if (issuing_inst->isSquashed()) {
7912292SN/A            readyInsts[op_class].pop();
7921060SN/A
7932292SN/A            if (!readyInsts[op_class].empty()) {
7942292SN/A                moveToYoungerInst(order_it);
7952292SN/A            } else {
7962292SN/A                readyIt[op_class] = listOrder.end();
7972292SN/A                queueOnList[op_class] = false;
7981060SN/A            }
7991060SN/A
8002292SN/A            listOrder.erase(order_it++);
8011060SN/A
8022292SN/A            ++iqSquashedInstsIssued;
8032292SN/A
8042292SN/A            continue;
8051060SN/A        }
8061060SN/A
80711365SRekai.GonzalezAlberquilla@arm.com        int idx = FUPool::NoCapableFU;
8089184Sandreas.hansson@arm.com        Cycles op_latency = Cycles(1);
8096221Snate@binkert.org        ThreadID tid = issuing_inst->threadNumber;
8101060SN/A
8112326SN/A        if (op_class != No_OpClass) {
8122326SN/A            idx = fuPool->getUnit(op_class);
8137897Shestness@cs.utexas.edu            issuing_inst->isFloating() ? fpAluAccesses++ : intAluAccesses++;
81411365SRekai.GonzalezAlberquilla@arm.com            if (idx > FUPool::NoFreeFU) {
8152326SN/A                op_latency = fuPool->getOpLatency(op_class);
8161060SN/A            }
8171060SN/A        }
8181060SN/A
8192348SN/A        // If we have an instruction that doesn't require a FU, or a
8202348SN/A        // valid FU, then schedule for execution.
82111365SRekai.GonzalezAlberquilla@arm.com        if (idx != FUPool::NoFreeFU) {
8229184Sandreas.hansson@arm.com            if (op_latency == Cycles(1)) {
8232292SN/A                i2e_info->size++;
8242333SN/A                instsToExecute.push_back(issuing_inst);
8251060SN/A
8262326SN/A                // Add the FU onto the list of FU's to be freed next
8272326SN/A                // cycle if we used one.
8282326SN/A                if (idx >= 0)
8292326SN/A                    fuPool->freeUnitNextCycle(idx);
8302292SN/A            } else {
83110807Snilay@cs.wisc.edu                bool pipelined = fuPool->isPipelined(op_class);
8322326SN/A                // Generate completion event for the FU
83310511Smitch.hayenga@arm.com                ++wbOutstanding;
8342326SN/A                FUCompletion *execution = new FUCompletion(issuing_inst,
8352326SN/A                                                           idx, this);
8361060SN/A
8379180Sandreas.hansson@arm.com                cpu->schedule(execution,
8389180Sandreas.hansson@arm.com                              cpu->clockEdge(Cycles(op_latency - 1)));
8391060SN/A
84010807Snilay@cs.wisc.edu                if (!pipelined) {
8412348SN/A                    // If FU isn't pipelined, then it must be freed
8422348SN/A                    // upon the execution completing.
8432326SN/A                    execution->setFreeFU();
8442292SN/A                } else {
8452292SN/A                    // Add the FU onto the list of FU's to be freed next cycle.
8462326SN/A                    fuPool->freeUnitNextCycle(idx);
8472292SN/A                }
8481060SN/A            }
8491060SN/A
8507720Sgblack@eecs.umich.edu            DPRINTF(IQ, "Thread %i: Issuing instruction PC %s "
8512292SN/A                    "[sn:%lli]\n",
8527720Sgblack@eecs.umich.edu                    tid, issuing_inst->pcState(),
8532292SN/A                    issuing_inst->seqNum);
8541060SN/A
8552292SN/A            readyInsts[op_class].pop();
8561061SN/A
8572292SN/A            if (!readyInsts[op_class].empty()) {
8582292SN/A                moveToYoungerInst(order_it);
8592292SN/A            } else {
8602292SN/A                readyIt[op_class] = listOrder.end();
8612292SN/A                queueOnList[op_class] = false;
8621060SN/A            }
8631060SN/A
8642064SN/A            issuing_inst->setIssued();
8652292SN/A            ++total_issued;
8662064SN/A
8678471SGiacomo.Gabrielli@arm.com#if TRACING_ON
8689046SAli.Saidi@ARM.com            issuing_inst->issueTick = curTick() - issuing_inst->fetchTick;
8698471SGiacomo.Gabrielli@arm.com#endif
8708471SGiacomo.Gabrielli@arm.com
8712292SN/A            if (!issuing_inst->isMemRef()) {
8722292SN/A                // Memory instructions can not be freed from the IQ until they
8732292SN/A                // complete.
8742292SN/A                ++freeEntries;
8752301SN/A                count[tid]--;
8762731Sktlim@umich.edu                issuing_inst->clearInIQ();
8772292SN/A            } else {
8782301SN/A                memDepUnit[tid].issue(issuing_inst);
8792292SN/A            }
8802292SN/A
8812292SN/A            listOrder.erase(order_it++);
8822326SN/A            statIssuedInstType[tid][op_class]++;
8832292SN/A        } else {
8842326SN/A            statFuBusy[op_class]++;
8852326SN/A            fuBusy[tid]++;
8862292SN/A            ++order_it;
8871060SN/A        }
8881060SN/A    }
8891062SN/A
8902326SN/A    numIssuedDist.sample(total_issued);
8912326SN/A    iqInstsIssued+= total_issued;
8922307SN/A
8932348SN/A    // If we issued any instructions, tell the CPU we had activity.
8948071SAli.Saidi@ARM.com    // @todo If the way deferred memory instructions are handeled due to
8958071SAli.Saidi@ARM.com    // translation changes then the deferredMemInsts condition should be removed
8968071SAli.Saidi@ARM.com    // from the code below.
89710333Smitch.hayenga@arm.com    if (total_issued || !retryMemInsts.empty() || !deferredMemInsts.empty()) {
8982292SN/A        cpu->activityThisCycle();
8992292SN/A    } else {
9002292SN/A        DPRINTF(IQ, "Not able to schedule any instructions.\n");
9012292SN/A    }
9021060SN/A}
9031060SN/A
9041061SN/Atemplate <class Impl>
9051060SN/Avoid
9061061SN/AInstructionQueue<Impl>::scheduleNonSpec(const InstSeqNum &inst)
9071060SN/A{
9082292SN/A    DPRINTF(IQ, "Marking nonspeculative instruction [sn:%lli] as ready "
9092292SN/A            "to execute.\n", inst);
9101062SN/A
9112292SN/A    NonSpecMapIt inst_it = nonSpecInsts.find(inst);
9121060SN/A
9131061SN/A    assert(inst_it != nonSpecInsts.end());
9141060SN/A
9156221Snate@binkert.org    ThreadID tid = (*inst_it).second->threadNumber;
9162292SN/A
9174033Sktlim@umich.edu    (*inst_it).second->setAtCommit();
9184033Sktlim@umich.edu
9191061SN/A    (*inst_it).second->setCanIssue();
9201060SN/A
9211062SN/A    if (!(*inst_it).second->isMemRef()) {
9221062SN/A        addIfReady((*inst_it).second);
9231062SN/A    } else {
9242292SN/A        memDepUnit[tid].nonSpecInstReady((*inst_it).second);
9251062SN/A    }
9261060SN/A
9272292SN/A    (*inst_it).second = NULL;
9282292SN/A
9291061SN/A    nonSpecInsts.erase(inst_it);
9301060SN/A}
9311060SN/A
9321061SN/Atemplate <class Impl>
9331061SN/Avoid
9346221Snate@binkert.orgInstructionQueue<Impl>::commit(const InstSeqNum &inst, ThreadID tid)
9352292SN/A{
9362292SN/A    DPRINTF(IQ, "[tid:%i]: Committing instructions older than [sn:%i]\n",
9372292SN/A            tid,inst);
9382292SN/A
9392292SN/A    ListIt iq_it = instList[tid].begin();
9402292SN/A
9412292SN/A    while (iq_it != instList[tid].end() &&
9422292SN/A           (*iq_it)->seqNum <= inst) {
9432292SN/A        ++iq_it;
9442292SN/A        instList[tid].pop_front();
9452292SN/A    }
9462292SN/A
9472292SN/A    assert(freeEntries == (numEntries - countInsts()));
9482292SN/A}
9492292SN/A
9502292SN/Atemplate <class Impl>
9512301SN/Aint
9521684SN/AInstructionQueue<Impl>::wakeDependents(DynInstPtr &completed_inst)
9531684SN/A{
9542301SN/A    int dependents = 0;
9552301SN/A
9567897Shestness@cs.utexas.edu    // The instruction queue here takes care of both floating and int ops
9577897Shestness@cs.utexas.edu    if (completed_inst->isFloating()) {
9587897Shestness@cs.utexas.edu        fpInstQueueWakeupQccesses++;
9597897Shestness@cs.utexas.edu    } else {
9607897Shestness@cs.utexas.edu        intInstQueueWakeupAccesses++;
9617897Shestness@cs.utexas.edu    }
9627897Shestness@cs.utexas.edu
9632292SN/A    DPRINTF(IQ, "Waking dependents of completed instruction.\n");
9642292SN/A
9652292SN/A    assert(!completed_inst->isSquashed());
9661684SN/A
9671684SN/A    // Tell the memory dependence unit to wake any dependents on this
9682292SN/A    // instruction if it is a memory instruction.  Also complete the memory
9692326SN/A    // instruction at this point since we know it executed without issues.
9702326SN/A    // @todo: Might want to rename "completeMemInst" to something that
9712326SN/A    // indicates that it won't need to be replayed, and call this
9722326SN/A    // earlier.  Might not be a big deal.
9731684SN/A    if (completed_inst->isMemRef()) {
9742292SN/A        memDepUnit[completed_inst->threadNumber].wakeDependents(completed_inst);
9752292SN/A        completeMemInst(completed_inst);
9762292SN/A    } else if (completed_inst->isMemBarrier() ||
9772292SN/A               completed_inst->isWriteBarrier()) {
9782292SN/A        memDepUnit[completed_inst->threadNumber].completeBarrier(completed_inst);
9791684SN/A    }
9801684SN/A
9811684SN/A    for (int dest_reg_idx = 0;
9821684SN/A         dest_reg_idx < completed_inst->numDestRegs();
9831684SN/A         dest_reg_idx++)
9841684SN/A    {
98512105Snathanael.premillieu@arm.com        PhysRegIdPtr dest_reg =
9861684SN/A            completed_inst->renamedDestRegIdx(dest_reg_idx);
9871684SN/A
9881684SN/A        // Special case of uniq or control registers.  They are not
9891684SN/A        // handled by the IQ and thus have no dependency graph entry.
99012105Snathanael.premillieu@arm.com        if (dest_reg->isFixedMapping()) {
99112105Snathanael.premillieu@arm.com            DPRINTF(IQ, "Reg %d [%s] is part of a fix mapping, skipping\n",
99212106SRekai.GonzalezAlberquilla@arm.com                    dest_reg->index(), dest_reg->className());
9931684SN/A            continue;
9941684SN/A        }
9951684SN/A
99612105Snathanael.premillieu@arm.com        DPRINTF(IQ, "Waking any dependents on register %i (%s).\n",
99712106SRekai.GonzalezAlberquilla@arm.com                dest_reg->index(),
99812106SRekai.GonzalezAlberquilla@arm.com                dest_reg->className());
9991684SN/A
10002326SN/A        //Go through the dependency chain, marking the registers as
10012326SN/A        //ready within the waiting instructions.
100212106SRekai.GonzalezAlberquilla@arm.com        DynInstPtr dep_inst = dependGraph.pop(dest_reg->flatIndex());
10031684SN/A
10042326SN/A        while (dep_inst) {
10057599Sminkyu.jeong@arm.com            DPRINTF(IQ, "Waking up a dependent instruction, [sn:%lli] "
10067720Sgblack@eecs.umich.edu                    "PC %s.\n", dep_inst->seqNum, dep_inst->pcState());
10071684SN/A
10081684SN/A            // Might want to give more information to the instruction
10092326SN/A            // so that it knows which of its source registers is
10102326SN/A            // ready.  However that would mean that the dependency
10112326SN/A            // graph entries would need to hold the src_reg_idx.
10122326SN/A            dep_inst->markSrcRegReady();
10131684SN/A
10142326SN/A            addIfReady(dep_inst);
10151684SN/A
101612106SRekai.GonzalezAlberquilla@arm.com            dep_inst = dependGraph.pop(dest_reg->flatIndex());
10171684SN/A
10182301SN/A            ++dependents;
10191684SN/A        }
10201684SN/A
10212326SN/A        // Reset the head node now that all of its dependents have
10222326SN/A        // been woken up.
102312106SRekai.GonzalezAlberquilla@arm.com        assert(dependGraph.empty(dest_reg->flatIndex()));
102412106SRekai.GonzalezAlberquilla@arm.com        dependGraph.clearInst(dest_reg->flatIndex());
10251684SN/A
10261684SN/A        // Mark the scoreboard as having that register ready.
102712106SRekai.GonzalezAlberquilla@arm.com        regScoreboard[dest_reg->flatIndex()] = true;
10281684SN/A    }
10292301SN/A    return dependents;
10302064SN/A}
10312064SN/A
10322064SN/Atemplate <class Impl>
10332064SN/Avoid
10342292SN/AInstructionQueue<Impl>::addReadyMemInst(DynInstPtr &ready_inst)
10352064SN/A{
10362292SN/A    OpClass op_class = ready_inst->opClass();
10372292SN/A
10382292SN/A    readyInsts[op_class].push(ready_inst);
10392292SN/A
10402326SN/A    // Will need to reorder the list if either a queue is not on the list,
10412326SN/A    // or it has an older instruction than last time.
10422326SN/A    if (!queueOnList[op_class]) {
10432326SN/A        addToOrderList(op_class);
10442326SN/A    } else if (readyInsts[op_class].top()->seqNum  <
10452326SN/A               (*readyIt[op_class]).oldestInst) {
10462326SN/A        listOrder.erase(readyIt[op_class]);
10472326SN/A        addToOrderList(op_class);
10482326SN/A    }
10492326SN/A
10502292SN/A    DPRINTF(IQ, "Instruction is ready to issue, putting it onto "
10517720Sgblack@eecs.umich.edu            "the ready list, PC %s opclass:%i [sn:%lli].\n",
10527720Sgblack@eecs.umich.edu            ready_inst->pcState(), op_class, ready_inst->seqNum);
10532064SN/A}
10542064SN/A
10552064SN/Atemplate <class Impl>
10562064SN/Avoid
10572292SN/AInstructionQueue<Impl>::rescheduleMemInst(DynInstPtr &resched_inst)
10582064SN/A{
10594033Sktlim@umich.edu    DPRINTF(IQ, "Rescheduling mem inst [sn:%lli]\n", resched_inst->seqNum);
10607944SGiacomo.Gabrielli@arm.com
10617944SGiacomo.Gabrielli@arm.com    // Reset DTB translation state
10629046SAli.Saidi@ARM.com    resched_inst->translationStarted(false);
10639046SAli.Saidi@ARM.com    resched_inst->translationCompleted(false);
10647944SGiacomo.Gabrielli@arm.com
10654033Sktlim@umich.edu    resched_inst->clearCanIssue();
10662292SN/A    memDepUnit[resched_inst->threadNumber].reschedule(resched_inst);
10672064SN/A}
10682064SN/A
10692064SN/Atemplate <class Impl>
10702064SN/Avoid
10712292SN/AInstructionQueue<Impl>::replayMemInst(DynInstPtr &replay_inst)
10722064SN/A{
107310333Smitch.hayenga@arm.com    memDepUnit[replay_inst->threadNumber].replay();
10742292SN/A}
10752292SN/A
10762292SN/Atemplate <class Impl>
10772292SN/Avoid
10782292SN/AInstructionQueue<Impl>::completeMemInst(DynInstPtr &completed_inst)
10792292SN/A{
10806221Snate@binkert.org    ThreadID tid = completed_inst->threadNumber;
10812292SN/A
10827720Sgblack@eecs.umich.edu    DPRINTF(IQ, "Completing mem instruction PC: %s [sn:%lli]\n",
10837720Sgblack@eecs.umich.edu            completed_inst->pcState(), completed_inst->seqNum);
10842292SN/A
10852292SN/A    ++freeEntries;
10862292SN/A
10879046SAli.Saidi@ARM.com    completed_inst->memOpDone(true);
10882292SN/A
10892292SN/A    memDepUnit[tid].completed(completed_inst);
10902292SN/A    count[tid]--;
10911684SN/A}
10921684SN/A
10931684SN/Atemplate <class Impl>
10941684SN/Avoid
10957944SGiacomo.Gabrielli@arm.comInstructionQueue<Impl>::deferMemInst(DynInstPtr &deferred_inst)
10967944SGiacomo.Gabrielli@arm.com{
10977944SGiacomo.Gabrielli@arm.com    deferredMemInsts.push_back(deferred_inst);
10987944SGiacomo.Gabrielli@arm.com}
10997944SGiacomo.Gabrielli@arm.com
11007944SGiacomo.Gabrielli@arm.comtemplate <class Impl>
110110333Smitch.hayenga@arm.comvoid
110210333Smitch.hayenga@arm.comInstructionQueue<Impl>::blockMemInst(DynInstPtr &blocked_inst)
110310333Smitch.hayenga@arm.com{
110410333Smitch.hayenga@arm.com    blocked_inst->translationStarted(false);
110510333Smitch.hayenga@arm.com    blocked_inst->translationCompleted(false);
110610333Smitch.hayenga@arm.com
110710333Smitch.hayenga@arm.com    blocked_inst->clearIssued();
110810333Smitch.hayenga@arm.com    blocked_inst->clearCanIssue();
110910333Smitch.hayenga@arm.com    blockedMemInsts.push_back(blocked_inst);
111010333Smitch.hayenga@arm.com}
111110333Smitch.hayenga@arm.com
111210333Smitch.hayenga@arm.comtemplate <class Impl>
111310333Smitch.hayenga@arm.comvoid
111410333Smitch.hayenga@arm.comInstructionQueue<Impl>::cacheUnblocked()
111510333Smitch.hayenga@arm.com{
111610333Smitch.hayenga@arm.com    retryMemInsts.splice(retryMemInsts.end(), blockedMemInsts);
111710333Smitch.hayenga@arm.com    // Get the CPU ticking again
111810333Smitch.hayenga@arm.com    cpu->wakeCPU();
111910333Smitch.hayenga@arm.com}
112010333Smitch.hayenga@arm.com
112110333Smitch.hayenga@arm.comtemplate <class Impl>
11227944SGiacomo.Gabrielli@arm.comtypename Impl::DynInstPtr
11237944SGiacomo.Gabrielli@arm.comInstructionQueue<Impl>::getDeferredMemInstToExecute()
11247944SGiacomo.Gabrielli@arm.com{
11257944SGiacomo.Gabrielli@arm.com    for (ListIt it = deferredMemInsts.begin(); it != deferredMemInsts.end();
11267944SGiacomo.Gabrielli@arm.com         ++it) {
11279046SAli.Saidi@ARM.com        if ((*it)->translationCompleted() || (*it)->isSquashed()) {
112810333Smitch.hayenga@arm.com            DynInstPtr mem_inst = *it;
11297944SGiacomo.Gabrielli@arm.com            deferredMemInsts.erase(it);
113010333Smitch.hayenga@arm.com            return mem_inst;
11317944SGiacomo.Gabrielli@arm.com        }
11327944SGiacomo.Gabrielli@arm.com    }
113310333Smitch.hayenga@arm.com    return nullptr;
113410333Smitch.hayenga@arm.com}
113510333Smitch.hayenga@arm.com
113610333Smitch.hayenga@arm.comtemplate <class Impl>
113710333Smitch.hayenga@arm.comtypename Impl::DynInstPtr
113810333Smitch.hayenga@arm.comInstructionQueue<Impl>::getBlockedMemInstToExecute()
113910333Smitch.hayenga@arm.com{
114010333Smitch.hayenga@arm.com    if (retryMemInsts.empty()) {
114110333Smitch.hayenga@arm.com        return nullptr;
114210333Smitch.hayenga@arm.com    } else {
114310333Smitch.hayenga@arm.com        DynInstPtr mem_inst = retryMemInsts.front();
114410333Smitch.hayenga@arm.com        retryMemInsts.pop_front();
114510333Smitch.hayenga@arm.com        return mem_inst;
114610333Smitch.hayenga@arm.com    }
11477944SGiacomo.Gabrielli@arm.com}
11487944SGiacomo.Gabrielli@arm.com
11497944SGiacomo.Gabrielli@arm.comtemplate <class Impl>
11507944SGiacomo.Gabrielli@arm.comvoid
11511061SN/AInstructionQueue<Impl>::violation(DynInstPtr &store,
11521061SN/A                                  DynInstPtr &faulting_load)
11531061SN/A{
11547897Shestness@cs.utexas.edu    intInstQueueWrites++;
11552292SN/A    memDepUnit[store->threadNumber].violation(store, faulting_load);
11561061SN/A}
11571061SN/A
11581061SN/Atemplate <class Impl>
11591060SN/Avoid
11606221Snate@binkert.orgInstructionQueue<Impl>::squash(ThreadID tid)
11611060SN/A{
11622292SN/A    DPRINTF(IQ, "[tid:%i]: Starting to squash instructions in "
11632292SN/A            "the IQ.\n", tid);
11641060SN/A
11651060SN/A    // Read instruction sequence number of last instruction out of the
11661060SN/A    // time buffer.
11672292SN/A    squashedSeqNum[tid] = fromCommit->commitInfo[tid].doneSeqNum;
11681060SN/A
116910797Sbrandon.potter@amd.com    doSquash(tid);
11701061SN/A
11711061SN/A    // Also tell the memory dependence unit to squash.
11722292SN/A    memDepUnit[tid].squash(squashedSeqNum[tid], tid);
11731060SN/A}
11741060SN/A
11751061SN/Atemplate <class Impl>
11761061SN/Avoid
11776221Snate@binkert.orgInstructionQueue<Impl>::doSquash(ThreadID tid)
11781061SN/A{
11792326SN/A    // Start at the tail.
11802326SN/A    ListIt squash_it = instList[tid].end();
11812326SN/A    --squash_it;
11821061SN/A
11832292SN/A    DPRINTF(IQ, "[tid:%i]: Squashing until sequence number %i!\n",
11842292SN/A            tid, squashedSeqNum[tid]);
11851061SN/A
11861061SN/A    // Squash any instructions younger than the squashed sequence number
11871061SN/A    // given.
11882326SN/A    while (squash_it != instList[tid].end() &&
11892326SN/A           (*squash_it)->seqNum > squashedSeqNum[tid]) {
11902292SN/A
11912326SN/A        DynInstPtr squashed_inst = (*squash_it);
11927897Shestness@cs.utexas.edu        squashed_inst->isFloating() ? fpInstQueueWrites++ : intInstQueueWrites++;
11931061SN/A
11941061SN/A        // Only handle the instruction if it actually is in the IQ and
11951061SN/A        // hasn't already been squashed in the IQ.
11962292SN/A        if (squashed_inst->threadNumber != tid ||
11972292SN/A            squashed_inst->isSquashedInIQ()) {
11982326SN/A            --squash_it;
11992292SN/A            continue;
12002292SN/A        }
12012292SN/A
12022292SN/A        if (!squashed_inst->isIssued() ||
12032292SN/A            (squashed_inst->isMemRef() &&
12049046SAli.Saidi@ARM.com             !squashed_inst->memOpDone())) {
12051062SN/A
12067720Sgblack@eecs.umich.edu            DPRINTF(IQ, "[tid:%i]: Instruction [sn:%lli] PC %s squashed.\n",
12077720Sgblack@eecs.umich.edu                    tid, squashed_inst->seqNum, squashed_inst->pcState());
12082367SN/A
120910032SGiacomo.Gabrielli@arm.com            bool is_acq_rel = squashed_inst->isMemBarrier() &&
121010032SGiacomo.Gabrielli@arm.com                         (squashed_inst->isLoad() ||
121110032SGiacomo.Gabrielli@arm.com                           (squashed_inst->isStore() &&
121210032SGiacomo.Gabrielli@arm.com                             !squashed_inst->isStoreConditional()));
121310032SGiacomo.Gabrielli@arm.com
12141061SN/A            // Remove the instruction from the dependency list.
121510032SGiacomo.Gabrielli@arm.com            if (is_acq_rel ||
121610032SGiacomo.Gabrielli@arm.com                (!squashed_inst->isNonSpeculative() &&
121710032SGiacomo.Gabrielli@arm.com                 !squashed_inst->isStoreConditional() &&
121810032SGiacomo.Gabrielli@arm.com                 !squashed_inst->isMemBarrier() &&
121910032SGiacomo.Gabrielli@arm.com                 !squashed_inst->isWriteBarrier())) {
12201061SN/A
12211061SN/A                for (int src_reg_idx = 0;
12221681SN/A                     src_reg_idx < squashed_inst->numSrcRegs();
12231061SN/A                     src_reg_idx++)
12241061SN/A                {
122512105Snathanael.premillieu@arm.com                    PhysRegIdPtr src_reg =
12261061SN/A                        squashed_inst->renamedSrcRegIdx(src_reg_idx);
12271061SN/A
12282326SN/A                    // Only remove it from the dependency graph if it
12292326SN/A                    // was placed there in the first place.
12302326SN/A
12312326SN/A                    // Instead of doing a linked list traversal, we
12322326SN/A                    // can just remove these squashed instructions
12332326SN/A                    // either at issue time, or when the register is
12342326SN/A                    // overwritten.  The only downside to this is it
12352326SN/A                    // leaves more room for error.
12362292SN/A
12371061SN/A                    if (!squashed_inst->isReadySrcRegIdx(src_reg_idx) &&
123812105Snathanael.premillieu@arm.com                        !src_reg->isFixedMapping()) {
123912106SRekai.GonzalezAlberquilla@arm.com                        dependGraph.remove(src_reg->flatIndex(),
124012106SRekai.GonzalezAlberquilla@arm.com                                           squashed_inst);
12411061SN/A                    }
12421062SN/A
12432292SN/A
12441062SN/A                    ++iqSquashedOperandsExamined;
12451061SN/A                }
12464033Sktlim@umich.edu            } else if (!squashed_inst->isStoreConditional() ||
12474033Sktlim@umich.edu                       !squashed_inst->isCompleted()) {
12482292SN/A                NonSpecMapIt ns_inst_it =
12492292SN/A                    nonSpecInsts.find(squashed_inst->seqNum);
12508275SAli.Saidi@ARM.com
125110017Sandreas.hansson@arm.com                // we remove non-speculative instructions from
125210017Sandreas.hansson@arm.com                // nonSpecInsts already when they are ready, and so we
125310017Sandreas.hansson@arm.com                // cannot always expect to find them
12544033Sktlim@umich.edu                if (ns_inst_it == nonSpecInsts.end()) {
125510017Sandreas.hansson@arm.com                    // loads that became ready but stalled on a
125610017Sandreas.hansson@arm.com                    // blocked cache are alreayd removed from
125710017Sandreas.hansson@arm.com                    // nonSpecInsts, and have not faulted
125810017Sandreas.hansson@arm.com                    assert(squashed_inst->getFault() != NoFault ||
125910017Sandreas.hansson@arm.com                           squashed_inst->isMemRef());
12604033Sktlim@umich.edu                } else {
12611062SN/A
12624033Sktlim@umich.edu                    (*ns_inst_it).second = NULL;
12631681SN/A
12644033Sktlim@umich.edu                    nonSpecInsts.erase(ns_inst_it);
12651062SN/A
12664033Sktlim@umich.edu                    ++iqSquashedNonSpecRemoved;
12674033Sktlim@umich.edu                }
12681061SN/A            }
12691061SN/A
12701061SN/A            // Might want to also clear out the head of the dependency graph.
12711061SN/A
12721061SN/A            // Mark it as squashed within the IQ.
12731061SN/A            squashed_inst->setSquashedInIQ();
12741061SN/A
12752292SN/A            // @todo: Remove this hack where several statuses are set so the
12762292SN/A            // inst will flow through the rest of the pipeline.
12771681SN/A            squashed_inst->setIssued();
12781681SN/A            squashed_inst->setCanCommit();
12792731Sktlim@umich.edu            squashed_inst->clearInIQ();
12802292SN/A
12812292SN/A            //Update Thread IQ Count
12822292SN/A            count[squashed_inst->threadNumber]--;
12831681SN/A
12841681SN/A            ++freeEntries;
12851061SN/A        }
12861061SN/A
12872326SN/A        instList[tid].erase(squash_it--);
12881062SN/A        ++iqSquashedInstsExamined;
12891061SN/A    }
12901060SN/A}
12911060SN/A
12921061SN/Atemplate <class Impl>
12931060SN/Abool
12941061SN/AInstructionQueue<Impl>::addToDependents(DynInstPtr &new_inst)
12951060SN/A{
12961060SN/A    // Loop through the instruction's source registers, adding
12971060SN/A    // them to the dependency list if they are not ready.
12981060SN/A    int8_t total_src_regs = new_inst->numSrcRegs();
12991060SN/A    bool return_val = false;
13001060SN/A
13011060SN/A    for (int src_reg_idx = 0;
13021060SN/A         src_reg_idx < total_src_regs;
13031060SN/A         src_reg_idx++)
13041060SN/A    {
13051060SN/A        // Only add it to the dependency graph if it's not ready.
13061060SN/A        if (!new_inst->isReadySrcRegIdx(src_reg_idx)) {
130712105Snathanael.premillieu@arm.com            PhysRegIdPtr src_reg = new_inst->renamedSrcRegIdx(src_reg_idx);
13081060SN/A
13091060SN/A            // Check the IQ's scoreboard to make sure the register
13101060SN/A            // hasn't become ready while the instruction was in flight
13111060SN/A            // between stages.  Only if it really isn't ready should
13121060SN/A            // it be added to the dependency graph.
131312105Snathanael.premillieu@arm.com            if (src_reg->isFixedMapping()) {
13141061SN/A                continue;
131512106SRekai.GonzalezAlberquilla@arm.com            } else if (!regScoreboard[src_reg->flatIndex()]) {
131612105Snathanael.premillieu@arm.com                DPRINTF(IQ, "Instruction PC %s has src reg %i (%s) that "
13171060SN/A                        "is being added to the dependency chain.\n",
131812106SRekai.GonzalezAlberquilla@arm.com                        new_inst->pcState(), src_reg->index(),
131912106SRekai.GonzalezAlberquilla@arm.com                        src_reg->className());
13201060SN/A
132112106SRekai.GonzalezAlberquilla@arm.com                dependGraph.insert(src_reg->flatIndex(), new_inst);
13221060SN/A
13231060SN/A                // Change the return value to indicate that something
13241060SN/A                // was added to the dependency graph.
13251060SN/A                return_val = true;
13261060SN/A            } else {
132712105Snathanael.premillieu@arm.com                DPRINTF(IQ, "Instruction PC %s has src reg %i (%s) that "
13281060SN/A                        "became ready before it reached the IQ.\n",
132912106SRekai.GonzalezAlberquilla@arm.com                        new_inst->pcState(), src_reg->index(),
133012106SRekai.GonzalezAlberquilla@arm.com                        src_reg->className());
13311060SN/A                // Mark a register ready within the instruction.
13322326SN/A                new_inst->markSrcRegReady(src_reg_idx);
13331060SN/A            }
13341060SN/A        }
13351060SN/A    }
13361060SN/A
13371060SN/A    return return_val;
13381060SN/A}
13391060SN/A
13401061SN/Atemplate <class Impl>
13411060SN/Avoid
13422326SN/AInstructionQueue<Impl>::addToProducers(DynInstPtr &new_inst)
13431060SN/A{
13442326SN/A    // Nothing really needs to be marked when an instruction becomes
13452326SN/A    // the producer of a register's value, but for convenience a ptr
13462326SN/A    // to the producing instruction will be placed in the head node of
13472326SN/A    // the dependency links.
13481060SN/A    int8_t total_dest_regs = new_inst->numDestRegs();
13491060SN/A
13501060SN/A    for (int dest_reg_idx = 0;
13511060SN/A         dest_reg_idx < total_dest_regs;
13521060SN/A         dest_reg_idx++)
13531060SN/A    {
135412105Snathanael.premillieu@arm.com        PhysRegIdPtr dest_reg = new_inst->renamedDestRegIdx(dest_reg_idx);
13551061SN/A
135612105Snathanael.premillieu@arm.com        // Some registers have fixed mapping, and there is no need to track
13571061SN/A        // dependencies as these instructions must be executed at commit.
135812105Snathanael.premillieu@arm.com        if (dest_reg->isFixedMapping()) {
13591061SN/A            continue;
13601060SN/A        }
13611060SN/A
136212106SRekai.GonzalezAlberquilla@arm.com        if (!dependGraph.empty(dest_reg->flatIndex())) {
13632326SN/A            dependGraph.dump();
136412105Snathanael.premillieu@arm.com            panic("Dependency graph %i (%s) (flat: %i) not empty!",
136512106SRekai.GonzalezAlberquilla@arm.com                  dest_reg->index(), dest_reg->className(),
136612106SRekai.GonzalezAlberquilla@arm.com                  dest_reg->flatIndex());
13672064SN/A        }
13681062SN/A
136912106SRekai.GonzalezAlberquilla@arm.com        dependGraph.setInst(dest_reg->flatIndex(), new_inst);
13701062SN/A
13711060SN/A        // Mark the scoreboard to say it's not yet ready.
137212106SRekai.GonzalezAlberquilla@arm.com        regScoreboard[dest_reg->flatIndex()] = false;
13731060SN/A    }
13741060SN/A}
13751060SN/A
13761061SN/Atemplate <class Impl>
13771060SN/Avoid
13781061SN/AInstructionQueue<Impl>::addIfReady(DynInstPtr &inst)
13791060SN/A{
13802326SN/A    // If the instruction now has all of its source registers
13811060SN/A    // available, then add it to the list of ready instructions.
13821060SN/A    if (inst->readyToIssue()) {
13831061SN/A
13841060SN/A        //Add the instruction to the proper ready list.
13852292SN/A        if (inst->isMemRef()) {
13861061SN/A
13872292SN/A            DPRINTF(IQ, "Checking if memory instruction can issue.\n");
13881061SN/A
13891062SN/A            // Message to the mem dependence unit that this instruction has
13901062SN/A            // its registers ready.
13912292SN/A            memDepUnit[inst->threadNumber].regsReady(inst);
13921062SN/A
13932292SN/A            return;
13942292SN/A        }
13951062SN/A
13962292SN/A        OpClass op_class = inst->opClass();
13971061SN/A
13982292SN/A        DPRINTF(IQ, "Instruction is ready to issue, putting it onto "
13997720Sgblack@eecs.umich.edu                "the ready list, PC %s opclass:%i [sn:%lli].\n",
14007720Sgblack@eecs.umich.edu                inst->pcState(), op_class, inst->seqNum);
14011061SN/A
14022292SN/A        readyInsts[op_class].push(inst);
14031061SN/A
14042326SN/A        // Will need to reorder the list if either a queue is not on the list,
14052326SN/A        // or it has an older instruction than last time.
14062326SN/A        if (!queueOnList[op_class]) {
14072326SN/A            addToOrderList(op_class);
14082326SN/A        } else if (readyInsts[op_class].top()->seqNum  <
14092326SN/A                   (*readyIt[op_class]).oldestInst) {
14102326SN/A            listOrder.erase(readyIt[op_class]);
14112326SN/A            addToOrderList(op_class);
14121060SN/A        }
14131060SN/A    }
14141060SN/A}
14151060SN/A
14161061SN/Atemplate <class Impl>
14171061SN/Aint
14181061SN/AInstructionQueue<Impl>::countInsts()
14191061SN/A{
14202698Sktlim@umich.edu#if 0
14212292SN/A    //ksewell:This works but definitely could use a cleaner write
14222292SN/A    //with a more intuitive way of counting. Right now it's
14232292SN/A    //just brute force ....
14242698Sktlim@umich.edu    // Change the #if if you want to use this method.
14251061SN/A    int total_insts = 0;
14261061SN/A
14276221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; ++tid) {
14286221Snate@binkert.org        ListIt count_it = instList[tid].begin();
14291681SN/A
14306221Snate@binkert.org        while (count_it != instList[tid].end()) {
14312292SN/A            if (!(*count_it)->isSquashed() && !(*count_it)->isSquashedInIQ()) {
14322292SN/A                if (!(*count_it)->isIssued()) {
14332292SN/A                    ++total_insts;
14342292SN/A                } else if ((*count_it)->isMemRef() &&
14352292SN/A                           !(*count_it)->memOpDone) {
14362292SN/A                    // Loads that have not been marked as executed still count
14372292SN/A                    // towards the total instructions.
14382292SN/A                    ++total_insts;
14392292SN/A                }
14402292SN/A            }
14412292SN/A
14422292SN/A            ++count_it;
14431061SN/A        }
14441061SN/A    }
14451061SN/A
14461061SN/A    return total_insts;
14472292SN/A#else
14482292SN/A    return numEntries - freeEntries;
14492292SN/A#endif
14501681SN/A}
14511681SN/A
14521681SN/Atemplate <class Impl>
14531681SN/Avoid
14541061SN/AInstructionQueue<Impl>::dumpLists()
14551061SN/A{
14562292SN/A    for (int i = 0; i < Num_OpClasses; ++i) {
14572292SN/A        cprintf("Ready list %i size: %i\n", i, readyInsts[i].size());
14581061SN/A
14592292SN/A        cprintf("\n");
14602292SN/A    }
14611061SN/A
14621061SN/A    cprintf("Non speculative list size: %i\n", nonSpecInsts.size());
14631061SN/A
14642292SN/A    NonSpecMapIt non_spec_it = nonSpecInsts.begin();
14652292SN/A    NonSpecMapIt non_spec_end_it = nonSpecInsts.end();
14661061SN/A
14671061SN/A    cprintf("Non speculative list: ");
14681061SN/A
14692292SN/A    while (non_spec_it != non_spec_end_it) {
14707720Sgblack@eecs.umich.edu        cprintf("%s [sn:%lli]", (*non_spec_it).second->pcState(),
14712292SN/A                (*non_spec_it).second->seqNum);
14721061SN/A        ++non_spec_it;
14731061SN/A    }
14741061SN/A
14751061SN/A    cprintf("\n");
14761061SN/A
14772292SN/A    ListOrderIt list_order_it = listOrder.begin();
14782292SN/A    ListOrderIt list_order_end_it = listOrder.end();
14792292SN/A    int i = 1;
14802292SN/A
14812292SN/A    cprintf("List order: ");
14822292SN/A
14832292SN/A    while (list_order_it != list_order_end_it) {
14842292SN/A        cprintf("%i OpClass:%i [sn:%lli] ", i, (*list_order_it).queueType,
14852292SN/A                (*list_order_it).oldestInst);
14862292SN/A
14872292SN/A        ++list_order_it;
14882292SN/A        ++i;
14892292SN/A    }
14902292SN/A
14912292SN/A    cprintf("\n");
14921061SN/A}
14932292SN/A
14942292SN/A
14952292SN/Atemplate <class Impl>
14962292SN/Avoid
14972292SN/AInstructionQueue<Impl>::dumpInsts()
14982292SN/A{
14996221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; ++tid) {
15002292SN/A        int num = 0;
15012292SN/A        int valid_num = 0;
15026221Snate@binkert.org        ListIt inst_list_it = instList[tid].begin();
15032292SN/A
15046221Snate@binkert.org        while (inst_list_it != instList[tid].end()) {
15056221Snate@binkert.org            cprintf("Instruction:%i\n", num);
15062292SN/A            if (!(*inst_list_it)->isSquashed()) {
15072292SN/A                if (!(*inst_list_it)->isIssued()) {
15082292SN/A                    ++valid_num;
15092292SN/A                    cprintf("Count:%i\n", valid_num);
15102292SN/A                } else if ((*inst_list_it)->isMemRef() &&
15119046SAli.Saidi@ARM.com                           !(*inst_list_it)->memOpDone()) {
15122326SN/A                    // Loads that have not been marked as executed
15132326SN/A                    // still count towards the total instructions.
15142292SN/A                    ++valid_num;
15152292SN/A                    cprintf("Count:%i\n", valid_num);
15162292SN/A                }
15172292SN/A            }
15182292SN/A
15197720Sgblack@eecs.umich.edu            cprintf("PC: %s\n[sn:%lli]\n[tid:%i]\n"
15202292SN/A                    "Issued:%i\nSquashed:%i\n",
15217720Sgblack@eecs.umich.edu                    (*inst_list_it)->pcState(),
15222292SN/A                    (*inst_list_it)->seqNum,
15232292SN/A                    (*inst_list_it)->threadNumber,
15242292SN/A                    (*inst_list_it)->isIssued(),
15252292SN/A                    (*inst_list_it)->isSquashed());
15262292SN/A
15272292SN/A            if ((*inst_list_it)->isMemRef()) {
15289046SAli.Saidi@ARM.com                cprintf("MemOpDone:%i\n", (*inst_list_it)->memOpDone());
15292292SN/A            }
15302292SN/A
15312292SN/A            cprintf("\n");
15322292SN/A
15332292SN/A            inst_list_it++;
15342292SN/A            ++num;
15352292SN/A        }
15362292SN/A    }
15372348SN/A
15382348SN/A    cprintf("Insts to Execute list:\n");
15392348SN/A
15402348SN/A    int num = 0;
15412348SN/A    int valid_num = 0;
15422348SN/A    ListIt inst_list_it = instsToExecute.begin();
15432348SN/A
15442348SN/A    while (inst_list_it != instsToExecute.end())
15452348SN/A    {
15462348SN/A        cprintf("Instruction:%i\n",
15472348SN/A                num);
15482348SN/A        if (!(*inst_list_it)->isSquashed()) {
15492348SN/A            if (!(*inst_list_it)->isIssued()) {
15502348SN/A                ++valid_num;
15512348SN/A                cprintf("Count:%i\n", valid_num);
15522348SN/A            } else if ((*inst_list_it)->isMemRef() &&
15539046SAli.Saidi@ARM.com                       !(*inst_list_it)->memOpDone()) {
15542348SN/A                // Loads that have not been marked as executed
15552348SN/A                // still count towards the total instructions.
15562348SN/A                ++valid_num;
15572348SN/A                cprintf("Count:%i\n", valid_num);
15582348SN/A            }
15592348SN/A        }
15602348SN/A
15617720Sgblack@eecs.umich.edu        cprintf("PC: %s\n[sn:%lli]\n[tid:%i]\n"
15622348SN/A                "Issued:%i\nSquashed:%i\n",
15637720Sgblack@eecs.umich.edu                (*inst_list_it)->pcState(),
15642348SN/A                (*inst_list_it)->seqNum,
15652348SN/A                (*inst_list_it)->threadNumber,
15662348SN/A                (*inst_list_it)->isIssued(),
15672348SN/A                (*inst_list_it)->isSquashed());
15682348SN/A
15692348SN/A        if ((*inst_list_it)->isMemRef()) {
15709046SAli.Saidi@ARM.com            cprintf("MemOpDone:%i\n", (*inst_list_it)->memOpDone());
15712348SN/A        }
15722348SN/A
15732348SN/A        cprintf("\n");
15742348SN/A
15752348SN/A        inst_list_it++;
15762348SN/A        ++num;
15772348SN/A    }
15782292SN/A}
15799944Smatt.horsnell@ARM.com
15809944Smatt.horsnell@ARM.com#endif//__CPU_O3_INST_QUEUE_IMPL_HH__
1581