Skip to content

Commit

Permalink
[llvm-reduce] Check if module data strings are empty before attemptin…
Browse files Browse the repository at this point in the history
…g to reduce
  • Loading branch information
aeubanks committed Aug 24, 2021
1 parent 266a8d5 commit 2d8a2a9
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp
Expand Up @@ -17,20 +17,36 @@ using namespace llvm;
static void clearModuleData(std::vector<Chunk> ChunksToKeep, Module *Program) {
Oracle O(ChunksToKeep);

if (!O.shouldKeep())
if (!Program->getModuleIdentifier().empty() && !O.shouldKeep())
Program->setModuleIdentifier("");
if (!O.shouldKeep())
if (!Program->getSourceFileName().empty() && !O.shouldKeep())
Program->setSourceFileName("");
if (!O.shouldKeep())
if (!Program->getDataLayoutStr().empty() && !O.shouldKeep())
Program->setDataLayout("");
if (!O.shouldKeep())
if (!Program->getTargetTriple().empty() && !O.shouldKeep())
Program->setTargetTriple("");
// TODO: clear line by line rather than all at once
if (!O.shouldKeep())
if (!Program->getModuleInlineAsm().empty() && !O.shouldKeep())
Program->setModuleInlineAsm("");
}

static int countModuleData(Module *M) {
int Count = 0;
if (!M->getModuleIdentifier().empty())
++Count;
if (!M->getSourceFileName().empty())
++Count;
if (!M->getDataLayoutStr().empty())
++Count;
if (!M->getTargetTriple().empty())
++Count;
if (!M->getModuleInlineAsm().empty())
++Count;
return Count;
}

void llvm::reduceModuleDataDeltaPass(TestRunner &Test) {
outs() << "*** Reducing Module Data...\n";
runDeltaPass(Test, 5, clearModuleData);
int Count = countModuleData(Test.getProgram());
runDeltaPass(Test, Count, clearModuleData);
}

0 comments on commit 2d8a2a9

Please sign in to comment.