[llvm-reduce] Count chunks by running a preliminary reduction
authorArthur Eubanks <aeubanks@google.com>
Fri, 12 Nov 2021 02:45:59 +0000 (18:45 -0800)
committerArthur Eubanks <aeubanks@google.com>
Fri, 12 Nov 2021 02:46:09 +0000 (18:46 -0800)
Having a separate counting method runs the risk of a mismatch between
the actual reduction method and the counting method.

Instead, create an Oracle that always returns true for shouldKeep(), run
the reduction, and count how many times shouldKeep() was called. The
module should not be modified if shouldKeep() always returns true.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D113537

20 files changed:
llvm/tools/llvm-reduce/deltas/Delta.cpp
llvm/tools/llvm-reduce/deltas/Delta.h
llvm/tools/llvm-reduce/deltas/ReduceAliases.cpp
llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp
llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp
llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp
llvm/tools/llvm-reduce/deltas/ReduceInstructionsMIR.cpp
llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp
llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp
llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp
llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp

index bd4e8de07047c4fbd8b1f6ff776c455601676307..f4f77c6310d6d41125d6c2e60e99b88d22117020 100644 (file)
@@ -102,9 +102,18 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
 /// given test.
 template <typename T>
 void runDeltaPassInt(
-    TestRunner &Test, int Targets,
+    TestRunner &Test,
     function_ref<void(Oracle &, T &)> ExtractChunksFromModule) {
-  assert(Targets >= 0);
+  int Targets;
+  {
+    // Count the number of targets by counting the number of calls to
+    // Oracle::shouldKeep() but always returning true so no changes are
+    // made.
+    std::vector<Chunk> AllChunks = {{0, INT_MAX}};
+    Oracle Counter(AllChunks);
+    ExtractChunksFromModule(Counter, Test.getProgram());
+    Targets = Counter.count();
+  }
   if (!Targets) {
     errs() << "\nNothing to reduce\n";
     return;
@@ -119,7 +128,7 @@ void runDeltaPassInt(
   assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) &&
          "input module is broken before making changes");
 
-  std::vector<Chunk> ChunksStillConsideredInteresting = {{1, Targets}};
+  std::vector<Chunk> ChunksStillConsideredInteresting = {{0, Targets - 1}};
   std::unique_ptr<ReducerWorkItem> ReducedProgram;
 
   for (unsigned int Level = 0; Level < StartingGranularityLevel; Level++) {
@@ -198,13 +207,13 @@ void runDeltaPassInt(
 }
 
 void llvm::runDeltaPass(
-    TestRunner &Test, int Targets,
+    TestRunner &Test,
     function_ref<void(Oracle &, Module &)> ExtractChunksFromModule) {
-  runDeltaPassInt<Module>(Test, Targets, ExtractChunksFromModule);
+  runDeltaPassInt<Module>(Test, ExtractChunksFromModule);
 }
 
 void llvm::runDeltaPass(
-    TestRunner &Test, int Targets,
+    TestRunner &Test,
     function_ref<void(Oracle &, MachineFunction &)> ExtractChunksFromModule) {
-  runDeltaPassInt<MachineFunction>(Test, Targets, ExtractChunksFromModule);
+  runDeltaPassInt<MachineFunction>(Test, ExtractChunksFromModule);
 }
index 00829ea1ae8105f2666929e8373cb592367ce8ef..a98da41957d012867e22e5a87cdb5aea2915caff 100644 (file)
@@ -52,8 +52,8 @@ struct Chunk {
 /// actually understand what is going on.
 class Oracle {
   /// Out of all the features that we promised to be,
-  /// how many have we already processed? 1-based!
-  int Index = 1;
+  /// how many have we already processed?
+  int Index = 0;
 
   /// The actual workhorse, contains the knowledge whether or not
   /// some particular feature should be preserved this time.
@@ -65,19 +65,24 @@ public:
   /// Should be called for each feature on which we are operating.
   /// Name is self-explanatory - if returns true, then it should be preserved.
   bool shouldKeep() {
-    if (ChunksToKeep.empty())
+    if (ChunksToKeep.empty()) {
+      ++Index;
       return false; // All further features are to be discarded.
+    }
 
     // Does the current (front) chunk contain such a feature?
     bool ShouldKeep = ChunksToKeep.front().contains(Index);
-    auto _ = make_scope_exit([&]() { ++Index; }); // Next time - next feature.
 
     // Is this the last feature in the chunk?
     if (ChunksToKeep.front().End == Index)
       ChunksToKeep = ChunksToKeep.drop_front(); // Onto next chunk.
 
+    ++Index;
+
     return ShouldKeep;
   }
+
+  int count() { return Index; }
 };
 
 /// This function implements the Delta Debugging algorithm, it receives a
@@ -92,9 +97,6 @@ public:
 /// RemoveFunctions) and receives three key parameters:
 /// * Test: The main TestRunner instance which is used to run the provided
 /// interesting-ness test, as well as to store and access the reduced Program.
-/// * Targets: The amount of Targets that are going to be reduced by the
-/// algorithm, for example, the RemoveGlobalVars pass would send the amount of
-/// initialized GVs.
 /// * ExtractChunksFromModule: A function used to tailor the main program so it
 /// only contains Targets that are inside Chunks of the given iteration.
 /// Note: This function is implemented by each specialized Delta pass
@@ -102,10 +104,10 @@ public:
 /// Other implementations of the Delta Debugging algorithm can also be found in
 /// the CReduce, Delta, and Lithium projects.
 void runDeltaPass(
-    TestRunner &Test, int Targets,
+    TestRunner &Test,
     function_ref<void(Oracle &, Module &)> ExtractChunksFromModule);
 void runDeltaPass(
-    TestRunner &Test, int Targets,
+    TestRunner &Test,
     function_ref<void(Oracle &, MachineFunction &)> ExtractChunksFromModule);
 } // namespace llvm
 
index dedaef860fcf3019aa58f9281f3f7c137f07bef0..cdcd4261cb5e22af521963f1173147745a235f6a 100644 (file)
@@ -29,22 +29,8 @@ static void extractAliasesFromModule(Oracle &O, Module &Program) {
   }
 }
 
-/// Counts the amount of aliases and prints their respective name & index.
-static int countAliases(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  errs() << "----------------------------\n";
-  errs() << "Aliases Index Reference:\n";
-  int Count = 0;
-  for (auto &GA : Program.aliases())
-    errs() << "\t" << ++Count << ": " << GA.getName() << "\n";
-
-  errs() << "----------------------------\n";
-  return Count;
-}
-
 void llvm::reduceAliasesDeltaPass(TestRunner &Test) {
   errs() << "*** Reducing Aliases ...\n";
-  int Functions = countAliases(Test.getProgram());
-  runDeltaPass(Test, Functions, extractAliasesFromModule);
+  runDeltaPass(Test, extractAliasesFromModule);
   errs() << "----------------------------\n";
 }
index eb582090bda582e8619ce5f6e886cb91635ca495..04ac47ebc4a7649c6b92774257bc03c37e20c3a2 100644 (file)
@@ -115,27 +115,7 @@ static void extractArgumentsFromModule(Oracle &O, Module &Program) {
   }
 }
 
