diff --git a/llvm/tools/llvm-reduce/CMakeLists.txt b/llvm/tools/llvm-reduce/CMakeLists.txt --- a/llvm/tools/llvm-reduce/CMakeLists.txt +++ b/llvm/tools/llvm-reduce/CMakeLists.txt @@ -11,6 +11,7 @@ ) add_llvm_tool(llvm-reduce + DeltaManager.cpp TestRunner.cpp deltas/Delta.cpp deltas/ReduceAliases.cpp diff --git a/llvm/tools/llvm-reduce/DeltaManager.h b/llvm/tools/llvm-reduce/DeltaManager.h --- a/llvm/tools/llvm-reduce/DeltaManager.h +++ b/llvm/tools/llvm-reduce/DeltaManager.h @@ -11,40 +11,13 @@ // //===----------------------------------------------------------------------===// +#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 diff --git a/llvm/tools/llvm-reduce/DeltaManager.h b/llvm/tools/llvm-reduce/DeltaManager.cpp copy from llvm/tools/llvm-reduce/DeltaManager.h copy to llvm/tools/llvm-reduce/DeltaManager.cpp --- a/llvm/tools/llvm-reduce/DeltaManager.h +++ b/llvm/tools/llvm-reduce/DeltaManager.cpp @@ -1,4 +1,4 @@ -//===- DeltaManager.h - Runs Delta Passes to reduce Input -----------------===// +//===- 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. @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "DeltaManager.h" #include "TestRunner.h" #include "deltas/Delta.h" #include "deltas/ReduceAliases.h" @@ -30,7 +31,7 @@ namespace llvm { // TODO: Add CLI option to run only specified Passes (for unit tests) -inline void runDeltaPasses(TestRunner &Tester) { +void runDeltaPasses(TestRunner &Tester) { reduceSpecialGlobalsDeltaPass(Tester); reduceAliasesDeltaPass(Tester); reduceFunctionBodiesDeltaPass(Tester); @@ -46,5 +47,4 @@ reduceAttributesDeltaPass(Tester); // TODO: Implement the remaining Delta Passes } - -} // namespace llvm +} // namespace llvm \ No newline at end of file diff --git a/llvm/tools/llvm-reduce/TestRunner.h b/llvm/tools/llvm-reduce/TestRunner.h --- a/llvm/tools/llvm-reduce/TestRunner.h +++ b/llvm/tools/llvm-reduce/TestRunner.h @@ -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" diff --git a/llvm/tools/llvm-reduce/deltas/Delta.h b/llvm/tools/llvm-reduce/deltas/Delta.h --- a/llvm/tools/llvm-reduce/deltas/Delta.h +++ b/llvm/tools/llvm-reduce/deltas/Delta.h @@ -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" @@ -24,27 +24,27 @@ 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 @@ ArrayRef ChunksToKeep; public: - explicit Oracle(ArrayRef ChunksToKeep_) - : ChunksToKeep(ChunksToKeep_) {} + explicit Oracle(ArrayRef 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 @@ 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; diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp --- a/llvm/tools/llvm-reduce/deltas/Delta.cpp +++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp @@ -24,7 +24,7 @@ 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 @@ 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 @@ 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 @@ 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; diff --git a/llvm/tools/llvm-reduce/deltas/ReduceAliases.h b/llvm/tools/llvm-reduce/deltas/ReduceAliases.h --- a/llvm/tools/llvm-reduce/deltas/ReduceAliases.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceAliases.h @@ -11,8 +11,13 @@ // //===----------------------------------------------------------------------===// +#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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.h b/llvm/tools/llvm-reduce/deltas/ReduceArguments.h --- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.h @@ -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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceAttributes.h b/llvm/tools/llvm-reduce/deltas/ReduceAttributes.h --- a/llvm/tools/llvm-reduce/deltas/ReduceAttributes.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceAttributes.h @@ -11,10 +11,12 @@ // //===----------------------------------------------------------------------===// -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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp b/llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp @@ -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. diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.h b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.h --- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.h @@ -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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp @@ -26,9 +26,9 @@ /// Replaces BB Terminator with one that only contains Chunk BBs static void replaceBranchTerminator(BasicBlock &BB, std::set BBsToKeep) { - auto Term = BB.getTerminator(); + auto *Term = BB.getTerminator(); std::vector ChunkSucessors; - for (auto Succ : successors(&BB)) + for (auto *Succ : successors(&BB)) if (BBsToKeep.count(Succ)) ChunkSucessors.push_back(Succ); @@ -38,7 +38,7 @@ bool IsBranch = isa(Term) || isa(Term); Value *Address = nullptr; - if (auto IndBI = dyn_cast(Term)) + if (auto *IndBI = dyn_cast(Term)) Address = IndBI->getAddress(); Term->replaceAllUsesWith(UndefValue::get(Term->getType())); @@ -56,9 +56,9 @@ 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); } } diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h --- a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h @@ -11,8 +11,13 @@ // //===----------------------------------------------------------------------===// +#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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.h b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.h --- a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.h @@ -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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.h b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.h --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.h @@ -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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.h b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.h --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.h @@ -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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp @@ -33,7 +33,7 @@ std::vector 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(U)) InstToRemove.push_back(Inst); diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInstructions.h b/llvm/tools/llvm-reduce/deltas/ReduceInstructions.h --- a/llvm/tools/llvm-reduce/deltas/ReduceInstructions.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceInstructions.h @@ -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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceMetadata.h b/llvm/tools/llvm-reduce/deltas/ReduceMetadata.h --- a/llvm/tools/llvm-reduce/deltas/ReduceMetadata.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceMetadata.h @@ -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. @@ -11,8 +11,13 @@ // //===----------------------------------------------------------------------===// +#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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.h b/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.h --- a/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.h @@ -11,10 +11,12 @@ // //===----------------------------------------------------------------------===// -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 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.h b/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.h --- a/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.h +++ b/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.h @@ -14,8 +14,13 @@ // //===----------------------------------------------------------------------===// +#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 diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp --- a/llvm/tools/llvm-reduce/llvm-reduce.cpp +++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp @@ -96,10 +96,10 @@ 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 OriginalProgram = diff --git a/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn b/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn --- a/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn @@ -9,6 +9,7 @@ ] include_dirs = [ "." ] sources = [ + "DeltaManager.cpp", "TestRunner.cpp", "deltas/Delta.cpp", "deltas/ReduceAliases.cpp",