GlobalISel: switch to SmallVector for pending legalizations.
authorTim Northover <tnorthover@apple.com>
Mon, 29 Aug 2016 19:27:20 +0000 (19:27 +0000)
committerTim Northover <tnorthover@apple.com>
Mon, 29 Aug 2016 19:27:20 +0000 (19:27 +0000)
std::queue was doing far to many heap allocations to be healthy.

llvm-svn: 279992

llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp

index afc8289..9787227 100644 (file)
@@ -58,21 +58,23 @@ MachineLegalizeHelper::legalizeInstrStep(MachineInstr &MI,
 MachineLegalizeHelper::LegalizeResult
 MachineLegalizeHelper::legalizeInstr(MachineInstr &MI,
                                      const MachineLegalizer &Legalizer) {
-  std::queue<MachineInstr *> WorkList;
-  MIRBuilder.recordInsertions([&](MachineInstr *MI) { WorkList.push(MI); });
-  WorkList.push(&MI);
+  SmallVector<MachineInstr *, 4> WorkList;
+  MIRBuilder.recordInsertions(
+      [&](MachineInstr *MI) { WorkList.push_back(MI); });
+  WorkList.push_back(&MI);
 
   bool Changed = false;
   LegalizeResult Res;
+  unsigned Idx = 0;
   do {
-    Res = legalizeInstrStep(*WorkList.front(), Legalizer);
+    Res = legalizeInstrStep(*WorkList[Idx], Legalizer);
     if (Res == UnableToLegalize) {
       MIRBuilder.stopRecordingInsertions();
       return UnableToLegalize;
     }
     Changed |= Res == Legalized;
-    WorkList.pop();
-  } while (!WorkList.empty());
+    ++Idx;
+  } while (Idx < WorkList.size());
 
   MIRBuilder.stopRecordingInsertions();