rename_impl.hh revision 13601:f5c84915eb7f
1/*
2 * Copyright (c) 2010-2012, 2014-2016 ARM Limited
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder.  You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2004-2006 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Kevin Lim
42 *          Korey Sewell
43 */
44
45#ifndef __CPU_O3_RENAME_IMPL_HH__
46#define __CPU_O3_RENAME_IMPL_HH__
47
48#include <list>
49
50#include "arch/isa_traits.hh"
51#include "arch/registers.hh"
52#include "config/the_isa.hh"
53#include "cpu/o3/rename.hh"
54#include "cpu/reg_class.hh"
55#include "debug/Activity.hh"
56#include "debug/Rename.hh"
57#include "debug/O3PipeView.hh"
58#include "params/DerivO3CPU.hh"
59
60using namespace std;
61
62template <class Impl>
63DefaultRename<Impl>::DefaultRename(O3CPU *_cpu, DerivO3CPUParams *params)
64    : cpu(_cpu),
65      iewToRenameDelay(params->iewToRenameDelay),
66      decodeToRenameDelay(params->decodeToRenameDelay),
67      commitToRenameDelay(params->commitToRenameDelay),
68      renameWidth(params->renameWidth),
69      commitWidth(params->commitWidth),
70      numThreads(params->numThreads)
71{
72    if (renameWidth > Impl::MaxWidth)
73        fatal("renameWidth (%d) is larger than compiled limit (%d),\n"
74             "\tincrease MaxWidth in src/cpu/o3/impl.hh\n",
75             renameWidth, static_cast<int>(Impl::MaxWidth));
76
77    // @todo: Make into a parameter.
78    skidBufferMax = (decodeToRenameDelay + 1) * params->decodeWidth;
79    for (uint32_t tid = 0; tid < Impl::MaxThreads; tid++) {
80        renameStatus[tid] = Idle;
81        renameMap[tid] = nullptr;
82        instsInProgress[tid] = 0;
83        loadsInProgress[tid] = 0;
84        storesInProgress[tid] = 0;
85        freeEntries[tid] = {0, 0, 0, 0};
86        emptyROB[tid] = true;
87        stalls[tid] = {false, false};
88        serializeInst[tid] = nullptr;
89        serializeOnNextInst[tid] = false;
90    }
91}
92
93template <class Impl>
94std::string
95DefaultRename<Impl>::name() const
96{
97    return cpu->name() + ".rename";
98}
99
100template <class Impl>
101void
102DefaultRename<Impl>::regStats()
103{
104    renameSquashCycles
105        .name(name() + ".SquashCycles")
106        .desc("Number of cycles rename is squashing")
107        .prereq(renameSquashCycles);
108    renameIdleCycles
109        .name(name() + ".IdleCycles")
110        .desc("Number of cycles rename is idle")
111        .prereq(renameIdleCycles);
112    renameBlockCycles
113        .name(name() + ".BlockCycles")
114        .desc("Number of cycles rename is blocking")
115        .prereq(renameBlockCycles);
116    renameSerializeStallCycles
117        .name(name() + ".serializeStallCycles")
118        .desc("count of cycles rename stalled for serializing inst")
119        .flags(Stats::total);
120    renameRunCycles
121        .name(name() + ".RunCycles")
122        .desc("Number of cycles rename is running")
123        .prereq(renameIdleCycles);
124    renameUnblockCycles
125        .name(name() + ".UnblockCycles")
126        .desc("Number of cycles rename is unblocking")
127        .prereq(renameUnblockCycles);
128    renameRenamedInsts
129        .name(name() + ".RenamedInsts")
130        .desc("Number of instructions processed by rename")
131        .prereq(renameRenamedInsts);
132    renameSquashedInsts
133        .name(name() + ".SquashedInsts")
134        .desc("Number of squashed instructions processed by rename")
135        .prereq(renameSquashedInsts);
136    renameROBFullEvents
137        .name(name() + ".ROBFullEvents")
138        .desc("Number of times rename has blocked due to ROB full")
139        .prereq(renameROBFullEvents);
140    renameIQFullEvents
141        .name(name() + ".IQFullEvents")
142        .desc("Number of times rename has blocked due to IQ full")
143        .prereq(renameIQFullEvents);
144    renameLQFullEvents
145        .name(name() + ".LQFullEvents")
146        .desc("Number of times rename has blocked due to LQ full")
147        .prereq(renameLQFullEvents);
148    renameSQFullEvents
149        .name(name() + ".SQFullEvents")
150        .desc("Number of times rename has blocked due to SQ full")
151        .prereq(renameSQFullEvents);
152    renameFullRegistersEvents
153        .name(name() + ".FullRegisterEvents")
154        .desc("Number of times there has been no free registers")
155        .prereq(renameFullRegistersEvents);
156    renameRenamedOperands
157        .name(name() + ".RenamedOperands")
158        .desc("Number of destination operands rename has renamed")
159        .prereq(renameRenamedOperands);
160    renameRenameLookups
161        .name(name() + ".RenameLookups")
162        .desc("Number of register rename lookups that rename has made")
163        .prereq(renameRenameLookups);
164    renameCommittedMaps
165        .name(name() + ".CommittedMaps")
166        .desc("Number of HB maps that are committed")
167        .prereq(renameCommittedMaps);
168    renameUndoneMaps
169        .name(name() + ".UndoneMaps")
170        .desc("Number of HB maps that are undone due to squashing")
171        .prereq(renameUndoneMaps);
172    renamedSerializing
173        .name(name() + ".serializingInsts")
174        .desc("count of serializing insts renamed")
175        .flags(Stats::total)
176        ;
177    renamedTempSerializing
178        .name(name() + ".tempSerializingInsts")
179        .desc("count of temporary serializing insts renamed")
180        .flags(Stats::total)
181        ;
182    renameSkidInsts
183        .name(name() + ".skidInsts")
184        .desc("count of insts added to the skid buffer")
185        .flags(Stats::total)
186        ;
187    intRenameLookups
188        .name(name() + ".int_rename_lookups")
189        .desc("Number of integer rename lookups")
190        .prereq(intRenameLookups);
191    fpRenameLookups
192        .name(name() + ".fp_rename_lookups")
193        .desc("Number of floating rename lookups")
194        .prereq(fpRenameLookups);
195    vecRenameLookups
196        .name(name() + ".vec_rename_lookups")
197        .desc("Number of vector rename lookups")
198        .prereq(vecRenameLookups);
199}
200
201template <class Impl>
202void
203DefaultRename<Impl>::regProbePoints()
204{
205    ppRename = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "Rename");
206    ppSquashInRename = new ProbePointArg<SeqNumRegPair>(cpu->getProbeManager(),
207                                                        "SquashInRename");
208}
209
210template <class Impl>
211void
212DefaultRename<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
213{
214    timeBuffer = tb_ptr;
215
216    // Setup wire to read information from time buffer, from IEW stage.
217    fromIEW = timeBuffer->getWire(-iewToRenameDelay);
218
219    // Setup wire to read infromation from time buffer, from commit stage.
220    fromCommit = timeBuffer->getWire(-commitToRenameDelay);
221
222    // Setup wire to write information to previous stages.
223    toDecode = timeBuffer->getWire(0);
224}
225
226template <class Impl>
227void
228DefaultRename<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr)
229{
230    renameQueue = rq_ptr;
231
232    // Setup wire to write information to future stages.
233    toIEW = renameQueue->getWire(0);
234}
235
236template <class Impl>
237void
238DefaultRename<Impl>::setDecodeQueue(TimeBuffer<DecodeStruct> *dq_ptr)
239{
240    decodeQueue = dq_ptr;
241
242    // Setup wire to get information from decode.
243    fromDecode = decodeQueue->getWire(-decodeToRenameDelay);
244}
245
246template <class Impl>
247void
248DefaultRename<Impl>::startupStage()
249{
250    resetStage();
251}
252
253template <class Impl>
254void
255DefaultRename<Impl>::resetStage()
256{
257    _status = Inactive;
258
259    resumeSerialize = false;
260    resumeUnblocking = false;
261
262    // Grab the number of free entries directly from the stages.
263    for (ThreadID tid = 0; tid < numThreads; tid++) {
264        renameStatus[tid] = Idle;
265
266        freeEntries[tid].iqEntries = iew_ptr->instQueue.numFreeEntries(tid);
267        freeEntries[tid].lqEntries = iew_ptr->ldstQueue.numFreeLoadEntries(tid);
268        freeEntries[tid].sqEntries = iew_ptr->ldstQueue.numFreeStoreEntries(tid);
269        freeEntries[tid].robEntries = commit_ptr->numROBFreeEntries(tid);
270        emptyROB[tid] = true;
271
272        stalls[tid].iew = false;
273        serializeInst[tid] = NULL;
274
275        instsInProgress[tid] = 0;
276        loadsInProgress[tid] = 0;
277        storesInProgress[tid] = 0;
278
279        serializeOnNextInst[tid] = false;
280    }
281}
282
283template<class Impl>
284void
285DefaultRename<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
286{
287    activeThreads = at_ptr;
288}
289
290
291template <class Impl>
292void
293DefaultRename<Impl>::setRenameMap(RenameMap rm_ptr[])
294{
295    for (ThreadID tid = 0; tid < numThreads; tid++)
296        renameMap[tid] = &rm_ptr[tid];
297}
298
299template <class Impl>
300void
301DefaultRename<Impl>::setFreeList(FreeList *fl_ptr)
302{
303    freeList = fl_ptr;
304}
305
306template<class Impl>
307void
308DefaultRename<Impl>::setScoreboard(Scoreboard *_scoreboard)
309{
310    scoreboard = _scoreboard;
311}
312
313template <class Impl>
314bool
315DefaultRename<Impl>::isDrained() const
316{
317    for (ThreadID tid = 0; tid < numThreads; tid++) {
318        if (instsInProgress[tid] != 0 ||
319            !historyBuffer[tid].empty() ||
320            !skidBuffer[tid].empty() ||
321            !insts[tid].empty() ||
322            (renameStatus[tid] != Idle && renameStatus[tid] != Running))
323            return false;
324    }
325    return true;
326}
327
328template <class Impl>
329void
330DefaultRename<Impl>::takeOverFrom()
331{
332    resetStage();
333}
334
335template <class Impl>
336void
337DefaultRename<Impl>::drainSanityCheck() const
338{
339    for (ThreadID tid = 0; tid < numThreads; tid++) {
340        assert(historyBuffer[tid].empty());
341        assert(insts[tid].empty());
342        assert(skidBuffer[tid].empty());
343        assert(instsInProgress[tid] == 0);
344    }
345}
346
347template <class Impl>
348void
349DefaultRename<Impl>::squash(const InstSeqNum &squash_seq_num, ThreadID tid)
350{
351    DPRINTF(Rename, "[tid:%u]: Squashing instructions.\n",tid);
352
353    // Clear the stall signal if rename was blocked or unblocking before.
354    // If it still needs to block, the blocking should happen the next
355    // cycle and there should be space to hold everything due to the squash.
356    if (renameStatus[tid] == Blocked ||
357        renameStatus[tid] == Unblocking) {
358        toDecode->renameUnblock[tid] = 1;
359
360        resumeSerialize = false;
361        serializeInst[tid] = NULL;
362    } else if (renameStatus[tid] == SerializeStall) {
363        if (serializeInst[tid]->seqNum <= squash_seq_num) {
364            DPRINTF(Rename, "Rename will resume serializing after squash\n");
365            resumeSerialize = true;
366            assert(serializeInst[tid]);
367        } else {
368            resumeSerialize = false;
369            toDecode->renameUnblock[tid] = 1;
370
371            serializeInst[tid] = NULL;
372        }
373    }
374
375    // Set the status to Squashing.
376    renameStatus[tid] = Squashing;
377
378    // Squash any instructions from decode.
379    for (int i=0; i<fromDecode->size; i++) {
380        if (fromDecode->insts[i]->threadNumber == tid &&
381            fromDecode->insts[i]->seqNum > squash_seq_num) {
382            fromDecode->insts[i]->setSquashed();
383            wroteToTimeBuffer = true;
384        }
385
386    }
387
388    // Clear the instruction list and skid buffer in case they have any
389    // insts in them.
390    insts[tid].clear();
391
392    // Clear the skid buffer in case it has any data in it.
393    skidBuffer[tid].clear();
394
395    doSquash(squash_seq_num, tid);
396}
397
398template <class Impl>
399void
400DefaultRename<Impl>::tick()
401{
402    wroteToTimeBuffer = false;
403
404    blockThisCycle = false;
405
406    bool status_change = false;
407
408    toIEWIndex = 0;
409
410    sortInsts();
411
412    list<ThreadID>::iterator threads = activeThreads->begin();
413    list<ThreadID>::iterator end = activeThreads->end();
414
415    // Check stall and squash signals.
416    while (threads != end) {
417        ThreadID tid = *threads++;
418
419        DPRINTF(Rename, "Processing [tid:%i]\n", tid);
420
421        status_change = checkSignalsAndUpdate(tid) || status_change;
422
423        rename(status_change, tid);
424    }
425
426    if (status_change) {
427        updateStatus();
428    }
429
430    if (wroteToTimeBuffer) {
431        DPRINTF(Activity, "Activity this cycle.\n");
432        cpu->activityThisCycle();
433    }
434
435    threads = activeThreads->begin();
436
437    while (threads != end) {
438        ThreadID tid = *threads++;
439
440        // If we committed this cycle then doneSeqNum will be > 0
441        if (fromCommit->commitInfo[tid].doneSeqNum != 0 &&
442            !fromCommit->commitInfo[tid].squash &&
443            renameStatus[tid] != Squashing) {
444
445            removeFromHistory(fromCommit->commitInfo[tid].doneSeqNum,
446                                  tid);
447        }
448    }
449
450    // @todo: make into updateProgress function
451    for (ThreadID tid = 0; tid < numThreads; tid++) {
452        instsInProgress[tid] -= fromIEW->iewInfo[tid].dispatched;
453        loadsInProgress[tid] -= fromIEW->iewInfo[tid].dispatchedToLQ;
454        storesInProgress[tid] -= fromIEW->iewInfo[tid].dispatchedToSQ;
455        assert(loadsInProgress[tid] >= 0);
456        assert(storesInProgress[tid] >= 0);
457        assert(instsInProgress[tid] >=0);
458    }
459
460}
461
462template<class Impl>
463void
464DefaultRename<Impl>::rename(bool &status_change, ThreadID tid)
465{
466    // If status is Running or idle,
467    //     call renameInsts()
468    // If status is Unblocking,
469    //     buffer any instructions coming from decode
470    //     continue trying to empty skid buffer
471    //     check if stall conditions have passed
472
473    if (renameStatus[tid] == Blocked) {
474        ++renameBlockCycles;
475    } else if (renameStatus[tid] == Squashing) {
476        ++renameSquashCycles;
477    } else if (renameStatus[tid] == SerializeStall) {
478        ++renameSerializeStallCycles;
479        // If we are currently in SerializeStall and resumeSerialize
480        // was set, then that means that we are resuming serializing
481        // this cycle.  Tell the previous stages to block.
482        if (resumeSerialize) {
483            resumeSerialize = false;
484            block(tid);
485            toDecode->renameUnblock[tid] = false;
486        }
487    } else if (renameStatus[tid] == Unblocking) {
488        if (resumeUnblocking) {
489            block(tid);
490            resumeUnblocking = false;
491            toDecode->renameUnblock[tid] = false;
492        }
493    }
494
495    if (renameStatus[tid] == Running ||
496        renameStatus[tid] == Idle) {
497        DPRINTF(Rename, "[tid:%u]: Not blocked, so attempting to run "
498                "stage.\n", tid);
499
500        renameInsts(tid);
501    } else if (renameStatus[tid] == Unblocking) {
502        renameInsts(tid);
503
504        if (validInsts()) {
505            // Add the current inputs to the skid buffer so they can be
506            // reprocessed when this stage unblocks.
507            skidInsert(tid);
508        }
509
510        // If we switched over to blocking, then there's a potential for
511        // an overall status change.
512        status_change = unblock(tid) || status_change || blockThisCycle;
513    }
514}
515
516template <class Impl>
517void
518DefaultRename<Impl>::renameInsts(ThreadID tid)
519{
520    // Instructions can be either in the skid buffer or the queue of
521    // instructions coming from decode, depending on the status.
522    int insts_available = renameStatus[tid] == Unblocking ?
523        skidBuffer[tid].size() : insts[tid].size();
524
525    // Check the decode queue to see if instructions are available.
526    // If there are no available instructions to rename, then do nothing.
527    if (insts_available == 0) {
528        DPRINTF(Rename, "[tid:%u]: Nothing to do, breaking out early.\n",
529                tid);
530        // Should I change status to idle?
531        ++renameIdleCycles;
532        return;
533    } else if (renameStatus[tid] == Unblocking) {
534        ++renameUnblockCycles;
535    } else if (renameStatus[tid] == Running) {
536        ++renameRunCycles;
537    }
538
539    // Will have to do a different calculation for the number of free
540    // entries.
541    int free_rob_entries = calcFreeROBEntries(tid);
542    int free_iq_entries  = calcFreeIQEntries(tid);
543    int min_free_entries = free_rob_entries;
544
545    FullSource source = ROB;
546
547    if (free_iq_entries < min_free_entries) {
548        min_free_entries = free_iq_entries;
549        source = IQ;
550    }
551
552    // Check if there's any space left.
553    if (min_free_entries <= 0) {
554        DPRINTF(Rename, "[tid:%u]: Blocking due to no free ROB/IQ/ "
555                "entries.\n"
556                "ROB has %i free entries.\n"
557                "IQ has %i free entries.\n",
558                tid,
559                free_rob_entries,
560                free_iq_entries);
561
562        blockThisCycle = true;
563
564        block(tid);
565
566        incrFullStat(source);
567
568        return;
569    } else if (min_free_entries < insts_available) {
570        DPRINTF(Rename, "[tid:%u]: Will have to block this cycle."
571                "%i insts available, but only %i insts can be "
572                "renamed due to ROB/IQ/LSQ limits.\n",
573                tid, insts_available, min_free_entries);
574
575        insts_available = min_free_entries;
576
577        blockThisCycle = true;
578
579        incrFullStat(source);
580    }
581
582    InstQueue &insts_to_rename = renameStatus[tid] == Unblocking ?
583        skidBuffer[tid] : insts[tid];
584
585    DPRINTF(Rename, "[tid:%u]: %i available instructions to "
586            "send iew.\n", tid, insts_available);
587
588    DPRINTF(Rename, "[tid:%u]: %i insts pipelining from Rename | %i insts "
589            "dispatched to IQ last cycle.\n",
590            tid, instsInProgress[tid], fromIEW->iewInfo[tid].dispatched);
591
592    // Handle serializing the next instruction if necessary.
593    if (serializeOnNextInst[tid]) {
594        if (emptyROB[tid] && instsInProgress[tid] == 0) {
595            // ROB already empty; no need to serialize.
596            serializeOnNextInst[tid] = false;
597        } else if (!insts_to_rename.empty()) {
598            insts_to_rename.front()->setSerializeBefore();
599        }
600    }
601
602    int renamed_insts = 0;
603
604    while (insts_available > 0 &&  toIEWIndex < renameWidth) {
605        DPRINTF(Rename, "[tid:%u]: Sending instructions to IEW.\n", tid);
606
607        assert(!insts_to_rename.empty());
608
609        DynInstPtr inst = insts_to_rename.front();
610
611        //For all kind of instructions, check ROB and IQ first
612        //For load instruction, check LQ size and take into account the inflight loads
613        //For store instruction, check SQ size and take into account the inflight stores
614
615        if (inst->isLoad()) {
616            if (calcFreeLQEntries(tid) <= 0) {
617                DPRINTF(Rename, "[tid:%u]: Cannot rename due to no free LQ\n");
618                source = LQ;
619                incrFullStat(source);
620                break;
621            }
622        }
623
624        if (inst->isStore()) {
625            if (calcFreeSQEntries(tid) <= 0) {
626                DPRINTF(Rename, "[tid:%u]: Cannot rename due to no free SQ\n");
627                source = SQ;
628                incrFullStat(source);
629                break;
630            }
631        }
632
633        insts_to_rename.pop_front();
634
635        if (renameStatus[tid] == Unblocking) {
636            DPRINTF(Rename,"[tid:%u]: Removing [sn:%lli] PC:%s from rename "
637                    "skidBuffer\n", tid, inst->seqNum, inst->pcState());
638        }
639
640        if (inst->isSquashed()) {
641            DPRINTF(Rename, "[tid:%u]: instruction %i with PC %s is "
642                    "squashed, skipping.\n", tid, inst->seqNum,
643                    inst->pcState());
644
645            ++renameSquashedInsts;
646
647            // Decrement how many instructions are available.
648            --insts_available;
649
650            continue;
651        }
652
653        DPRINTF(Rename, "[tid:%u]: Processing instruction [sn:%lli] with "
654                "PC %s.\n", tid, inst->seqNum, inst->pcState());
655
656        // Check here to make sure there are enough destination registers
657        // to rename to.  Otherwise block.
658        if (!renameMap[tid]->canRename(inst->numIntDestRegs(),
659                                       inst->numFPDestRegs(),
660                                       inst->numVecDestRegs(),
661                                       inst->numVecElemDestRegs(),
662                                       inst->numCCDestRegs())) {
663            DPRINTF(Rename, "Blocking due to lack of free "
664                    "physical registers to rename to.\n");
665            blockThisCycle = true;
666            insts_to_rename.push_front(inst);
667            ++renameFullRegistersEvents;
668
669            break;
670        }
671
672        // Handle serializeAfter/serializeBefore instructions.
673        // serializeAfter marks the next instruction as serializeBefore.
674        // serializeBefore makes the instruction wait in rename until the ROB
675        // is empty.
676
677        // In this model, IPR accesses are serialize before
678        // instructions, and store conditionals are serialize after
679        // instructions.  This is mainly due to lack of support for
680        // out-of-order operations of either of those classes of
681        // instructions.
682        if ((inst->isIprAccess() || inst->isSerializeBefore()) &&
683            !inst->isSerializeHandled()) {
684            DPRINTF(Rename, "Serialize before instruction encountered.\n");
685
686            if (!inst->isTempSerializeBefore()) {
687                renamedSerializing++;
688                inst->setSerializeHandled();
689            } else {
690                renamedTempSerializing++;
691            }
692
693            // Change status over to SerializeStall so that other stages know
694            // what this is blocked on.
695            renameStatus[tid] = SerializeStall;
696
697            serializeInst[tid] = inst;
698
699            blockThisCycle = true;
700
701            break;
702        } else if ((inst->isStoreConditional() || inst->isSerializeAfter()) &&
703                   !inst->isSerializeHandled()) {
704            DPRINTF(Rename, "Serialize after instruction encountered.\n");
705
706            renamedSerializing++;
707
708            inst->setSerializeHandled();
709
710            serializeAfter(insts_to_rename, tid);
711        }
712
713        renameSrcRegs(inst, inst->threadNumber);
714
715        renameDestRegs(inst, inst->threadNumber);
716
717        if (inst->isLoad()) {
718                loadsInProgress[tid]++;
719        }
720        if (inst->isStore()) {
721                storesInProgress[tid]++;
722        }
723        ++renamed_insts;
724        // Notify potential listeners that source and destination registers for
725        // this instruction have been renamed.
726        ppRename->notify(inst);
727
728        // Put instruction in rename queue.
729        toIEW->insts[toIEWIndex] = inst;
730        ++(toIEW->size);
731
732        // Increment which instruction we're on.
733        ++toIEWIndex;
734
735        // Decrement how many instructions are available.
736        --insts_available;
737    }
738
739    instsInProgress[tid] += renamed_insts;
740    renameRenamedInsts += renamed_insts;
741
742    // If we wrote to the time buffer, record this.
743    if (toIEWIndex) {
744        wroteToTimeBuffer = true;
745    }
746
747    // Check if there's any instructions left that haven't yet been renamed.
748    // If so then block.
749    if (insts_available) {
750        blockThisCycle = true;
751    }
752
753    if (blockThisCycle) {
754        block(tid);
755        toDecode->renameUnblock[tid] = false;
756    }
757}
758
759template<class Impl>
760void
761DefaultRename<Impl>::skidInsert(ThreadID tid)
762{
763    DynInstPtr inst = NULL;
764
765    while (!insts[tid].empty()) {
766        inst = insts[tid].front();
767
768        insts[tid].pop_front();
769
770        assert(tid == inst->threadNumber);
771
772        DPRINTF(Rename, "[tid:%u]: Inserting [sn:%lli] PC: %s into Rename "
773                "skidBuffer\n", tid, inst->seqNum, inst->pcState());
774
775        ++renameSkidInsts;
776
777        skidBuffer[tid].push_back(inst);
778    }
779
780    if (skidBuffer[tid].size() > skidBufferMax)
781    {
782        typename InstQueue::iterator it;
783        warn("Skidbuffer contents:\n");
784        for (it = skidBuffer[tid].begin(); it != skidBuffer[tid].end(); it++)
785        {
786            warn("[tid:%u]: %s [sn:%i].\n", tid,
787                    (*it)->staticInst->disassemble(inst->instAddr()),
788                    (*it)->seqNum);
789        }
790        panic("Skidbuffer Exceeded Max Size");
791    }
792}
793
794template <class Impl>
795void
796DefaultRename<Impl>::sortInsts()
797{
798    int insts_from_decode = fromDecode->size;
799    for (int i = 0; i < insts_from_decode; ++i) {
800        const DynInstPtr &inst = fromDecode->insts[i];
801        insts[inst->threadNumber].push_back(inst);
802#if TRACING_ON
803        if (DTRACE(O3PipeView)) {
804            inst->renameTick = curTick() - inst->fetchTick;
805        }
806#endif
807    }
808}
809
810template<class Impl>
811bool
812DefaultRename<Impl>::skidsEmpty()
813{
814    list<ThreadID>::iterator threads = activeThreads->begin();
815    list<ThreadID>::iterator end = activeThreads->end();
816
817    while (threads != end) {
818        ThreadID tid = *threads++;
819
820        if (!skidBuffer[tid].empty())
821            return false;
822    }
823
824    return true;
825}
826
827template<class Impl>
828void
829DefaultRename<Impl>::updateStatus()
830{
831    bool any_unblocking = false;
832
833    list<ThreadID>::iterator threads = activeThreads->begin();
834    list<ThreadID>::iterator end = activeThreads->end();
835
836    while (threads != end) {
837        ThreadID tid = *threads++;
838
839        if (renameStatus[tid] == Unblocking) {
840            any_unblocking = true;
841            break;
842        }
843    }
844
845    // Rename will have activity if it's unblocking.
846    if (any_unblocking) {
847        if (_status == Inactive) {
848            _status = Active;
849
850            DPRINTF(Activity, "Activating stage.\n");
851
852            cpu->activateStage(O3CPU::RenameIdx);
853        }
854    } else {
855        // If it's not unblocking, then rename will not have any internal
856        // activity.  Switch it to inactive.
857        if (_status == Active) {
858            _status = Inactive;
859            DPRINTF(Activity, "Deactivating stage.\n");
860
861            cpu->deactivateStage(O3CPU::RenameIdx);
862        }
863    }
864}
865
866template <class Impl>
867bool
868DefaultRename<Impl>::block(ThreadID tid)
869{
870    DPRINTF(Rename, "[tid:%u]: Blocking.\n", tid);
871
872    // Add the current inputs onto the skid buffer, so they can be
873    // reprocessed when this stage unblocks.
874    skidInsert(tid);
875
876    // Only signal backwards to block if the previous stages do not think
877    // rename is already blocked.
878    if (renameStatus[tid] != Blocked) {
879        // If resumeUnblocking is set, we unblocked during the squash,
880        // but now we're have unblocking status. We need to tell earlier
881        // stages to block.
882        if (resumeUnblocking || renameStatus[tid] != Unblocking) {
883            toDecode->renameBlock[tid] = true;
884            toDecode->renameUnblock[tid] = false;
885            wroteToTimeBuffer = true;
886        }
887
888        // Rename can not go from SerializeStall to Blocked, otherwise
889        // it would not know to complete the serialize stall.
890        if (renameStatus[tid] != SerializeStall) {
891            // Set status to Blocked.
892            renameStatus[tid] = Blocked;
893            return true;
894        }
895    }
896
897    return false;
898}
899
900template <class Impl>
901bool
902DefaultRename<Impl>::unblock(ThreadID tid)
903{
904    DPRINTF(Rename, "[tid:%u]: Trying to unblock.\n", tid);
905
906    // Rename is done unblocking if the skid buffer is empty.
907    if (skidBuffer[tid].empty() && renameStatus[tid] != SerializeStall) {
908
909        DPRINTF(Rename, "[tid:%u]: Done unblocking.\n", tid);
910
911        toDecode->renameUnblock[tid] = true;
912        wroteToTimeBuffer = true;
913
914        renameStatus[tid] = Running;
915        return true;
916    }
917
918    return false;
919}
920
921template <class Impl>
922void
923DefaultRename<Impl>::doSquash(const InstSeqNum &squashed_seq_num, ThreadID tid)
924{
925    typename std::list<RenameHistory>::iterator hb_it =
926        historyBuffer[tid].begin();
927
928    // After a syscall squashes everything, the history buffer may be empty
929    // but the ROB may still be squashing instructions.
930    // Go through the most recent instructions, undoing the mappings
931    // they did and freeing up the registers.
932    while (!historyBuffer[tid].empty() &&
933           hb_it->instSeqNum > squashed_seq_num) {
934        assert(hb_it != historyBuffer[tid].end());
935
936        DPRINTF(Rename, "[tid:%u]: Removing history entry with sequence "
937                "number %i.\n", tid, hb_it->instSeqNum);
938
939        // Undo the rename mapping only if it was really a change.
940        // Special regs that are not really renamed (like misc regs
941        // and the zero reg) can be recognized because the new mapping
942        // is the same as the old one.  While it would be merely a
943        // waste of time to update the rename table, we definitely
944        // don't want to put these on the free list.
945        if (hb_it->newPhysReg != hb_it->prevPhysReg) {
946            // Tell the rename map to set the architected register to the
947            // previous physical register that it was renamed to.
948            renameMap[tid]->setEntry(hb_it->archReg, hb_it->prevPhysReg);
949
950            // Put the renamed physical register back on the free list.
951            freeList->addReg(hb_it->newPhysReg);
952        }
953
954        // Notify potential listeners that the register mapping needs to be
955        // removed because the instruction it was mapped to got squashed. Note
956        // that this is done before hb_it is incremented.
957        ppSquashInRename->notify(std::make_pair(hb_it->instSeqNum,
958                                                hb_it->newPhysReg));
959
960        historyBuffer[tid].erase(hb_it++);
961
962        ++renameUndoneMaps;
963    }
964
965    // Check if we need to change vector renaming mode after squashing
966    cpu->switchRenameMode(tid, freeList);
967}
968
969template<class Impl>
970void
971DefaultRename<Impl>::removeFromHistory(InstSeqNum inst_seq_num, ThreadID tid)
972{
973    DPRINTF(Rename, "[tid:%u]: Removing a committed instruction from the "
974            "history buffer %u (size=%i), until [sn:%lli].\n",
975            tid, tid, historyBuffer[tid].size(), inst_seq_num);
976
977    typename std::list<RenameHistory>::iterator hb_it =
978        historyBuffer[tid].end();
979
980    --hb_it;
981
982    if (historyBuffer[tid].empty()) {
983        DPRINTF(Rename, "[tid:%u]: History buffer is empty.\n", tid);
984        return;
985    } else if (hb_it->instSeqNum > inst_seq_num) {
986        DPRINTF(Rename, "[tid:%u]: Old sequence number encountered.  Ensure "
987                "that a syscall happened recently.\n", tid);
988        return;
989    }
990
991    // Commit all the renames up until (and including) the committed sequence
992    // number. Some or even all of the committed instructions may not have
993    // rename histories if they did not have destination registers that were
994    // renamed.
995    while (!historyBuffer[tid].empty() &&
996           hb_it != historyBuffer[tid].end() &&
997           hb_it->instSeqNum <= inst_seq_num) {
998
999        DPRINTF(Rename, "[tid:%u]: Freeing up older rename of reg %i (%s), "
1000                "[sn:%lli].\n",
1001                tid, hb_it->prevPhysReg->index(),
1002                hb_it->prevPhysReg->className(),
1003                hb_it->instSeqNum);
1004
1005        // Don't free special phys regs like misc and zero regs, which
1006        // can be recognized because the new mapping is the same as
1007        // the old one.
1008        if (hb_it->newPhysReg != hb_it->prevPhysReg) {
1009            freeList->addReg(hb_it->prevPhysReg);
1010        }
1011
1012        ++renameCommittedMaps;
1013
1014        historyBuffer[tid].erase(hb_it--);
1015    }
1016}
1017
1018template <class Impl>
1019inline void
1020DefaultRename<Impl>::renameSrcRegs(const DynInstPtr &inst, ThreadID tid)
1021{
1022    ThreadContext *tc = inst->tcBase();
1023    RenameMap *map = renameMap[tid];
1024    unsigned num_src_regs = inst->numSrcRegs();
1025
1026    // Get the architectual register numbers from the source and
1027    // operands, and redirect them to the right physical register.
1028    for (int src_idx = 0; src_idx < num_src_regs; src_idx++) {
1029        const RegId& src_reg = inst->srcRegIdx(src_idx);
1030        PhysRegIdPtr renamed_reg;
1031
1032        renamed_reg = map->lookup(tc->flattenRegId(src_reg));
1033        switch (src_reg.classValue()) {
1034          case IntRegClass:
1035            intRenameLookups++;
1036            break;
1037          case FloatRegClass:
1038            fpRenameLookups++;
1039            break;
1040          case VecRegClass:
1041          case VecElemClass:
1042            vecRenameLookups++;
1043            break;
1044          case CCRegClass:
1045          case MiscRegClass:
1046            break;
1047
1048          default:
1049            panic("Invalid register class: %d.", src_reg.classValue());
1050        }
1051
1052        DPRINTF(Rename, "[tid:%u]: Looking up %s arch reg %i"
1053                ", got phys reg %i (%s)\n", tid,
1054                src_reg.className(), src_reg.index(),
1055                renamed_reg->index(),
1056                renamed_reg->className());
1057
1058        inst->renameSrcReg(src_idx, renamed_reg);
1059
1060        // See if the register is ready or not.
1061        if (scoreboard->getReg(renamed_reg)) {
1062            DPRINTF(Rename, "[tid:%u]: Register %d (flat: %d) (%s)"
1063                    " is ready.\n", tid, renamed_reg->index(),
1064                    renamed_reg->flatIndex(),
1065                    renamed_reg->className());
1066
1067            inst->markSrcRegReady(src_idx);
1068        } else {
1069            DPRINTF(Rename, "[tid:%u]: Register %d (flat: %d) (%s)"
1070                    " is not ready.\n", tid, renamed_reg->index(),
1071                    renamed_reg->flatIndex(),
1072                    renamed_reg->className());
1073        }
1074
1075        ++renameRenameLookups;
1076    }
1077}
1078
1079template <class Impl>
1080inline void
1081DefaultRename<Impl>::renameDestRegs(const DynInstPtr &inst, ThreadID tid)
1082{
1083    ThreadContext *tc = inst->tcBase();
1084    RenameMap *map = renameMap[tid];
1085    unsigned num_dest_regs = inst->numDestRegs();
1086
1087    // Rename the destination registers.
1088    for (int dest_idx = 0; dest_idx < num_dest_regs; dest_idx++) {
1089        const RegId& dest_reg = inst->destRegIdx(dest_idx);
1090        typename RenameMap::RenameInfo rename_result;
1091
1092        RegId flat_dest_regid = tc->flattenRegId(dest_reg);
1093
1094        rename_result = map->rename(flat_dest_regid);
1095
1096        inst->flattenDestReg(dest_idx, flat_dest_regid);
1097
1098        // Mark Scoreboard entry as not ready
1099        scoreboard->unsetReg(rename_result.first);
1100
1101        DPRINTF(Rename, "[tid:%u]: Renaming arch reg %i (%s) to physical "
1102                "reg %i (%i).\n", tid, dest_reg.index(),
1103                dest_reg.className(),
1104                rename_result.first->index(),
1105                rename_result.first->flatIndex());
1106
1107        // Record the rename information so that a history can be kept.
1108        RenameHistory hb_entry(inst->seqNum, flat_dest_regid,
1109                               rename_result.first,
1110                               rename_result.second);
1111
1112        historyBuffer[tid].push_front(hb_entry);
1113
1114        DPRINTF(Rename, "[tid:%u]: Adding instruction to history buffer "
1115                "(size=%i), [sn:%lli].\n",tid,
1116                historyBuffer[tid].size(),
1117                (*historyBuffer[tid].begin()).instSeqNum);
1118
1119        // Tell the instruction to rename the appropriate destination
1120        // register (dest_idx) to the new physical register
1121        // (rename_result.first), and record the previous physical
1122        // register that the same logical register was renamed to
1123        // (rename_result.second).
1124        inst->renameDestReg(dest_idx,
1125                            rename_result.first,
1126                            rename_result.second);
1127
1128        ++renameRenamedOperands;
1129    }
1130}
1131
1132template <class Impl>
1133inline int
1134DefaultRename<Impl>::calcFreeROBEntries(ThreadID tid)
1135{
1136    int num_free = freeEntries[tid].robEntries -
1137                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched);
1138
1139    //DPRINTF(Rename,"[tid:%i]: %i rob free\n",tid,num_free);
1140
1141    return num_free;
1142}
1143
1144template <class Impl>
1145inline int
1146DefaultRename<Impl>::calcFreeIQEntries(ThreadID tid)
1147{
1148    int num_free = freeEntries[tid].iqEntries -
1149                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched);
1150
1151    //DPRINTF(Rename,"[tid:%i]: %i iq free\n",tid,num_free);
1152
1153    return num_free;
1154}
1155
1156template <class Impl>
1157inline int
1158DefaultRename<Impl>::calcFreeLQEntries(ThreadID tid)
1159{
1160        int num_free = freeEntries[tid].lqEntries -
1161                                  (loadsInProgress[tid] - fromIEW->iewInfo[tid].dispatchedToLQ);
1162        DPRINTF(Rename, "calcFreeLQEntries: free lqEntries: %d, loadsInProgress: %d, "
1163                "loads dispatchedToLQ: %d\n", freeEntries[tid].lqEntries,
1164                loadsInProgress[tid], fromIEW->iewInfo[tid].dispatchedToLQ);
1165        return num_free;
1166}
1167
1168template <class Impl>
1169inline int
1170DefaultRename<Impl>::calcFreeSQEntries(ThreadID tid)
1171{
1172        int num_free = freeEntries[tid].sqEntries -
1173                                  (storesInProgress[tid] - fromIEW->iewInfo[tid].dispatchedToSQ);
1174        DPRINTF(Rename, "calcFreeSQEntries: free sqEntries: %d, storesInProgress: %d, "
1175                "stores dispatchedToSQ: %d\n", freeEntries[tid].sqEntries,
1176                storesInProgress[tid], fromIEW->iewInfo[tid].dispatchedToSQ);
1177        return num_free;
1178}
1179
1180template <class Impl>
1181unsigned
1182DefaultRename<Impl>::validInsts()
1183{
1184    unsigned inst_count = 0;
1185
1186    for (int i=0; i<fromDecode->size; i++) {
1187        if (!fromDecode->insts[i]->isSquashed())
1188            inst_count++;
1189    }
1190
1191    return inst_count;
1192}
1193
1194template <class Impl>
1195void
1196DefaultRename<Impl>::readStallSignals(ThreadID tid)
1197{
1198    if (fromIEW->iewBlock[tid]) {
1199        stalls[tid].iew = true;
1200    }
1201
1202    if (fromIEW->iewUnblock[tid]) {
1203        assert(stalls[tid].iew);
1204        stalls[tid].iew = false;
1205    }
1206}
1207
1208template <class Impl>
1209bool
1210DefaultRename<Impl>::checkStall(ThreadID tid)
1211{
1212    bool ret_val = false;
1213
1214    if (stalls[tid].iew) {
1215        DPRINTF(Rename,"[tid:%i]: Stall from IEW stage detected.\n", tid);
1216        ret_val = true;
1217    } else if (calcFreeROBEntries(tid) <= 0) {
1218        DPRINTF(Rename,"[tid:%i]: Stall: ROB has 0 free entries.\n", tid);
1219        ret_val = true;
1220    } else if (calcFreeIQEntries(tid) <= 0) {
1221        DPRINTF(Rename,"[tid:%i]: Stall: IQ has 0 free entries.\n", tid);
1222        ret_val = true;
1223    } else if (calcFreeLQEntries(tid) <= 0 && calcFreeSQEntries(tid) <= 0) {
1224        DPRINTF(Rename,"[tid:%i]: Stall: LSQ has 0 free entries.\n", tid);
1225        ret_val = true;
1226    } else if (renameMap[tid]->numFreeEntries() <= 0) {
1227        DPRINTF(Rename,"[tid:%i]: Stall: RenameMap has 0 free entries.\n", tid);
1228        ret_val = true;
1229    } else if (renameStatus[tid] == SerializeStall &&
1230               (!emptyROB[tid] || instsInProgress[tid])) {
1231        DPRINTF(Rename,"[tid:%i]: Stall: Serialize stall and ROB is not "
1232                "empty.\n",
1233                tid);
1234        ret_val = true;
1235    }
1236
1237    return ret_val;
1238}
1239
1240template <class Impl>
1241void
1242DefaultRename<Impl>::readFreeEntries(ThreadID tid)
1243{
1244    if (fromIEW->iewInfo[tid].usedIQ)
1245        freeEntries[tid].iqEntries = fromIEW->iewInfo[tid].freeIQEntries;
1246
1247    if (fromIEW->iewInfo[tid].usedLSQ) {
1248        freeEntries[tid].lqEntries = fromIEW->iewInfo[tid].freeLQEntries;
1249        freeEntries[tid].sqEntries = fromIEW->iewInfo[tid].freeSQEntries;
1250    }
1251
1252    if (fromCommit->commitInfo[tid].usedROB) {
1253        freeEntries[tid].robEntries =
1254            fromCommit->commitInfo[tid].freeROBEntries;
1255        emptyROB[tid] = fromCommit->commitInfo[tid].emptyROB;
1256    }
1257
1258    DPRINTF(Rename, "[tid:%i]: Free IQ: %i, Free ROB: %i, "
1259                    "Free LQ: %i, Free SQ: %i, FreeRM %i(%i %i %i %i)\n",
1260            tid,
1261            freeEntries[tid].iqEntries,
1262            freeEntries[tid].robEntries,
1263            freeEntries[tid].lqEntries,
1264            freeEntries[tid].sqEntries,
1265            renameMap[tid]->numFreeEntries(),
1266            renameMap[tid]->numFreeIntEntries(),
1267            renameMap[tid]->numFreeFloatEntries(),
1268            renameMap[tid]->numFreeVecEntries(),
1269            renameMap[tid]->numFreeCCEntries());
1270
1271    DPRINTF(Rename, "[tid:%i]: %i instructions not yet in ROB\n",
1272            tid, instsInProgress[tid]);
1273}
1274
1275template <class Impl>
1276bool
1277DefaultRename<Impl>::checkSignalsAndUpdate(ThreadID tid)
1278{
1279    // Check if there's a squash signal, squash if there is
1280    // Check stall signals, block if necessary.
1281    // If status was blocked
1282    //     check if stall conditions have passed
1283    //         if so then go to unblocking
1284    // If status was Squashing
1285    //     check if squashing is not high.  Switch to running this cycle.
1286    // If status was serialize stall
1287    //     check if ROB is empty and no insts are in flight to the ROB
1288
1289    readFreeEntries(tid);
1290    readStallSignals(tid);
1291
1292    if (fromCommit->commitInfo[tid].squash) {
1293        DPRINTF(Rename, "[tid:%u]: Squashing instructions due to squash from "
1294                "commit.\n", tid);
1295
1296        squash(fromCommit->commitInfo[tid].doneSeqNum, tid);
1297
1298        return true;
1299    }
1300
1301    if (checkStall(tid)) {
1302        return block(tid);
1303    }
1304
1305    if (renameStatus[tid] == Blocked) {
1306        DPRINTF(Rename, "[tid:%u]: Done blocking, switching to unblocking.\n",
1307                tid);
1308
1309        renameStatus[tid] = Unblocking;
1310
1311        unblock(tid);
1312
1313        return true;
1314    }
1315
1316    if (renameStatus[tid] == Squashing) {
1317        // Switch status to running if rename isn't being told to block or
1318        // squash this cycle.
1319        if (resumeSerialize) {
1320            DPRINTF(Rename, "[tid:%u]: Done squashing, switching to serialize.\n",
1321                    tid);
1322
1323            renameStatus[tid] = SerializeStall;
1324            return true;
1325        } else if (resumeUnblocking) {
1326            DPRINTF(Rename, "[tid:%u]: Done squashing, switching to unblocking.\n",
1327                    tid);
1328            renameStatus[tid] = Unblocking;
1329            return true;
1330        } else {
1331            DPRINTF(Rename, "[tid:%u]: Done squashing, switching to running.\n",
1332                    tid);
1333
1334            renameStatus[tid] = Running;
1335            return false;
1336        }
1337    }
1338
1339    if (renameStatus[tid] == SerializeStall) {
1340        // Stall ends once the ROB is free.
1341        DPRINTF(Rename, "[tid:%u]: Done with serialize stall, switching to "
1342                "unblocking.\n", tid);
1343
1344        DynInstPtr serial_inst = serializeInst[tid];
1345
1346        renameStatus[tid] = Unblocking;
1347
1348        unblock(tid);
1349
1350        DPRINTF(Rename, "[tid:%u]: Processing instruction [%lli] with "
1351                "PC %s.\n", tid, serial_inst->seqNum, serial_inst->pcState());
1352
1353        // Put instruction into queue here.
1354        serial_inst->clearSerializeBefore();
1355
1356        if (!skidBuffer[tid].empty()) {
1357            skidBuffer[tid].push_front(serial_inst);
1358        } else {
1359            insts[tid].push_front(serial_inst);
1360        }
1361
1362        DPRINTF(Rename, "[tid:%u]: Instruction must be processed by rename."
1363                " Adding to front of list.\n", tid);
1364
1365        serializeInst[tid] = NULL;
1366
1367        return true;
1368    }
1369
1370    // If we've reached this point, we have not gotten any signals that
1371    // cause rename to change its status.  Rename remains the same as before.
1372    return false;
1373}
1374
1375template<class Impl>
1376void
1377DefaultRename<Impl>::serializeAfter(InstQueue &inst_list, ThreadID tid)
1378{
1379    if (inst_list.empty()) {
1380        // Mark a bit to say that I must serialize on the next instruction.
1381        serializeOnNextInst[tid] = true;
1382        return;
1383    }
1384
1385    // Set the next instruction as serializing.
1386    inst_list.front()->setSerializeBefore();
1387}
1388
1389template <class Impl>
1390inline void
1391DefaultRename<Impl>::incrFullStat(const FullSource &source)
1392{
1393    switch (source) {
1394      case ROB:
1395        ++renameROBFullEvents;
1396        break;
1397      case IQ:
1398        ++renameIQFullEvents;
1399        break;
1400      case LQ:
1401        ++renameLQFullEvents;
1402        break;
1403      case SQ:
1404        ++renameSQFullEvents;
1405        break;
1406      default:
1407        panic("Rename full stall stat should be incremented for a reason!");
1408        break;
1409    }
1410}
1411
1412template <class Impl>
1413void
1414DefaultRename<Impl>::dumpHistory()
1415{
1416    typename std::list<RenameHistory>::iterator buf_it;
1417
1418    for (ThreadID tid = 0; tid < numThreads; tid++) {
1419
1420        buf_it = historyBuffer[tid].begin();
1421
1422        while (buf_it != historyBuffer[tid].end()) {
1423            cprintf("Seq num: %i\nArch reg[%s]: %i New phys reg:"
1424                    " %i[%s] Old phys reg: %i[%s]\n",
1425                    (*buf_it).instSeqNum,
1426                    (*buf_it).archReg.className(),
1427                    (*buf_it).archReg.index(),
1428                    (*buf_it).newPhysReg->index(),
1429                    (*buf_it).newPhysReg->className(),
1430                    (*buf_it).prevPhysReg->index(),
1431                    (*buf_it).prevPhysReg->className());
1432
1433            buf_it++;
1434        }
1435    }
1436}
1437
1438#endif//__CPU_O3_RENAME_IMPL_HH__
1439