[llvm-reduce] Add header guards and fix clang-tidy warnings
authorSamuel <swamulism@gmail.com>
Fri, 2 Apr 2021 03:38:39 +0000 (20:38 -0700)
committerArthur Eubanks <aeubanks@google.com>
Fri, 2 Apr 2021 03:38:49 +0000 (20:38 -0700)
Add header guards and fix other clang-tidy warnings in .h files.
Also align misaligned header docs

Reviewed By: aeubanks

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

23 files changed:
llvm/tools/llvm-reduce/CMakeLists.txt
llvm/tools/llvm-reduce/DeltaManager.cpp [new file with mode: 0644]
llvm/tools/llvm-reduce/DeltaManager.h
llvm/tools/llvm-reduce/TestRunner.h
llvm/tools/llvm-reduce/deltas/Delta.cpp
llvm/tools/llvm-reduce/deltas/Delta.h
llvm/tools/llvm-reduce/deltas/ReduceAliases.h
llvm/tools/llvm-reduce/deltas/ReduceArguments.h
llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp
llvm/tools/llvm-reduce/deltas/ReduceAttributes.h
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.h
llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h
llvm/tools/llvm-reduce/deltas/ReduceFunctions.h
llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.h
llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.h
llvm/tools/llvm-reduce/deltas/ReduceInstructions.h
llvm/tools/llvm-reduce/deltas/ReduceMetadata.h
llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.h
llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.h
llvm/tools/llvm-reduce/llvm-reduce.cpp
llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn

index 0f91677..4b37ff6 100644 (file)
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_llvm_tool(llvm-reduce
+  DeltaManager.cpp
   TestRunner.cpp
   deltas/Delta.cpp
   deltas/ReduceAliases.cpp
diff --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
new file mode 100644 (file)
index 0000000..797b680
--- /dev/null
@@ -0,0 +1,50 @@
+//===- DeltaManager.cpp - Runs Delta Passes to reduce Input ---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file calls each specialized Delta pass in order to reduce the input IR
+// file.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DeltaManager.h"
+#include "TestRunner.h"
+#include "deltas/Delta.h"
+#include "deltas/ReduceAliases.h"
+#include "deltas/ReduceArguments.h"
+#include "deltas/ReduceAttributes.h"
+#include "deltas/ReduceBasicBlocks.h"
+#include "deltas/ReduceFunctionBodies.h"
+#include "deltas/ReduceFunctions.h"
+#include "deltas/ReduceGlobalValues.h"
+#include "deltas/ReduceGlobalVarInitializers.h"
+#include "deltas/ReduceGlobalVars.h"
+#include "deltas/ReduceInstructions.h"
+#include "deltas/ReduceMetadata.h"
+#include "deltas/ReduceOperandBundles.h"
+#include "deltas/ReduceSpecialGlobals.h"
+
+namespace llvm {
+
+// TODO: Add CLI option to run only specified Passes (for unit tests)
+void runDeltaPasses(TestRunner &Tester) {
+  reduceSpecialGlobalsDeltaPass(Tester);
+  reduceAliasesDeltaPass(Tester);
+  reduceFunctionBodiesDeltaPass(Tester);
+  reduceFunctionsDeltaPass(Tester);
+  reduceBasicBlocksDeltaPass(Tester);
+  reduceGlobalValuesDeltaPass(Tester);
+  reduceGlobalsInitializersDeltaPass(Tester);
+  reduceGlobalsDeltaPass(Tester);
+  reduceMetadataDeltaPass(Tester);
+  reduceArgumentsDeltaPass(Tester);
+  reduceInstructionsDeltaPass(Tester);
+  reduceOperandBundesDeltaPass(Tester);
+  reduceAttributesDeltaPass(Tester);
+  // TODO: Implement the remaining Delta Passes
+}
+} // namespace llvm
\ No newline at end of file
index 5970a3a..b310f89 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAMANAGER_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAMANAGER_H
+
 #include "TestRunner.h"
-#include "deltas/Delta.h"
-#include "deltas/ReduceAliases.h"
-#include "deltas/ReduceArguments.h"
-#include "deltas/ReduceAttributes.h"
-#include "deltas/ReduceBasicBlocks.h"
-#include "deltas/ReduceFunctionBodies.h"
-#include "deltas/ReduceFunctions.h"
-#include "deltas/ReduceGlobalValues.h"
-#include "deltas/ReduceGlobalVarInitializers.h"
-#include "deltas/ReduceGlobalVars.h"
-#include "deltas/ReduceInstructions.h"
-#include "deltas/ReduceMetadata.h"
-#include "deltas/ReduceOperandBundles.h"
-#include "deltas/ReduceSpecialGlobals.h"
 
 namespace llvm {
-
-// TODO: Add CLI option to run only specified Passes (for unit tests)
-inline void runDeltaPasses(TestRunner &Tester) {
-  reduceSpecialGlobalsDeltaPass(Tester);
-  reduceAliasesDeltaPass(Tester);
-  reduceFunctionBodiesDeltaPass(Tester);
-  reduceFunctionsDeltaPass(Tester);
-  reduceBasicBlocksDeltaPass(Tester);
-  reduceGlobalValuesDeltaPass(Tester);
-  reduceGlobalsInitializersDeltaPass(Tester);
-  reduceGlobalsDeltaPass(Tester);
-  reduceMetadataDeltaPass(Tester);
-  reduceArgumentsDeltaPass(Tester);
-  reduceInstructionsDeltaPass(Tester);
-  reduceOperandBundesDeltaPass(Tester);
-  reduceAttributesDeltaPass(Tester);
-  // TODO: Implement the remaining Delta Passes
-}
-
+void runDeltaPasses(TestRunner &Tester);
 } // namespace llvm
+
+#endif
index 2270d6b..b7fb44e 100644 (file)
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TOOLS_LLVMREDUCE_TESTRUNNER_H
-#define LLVM_TOOLS_LLVMREDUCE_TESTRUNNER_H
+#ifndef LLVM_TOOLS_LLVM_REDUCE_TESTRUNNER_H
+#define LLVM_TOOLS_LLVM_REDUCE_TESTRUNNER_H
 
 #include "llvm/ADT/SmallString.h"
 #include "llvm/IR/Module.h"
index 9b0969e..75d9279 100644 (file)
@@ -24,7 +24,7 @@ using namespace llvm;
 
 void writeOutput(llvm::Module *M, llvm::StringRef Message);
 
-bool IsReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) {
+bool isReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) {
   // Write Module to tmp file
   int FD;
   std::error_code EC =
@@ -66,12 +66,12 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
   bool SplitOne = false;
 
   for (auto &C : Chunks) {
-    if (C.end - C.begin == 0)
+    if (C.End - C.Begin == 0)
       NewChunks.push_back(C);
     else {
-      int Half = (C.begin + C.end) / 2;
-      NewChunks.push_back({C.begin, Half});
-      NewChunks.push_back({Half + 1, C.end});
+      int Half = (C.Begin + C.End) / 2;
+      NewChunks.push_back({C.Begin, Half});
+      NewChunks.push_back({Half + 1, C.End});
       SplitOne = true;
     }
   }
@@ -102,7 +102,7 @@ void llvm::runDeltaPass(
 
   if (Module *Program = Test.getProgram()) {
     SmallString<128> CurrentFilepath;
-    if (!IsReduced(*Program, Test, CurrentFilepath)) {
+    if (!isReduced(*Program, Test, CurrentFilepath)) {
       errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
       exit(1);
     }
@@ -152,7 +152,7 @@ void llvm::runDeltaPass(
         C.print();
 
       SmallString<128> CurrentFilepath;
-      if (!IsReduced(*Clone, Test, CurrentFilepath)) {
+      if (!isReduced(*Clone, Test, CurrentFilepath)) {
         // Program became non-reduced, so this chunk appears to be interesting.
         errs() << "\n";
         continue;
index 7da3c79..69bd4d2 100644 (file)
@@ -12,8 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TOOLS_LLVMREDUCE_LLVMREDUCE_DELTA_H
-#define LLVM_TOOLS_LLVMREDUCE_LLVMREDUCE_DELTA_H
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_DELTA_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_DELTA_H
 
 #include "TestRunner.h"
 #include "llvm/ADT/ScopeExit.h"
 namespace llvm {
 
 struct Chunk {
-  int begin;
-  int end;
+  int Begin;
+  int End;
 
   /// Helper function to verify if a given Target-index is inside the Chunk
-  bool contains(int Index) const { return Index >= begin && Index <= end; }
+  bool contains(int Index) const { return Index >= Begin && Index <= End; }
 
   void print() const {
-    errs() << "[" << begin;
-    if (end - begin != 0)
-      errs() << "," << end;
+    errs() << "[" << Begin;
+    if (End - Begin != 0)
+      errs() << "," << End;
     errs() << "]";
   }
 
   /// Operator when populating CurrentChunks in Generic Delta Pass
   friend bool operator!=(const Chunk &C1, const Chunk &C2) {
-    return C1.begin != C2.begin || C1.end != C2.end;
+    return C1.Begin != C2.Begin || C1.End != C2.End;
   }
 
   /// Operator used for sets
   friend bool operator<(const Chunk &C1, const Chunk &C2) {
-    return std::tie(C1.begin, C1.end) < std::tie(C2.begin, C2.end);
+    return std::tie(C1.Begin, C1.End) < std::tie(C2.Begin, C2.End);
   }
 };
 
@@ -60,8 +60,7 @@ class Oracle {
   ArrayRef<Chunk> ChunksToKeep;
 
 public:
-  explicit Oracle(ArrayRef<Chunk> ChunksToKeep_)
-      : ChunksToKeep(ChunksToKeep_) {}
+  explicit Oracle(ArrayRef<Chunk> ChunksToKeep) : ChunksToKeep(ChunksToKeep) {}
 
   /// Should be called for each feature on which we are operating.
   /// Name is self-explanatory - if returns true, then it should be preserved.
@@ -74,7 +73,7 @@ public:
     auto _ = make_scope_exit([&]() { ++Index; }); // Next time - next feature.
 
     // Is this the last feature in the chunk?
-    if (ChunksToKeep.front().end == Index)
+    if (ChunksToKeep.front().End == Index)
       ChunksToKeep = ChunksToKeep.drop_front(); // Onto next chunk.
 
     return ShouldKeep;
index 0c2886e..0660efe 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEALIASES_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEALIASES_H
+
 #include "Delta.h"
 
 namespace llvm {
 void reduceAliasesDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index d9682b4..228409d 100644 (file)
@@ -11,6 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEARGUMENTS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEARGUMENTS_H
+
 #include "Delta.h"
 #include "llvm/IR/Argument.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -19,3 +22,5 @@
 namespace llvm {
 void reduceArgumentsDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index cbaf5d5..26b77bf 100644 (file)
@@ -1,4 +1,4 @@
-//===- ReduceAttributes.cpp - Specialized Delta Pass -------------------===//
+//===- ReduceAttributes.cpp - Specialized Delta Pass ----------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
index f8deb04..375e764 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-namespace llvm {
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEATTRIBUTES_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEATTRIBUTES_H
 
+namespace llvm {
 class TestRunner;
-
 void reduceAttributesDeltaPass(TestRunner &Test);
-
 } // namespace llvm
+
+#endif
index 8c0832d..5a1905d 100644 (file)
@@ -26,9 +26,9 @@ using namespace llvm;
 /// Replaces BB Terminator with one that only contains Chunk BBs
 static void replaceBranchTerminator(BasicBlock &BB,
                                     std::set<BasicBlock *> BBsToKeep) {
-  auto Term = BB.getTerminator();
+  auto *Term = BB.getTerminator();
   std::vector<BasicBlock *> ChunkSucessors;
-  for (auto Succ : successors(&BB))
+  for (auto *Succ : successors(&BB))
     if (BBsToKeep.count(Succ))
       ChunkSucessors.push_back(Succ);
 
@@ -38,7 +38,7 @@ static void replaceBranchTerminator(BasicBlock &BB,
 
   bool IsBranch = isa<BranchInst>(Term) || isa<InvokeInst>(Term);
   Value *Address = nullptr;
-  if (auto IndBI = dyn_cast<IndirectBrInst>(Term))
+  if (auto *IndBI = dyn_cast<IndirectBrInst>(Term))
     Address = IndBI->getAddress();
 
   Term->replaceAllUsesWith(UndefValue::get(Term->getType()));
@@ -56,9 +56,9 @@ static void replaceBranchTerminator(BasicBlock &BB,
     BranchInst::Create(ChunkSucessors[0], &BB);
 
   if (Address) {
-    auto NewIndBI =
+    auto *NewIndBI =
         IndirectBrInst::Create(Address, ChunkSucessors.size(), &BB);
-    for (auto Dest : ChunkSucessors)
+    for (auto *Dest : ChunkSucessors)
       NewIndBI->addDestination(Dest);
   }
 }
index cf76a0a..4938552 100644 (file)
@@ -10,6 +10,8 @@
 // to reduce uninteresting Arguments from defined functions.
 //
 //===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEBASICBLOCKS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEBASICBLOCKS_H
 
 #include "Delta.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -18,3 +20,5 @@
 namespace llvm {
 void reduceBasicBlocksDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index 8c06c2e..bfe701b 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEFUNCTIONBODIES_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEFUNCTIONBODIES_H
+
 #include "Delta.h"
 
 namespace llvm {
 void reduceFunctionBodiesDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index 7c2cd3f..f5bc83b 100644 (file)
@@ -11,6 +11,8 @@
 // Module.
 //
 //===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEFUNCTIONS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEFUNCTIONS_H
 
 #include "Delta.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -18,3 +20,5 @@
 namespace llvm {
 void reduceFunctionsDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index 39288ad..0f5f22a 100644 (file)
@@ -1,5 +1,4 @@
-//===- reduceGlobalsInitializersDeltaPass.h - Specialized Delta Pass
-//-------===//
+//===- reduceGlobalsInitializersDeltaPass.h - Specialized Delta Pass ------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -12,6 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEGLOBALVARINITIALIZERS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEGLOBALVARINITIALIZERS_H
+
 #include "Delta.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -19,3 +21,5 @@
 namespace llvm {
 void reduceGlobalsInitializersDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index 4b184e5..525eff9 100644 (file)
@@ -33,7 +33,7 @@ static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
   std::vector<WeakVH> InstToRemove;
   for (auto &GV : Program->globals())
     if (!GVsToKeep.count(&GV)) {
-      for (auto U : GV.users())
+      for (auto *U : GV.users())
         if (auto *Inst = dyn_cast<Instruction>(U))
           InstToRemove.push_back(Inst);
 
index c8ba7ea..fe7813c 100644 (file)
@@ -11,6 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEGLOBALVARS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEGLOBALVARS_H
+
 #include "Delta.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -18,3 +21,5 @@
 namespace llvm {
 void reduceGlobalsDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index a9266ac..be568f1 100644 (file)
@@ -11,6 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEINSTRUCTIONS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEINSTRUCTIONS_H
+
 #include "Delta.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -18,3 +21,5 @@
 namespace llvm {
 void reduceInstructionsDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index 275b44c..6efc3f5 100644 (file)
@@ -1,4 +1,4 @@
-//===- ReduceMetadata.h - Specialized Delta Pass ------------------------===//
+//===- ReduceMetadata.h - Specialized Delta Pass --------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEMETADATA_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEMETADATA_H
+
 #include "TestRunner.h"
 
 namespace llvm {
 void reduceMetadataDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index 382c5cb..d07e021 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-namespace llvm {
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEOPERANDBUNDLES_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEOPERANDBUNDLES_H
 
+namespace llvm {
 class TestRunner;
-
 void reduceOperandBundesDeltaPass(TestRunner &Test);
-
 } // namespace llvm
+
+#endif
index 52ecaed..c0f3f9e 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCESPECIALGLOBALS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCESPECIALGLOBALS_H
+
 #include "Delta.h"
 
 namespace llvm {
 void reduceSpecialGlobalsDeltaPass(TestRunner &Test);
 } // namespace llvm
+
+#endif
index 376826b..0499d49 100644 (file)
@@ -96,10 +96,10 @@ void writeOutput(Module *M, StringRef Message) {
   errs() << Message << OutputFilename << "\n";
 }
 
-int main(int argc, char **argv) {
-  InitLLVM X(argc, argv);
+int main(int Argc, char **Argv) {
+  InitLLVM X(Argc, Argv);
 
-  cl::ParseCommandLineOptions(argc, argv, "LLVM automatic testcase reducer.\n");
+  cl::ParseCommandLineOptions(Argc, Argv, "LLVM automatic testcase reducer.\n");
 
   LLVMContext Context;
   std::unique_ptr<Module> OriginalProgram =
index a00f00c..eb1492b 100644 (file)
@@ -9,6 +9,7 @@ executable("llvm-reduce") {
   ]
   include_dirs = [ "." ]
   sources = [
+    "DeltaManager.cpp",
     "TestRunner.cpp",
     "deltas/Delta.cpp",
     "deltas/ReduceAliases.cpp",