-/// Counts the amount of arguments in functions and prints their respective
-/// name, index, and parent function name
-static int countArguments(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  outs() << "----------------------------\n";
-  outs() << "Param Index Reference:\n";
-  int ArgsCount = 0;
-  for (auto &F : Program)
-    if (shouldRemoveArguments(F)) {
-      outs() << "  " << F.getName() << "\n";
-      for (auto &A : F.args())
-        outs() << "\t" << ++ArgsCount << ": " << A.getName() << "\n";
-
-      outs() << "----------------------------\n";
-    }
-
-  return ArgsCount;
-}
-
 void llvm::reduceArgumentsDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing Arguments...\n";
-  int ArgCount = countArguments(Test.getProgram());
-  runDeltaPass(Test, ArgCount, extractArgumentsFromModule);
+  runDeltaPass(Test, extractArgumentsFromModule);
 }
index b2791b22e90433938907b20e62dbc320c5546fc2..27a03d8f6d11b5e22a023cdbda0a427915a34bda 100644 (file)
@@ -180,20 +180,7 @@ static void extractAttributesFromModule(Oracle &O, Module &Program) {
     I.first->setAttributes(convertAttributeRefVecToAttributeList(C, I.second));
 }
 
-/// Counts the amount of attributes.
-static int countAttributes(Module &Program) {
-  AttributeCounter C;
-
-  // TODO: Silence index with --quiet flag
-  outs() << "----------------------------\n";
-  C.visit(Program);
-  outs() << "Number of attributes: " << C.AttributeCount << "\n";
-
-  return C.AttributeCount;
-}
-
 void llvm::reduceAttributesDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing Attributes...\n";
