mem_dep_unit_impl.hh revision 8519
11689SN/A/* 22329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 291689SN/A */ 301061SN/A 311061SN/A#include <map> 321061SN/A 332292SN/A#include "cpu/o3/inst_queue.hh" 341717SN/A#include "cpu/o3/mem_dep_unit.hh" 358232Snate@binkert.org#include "debug/MemDepUnit.hh" 365529Snate@binkert.org#include "params/DerivO3CPU.hh" 375529Snate@binkert.org 381061SN/Atemplate <class MemDepPred, class Impl> 393500Sktlim@umich.eduMemDepUnit<MemDepPred, Impl>::MemDepUnit() 403500Sktlim@umich.edu : loadBarrier(false), loadBarrierSN(0), storeBarrier(false), 413500Sktlim@umich.edu storeBarrierSN(0), iqPtr(NULL) 423500Sktlim@umich.edu{ 433500Sktlim@umich.edu} 443500Sktlim@umich.edu 453500Sktlim@umich.edutemplate <class MemDepPred, class Impl> 465529Snate@binkert.orgMemDepUnit<MemDepPred, Impl>::MemDepUnit(DerivO3CPUParams *params) 476005Snate@binkert.org : _name(params->name + ".memdepunit"), 488519SAli.Saidi@ARM.com depPred(params->store_set_clear_period, params->SSITSize, 498519SAli.Saidi@ARM.com params->LFSTSize), 508519SAli.Saidi@ARM.com loadBarrier(false), loadBarrierSN(0), storeBarrier(false), 518519SAli.Saidi@ARM.com storeBarrierSN(0), iqPtr(NULL) 521061SN/A{ 532292SN/A DPRINTF(MemDepUnit, "Creating MemDepUnit object.\n"); 542292SN/A} 552292SN/A 562292SN/Atemplate <class MemDepPred, class Impl> 572292SN/AMemDepUnit<MemDepPred, Impl>::~MemDepUnit() 582292SN/A{ 596221Snate@binkert.org for (ThreadID tid = 0; tid < Impl::MaxThreads; tid++) { 602292SN/A 612292SN/A ListIt inst_list_it = instList[tid].begin(); 622292SN/A 632292SN/A MemDepHashIt hash_it; 642292SN/A 652292SN/A while (!instList[tid].empty()) { 662292SN/A hash_it = memDepHash.find((*inst_list_it)->seqNum); 672292SN/A 682292SN/A assert(hash_it != memDepHash.end()); 692292SN/A 702292SN/A memDepHash.erase(hash_it); 712292SN/A 722292SN/A instList[tid].erase(inst_list_it++); 732292SN/A } 742292SN/A } 752292SN/A 762678Sktlim@umich.edu#ifdef DEBUG 772292SN/A assert(MemDepEntry::memdep_count == 0); 782678Sktlim@umich.edu#endif 792292SN/A} 802292SN/A 812292SN/Atemplate <class MemDepPred, class Impl> 822292SN/Avoid 836221Snate@binkert.orgMemDepUnit<MemDepPred, Impl>::init(DerivO3CPUParams *params, ThreadID tid) 842292SN/A{ 852292SN/A DPRINTF(MemDepUnit, "Creating MemDepUnit %i object.\n",tid); 862292SN/A 876005Snate@binkert.org _name = csprintf("%s.memDep%d", params->name, tid); 882292SN/A id = tid; 892292SN/A 908519SAli.Saidi@ARM.com depPred.init(params->store_set_clear_period, params->SSITSize, 918519SAli.Saidi@ARM.com params->LFSTSize); 921061SN/A} 931061SN/A 941061SN/Atemplate <class MemDepPred, class Impl> 951061SN/Avoid 961062SN/AMemDepUnit<MemDepPred, Impl>::regStats() 971062SN/A{ 981062SN/A insertedLoads 996005Snate@binkert.org .name(name() + ".insertedLoads") 1001062SN/A .desc("Number of loads inserted to the mem dependence unit."); 1011062SN/A 1021062SN/A insertedStores 1036005Snate@binkert.org .name(name() + ".insertedStores") 1041062SN/A .desc("Number of stores inserted to the mem dependence unit."); 1051062SN/A 1061062SN/A conflictingLoads 1076005Snate@binkert.org .name(name() + ".conflictingLoads") 1081062SN/A .desc("Number of conflicting loads."); 1091062SN/A 1101062SN/A conflictingStores 1116005Snate@binkert.org .name(name() + ".conflictingStores") 1121062SN/A .desc("Number of conflicting stores."); 1131062SN/A} 1141062SN/A 1151062SN/Atemplate <class MemDepPred, class Impl> 1161062SN/Avoid 1172307SN/AMemDepUnit<MemDepPred, Impl>::switchOut() 1182307SN/A{ 1192367SN/A assert(instList[0].empty()); 1202367SN/A assert(instsToReplay.empty()); 1212367SN/A assert(memDepHash.empty()); 1222348SN/A // Clear any state. 1232307SN/A for (int i = 0; i < Impl::MaxThreads; ++i) { 1242307SN/A instList[i].clear(); 1252307SN/A } 1262307SN/A instsToReplay.clear(); 1272307SN/A memDepHash.clear(); 1282307SN/A} 1292307SN/A 1302307SN/Atemplate <class MemDepPred, class Impl> 1312307SN/Avoid 1322307SN/AMemDepUnit<MemDepPred, Impl>::takeOverFrom() 1332307SN/A{ 1342348SN/A // Be sure to reset all state. 1352307SN/A loadBarrier = storeBarrier = false; 1362307SN/A loadBarrierSN = storeBarrierSN = 0; 1372307SN/A depPred.clear(); 1382307SN/A} 1392307SN/A 1402307SN/Atemplate <class MemDepPred, class Impl> 1412307SN/Avoid 1422292SN/AMemDepUnit<MemDepPred, Impl>::setIQ(InstructionQueue<Impl> *iq_ptr) 1432292SN/A{ 1442292SN/A iqPtr = iq_ptr; 1452292SN/A} 1462292SN/A 1472292SN/Atemplate <class MemDepPred, class Impl> 1482292SN/Avoid 1491061SN/AMemDepUnit<MemDepPred, Impl>::insert(DynInstPtr &inst) 1501061SN/A{ 1516221Snate@binkert.org ThreadID tid = inst->threadNumber; 1521061SN/A 1532292SN/A MemDepEntryPtr inst_entry = new MemDepEntry(inst); 1541061SN/A 1552292SN/A // Add the MemDepEntry to the hash. 1562292SN/A memDepHash.insert( 1572292SN/A std::pair<InstSeqNum, MemDepEntryPtr>(inst->seqNum, inst_entry)); 1582678Sktlim@umich.edu#ifdef DEBUG 1592292SN/A MemDepEntry::memdep_insert++; 1602678Sktlim@umich.edu#endif 1611061SN/A 1622292SN/A instList[tid].push_back(inst); 1631062SN/A 1642292SN/A inst_entry->listIt = --(instList[tid].end()); 1651062SN/A 1662329SN/A // Check any barriers and the dependence predictor for any 1672348SN/A // producing memrefs/stores. 1682292SN/A InstSeqNum producing_store; 1692292SN/A if (inst->isLoad() && loadBarrier) { 1703500Sktlim@umich.edu DPRINTF(MemDepUnit, "Load barrier [sn:%lli] in flight\n", 1713500Sktlim@umich.edu loadBarrierSN); 1722292SN/A producing_store = loadBarrierSN; 1732292SN/A } else if (inst->isStore() && storeBarrier) { 1743500Sktlim@umich.edu DPRINTF(MemDepUnit, "Store barrier [sn:%lli] in flight\n", 1753500Sktlim@umich.edu storeBarrierSN); 1762292SN/A producing_store = storeBarrierSN; 1772292SN/A } else { 1787720Sgblack@eecs.umich.edu producing_store = depPred.checkInst(inst->instAddr()); 1792292SN/A } 1802292SN/A 1812292SN/A MemDepEntryPtr store_entry = NULL; 1822292SN/A 1832292SN/A // If there is a producing store, try to find the entry. 1842292SN/A if (producing_store != 0) { 1853500Sktlim@umich.edu DPRINTF(MemDepUnit, "Searching for producer\n"); 1862292SN/A MemDepHashIt hash_it = memDepHash.find(producing_store); 1872292SN/A 1882292SN/A if (hash_it != memDepHash.end()) { 1892292SN/A store_entry = (*hash_it).second; 1903500Sktlim@umich.edu DPRINTF(MemDepUnit, "Proucer found\n"); 1912292SN/A } 1922292SN/A } 1932292SN/A 1942292SN/A // If no store entry, then instruction can issue as soon as the registers 1952292SN/A // are ready. 1962292SN/A if (!store_entry) { 1972292SN/A DPRINTF(MemDepUnit, "No dependency for inst PC " 1987720Sgblack@eecs.umich.edu "%s [sn:%lli].\n", inst->pcState(), inst->seqNum); 1992292SN/A 2002292SN/A inst_entry->memDepReady = true; 2011062SN/A 2021062SN/A if (inst->readyToIssue()) { 2032292SN/A inst_entry->regsReady = true; 2041062SN/A 2052292SN/A moveToReady(inst_entry); 2061062SN/A } 2071061SN/A } else { 2082329SN/A // Otherwise make the instruction dependent on the store/barrier. 2092292SN/A DPRINTF(MemDepUnit, "Adding to dependency list; " 2107720Sgblack@eecs.umich.edu "inst PC %s is dependent on [sn:%lli].\n", 2117720Sgblack@eecs.umich.edu inst->pcState(), producing_store); 2121062SN/A 2131062SN/A if (inst->readyToIssue()) { 2142292SN/A inst_entry->regsReady = true; 2151062SN/A } 2161062SN/A 2174033Sktlim@umich.edu // Clear the bit saying this instruction can issue. 2184033Sktlim@umich.edu inst->clearCanIssue(); 2194033Sktlim@umich.edu 2201062SN/A // Add this instruction to the list of dependents. 2212292SN/A store_entry->dependInsts.push_back(inst_entry); 2221062SN/A 2231062SN/A if (inst->isLoad()) { 2241062SN/A ++conflictingLoads; 2251062SN/A } else { 2261062SN/A ++conflictingStores; 2271062SN/A } 2281061SN/A } 2291061SN/A 2301061SN/A if (inst->isStore()) { 2317720Sgblack@eecs.umich.edu DPRINTF(MemDepUnit, "Inserting store PC %s [sn:%lli].\n", 2327720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum); 2331062SN/A 2347720Sgblack@eecs.umich.edu depPred.insertStore(inst->instAddr(), inst->seqNum, inst->threadNumber); 2351062SN/A 2361062SN/A ++insertedStores; 2371062SN/A } else if (inst->isLoad()) { 2381062SN/A ++insertedLoads; 2391062SN/A } else { 2402292SN/A panic("Unknown type! (most likely a barrier)."); 2411061SN/A } 2421062SN/A} 2431062SN/A 2441062SN/Atemplate <class MemDepPred, class Impl> 2451062SN/Avoid 2461062SN/AMemDepUnit<MemDepPred, Impl>::insertNonSpec(DynInstPtr &inst) 2471062SN/A{ 2486221Snate@binkert.org ThreadID tid = inst->threadNumber; 2491062SN/A 2502292SN/A MemDepEntryPtr inst_entry = new MemDepEntry(inst); 2511062SN/A 2522292SN/A // Insert the MemDepEntry into the hash. 2532292SN/A memDepHash.insert( 2542292SN/A std::pair<InstSeqNum, MemDepEntryPtr>(inst->seqNum, inst_entry)); 2552678Sktlim@umich.edu#ifdef DEBUG 2562292SN/A MemDepEntry::memdep_insert++; 2572678Sktlim@umich.edu#endif 2581062SN/A 2592292SN/A // Add the instruction to the list. 2602292SN/A instList[tid].push_back(inst); 2612292SN/A 2622292SN/A inst_entry->listIt = --(instList[tid].end()); 2631062SN/A 2641062SN/A // Might want to turn this part into an inline function or something. 2651062SN/A // It's shared between both insert functions. 2661062SN/A if (inst->isStore()) { 2677720Sgblack@eecs.umich.edu DPRINTF(MemDepUnit, "Inserting store PC %s [sn:%lli].\n", 2687720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum); 2691062SN/A 2707720Sgblack@eecs.umich.edu depPred.insertStore(inst->instAddr(), inst->seqNum, inst->threadNumber); 2711062SN/A 2721062SN/A ++insertedStores; 2731062SN/A } else if (inst->isLoad()) { 2741062SN/A ++insertedLoads; 2751062SN/A } else { 2762292SN/A panic("Unknown type! (most likely a barrier)."); 2771062SN/A } 2781062SN/A} 2791062SN/A 2801062SN/Atemplate <class MemDepPred, class Impl> 2811062SN/Avoid 2822292SN/AMemDepUnit<MemDepPred, Impl>::insertBarrier(DynInstPtr &barr_inst) 2831062SN/A{ 2842292SN/A InstSeqNum barr_sn = barr_inst->seqNum; 2852348SN/A // Memory barriers block loads and stores, write barriers only stores. 2862292SN/A if (barr_inst->isMemBarrier()) { 2872292SN/A loadBarrier = true; 2882292SN/A loadBarrierSN = barr_sn; 2892292SN/A storeBarrier = true; 2902292SN/A storeBarrierSN = barr_sn; 2918516SMrinmoy.Ghosh@arm.com DPRINTF(MemDepUnit, "Inserted a memory barrier %s SN:%lli\n", 2928516SMrinmoy.Ghosh@arm.com barr_inst->pcState(),barr_sn); 2932292SN/A } else if (barr_inst->isWriteBarrier()) { 2942292SN/A storeBarrier = true; 2952292SN/A storeBarrierSN = barr_sn; 2962292SN/A DPRINTF(MemDepUnit, "Inserted a write barrier\n"); 2972292SN/A } 2981062SN/A 2996221Snate@binkert.org ThreadID tid = barr_inst->threadNumber; 3001062SN/A 3012292SN/A MemDepEntryPtr inst_entry = new MemDepEntry(barr_inst); 3021062SN/A 3032292SN/A // Add the MemDepEntry to the hash. 3042292SN/A memDepHash.insert( 3052292SN/A std::pair<InstSeqNum, MemDepEntryPtr>(barr_sn, inst_entry)); 3062678Sktlim@umich.edu#ifdef DEBUG 3072292SN/A MemDepEntry::memdep_insert++; 3082678Sktlim@umich.edu#endif 3091062SN/A 3102292SN/A // Add the instruction to the instruction list. 3112292SN/A instList[tid].push_back(barr_inst); 3122292SN/A 3132292SN/A inst_entry->listIt = --(instList[tid].end()); 3141062SN/A} 3151062SN/A 3161062SN/Atemplate <class MemDepPred, class Impl> 3171062SN/Avoid 3181062SN/AMemDepUnit<MemDepPred, Impl>::regsReady(DynInstPtr &inst) 3191062SN/A{ 3202292SN/A DPRINTF(MemDepUnit, "Marking registers as ready for " 3217720Sgblack@eecs.umich.edu "instruction PC %s [sn:%lli].\n", 3227720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum); 3231062SN/A 3242292SN/A MemDepEntryPtr inst_entry = findInHash(inst); 3251062SN/A 3262292SN/A inst_entry->regsReady = true; 3271062SN/A 3282292SN/A if (inst_entry->memDepReady) { 3292292SN/A DPRINTF(MemDepUnit, "Instruction has its memory " 3301062SN/A "dependencies resolved, adding it to the ready list.\n"); 3311062SN/A 3322292SN/A moveToReady(inst_entry); 3331062SN/A } else { 3342292SN/A DPRINTF(MemDepUnit, "Instruction still waiting on " 3351062SN/A "memory dependency.\n"); 3361062SN/A } 3371061SN/A} 3381061SN/A 3391061SN/Atemplate <class MemDepPred, class Impl> 3401062SN/Avoid 3411062SN/AMemDepUnit<MemDepPred, Impl>::nonSpecInstReady(DynInstPtr &inst) 3421061SN/A{ 3432292SN/A DPRINTF(MemDepUnit, "Marking non speculative " 3447720Sgblack@eecs.umich.edu "instruction PC %s as ready [sn:%lli].\n", 3457720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum); 3461062SN/A 3472292SN/A MemDepEntryPtr inst_entry = findInHash(inst); 3481061SN/A 3492292SN/A moveToReady(inst_entry); 3501061SN/A} 3511061SN/A 3521061SN/Atemplate <class MemDepPred, class Impl> 3531061SN/Avoid 3542292SN/AMemDepUnit<MemDepPred, Impl>::reschedule(DynInstPtr &inst) 3551061SN/A{ 3562292SN/A instsToReplay.push_back(inst); 3572292SN/A} 3581061SN/A 3592292SN/Atemplate <class MemDepPred, class Impl> 3602292SN/Avoid 3612292SN/AMemDepUnit<MemDepPred, Impl>::replay(DynInstPtr &inst) 3622292SN/A{ 3632292SN/A DynInstPtr temp_inst; 3641062SN/A 3652348SN/A // For now this replay function replays all waiting memory ops. 3662292SN/A while (!instsToReplay.empty()) { 3672292SN/A temp_inst = instsToReplay.front(); 3681062SN/A 3692292SN/A MemDepEntryPtr inst_entry = findInHash(temp_inst); 3702292SN/A 3717720Sgblack@eecs.umich.edu DPRINTF(MemDepUnit, "Replaying mem instruction PC %s [sn:%lli].\n", 3727720Sgblack@eecs.umich.edu temp_inst->pcState(), temp_inst->seqNum); 3732292SN/A 3742292SN/A moveToReady(inst_entry); 3752292SN/A 3762292SN/A instsToReplay.pop_front(); 3772292SN/A } 3782292SN/A} 3792292SN/A 3802292SN/Atemplate <class MemDepPred, class Impl> 3812292SN/Avoid 3822292SN/AMemDepUnit<MemDepPred, Impl>::completed(DynInstPtr &inst) 3832292SN/A{ 3847720Sgblack@eecs.umich.edu DPRINTF(MemDepUnit, "Completed mem instruction PC %s [sn:%lli].\n", 3857720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum); 3862292SN/A 3876221Snate@binkert.org ThreadID tid = inst->threadNumber; 3882292SN/A 3892292SN/A // Remove the instruction from the hash and the list. 3902292SN/A MemDepHashIt hash_it = memDepHash.find(inst->seqNum); 3912292SN/A 3922292SN/A assert(hash_it != memDepHash.end()); 3932292SN/A 3942292SN/A instList[tid].erase((*hash_it).second->listIt); 3952292SN/A 3962292SN/A (*hash_it).second = NULL; 3972292SN/A 3982292SN/A memDepHash.erase(hash_it); 3992678Sktlim@umich.edu#ifdef DEBUG 4002292SN/A MemDepEntry::memdep_erase++; 4012678Sktlim@umich.edu#endif 4022292SN/A} 4032292SN/A 4042292SN/Atemplate <class MemDepPred, class Impl> 4052292SN/Avoid 4062292SN/AMemDepUnit<MemDepPred, Impl>::completeBarrier(DynInstPtr &inst) 4072292SN/A{ 4082292SN/A wakeDependents(inst); 4092292SN/A completed(inst); 4102292SN/A 4112292SN/A InstSeqNum barr_sn = inst->seqNum; 4128515SMrinmoy.Ghosh@arm.com DPRINTF(MemDepUnit, "barrier completed: %s SN:%lli\n", inst->pcState(), 4138515SMrinmoy.Ghosh@arm.com inst->seqNum); 4142292SN/A if (inst->isMemBarrier()) { 4152292SN/A if (loadBarrierSN == barr_sn) 4162292SN/A loadBarrier = false; 4172292SN/A if (storeBarrierSN == barr_sn) 4182292SN/A storeBarrier = false; 4192292SN/A } else if (inst->isWriteBarrier()) { 4202292SN/A if (storeBarrierSN == barr_sn) 4212292SN/A storeBarrier = false; 4222292SN/A } 4231061SN/A} 4241061SN/A 4251061SN/Atemplate <class MemDepPred, class Impl> 4261061SN/Avoid 4271061SN/AMemDepUnit<MemDepPred, Impl>::wakeDependents(DynInstPtr &inst) 4281061SN/A{ 4292292SN/A // Only stores and barriers have dependents. 4302292SN/A if (!inst->isStore() && !inst->isMemBarrier() && !inst->isWriteBarrier()) { 4311062SN/A return; 4321062SN/A } 4331062SN/A 4342292SN/A MemDepEntryPtr inst_entry = findInHash(inst); 4351061SN/A 4362292SN/A for (int i = 0; i < inst_entry->dependInsts.size(); ++i ) { 4372292SN/A MemDepEntryPtr woken_inst = inst_entry->dependInsts[i]; 4381062SN/A 4392292SN/A if (!woken_inst->inst) { 4402292SN/A // Potentially removed mem dep entries could be on this list 4412292SN/A continue; 4422292SN/A } 4431061SN/A 4442292SN/A DPRINTF(MemDepUnit, "Waking up a dependent inst, " 4452292SN/A "[sn:%lli].\n", 4462292SN/A woken_inst->inst->seqNum); 4471061SN/A 4482292SN/A if (woken_inst->regsReady && !woken_inst->squashed) { 4491062SN/A moveToReady(woken_inst); 4501062SN/A } else { 4512292SN/A woken_inst->memDepReady = true; 4521062SN/A } 4531061SN/A } 4541061SN/A 4552292SN/A inst_entry->dependInsts.clear(); 4561061SN/A} 4571061SN/A 4581061SN/Atemplate <class MemDepPred, class Impl> 4591061SN/Avoid 4602292SN/AMemDepUnit<MemDepPred, Impl>::squash(const InstSeqNum &squashed_num, 4616221Snate@binkert.org ThreadID tid) 4621061SN/A{ 4632292SN/A if (!instsToReplay.empty()) { 4642292SN/A ListIt replay_it = instsToReplay.begin(); 4652292SN/A while (replay_it != instsToReplay.end()) { 4662292SN/A if ((*replay_it)->threadNumber == tid && 4672292SN/A (*replay_it)->seqNum > squashed_num) { 4682292SN/A instsToReplay.erase(replay_it++); 4692292SN/A } else { 4702292SN/A ++replay_it; 4711062SN/A } 4721061SN/A } 4731061SN/A } 4741061SN/A 4752292SN/A ListIt squash_it = instList[tid].end(); 4762292SN/A --squash_it; 4771061SN/A 4782292SN/A MemDepHashIt hash_it; 4791061SN/A 4802292SN/A while (!instList[tid].empty() && 4812292SN/A (*squash_it)->seqNum > squashed_num) { 4821061SN/A 4832292SN/A DPRINTF(MemDepUnit, "Squashing inst [sn:%lli]\n", 4842292SN/A (*squash_it)->seqNum); 4851061SN/A 4868515SMrinmoy.Ghosh@arm.com if ((*squash_it)->seqNum == loadBarrierSN) 4878515SMrinmoy.Ghosh@arm.com loadBarrier = false; 4888515SMrinmoy.Ghosh@arm.com 4898515SMrinmoy.Ghosh@arm.com if ((*squash_it)->seqNum == storeBarrierSN) 4908515SMrinmoy.Ghosh@arm.com storeBarrier = false; 4918515SMrinmoy.Ghosh@arm.com 4922292SN/A hash_it = memDepHash.find((*squash_it)->seqNum); 4931061SN/A 4942292SN/A assert(hash_it != memDepHash.end()); 4951062SN/A 4962292SN/A (*hash_it).second->squashed = true; 4971717SN/A 4982292SN/A (*hash_it).second = NULL; 4991717SN/A 5002292SN/A memDepHash.erase(hash_it); 5012678Sktlim@umich.edu#ifdef DEBUG 5022292SN/A MemDepEntry::memdep_erase++; 5032678Sktlim@umich.edu#endif 5041717SN/A 5052292SN/A instList[tid].erase(squash_it--); 5061061SN/A } 5071061SN/A 5081061SN/A // Tell the dependency predictor to squash as well. 5092292SN/A depPred.squash(squashed_num, tid); 5101061SN/A} 5111061SN/A 5121061SN/Atemplate <class MemDepPred, class Impl> 5131061SN/Avoid 5141061SN/AMemDepUnit<MemDepPred, Impl>::violation(DynInstPtr &store_inst, 5151061SN/A DynInstPtr &violating_load) 5161061SN/A{ 5172292SN/A DPRINTF(MemDepUnit, "Passing violating PCs to store sets," 5187720Sgblack@eecs.umich.edu " load: %#x, store: %#x\n", violating_load->instAddr(), 5197720Sgblack@eecs.umich.edu store_inst->instAddr()); 5201061SN/A // Tell the memory dependence unit of the violation. 5218515SMrinmoy.Ghosh@arm.com depPred.violation(store_inst->instAddr(), violating_load->instAddr()); 5221061SN/A} 5231062SN/A 5241062SN/Atemplate <class MemDepPred, class Impl> 5252292SN/Avoid 5262292SN/AMemDepUnit<MemDepPred, Impl>::issue(DynInstPtr &inst) 5272292SN/A{ 5282292SN/A DPRINTF(MemDepUnit, "Issuing instruction PC %#x [sn:%lli].\n", 5297720Sgblack@eecs.umich.edu inst->instAddr(), inst->seqNum); 5302292SN/A 5317720Sgblack@eecs.umich.edu depPred.issued(inst->instAddr(), inst->seqNum, inst->isStore()); 5322292SN/A} 5332292SN/A 5342292SN/Atemplate <class MemDepPred, class Impl> 5352292SN/Ainline typename MemDepUnit<MemDepPred,Impl>::MemDepEntryPtr & 5362292SN/AMemDepUnit<MemDepPred, Impl>::findInHash(const DynInstPtr &inst) 5372292SN/A{ 5382292SN/A MemDepHashIt hash_it = memDepHash.find(inst->seqNum); 5392292SN/A 5402292SN/A assert(hash_it != memDepHash.end()); 5412292SN/A 5422292SN/A return (*hash_it).second; 5432292SN/A} 5442292SN/A 5452292SN/Atemplate <class MemDepPred, class Impl> 5461062SN/Ainline void 5472292SN/AMemDepUnit<MemDepPred, Impl>::moveToReady(MemDepEntryPtr &woken_inst_entry) 5481062SN/A{ 5492292SN/A DPRINTF(MemDepUnit, "Adding instruction [sn:%lli] " 5502292SN/A "to the ready list.\n", woken_inst_entry->inst->seqNum); 5511062SN/A 5522292SN/A assert(!woken_inst_entry->squashed); 5531062SN/A 5542292SN/A iqPtr->addReadyMemInst(woken_inst_entry->inst); 5551062SN/A} 5562292SN/A 5572292SN/A 5582292SN/Atemplate <class MemDepPred, class Impl> 5592292SN/Avoid 5602292SN/AMemDepUnit<MemDepPred, Impl>::dumpLists() 5612292SN/A{ 5626221Snate@binkert.org for (ThreadID tid = 0; tid < Impl::MaxThreads; tid++) { 5632292SN/A cprintf("Instruction list %i size: %i\n", 5642292SN/A tid, instList[tid].size()); 5652292SN/A 5662292SN/A ListIt inst_list_it = instList[tid].begin(); 5672292SN/A int num = 0; 5682292SN/A 5692292SN/A while (inst_list_it != instList[tid].end()) { 5707720Sgblack@eecs.umich.edu cprintf("Instruction:%i\nPC: %s\n[sn:%i]\n[tid:%i]\nIssued:%i\n" 5712292SN/A "Squashed:%i\n\n", 5727720Sgblack@eecs.umich.edu num, (*inst_list_it)->pcState(), 5732292SN/A (*inst_list_it)->seqNum, 5742292SN/A (*inst_list_it)->threadNumber, 5752292SN/A (*inst_list_it)->isIssued(), 5762292SN/A (*inst_list_it)->isSquashed()); 5772292SN/A inst_list_it++; 5782292SN/A ++num; 5792292SN/A } 5802292SN/A } 5812292SN/A 5822292SN/A cprintf("Memory dependence hash size: %i\n", memDepHash.size()); 5832292SN/A 5842678Sktlim@umich.edu#ifdef DEBUG 5852292SN/A cprintf("Memory dependence entries: %i\n", MemDepEntry::memdep_count); 5862678Sktlim@umich.edu#endif 5872292SN/A} 588