inorder: cleanup in destructors
authorKorey Sewell <ksewell@umich.edu>
Fri, 18 Feb 2011 19:29:26 +0000 (14:29 -0500)
committerKorey Sewell <ksewell@umich.edu>
Fri, 18 Feb 2011 19:29:26 +0000 (14:29 -0500)
cleanup hanging pointers and other cruft in the destructors

src/cpu/inorder/cpu.cc
src/cpu/inorder/cpu.hh
src/cpu/inorder/pipeline_stage.cc
src/cpu/inorder/pipeline_stage.hh
src/cpu/inorder/reg_dep_map.cc
src/cpu/inorder/reg_dep_map.hh
src/cpu/inorder/resource.cc

index 196682621772c96a4510d4f1a4dc3a53a6cea95a..4130b9e142667a040f7635d695705e747d4066a8 100644 (file)
@@ -356,6 +356,17 @@ InOrderCPU::InOrderCPU(Params *params)
 InOrderCPU::~InOrderCPU()
 {
     delete resPool;
+
+    std::map<SkedID, ThePipeline::RSkedPtr>::iterator sked_it =
+        skedCache.begin();
+    std::map<SkedID, ThePipeline::RSkedPtr>::iterator sked_end =
+        skedCache.end();
+
+    while (sked_it != sked_end) {
+        delete (*sked_it).second;
+        sked_it++;
+    }
+    skedCache.clear();
 }
 
 std::map<InOrderCPU::SkedID, ThePipeline::RSkedPtr> InOrderCPU::skedCache;
@@ -460,7 +471,7 @@ InOrderCPU::createBackEndSked(DynInstPtr inst)
 
     W.needs(Grad, GraduationUnit::GraduateInst);
 
-    // Insert Front Schedule into our cache of
+    // Insert Back Schedule into our cache of
     // resource schedules
     addToSkedCache(inst, res_sked);
 
index 073a0a982ef8e786a2387bf3988522e432468c79..2fa6bdc593e35adae7966cbb405e3bcf84c54488 100644 (file)
@@ -315,6 +315,7 @@ class InOrderCPU : public BaseCPU
     void addToSkedCache(DynInstPtr inst, ThePipeline::RSkedPtr inst_sked)
     {
         SkedID sked_id = genSkedID(inst);
+        assert(skedCache.find(sked_id) == skedCache.end());
         skedCache[sked_id] = inst_sked;
     }
 
index 15f143251ff6800a3c316e1548d24028a20fb447..b267ac00e4b431263b556dd47f10aef500c0920d 100644 (file)
@@ -44,12 +44,17 @@ PipelineStage::PipelineStage(Params *params, unsigned stage_num)
       stageBufferMax(params->stageWidth),
       prevStageValid(false), nextStageValid(false), idle(false)
 {
-    switchedOutBuffer.resize(ThePipeline::MaxThreads);
-    switchedOutValid.resize(ThePipeline::MaxThreads);
-    
     init(params);
 }
 
+PipelineStage::~PipelineStage()
+{
+   for(ThreadID tid = 0; tid < numThreads; tid++) {
+       skidBuffer[tid].clear();
+       stalls[tid].resources.clear();
+   }
+}
+
 void
 PipelineStage::init(Params *params)
 {
@@ -66,6 +71,12 @@ PipelineStage::init(Params *params)
         else
             lastStallingStage[tid] = NumStages - 1;
     }
+
+    if ((InOrderCPU::ThreadModel) params->threadModel ==
+        InOrderCPU::SwitchOnCacheMiss) {
+        switchedOutBuffer.resize(ThePipeline::MaxThreads);
+        switchedOutValid.resize(ThePipeline::MaxThreads);
+    }
 }
 
 
@@ -190,9 +201,6 @@ PipelineStage::takeOverFrom()
 
         stalls[tid].resources.clear();
 
-        while (!insts[tid].empty())
-            insts[tid].pop();
-
         skidBuffer[tid].clear();
     }
     wroteToTimeBuffer = false;
index dfa88de87ca842055e56e4298232e434eeefebcb..ec70fefc5daf3c0dba3169f471b704041f7b6e78 100644 (file)
@@ -91,10 +91,7 @@ class PipelineStage
   public:
     PipelineStage(Params *params, unsigned stage_num);
 
-    /** MUST use init() function if this constructor is used. */
-    PipelineStage() { }
-
-    virtual ~PipelineStage() { }
+    virtual ~PipelineStage();
 
     /** PipelineStage initialization. */
     void init(Params *params);
@@ -268,16 +265,6 @@ class PipelineStage
      */
     unsigned instsProcessed;    
 
-    /** Queue of all instructions coming from previous stage on this cycle. */
-    std::queue<DynInstPtr> insts[ThePipeline::MaxThreads];
-
-    /** Queue of instructions that are finished processing and ready to go 
-     *  next stage. This is used to prevent from processing an instrution more 
-     *  than once on any stage. NOTE: It is up to the PROGRAMMER must manage 
-     *  this as a queue
-     */
-    std::list<DynInstPtr> instsToNextStage;
-
     /** Skid buffer between previous stage and this one. */
     std::list<DynInstPtr> skidBuffer[ThePipeline::MaxThreads];
 
index 98a0727a9af2d197d63e500a27c3d7fe1ef10225..48820b50e532252526495ab1501ef07b877691cb 100644 (file)
@@ -45,6 +45,14 @@ RegDepMap::RegDepMap(int size)
     regMap.resize(size);
 }
 
+RegDepMap::~RegDepMap()
+{
+    for (int i = 0; i < regMap.size(); i++) {
+        regMap[i].clear();
+    }
+    regMap.clear();
+}
+
 string
 RegDepMap::name()
 {
index fa4fe45f37373216988ebc7f9fd8d4837c3a57ed..047e4d12918059908ac5013efdaedba8dc9a04cc 100644 (file)
@@ -48,7 +48,7 @@ class RegDepMap
   public:
     RegDepMap(int size = TheISA::TotalNumRegs);
 
-    ~RegDepMap() { }
+    ~RegDepMap();
 
     std::string name();
 
index c371f8244cc3c82843563c0c1aa836a25a6d569c..6a2f5e62a1ae5c586370ecc7dc6323bd6a69a9bc 100644 (file)
@@ -53,7 +53,11 @@ Resource::~Resource()
         delete [] resourceEvent;
     }
 
-    delete deniedReq;    
+    delete deniedReq;
+
+    for (int i = 0; i < width; i++) {
+        delete reqs[i];
+    }
 }
 
 
@@ -386,6 +390,7 @@ ResourceRequest::~ResourceRequest()
         DPRINTF(ResReqCount, "Res. Req %i deleted. resReqCount=%i.\n", reqID, 
                 res->cpu->resReqCount);
 #endif
+        inst = NULL;
 }
 
 void