-  int AttributeCount = countAttributes(Test.getProgram());
-  runDeltaPass(Test, AttributeCount, extractAttributesFromModule);
+  runDeltaPass(Test, extractAttributesFromModule);
 }
index 024129e28d64b560af834131e42f3177b0e52177..59d0cd910a94747787e77ac0c7fe51a11192403a 100644 (file)
@@ -139,24 +139,7 @@ static void extractBasicBlocksFromModule(Oracle &O, Module &Program) {
   }
 }
 
-/// Counts the amount of basic blocks and prints their name & respective index
-static int countBasicBlocks(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  outs() << "----------------------------\n";
-  int BBCount = 0;
-  for (auto &F : Program)
-    for (auto &BB : F) {
-      if (BB.hasName())
-        outs() << "\t" << ++BBCount << ": " << BB.getName() << "\n";
-      else
-        outs() << "\t" << ++BBCount << ": Unnamed\n";
-    }
-
-  return BBCount;
-}
-
 void llvm::reduceBasicBlocksDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing Basic Blocks...\n";
-  int BBCount = countBasicBlocks(Test.getProgram());
-  runDeltaPass(Test, BBCount, extractBasicBlocksFromModule);
+  runDeltaPass(Test, extractBasicBlocksFromModule);
 }
index 4a91e43987ca2ffc619a106b3d626db37c4fe312..63dd2f03b18f6671a96213080650da5ecf49bd3c 100644 (file)
@@ -29,25 +29,8 @@ static void extractFunctionBodiesFromModule(Oracle &O, Module &Program) {
     }
 }
 
-/// Counts the amount of non-declaration functions and prints their
-/// respective name & index
-static int countFunctionDefinitions(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  errs() << "----------------------------\n";
-  errs() << "Function Definition Index Reference:\n";
-  int FunctionDefinitionCount = 0;
-  for (auto &F : Program)
-    if (!F.isDeclaration())
-      errs() << "\t" << ++FunctionDefinitionCount << ": " << F.getName()
-             << "\n";
-
-  errs() << "----------------------------\n";
-  return FunctionDefinitionCount;
-}
-
 void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) {
   errs() << "*** Reducing Function Bodies...\n";
-  int Functions = countFunctionDefinitions(Test.getProgram());
-  runDeltaPass(Test, Functions, extractFunctionBodiesFromModule);
+  runDeltaPass(Test, extractFunctionBodiesFromModule);
   errs() << "----------------------------\n";
 }
index b033f1a05671aa177e9e1850c97bd7bb03d2d589..2a26d4340af83001c9fa24eeb4a43e4678630ca7 100644 (file)
@@ -48,27 +48,8 @@ static void extractFunctionsFromModule(Oracle &O, Module &Program) {
   }
 }
 
