1/*
2 * Copyright (c) 2010-2012, 2014-2019 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    vecPredRenameLookups
200        .name(name() + ".vec_pred_rename_lookups")
201        .desc("Number of vector predicate rename lookups")
202        .prereq(vecPredRenameLookups);
203}
204
205template <class Impl>
206void
207DefaultRename<Impl>::regProbePoints()
208{
209    ppRename = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "Rename");
210    ppSquashInRename = new ProbePointArg<SeqNumRegPair>(cpu->getProbeManager(),
211                                                        "SquashInRename");
212}
213
214template <class Impl>
215void
216DefaultRename<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
217{
218    timeBuffer = tb_ptr;
219
220    // Setup wire to read information from time buffer, from IEW stage.
221    fromIEW = timeBuffer->getWire(-iewToRenameDelay);
222
223    // Setup wire to read infromation from time buffer, from commit stage.
224    fromCommit = timeBuffer->getWire(-commitToRenameDelay);
225
226    // Setup wire to write information to previous stages.
227    toDecode = timeBuffer->getWire(0);
228}
229
230template <class Impl>
231void
232DefaultRename<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr)
233{
234    renameQueue = rq_ptr;
235
236    // Setup wire to write information to future stages.
237    toIEW = renameQueue->getWire(0);
238}
239
240template <class Impl>
241void
242DefaultRename<Impl>::setDecodeQueue(TimeBuffer<DecodeStruct> *dq_ptr)
243{
244    decodeQueue = dq_ptr;
245
246    // Setup wire to get information from decode.
247    fromDecode = decodeQueue->getWire(-decodeToRenameDelay);
248}
249
250template <class Impl>
251void
252DefaultRename<Impl>::startupStage()
253{
254    resetStage();
255}
256
257template <class Impl>
258void
259DefaultRename<Impl>::clearStates(ThreadID tid)
260{
261    renameStatus[tid] = Idle;
262
263    freeEntries[tid].iqEntries = iew_ptr->instQueue.numFreeEntries(tid);
264    freeEntries[tid].lqEntries = iew_ptr->ldstQueue.numFreeLoadEntries(tid);
265    freeEntries[tid].sqEntries = iew_ptr->ldstQueue.numFreeStoreEntries(tid);
266    freeEntries[tid].robEntries = commit_ptr->numROBFreeEntries(tid);
267    emptyROB[tid] = true;
268
269    stalls[tid].iew = false;
270    serializeInst[tid] = NULL;
271
272    instsInProgress[tid] = 0;
273    loadsInProgress[tid] = 0;
274    storesInProgress[tid] = 0;
275
276    serializeOnNextInst[tid] = false;
277}
278
279template <class Impl>
280void
281DefaultRename<Impl>::resetStage()
282{
283    _status = Inactive;
284
285    resumeSerialize = false;
286    resumeUnblocking = false;
287
288    // Grab the number of free entries directly from the stages.
289    for (ThreadID tid = 0; tid < numThreads; tid++) {
290        renameStatus[tid] = Idle;
291
292        freeEntries[tid].iqEntries = iew_ptr->instQueue.numFreeEntries(tid);
293        freeEntries[tid].lqEntries = iew_ptr->ldstQueue.numFreeLoadEntries(tid);
294        freeEntries[tid].sqEntries = iew_ptr->ldstQueue.numFreeStoreEntries(tid);
295        freeEntries[tid].robEntries = commit_ptr->numROBFreeEntries(tid);
296        emptyROB[tid] = true;
297
298        stalls[tid].iew = false;
299        serializeInst[tid] = NULL;
300
301        instsInProgress[tid] = 0;
302        loadsInProgress[tid] = 0;
303        storesInProgress[tid] = 0;
304
305        serializeOnNextInst[tid] = false;
306    }
307}
308
309template<class Impl>
310void
311DefaultRename<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
312{
313    activeThreads = at_ptr;
314}
315
316
317template <class Impl>
318void
319DefaultRename<Impl>::setRenameMap(RenameMap rm_ptr[])
320{
321    for (ThreadID tid = 0; tid < numThreads; tid++)
322        renameMap[tid] = &rm_ptr[tid];
323}
324
325template <class Impl>
326void
327DefaultRename<Impl>::setFreeList(FreeList *fl_ptr)
328{
329    freeList = fl_ptr;
330}
331
332template<class Impl>
333void
334DefaultRename<Impl>::setScoreboard(Scoreboard *_scoreboard)
335{
336    scoreboard = _scoreboard;
337}
338
339template <class Impl>
340bool
341DefaultRename<Impl>::isDrained() const
342{
343    for (ThreadID tid = 0; tid < numThreads; tid++) {
344        if (instsInProgress[tid] != 0 ||
345            !historyBuffer[tid].empty() ||
346            !skidBuffer[tid].empty() ||
347            !insts[tid].empty() ||
348            (renameStatus[tid] != Idle && renameStatus[tid] != Running))
349            return false;
350    }
351    return true;
352}
353
354template <class Impl>
355void
356DefaultRename<Impl>::takeOverFrom()
357{
358    resetStage();
359}
360
361template <class Impl>
362void
363DefaultRename<Impl>::drainSanityCheck() const
364{
365    for (ThreadID tid = 0; tid < numThreads; tid++) {
366        assert(historyBuffer[tid].empty());
367        assert(insts[tid].empty());
368        assert(skidBuffer[tid].empty());
369        assert(instsInProgress[tid] == 0);
370    }
371}
372
373template <class Impl>
374void
375DefaultRename<Impl>::squash(const InstSeqNum &squash_seq_num, ThreadID tid)
376{
377    DPRINTF(Rename, "[tid:%i] [squash sn:%llu] Squashing instructions.\n",
378        tid,squash_seq_num);
379
380    // Clear the stall signal if rename was blocked or unblocking before.
381    // If it still needs to block, the blocking should happen the next
382    // cycle and there should be space to hold everything due to the squash.
383    if (renameStatus[tid] == Blocked ||
384        renameStatus[tid] == Unblocking) {
385        toDecode->renameUnblock[tid] = 1;
386
387        resumeSerialize = false;
388        serializeInst[tid] = NULL;
389    } else if (renameStatus[tid] == SerializeStall) {
390        if (serializeInst[tid]->seqNum <= squash_seq_num) {
391            DPRINTF(Rename, "[tid:%i] [squash sn:%llu] "
392                "Rename will resume serializing after squash\n",
393                tid,squash_seq_num);
394            resumeSerialize = true;
395            assert(serializeInst[tid]);
396        } else {
397            resumeSerialize = false;
398            toDecode->renameUnblock[tid] = 1;
399
400            serializeInst[tid] = NULL;
401        }
402    }
403
404    // Set the status to Squashing.
405    renameStatus[tid] = Squashing;
406
407    // Squash any instructions from decode.
408    for (int i=0; i<fromDecode->size; i++) {
409        if (fromDecode->insts[i]->threadNumber == tid &&
410            fromDecode->insts[i]->seqNum > squash_seq_num) {
411            fromDecode->insts[i]->setSquashed();
412            wroteToTimeBuffer = true;
413        }
414
415    }
416
417    // Clear the instruction list and skid buffer in case they have any
418    // insts in them.
419    insts[tid].clear();
420
421    // Clear the skid buffer in case it has any data in it.
422    skidBuffer[tid].clear();
423
424    doSquash(squash_seq_num, tid);
425}
426
427template <class Impl>
428void
429DefaultRename<Impl>::tick()
430{
431    wroteToTimeBuffer = false;
432
433    blockThisCycle = false;
434
435    bool status_change = false;
436
437    toIEWIndex = 0;
438
439    sortInsts();
440
441    list<ThreadID>::iterator threads = activeThreads->begin();
442    list<ThreadID>::iterator end = activeThreads->end();
443
444    // Check stall and squash signals.
445    while (threads != end) {
446        ThreadID tid = *threads++;
447
448        DPRINTF(Rename, "Processing [tid:%i]\n", tid);
449
450        status_change = checkSignalsAndUpdate(tid) || status_change;
451
452        rename(status_change, tid);
453    }
454
455    if (status_change) {
456        updateStatus();
457    }
458
459    if (wroteToTimeBuffer) {
460        DPRINTF(Activity, "Activity this cycle.\n");
461        cpu->activityThisCycle();
462    }
463
464    threads = activeThreads->begin();
465
466    while (threads != end) {
467        ThreadID tid = *threads++;
468
469        // If we committed this cycle then doneSeqNum will be > 0
470        if (fromCommit->commitInfo[tid].doneSeqNum != 0 &&
471            !fromCommit->commitInfo[tid].squash &&
472            renameStatus[tid] != Squashing) {
473
474            removeFromHistory(fromCommit->commitInfo[tid].doneSeqNum,
475                                  tid);
476        }
477    }
478
479    // @todo: make into updateProgress function
480    for (ThreadID tid = 0; tid < numThreads; tid++) {
481        instsInProgress[tid] -= fromIEW->iewInfo[tid].dispatched;
482        loadsInProgress[tid] -= fromIEW->iewInfo[tid].dispatchedToLQ;
483        storesInProgress[tid] -= fromIEW->iewInfo[tid].dispatchedToSQ;
484        assert(loadsInProgress[tid] >= 0);
485        assert(storesInProgress[tid] >= 0);
486        assert(instsInProgress[tid] >=0);
487    }
488
489}
490
491template<class Impl>
492void
493DefaultRename<Impl>::rename(bool &status_change, ThreadID tid)
494{
495    // If status is Running or idle,
496    //     call renameInsts()
497    // If status is Unblocking,
498    //     buffer any instructions coming from decode
499    //     continue trying to empty skid buffer
500    //     check if stall conditions have passed
501
502    if (renameStatus[tid] == Blocked) {
503        ++renameBlockCycles;
504    } else if (renameStatus[tid] == Squashing) {
505        ++renameSquashCycles;
506    } else if (renameStatus[tid] == SerializeStall) {
507        ++renameSerializeStallCycles;
508        // If we are currently in SerializeStall and resumeSerialize
509        // was set, then that means that we are resuming serializing
510        // this cycle.  Tell the previous stages to block.
511        if (resumeSerialize) {
512            resumeSerialize = false;
513            block(tid);
514            toDecode->renameUnblock[tid] = false;
515        }
516    } else if (renameStatus[tid] == Unblocking) {
517        if (resumeUnblocking) {
518            block(tid);
519            resumeUnblocking = false;
520            toDecode->renameUnblock[tid] = false;
521        }
522    }
523
524    if (renameStatus[tid] == Running ||
525        renameStatus[tid] == Idle) {
526        DPRINTF(Rename,
527                "[tid:%i] "
528                "Not blocked, so attempting to run stage.\n",
529                tid);
530
531        renameInsts(tid);
532    } else if (renameStatus[tid] == Unblocking) {
533        renameInsts(tid);
534
535        if (validInsts()) {
536            // Add the current inputs to the skid buffer so they can be
537            // reprocessed when this stage unblocks.
538            skidInsert(tid);
539        }
540
541        // If we switched over to blocking, then there's a potential for
542        // an overall status change.
543        status_change = unblock(tid) || status_change || blockThisCycle;
544    }
545}
546
547template <class Impl>
548void
549DefaultRename<Impl>::renameInsts(ThreadID tid)
550{
551    // Instructions can be either in the skid buffer or the queue of
552    // instructions coming from decode, depending on the status.
553    int insts_available = renameStatus[tid] == Unblocking ?
554        skidBuffer[tid].size() : insts[tid].size();
555
556    // Check the decode queue to see if instructions are available.
557    // If there are no available instructions to rename, then do nothing.
558    if (insts_available == 0) {
559        DPRINTF(Rename, "[tid:%i] Nothing to do, breaking out early.\n",
560                tid);
561        // Should I change status to idle?
562        ++renameIdleCycles;
563        return;
564    } else if (renameStatus[tid] == Unblocking) {
565        ++renameUnblockCycles;
566    } else if (renameStatus[tid] == Running) {
567        ++renameRunCycles;
568    }
569
570    // Will have to do a different calculation for the number of free
571    // entries.
572    int free_rob_entries = calcFreeROBEntries(tid);
573    int free_iq_entries  = calcFreeIQEntries(tid);
574    int min_free_entries = free_rob_entries;
575
576    FullSource source = ROB;
577
578    if (free_iq_entries < min_free_entries) {
579        min_free_entries = free_iq_entries;
580        source = IQ;
581    }
582
583    // Check if there's any space left.
584    if (min_free_entries <= 0) {
585        DPRINTF(Rename,
586                "[tid:%i] Blocking due to no free ROB/IQ/ entries.\n"
587                "ROB has %i free entries.\n"
588                "IQ has %i free entries.\n",
589                tid, free_rob_entries, free_iq_entries);
590
591        blockThisCycle = true;
592
593        block(tid);
594
595        incrFullStat(source);
596
597        return;
598    } else if (min_free_entries < insts_available) {
599        DPRINTF(Rename,
600                "[tid:%i] "
601                "Will have to block this cycle. "
602                "%i insts available, "
603                "but only %i insts can be renamed due to ROB/IQ/LSQ limits.\n",
604                tid, insts_available, min_free_entries);
605
606        insts_available = min_free_entries;
607
608        blockThisCycle = true;
609
610        incrFullStat(source);
611    }
612
613    InstQueue &insts_to_rename = renameStatus[tid] == Unblocking ?
614        skidBuffer[tid] : insts[tid];
615
616    DPRINTF(Rename,
617            "[tid:%i] "
618            "%i available instructions to send iew.\n",
619            tid, insts_available);
620
621    DPRINTF(Rename,
622            "[tid:%i] "
623            "%i insts pipelining from Rename | "
624            "%i insts dispatched to IQ last cycle.\n",
625            tid, instsInProgress[tid], fromIEW->iewInfo[tid].dispatched);
626
627    // Handle serializing the next instruction if necessary.
628    if (serializeOnNextInst[tid]) {
629        if (emptyROB[tid] && instsInProgress[tid] == 0) {
630            // ROB already empty; no need to serialize.
631            serializeOnNextInst[tid] = false;
632        } else if (!insts_to_rename.empty()) {
633            insts_to_rename.front()->setSerializeBefore();
634        }
635    }
636
637    int renamed_insts = 0;
638
639    while (insts_available > 0 &&  toIEWIndex < renameWidth) {
640        DPRINTF(Rename, "[tid:%i] Sending instructions to IEW.\n", tid);
641
642        assert(!insts_to_rename.empty());
643
644        DynInstPtr inst = insts_to_rename.front();
645
646        //For all kind of instructions, check ROB and IQ first
647        //For load instruction, check LQ size and take into account the inflight loads
648        //For store instruction, check SQ size and take into account the inflight stores
649
650        if (inst->isLoad()) {
651            if (calcFreeLQEntries(tid) <= 0) {
652                DPRINTF(Rename, "[tid:%i] Cannot rename due to no free LQ\n");
653                source = LQ;
654                incrFullStat(source);
655                break;
656            }
657        }
658
659        if (inst->isStore() || inst->isAtomic()) {
660            if (calcFreeSQEntries(tid) <= 0) {
661                DPRINTF(Rename, "[tid:%i] Cannot rename due to no free SQ\n");
662                source = SQ;
663                incrFullStat(source);
664                break;
665            }
666        }
667
668        insts_to_rename.pop_front();
669
670        if (renameStatus[tid] == Unblocking) {
671            DPRINTF(Rename,
672                    "[tid:%i] "
673                    "Removing [sn:%llu] PC:%s from rename skidBuffer\n",
674                    tid, inst->seqNum, inst->pcState());
675        }
676
677        if (inst->isSquashed()) {
678            DPRINTF(Rename,
679                    "[tid:%i] "
680                    "instruction %i with PC %s is squashed, skipping.\n",
681                    tid, inst->seqNum, inst->pcState());
682
683            ++renameSquashedInsts;
684
685            // Decrement how many instructions are available.
686            --insts_available;
687
688            continue;
689        }
690
691        DPRINTF(Rename,
692                "[tid:%i] "
693                "Processing instruction [sn:%llu] with PC %s.\n",
694                tid, inst->seqNum, inst->pcState());
695
696        // Check here to make sure there are enough destination registers
697        // to rename to.  Otherwise block.
698        if (!renameMap[tid]->canRename(inst->numIntDestRegs(),
699                                       inst->numFPDestRegs(),
700                                       inst->numVecDestRegs(),
701                                       inst->numVecElemDestRegs(),
702                                       inst->numVecPredDestRegs(),
703                                       inst->numCCDestRegs())) {
704            DPRINTF(Rename,
705                    "Blocking due to "
706                    " lack of free physical registers to rename to.\n");
707            blockThisCycle = true;
708            insts_to_rename.push_front(inst);
709            ++renameFullRegistersEvents;
710
711            break;
712        }
713
714        // Handle serializeAfter/serializeBefore instructions.
715        // serializeAfter marks the next instruction as serializeBefore.
716        // serializeBefore makes the instruction wait in rename until the ROB
717        // is empty.
718
719        // In this model, IPR accesses are serialize before
720        // instructions, and store conditionals are serialize after
721        // instructions.  This is mainly due to lack of support for
722        // out-of-order operations of either of those classes of
723        // instructions.
724        if ((inst->isIprAccess() || inst->isSerializeBefore()) &&
725            !inst->isSerializeHandled()) {
726            DPRINTF(Rename, "Serialize before instruction encountered.\n");
727
728            if (!inst->isTempSerializeBefore()) {
729                renamedSerializing++;
730                inst->setSerializeHandled();
731            } else {
732                renamedTempSerializing++;
733            }
734
735            // Change status over to SerializeStall so that other stages know
736            // what this is blocked on.
737            renameStatus[tid] = SerializeStall;
738
739            serializeInst[tid] = inst;
740
741            blockThisCycle = true;
742
743            break;
744        } else if ((inst->isStoreConditional() || inst->isSerializeAfter()) &&
745                   !inst->isSerializeHandled()) {
746            DPRINTF(Rename, "Serialize after instruction encountered.\n");
747
748            renamedSerializing++;
749
750            inst->setSerializeHandled();
751
752            serializeAfter(insts_to_rename, tid);
753        }
754
755        renameSrcRegs(inst, inst->threadNumber);
756
757        renameDestRegs(inst, inst->threadNumber);
758
759        if (inst->isAtomic() || inst->isStore()) {
760            storesInProgress[tid]++;
761        } else if (inst->isLoad()) {
762            loadsInProgress[tid]++;
763        }
764
765        ++renamed_insts;
766        // Notify potential listeners that source and destination registers for
767        // this instruction have been renamed.
768        ppRename->notify(inst);
769
770        // Put instruction in rename queue.
771        toIEW->insts[toIEWIndex] = inst;
772        ++(toIEW->size);
773
774        // Increment which instruction we're on.
775        ++toIEWIndex;
776
777        // Decrement how many instructions are available.
778        --insts_available;
779    }
780
781    instsInProgress[tid] += renamed_insts;
782    renameRenamedInsts += renamed_insts;
783
784    // If we wrote to the time buffer, record this.
785    if (toIEWIndex) {
786        wroteToTimeBuffer = true;
787    }
788
789    // Check if there's any instructions left that haven't yet been renamed.
790    // If so then block.
791    if (insts_available) {
792        blockThisCycle = true;
793    }
794
795    if (blockThisCycle) {
796        block(tid);
797        toDecode->renameUnblock[tid] = false;
798    }
799}
800
801template<class Impl>
802void
803DefaultRename<Impl>::skidInsert(ThreadID tid)
804{
805    DynInstPtr inst = NULL;
806
807    while (!insts[tid].empty()) {
808        inst = insts[tid].front();
809
810        insts[tid].pop_front();
811
812        assert(tid == inst->threadNumber);
813
814        DPRINTF(Rename, "[tid:%i] Inserting [sn:%llu] PC: %s into Rename "
815                "skidBuffer\n", tid, inst->seqNum, inst->pcState());
816
817        ++renameSkidInsts;
818
819        skidBuffer[tid].push_back(inst);
820    }
821
822    if (skidBuffer[tid].size() > skidBufferMax)
823    {
824        typename InstQueue::iterator it;
825        warn("Skidbuffer contents:\n");
826        for (it = skidBuffer[tid].begin(); it != skidBuffer[tid].end(); it++)
827        {
828            warn("[tid:%i] %s [sn:%llu].\n", tid,
829                    (*it)->staticInst->disassemble(inst->instAddr()),
830                    (*it)->seqNum);
831        }
832        panic("Skidbuffer Exceeded Max Size");
833    }
834}
835
836template <class Impl>
837void
838DefaultRename<Impl>::sortInsts()
839{
840    int insts_from_decode = fromDecode->size;
841    for (int i = 0; i < insts_from_decode; ++i) {
842        const DynInstPtr &inst = fromDecode->insts[i];
843        insts[inst->threadNumber].push_back(inst);
844#if TRACING_ON
845        if (DTRACE(O3PipeView)) {
846            inst->renameTick = curTick() - inst->fetchTick;
847        }
848#endif
849    }
850}
851
852template<class Impl>
853bool
854DefaultRename<Impl>::skidsEmpty()
855{
856    list<ThreadID>::iterator threads = activeThreads->begin();
857    list<ThreadID>::iterator end = activeThreads->end();
858
859    while (threads != end) {
860        ThreadID tid = *threads++;
861
862        if (!skidBuffer[tid].empty())
863            return false;
864    }
865
866    return true;
867}
868
869template<class Impl>
870void
871DefaultRename<Impl>::updateStatus()
872{
873    bool any_unblocking = false;
874
875    list<ThreadID>::iterator threads = activeThreads->begin();
876    list<ThreadID>::iterator end = activeThreads->end();
877
878    while (threads != end) {
879        ThreadID tid = *threads++;
880
881        if (renameStatus[tid] == Unblocking) {
882            any_unblocking = true;
883            break;
884        }
885    }
886
887    // Rename will have activity if it's unblocking.
888    if (any_unblocking) {
889        if (_status == Inactive) {
890            _status = Active;
891
892            DPRINTF(Activity, "Activating stage.\n");
893
894            cpu->activateStage(O3CPU::RenameIdx);
895        }
896    } else {
897        // If it's not unblocking, then rename will not have any internal
898        // activity.  Switch it to inactive.
899        if (_status == Active) {
900            _status = Inactive;
901            DPRINTF(Activity, "Deactivating stage.\n");
902
903            cpu->deactivateStage(O3CPU::RenameIdx);
904        }
905    }
906}
907
908template <class Impl>
909bool
910DefaultRename<Impl>::block(ThreadID tid)
911{
912    DPRINTF(Rename, "[tid:%i] Blocking.\n", tid);
913
914    // Add the current inputs onto the skid buffer, so they can be
915    // reprocessed when this stage unblocks.
916    skidInsert(tid);
917
918    // Only signal backwards to block if the previous stages do not think
919    // rename is already blocked.
920    if (renameStatus[tid] != Blocked) {
921        // If resumeUnblocking is set, we unblocked during the squash,
922        // but now we're have unblocking status. We need to tell earlier
923        // stages to block.
924        if (resumeUnblocking || renameStatus[tid] != Unblocking) {
925            toDecode->renameBlock[tid] = true;
926            toDecode->renameUnblock[tid] = false;
927            wroteToTimeBuffer = true;
928        }
929
930        // Rename can not go from SerializeStall to Blocked, otherwise
931        // it would not know to complete the serialize stall.
932        if (renameStatus[tid] != SerializeStall) {
933            // Set status to Blocked.
934            renameStatus[tid] = Blocked;
935            return true;
936        }
937    }
938
939    return false;
940}
941
942template <class Impl>
943bool
944DefaultRename<Impl>::unblock(ThreadID tid)
945{
946    DPRINTF(Rename, "[tid:%i] Trying to unblock.\n", tid);
947
948    // Rename is done unblocking if the skid buffer is empty.
949    if (skidBuffer[tid].empty() && renameStatus[tid] != SerializeStall) {
950
951        DPRINTF(Rename, "[tid:%i] Done unblocking.\n", tid);
952
953        toDecode->renameUnblock[tid] = true;
954        wroteToTimeBuffer = true;
955
956        renameStatus[tid] = Running;
957        return true;
958    }
959
960    return false;
961}
962
963template <class Impl>
964void
965DefaultRename<Impl>::doSquash(const InstSeqNum &squashed_seq_num, ThreadID tid)
966{
967    typename std::list<RenameHistory>::iterator hb_it =
968        historyBuffer[tid].begin();
969
970    // After a syscall squashes everything, the history buffer may be empty
971    // but the ROB may still be squashing instructions.
972    // Go through the most recent instructions, undoing the mappings
973    // they did and freeing up the registers.
974    while (!historyBuffer[tid].empty() &&
975           hb_it->instSeqNum > squashed_seq_num) {
976        assert(hb_it != historyBuffer[tid].end());
977
978        DPRINTF(Rename, "[tid:%i] Removing history entry with sequence "
979                "number %i (archReg: %d, newPhysReg: %d, prevPhysReg: %d).\n",
980                tid, hb_it->instSeqNum, hb_it->archReg.index(),
981                hb_it->newPhysReg->index(), hb_it->prevPhysReg->index());
982
983        // Undo the rename mapping only if it was really a change.
984        // Special regs that are not really renamed (like misc regs
985        // and the zero reg) can be recognized because the new mapping
986        // is the same as the old one.  While it would be merely a
987        // waste of time to update the rename table, we definitely
988        // don't want to put these on the free list.
989        if (hb_it->newPhysReg != hb_it->prevPhysReg) {
990            // Tell the rename map to set the architected register to the
991            // previous physical register that it was renamed to.
992            renameMap[tid]->setEntry(hb_it->archReg, hb_it->prevPhysReg);
993
994            // Put the renamed physical register back on the free list.
995            freeList->addReg(hb_it->newPhysReg);
996        }
997
998        // Notify potential listeners that the register mapping needs to be
999        // removed because the instruction it was mapped to got squashed. Note
1000        // that this is done before hb_it is incremented.
1001        ppSquashInRename->notify(std::make_pair(hb_it->instSeqNum,
1002                                                hb_it->newPhysReg));
1003
1004        historyBuffer[tid].erase(hb_it++);
1005
1006        ++renameUndoneMaps;
1007    }
1008
1009    // Check if we need to change vector renaming mode after squashing
1010    cpu->switchRenameMode(tid, freeList);
1011}
1012
1013template<class Impl>
1014void
1015DefaultRename<Impl>::removeFromHistory(InstSeqNum inst_seq_num, ThreadID tid)
1016{
1017    DPRINTF(Rename, "[tid:%i] Removing a committed instruction from the "
1018            "history buffer %u (size=%i), until [sn:%llu].\n",
1019            tid, tid, historyBuffer[tid].size(), inst_seq_num);
1020
1021    typename std::list<RenameHistory>::iterator hb_it =
1022        historyBuffer[tid].end();
1023
1024    --hb_it;
1025
1026    if (historyBuffer[tid].empty()) {
1027        DPRINTF(Rename, "[tid:%i] History buffer is empty.\n", tid);
1028        return;
1029    } else if (hb_it->instSeqNum > inst_seq_num) {
1030        DPRINTF(Rename, "[tid:%i] [sn:%llu] "
1031                "Old sequence number encountered. "
1032                "Ensure that a syscall happened recently.\n",
1033                tid,inst_seq_num);
1034        return;
1035    }
1036
1037    // Commit all the renames up until (and including) the committed sequence
1038    // number. Some or even all of the committed instructions may not have
1039    // rename histories if they did not have destination registers that were
1040    // renamed.
1041    while (!historyBuffer[tid].empty() &&
1042           hb_it != historyBuffer[tid].end() &&
1043           hb_it->instSeqNum <= inst_seq_num) {
1044
1045        DPRINTF(Rename, "[tid:%i] Freeing up older rename of reg %i (%s), "
1046                "[sn:%llu].\n",
1047                tid, hb_it->prevPhysReg->index(),
1048                hb_it->prevPhysReg->className(),
1049                hb_it->instSeqNum);
1050
1051        // Don't free special phys regs like misc and zero regs, which
1052        // can be recognized because the new mapping is the same as
1053        // the old one.
1054        if (hb_it->newPhysReg != hb_it->prevPhysReg) {
1055            freeList->addReg(hb_it->prevPhysReg);
1056        }
1057
1058        ++renameCommittedMaps;
1059
1060        historyBuffer[tid].erase(hb_it--);
1061    }
1062}
1063
1064template <class Impl>
1065inline void
1066DefaultRename<Impl>::renameSrcRegs(const DynInstPtr &inst, ThreadID tid)
1067{
1068    ThreadContext *tc = inst->tcBase();
1069    RenameMap *map = renameMap[tid];
1070    unsigned num_src_regs = inst->numSrcRegs();
1071
1072    // Get the architectual register numbers from the source and
1073    // operands, and redirect them to the right physical register.
1074    for (int src_idx = 0; src_idx < num_src_regs; src_idx++) {
1075        const RegId& src_reg = inst->srcRegIdx(src_idx);
1076        PhysRegIdPtr renamed_reg;
1077
1078        renamed_reg = map->lookup(tc->flattenRegId(src_reg));
1079        switch (src_reg.classValue()) {
1080          case IntRegClass:
1081            intRenameLookups++;
1082            break;
1083          case FloatRegClass:
1084            fpRenameLookups++;
1085            break;
1086          case VecRegClass:
1087          case VecElemClass:
1088            vecRenameLookups++;
1089            break;
1090          case VecPredRegClass:
1091            vecPredRenameLookups++;
1092            break;
1093          case CCRegClass:
1094          case MiscRegClass:
1095            break;
1096
1097          default:
1098            panic("Invalid register class: %d.", src_reg.classValue());
1099        }
1100
1101        DPRINTF(Rename,
1102                "[tid:%i] "
1103                "Looking up %s arch reg %i, got phys reg %i (%s)\n",
1104                tid, src_reg.className(),
1105                src_reg.index(), renamed_reg->index(),
1106                renamed_reg->className());
1107
1108        inst->renameSrcReg(src_idx, renamed_reg);
1109
1110        // See if the register is ready or not.
1111        if (scoreboard->getReg(renamed_reg)) {
1112            DPRINTF(Rename,
1113                    "[tid:%i] "
1114                    "Register %d (flat: %d) (%s) is ready.\n",
1115                    tid, renamed_reg->index(), renamed_reg->flatIndex(),
1116                    renamed_reg->className());
1117
1118            inst->markSrcRegReady(src_idx);
1119        } else {
1120            DPRINTF(Rename,
1121                    "[tid:%i] "
1122                    "Register %d (flat: %d) (%s) is not ready.\n",
1123                    tid, renamed_reg->index(), renamed_reg->flatIndex(),
1124                    renamed_reg->className());
1125        }
1126
1127        ++renameRenameLookups;
1128    }
1129}
1130
1131template <class Impl>
1132inline void
1133DefaultRename<Impl>::renameDestRegs(const DynInstPtr &inst, ThreadID tid)
1134{
1135    ThreadContext *tc = inst->tcBase();
1136    RenameMap *map = renameMap[tid];
1137    unsigned num_dest_regs = inst->numDestRegs();
1138
1139    // Rename the destination registers.
1140    for (int dest_idx = 0; dest_idx < num_dest_regs; dest_idx++) {
1141        const RegId& dest_reg = inst->destRegIdx(dest_idx);
1142        typename RenameMap::RenameInfo rename_result;
1143
1144        RegId flat_dest_regid = tc->flattenRegId(dest_reg);
1145        flat_dest_regid.setNumPinnedWrites(dest_reg.getNumPinnedWrites());
1146
1147        rename_result = map->rename(flat_dest_regid);
1148
1149        inst->flattenDestReg(dest_idx, flat_dest_regid);
1150
1151        scoreboard->unsetReg(rename_result.first);
1152
1153        DPRINTF(Rename,
1154                "[tid:%i] "
1155                "Renaming arch reg %i (%s) to physical reg %i (%i).\n",
1156                tid, dest_reg.index(), dest_reg.className(),
1157                rename_result.first->index(),
1158                rename_result.first->flatIndex());
1159
1160        // Record the rename information so that a history can be kept.
1161        RenameHistory hb_entry(inst->seqNum, flat_dest_regid,
1162                               rename_result.first,
1163                               rename_result.second);
1164
1165        historyBuffer[tid].push_front(hb_entry);
1166
1167        DPRINTF(Rename, "[tid:%i] [sn:%llu] "
1168                "Adding instruction to history buffer (size=%i).\n",
1169                tid,(*historyBuffer[tid].begin()).instSeqNum,
1170                historyBuffer[tid].size());
1171
1172        // Tell the instruction to rename the appropriate destination
1173        // register (dest_idx) to the new physical register
1174        // (rename_result.first), and record the previous physical
1175        // register that the same logical register was renamed to
1176        // (rename_result.second).
1177        inst->renameDestReg(dest_idx,
1178                            rename_result.first,
1179                            rename_result.second);
1180
1181        ++renameRenamedOperands;
1182    }
1183}
1184
1185template <class Impl>
1186inline int
1187DefaultRename<Impl>::calcFreeROBEntries(ThreadID tid)
1188{
1189    int num_free = freeEntries[tid].robEntries -
1190                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched);
1191
1192    //DPRINTF(Rename,"[tid:%i] %i rob free\n",tid,num_free);
1193
1194    return num_free;
1195}
1196
1197template <class Impl>
1198inline int
1199DefaultRename<Impl>::calcFreeIQEntries(ThreadID tid)
1200{
1201    int num_free = freeEntries[tid].iqEntries -
1202                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched);
1203
1204    //DPRINTF(Rename,"[tid:%i] %i iq free\n",tid,num_free);
1205
1206    return num_free;
1207}
1208
1209template <class Impl>
1210inline int
1211DefaultRename<Impl>::calcFreeLQEntries(ThreadID tid)
1212{
1213        int num_free = freeEntries[tid].lqEntries -
1214                                  (loadsInProgress[tid] - fromIEW->iewInfo[tid].dispatchedToLQ);
1215        DPRINTF(Rename,
1216                "calcFreeLQEntries: free lqEntries: %d, loadsInProgress: %d, "
1217                "loads dispatchedToLQ: %d\n",
1218                freeEntries[tid].lqEntries, loadsInProgress[tid],
1219                fromIEW->iewInfo[tid].dispatchedToLQ);
1220        return num_free;
1221}
1222
1223template <class Impl>
1224inline int
1225DefaultRename<Impl>::calcFreeSQEntries(ThreadID tid)
1226{
1227        int num_free = freeEntries[tid].sqEntries -
1228                                  (storesInProgress[tid] - fromIEW->iewInfo[tid].dispatchedToSQ);
1229        DPRINTF(Rename, "calcFreeSQEntries: free sqEntries: %d, storesInProgress: %d, "
1230                "stores dispatchedToSQ: %d\n", freeEntries[tid].sqEntries,
1231                storesInProgress[tid], fromIEW->iewInfo[tid].dispatchedToSQ);
1232        return num_free;
1233}
1234
1235template <class Impl>
1236unsigned
1237DefaultRename<Impl>::validInsts()
1238{
1239    unsigned inst_count = 0;
1240
1241    for (int i=0; i<fromDecode->size; i++) {
1242        if (!fromDecode->insts[i]->isSquashed())
1243            inst_count++;
1244    }
1245
1246    return inst_count;
1247}
1248
1249template <class Impl>
1250void
1251DefaultRename<Impl>::readStallSignals(ThreadID tid)
1252{
1253    if (fromIEW->iewBlock[tid]) {
1254        stalls[tid].iew = true;
1255    }
1256
1257    if (fromIEW->iewUnblock[tid]) {
1258        assert(stalls[tid].iew);
1259        stalls[tid].iew = false;
1260    }
1261}
1262
1263template <class Impl>
1264bool
1265DefaultRename<Impl>::checkStall(ThreadID tid)
1266{
1267    bool ret_val = false;
1268
1269    if (stalls[tid].iew) {
1270        DPRINTF(Rename,"[tid:%i] Stall from IEW stage detected.\n", tid);
1271        ret_val = true;
1272    } else if (calcFreeROBEntries(tid) <= 0) {
1273        DPRINTF(Rename,"[tid:%i] Stall: ROB has 0 free entries.\n", tid);
1274        ret_val = true;
1275    } else if (calcFreeIQEntries(tid) <= 0) {
1276        DPRINTF(Rename,"[tid:%i] Stall: IQ has 0 free entries.\n", tid);
1277        ret_val = true;
1278    } else if (calcFreeLQEntries(tid) <= 0 && calcFreeSQEntries(tid) <= 0) {
1279        DPRINTF(Rename,"[tid:%i] Stall: LSQ has 0 free entries.\n", tid);
1280        ret_val = true;
1281    } else if (renameMap[tid]->numFreeEntries() <= 0) {
1282        DPRINTF(Rename,"[tid:%i] Stall: RenameMap has 0 free entries.\n", tid);
1283        ret_val = true;
1284    } else if (renameStatus[tid] == SerializeStall &&
1285               (!emptyROB[tid] || instsInProgress[tid])) {
1286        DPRINTF(Rename,"[tid:%i] Stall: Serialize stall and ROB is not "
1287                "empty.\n",
1288                tid);
1289        ret_val = true;
1290    }
1291
1292    return ret_val;
1293}
1294
1295template <class Impl>
1296void
1297DefaultRename<Impl>::readFreeEntries(ThreadID tid)
1298{
1299    if (fromIEW->iewInfo[tid].usedIQ)
1300        freeEntries[tid].iqEntries = fromIEW->iewInfo[tid].freeIQEntries;
1301
1302    if (fromIEW->iewInfo[tid].usedLSQ) {
1303        freeEntries[tid].lqEntries = fromIEW->iewInfo[tid].freeLQEntries;
1304        freeEntries[tid].sqEntries = fromIEW->iewInfo[tid].freeSQEntries;
1305    }
1306
1307    if (fromCommit->commitInfo[tid].usedROB) {
1308        freeEntries[tid].robEntries =
1309            fromCommit->commitInfo[tid].freeROBEntries;
1310        emptyROB[tid] = fromCommit->commitInfo[tid].emptyROB;
1311    }
1312
1313    DPRINTF(Rename, "[tid:%i] Free IQ: %i, Free ROB: %i, "
1314                    "Free LQ: %i, Free SQ: %i, FreeRM %i(%i %i %i %i %i)\n",
1315            tid,
1316            freeEntries[tid].iqEntries,
1317            freeEntries[tid].robEntries,
1318            freeEntries[tid].lqEntries,
1319            freeEntries[tid].sqEntries,
1320            renameMap[tid]->numFreeEntries(),
1321            renameMap[tid]->numFreeIntEntries(),
1322            renameMap[tid]->numFreeFloatEntries(),
1323            renameMap[tid]->numFreeVecEntries(),
1324            renameMap[tid]->numFreePredEntries(),
1325            renameMap[tid]->numFreeCCEntries());
1326
1327    DPRINTF(Rename, "[tid:%i] %i instructions not yet in ROB\n",
1328            tid, instsInProgress[tid]);
1329}
1330
1331template <class Impl>
1332bool
1333DefaultRename<Impl>::checkSignalsAndUpdate(ThreadID tid)
1334{
1335    // Check if there's a squash signal, squash if there is
1336    // Check stall signals, block if necessary.
1337    // If status was blocked
1338    //     check if stall conditions have passed
1339    //         if so then go to unblocking
1340    // If status was Squashing
1341    //     check if squashing is not high.  Switch to running this cycle.
1342    // If status was serialize stall
1343    //     check if ROB is empty and no insts are in flight to the ROB
1344
1345    readFreeEntries(tid);
1346    readStallSignals(tid);
1347
1348    if (fromCommit->commitInfo[tid].squash) {
1349        DPRINTF(Rename, "[tid:%i] Squashing instructions due to squash from "
1350                "commit.\n", tid);
1351
1352        squash(fromCommit->commitInfo[tid].doneSeqNum, tid);
1353
1354        return true;
1355    }
1356
1357    if (checkStall(tid)) {
1358        return block(tid);
1359    }
1360
1361    if (renameStatus[tid] == Blocked) {
1362        DPRINTF(Rename, "[tid:%i] Done blocking, switching to unblocking.\n",
1363                tid);
1364
1365        renameStatus[tid] = Unblocking;
1366
1367        unblock(tid);
1368
1369        return true;
1370    }
1371
1372    if (renameStatus[tid] == Squashing) {
1373        // Switch status to running if rename isn't being told to block or
1374        // squash this cycle.
1375        if (resumeSerialize) {
1376            DPRINTF(Rename,
1377                    "[tid:%i] Done squashing, switching to serialize.\n", tid);
1378
1379            renameStatus[tid] = SerializeStall;
1380            return true;
1381        } else if (resumeUnblocking) {
1382            DPRINTF(Rename,
1383                    "[tid:%i] Done squashing, switching to unblocking.\n",
1384                    tid);
1385            renameStatus[tid] = Unblocking;
1386            return true;
1387        } else {
1388            DPRINTF(Rename, "[tid:%i] Done squashing, switching to running.\n",
1389                    tid);
1390            renameStatus[tid] = Running;
1391            return false;
1392        }
1393    }
1394
1395    if (renameStatus[tid] == SerializeStall) {
1396        // Stall ends once the ROB is free.
1397        DPRINTF(Rename, "[tid:%i] Done with serialize stall, switching to "
1398                "unblocking.\n", tid);
1399
1400        DynInstPtr serial_inst = serializeInst[tid];
1401
1402        renameStatus[tid] = Unblocking;
1403
1404        unblock(tid);
1405
1406        DPRINTF(Rename, "[tid:%i] Processing instruction [%lli] with "
1407                "PC %s.\n", tid, serial_inst->seqNum, serial_inst->pcState());
1408
1409        // Put instruction into queue here.
1410        serial_inst->clearSerializeBefore();
1411
1412        if (!skidBuffer[tid].empty()) {
1413            skidBuffer[tid].push_front(serial_inst);
1414        } else {
1415            insts[tid].push_front(serial_inst);
1416        }
1417
1418        DPRINTF(Rename, "[tid:%i] Instruction must be processed by rename."
1419                " Adding to front of list.\n", tid);
1420
1421        serializeInst[tid] = NULL;
1422
1423        return true;
1424    }
1425
1426    // If we've reached this point, we have not gotten any signals that
1427    // cause rename to change its status.  Rename remains the same as before.
1428    return false;
1429}
1430
1431template<class Impl>
1432void
1433DefaultRename<Impl>::serializeAfter(InstQueue &inst_list, ThreadID tid)
1434{
1435    if (inst_list.empty()) {
1436        // Mark a bit to say that I must serialize on the next instruction.
1437        serializeOnNextInst[tid] = true;
1438        return;
1439    }
1440
1441    // Set the next instruction as serializing.
1442    inst_list.front()->setSerializeBefore();
1443}
1444
1445template <class Impl>
1446inline void
1447DefaultRename<Impl>::incrFullStat(const FullSource &source)
1448{
1449    switch (source) {
1450      case ROB:
1451        ++renameROBFullEvents;
1452        break;
1453      case IQ:
1454        ++renameIQFullEvents;
1455        break;
1456      case LQ:
1457        ++renameLQFullEvents;
1458        break;
1459      case SQ:
1460        ++renameSQFullEvents;
1461        break;
1462      default:
1463        panic("Rename full stall stat should be incremented for a reason!");
1464        break;
1465    }
1466}
1467
1468template <class Impl>
1469void
1470DefaultRename<Impl>::dumpHistory()
1471{
1472    typename std::list<RenameHistory>::iterator buf_it;
1473
1474    for (ThreadID tid = 0; tid < numThreads; tid++) {
1475
1476        buf_it = historyBuffer[tid].begin();
1477
1478        while (buf_it != historyBuffer[tid].end()) {
1479            cprintf("Seq num: %i\nArch reg[%s]: %i New phys reg:"
1480                    " %i[%s] Old phys reg: %i[%s]\n",
1481                    (*buf_it).instSeqNum,
1482                    (*buf_it).archReg.className(),
1483                    (*buf_it).archReg.index(),
1484                    (*buf_it).newPhysReg->index(),
1485                    (*buf_it).newPhysReg->className(),
1486                    (*buf_it).prevPhysReg->index(),
1487                    (*buf_it).prevPhysReg->className());
1488
1489            buf_it++;
1490        }
1491    }
1492}
1493
1494#endif//__CPU_O3_RENAME_IMPL_HH__
1495