diff --git a/tools/llvm-reduce/deltas/Delta.cpp b/tools/llvm-reduce/deltas/Delta.cpp index 0b5571f74de..0642241ddeb 100644 --- a/tools/llvm-reduce/deltas/Delta.cpp +++ b/tools/llvm-reduce/deltas/Delta.cpp @@ -44,8 +44,8 @@ bool IsReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) { } /// Counts the amount of lines for a given file -static unsigned getLines(StringRef Filepath) { - unsigned Lines = 0; +static int getLines(StringRef Filepath) { + int Lines = 0; std::string CurrLine; std::ifstream FileStream(Filepath); @@ -66,7 +66,7 @@ static bool increaseGranularity(std::vector &Chunks) { if (C.end - C.begin == 0) NewChunks.push_back(C); else { - unsigned Half = (C.begin + C.end) / 2; + int Half = (C.begin + C.end) / 2; NewChunks.push_back({C.begin, Half}); NewChunks.push_back({Half + 1, C.end}); SplitOne = true; @@ -88,9 +88,10 @@ static bool increaseGranularity(std::vector &Chunks) { /// reduces the amount of chunks that are considered interesting by the /// given test. void llvm::runDeltaPass( - TestRunner &Test, unsigned Targets, + TestRunner &Test, int Targets, std::function &, Module *)> ExtractChunksFromModule) { + assert(Targets >= 0); if (!Targets) { errs() << "\nNothing to reduce\n"; return; diff --git a/tools/llvm-reduce/deltas/Delta.h b/tools/llvm-reduce/deltas/Delta.h index d6cf52f8d63..dbb18e4bd07 100644 --- a/tools/llvm-reduce/deltas/Delta.h +++ b/tools/llvm-reduce/deltas/Delta.h @@ -23,11 +23,11 @@ namespace llvm { struct Chunk { - unsigned begin; - unsigned end; + int begin; + int end; /// Helper function to verify if a given Target-index is inside the Chunk - bool contains(unsigned Index) const { return Index >= begin && Index <= end; } + bool contains(int Index) const { return Index >= begin && Index <= end; } void print() const { errs() << "[" << begin; @@ -68,7 +68,7 @@ struct Chunk { /// /// Other implementations of the Delta Debugging algorithm can also be found in /// the CReduce, Delta, and Lithium projects. -void runDeltaPass(TestRunner &Test, unsigned Targets, +void runDeltaPass(TestRunner &Test, int Targets, std::function &, Module *)> ExtractChunksFromModule); } // namespace llvm diff --git a/tools/llvm-reduce/deltas/ReduceArguments.cpp b/tools/llvm-reduce/deltas/ReduceArguments.cpp index 34977f33a90..f5f14b83f42 100644 --- a/tools/llvm-reduce/deltas/ReduceArguments.cpp +++ b/tools/llvm-reduce/deltas/ReduceArguments.cpp @@ -42,7 +42,7 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF, /// accordingly. It also removes allocations of out-of-chunk arguments. static void extractArgumentsFromModule(std::vector ChunksToKeep, Module *Program) { - unsigned I = 0, ArgCount = 0; + int I = 0, ArgCount = 0; std::set ArgsToKeep; std::vector Funcs; // Get inside-chunk arguments, as well as their parent function @@ -50,7 +50,7 @@ static void extractArgumentsFromModule(std::vector ChunksToKeep, if (!F.isDeclaration()) { Funcs.push_back(&F); for (auto &A : F.args()) - if (I < ChunksToKeep.size()) { + if (I < (int)ChunksToKeep.size()) { if (ChunksToKeep[I].contains(++ArgCount)) ArgsToKeep.insert(&A); if (ChunksToKeep[I].end == ArgCount) @@ -120,6 +120,6 @@ static int countArguments(Module *Program) { void llvm::reduceArgumentsDeltaPass(TestRunner &Test) { outs() << "*** Reducing Arguments...\n"; - unsigned ArgCount = countArguments(Test.getProgram()); + int ArgCount = countArguments(Test.getProgram()); runDeltaPass(Test, ArgCount, extractArgumentsFromModule); } diff --git a/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp index 538394eb879..1f5957ef911 100644 --- a/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp +++ b/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp @@ -78,12 +78,12 @@ static void removeUninterestingBBsFromSwitch(SwitchInst &SwInst, /// @returns the Module stripped of out-of-chunk functions static void extractBasicBlocksFromModule(std::vector ChunksToKeep, Module *Program) { - unsigned I = 0, BBCount = 0; + int I = 0, BBCount = 0; std::set BBsToKeep; for (auto &F : *Program) for (auto &BB : F) - if (I < ChunksToKeep.size()) { + if (I < (int)ChunksToKeep.size()) { if (ChunksToKeep[I].contains(++BBCount)) BBsToKeep.insert(&BB); if (ChunksToKeep[I].end == BBCount) @@ -120,7 +120,7 @@ static void extractBasicBlocksFromModule(std::vector ChunksToKeep, } /// Counts the amount of basic blocks and prints their name & respective index -static unsigned countBasicBlocks(Module *Program) { +static int countBasicBlocks(Module *Program) { // TODO: Silence index with --quiet flag outs() << "----------------------------\n"; int BBCount = 0; @@ -137,6 +137,6 @@ static unsigned countBasicBlocks(Module *Program) { void llvm::reduceBasicBlocksDeltaPass(TestRunner &Test) { outs() << "*** Reducing Basic Blocks...\n"; - unsigned BBCount = countBasicBlocks(Test.getProgram()); + int BBCount = countBasicBlocks(Test.getProgram()); runDeltaPass(Test, BBCount, extractBasicBlocksFromModule); } diff --git a/tools/llvm-reduce/deltas/ReduceFunctions.cpp b/tools/llvm-reduce/deltas/ReduceFunctions.cpp index 84dc842d972..3382f35a945 100644 --- a/tools/llvm-reduce/deltas/ReduceFunctions.cpp +++ b/tools/llvm-reduce/deltas/ReduceFunctions.cpp @@ -25,9 +25,9 @@ static void extractFunctionsFromModule(const std::vector &ChunksToKeep, Module *Program) { // Get functions inside desired chunks std::set FuncsToKeep; - unsigned I = 0, FunctionCount = 0; + int I = 0, FunctionCount = 0; for (auto &F : *Program) - if (I < ChunksToKeep.size()) { + if (I < (int)ChunksToKeep.size()) { if (ChunksToKeep[I].contains(++FunctionCount)) FuncsToKeep.insert(&F); if (FunctionCount == ChunksToKeep[I].end) @@ -57,11 +57,11 @@ static void extractFunctionsFromModule(const std::vector &ChunksToKeep, /// Counts the amount of non-declaration functions and prints their /// respective name & index -static unsigned countFunctions(Module *Program) { +static int countFunctions(Module *Program) { // TODO: Silence index with --quiet flag errs() << "----------------------------\n"; errs() << "Function Index Reference:\n"; - unsigned FunctionCount = 0; + int FunctionCount = 0; for (auto &F : *Program) errs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n"; @@ -71,7 +71,7 @@ static unsigned countFunctions(Module *Program) { void llvm::reduceFunctionsDeltaPass(TestRunner &Test) { errs() << "*** Reducing Functions...\n"; - unsigned Functions = countFunctions(Test.getProgram()); + int Functions = countFunctions(Test.getProgram()); runDeltaPass(Test, Functions, extractFunctionsFromModule); errs() << "----------------------------\n"; } diff --git a/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp b/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp index b2c78d17078..5732208ee0a 100644 --- a/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp +++ b/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp @@ -21,9 +21,9 @@ static void extractGVsFromModule(std::vector ChunksToKeep, Module *Program) { // Get GVs inside desired chunks std::set GVsToKeep; - unsigned I = 0, GVCount = 0; + int I = 0, GVCount = 0; for (auto &GV : Program->globals()) - if (GV.hasInitializer() && I < ChunksToKeep.size()) { + if (GV.hasInitializer() && I < (int)ChunksToKeep.size()) { if (ChunksToKeep[I].contains(++GVCount)) GVsToKeep.insert(&GV); if (GVCount == ChunksToKeep[I].end) @@ -69,6 +69,6 @@ static int countGVs(Module *Program) { void llvm::reduceGlobalsDeltaPass(TestRunner &Test) { outs() << "*** Reducing GVs...\n"; - unsigned GVCount = countGVs(Test.getProgram()); + int GVCount = countGVs(Test.getProgram()); runDeltaPass(Test, GVCount, extractGVsFromModule); } diff --git a/tools/llvm-reduce/deltas/ReduceMetadata.cpp b/tools/llvm-reduce/deltas/ReduceMetadata.cpp index 56e69ce873d..4ea223546ef 100644 --- a/tools/llvm-reduce/deltas/ReduceMetadata.cpp +++ b/tools/llvm-reduce/deltas/ReduceMetadata.cpp @@ -21,7 +21,7 @@ using namespace llvm; /// Adds all Unnamed Metadata Nodes that are inside desired Chunks to set template -static void getChunkMetadataNodes(T &MDUser, unsigned &I, +static void getChunkMetadataNodes(T &MDUser, int &I, const std::vector &ChunksToKeep, std::set &SeenNodes, std::set &NodesToKeep) { @@ -29,10 +29,10 @@ static void getChunkMetadataNodes(T &MDUser, unsigned &I, MDUser.getAllMetadata(MDs); for (auto &MD : MDs) { SeenNodes.insert(MD.second); - if (I < ChunksToKeep.size()) { + if (I < (int)ChunksToKeep.size()) { if (ChunksToKeep[I].contains(SeenNodes.size())) NodesToKeep.insert(MD.second); - if (ChunksToKeep[I].end == SeenNodes.size()) + if (ChunksToKeep[I].end == (int)SeenNodes.size()) ++I; } } @@ -55,7 +55,7 @@ static void extractMetadataFromModule(const std::vector &ChunksToKeep, Module *Program) { std::set SeenNodes; std::set NodesToKeep; - unsigned I = 0; + int I = 0; // Add chunk MDNodes used by GVs, Functions, and Instructions to set for (auto &GV : Program->globals()) @@ -84,10 +84,10 @@ static void extractMetadataFromModule(const std::vector &ChunksToKeep, unsigned MetadataCount = SeenNodes.size(); std::vector NamedNodesToDelete; for (auto &MD : Program->named_metadata()) { - if (I < ChunksToKeep.size()) { + if (I < (int)ChunksToKeep.size()) { if (!ChunksToKeep[I].contains(++MetadataCount)) NamedNodesToDelete.push_back(&MD); - if (ChunksToKeep[I].end == SeenNodes.size()) + if (ChunksToKeep[I].end == (int)SeenNodes.size()) ++I; } else NamedNodesToDelete.push_back(&MD); @@ -111,7 +111,7 @@ static void addMetadataToSet(T &MDUser, std::set &UnnamedNodes) { } /// Returns the amount of Named and Unnamed Metadata Nodes -static unsigned countMetadataTargets(Module *Program) { +static int countMetadataTargets(Module *Program) { std::set UnnamedNodes; int NamedMetadataNodes = Program->named_metadata_size(); @@ -132,7 +132,7 @@ static unsigned countMetadataTargets(Module *Program) { void llvm::reduceMetadataDeltaPass(TestRunner &Test) { outs() << "*** Reducing Metadata...\n"; - unsigned MDCount = countMetadataTargets(Test.getProgram()); + int MDCount = countMetadataTargets(Test.getProgram()); runDeltaPass(Test, MDCount, extractMetadataFromModule); outs() << "----------------------------\n"; }