-/// Counts the amount of functions and prints their
-/// respective name & index
-static int countFunctions(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  errs() << "----------------------------\n";
-  errs() << "Function Index Reference:\n";
-  int FunctionCount = 0;
-  for (auto &F : Program) {
-    if (F.isIntrinsic() && !F.use_empty())
-      continue;
-
-    errs() << '\t' << ++FunctionCount << ": " << F.getName() << '\n';
-  }
-
-  errs() << "----------------------------\n";
-  return FunctionCount;
-}
-
 void llvm::reduceFunctionsDeltaPass(TestRunner &Test) {
   errs() << "*** Reducing Functions...\n";
-  int Functions = countFunctions(Test.getProgram());
-  runDeltaPass(Test, Functions, extractFunctionsFromModule);
+  runDeltaPass(Test, extractFunctionsFromModule);
   errs() << "----------------------------\n";
 }
index cd7627309b555692452375b9d72a0b95f35a9b71..8bbaf4489509d72c79f393d34e2f9bb3ea761ad4 100644 (file)
@@ -26,18 +26,7 @@ static void reduceGOs(Oracle &O, Module &Program) {
   }
 }
 
-static int countGOs(Module &Program) {
-  int SectionCount = count_if(Program.global_objects(), [](GlobalObject &GO) {
-    return shouldReduceSection(GO);
-  });
-  int AlignCount = count_if(Program.global_objects(), [](GlobalObject &GO) {
-    return shouldReduceAlign(GO);
-  });
-  return SectionCount + AlignCount;
-}
-
 void llvm::reduceGlobalObjectsDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing GlobalObjects...\n";
-  int GVCount = countGOs(Test.getProgram());
-  runDeltaPass(Test, GVCount, reduceGOs);
+  runDeltaPass(Test, reduceGOs);
 }
index 0110251d26a67adf49ff93a7b0114bc6535ea398..26a3cbded08d299c14f57edd9c5af567c2f8fed9 100644 (file)
@@ -57,28 +57,7 @@ static void reduceGVs(Oracle &O, Module &Program) {
   }
 }
 
-static int countGVs(Module &Program) {
-  int DSOLocalCount = count_if(Program.global_values(), [](GlobalValue &GV) {
-    return shouldReduceDSOLocal(GV);
-  });
-  int VisibilityCount = count_if(Program.global_values(), [](GlobalValue &GV) {
-    return shouldReduceVisibility(GV);
-  });
-  int UnnamedAddrCount = count_if(Program.global_values(), [](GlobalValue &GV) {
-    return shouldReduceUnnamedAddress(GV);
-  });
-  int DLLStorageClassCount =
-      count_if(Program.global_values(),
-               [](GlobalValue &GV) { return shouldReduceDLLStorageClass(GV); });
-  int ThreadLocalCount = count_if(Program.global_values(), [](GlobalValue &GV) {
-    return shouldReduceThreadLocal(GV);
-  });
-  return DSOLocalCount + VisibilityCount + UnnamedAddrCount +
-         DLLStorageClassCount + ThreadLocalCount;
-}
-
 void llvm::reduceGlobalValuesDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing GlobalValues...\n";
-  int GVCount = countGVs(Test.getProgram());
-  runDeltaPass(Test, GVCount, reduceGVs);
+  runDeltaPass(Test, reduceGVs);
 }
index 14c6a414e4b158c642599b96374c178baa436978..c9e4d9f6768215705027b4762053c6e513e34009 100644 (file)
@@ -28,22 +28,7 @@ static void extractGVsFromModule(Oracle &O, Module &Program) {
     }
 }
 
-/// Counts the amount of initialized GVs and displays their
-/// respective name & index
-static int countGVs(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  outs() << "----------------------------\n";
-  outs() << "GlobalVariable Index Reference:\n";
-  int GVCount = 0;
-  for (auto &GV : Program.globals())
-    if (GV.hasInitializer())
-      outs() << "\t" << ++GVCount << ": " << GV.getName() << "\n";
-  outs() << "----------------------------\n";
-  return GVCount;
-}
-
 void llvm::reduceGlobalsInitializersDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing GVs initializers...\n";
-  int GVCount = countGVs(Test.getProgram());
-  runDeltaPass(Test, GVCount, extractGVsFromModule);
+  runDeltaPass(Test, extractGVsFromModule);
 }
