2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // Current ordering allows for 0 cycle added-to-scheduled. Could maybe fake
31 // it; either do in reverse order, or have added instructions put into a
32 // different ready queue that, in scheduleRreadyInsts(), gets put onto the
33 // normal ready queue. This would however give only a one cycle delay,
34 // but probably is more flexible to actually add in a delay parameter than
35 // just running it backwards.
39 #include "sim/universe.hh"
41 #include "cpu/beta_cpu/inst_queue.hh"
43 // Either compile error or max int due to sign extension.
44 // Hack to avoid compile warnings.
45 const InstSeqNum MaxInstSeqNum = 0 - 1;
48 InstructionQueue<Impl>::InstructionQueue(Params ¶ms)
50 numEntries(params.numIQEntries),
51 intWidth(params.executeIntWidth),
52 floatWidth(params.executeFloatWidth),
53 branchWidth(params.executeBranchWidth),
54 memoryWidth(params.executeMemoryWidth),
55 totalWidth(params.issueWidth),
56 numPhysIntRegs(params.numPhysIntRegs),
57 numPhysFloatRegs(params.numPhysFloatRegs),
58 commitToIEWDelay(params.commitToIEWDelay)
60 // Initialize the number of free IQ entries.
61 freeEntries = numEntries;
63 // Set the number of physical registers as the number of int + float
64 numPhysRegs = numPhysIntRegs + numPhysFloatRegs;
66 DPRINTF(IQ, "IQ: There are %i physical registers.\n", numPhysRegs);
68 //Create an entry for each physical register within the
70 dependGraph = new DependencyEntry[numPhysRegs];
72 // Resize the register scoreboard.
73 regScoreboard.resize(numPhysRegs);
75 // Initialize all the head pointers to point to NULL, and all the
76 // entries as unready.
77 // Note that in actuality, the registers corresponding to the logical
78 // registers start off as ready. However this doesn't matter for the
79 // IQ as the instruction should have been correctly told if those
80 // registers are ready in rename. Thus it can all be initialized as
82 for (int i = 0; i < numPhysRegs; ++i)
84 dependGraph[i].next = NULL;
85 dependGraph[i].inst = NULL;
86 regScoreboard[i] = false;
93 InstructionQueue<Impl>::regStats()
96 .name(name() + ".iqInstsAdded")
97 .desc("Number of instructions added to the IQ (excludes non-spec)")
98 .prereq(iqInstsAdded);
101 .name(name() + ".iqNonSpecInstsAdded")
102 .desc("Number of non-speculative instructions added to the IQ")
103 .prereq(iqNonSpecInstsAdded);
108 .name(name() + ".iqIntInstsIssued")
109 .desc("Number of integer instructions issued")
110 .prereq(iqIntInstsIssued);
112 // iqFloatInstsAdded;
115 .name(name() + ".iqFloatInstsIssued")
116 .desc("Number of float instructions issued")
117 .prereq(iqFloatInstsIssued);
119 // iqBranchInstsAdded;
122 .name(name() + ".iqBranchInstsIssued")
123 .desc("Number of branch instructions issued")
124 .prereq(iqBranchInstsIssued);
129 .name(name() + ".iqMemInstsIssued")
130 .desc("Number of memory instructions issued")
131 .prereq(iqMemInstsIssued);
136 .name(name() + ".iqMiscInstsIssued")
137 .desc("Number of miscellaneous instructions issued")
138 .prereq(iqMiscInstsIssued);
140 iqSquashedInstsIssued
141 .name(name() + ".iqSquashedInstsIssued")
142 .desc("Number of squashed instructions issued")
143 .prereq(iqSquashedInstsIssued);
146 .name(name() + ".iqLoopSquashStalls")
147 .desc("Number of times issue loop had to restart due to squashed "
148 "inst; mainly for profiling")
149 .prereq(iqLoopSquashStalls);
151 iqSquashedInstsExamined
152 .name(name() + ".iqSquashedInstsExamined")
153 .desc("Number of squashed instructions iterated over during squash;"
154 " mainly for profiling")
155 .prereq(iqSquashedInstsExamined);
157 iqSquashedOperandsExamined
158 .name(name() + ".iqSquashedOperandsExamined")
159 .desc("Number of squashed operands that are examined and possibly "
160 "removed from graph")
161 .prereq(iqSquashedOperandsExamined);
163 iqSquashedNonSpecRemoved
164 .name(name() + ".iqSquashedNonSpecRemoved")
165 .desc("Number of squashed non-spec instructions that were removed")
166 .prereq(iqSquashedNonSpecRemoved);
168 // Tell mem dependence unit to reg stats as well.
169 memDepUnit.regStats();
172 template <class Impl>
174 InstructionQueue<Impl>::setCPU(FullCPU *cpu_ptr)
178 tail = cpu->instList.begin();
181 template <class Impl>
183 InstructionQueue<Impl>::setIssueToExecuteQueue(
184 TimeBuffer<IssueStruct> *i2e_ptr)
186 DPRINTF(IQ, "IQ: Set the issue to execute queue.\n");
187 issueToExecuteQueue = i2e_ptr;
190 template <class Impl>
192 InstructionQueue<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
194 DPRINTF(IQ, "IQ: Set the time buffer.\n");
197 fromCommit = timeBuffer->getWire(-commitToIEWDelay);
200 template <class Impl>
202 InstructionQueue<Impl>::numFreeEntries()
207 // Might want to do something more complex if it knows how many instructions
208 // will be issued this cycle.
209 template <class Impl>
211 InstructionQueue<Impl>::isFull()
213 if (freeEntries == 0) {
220 template <class Impl>
222 InstructionQueue<Impl>::insert(DynInstPtr &new_inst)
224 // Make sure the instruction is valid
227 DPRINTF(IQ, "IQ: Adding instruction PC %#x to the IQ.\n",
230 // Check if there are any free entries. Panic if there are none.
231 // Might want to have this return a fault in the future instead of
233 assert(freeEntries != 0);
235 // If the IQ currently has nothing in it, then there's a possibility
236 // that the tail iterator is invalid (might have been pointing at an
237 // instruction that was retired). Reset the tail iterator.
238 if (freeEntries == numEntries) {
239 tail = cpu->instList.begin();
242 // Move the tail iterator. Instructions may not have been issued
243 // to the IQ, so we may have to increment the iterator more than once.
244 while ((*tail) != new_inst) {
247 // Make sure the tail iterator points at something legal.
248 assert(tail != cpu->instList.end());
252 // Decrease the number of free entries.
255 // Look through its source registers (physical regs), and mark any
257 addToDependents(new_inst);
259 // Have this instruction set itself as the producer of its destination
261 createDependency(new_inst);
263 // If it's a memory instruction, add it to the memory dependency
265 if (new_inst->isMemRef()) {
266 memDepUnit.insert(new_inst);
267 // Uh..forgot to look it up and put it on the proper dependency list
268 // if the instruction should not go yet.
270 // If the instruction is ready then add it to the ready list.
271 addIfReady(new_inst);
276 assert(freeEntries == (numEntries - countInsts()));
279 template <class Impl>
281 InstructionQueue<Impl>::insertNonSpec(DynInstPtr &inst)
283 nonSpecInsts[inst->seqNum] = inst;
285 // @todo: Clean up this code; can do it by setting inst as unable
286 // to issue, then calling normal insert on the inst.
288 // Make sure the instruction is valid
291 DPRINTF(IQ, "IQ: Adding instruction PC %#x to the IQ.\n",
294 // Check if there are any free entries. Panic if there are none.
295 // Might want to have this return a fault in the future instead of
297 assert(freeEntries != 0);
299 // If the IQ currently has nothing in it, then there's a possibility
300 // that the tail iterator is invalid (might have been pointing at an
301 // instruction that was retired). Reset the tail iterator.
302 if (freeEntries == numEntries) {
303 tail = cpu->instList.begin();
306 // Move the tail iterator. Instructions may not have been issued
307 // to the IQ, so we may have to increment the iterator more than once.
308 while ((*tail) != inst) {
311 // Make sure the tail iterator points at something legal.
312 assert(tail != cpu->instList.end());
315 // Decrease the number of free entries.
318 // Have this instruction set itself as the producer of its destination
320 createDependency(inst);
322 // If it's a memory instruction, add it to the memory dependency
324 if (inst->isMemRef()) {
325 memDepUnit.insertNonSpec(inst);
328 ++iqNonSpecInstsAdded;
331 // Slightly hack function to advance the tail iterator in the case that
332 // the IEW stage issues an instruction that is not added to the IQ. This
333 // is needed in case a long chain of such instructions occurs.
334 // I don't think this is used anymore.
335 template <class Impl>
337 InstructionQueue<Impl>::advanceTail(DynInstPtr &inst)
339 // Make sure the instruction is valid
342 DPRINTF(IQ, "IQ: Adding instruction PC %#x to the IQ.\n",
345 // Check if there are any free entries. Panic if there are none.
346 // Might want to have this return a fault in the future instead of
348 assert(freeEntries != 0);
350 // If the IQ currently has nothing in it, then there's a possibility
351 // that the tail iterator is invalid (might have been pointing at an
352 // instruction that was retired). Reset the tail iterator.
353 if (freeEntries == numEntries) {
354 tail = cpu->instList.begin();
357 // Move the tail iterator. Instructions may not have been issued
358 // to the IQ, so we may have to increment the iterator more than once.
359 while ((*tail) != inst) {
362 // Make sure the tail iterator points at something legal.
363 assert(tail != cpu->instList.end());
366 assert(freeEntries <= numEntries);
368 // Have this instruction set itself as the producer of its destination
370 createDependency(inst);
373 // Need to make sure the number of float and integer instructions
374 // issued does not exceed the total issue bandwidth.
375 // @todo: Figure out a better way to remove the squashed items from the
376 // lists. Checking the top item of each list to see if it's squashed
377 // wastes time and forces jumps.
378 template <class Impl>
380 InstructionQueue<Impl>::scheduleReadyInsts()
382 DPRINTF(IQ, "IQ: Attempting to schedule ready instructions from "
386 int float_issued = 0;
387 int branch_issued = 0;
388 int memory_issued = 0;
389 int squashed_issued = 0;
390 int total_issued = 0;
392 IssueStruct *i2e_info = issueToExecuteQueue->access(0);
394 bool insts_available = !readyBranchInsts.empty() ||
395 !readyIntInsts.empty() ||
396 !readyFloatInsts.empty() ||
397 !memDepUnit.empty() ||
398 !readyMiscInsts.empty() ||
399 !squashedInsts.empty();
401 // Note: Requires a globally defined constant.
402 InstSeqNum oldest_inst = MaxInstSeqNum;
403 InstList list_with_oldest = None;
406 DynInstPtr int_head_inst;
407 DynInstPtr float_head_inst;
408 DynInstPtr branch_head_inst;
409 DynInstPtr mem_head_inst;
410 DynInstPtr misc_head_inst;
411 DynInstPtr squashed_head_inst;
413 // Somewhat nasty code to look at all of the lists where issuable
414 // instructions are located, and choose the oldest instruction among
415 // those lists. Consider a rewrite in the future.
416 while (insts_available && total_issued < totalWidth)
418 // Set this to false. Each if-block is required to set it to true
419 // if there were instructions available this check. This will cause
420 // this loop to run once more than necessary, but avoids extra calls.
421 insts_available = false;
423 oldest_inst = MaxInstSeqNum;
425 list_with_oldest = None;
427 if (!readyIntInsts.empty() &&
428 int_issued < intWidth) {
430 insts_available = true;
432 int_head_inst = readyIntInsts.top();
434 if (int_head_inst->isSquashed()) {
437 ++iqLoopSquashStalls;
442 oldest_inst = int_head_inst->seqNum;
444 list_with_oldest = Int;
447 if (!readyFloatInsts.empty() &&
448 float_issued < floatWidth) {
450 insts_available = true;
452 float_head_inst = readyFloatInsts.top();
454 if (float_head_inst->isSquashed()) {
455 readyFloatInsts.pop();
457 ++iqLoopSquashStalls;
460 } else if (float_head_inst->seqNum < oldest_inst) {
461 oldest_inst = float_head_inst->seqNum;
463 list_with_oldest = Float;
467 if (!readyBranchInsts.empty() &&
468 branch_issued < branchWidth) {
470 insts_available = true;
472 branch_head_inst = readyBranchInsts.top();
474 if (branch_head_inst->isSquashed()) {
475 readyBranchInsts.pop();
477 ++iqLoopSquashStalls;
480 } else if (branch_head_inst->seqNum < oldest_inst) {
481 oldest_inst = branch_head_inst->seqNum;
483 list_with_oldest = Branch;
488 if (!memDepUnit.empty() &&
489 memory_issued < memoryWidth) {
491 insts_available = true;
493 mem_head_inst = memDepUnit.top();
495 if (mem_head_inst->isSquashed()) {
498 ++iqLoopSquashStalls;
501 } else if (mem_head_inst->seqNum < oldest_inst) {
502 oldest_inst = mem_head_inst->seqNum;
504 list_with_oldest = Memory;
508 if (!readyMiscInsts.empty()) {
510 insts_available = true;
512 misc_head_inst = readyMiscInsts.top();
514 if (misc_head_inst->isSquashed()) {
515 readyMiscInsts.pop();
517 ++iqLoopSquashStalls;
520 } else if (misc_head_inst->seqNum < oldest_inst) {
521 oldest_inst = misc_head_inst->seqNum;
523 list_with_oldest = Misc;
527 if (!squashedInsts.empty()) {
529 insts_available = true;
531 squashed_head_inst = squashedInsts.top();
533 if (squashed_head_inst->seqNum < oldest_inst) {
534 list_with_oldest = Squashed;
539 DynInstPtr issuing_inst = NULL;
541 switch (list_with_oldest) {
543 DPRINTF(IQ, "IQ: Not able to schedule any instructions. Issuing "
544 "inst is %#x.\n", issuing_inst);
548 issuing_inst = int_head_inst;
551 DPRINTF(IQ, "IQ: Issuing integer instruction PC %#x.\n",
552 issuing_inst->readPC());
556 issuing_inst = float_head_inst;
557 readyFloatInsts.pop();
559 DPRINTF(IQ, "IQ: Issuing float instruction PC %#x.\n",
560 issuing_inst->readPC());
564 issuing_inst = branch_head_inst;
565 readyBranchInsts.pop();
567 DPRINTF(IQ, "IQ: Issuing branch instruction PC %#x.\n",
568 issuing_inst->readPC());
572 issuing_inst = mem_head_inst;
576 DPRINTF(IQ, "IQ: Issuing memory instruction PC %#x.\n",
577 issuing_inst->readPC());
581 issuing_inst = misc_head_inst;
582 readyMiscInsts.pop();
586 DPRINTF(IQ, "IQ: Issuing a miscellaneous instruction PC %#x.\n",
587 issuing_inst->readPC());
591 assert(0 && "Squashed insts should not issue any more!");
593 // Set the squashed instruction as able to commit so that commit
594 // can just drop it from the ROB. This is a bit faked.
598 DPRINTF(IQ, "IQ: Issuing squashed instruction PC %#x.\n",
599 squashed_head_inst->readPC());
603 if (list_with_oldest != None && list_with_oldest != Squashed) {
604 i2e_info->insts[total_issued] = issuing_inst;
607 issuing_inst->setIssued();
613 assert(freeEntries == (numEntries - countInsts()));
616 iqIntInstsIssued += int_issued;
617 iqFloatInstsIssued += float_issued;
618 iqBranchInstsIssued += branch_issued;
619 iqMemInstsIssued += memory_issued;
620 iqSquashedInstsIssued += squashed_issued;
623 template <class Impl>
625 InstructionQueue<Impl>::scheduleNonSpec(const InstSeqNum &inst)
627 DPRINTF(IQ, "IQ: Marking nonspeculative instruction with sequence "
628 "number %i as ready to execute.\n", inst);
630 non_spec_it_t inst_it = nonSpecInsts.find(inst);
632 assert(inst_it != nonSpecInsts.end());
634 // Mark this instruction as ready to issue.
635 (*inst_it).second->setCanIssue();
637 // Now schedule the instruction.
638 if (!(*inst_it).second->isMemRef()) {
639 addIfReady((*inst_it).second);
641 memDepUnit.nonSpecInstReady((*inst_it).second);
644 nonSpecInsts.erase(inst_it);
647 template <class Impl>
649 InstructionQueue<Impl>::wakeDependents(DynInstPtr &completed_inst)
651 DPRINTF(IQ, "IQ: Waking dependents of completed instruction.\n");
652 //Look at the physical destination register of the DynInst
653 //and look it up on the dependency graph. Then mark as ready
654 //any instructions within the instruction queue.
655 DependencyEntry *curr;
657 // Tell the memory dependence unit to wake any dependents on this
658 // instruction if it is a memory instruction.
660 if (completed_inst->isMemRef()) {
661 memDepUnit.wakeDependents(completed_inst);
664 for (int dest_reg_idx = 0;
665 dest_reg_idx < completed_inst->numDestRegs();
668 PhysRegIndex dest_reg =
669 completed_inst->renamedDestRegIdx(dest_reg_idx);
671 // Special case of uniq or control registers. They are not
672 // handled by the IQ and thus have no dependency graph entry.
673 // @todo Figure out a cleaner way to handle this.
674 if (dest_reg >= numPhysRegs) {
678 DPRINTF(IQ, "IQ: Waking any dependents on register %i.\n",
681 //Maybe abstract this part into a function.
682 //Go through the dependency chain, marking the registers as ready
683 //within the waiting instructions.
684 while (dependGraph[dest_reg].next) {
686 curr = dependGraph[dest_reg].next;
688 DPRINTF(IQ, "IQ: Waking up a dependent instruction, PC%#x.\n",
689 curr->inst->readPC());
691 // Might want to give more information to the instruction
692 // so that it knows which of its source registers is ready.
693 // However that would mean that the dependency graph entries
694 // would need to hold the src_reg_idx.
695 curr->inst->markSrcRegReady();
697 addIfReady(curr->inst);
699 dependGraph[dest_reg].next = curr->next;
701 DependencyEntry::mem_alloc_counter--;
708 // Reset the head node now that all of its dependents have been woken
710 dependGraph[dest_reg].next = NULL;
711 dependGraph[dest_reg].inst = NULL;
713 // Mark the scoreboard as having that register ready.
714 regScoreboard[dest_reg] = true;
718 template <class Impl>
720 InstructionQueue<Impl>::violation(DynInstPtr &store,
721 DynInstPtr &faulting_load)
723 memDepUnit.violation(store, faulting_load);
726 template <class Impl>
728 InstructionQueue<Impl>::squash()
730 DPRINTF(IQ, "IQ: Starting to squash instructions in the IQ.\n");
732 // Read instruction sequence number of last instruction out of the
734 squashedSeqNum = fromCommit->commitInfo.doneSeqNum;
736 // Setup the squash iterator to point to the tail.
739 // Call doSquash if there are insts in the IQ
740 if (freeEntries != numEntries) {
744 // Also tell the memory dependence unit to squash.
745 memDepUnit.squash(squashedSeqNum);
748 template <class Impl>
750 InstructionQueue<Impl>::doSquash()
752 // Make sure the squash iterator isn't pointing to nothing.
753 assert(squashIt != cpu->instList.end());
754 // Make sure the squashed sequence number is valid.
755 assert(squashedSeqNum != 0);
757 DPRINTF(IQ, "IQ: Squashing instructions in the IQ.\n");
759 // Squash any instructions younger than the squashed sequence number
761 while ((*squashIt)->seqNum > squashedSeqNum) {
762 DynInstPtr squashed_inst = (*squashIt);
764 // Only handle the instruction if it actually is in the IQ and
765 // hasn't already been squashed in the IQ.
766 if (!squashed_inst->isIssued() &&
767 !squashed_inst->isSquashedInIQ()) {
769 // Remove the instruction from the dependency list.
770 // Hack for now: These below don't add themselves to the
771 // dependency list, so don't try to remove them.
772 if (!squashed_inst->isNonSpeculative()/* &&
773 !squashed_inst->isStore()*/
776 for (int src_reg_idx = 0;
777 src_reg_idx < squashed_inst->numSrcRegs();
780 PhysRegIndex src_reg =
781 squashed_inst->renamedSrcRegIdx(src_reg_idx);
783 // Only remove it from the dependency graph if it was
784 // placed there in the first place.
785 // HACK: This assumes that instructions woken up from the
786 // dependency chain aren't informed that a specific src
787 // register has become ready. This may not always be true
789 if (!squashed_inst->isReadySrcRegIdx(src_reg_idx) &&
790 src_reg < numPhysRegs) {
791 dependGraph[src_reg].remove(squashed_inst);
794 ++iqSquashedOperandsExamined;
797 // Might want to remove producers as well.
799 nonSpecInsts[squashed_inst->seqNum] = NULL;
801 nonSpecInsts.erase(squashed_inst->seqNum);
803 ++iqSquashedNonSpecRemoved;
806 // Might want to also clear out the head of the dependency graph.
808 // Mark it as squashed within the IQ.
809 squashed_inst->setSquashedInIQ();
811 // squashedInsts.push(squashed_inst);
812 squashed_inst->setIssued();
813 squashed_inst->setCanCommit();
817 DPRINTF(IQ, "IQ: Instruction PC %#x squashed.\n",
818 squashed_inst->readPC());
822 ++iqSquashedInstsExamined;
825 assert(freeEntries <= numEntries);
827 if (freeEntries == numEntries) {
828 tail = cpu->instList.end();
833 template <class Impl>
835 InstructionQueue<Impl>::stopSquash()
837 // Clear up the squash variables to ensure that squashing doesn't
838 // get called improperly.
841 squashIt = cpu->instList.end();
844 template <class Impl>
846 InstructionQueue<Impl>::DependencyEntry::insert(DynInstPtr &new_inst)
848 //Add this new, dependent instruction at the head of the dependency
851 // First create the entry that will be added to the head of the
853 DependencyEntry *new_entry = new DependencyEntry;
854 new_entry->next = this->next;
855 new_entry->inst = new_inst;
857 // Then actually add it to the chain.
858 this->next = new_entry;
863 template <class Impl>
865 InstructionQueue<Impl>::DependencyEntry::remove(DynInstPtr &inst_to_remove)
867 DependencyEntry *prev = this;
868 DependencyEntry *curr = this->next;
870 // Make sure curr isn't NULL. Because this instruction is being
871 // removed from a dependency list, it must have been placed there at
872 // an earlier time. The dependency chain should not be empty,
873 // unless the instruction dependent upon it is already ready.
878 // Find the instruction to remove within the dependency linked list.
879 while(curr->inst != inst_to_remove)
884 assert(curr != NULL);
887 // Now remove this instruction from the list.
888 prev->next = curr->next;
892 // Could push this off to the destructor of DependencyEntry
898 template <class Impl>
900 InstructionQueue<Impl>::addToDependents(DynInstPtr &new_inst)
902 // Loop through the instruction's source registers, adding
903 // them to the dependency list if they are not ready.
904 int8_t total_src_regs = new_inst->numSrcRegs();
905 bool return_val = false;
907 for (int src_reg_idx = 0;
908 src_reg_idx < total_src_regs;
911 // Only add it to the dependency graph if it's not ready.
912 if (!new_inst->isReadySrcRegIdx(src_reg_idx)) {
913 PhysRegIndex src_reg = new_inst->renamedSrcRegIdx(src_reg_idx);
915 // Check the IQ's scoreboard to make sure the register
916 // hasn't become ready while the instruction was in flight
917 // between stages. Only if it really isn't ready should
918 // it be added to the dependency graph.
919 if (src_reg >= numPhysRegs) {
921 } else if (regScoreboard[src_reg] == false) {
922 DPRINTF(IQ, "IQ: Instruction PC %#x has src reg %i that "
923 "is being added to the dependency chain.\n",
924 new_inst->readPC(), src_reg);
926 dependGraph[src_reg].insert(new_inst);
928 // Change the return value to indicate that something
929 // was added to the dependency graph.
932 DPRINTF(IQ, "IQ: Instruction PC %#x has src reg %i that "
933 "became ready before it reached the IQ.\n",
934 new_inst->readPC(), src_reg);
935 // Mark a register ready within the instruction.
936 new_inst->markSrcRegReady();
944 template <class Impl>
946 InstructionQueue<Impl>::createDependency(DynInstPtr &new_inst)
948 //Actually nothing really needs to be marked when an
949 //instruction becomes the producer of a register's value,
950 //but for convenience a ptr to the producing instruction will
951 //be placed in the head node of the dependency links.
952 int8_t total_dest_regs = new_inst->numDestRegs();
954 for (int dest_reg_idx = 0;
955 dest_reg_idx < total_dest_regs;
958 PhysRegIndex dest_reg = new_inst->renamedDestRegIdx(dest_reg_idx);
960 // Instructions that use the misc regs will have a reg number
961 // higher than the normal physical registers. In this case these
962 // registers are not renamed, and there is no need to track
963 // dependencies as these instructions must be executed at commit.
964 if (dest_reg >= numPhysRegs) {
968 dependGraph[dest_reg].inst = new_inst;
970 if (dependGraph[dest_reg].next) {
972 panic("IQ: Dependency graph not empty!");
975 // Mark the scoreboard to say it's not yet ready.
976 regScoreboard[dest_reg] = false;
980 template <class Impl>
982 InstructionQueue<Impl>::addIfReady(DynInstPtr &inst)
984 //If the instruction now has all of its source registers
985 // available, then add it to the list of ready instructions.
986 if (inst->readyToIssue()) {
988 //Add the instruction to the proper ready list.
989 if (inst->isControl()) {
991 DPRINTF(IQ, "IQ: Branch instruction is ready to issue, "
992 "putting it onto the ready list, PC %#x.\n",
994 readyBranchInsts.push(inst);
996 } else if (inst->isMemRef()) {
998 DPRINTF(IQ, "IQ: Checking if memory instruction can issue.\n");
1000 // Message to the mem dependence unit that this instruction has
1001 // its registers ready.
1003 memDepUnit.regsReady(inst);
1006 if (memDepUnit.readyToIssue(inst)) {
1007 DPRINTF(IQ, "IQ: Memory instruction is ready to issue, "
1008 "putting it onto the ready list, PC %#x.\n",
1010 readyMemInsts.push(inst);
1012 // Make dependent on the store.
1013 // Will need some way to get the store instruction it should
1014 // be dependent upon; then when the store issues it can
1015 // put the instruction on the ready list.
1016 // Yet another tree?
1017 assert(0 && "Instruction has no way to actually issue");
1021 } else if (inst->isInteger()) {
1023 DPRINTF(IQ, "IQ: Integer instruction is ready to issue, "
1024 "putting it onto the ready list, PC %#x.\n",
1026 readyIntInsts.push(inst);
1028 } else if (inst->isFloating()) {
1030 DPRINTF(IQ, "IQ: Floating instruction is ready to issue, "
1031 "putting it onto the ready list, PC %#x.\n",
1033 readyFloatInsts.push(inst);
1036 DPRINTF(IQ, "IQ: Miscellaneous instruction is ready to issue, "
1037 "putting it onto the ready list, PC %#x..\n",
1040 readyMiscInsts.push(inst);
1046 * Caution, this function must not be called prior to tail being updated at
1047 * least once, otherwise it will fail the assertion. This is because
1048 * instList.begin() actually changes upon the insertion of an element into the
1049 * list when the list is empty.
1051 template <class Impl>
1053 InstructionQueue<Impl>::countInsts()
1055 ListIt count_it = cpu->instList.begin();
1056 int total_insts = 0;
1058 if (tail == cpu->instList.end())
1061 while (count_it != tail) {
1062 if (!(*count_it)->isIssued()) {
1068 assert(count_it != cpu->instList.end());
1071 // Need to count the tail iterator as well.
1072 if (count_it != cpu->instList.end() &&
1074 !(*count_it)->isIssued()) {
1081 template <class Impl>
1083 InstructionQueue<Impl>::dumpDependGraph()
1085 DependencyEntry *curr;
1087 for (int i = 0; i < numPhysRegs; ++i)
1089 curr = &dependGraph[i];
1092 cprintf("dependGraph[%i]: producer: %#x consumer: ", i,
1093 curr->inst->readPC());
1095 cprintf("dependGraph[%i]: No producer. consumer: ", i);
1098 while (curr->next != NULL) {
1101 cprintf("%#x ", curr->inst->readPC());
1108 template <class Impl>
1110 InstructionQueue<Impl>::dumpLists()
1112 cprintf("Ready integer list size: %i\n", readyIntInsts.size());
1114 cprintf("Ready float list size: %i\n", readyFloatInsts.size());
1116 cprintf("Ready branch list size: %i\n", readyBranchInsts.size());
1118 cprintf("Ready misc list size: %i\n", readyMiscInsts.size());
1120 cprintf("Squashed list size: %i\n", squashedInsts.size());
1122 cprintf("Non speculative list size: %i\n", nonSpecInsts.size());
1124 non_spec_it_t non_spec_it = nonSpecInsts.begin();
1126 cprintf("Non speculative list: ");
1128 while (non_spec_it != nonSpecInsts.end()) {
1129 cprintf("%#x ", (*non_spec_it).second->readPC());