Reapply 53476 and 53480, with a fix so that it properly updates
authorDan Gohman <gohman@apple.com>
Mon, 14 Jul 2008 18:19:29 +0000 (18:19 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 14 Jul 2008 18:19:29 +0000 (18:19 +0000)
the BB member to the current basic block after emitting
instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53567 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/ScheduleDAG.h
include/llvm/CodeGen/SelectionDAGISel.h
include/llvm/Support/Timer.h
lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp
lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/Support/Timer.cpp

index ed7801fbfc409b82dfe2528fef00eb9d80ad52e0..0225b1231e6835ea2fadd4d1f2557622a4de1d17 100644 (file)
@@ -265,7 +265,7 @@ namespace llvm {
   
     /// Run - perform scheduling.
     ///
-    MachineBasicBlock *Run();
+    void Run();
 
     /// isPassiveNode - Return true if the node is a non-scheduled leaf.
     ///
@@ -336,7 +336,7 @@ namespace llvm {
     ///
     void EmitNoop();
 
-    void EmitSchedule();
+    MachineBasicBlock *EmitSchedule();
 
     void dumpSchedule() const;
 
index e0b26b926bbb39773d9d4b44915ae5eed0c417ad..72a836f55b797373e4380ef975823caae72fa56b 100644 (file)
@@ -30,6 +30,7 @@ namespace llvm {
   class FunctionLoweringInfo;
   class HazardRecognizer;
   class CollectorMetadata;
+  class ScheduleDAG;
  
 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
 /// pattern-matching instruction selectors.
@@ -191,9 +192,9 @@ private:
   
   void ComputeLiveOutVRegInfo(SelectionDAG &DAG);
 
-  /// Pick a safe ordering and emit instructions for each target node in the
+  /// Pick a safe ordering for instructions for each target node in the
   /// graph.
-  void ScheduleAndEmitDAG(SelectionDAG &DAG);
+  ScheduleDAG *Schedule(SelectionDAG &DAG);
 
   /// SwitchCases - Vector of CaseBlock structures used to communicate
   /// SwitchInst code generation information.
index 4164ddc891a7ac34a75b495d4db2e4905a9e52be..b9882a970820789b56818afb08859608af6e2192 100644 (file)
@@ -132,6 +132,8 @@ public:
 ///
 struct NamedRegionTimer : public TimeRegion {
   explicit NamedRegionTimer(const std::string &Name);
+  explicit NamedRegionTimer(const std::string &Name,
+                            const std::string &GroupName);
 };
 
 
index 02f20f919e6cfacd3bcef01b82267973a944472f..982bbab3cb280090ca92be12433c01834b89246c 100644 (file)
@@ -1082,7 +1082,7 @@ void ScheduleDAG::EmitLiveInCopies(MachineBasicBlock *MBB) {
 }
 
 /// EmitSchedule - Emit the machine code in scheduled order.
-void ScheduleDAG::EmitSchedule() {
+MachineBasicBlock *ScheduleDAG::EmitSchedule() {
   bool isEntryBB = &MF->front() == BB;
 
   if (isEntryBB && !SchedLiveInCopies) {
@@ -1118,6 +1118,8 @@ void ScheduleDAG::EmitSchedule() {
 
   if (isEntryBB && SchedLiveInCopies)
     EmitLiveInCopies(MF->begin());
+
+  return BB;
 }
 
 /// dump - dump the schedule.
@@ -1133,9 +1135,12 @@ void ScheduleDAG::dumpSchedule() const {
 
 /// Run - perform scheduling.
 ///
-MachineBasicBlock *ScheduleDAG::Run() {
+void ScheduleDAG::Run() {
   Schedule();
-  return BB;
+  
+  DOUT << "*** Final schedule ***\n";
+  DEBUG(dumpSchedule());
+  DOUT << "\n";
 }
 
 /// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
index 8a1dade30b3ba0f1f57ece6dcb6b94681bce297b..39aadd5279c65bd2183e4919fd0f21dd741c2349 100644 (file)
@@ -99,13 +99,6 @@ void ScheduleDAGList::Schedule() {
   ListScheduleTopDown();
   
   AvailableQueue->releaseState();
-  
-  DOUT << "*** Final schedule ***\n";
-  DEBUG(dumpSchedule());
-  DOUT << "\n";
-  
-  // Emit in scheduled order
-  EmitSchedule();
 }
 
 //===----------------------------------------------------------------------===//
index 287e8c5b0e5fe659625b6e8e2432d43dc7800d25..098b7996d4c8003be75d10fb2fc794f3f75f0801 100644 (file)
@@ -204,13 +204,6 @@ void ScheduleDAGRRList::Schedule() {
 
   if (!Fast)
     CommuteNodesToReducePressure();
-  
-  DOUT << "*** Final schedule ***\n";
-  DEBUG(dumpSchedule());
-  DOUT << "\n";
-  
-  // Emit in scheduled order
-  EmitSchedule();
 }
 
 /// CommuteNodesToReducePressure - If a node is two-address and commutable, and
index b4b81cd4f1368a11e70d27c9a55a337b1a684b95..bf68040c97aebf62e3831692f2d4016728e40d84 100644 (file)
@@ -5284,10 +5284,11 @@ void SelectionDAGISel::ComputeLiveOutVRegInfo(SelectionDAG &DAG) {
 void SelectionDAGISel::CodeGenAndEmitDAG(SelectionDAG &DAG) {
   DOUT << "Lowered selection DAG:\n";
   DEBUG(DAG.dump());
+  std::string GroupName = "Instruction Selection and Scheduling";
 
   // Run the DAG combiner in pre-legalize mode.
   if (TimePassesIsEnabled) {
-    NamedRegionTimer T("DAG Combining 1");
+    NamedRegionTimer T("DAG Combining 1", GroupName);
     DAG.Combine(false, *AA);
   } else {
     DAG.Combine(false, *AA);
@@ -5304,7 +5305,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG(SelectionDAG &DAG) {
   }
   
   if (TimePassesIsEnabled) {
-    NamedRegionTimer T("DAG Legalization");
+    NamedRegionTimer T("DAG Legalization", GroupName);
     DAG.Legalize();
   } else {
     DAG.Legalize();
@@ -5315,7 +5316,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG(SelectionDAG &DAG) {
   
   // Run the DAG combiner in post-legalize mode.
   if (TimePassesIsEnabled) {
-    NamedRegionTimer T("DAG Combining 2");
+    NamedRegionTimer T("DAG Combining 2", GroupName);
     DAG.Combine(true, *AA);
   } else {
     DAG.Combine(true, *AA);
@@ -5332,24 +5333,41 @@ void SelectionDAGISel::CodeGenAndEmitDAG(SelectionDAG &DAG) {
   // Third, instruction select all of the operations to machine code, adding the
   // code to the MachineBasicBlock.
   if (TimePassesIsEnabled) {
-    NamedRegionTimer T("Instruction Selection");
+    NamedRegionTimer T("Instruction Selection", GroupName);
     InstructionSelect(DAG);
   } else {
     InstructionSelect(DAG);
   }
 
+  // Schedule machine code.
+  ScheduleDAG *Scheduler;
+  if (TimePassesIsEnabled) {
+    NamedRegionTimer T("Instruction Scheduling", GroupName);
+    Scheduler = Schedule(DAG);
+  } else {
+    Scheduler = Schedule(DAG);
+  }
+
   // Emit machine code to BB.  This can change 'BB' to the last block being 
   // inserted into.
   if (TimePassesIsEnabled) {
-    NamedRegionTimer T("Instruction Scheduling");
-    ScheduleAndEmitDAG(DAG);
+    NamedRegionTimer T("Instruction Creation", GroupName);
+    BB = Scheduler->EmitSchedule();
   } else {
-    ScheduleAndEmitDAG(DAG);
+    BB = Scheduler->EmitSchedule();
+  }
+
+  // Free the scheduler state.
+  if (TimePassesIsEnabled) {
+    NamedRegionTimer T("Instruction Scheduling Cleanup", GroupName);
+    delete Scheduler;
+  } else {
+    delete Scheduler;
   }
 
   // Perform target specific isel post processing.
   if (TimePassesIsEnabled) {
-    NamedRegionTimer T("Instruction Selection Post Processing");
+    NamedRegionTimer T("Instruction Selection Post Processing", GroupName);
     InstructionSelectPostProcessing(DAG);
   } else {
     InstructionSelectPostProcessing(DAG);
@@ -5597,10 +5615,10 @@ void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB, MachineFunction &MF,
 }
 
 
-//===----------------------------------------------------------------------===//
-/// ScheduleAndEmitDAG - Pick a safe ordering and emit instructions for each
+/// Schedule - Pick a safe ordering for instructions for each
 /// target node in the graph.
-void SelectionDAGISel::ScheduleAndEmitDAG(SelectionDAG &DAG) {
+///
+ScheduleDAG *SelectionDAGISel::Schedule(SelectionDAG &DAG) {
   if (ViewSchedDAGs) DAG.viewGraph();
 
   RegisterScheduler::FunctionPassCtor Ctor = RegisterScheduler::getDefault();
@@ -5610,12 +5628,11 @@ void SelectionDAGISel::ScheduleAndEmitDAG(SelectionDAG &DAG) {
     RegisterScheduler::setDefault(Ctor);
   }
   
-  ScheduleDAG *SL = Ctor(this, &DAG, BB, FastISel);
-  BB = SL->Run();
-
-  if (ViewSUnitDAGs) SL->viewGraph();
+  ScheduleDAG *Scheduler = Ctor(this, &DAG, BB, FastISel);
+  Scheduler->Run();
 
-  delete SL;
+  if (ViewSUnitDAGs) Scheduler->viewGraph();
+  return Scheduler;
 }
 
 
index 29fd00c0a3382c21a39f7753be7ca537f1482f4f..3c8879bd06e35da6aad9377c189034c4d7ee79d3 100644 (file)
@@ -182,19 +182,51 @@ void Timer::addPeakMemoryMeasurement() {
 //   NamedRegionTimer Implementation
 //===----------------------------------------------------------------------===//
 
-static ManagedStatic<std::map<std::string, Timer> > NamedTimers;
+namespace {
+
+typedef std::map<std::string, Timer> Name2Timer;
+typedef std::map<std::string, std::pair<TimerGroup, Name2Timer> > Name2Pair;
+
+}
+
+static ManagedStatic<Name2Timer> NamedTimers;
+
+static ManagedStatic<Name2Pair> NamedGroupedTimers;
 
 static Timer &getNamedRegionTimer(const std::string &Name) {
-  std::map<std::string, Timer>::iterator I = NamedTimers->find(Name);
+  Name2Timer::iterator I = NamedTimers->find(Name);
   if (I != NamedTimers->end())
     return I->second;
 
   return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second;
 }
 
+static Timer &getNamedRegionTimer(const std::string &Name,
+                                  const std::string &GroupName) {
+
+  Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
+  if (I == NamedGroupedTimers->end()) {
+    TimerGroup TG(GroupName);
+    std::pair<TimerGroup, Name2Timer> Pair(TG, Name2Timer());
+    I = NamedGroupedTimers->insert(I, std::make_pair(GroupName, Pair));
+  }
+
+  Name2Timer::iterator J = I->second.second.find(Name);
+  if (J == I->second.second.end())
+    J = I->second.second.insert(J,
+                                std::make_pair(Name,
+                                               Timer(Name,
+                                                     I->second.first)));
+
+  return J->second;
+}
+
 NamedRegionTimer::NamedRegionTimer(const std::string &Name)
   : TimeRegion(getNamedRegionTimer(Name)) {}
 
+NamedRegionTimer::NamedRegionTimer(const std::string &Name,
+                                   const std::string &GroupName)
+  : TimeRegion(getNamedRegionTimer(Name, GroupName)) {}
 
 //===----------------------------------------------------------------------===//
 //   TimerGroup Implementation