index 0cb481616841bdbaeed2a57500a4f975d9627627..1651a37eaa12b0a50576d607b812a41fccc15e5d 100644 (file)
@@ -57,21 +57,7 @@ static void extractGVsFromModule(Oracle &O, Module &Program) {
     GV->eraseFromParent();
 }
 
-/// Counts the amount of GVs and displays their
-/// respective name & index
-static int countGVs(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  outs() << "----------------------------\n";
-  outs() << "GlobalVariable Index Reference:\n";
-  int GVCount = 0;
-  for (auto &GV : Program.globals())
-    outs() << "\t" << ++GVCount << ": " << GV.getName() << "\n";
-  outs() << "----------------------------\n";
-  return GVCount;
-}
-
 void llvm::reduceGlobalsDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing GVs...\n";
-  int GVCount = countGVs(Test.getProgram());
-  runDeltaPass(Test, GVCount, extractGVsFromModule);
+  runDeltaPass(Test, extractGVsFromModule);
 }
index df7b54ccc0a9d32fa10cde7b17686ca3f6271c41..f27959fb98af51712956dc2aa05316c2f9245bbd 100644 (file)
@@ -49,22 +49,7 @@ static void extractInstrFromModule(Oracle &O, Module &Program) {
     I->eraseFromParent();
 }
 
-/// Counts the amount of basic blocks and prints their name & respective index
-static unsigned countInstructions(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  outs() << "----------------------------\n";
-  int InstCount = 0;
-  for (auto &F : Program)
-    for (auto &BB : F)
-      // Well-formed blocks have terminators, which we cannot remove.
-      InstCount += BB.getInstList().size() - 1;
-  outs() << "Number of instructions: " << InstCount << "\n";
-
-  return InstCount;
-}
-
 void llvm::reduceInstructionsDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing Instructions...\n";
-  unsigned InstCount = countInstructions(Test.getProgram());
-  runDeltaPass(Test, InstCount, extractInstrFromModule);
+  runDeltaPass(Test, extractInstrFromModule);
 }
index 4998de02811ffd22e4ab12e5c9de270da9df44c1..e64d6f3c5ee1b7e4b2a461611fd8f9f10d973440 100644 (file)
@@ -44,23 +44,6 @@ static Register getPrevDefOfRCInMBB(MachineBasicBlock &MBB,
   return 0;
 }
 
-static unsigned countInstructions(MachineFunction &MF) {
-  unsigned Count = 0;
-  MachineInstr *TopMI = nullptr;
-  for (auto &MBB : MF) {
-    for (auto &MI : MBB) {
-      if (MI.isTerminator())
-        continue;
-      if (MBB.isEntryBlock() && !TopMI) {
-        TopMI = &MI;
-        continue;
-      }
-      Count++;
-    }
-  }
-  return Count;
-}
-
 static void extractInstrFromModule(Oracle &O, MachineFunction &MF) {
   MachineDominatorTree MDT;
   MDT.runOnMachineFunction(MF);
@@ -138,6 +121,5 @@ static void extractInstrFromModule(Oracle &O, MachineFunction &MF) {
 
 void llvm::reduceInstructionsMIRDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing Instructions...\n";
-  unsigned InstCount = countInstructions(Test.getProgram());
-  runDeltaPass(Test, InstCount, extractInstrFromModule);
+  runDeltaPass(Test, extractInstrFromModule);
 }
index 066108ef12e8310054cda13b38e1ed004f84352b..2fa616c47c3f9f1f2faeaad913e5fb05bd32d150 100644 (file)
@@ -61,37 +61,8 @@ static void extractMetadataFromModule(Oracle &O, Module &Program) {
   }
 }
 
