inst_queue_impl.hh revision 8581
11689SN/A/*
27944SGiacomo.Gabrielli@arm.com * Copyright (c) 2011 ARM Limited
37944SGiacomo.Gabrielli@arm.com * All rights reserved.
47944SGiacomo.Gabrielli@arm.com *
57944SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall
67944SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual
77944SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating
87944SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software
97944SGiacomo.Gabrielli@arm.com * licensed hereunder.  You may use the software subject to the license
107944SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated
117944SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software,
127944SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form.
137944SGiacomo.Gabrielli@arm.com *
142326SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
151689SN/A * All rights reserved.
161689SN/A *
171689SN/A * Redistribution and use in source and binary forms, with or without
181689SN/A * modification, are permitted provided that the following conditions are
191689SN/A * met: redistributions of source code must retain the above copyright
201689SN/A * notice, this list of conditions and the following disclaimer;
211689SN/A * redistributions in binary form must reproduce the above copyright
221689SN/A * notice, this list of conditions and the following disclaimer in the
231689SN/A * documentation and/or other materials provided with the distribution;
241689SN/A * neither the name of the copyright holders nor the names of its
251689SN/A * contributors may be used to endorse or promote products derived from
261689SN/A * this software without specific prior written permission.
271689SN/A *
281689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
321689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
331689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
341689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
351689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
361689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
371689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
381689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
412831Sksewell@umich.edu *          Korey Sewell
421689SN/A */
431689SN/A
442064SN/A#include <limits>
451060SN/A#include <vector>
461060SN/A
472292SN/A#include "cpu/o3/fu_pool.hh"
481717SN/A#include "cpu/o3/inst_queue.hh"
498232Snate@binkert.org#include "debug/IQ.hh"
504762Snate@binkert.org#include "enums/OpClass.hh"
516221Snate@binkert.org#include "params/DerivO3CPU.hh"
524762Snate@binkert.org#include "sim/core.hh"
531060SN/A
546221Snate@binkert.orgusing namespace std;
555529Snate@binkert.org
561061SN/Atemplate <class Impl>
572292SN/AInstructionQueue<Impl>::FUCompletion::FUCompletion(DynInstPtr &_inst,
585606Snate@binkert.org    int fu_idx, InstructionQueue<Impl> *iq_ptr)
598581Ssteve.reinhardt@amd.com    : Event(Stat_Event_Pri, AutoDelete),
608581Ssteve.reinhardt@amd.com      inst(_inst), fuIdx(fu_idx), iqPtr(iq_ptr), freeFU(false)
611060SN/A{
622292SN/A}
632292SN/A
642292SN/Atemplate <class Impl>
652292SN/Avoid
662292SN/AInstructionQueue<Impl>::FUCompletion::process()
672292SN/A{
682326SN/A    iqPtr->processFUCompletion(inst, freeFU ? fuIdx : -1);
692292SN/A    inst = NULL;
702292SN/A}
712292SN/A
722292SN/A
732292SN/Atemplate <class Impl>
742292SN/Aconst char *
755336Shines@cs.fsu.eduInstructionQueue<Impl>::FUCompletion::description() const
762292SN/A{
774873Sstever@eecs.umich.edu    return "Functional unit completion";
782292SN/A}
792292SN/A
802292SN/Atemplate <class Impl>
814329Sktlim@umich.eduInstructionQueue<Impl>::InstructionQueue(O3CPU *cpu_ptr, IEW *iew_ptr,
825529Snate@binkert.org                                         DerivO3CPUParams *params)
834329Sktlim@umich.edu    : cpu(cpu_ptr),
844329Sktlim@umich.edu      iewStage(iew_ptr),
854329Sktlim@umich.edu      fuPool(params->fuPool),
862292SN/A      numEntries(params->numIQEntries),
872292SN/A      totalWidth(params->issueWidth),
882292SN/A      numPhysIntRegs(params->numPhysIntRegs),
892292SN/A      numPhysFloatRegs(params->numPhysFloatRegs),
902292SN/A      commitToIEWDelay(params->commitToIEWDelay)
912292SN/A{
922292SN/A    assert(fuPool);
932292SN/A
942307SN/A    switchedOut = false;
952307SN/A
965529Snate@binkert.org    numThreads = params->numThreads;
971060SN/A
981060SN/A    // Set the number of physical registers as the number of int + float
991060SN/A    numPhysRegs = numPhysIntRegs + numPhysFloatRegs;
1001060SN/A
1011060SN/A    //Create an entry for each physical register within the
1021060SN/A    //dependency graph.
1032326SN/A    dependGraph.resize(numPhysRegs);
1041060SN/A
1051060SN/A    // Resize the register scoreboard.
1061060SN/A    regScoreboard.resize(numPhysRegs);
1071060SN/A
1082292SN/A    //Initialize Mem Dependence Units
1096221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
1106221Snate@binkert.org        memDepUnit[tid].init(params, tid);
1116221Snate@binkert.org        memDepUnit[tid].setIQ(this);
1121060SN/A    }
1131060SN/A
1142307SN/A    resetState();
1152292SN/A
1162980Sgblack@eecs.umich.edu    std::string policy = params->smtIQPolicy;
1172292SN/A
1182292SN/A    //Convert string to lowercase
1192292SN/A    std::transform(policy.begin(), policy.end(), policy.begin(),
1202292SN/A                   (int(*)(int)) tolower);
1212292SN/A
1222292SN/A    //Figure out resource sharing policy
1232292SN/A    if (policy == "dynamic") {
1242292SN/A        iqPolicy = Dynamic;
1252292SN/A
1262292SN/A        //Set Max Entries to Total ROB Capacity
1276221Snate@binkert.org        for (ThreadID tid = 0; tid < numThreads; tid++) {
1286221Snate@binkert.org            maxEntries[tid] = numEntries;
1292292SN/A        }
1302292SN/A
1312292SN/A    } else if (policy == "partitioned") {
1322292SN/A        iqPolicy = Partitioned;
1332292SN/A
1342292SN/A        //@todo:make work if part_amt doesnt divide evenly.
1352292SN/A        int part_amt = numEntries / numThreads;
1362292SN/A
1372292SN/A        //Divide ROB up evenly
1386221Snate@binkert.org        for (ThreadID tid = 0; tid < numThreads; tid++) {
1396221Snate@binkert.org            maxEntries[tid] = part_amt;
1402292SN/A        }
1412292SN/A
1422831Sksewell@umich.edu        DPRINTF(IQ, "IQ sharing policy set to Partitioned:"
1432292SN/A                "%i entries per thread.\n",part_amt);
1442292SN/A    } else if (policy == "threshold") {
1452292SN/A        iqPolicy = Threshold;
1462292SN/A
1472292SN/A        double threshold =  (double)params->smtIQThreshold / 100;
1482292SN/A
1492292SN/A        int thresholdIQ = (int)((double)threshold * numEntries);
1502292SN/A
1512292SN/A        //Divide up by threshold amount
1526221Snate@binkert.org        for (ThreadID tid = 0; tid < numThreads; tid++) {
1536221Snate@binkert.org            maxEntries[tid] = thresholdIQ;
1542292SN/A        }
1552292SN/A
1562831Sksewell@umich.edu        DPRINTF(IQ, "IQ sharing policy set to Threshold:"
1572292SN/A                "%i entries per thread.\n",thresholdIQ);
1582292SN/A   } else {
1592292SN/A       assert(0 && "Invalid IQ Sharing Policy.Options Are:{Dynamic,"
1602292SN/A              "Partitioned, Threshold}");
1612292SN/A   }
1622292SN/A}
1632292SN/A
1642292SN/Atemplate <class Impl>
1652292SN/AInstructionQueue<Impl>::~InstructionQueue()
1662292SN/A{
1672326SN/A    dependGraph.reset();
1682348SN/A#ifdef DEBUG
1692326SN/A    cprintf("Nodes traversed: %i, removed: %i\n",
1702326SN/A            dependGraph.nodesTraversed, dependGraph.nodesRemoved);
1712348SN/A#endif
1722292SN/A}
1732292SN/A
1742292SN/Atemplate <class Impl>
1752292SN/Astd::string
1762292SN/AInstructionQueue<Impl>::name() const
1772292SN/A{
1782292SN/A    return cpu->name() + ".iq";
1791060SN/A}
1801060SN/A
1811061SN/Atemplate <class Impl>
1821060SN/Avoid
1831062SN/AInstructionQueue<Impl>::regStats()
1841062SN/A{
1852301SN/A    using namespace Stats;
1861062SN/A    iqInstsAdded
1871062SN/A        .name(name() + ".iqInstsAdded")
1881062SN/A        .desc("Number of instructions added to the IQ (excludes non-spec)")
1891062SN/A        .prereq(iqInstsAdded);
1901062SN/A
1911062SN/A    iqNonSpecInstsAdded
1921062SN/A        .name(name() + ".iqNonSpecInstsAdded")
1931062SN/A        .desc("Number of non-speculative instructions added to the IQ")
1941062SN/A        .prereq(iqNonSpecInstsAdded);
1951062SN/A
1962301SN/A    iqInstsIssued
1972301SN/A        .name(name() + ".iqInstsIssued")
1982301SN/A        .desc("Number of instructions issued")
1992301SN/A        .prereq(iqInstsIssued);
2001062SN/A
2011062SN/A    iqIntInstsIssued
2021062SN/A        .name(name() + ".iqIntInstsIssued")
2031062SN/A        .desc("Number of integer instructions issued")
2041062SN/A        .prereq(iqIntInstsIssued);
2051062SN/A
2061062SN/A    iqFloatInstsIssued
2071062SN/A        .name(name() + ".iqFloatInstsIssued")
2081062SN/A        .desc("Number of float instructions issued")
2091062SN/A        .prereq(iqFloatInstsIssued);
2101062SN/A
2111062SN/A    iqBranchInstsIssued
2121062SN/A        .name(name() + ".iqBranchInstsIssued")
2131062SN/A        .desc("Number of branch instructions issued")
2141062SN/A        .prereq(iqBranchInstsIssued);
2151062SN/A
2161062SN/A    iqMemInstsIssued
2171062SN/A        .name(name() + ".iqMemInstsIssued")
2181062SN/A        .desc("Number of memory instructions issued")
2191062SN/A        .prereq(iqMemInstsIssued);
2201062SN/A
2211062SN/A    iqMiscInstsIssued
2221062SN/A        .name(name() + ".iqMiscInstsIssued")
2231062SN/A        .desc("Number of miscellaneous instructions issued")
2241062SN/A        .prereq(iqMiscInstsIssued);
2251062SN/A
2261062SN/A    iqSquashedInstsIssued
2271062SN/A        .name(name() + ".iqSquashedInstsIssued")
2281062SN/A        .desc("Number of squashed instructions issued")
2291062SN/A        .prereq(iqSquashedInstsIssued);
2301062SN/A
2311062SN/A    iqSquashedInstsExamined
2321062SN/A        .name(name() + ".iqSquashedInstsExamined")
2331062SN/A        .desc("Number of squashed instructions iterated over during squash;"
2341062SN/A              " mainly for profiling")
2351062SN/A        .prereq(iqSquashedInstsExamined);
2361062SN/A
2371062SN/A    iqSquashedOperandsExamined
2381062SN/A        .name(name() + ".iqSquashedOperandsExamined")
2391062SN/A        .desc("Number of squashed operands that are examined and possibly "
2401062SN/A              "removed from graph")
2411062SN/A        .prereq(iqSquashedOperandsExamined);
2421062SN/A
2431062SN/A    iqSquashedNonSpecRemoved
2441062SN/A        .name(name() + ".iqSquashedNonSpecRemoved")
2451062SN/A        .desc("Number of squashed non-spec instructions that were removed")
2461062SN/A        .prereq(iqSquashedNonSpecRemoved);
2472361SN/A/*
2482326SN/A    queueResDist
2492301SN/A        .init(Num_OpClasses, 0, 99, 2)
2502301SN/A        .name(name() + ".IQ:residence:")
2512301SN/A        .desc("cycles from dispatch to issue")
2522301SN/A        .flags(total | pdf | cdf )
2532301SN/A        ;
2542301SN/A    for (int i = 0; i < Num_OpClasses; ++i) {
2552326SN/A        queueResDist.subname(i, opClassStrings[i]);
2562301SN/A    }
2572361SN/A*/
2582326SN/A    numIssuedDist
2592307SN/A        .init(0,totalWidth,1)
2608240Snate@binkert.org        .name(name() + ".issued_per_cycle")
2612301SN/A        .desc("Number of insts issued each cycle")
2622307SN/A        .flags(pdf)
2632301SN/A        ;
2642301SN/A/*
2652301SN/A    dist_unissued
2662301SN/A        .init(Num_OpClasses+2)
2678240Snate@binkert.org        .name(name() + ".unissued_cause")
2682301SN/A        .desc("Reason ready instruction not issued")
2692301SN/A        .flags(pdf | dist)
2702301SN/A        ;
2712301SN/A    for (int i=0; i < (Num_OpClasses + 2); ++i) {
2722301SN/A        dist_unissued.subname(i, unissued_names[i]);
2732301SN/A    }
2742301SN/A*/
2752326SN/A    statIssuedInstType
2764762Snate@binkert.org        .init(numThreads,Enums::Num_OpClass)
2778240Snate@binkert.org        .name(name() + ".FU_type")
2782301SN/A        .desc("Type of FU issued")
2792301SN/A        .flags(total | pdf | dist)
2802301SN/A        ;
2814762Snate@binkert.org    statIssuedInstType.ysubnames(Enums::OpClassStrings);
2822301SN/A
2832301SN/A    //
2842301SN/A    //  How long did instructions for a particular FU type wait prior to issue
2852301SN/A    //
2862361SN/A/*
2872326SN/A    issueDelayDist
2882301SN/A        .init(Num_OpClasses,0,99,2)
2898240Snate@binkert.org        .name(name() + ".")
2902301SN/A        .desc("cycles from operands ready to issue")
2912301SN/A        .flags(pdf | cdf)
2922301SN/A        ;
2932301SN/A
2942301SN/A    for (int i=0; i<Num_OpClasses; ++i) {
2952980Sgblack@eecs.umich.edu        std::stringstream subname;
2962301SN/A        subname << opClassStrings[i] << "_delay";
2972326SN/A        issueDelayDist.subname(i, subname.str());
2982301SN/A    }
2992361SN/A*/
3002326SN/A    issueRate
3018240Snate@binkert.org        .name(name() + ".rate")
3022301SN/A        .desc("Inst issue rate")
3032301SN/A        .flags(total)
3042301SN/A        ;
3052326SN/A    issueRate = iqInstsIssued / cpu->numCycles;
3062727Sktlim@umich.edu
3072326SN/A    statFuBusy
3082301SN/A        .init(Num_OpClasses)
3098240Snate@binkert.org        .name(name() + ".fu_full")
3102301SN/A        .desc("attempts to use FU when none available")
3112301SN/A        .flags(pdf | dist)
3122301SN/A        ;
3132301SN/A    for (int i=0; i < Num_OpClasses; ++i) {
3144762Snate@binkert.org        statFuBusy.subname(i, Enums::OpClassStrings[i]);
3152301SN/A    }
3162301SN/A
3172326SN/A    fuBusy
3182301SN/A        .init(numThreads)
3198240Snate@binkert.org        .name(name() + ".fu_busy_cnt")
3202301SN/A        .desc("FU busy when requested")
3212301SN/A        .flags(total)
3222301SN/A        ;
3232301SN/A
3242326SN/A    fuBusyRate
3258240Snate@binkert.org        .name(name() + ".fu_busy_rate")
3262301SN/A        .desc("FU busy rate (busy events/executed inst)")
3272301SN/A        .flags(total)
3282301SN/A        ;
3292326SN/A    fuBusyRate = fuBusy / iqInstsIssued;
3302301SN/A
3316221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
3322292SN/A        // Tell mem dependence unit to reg stats as well.
3336221Snate@binkert.org        memDepUnit[tid].regStats();
3342292SN/A    }
3357897Shestness@cs.utexas.edu
3367897Shestness@cs.utexas.edu    intInstQueueReads
3377897Shestness@cs.utexas.edu        .name(name() + ".int_inst_queue_reads")
3387897Shestness@cs.utexas.edu        .desc("Number of integer instruction queue reads")
3397897Shestness@cs.utexas.edu        .flags(total);
3407897Shestness@cs.utexas.edu
3417897Shestness@cs.utexas.edu    intInstQueueWrites
3427897Shestness@cs.utexas.edu        .name(name() + ".int_inst_queue_writes")
3437897Shestness@cs.utexas.edu        .desc("Number of integer instruction queue writes")
3447897Shestness@cs.utexas.edu        .flags(total);
3457897Shestness@cs.utexas.edu
3467897Shestness@cs.utexas.edu    intInstQueueWakeupAccesses
3477897Shestness@cs.utexas.edu        .name(name() + ".int_inst_queue_wakeup_accesses")
3487897Shestness@cs.utexas.edu        .desc("Number of integer instruction queue wakeup accesses")
3497897Shestness@cs.utexas.edu        .flags(total);
3507897Shestness@cs.utexas.edu
3517897Shestness@cs.utexas.edu    fpInstQueueReads
3527897Shestness@cs.utexas.edu        .name(name() + ".fp_inst_queue_reads")
3537897Shestness@cs.utexas.edu        .desc("Number of floating instruction queue reads")
3547897Shestness@cs.utexas.edu        .flags(total);
3557897Shestness@cs.utexas.edu
3567897Shestness@cs.utexas.edu    fpInstQueueWrites
3577897Shestness@cs.utexas.edu        .name(name() + ".fp_inst_queue_writes")
3587897Shestness@cs.utexas.edu        .desc("Number of floating instruction queue writes")
3597897Shestness@cs.utexas.edu        .flags(total);
3607897Shestness@cs.utexas.edu
3617897Shestness@cs.utexas.edu    fpInstQueueWakeupQccesses
3627897Shestness@cs.utexas.edu        .name(name() + ".fp_inst_queue_wakeup_accesses")
3637897Shestness@cs.utexas.edu        .desc("Number of floating instruction queue wakeup accesses")
3647897Shestness@cs.utexas.edu        .flags(total);
3657897Shestness@cs.utexas.edu
3667897Shestness@cs.utexas.edu    intAluAccesses
3677897Shestness@cs.utexas.edu        .name(name() + ".int_alu_accesses")
3687897Shestness@cs.utexas.edu        .desc("Number of integer alu accesses")
3697897Shestness@cs.utexas.edu        .flags(total);
3707897Shestness@cs.utexas.edu
3717897Shestness@cs.utexas.edu    fpAluAccesses
3727897Shestness@cs.utexas.edu        .name(name() + ".fp_alu_accesses")
3737897Shestness@cs.utexas.edu        .desc("Number of floating point alu accesses")
3747897Shestness@cs.utexas.edu        .flags(total);
3757897Shestness@cs.utexas.edu
3761062SN/A}
3771062SN/A
3781062SN/Atemplate <class Impl>
3791062SN/Avoid
3802307SN/AInstructionQueue<Impl>::resetState()
3811060SN/A{
3822307SN/A    //Initialize thread IQ counts
3836221Snate@binkert.org    for (ThreadID tid = 0; tid <numThreads; tid++) {
3846221Snate@binkert.org        count[tid] = 0;
3856221Snate@binkert.org        instList[tid].clear();
3862307SN/A    }
3871060SN/A
3882307SN/A    // Initialize the number of free IQ entries.
3892307SN/A    freeEntries = numEntries;
3902307SN/A
3912307SN/A    // Note that in actuality, the registers corresponding to the logical
3922307SN/A    // registers start off as ready.  However this doesn't matter for the
3932307SN/A    // IQ as the instruction should have been correctly told if those
3942307SN/A    // registers are ready in rename.  Thus it can all be initialized as
3952307SN/A    // unready.
3962307SN/A    for (int i = 0; i < numPhysRegs; ++i) {
3972307SN/A        regScoreboard[i] = false;
3982307SN/A    }
3992307SN/A
4006221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; ++tid) {
4016221Snate@binkert.org        squashedSeqNum[tid] = 0;
4022307SN/A    }
4032307SN/A
4042307SN/A    for (int i = 0; i < Num_OpClasses; ++i) {
4052307SN/A        while (!readyInsts[i].empty())
4062307SN/A            readyInsts[i].pop();
4072307SN/A        queueOnList[i] = false;
4082307SN/A        readyIt[i] = listOrder.end();
4092307SN/A    }
4102307SN/A    nonSpecInsts.clear();
4112307SN/A    listOrder.clear();
4127944SGiacomo.Gabrielli@arm.com    deferredMemInsts.clear();
4131060SN/A}
4141060SN/A
4151061SN/Atemplate <class Impl>
4161060SN/Avoid
4176221Snate@binkert.orgInstructionQueue<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
4181060SN/A{
4192292SN/A    activeThreads = at_ptr;
4202064SN/A}
4212064SN/A
4222064SN/Atemplate <class Impl>
4232064SN/Avoid
4242292SN/AInstructionQueue<Impl>::setIssueToExecuteQueue(TimeBuffer<IssueStruct> *i2e_ptr)
4252064SN/A{
4264318Sktlim@umich.edu      issueToExecuteQueue = i2e_ptr;
4271060SN/A}
4281060SN/A
4291061SN/Atemplate <class Impl>
4301060SN/Avoid
4311060SN/AInstructionQueue<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
4321060SN/A{
4331060SN/A    timeBuffer = tb_ptr;
4341060SN/A
4351060SN/A    fromCommit = timeBuffer->getWire(-commitToIEWDelay);
4361060SN/A}
4371060SN/A
4381684SN/Atemplate <class Impl>
4392307SN/Avoid
4402307SN/AInstructionQueue<Impl>::switchOut()
4412307SN/A{
4422367SN/A/*
4432367SN/A    if (!instList[0].empty() || (numEntries != freeEntries) ||
4442367SN/A        !readyInsts[0].empty() || !nonSpecInsts.empty() || !listOrder.empty()) {
4452367SN/A        dumpInsts();
4462367SN/A//        assert(0);
4472367SN/A    }
4482367SN/A*/
4492307SN/A    resetState();
4502326SN/A    dependGraph.reset();
4512367SN/A    instsToExecute.clear();
4522307SN/A    switchedOut = true;
4536221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; ++tid) {
4546221Snate@binkert.org        memDepUnit[tid].switchOut();
4552307SN/A    }
4562307SN/A}
4572307SN/A
4582307SN/Atemplate <class Impl>
4592307SN/Avoid
4602307SN/AInstructionQueue<Impl>::takeOverFrom()
4612307SN/A{
4622307SN/A    switchedOut = false;
4632307SN/A}
4642307SN/A
4652307SN/Atemplate <class Impl>
4662292SN/Aint
4676221Snate@binkert.orgInstructionQueue<Impl>::entryAmount(ThreadID num_threads)
4682292SN/A{
4692292SN/A    if (iqPolicy == Partitioned) {
4702292SN/A        return numEntries / num_threads;
4712292SN/A    } else {
4722292SN/A        return 0;
4732292SN/A    }
4742292SN/A}
4752292SN/A
4762292SN/A
4772292SN/Atemplate <class Impl>
4782292SN/Avoid
4792292SN/AInstructionQueue<Impl>::resetEntries()
4802292SN/A{
4812292SN/A    if (iqPolicy != Dynamic || numThreads > 1) {
4823867Sbinkertn@umich.edu        int active_threads = activeThreads->size();
4832292SN/A
4846221Snate@binkert.org        list<ThreadID>::iterator threads = activeThreads->begin();
4856221Snate@binkert.org        list<ThreadID>::iterator end = activeThreads->end();
4862292SN/A
4873867Sbinkertn@umich.edu        while (threads != end) {
4886221Snate@binkert.org            ThreadID tid = *threads++;
4893867Sbinkertn@umich.edu
4902292SN/A            if (iqPolicy == Partitioned) {
4913867Sbinkertn@umich.edu                maxEntries[tid] = numEntries / active_threads;
4922292SN/A            } else if(iqPolicy == Threshold && active_threads == 1) {
4933867Sbinkertn@umich.edu                maxEntries[tid] = numEntries;
4942292SN/A            }
4952292SN/A        }
4962292SN/A    }
4972292SN/A}
4982292SN/A
4992292SN/Atemplate <class Impl>
5001684SN/Aunsigned
5011684SN/AInstructionQueue<Impl>::numFreeEntries()
5021684SN/A{
5031684SN/A    return freeEntries;
5041684SN/A}
5051684SN/A
5062292SN/Atemplate <class Impl>
5072292SN/Aunsigned
5086221Snate@binkert.orgInstructionQueue<Impl>::numFreeEntries(ThreadID tid)
5092292SN/A{
5102292SN/A    return maxEntries[tid] - count[tid];
5112292SN/A}
5122292SN/A
5131060SN/A// Might want to do something more complex if it knows how many instructions
5141060SN/A// will be issued this cycle.
5151061SN/Atemplate <class Impl>
5161060SN/Abool
5171060SN/AInstructionQueue<Impl>::isFull()
5181060SN/A{
5191060SN/A    if (freeEntries == 0) {
5201060SN/A        return(true);
5211060SN/A    } else {
5221060SN/A        return(false);
5231060SN/A    }
5241060SN/A}
5251060SN/A
5261061SN/Atemplate <class Impl>
5272292SN/Abool
5286221Snate@binkert.orgInstructionQueue<Impl>::isFull(ThreadID tid)
5292292SN/A{
5302292SN/A    if (numFreeEntries(tid) == 0) {
5312292SN/A        return(true);
5322292SN/A    } else {
5332292SN/A        return(false);
5342292SN/A    }
5352292SN/A}
5362292SN/A
5372292SN/Atemplate <class Impl>
5382292SN/Abool
5392292SN/AInstructionQueue<Impl>::hasReadyInsts()
5402292SN/A{
5412292SN/A    if (!listOrder.empty()) {
5422292SN/A        return true;
5432292SN/A    }
5442292SN/A
5452292SN/A    for (int i = 0; i < Num_OpClasses; ++i) {
5462292SN/A        if (!readyInsts[i].empty()) {
5472292SN/A            return true;
5482292SN/A        }
5492292SN/A    }
5502292SN/A
5512292SN/A    return false;
5522292SN/A}
5532292SN/A
5542292SN/Atemplate <class Impl>
5551060SN/Avoid
5561061SN/AInstructionQueue<Impl>::insert(DynInstPtr &new_inst)
5571060SN/A{
5587897Shestness@cs.utexas.edu    new_inst->isFloating() ? fpInstQueueWrites++ : intInstQueueWrites++;
5591060SN/A    // Make sure the instruction is valid
5601060SN/A    assert(new_inst);
5611060SN/A
5627720Sgblack@eecs.umich.edu    DPRINTF(IQ, "Adding instruction [sn:%lli] PC %s to the IQ.\n",
5637720Sgblack@eecs.umich.edu            new_inst->seqNum, new_inst->pcState());
5641060SN/A
5651060SN/A    assert(freeEntries != 0);
5661060SN/A
5672292SN/A    instList[new_inst->threadNumber].push_back(new_inst);
5681060SN/A
5692064SN/A    --freeEntries;
5701060SN/A
5712292SN/A    new_inst->setInIQ();
5721060SN/A
5731060SN/A    // Look through its source registers (physical regs), and mark any
5741060SN/A    // dependencies.
5751060SN/A    addToDependents(new_inst);
5761060SN/A
5771060SN/A    // Have this instruction set itself as the producer of its destination
5781060SN/A    // register(s).
5792326SN/A    addToProducers(new_inst);
5801060SN/A
5811061SN/A    if (new_inst->isMemRef()) {
5822292SN/A        memDepUnit[new_inst->threadNumber].insert(new_inst);
5831062SN/A    } else {
5841062SN/A        addIfReady(new_inst);
5851061SN/A    }
5861061SN/A
5871062SN/A    ++iqInstsAdded;
5881060SN/A
5892292SN/A    count[new_inst->threadNumber]++;
5902292SN/A
5911060SN/A    assert(freeEntries == (numEntries - countInsts()));
5921060SN/A}
5931060SN/A
5941061SN/Atemplate <class Impl>
5951061SN/Avoid
5962292SN/AInstructionQueue<Impl>::insertNonSpec(DynInstPtr &new_inst)
5971061SN/A{
5981061SN/A    // @todo: Clean up this code; can do it by setting inst as unable
5991061SN/A    // to issue, then calling normal insert on the inst.
6007897Shestness@cs.utexas.edu    new_inst->isFloating() ? fpInstQueueWrites++ : intInstQueueWrites++;
6011061SN/A
6022292SN/A    assert(new_inst);
6031061SN/A
6042292SN/A    nonSpecInsts[new_inst->seqNum] = new_inst;
6051061SN/A
6067720Sgblack@eecs.umich.edu    DPRINTF(IQ, "Adding non-speculative instruction [sn:%lli] PC %s "
6072326SN/A            "to the IQ.\n",
6087720Sgblack@eecs.umich.edu            new_inst->seqNum, new_inst->pcState());
6092064SN/A
6101061SN/A    assert(freeEntries != 0);
6111061SN/A
6122292SN/A    instList[new_inst->threadNumber].push_back(new_inst);
6131061SN/A
6142064SN/A    --freeEntries;
6151061SN/A
6162292SN/A    new_inst->setInIQ();
6171061SN/A
6181061SN/A    // Have this instruction set itself as the producer of its destination
6191061SN/A    // register(s).
6202326SN/A    addToProducers(new_inst);
6211061SN/A
6221061SN/A    // If it's a memory instruction, add it to the memory dependency
6231061SN/A    // unit.
6242292SN/A    if (new_inst->isMemRef()) {
6252292SN/A        memDepUnit[new_inst->threadNumber].insertNonSpec(new_inst);
6261061SN/A    }
6271062SN/A
6281062SN/A    ++iqNonSpecInstsAdded;
6292292SN/A
6302292SN/A    count[new_inst->threadNumber]++;
6312292SN/A
6322292SN/A    assert(freeEntries == (numEntries - countInsts()));
6331061SN/A}
6341061SN/A
6351061SN/Atemplate <class Impl>
6361060SN/Avoid
6372292SN/AInstructionQueue<Impl>::insertBarrier(DynInstPtr &barr_inst)
6381060SN/A{
6392292SN/A    memDepUnit[barr_inst->threadNumber].insertBarrier(barr_inst);
6401060SN/A
6412292SN/A    insertNonSpec(barr_inst);
6422292SN/A}
6431060SN/A
6442064SN/Atemplate <class Impl>
6452333SN/Atypename Impl::DynInstPtr
6462333SN/AInstructionQueue<Impl>::getInstToExecute()
6472333SN/A{
6482333SN/A    assert(!instsToExecute.empty());
6492333SN/A    DynInstPtr inst = instsToExecute.front();
6502333SN/A    instsToExecute.pop_front();
6517897Shestness@cs.utexas.edu    if (inst->isFloating()){
6527897Shestness@cs.utexas.edu        fpInstQueueReads++;
6537897Shestness@cs.utexas.edu    } else {
6547897Shestness@cs.utexas.edu        intInstQueueReads++;
6557897Shestness@cs.utexas.edu    }
6562333SN/A    return inst;
6572333SN/A}
6581060SN/A
6592333SN/Atemplate <class Impl>
6602064SN/Avoid
6612292SN/AInstructionQueue<Impl>::addToOrderList(OpClass op_class)
6622292SN/A{
6632292SN/A    assert(!readyInsts[op_class].empty());
6642292SN/A
6652292SN/A    ListOrderEntry queue_entry;
6662292SN/A
6672292SN/A    queue_entry.queueType = op_class;
6682292SN/A
6692292SN/A    queue_entry.oldestInst = readyInsts[op_class].top()->seqNum;
6702292SN/A
6712292SN/A    ListOrderIt list_it = listOrder.begin();
6722292SN/A    ListOrderIt list_end_it = listOrder.end();
6732292SN/A
6742292SN/A    while (list_it != list_end_it) {
6752292SN/A        if ((*list_it).oldestInst > queue_entry.oldestInst) {
6762292SN/A            break;
6772292SN/A        }
6782292SN/A
6792292SN/A        list_it++;
6801060SN/A    }
6811060SN/A
6822292SN/A    readyIt[op_class] = listOrder.insert(list_it, queue_entry);
6832292SN/A    queueOnList[op_class] = true;
6842292SN/A}
6851060SN/A
6862292SN/Atemplate <class Impl>
6872292SN/Avoid
6882292SN/AInstructionQueue<Impl>::moveToYoungerInst(ListOrderIt list_order_it)
6892292SN/A{
6902292SN/A    // Get iterator of next item on the list
6912292SN/A    // Delete the original iterator
6922292SN/A    // Determine if the next item is either the end of the list or younger
6932292SN/A    // than the new instruction.  If so, then add in a new iterator right here.
6942292SN/A    // If not, then move along.
6952292SN/A    ListOrderEntry queue_entry;
6962292SN/A    OpClass op_class = (*list_order_it).queueType;
6972292SN/A    ListOrderIt next_it = list_order_it;
6982292SN/A
6992292SN/A    ++next_it;
7002292SN/A
7012292SN/A    queue_entry.queueType = op_class;
7022292SN/A    queue_entry.oldestInst = readyInsts[op_class].top()->seqNum;
7032292SN/A
7042292SN/A    while (next_it != listOrder.end() &&
7052292SN/A           (*next_it).oldestInst < queue_entry.oldestInst) {
7062292SN/A        ++next_it;
7071060SN/A    }
7081060SN/A
7092292SN/A    readyIt[op_class] = listOrder.insert(next_it, queue_entry);
7101060SN/A}
7111060SN/A
7122292SN/Atemplate <class Impl>
7132292SN/Avoid
7142292SN/AInstructionQueue<Impl>::processFUCompletion(DynInstPtr &inst, int fu_idx)
7152292SN/A{
7162367SN/A    DPRINTF(IQ, "Processing FU completion [sn:%lli]\n", inst->seqNum);
7172292SN/A    // The CPU could have been sleeping until this op completed (*extremely*
7182292SN/A    // long latency op).  Wake it if it was.  This may be overkill.
7192307SN/A    if (isSwitchedOut()) {
7202367SN/A        DPRINTF(IQ, "FU completion not processed, IQ is switched out [sn:%lli]\n",
7212367SN/A                inst->seqNum);
7222307SN/A        return;
7232307SN/A    }
7242307SN/A
7252292SN/A    iewStage->wakeCPU();
7262292SN/A
7272326SN/A    if (fu_idx > -1)
7282326SN/A        fuPool->freeUnitNextCycle(fu_idx);
7292292SN/A
7302326SN/A    // @todo: Ensure that these FU Completions happen at the beginning
7312326SN/A    // of a cycle, otherwise they could add too many instructions to
7322326SN/A    // the queue.
7335327Smengke97@hotmail.com    issueToExecuteQueue->access(-1)->size++;
7342333SN/A    instsToExecute.push_back(inst);
7352292SN/A}
7362292SN/A
7371061SN/A// @todo: Figure out a better way to remove the squashed items from the
7381061SN/A// lists.  Checking the top item of each list to see if it's squashed
7391061SN/A// wastes time and forces jumps.
7401061SN/Atemplate <class Impl>
7411060SN/Avoid
7421060SN/AInstructionQueue<Impl>::scheduleReadyInsts()
7431060SN/A{
7442292SN/A    DPRINTF(IQ, "Attempting to schedule ready instructions from "
7452292SN/A            "the IQ.\n");
7461060SN/A
7471060SN/A    IssueStruct *i2e_info = issueToExecuteQueue->access(0);
7481060SN/A
7497944SGiacomo.Gabrielli@arm.com    DynInstPtr deferred_mem_inst;
7507944SGiacomo.Gabrielli@arm.com    int total_deferred_mem_issued = 0;
7517944SGiacomo.Gabrielli@arm.com    while (total_deferred_mem_issued < totalWidth &&
7527962Ssaidi@eecs.umich.edu           (deferred_mem_inst = getDeferredMemInstToExecute()) != 0) {
7537944SGiacomo.Gabrielli@arm.com        issueToExecuteQueue->access(0)->size++;
7547944SGiacomo.Gabrielli@arm.com        instsToExecute.push_back(deferred_mem_inst);
7557944SGiacomo.Gabrielli@arm.com        total_deferred_mem_issued++;
7567944SGiacomo.Gabrielli@arm.com    }
7577944SGiacomo.Gabrielli@arm.com
7582292SN/A    // Have iterator to head of the list
7592292SN/A    // While I haven't exceeded bandwidth or reached the end of the list,
7602292SN/A    // Try to get a FU that can do what this op needs.
7612292SN/A    // If successful, change the oldestInst to the new top of the list, put
7622292SN/A    // the queue in the proper place in the list.
7632292SN/A    // Increment the iterator.
7642292SN/A    // This will avoid trying to schedule a certain op class if there are no
7652292SN/A    // FUs that handle it.
7662292SN/A    ListOrderIt order_it = listOrder.begin();
7672292SN/A    ListOrderIt order_end_it = listOrder.end();
7682292SN/A    int total_issued = 0;
7691060SN/A
7707944SGiacomo.Gabrielli@arm.com    while (total_issued < (totalWidth - total_deferred_mem_issued) &&
7712820Sktlim@umich.edu           iewStage->canIssue() &&
7722326SN/A           order_it != order_end_it) {
7732292SN/A        OpClass op_class = (*order_it).queueType;
7741060SN/A
7752292SN/A        assert(!readyInsts[op_class].empty());
7761060SN/A
7772292SN/A        DynInstPtr issuing_inst = readyInsts[op_class].top();
7781060SN/A
7797897Shestness@cs.utexas.edu        issuing_inst->isFloating() ? fpInstQueueReads++ : intInstQueueReads++;
7807897Shestness@cs.utexas.edu
7812292SN/A        assert(issuing_inst->seqNum == (*order_it).oldestInst);
7821060SN/A
7832292SN/A        if (issuing_inst->isSquashed()) {
7842292SN/A            readyInsts[op_class].pop();
7851060SN/A
7862292SN/A            if (!readyInsts[op_class].empty()) {
7872292SN/A                moveToYoungerInst(order_it);
7882292SN/A            } else {
7892292SN/A                readyIt[op_class] = listOrder.end();
7902292SN/A                queueOnList[op_class] = false;
7911060SN/A            }
7921060SN/A
7932292SN/A            listOrder.erase(order_it++);
7941060SN/A
7952292SN/A            ++iqSquashedInstsIssued;
7962292SN/A
7972292SN/A            continue;
7981060SN/A        }
7991060SN/A
8002326SN/A        int idx = -2;
8012326SN/A        int op_latency = 1;
8026221Snate@binkert.org        ThreadID tid = issuing_inst->threadNumber;
8031060SN/A
8042326SN/A        if (op_class != No_OpClass) {
8052326SN/A            idx = fuPool->getUnit(op_class);
8067897Shestness@cs.utexas.edu            issuing_inst->isFloating() ? fpAluAccesses++ : intAluAccesses++;
8072326SN/A            if (idx > -1) {
8082326SN/A                op_latency = fuPool->getOpLatency(op_class);
8091060SN/A            }
8101060SN/A        }
8111060SN/A
8122348SN/A        // If we have an instruction that doesn't require a FU, or a
8132348SN/A        // valid FU, then schedule for execution.
8142326SN/A        if (idx == -2 || idx != -1) {
8152292SN/A            if (op_latency == 1) {
8162292SN/A                i2e_info->size++;
8172333SN/A                instsToExecute.push_back(issuing_inst);
8181060SN/A
8192326SN/A                // Add the FU onto the list of FU's to be freed next
8202326SN/A                // cycle if we used one.
8212326SN/A                if (idx >= 0)
8222326SN/A                    fuPool->freeUnitNextCycle(idx);
8232292SN/A            } else {
8242292SN/A                int issue_latency = fuPool->getIssueLatency(op_class);
8252326SN/A                // Generate completion event for the FU
8262326SN/A                FUCompletion *execution = new FUCompletion(issuing_inst,
8272326SN/A                                                           idx, this);
8281060SN/A
8297823Ssteve.reinhardt@amd.com                cpu->schedule(execution, curTick() + cpu->ticks(op_latency - 1));
8301060SN/A
8312326SN/A                // @todo: Enforce that issue_latency == 1 or op_latency
8322292SN/A                if (issue_latency > 1) {
8332348SN/A                    // If FU isn't pipelined, then it must be freed
8342348SN/A                    // upon the execution completing.
8352326SN/A                    execution->setFreeFU();
8362292SN/A                } else {
8372292SN/A                    // Add the FU onto the list of FU's to be freed next cycle.
8382326SN/A                    fuPool->freeUnitNextCycle(idx);
8392292SN/A                }
8401060SN/A            }
8411060SN/A
8427720Sgblack@eecs.umich.edu            DPRINTF(IQ, "Thread %i: Issuing instruction PC %s "
8432292SN/A                    "[sn:%lli]\n",
8447720Sgblack@eecs.umich.edu                    tid, issuing_inst->pcState(),
8452292SN/A                    issuing_inst->seqNum);
8461060SN/A
8472292SN/A            readyInsts[op_class].pop();
8481061SN/A
8492292SN/A            if (!readyInsts[op_class].empty()) {
8502292SN/A                moveToYoungerInst(order_it);
8512292SN/A            } else {
8522292SN/A                readyIt[op_class] = listOrder.end();
8532292SN/A                queueOnList[op_class] = false;
8541060SN/A            }
8551060SN/A
8562064SN/A            issuing_inst->setIssued();
8572292SN/A            ++total_issued;
8582064SN/A
8598471SGiacomo.Gabrielli@arm.com#if TRACING_ON
8608471SGiacomo.Gabrielli@arm.com            issuing_inst->issueTick = curTick();
8618471SGiacomo.Gabrielli@arm.com#endif
8628471SGiacomo.Gabrielli@arm.com
8632292SN/A            if (!issuing_inst->isMemRef()) {
8642292SN/A                // Memory instructions can not be freed from the IQ until they
8652292SN/A                // complete.
8662292SN/A                ++freeEntries;
8672301SN/A                count[tid]--;
8682731Sktlim@umich.edu                issuing_inst->clearInIQ();
8692292SN/A            } else {
8702301SN/A                memDepUnit[tid].issue(issuing_inst);
8712292SN/A            }
8722292SN/A
8732292SN/A            listOrder.erase(order_it++);
8742326SN/A            statIssuedInstType[tid][op_class]++;
8752820Sktlim@umich.edu            iewStage->incrWb(issuing_inst->seqNum);
8762292SN/A        } else {
8772326SN/A            statFuBusy[op_class]++;
8782326SN/A            fuBusy[tid]++;
8792292SN/A            ++order_it;
8801060SN/A        }
8811060SN/A    }
8821062SN/A
8832326SN/A    numIssuedDist.sample(total_issued);
8842326SN/A    iqInstsIssued+= total_issued;
8852307SN/A
8862348SN/A    // If we issued any instructions, tell the CPU we had activity.
8878071SAli.Saidi@ARM.com    // @todo If the way deferred memory instructions are handeled due to
8888071SAli.Saidi@ARM.com    // translation changes then the deferredMemInsts condition should be removed
8898071SAli.Saidi@ARM.com    // from the code below.
8908071SAli.Saidi@ARM.com    if (total_issued || total_deferred_mem_issued || deferredMemInsts.size()) {
8912292SN/A        cpu->activityThisCycle();
8922292SN/A    } else {
8932292SN/A        DPRINTF(IQ, "Not able to schedule any instructions.\n");
8942292SN/A    }
8951060SN/A}
8961060SN/A
8971061SN/Atemplate <class Impl>
8981060SN/Avoid
8991061SN/AInstructionQueue<Impl>::scheduleNonSpec(const InstSeqNum &inst)
9001060SN/A{
9012292SN/A    DPRINTF(IQ, "Marking nonspeculative instruction [sn:%lli] as ready "
9022292SN/A            "to execute.\n", inst);
9031062SN/A
9042292SN/A    NonSpecMapIt inst_it = nonSpecInsts.find(inst);
9051060SN/A
9061061SN/A    assert(inst_it != nonSpecInsts.end());
9071060SN/A
9086221Snate@binkert.org    ThreadID tid = (*inst_it).second->threadNumber;
9092292SN/A
9104033Sktlim@umich.edu    (*inst_it).second->setAtCommit();
9114033Sktlim@umich.edu
9121061SN/A    (*inst_it).second->setCanIssue();
9131060SN/A
9141062SN/A    if (!(*inst_it).second->isMemRef()) {
9151062SN/A        addIfReady((*inst_it).second);
9161062SN/A    } else {
9172292SN/A        memDepUnit[tid].nonSpecInstReady((*inst_it).second);
9181062SN/A    }
9191060SN/A
9202292SN/A    (*inst_it).second = NULL;
9212292SN/A
9221061SN/A    nonSpecInsts.erase(inst_it);
9231060SN/A}
9241060SN/A
9251061SN/Atemplate <class Impl>
9261061SN/Avoid
9276221Snate@binkert.orgInstructionQueue<Impl>::commit(const InstSeqNum &inst, ThreadID tid)
9282292SN/A{
9292292SN/A    DPRINTF(IQ, "[tid:%i]: Committing instructions older than [sn:%i]\n",
9302292SN/A            tid,inst);
9312292SN/A
9322292SN/A    ListIt iq_it = instList[tid].begin();
9332292SN/A
9342292SN/A    while (iq_it != instList[tid].end() &&
9352292SN/A           (*iq_it)->seqNum <= inst) {
9362292SN/A        ++iq_it;
9372292SN/A        instList[tid].pop_front();
9382292SN/A    }
9392292SN/A
9402292SN/A    assert(freeEntries == (numEntries - countInsts()));
9412292SN/A}
9422292SN/A
9432292SN/Atemplate <class Impl>
9442301SN/Aint
9451684SN/AInstructionQueue<Impl>::wakeDependents(DynInstPtr &completed_inst)
9461684SN/A{
9472301SN/A    int dependents = 0;
9482301SN/A
9497897Shestness@cs.utexas.edu    // The instruction queue here takes care of both floating and int ops
9507897Shestness@cs.utexas.edu    if (completed_inst->isFloating()) {
9517897Shestness@cs.utexas.edu        fpInstQueueWakeupQccesses++;
9527897Shestness@cs.utexas.edu    } else {
9537897Shestness@cs.utexas.edu        intInstQueueWakeupAccesses++;
9547897Shestness@cs.utexas.edu    }
9557897Shestness@cs.utexas.edu
9562292SN/A    DPRINTF(IQ, "Waking dependents of completed instruction.\n");
9572292SN/A
9582292SN/A    assert(!completed_inst->isSquashed());
9591684SN/A
9601684SN/A    // Tell the memory dependence unit to wake any dependents on this
9612292SN/A    // instruction if it is a memory instruction.  Also complete the memory
9622326SN/A    // instruction at this point since we know it executed without issues.
9632326SN/A    // @todo: Might want to rename "completeMemInst" to something that
9642326SN/A    // indicates that it won't need to be replayed, and call this
9652326SN/A    // earlier.  Might not be a big deal.
9661684SN/A    if (completed_inst->isMemRef()) {
9672292SN/A        memDepUnit[completed_inst->threadNumber].wakeDependents(completed_inst);
9682292SN/A        completeMemInst(completed_inst);
9692292SN/A    } else if (completed_inst->isMemBarrier() ||
9702292SN/A               completed_inst->isWriteBarrier()) {
9712292SN/A        memDepUnit[completed_inst->threadNumber].completeBarrier(completed_inst);
9721684SN/A    }
9731684SN/A
9741684SN/A    for (int dest_reg_idx = 0;
9751684SN/A         dest_reg_idx < completed_inst->numDestRegs();
9761684SN/A         dest_reg_idx++)
9771684SN/A    {
9781684SN/A        PhysRegIndex dest_reg =
9791684SN/A            completed_inst->renamedDestRegIdx(dest_reg_idx);
9801684SN/A
9811684SN/A        // Special case of uniq or control registers.  They are not
9821684SN/A        // handled by the IQ and thus have no dependency graph entry.
9831684SN/A        // @todo Figure out a cleaner way to handle this.
9841684SN/A        if (dest_reg >= numPhysRegs) {
9857599Sminkyu.jeong@arm.com            DPRINTF(IQ, "dest_reg :%d, numPhysRegs: %d\n", dest_reg,
9867599Sminkyu.jeong@arm.com                    numPhysRegs);
9871684SN/A            continue;
9881684SN/A        }
9891684SN/A
9902292SN/A        DPRINTF(IQ, "Waking any dependents on register %i.\n",
9911684SN/A                (int) dest_reg);
9921684SN/A
9932326SN/A        //Go through the dependency chain, marking the registers as
9942326SN/A        //ready within the waiting instructions.
9952326SN/A        DynInstPtr dep_inst = dependGraph.pop(dest_reg);
9961684SN/A
9972326SN/A        while (dep_inst) {
9987599Sminkyu.jeong@arm.com            DPRINTF(IQ, "Waking up a dependent instruction, [sn:%lli] "
9997720Sgblack@eecs.umich.edu                    "PC %s.\n", dep_inst->seqNum, dep_inst->pcState());
10001684SN/A
10011684SN/A            // Might want to give more information to the instruction
10022326SN/A            // so that it knows which of its source registers is
10032326SN/A            // ready.  However that would mean that the dependency
10042326SN/A            // graph entries would need to hold the src_reg_idx.
10052326SN/A            dep_inst->markSrcRegReady();
10061684SN/A
10072326SN/A            addIfReady(dep_inst);
10081684SN/A
10092326SN/A            dep_inst = dependGraph.pop(dest_reg);
10101684SN/A
10112301SN/A            ++dependents;
10121684SN/A        }
10131684SN/A
10142326SN/A        // Reset the head node now that all of its dependents have
10152326SN/A        // been woken up.
10162326SN/A        assert(dependGraph.empty(dest_reg));
10172326SN/A        dependGraph.clearInst(dest_reg);
10181684SN/A
10191684SN/A        // Mark the scoreboard as having that register ready.
10201684SN/A        regScoreboard[dest_reg] = true;
10211684SN/A    }
10222301SN/A    return dependents;
10232064SN/A}
10242064SN/A
10252064SN/Atemplate <class Impl>
10262064SN/Avoid
10272292SN/AInstructionQueue<Impl>::addReadyMemInst(DynInstPtr &ready_inst)
10282064SN/A{
10292292SN/A    OpClass op_class = ready_inst->opClass();
10302292SN/A
10312292SN/A    readyInsts[op_class].push(ready_inst);
10322292SN/A
10332326SN/A    // Will need to reorder the list if either a queue is not on the list,
10342326SN/A    // or it has an older instruction than last time.
10352326SN/A    if (!queueOnList[op_class]) {
10362326SN/A        addToOrderList(op_class);
10372326SN/A    } else if (readyInsts[op_class].top()->seqNum  <
10382326SN/A               (*readyIt[op_class]).oldestInst) {
10392326SN/A        listOrder.erase(readyIt[op_class]);
10402326SN/A        addToOrderList(op_class);
10412326SN/A    }
10422326SN/A
10432292SN/A    DPRINTF(IQ, "Instruction is ready to issue, putting it onto "
10447720Sgblack@eecs.umich.edu            "the ready list, PC %s opclass:%i [sn:%lli].\n",
10457720Sgblack@eecs.umich.edu            ready_inst->pcState(), op_class, ready_inst->seqNum);
10462064SN/A}
10472064SN/A
10482064SN/Atemplate <class Impl>
10492064SN/Avoid
10502292SN/AInstructionQueue<Impl>::rescheduleMemInst(DynInstPtr &resched_inst)
10512064SN/A{
10524033Sktlim@umich.edu    DPRINTF(IQ, "Rescheduling mem inst [sn:%lli]\n", resched_inst->seqNum);
10537944SGiacomo.Gabrielli@arm.com
10547944SGiacomo.Gabrielli@arm.com    // Reset DTB translation state
10557944SGiacomo.Gabrielli@arm.com    resched_inst->translationStarted = false;
10567944SGiacomo.Gabrielli@arm.com    resched_inst->translationCompleted = false;
10577944SGiacomo.Gabrielli@arm.com
10584033Sktlim@umich.edu    resched_inst->clearCanIssue();
10592292SN/A    memDepUnit[resched_inst->threadNumber].reschedule(resched_inst);
10602064SN/A}
10612064SN/A
10622064SN/Atemplate <class Impl>
10632064SN/Avoid
10642292SN/AInstructionQueue<Impl>::replayMemInst(DynInstPtr &replay_inst)
10652064SN/A{
10662292SN/A    memDepUnit[replay_inst->threadNumber].replay(replay_inst);
10672292SN/A}
10682292SN/A
10692292SN/Atemplate <class Impl>
10702292SN/Avoid
10712292SN/AInstructionQueue<Impl>::completeMemInst(DynInstPtr &completed_inst)
10722292SN/A{
10736221Snate@binkert.org    ThreadID tid = completed_inst->threadNumber;
10742292SN/A
10757720Sgblack@eecs.umich.edu    DPRINTF(IQ, "Completing mem instruction PC: %s [sn:%lli]\n",
10767720Sgblack@eecs.umich.edu            completed_inst->pcState(), completed_inst->seqNum);
10772292SN/A
10782292SN/A    ++freeEntries;
10792292SN/A
10802292SN/A    completed_inst->memOpDone = true;
10812292SN/A
10822292SN/A    memDepUnit[tid].completed(completed_inst);
10832292SN/A    count[tid]--;
10841684SN/A}
10851684SN/A
10861684SN/Atemplate <class Impl>
10871684SN/Avoid
10887944SGiacomo.Gabrielli@arm.comInstructionQueue<Impl>::deferMemInst(DynInstPtr &deferred_inst)
10897944SGiacomo.Gabrielli@arm.com{
10907944SGiacomo.Gabrielli@arm.com    deferredMemInsts.push_back(deferred_inst);
10917944SGiacomo.Gabrielli@arm.com}
10927944SGiacomo.Gabrielli@arm.com
10937944SGiacomo.Gabrielli@arm.comtemplate <class Impl>
10947944SGiacomo.Gabrielli@arm.comtypename Impl::DynInstPtr
10957944SGiacomo.Gabrielli@arm.comInstructionQueue<Impl>::getDeferredMemInstToExecute()
10967944SGiacomo.Gabrielli@arm.com{
10977944SGiacomo.Gabrielli@arm.com    for (ListIt it = deferredMemInsts.begin(); it != deferredMemInsts.end();
10987944SGiacomo.Gabrielli@arm.com         ++it) {
10998489Sgblack@eecs.umich.edu        if ((*it)->translationCompleted || (*it)->isSquashed()) {
11007944SGiacomo.Gabrielli@arm.com            DynInstPtr ret = *it;
11017944SGiacomo.Gabrielli@arm.com            deferredMemInsts.erase(it);
11027944SGiacomo.Gabrielli@arm.com            return ret;
11037944SGiacomo.Gabrielli@arm.com        }
11047944SGiacomo.Gabrielli@arm.com    }
11057944SGiacomo.Gabrielli@arm.com    return NULL;
11067944SGiacomo.Gabrielli@arm.com}
11077944SGiacomo.Gabrielli@arm.com
11087944SGiacomo.Gabrielli@arm.comtemplate <class Impl>
11097944SGiacomo.Gabrielli@arm.comvoid
11101061SN/AInstructionQueue<Impl>::violation(DynInstPtr &store,
11111061SN/A                                  DynInstPtr &faulting_load)
11121061SN/A{
11137897Shestness@cs.utexas.edu    intInstQueueWrites++;
11142292SN/A    memDepUnit[store->threadNumber].violation(store, faulting_load);
11151061SN/A}
11161061SN/A
11171061SN/Atemplate <class Impl>
11181060SN/Avoid
11196221Snate@binkert.orgInstructionQueue<Impl>::squash(ThreadID tid)
11201060SN/A{
11212292SN/A    DPRINTF(IQ, "[tid:%i]: Starting to squash instructions in "
11222292SN/A            "the IQ.\n", tid);
11231060SN/A
11241060SN/A    // Read instruction sequence number of last instruction out of the
11251060SN/A    // time buffer.
11262292SN/A    squashedSeqNum[tid] = fromCommit->commitInfo[tid].doneSeqNum;
11271060SN/A
11281681SN/A    // Call doSquash if there are insts in the IQ
11292292SN/A    if (count[tid] > 0) {
11302292SN/A        doSquash(tid);
11311681SN/A    }
11321061SN/A
11331061SN/A    // Also tell the memory dependence unit to squash.
11342292SN/A    memDepUnit[tid].squash(squashedSeqNum[tid], tid);
11351060SN/A}
11361060SN/A
11371061SN/Atemplate <class Impl>
11381061SN/Avoid
11396221Snate@binkert.orgInstructionQueue<Impl>::doSquash(ThreadID tid)
11401061SN/A{
11412326SN/A    // Start at the tail.
11422326SN/A    ListIt squash_it = instList[tid].end();
11432326SN/A    --squash_it;
11441061SN/A
11452292SN/A    DPRINTF(IQ, "[tid:%i]: Squashing until sequence number %i!\n",
11462292SN/A            tid, squashedSeqNum[tid]);
11471061SN/A
11481061SN/A    // Squash any instructions younger than the squashed sequence number
11491061SN/A    // given.
11502326SN/A    while (squash_it != instList[tid].end() &&
11512326SN/A           (*squash_it)->seqNum > squashedSeqNum[tid]) {
11522292SN/A
11532326SN/A        DynInstPtr squashed_inst = (*squash_it);
11547897Shestness@cs.utexas.edu        squashed_inst->isFloating() ? fpInstQueueWrites++ : intInstQueueWrites++;
11551061SN/A
11561061SN/A        // Only handle the instruction if it actually is in the IQ and
11571061SN/A        // hasn't already been squashed in the IQ.
11582292SN/A        if (squashed_inst->threadNumber != tid ||
11592292SN/A            squashed_inst->isSquashedInIQ()) {
11602326SN/A            --squash_it;
11612292SN/A            continue;
11622292SN/A        }
11632292SN/A
11642292SN/A        if (!squashed_inst->isIssued() ||
11652292SN/A            (squashed_inst->isMemRef() &&
11662292SN/A             !squashed_inst->memOpDone)) {
11671062SN/A
11687720Sgblack@eecs.umich.edu            DPRINTF(IQ, "[tid:%i]: Instruction [sn:%lli] PC %s squashed.\n",
11697720Sgblack@eecs.umich.edu                    tid, squashed_inst->seqNum, squashed_inst->pcState());
11702367SN/A
11711061SN/A            // Remove the instruction from the dependency list.
11722292SN/A            if (!squashed_inst->isNonSpeculative() &&
11732336SN/A                !squashed_inst->isStoreConditional() &&
11742292SN/A                !squashed_inst->isMemBarrier() &&
11752292SN/A                !squashed_inst->isWriteBarrier()) {
11761061SN/A
11771061SN/A                for (int src_reg_idx = 0;
11781681SN/A                     src_reg_idx < squashed_inst->numSrcRegs();
11791061SN/A                     src_reg_idx++)
11801061SN/A                {
11811061SN/A                    PhysRegIndex src_reg =
11821061SN/A                        squashed_inst->renamedSrcRegIdx(src_reg_idx);
11831061SN/A
11842326SN/A                    // Only remove it from the dependency graph if it
11852326SN/A                    // was placed there in the first place.
11862326SN/A
11872326SN/A                    // Instead of doing a linked list traversal, we
11882326SN/A                    // can just remove these squashed instructions
11892326SN/A                    // either at issue time, or when the register is
11902326SN/A                    // overwritten.  The only downside to this is it
11912326SN/A                    // leaves more room for error.
11922292SN/A
11931061SN/A                    if (!squashed_inst->isReadySrcRegIdx(src_reg_idx) &&
11941061SN/A                        src_reg < numPhysRegs) {
11952326SN/A                        dependGraph.remove(src_reg, squashed_inst);
11961061SN/A                    }
11971062SN/A
11982292SN/A
11991062SN/A                    ++iqSquashedOperandsExamined;
12001061SN/A                }
12014033Sktlim@umich.edu            } else if (!squashed_inst->isStoreConditional() ||
12024033Sktlim@umich.edu                       !squashed_inst->isCompleted()) {
12032292SN/A                NonSpecMapIt ns_inst_it =
12042292SN/A                    nonSpecInsts.find(squashed_inst->seqNum);
12058275SAli.Saidi@ARM.com
12064033Sktlim@umich.edu                if (ns_inst_it == nonSpecInsts.end()) {
12074033Sktlim@umich.edu                    assert(squashed_inst->getFault() != NoFault);
12084033Sktlim@umich.edu                } else {
12091062SN/A
12104033Sktlim@umich.edu                    (*ns_inst_it).second = NULL;
12111681SN/A
12124033Sktlim@umich.edu                    nonSpecInsts.erase(ns_inst_it);
12131062SN/A
12144033Sktlim@umich.edu                    ++iqSquashedNonSpecRemoved;
12154033Sktlim@umich.edu                }
12161061SN/A            }
12171061SN/A
12181061SN/A            // Might want to also clear out the head of the dependency graph.
12191061SN/A
12201061SN/A            // Mark it as squashed within the IQ.
12211061SN/A            squashed_inst->setSquashedInIQ();
12221061SN/A
12232292SN/A            // @todo: Remove this hack where several statuses are set so the
12242292SN/A            // inst will flow through the rest of the pipeline.
12251681SN/A            squashed_inst->setIssued();
12261681SN/A            squashed_inst->setCanCommit();
12272731Sktlim@umich.edu            squashed_inst->clearInIQ();
12282292SN/A
12292292SN/A            //Update Thread IQ Count
12302292SN/A            count[squashed_inst->threadNumber]--;
12311681SN/A
12321681SN/A            ++freeEntries;
12331061SN/A        }
12341061SN/A
12352326SN/A        instList[tid].erase(squash_it--);
12361062SN/A        ++iqSquashedInstsExamined;
12371061SN/A    }
12381060SN/A}
12391060SN/A
12401061SN/Atemplate <class Impl>
12411060SN/Abool
12421061SN/AInstructionQueue<Impl>::addToDependents(DynInstPtr &new_inst)
12431060SN/A{
12441060SN/A    // Loop through the instruction's source registers, adding
12451060SN/A    // them to the dependency list if they are not ready.
12461060SN/A    int8_t total_src_regs = new_inst->numSrcRegs();
12471060SN/A    bool return_val = false;
12481060SN/A
12491060SN/A    for (int src_reg_idx = 0;
12501060SN/A         src_reg_idx < total_src_regs;
12511060SN/A         src_reg_idx++)
12521060SN/A    {
12531060SN/A        // Only add it to the dependency graph if it's not ready.
12541060SN/A        if (!new_inst->isReadySrcRegIdx(src_reg_idx)) {
12551060SN/A            PhysRegIndex src_reg = new_inst->renamedSrcRegIdx(src_reg_idx);
12561060SN/A
12571060SN/A            // Check the IQ's scoreboard to make sure the register
12581060SN/A            // hasn't become ready while the instruction was in flight
12591060SN/A            // between stages.  Only if it really isn't ready should
12601060SN/A            // it be added to the dependency graph.
12611061SN/A            if (src_reg >= numPhysRegs) {
12621061SN/A                continue;
12631061SN/A            } else if (regScoreboard[src_reg] == false) {
12647720Sgblack@eecs.umich.edu                DPRINTF(IQ, "Instruction PC %s has src reg %i that "
12651060SN/A                        "is being added to the dependency chain.\n",
12667720Sgblack@eecs.umich.edu                        new_inst->pcState(), src_reg);
12671060SN/A
12682326SN/A                dependGraph.insert(src_reg, new_inst);
12691060SN/A
12701060SN/A                // Change the return value to indicate that something
12711060SN/A                // was added to the dependency graph.
12721060SN/A                return_val = true;
12731060SN/A            } else {
12747720Sgblack@eecs.umich.edu                DPRINTF(IQ, "Instruction PC %s has src reg %i that "
12751060SN/A                        "became ready before it reached the IQ.\n",
12767720Sgblack@eecs.umich.edu                        new_inst->pcState(), src_reg);
12771060SN/A                // Mark a register ready within the instruction.
12782326SN/A                new_inst->markSrcRegReady(src_reg_idx);
12791060SN/A            }
12801060SN/A        }
12811060SN/A    }
12821060SN/A
12831060SN/A    return return_val;
12841060SN/A}
12851060SN/A
12861061SN/Atemplate <class Impl>
12871060SN/Avoid
12882326SN/AInstructionQueue<Impl>::addToProducers(DynInstPtr &new_inst)
12891060SN/A{
12902326SN/A    // Nothing really needs to be marked when an instruction becomes
12912326SN/A    // the producer of a register's value, but for convenience a ptr
12922326SN/A    // to the producing instruction will be placed in the head node of
12932326SN/A    // the dependency links.
12941060SN/A    int8_t total_dest_regs = new_inst->numDestRegs();
12951060SN/A
12961060SN/A    for (int dest_reg_idx = 0;
12971060SN/A         dest_reg_idx < total_dest_regs;
12981060SN/A         dest_reg_idx++)
12991060SN/A    {
13001061SN/A        PhysRegIndex dest_reg = new_inst->renamedDestRegIdx(dest_reg_idx);
13011061SN/A
13021061SN/A        // Instructions that use the misc regs will have a reg number
13031061SN/A        // higher than the normal physical registers.  In this case these
13041061SN/A        // registers are not renamed, and there is no need to track
13051061SN/A        // dependencies as these instructions must be executed at commit.
13061061SN/A        if (dest_reg >= numPhysRegs) {
13071061SN/A            continue;
13081060SN/A        }
13091060SN/A
13102326SN/A        if (!dependGraph.empty(dest_reg)) {
13112326SN/A            dependGraph.dump();
13122292SN/A            panic("Dependency graph %i not empty!", dest_reg);
13132064SN/A        }
13141062SN/A
13152326SN/A        dependGraph.setInst(dest_reg, new_inst);
13161062SN/A
13171060SN/A        // Mark the scoreboard to say it's not yet ready.
13181060SN/A        regScoreboard[dest_reg] = false;
13191060SN/A    }
13201060SN/A}
13211060SN/A
13221061SN/Atemplate <class Impl>
13231060SN/Avoid
13241061SN/AInstructionQueue<Impl>::addIfReady(DynInstPtr &inst)
13251060SN/A{
13262326SN/A    // If the instruction now has all of its source registers
13271060SN/A    // available, then add it to the list of ready instructions.
13281060SN/A    if (inst->readyToIssue()) {
13291061SN/A
13301060SN/A        //Add the instruction to the proper ready list.
13312292SN/A        if (inst->isMemRef()) {
13321061SN/A
13332292SN/A            DPRINTF(IQ, "Checking if memory instruction can issue.\n");
13341061SN/A
13351062SN/A            // Message to the mem dependence unit that this instruction has
13361062SN/A            // its registers ready.
13372292SN/A            memDepUnit[inst->threadNumber].regsReady(inst);
13381062SN/A
13392292SN/A            return;
13402292SN/A        }
13411062SN/A
13422292SN/A        OpClass op_class = inst->opClass();
13431061SN/A
13442292SN/A        DPRINTF(IQ, "Instruction is ready to issue, putting it onto "
13457720Sgblack@eecs.umich.edu                "the ready list, PC %s opclass:%i [sn:%lli].\n",
13467720Sgblack@eecs.umich.edu                inst->pcState(), op_class, inst->seqNum);
13471061SN/A
13482292SN/A        readyInsts[op_class].push(inst);
13491061SN/A
13502326SN/A        // Will need to reorder the list if either a queue is not on the list,
13512326SN/A        // or it has an older instruction than last time.
13522326SN/A        if (!queueOnList[op_class]) {
13532326SN/A            addToOrderList(op_class);
13542326SN/A        } else if (readyInsts[op_class].top()->seqNum  <
13552326SN/A                   (*readyIt[op_class]).oldestInst) {
13562326SN/A            listOrder.erase(readyIt[op_class]);
13572326SN/A            addToOrderList(op_class);
13581060SN/A        }
13591060SN/A    }
13601060SN/A}
13611060SN/A
13621061SN/Atemplate <class Impl>
13631061SN/Aint
13641061SN/AInstructionQueue<Impl>::countInsts()
13651061SN/A{
13662698Sktlim@umich.edu#if 0
13672292SN/A    //ksewell:This works but definitely could use a cleaner write
13682292SN/A    //with a more intuitive way of counting. Right now it's
13692292SN/A    //just brute force ....
13702698Sktlim@umich.edu    // Change the #if if you want to use this method.
13711061SN/A    int total_insts = 0;
13721061SN/A
13736221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; ++tid) {
13746221Snate@binkert.org        ListIt count_it = instList[tid].begin();
13751681SN/A
13766221Snate@binkert.org        while (count_it != instList[tid].end()) {
13772292SN/A            if (!(*count_it)->isSquashed() && !(*count_it)->isSquashedInIQ()) {
13782292SN/A                if (!(*count_it)->isIssued()) {
13792292SN/A                    ++total_insts;
13802292SN/A                } else if ((*count_it)->isMemRef() &&
13812292SN/A                           !(*count_it)->memOpDone) {
13822292SN/A                    // Loads that have not been marked as executed still count
13832292SN/A                    // towards the total instructions.
13842292SN/A                    ++total_insts;
13852292SN/A                }
13862292SN/A            }
13872292SN/A
13882292SN/A            ++count_it;
13891061SN/A        }
13901061SN/A    }
13911061SN/A
13921061SN/A    return total_insts;
13932292SN/A#else
13942292SN/A    return numEntries - freeEntries;
13952292SN/A#endif
13961681SN/A}
13971681SN/A
13981681SN/Atemplate <class Impl>
13991681SN/Avoid
14001061SN/AInstructionQueue<Impl>::dumpLists()
14011061SN/A{
14022292SN/A    for (int i = 0; i < Num_OpClasses; ++i) {
14032292SN/A        cprintf("Ready list %i size: %i\n", i, readyInsts[i].size());
14041061SN/A
14052292SN/A        cprintf("\n");
14062292SN/A    }
14071061SN/A
14081061SN/A    cprintf("Non speculative list size: %i\n", nonSpecInsts.size());
14091061SN/A
14102292SN/A    NonSpecMapIt non_spec_it = nonSpecInsts.begin();
14112292SN/A    NonSpecMapIt non_spec_end_it = nonSpecInsts.end();
14121061SN/A
14131061SN/A    cprintf("Non speculative list: ");
14141061SN/A
14152292SN/A    while (non_spec_it != non_spec_end_it) {
14167720Sgblack@eecs.umich.edu        cprintf("%s [sn:%lli]", (*non_spec_it).second->pcState(),
14172292SN/A                (*non_spec_it).second->seqNum);
14181061SN/A        ++non_spec_it;
14191061SN/A    }
14201061SN/A
14211061SN/A    cprintf("\n");
14221061SN/A
14232292SN/A    ListOrderIt list_order_it = listOrder.begin();
14242292SN/A    ListOrderIt list_order_end_it = listOrder.end();
14252292SN/A    int i = 1;
14262292SN/A
14272292SN/A    cprintf("List order: ");
14282292SN/A
14292292SN/A    while (list_order_it != list_order_end_it) {
14302292SN/A        cprintf("%i OpClass:%i [sn:%lli] ", i, (*list_order_it).queueType,
14312292SN/A                (*list_order_it).oldestInst);
14322292SN/A
14332292SN/A        ++list_order_it;
14342292SN/A        ++i;
14352292SN/A    }
14362292SN/A
14372292SN/A    cprintf("\n");
14381061SN/A}
14392292SN/A
14402292SN/A
14412292SN/Atemplate <class Impl>
14422292SN/Avoid
14432292SN/AInstructionQueue<Impl>::dumpInsts()
14442292SN/A{
14456221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; ++tid) {
14462292SN/A        int num = 0;
14472292SN/A        int valid_num = 0;
14486221Snate@binkert.org        ListIt inst_list_it = instList[tid].begin();
14492292SN/A
14506221Snate@binkert.org        while (inst_list_it != instList[tid].end()) {
14516221Snate@binkert.org            cprintf("Instruction:%i\n", num);
14522292SN/A            if (!(*inst_list_it)->isSquashed()) {
14532292SN/A                if (!(*inst_list_it)->isIssued()) {
14542292SN/A                    ++valid_num;
14552292SN/A                    cprintf("Count:%i\n", valid_num);
14562292SN/A                } else if ((*inst_list_it)->isMemRef() &&
14572292SN/A                           !(*inst_list_it)->memOpDone) {
14582326SN/A                    // Loads that have not been marked as executed
14592326SN/A                    // still count towards the total instructions.
14602292SN/A                    ++valid_num;
14612292SN/A                    cprintf("Count:%i\n", valid_num);
14622292SN/A                }
14632292SN/A            }
14642292SN/A
14657720Sgblack@eecs.umich.edu            cprintf("PC: %s\n[sn:%lli]\n[tid:%i]\n"
14662292SN/A                    "Issued:%i\nSquashed:%i\n",
14677720Sgblack@eecs.umich.edu                    (*inst_list_it)->pcState(),
14682292SN/A                    (*inst_list_it)->seqNum,
14692292SN/A                    (*inst_list_it)->threadNumber,
14702292SN/A                    (*inst_list_it)->isIssued(),
14712292SN/A                    (*inst_list_it)->isSquashed());
14722292SN/A
14732292SN/A            if ((*inst_list_it)->isMemRef()) {
14742292SN/A                cprintf("MemOpDone:%i\n", (*inst_list_it)->memOpDone);
14752292SN/A            }
14762292SN/A
14772292SN/A            cprintf("\n");
14782292SN/A
14792292SN/A            inst_list_it++;
14802292SN/A            ++num;
14812292SN/A        }
14822292SN/A    }
14832348SN/A
14842348SN/A    cprintf("Insts to Execute list:\n");
14852348SN/A
14862348SN/A    int num = 0;
14872348SN/A    int valid_num = 0;
14882348SN/A    ListIt inst_list_it = instsToExecute.begin();
14892348SN/A
14902348SN/A    while (inst_list_it != instsToExecute.end())
14912348SN/A    {
14922348SN/A        cprintf("Instruction:%i\n",
14932348SN/A                num);
14942348SN/A        if (!(*inst_list_it)->isSquashed()) {
14952348SN/A            if (!(*inst_list_it)->isIssued()) {
14962348SN/A                ++valid_num;
14972348SN/A                cprintf("Count:%i\n", valid_num);
14982348SN/A            } else if ((*inst_list_it)->isMemRef() &&
14992348SN/A                       !(*inst_list_it)->memOpDone) {
15002348SN/A                // Loads that have not been marked as executed
15012348SN/A                // still count towards the total instructions.
15022348SN/A                ++valid_num;
15032348SN/A                cprintf("Count:%i\n", valid_num);
15042348SN/A            }
15052348SN/A        }
15062348SN/A
15077720Sgblack@eecs.umich.edu        cprintf("PC: %s\n[sn:%lli]\n[tid:%i]\n"
15082348SN/A                "Issued:%i\nSquashed:%i\n",
15097720Sgblack@eecs.umich.edu                (*inst_list_it)->pcState(),
15102348SN/A                (*inst_list_it)->seqNum,
15112348SN/A                (*inst_list_it)->threadNumber,
15122348SN/A                (*inst_list_it)->isIssued(),
15132348SN/A                (*inst_list_it)->isSquashed());
15142348SN/A
15152348SN/A        if ((*inst_list_it)->isMemRef()) {
15162348SN/A            cprintf("MemOpDone:%i\n", (*inst_list_it)->memOpDone);
15172348SN/A        }
15182348SN/A
15192348SN/A        cprintf("\n");
15202348SN/A
15212348SN/A        inst_list_it++;
15222348SN/A        ++num;
15232348SN/A    }
15242292SN/A}
1525