mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
llvm-reduce: Fix inconsistencies between int/unsigned usage (standardize on int)
llvm-svn: 372270
This commit is contained in:
parent
424d18eccd
commit
4d43efb06f
@ -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<Chunk> &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<Chunk> &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<void(const std::vector<Chunk> &, Module *)>
|
||||
ExtractChunksFromModule) {
|
||||
assert(Targets >= 0);
|
||||
if (!Targets) {
|
||||
errs() << "\nNothing to reduce\n";
|
||||
return;
|
||||
|
@ -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<void(const std::vector<Chunk> &, Module *)>
|
||||
ExtractChunksFromModule);
|
||||
} // namespace llvm
|
||||
|
@ -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<Chunk> ChunksToKeep,
|
||||
Module *Program) {
|
||||
unsigned I = 0, ArgCount = 0;
|
||||
int I = 0, ArgCount = 0;
|
||||
std::set<Argument *> ArgsToKeep;
|
||||
std::vector<Function *> Funcs;
|
||||
// Get inside-chunk arguments, as well as their parent function
|
||||
@ -50,7 +50,7 @@ static void extractArgumentsFromModule(std::vector<Chunk> 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);
|
||||
}
|
||||
|
@ -78,12 +78,12 @@ static void removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
|
||||
/// @returns the Module stripped of out-of-chunk functions
|
||||
static void extractBasicBlocksFromModule(std::vector<Chunk> ChunksToKeep,
|
||||
Module *Program) {
|
||||
unsigned I = 0, BBCount = 0;
|
||||
int I = 0, BBCount = 0;
|
||||
std::set<BasicBlock *> 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<Chunk> 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);
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
|
||||
Module *Program) {
|
||||
// Get functions inside desired chunks
|
||||
std::set<Function *> 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<Chunk> &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";
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
|
||||
Module *Program) {
|
||||
// Get GVs inside desired chunks
|
||||
std::set<GlobalVariable *> 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);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ using namespace llvm;
|
||||
|
||||
/// Adds all Unnamed Metadata Nodes that are inside desired Chunks to set
|
||||
template <class T>
|
||||
static void getChunkMetadataNodes(T &MDUser, unsigned &I,
|
||||
static void getChunkMetadataNodes(T &MDUser, int &I,
|
||||
const std::vector<Chunk> &ChunksToKeep,
|
||||
std::set<MDNode *> &SeenNodes,
|
||||
std::set<MDNode *> &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<Chunk> &ChunksToKeep,
|
||||
Module *Program) {
|
||||
std::set<MDNode *> SeenNodes;
|
||||
std::set<MDNode *> 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<Chunk> &ChunksToKeep,
|
||||
unsigned MetadataCount = SeenNodes.size();
|
||||
std::vector<NamedMDNode *> 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<MDNode *> &UnnamedNodes) {
|
||||
}
|
||||
|
||||
/// Returns the amount of Named and Unnamed Metadata Nodes
|
||||
static unsigned countMetadataTargets(Module *Program) {
|
||||
static int countMetadataTargets(Module *Program) {
|
||||
std::set<MDNode *> 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";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user