-static int countMetadataTargets(Module &Program) {
-  int NamedMetadataNodes = Program.named_metadata_size();
-
-  // Get metadata attached to globals.
-  int GlobalMetadataArgs = 0;
-  SmallVector<std::pair<unsigned, MDNode *>> MDs;
-  for (GlobalVariable &GV : Program.globals()) {
-    GV.getAllMetadata(MDs);
-    GlobalMetadataArgs += MDs.size();
-  }
-
-  // Get metadata attached to functions & instructions.
-  int FunctionMetadataArgs = 0;
-  int InstructionMetadataArgs = 0;
-  for (Function &F : Program) {
-    F.getAllMetadata(MDs);
-    FunctionMetadataArgs += MDs.size();
-
-    for (Instruction &I : instructions(F)) {
-      I.getAllMetadata(MDs);
-      InstructionMetadataArgs += MDs.size();
-    }
-  }
-
-  return NamedMetadataNodes + GlobalMetadataArgs + FunctionMetadataArgs +
-         InstructionMetadataArgs;
-}
-
 void llvm::reduceMetadataDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing Metadata...\n";
-  int MDCount = countMetadataTargets(Test.getProgram());
-  runDeltaPass(Test, MDCount, extractMetadataFromModule);
+  runDeltaPass(Test, extractMetadataFromModule);
   outs() << "----------------------------\n";
 }
index c134600e2f8772322e426d81854b20ba4a114a61..7a59950ca907c044c5d56ccdb0b54b7ce895e9d7 100644 (file)
@@ -28,23 +28,7 @@ static void clearModuleData(Oracle &O, Module &Program) {
     Program.setModuleInlineAsm("");
 }
 
-static int countModuleData(Module &M) {
-  int Count = 0;
-  if (!M.getModuleIdentifier().empty())
-    ++Count;
-  if (!M.getSourceFileName().empty())
-    ++Count;
-  if (!M.getDataLayoutStr().empty())
-    ++Count;
-  if (!M.getTargetTriple().empty())
-    ++Count;
-  if (!M.getModuleInlineAsm().empty())
-    ++Count;
-  return Count;
-}
-
 void llvm::reduceModuleDataDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing Module Data...\n";
-  int Count = countModuleData(Test.getProgram());
-  runDeltaPass(Test, Count, clearModuleData);
+  runDeltaPass(Test, clearModuleData);
 }
index 41e794f357408a4312bc6a69c9b158636dfe2481..c28bbb2e48dce71e6f774e34b55e9092b7a6669b 100644 (file)
@@ -103,20 +103,7 @@ static void extractOperandBundesFromModule(Oracle &O, Module &Program) {
     maybeRewriteCallWithDifferentBundles(I.first, I.second);
 }
 
-/// Counts the amount of operand bundles.
-static int countOperandBundes(Module &Program) {
-  OperandBundleCounter C;
-
-  // TODO: Silence index with --quiet flag
-  outs() << "----------------------------\n";
-  C.visit(Program);
-  outs() << "Number of operand bundles: " << C.OperandBundeCount << "\n";
-
-  return C.OperandBundeCount;
-}
-
 void llvm::reduceOperandBundesDeltaPass(TestRunner &Test) {
   outs() << "*** Reducing OperandBundes...\n";
-  int OperandBundeCount = countOperandBundes(Test.getProgram());
-  runDeltaPass(Test, OperandBundeCount, extractOperandBundesFromModule);
+  runDeltaPass(Test, extractOperandBundesFromModule);
 }
index 31c4921782b49228f80aebc3b3765d6d437748e4..5bfd87633f131bdbb85777ab668be85ee76360ce 100755 (executable)
@@ -29,20 +29,6 @@ extractOperandsFromModule(Oracle &O, Module &Program,
   }
 }
 
