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
|
/// Counts the amount of lines for a given file
|
||||||
static unsigned getLines(StringRef Filepath) {
|
static int getLines(StringRef Filepath) {
|
||||||
unsigned Lines = 0;
|
int Lines = 0;
|
||||||
std::string CurrLine;
|
std::string CurrLine;
|
||||||
std::ifstream FileStream(Filepath);
|
std::ifstream FileStream(Filepath);
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
|
|||||||
if (C.end - C.begin == 0)
|
if (C.end - C.begin == 0)
|
||||||
NewChunks.push_back(C);
|
NewChunks.push_back(C);
|
||||||
else {
|
else {
|
||||||
unsigned Half = (C.begin + C.end) / 2;
|
int Half = (C.begin + C.end) / 2;
|
||||||
NewChunks.push_back({C.begin, Half});
|
NewChunks.push_back({C.begin, Half});
|
||||||
NewChunks.push_back({Half + 1, C.end});
|
NewChunks.push_back({Half + 1, C.end});
|
||||||
SplitOne = true;
|
SplitOne = true;
|
||||||
@ -88,9 +88,10 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
|
|||||||
/// reduces the amount of chunks that are considered interesting by the
|
/// reduces the amount of chunks that are considered interesting by the
|
||||||
/// given test.
|
/// given test.
|
||||||
void llvm::runDeltaPass(
|
void llvm::runDeltaPass(
|
||||||
TestRunner &Test, unsigned Targets,
|
TestRunner &Test, int Targets,
|
||||||
std::function<void(const std::vector<Chunk> &, Module *)>
|
std::function<void(const std::vector<Chunk> &, Module *)>
|
||||||
ExtractChunksFromModule) {
|
ExtractChunksFromModule) {
|
||||||
|
assert(Targets >= 0);
|
||||||
if (!Targets) {
|
if (!Targets) {
|
||||||
errs() << "\nNothing to reduce\n";
|
errs() << "\nNothing to reduce\n";
|
||||||
return;
|
return;
|
||||||
|
@ -23,11 +23,11 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
struct Chunk {
|
struct Chunk {
|
||||||
unsigned begin;
|
int begin;
|
||||||
unsigned end;
|
int end;
|
||||||
|
|
||||||
/// Helper function to verify if a given Target-index is inside the Chunk
|
/// 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 {
|
void print() const {
|
||||||
errs() << "[" << begin;
|
errs() << "[" << begin;
|
||||||
@ -68,7 +68,7 @@ struct Chunk {
|
|||||||
///
|
///
|
||||||
/// Other implementations of the Delta Debugging algorithm can also be found in
|
/// Other implementations of the Delta Debugging algorithm can also be found in
|
||||||
/// the CReduce, Delta, and Lithium projects.
|
/// 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 *)>
|
std::function<void(const std::vector<Chunk> &, Module *)>
|
||||||
ExtractChunksFromModule);
|
ExtractChunksFromModule);
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
@ -42,7 +42,7 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
|
|||||||
/// accordingly. It also removes allocations of out-of-chunk arguments.
|
/// accordingly. It also removes allocations of out-of-chunk arguments.
|
||||||
static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
|
static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
|
||||||
Module *Program) {
|
Module *Program) {
|
||||||
unsigned I = 0, ArgCount = 0;
|
int I = 0, ArgCount = 0;
|
||||||
std::set<Argument *> ArgsToKeep;
|
std::set<Argument *> ArgsToKeep;
|
||||||
std::vector<Function *> Funcs;
|
std::vector<Function *> Funcs;
|
||||||
// Get inside-chunk arguments, as well as their parent function
|
// Get inside-chunk arguments, as well as their parent function
|
||||||
@ -50,7 +50,7 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
|
|||||||
if (!F.isDeclaration()) {
|
if (!F.isDeclaration()) {
|
||||||
Funcs.push_back(&F);
|
Funcs.push_back(&F);
|
||||||
for (auto &A : F.args())
|
for (auto &A : F.args())
|
||||||
if (I < ChunksToKeep.size()) {
|
if (I < (int)ChunksToKeep.size()) {
|
||||||
if (ChunksToKeep[I].contains(++ArgCount))
|
if (ChunksToKeep[I].contains(++ArgCount))
|
||||||
ArgsToKeep.insert(&A);
|
ArgsToKeep.insert(&A);
|
||||||
if (ChunksToKeep[I].end == ArgCount)
|
if (ChunksToKeep[I].end == ArgCount)
|
||||||
@ -120,6 +120,6 @@ static int countArguments(Module *Program) {
|
|||||||
|
|
||||||
void llvm::reduceArgumentsDeltaPass(TestRunner &Test) {
|
void llvm::reduceArgumentsDeltaPass(TestRunner &Test) {
|
||||||
outs() << "*** Reducing Arguments...\n";
|
outs() << "*** Reducing Arguments...\n";
|
||||||
unsigned ArgCount = countArguments(Test.getProgram());
|
int ArgCount = countArguments(Test.getProgram());
|
||||||
runDeltaPass(Test, ArgCount, extractArgumentsFromModule);
|
runDeltaPass(Test, ArgCount, extractArgumentsFromModule);
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,12 @@ static void removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
|
|||||||
/// @returns the Module stripped of out-of-chunk functions
|
/// @returns the Module stripped of out-of-chunk functions
|
||||||
static void extractBasicBlocksFromModule(std::vector<Chunk> ChunksToKeep,
|
static void extractBasicBlocksFromModule(std::vector<Chunk> ChunksToKeep,
|
||||||
Module *Program) {
|
Module *Program) {
|
||||||
unsigned I = 0, BBCount = 0;
|
int I = 0, BBCount = 0;
|
||||||
std::set<BasicBlock *> BBsToKeep;
|
std::set<BasicBlock *> BBsToKeep;
|
||||||
|
|
||||||
for (auto &F : *Program)
|
for (auto &F : *Program)
|
||||||
for (auto &BB : F)
|
for (auto &BB : F)
|
||||||
if (I < ChunksToKeep.size()) {
|
if (I < (int)ChunksToKeep.size()) {
|
||||||
if (ChunksToKeep[I].contains(++BBCount))
|
if (ChunksToKeep[I].contains(++BBCount))
|
||||||
BBsToKeep.insert(&BB);
|
BBsToKeep.insert(&BB);
|
||||||
if (ChunksToKeep[I].end == BBCount)
|
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
|
/// 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
|
// TODO: Silence index with --quiet flag
|
||||||
outs() << "----------------------------\n";
|
outs() << "----------------------------\n";
|
||||||
int BBCount = 0;
|
int BBCount = 0;
|
||||||
@ -137,6 +137,6 @@ static unsigned countBasicBlocks(Module *Program) {
|
|||||||
|
|
||||||
void llvm::reduceBasicBlocksDeltaPass(TestRunner &Test) {
|
void llvm::reduceBasicBlocksDeltaPass(TestRunner &Test) {
|
||||||
outs() << "*** Reducing Basic Blocks...\n";
|
outs() << "*** Reducing Basic Blocks...\n";
|
||||||
unsigned BBCount = countBasicBlocks(Test.getProgram());
|
int BBCount = countBasicBlocks(Test.getProgram());
|
||||||
runDeltaPass(Test, BBCount, extractBasicBlocksFromModule);
|
runDeltaPass(Test, BBCount, extractBasicBlocksFromModule);
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
|
|||||||
Module *Program) {
|
Module *Program) {
|
||||||
// Get functions inside desired chunks
|
// Get functions inside desired chunks
|
||||||
std::set<Function *> FuncsToKeep;
|
std::set<Function *> FuncsToKeep;
|
||||||
unsigned I = 0, FunctionCount = 0;
|
int I = 0, FunctionCount = 0;
|
||||||
for (auto &F : *Program)
|
for (auto &F : *Program)
|
||||||
if (I < ChunksToKeep.size()) {
|
if (I < (int)ChunksToKeep.size()) {
|
||||||
if (ChunksToKeep[I].contains(++FunctionCount))
|
if (ChunksToKeep[I].contains(++FunctionCount))
|
||||||
FuncsToKeep.insert(&F);
|
FuncsToKeep.insert(&F);
|
||||||
if (FunctionCount == ChunksToKeep[I].end)
|
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
|
/// Counts the amount of non-declaration functions and prints their
|
||||||
/// respective name & index
|
/// respective name & index
|
||||||
static unsigned countFunctions(Module *Program) {
|
static int countFunctions(Module *Program) {
|
||||||
// TODO: Silence index with --quiet flag
|
// TODO: Silence index with --quiet flag
|
||||||
errs() << "----------------------------\n";
|
errs() << "----------------------------\n";
|
||||||
errs() << "Function Index Reference:\n";
|
errs() << "Function Index Reference:\n";
|
||||||
unsigned FunctionCount = 0;
|
int FunctionCount = 0;
|
||||||
for (auto &F : *Program)
|
for (auto &F : *Program)
|
||||||
errs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n";
|
errs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n";
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ static unsigned countFunctions(Module *Program) {
|
|||||||
|
|
||||||
void llvm::reduceFunctionsDeltaPass(TestRunner &Test) {
|
void llvm::reduceFunctionsDeltaPass(TestRunner &Test) {
|
||||||
errs() << "*** Reducing Functions...\n";
|
errs() << "*** Reducing Functions...\n";
|
||||||
unsigned Functions = countFunctions(Test.getProgram());
|
int Functions = countFunctions(Test.getProgram());
|
||||||
runDeltaPass(Test, Functions, extractFunctionsFromModule);
|
runDeltaPass(Test, Functions, extractFunctionsFromModule);
|
||||||
errs() << "----------------------------\n";
|
errs() << "----------------------------\n";
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,9 @@ static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
|
|||||||
Module *Program) {
|
Module *Program) {
|
||||||
// Get GVs inside desired chunks
|
// Get GVs inside desired chunks
|
||||||
std::set<GlobalVariable *> GVsToKeep;
|
std::set<GlobalVariable *> GVsToKeep;
|
||||||
unsigned I = 0, GVCount = 0;
|
int I = 0, GVCount = 0;
|
||||||
for (auto &GV : Program->globals())
|
for (auto &GV : Program->globals())
|
||||||
if (GV.hasInitializer() && I < ChunksToKeep.size()) {
|
if (GV.hasInitializer() && I < (int)ChunksToKeep.size()) {
|
||||||
if (ChunksToKeep[I].contains(++GVCount))
|
if (ChunksToKeep[I].contains(++GVCount))
|
||||||
GVsToKeep.insert(&GV);
|
GVsToKeep.insert(&GV);
|
||||||
if (GVCount == ChunksToKeep[I].end)
|
if (GVCount == ChunksToKeep[I].end)
|
||||||
@ -69,6 +69,6 @@ static int countGVs(Module *Program) {
|
|||||||
|
|
||||||
void llvm::reduceGlobalsDeltaPass(TestRunner &Test) {
|
void llvm::reduceGlobalsDeltaPass(TestRunner &Test) {
|
||||||
outs() << "*** Reducing GVs...\n";
|
outs() << "*** Reducing GVs...\n";
|
||||||
unsigned GVCount = countGVs(Test.getProgram());
|
int GVCount = countGVs(Test.getProgram());
|
||||||
runDeltaPass(Test, GVCount, extractGVsFromModule);
|
runDeltaPass(Test, GVCount, extractGVsFromModule);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ using namespace llvm;
|
|||||||
|
|
||||||
/// Adds all Unnamed Metadata Nodes that are inside desired Chunks to set
|
/// Adds all Unnamed Metadata Nodes that are inside desired Chunks to set
|
||||||
template <class T>
|
template <class T>
|
||||||
static void getChunkMetadataNodes(T &MDUser, unsigned &I,
|
static void getChunkMetadataNodes(T &MDUser, int &I,
|
||||||
const std::vector<Chunk> &ChunksToKeep,
|
const std::vector<Chunk> &ChunksToKeep,
|
||||||
std::set<MDNode *> &SeenNodes,
|
std::set<MDNode *> &SeenNodes,
|
||||||
std::set<MDNode *> &NodesToKeep) {
|
std::set<MDNode *> &NodesToKeep) {
|
||||||
@ -29,10 +29,10 @@ static void getChunkMetadataNodes(T &MDUser, unsigned &I,
|
|||||||
MDUser.getAllMetadata(MDs);
|
MDUser.getAllMetadata(MDs);
|
||||||
for (auto &MD : MDs) {
|
for (auto &MD : MDs) {
|
||||||
SeenNodes.insert(MD.second);
|
SeenNodes.insert(MD.second);
|
||||||
if (I < ChunksToKeep.size()) {
|
if (I < (int)ChunksToKeep.size()) {
|
||||||
if (ChunksToKeep[I].contains(SeenNodes.size()))
|
if (ChunksToKeep[I].contains(SeenNodes.size()))
|
||||||
NodesToKeep.insert(MD.second);
|
NodesToKeep.insert(MD.second);
|
||||||
if (ChunksToKeep[I].end == SeenNodes.size())
|
if (ChunksToKeep[I].end == (int)SeenNodes.size())
|
||||||
++I;
|
++I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ static void extractMetadataFromModule(const std::vector<Chunk> &ChunksToKeep,
|
|||||||
Module *Program) {
|
Module *Program) {
|
||||||
std::set<MDNode *> SeenNodes;
|
std::set<MDNode *> SeenNodes;
|
||||||
std::set<MDNode *> NodesToKeep;
|
std::set<MDNode *> NodesToKeep;
|
||||||
unsigned I = 0;
|
int I = 0;
|
||||||
|
|
||||||
// Add chunk MDNodes used by GVs, Functions, and Instructions to set
|
// Add chunk MDNodes used by GVs, Functions, and Instructions to set
|
||||||
for (auto &GV : Program->globals())
|
for (auto &GV : Program->globals())
|
||||||
@ -84,10 +84,10 @@ static void extractMetadataFromModule(const std::vector<Chunk> &ChunksToKeep,
|
|||||||
unsigned MetadataCount = SeenNodes.size();
|
unsigned MetadataCount = SeenNodes.size();
|
||||||
std::vector<NamedMDNode *> NamedNodesToDelete;
|
std::vector<NamedMDNode *> NamedNodesToDelete;
|
||||||
for (auto &MD : Program->named_metadata()) {
|
for (auto &MD : Program->named_metadata()) {
|
||||||
if (I < ChunksToKeep.size()) {
|
if (I < (int)ChunksToKeep.size()) {
|
||||||
if (!ChunksToKeep[I].contains(++MetadataCount))
|
if (!ChunksToKeep[I].contains(++MetadataCount))
|
||||||
NamedNodesToDelete.push_back(&MD);
|
NamedNodesToDelete.push_back(&MD);
|
||||||
if (ChunksToKeep[I].end == SeenNodes.size())
|
if (ChunksToKeep[I].end == (int)SeenNodes.size())
|
||||||
++I;
|
++I;
|
||||||
} else
|
} else
|
||||||
NamedNodesToDelete.push_back(&MD);
|
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
|
/// Returns the amount of Named and Unnamed Metadata Nodes
|
||||||
static unsigned countMetadataTargets(Module *Program) {
|
static int countMetadataTargets(Module *Program) {
|
||||||
std::set<MDNode *> UnnamedNodes;
|
std::set<MDNode *> UnnamedNodes;
|
||||||
int NamedMetadataNodes = Program->named_metadata_size();
|
int NamedMetadataNodes = Program->named_metadata_size();
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ static unsigned countMetadataTargets(Module *Program) {
|
|||||||
|
|
||||||
void llvm::reduceMetadataDeltaPass(TestRunner &Test) {
|
void llvm::reduceMetadataDeltaPass(TestRunner &Test) {
|
||||||
outs() << "*** Reducing Metadata...\n";
|
outs() << "*** Reducing Metadata...\n";
|
||||||
unsigned MDCount = countMetadataTargets(Test.getProgram());
|
int MDCount = countMetadataTargets(Test.getProgram());
|
||||||
runDeltaPass(Test, MDCount, extractMetadataFromModule);
|
runDeltaPass(Test, MDCount, extractMetadataFromModule);
|
||||||
outs() << "----------------------------\n";
|
outs() << "----------------------------\n";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user