-static int countOperands(Module &Program,
-                         function_ref<Value *(Use &)> ReduceValue) {
-  int Count = 0;
-  for (auto &F : Program.functions()) {
-    for (auto &I : instructions(&F)) {
-      for (auto &Op : I.operands()) {
-        if (ReduceValue(Op))
-          Count++;
-      }
-    }
-  }
-  return Count;
-}
-
 static bool isOne(Use &Op) {
   auto *C = dyn_cast<Constant>(Op);
   return C && C->isOneValue();
@@ -76,8 +62,7 @@ void llvm::reduceOperandsUndefDeltaPass(TestRunner &Test) {
     // Don't replace existing ConstantData Uses.
     return isa<ConstantData>(*Op) ? nullptr : UndefValue::get(Op->getType());
   };
-  int Count = countOperands(Test.getProgram(), ReduceValue);
-  runDeltaPass(Test, Count, [ReduceValue](Oracle &O, Module &Program) {
+  runDeltaPass(Test, [ReduceValue](Oracle &O, Module &Program) {
     extractOperandsFromModule(O, Program, ReduceValue);
   });
 }
@@ -94,8 +79,7 @@ void llvm::reduceOperandsOneDeltaPass(TestRunner &Test) {
     // Don't replace existing ones and zeroes.
     return (isOne(Op) || isZero(Op)) ? nullptr : ConstantInt::get(Ty, 1);
   };
-  int Count = countOperands(Test.getProgram(), ReduceValue);
-  runDeltaPass(Test, Count, [ReduceValue](Oracle &O, Module &Program) {
+  runDeltaPass(Test, [ReduceValue](Oracle &O, Module &Program) {
     extractOperandsFromModule(O, Program, ReduceValue);
   });
 }
@@ -108,8 +92,7 @@ void llvm::reduceOperandsZeroDeltaPass(TestRunner &Test) {
     // Don't replace existing zeroes.
     return isZero(Op) ? nullptr : Constant::getNullValue(Op->getType());
   };
-  int Count = countOperands(Test.getProgram(), ReduceValue);
-  runDeltaPass(Test, Count, [ReduceValue](Oracle &O, Module &Program) {
+  runDeltaPass(Test, [ReduceValue](Oracle &O, Module &Program) {
     extractOperandsFromModule(O, Program, ReduceValue);
   });
 }
index e91c505fb8feb32c36c712ef9bf61628c55583f5..f1dcf24c6ea72fa098109c94bce5cc4bac328c8e 100644 (file)
@@ -192,27 +192,7 @@ static void reduceOperandsToArgs(Oracle &O, Module &Program) {
   }
 }
 
-/// Counts the amount of operands in the module that can be reduced.
-static int countOperands(Module &Program) {
-  int Count = 0;
-
-  for (Function &F : Program.functions()) {
-    if (!canReplaceFunction(&F))
-      continue;
-    for (Instruction &I : instructions(&F)) {
-      for (Use &Op : I.operands()) {
-        if (!canReduceUse(Op))
-          continue;
-        Count += 1;
-      }
-    }
-  }
-
-  return Count;
-}
-
 void llvm::reduceOperandsToArgsDeltaPass(TestRunner &Test) {
   outs() << "*** Converting operands to function arguments ...\n";
-  int ArgCount = countOperands(Test.getProgram());
-  return runDeltaPass(Test, ArgCount, reduceOperandsToArgs);
+  return runDeltaPass(Test, reduceOperandsToArgs);
 }
index 1030d6315b2d10775ef2dd51488e9ca820e3c546..57160f46ff8d9cde42d3b7e1f116ebebcfddd84b 100644 (file)
@@ -35,24 +35,8 @@ static void extractSpecialGlobalsFromModule(Oracle &O, Module &Program) {
   }
 }
 
-/// Counts the amount of special globals and prints their
-/// respective name & index
-static int countSpecialGlobals(Module &Program) {
-  // TODO: Silence index with --quiet flag
-  errs() << "----------------------------\n";
-  errs() << "Special Globals Index Reference:\n";
-  int Count = 0;
-  for (StringRef Name : SpecialGlobalNames) {
-    if (auto *Used = Program.getNamedGlobal(Name))
-      errs() << "\t" << ++Count << ": " << Used->getName() << "\n";
-  }
-  errs() << "----------------------------\n";
-  return Count;
-}
-
 void llvm::reduceSpecialGlobalsDeltaPass(TestRunner &Test) {
   errs() << "*** Reducing Special Globals ...\n";
-  int Functions = countSpecialGlobals(Test.getProgram());
-  runDeltaPass(Test, Functions, extractSpecialGlobalsFromModule);
+  runDeltaPass(Test, extractSpecialGlobalsFromModule);
   errs() << "----------------------------\n";
 }