20 changes: 1 addition & 19 deletions llvm/tools/llvm-reduce/deltas/ReduceInstructionsMIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ static Register getPrevDefOfRCInMBB(MachineBasicBlock &MBB,
return 0;
}

static unsigned countInstructions(MachineFunction &MF) {
unsigned Count = 0;
MachineInstr *TopMI = nullptr;
for (auto &MBB : MF) {
for (auto &MI : MBB) {
if (MI.isTerminator())
continue;
if (MBB.isEntryBlock() && !TopMI) {
TopMI = &MI;
continue;
}
Count++;
}
}
return Count;
}

static void extractInstrFromModule(Oracle &O, MachineFunction &MF) {
MachineDominatorTree MDT;
MDT.runOnMachineFunction(MF);
Expand Down Expand Up @@ -138,6 +121,5 @@ static void extractInstrFromModule(Oracle &O, MachineFunction &MF) {

void llvm::reduceInstructionsMIRDeltaPass(TestRunner &Test) {
outs() << "*** Reducing Instructions...\n";
unsigned InstCount = countInstructions(Test.getProgram());
runDeltaPass(Test, InstCount, extractInstrFromModule);
runDeltaPass(Test, extractInstrFromModule);
}
31 changes: 1 addition & 30 deletions llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,8 @@ static void extractMetadataFromModule(Oracle &O, Module &Program) {
}
}

static int countMetadataTargets(Module &Program) {
int NamedMetadataNodes = Program.named_metadata_size();

// Get metadata attached to globals.
int GlobalMetadataArgs = 0;
SmallVector<std::pair<unsigned, MDNode *>> MDs;
for (GlobalVariable &GV : Program.globals()) {
GV.getAllMetadata(MDs);
GlobalMetadataArgs += MDs.size();
}

// Get metadata attached to functions & instructions.
int FunctionMetadataArgs = 0;
int InstructionMetadataArgs = 0;
for (Function &F : Program) {
F.getAllMetadata(MDs);
FunctionMetadataArgs += MDs.size();

for (Instruction &I : instructions(F)) {
I.getAllMetadata(MDs);
InstructionMetadataArgs += MDs.size();
}
}

return NamedMetadataNodes + GlobalMetadataArgs + FunctionMetadataArgs +
InstructionMetadataArgs;
}

void llvm::reduceMetadataDeltaPass(TestRunner &Test) {
outs() << "*** Reducing Metadata...\n";
int MDCount = countMetadataTargets(Test.getProgram());
runDeltaPass(Test, MDCount, extractMetadataFromModule);
runDeltaPass(Test, extractMetadataFromModule);
outs() << "----------------------------\n";
}
18 changes: 1 addition & 17 deletions llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,7 @@ static void clearModuleData(Oracle &O, Module &Program) {
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";
int Count = countModuleData(Test.getProgram());
runDeltaPass(Test, Count, clearModuleData);
runDeltaPass(Test, clearModuleData);
}
15 changes: 1 addition & 14 deletions llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,7 @@ static void extractOperandBundesFromModule(Oracle &O, Module &Program) {
maybeRewriteCallWithDifferentBundles(I.first, I.second);
}

/// Counts the amount of operand bundles.
static int countOperandBundes(Module &Program) {
OperandBundleCounter C;

// TODO: Silence index with --quiet flag
outs() << "----------------------------\n";
C.visit(Program);
outs() << "Number of operand bundles: " << C.OperandBundeCount << "\n";

return C.OperandBundeCount;
}

void llvm::reduceOperandBundesDeltaPass(TestRunner &Test) {
outs() << "*** Reducing OperandBundes...\n";
int OperandBundeCount = countOperandBundes(Test.getProgram());
runDeltaPass(Test, OperandBundeCount, extractOperandBundesFromModule);
runDeltaPass(Test, extractOperandBundesFromModule);
}
23 changes: 3 additions & 20 deletions llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ extractOperandsFromModule(Oracle &O, Module &Program,
}
}

static int countOperands(Module &Program,
function_ref<Value *(Use &)> ReduceValue) {
int Count = 0;
for (auto &F : Program.functions()) {
for (auto &I : instructions(&F)) {
for (auto &Op : I.operands()) {
if (ReduceValue(Op))
Count++;
}
}
}
return Count;
}

static bool isOne(Use &Op) {
auto *C = dyn_cast<Constant>(Op);
return C && C->isOneValue();
Expand Down Expand Up @@ -76,8 +62,7 @@ void llvm::reduceOperandsUndefDeltaPass(TestRunner &Test) {
// Don't replace existing ConstantData Uses.
return isa<ConstantData>(*Op) ? nullptr : UndefValue::get(Op->getType());
};
int Count = countOperands(Test.getProgram(), ReduceValue);
runDeltaPass(Test, Count, [ReduceValue](Oracle &O, Module &Program) {
runDeltaPass(Test, [ReduceValue](Oracle &O, Module &Program) {
extractOperandsFromModule(O, Program, ReduceValue);
});
}
Expand All @@ -94,8 +79,7 @@ void llvm::reduceOperandsOneDeltaPass(TestRunner &Test) {
// Don't replace existing ones and zeroes.
return (isOne(Op) || isZero(Op)) ? nullptr : ConstantInt::get(Ty, 1);
};
int Count = countOperands(Test.getProgram(), ReduceValue);
runDeltaPass(Test, Count, [ReduceValue](Oracle &O, Module &Program) {
runDeltaPass(Test, [ReduceValue](Oracle &O, Module &Program) {
extractOperandsFromModule(O, Program, ReduceValue);
});
}
Expand All @@ -108,8 +92,7 @@ void llvm::reduceOperandsZeroDeltaPass(TestRunner &Test) {
// Don't replace existing zeroes.
return isZero(Op) ? nullptr : Constant::getNullValue(Op->getType());
};
int Count = countOperands(Test.getProgram(), ReduceValue);
runDeltaPass(Test, Count, [ReduceValue](Oracle &O, Module &Program) {
runDeltaPass(Test, [ReduceValue](Oracle &O, Module &Program) {
extractOperandsFromModule(O, Program, ReduceValue);
});
}
22 changes: 1 addition & 21 deletions llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,7 @@ static void reduceOperandsToArgs(Oracle &O, Module &Program) {
}
}

/// Counts the amount of operands in the module that can be reduced.
static int countOperands(Module &Program) {
int Count = 0;

for (Function &F : Program.functions()) {
if (!canReplaceFunction(&F))
continue;
for (Instruction &I : instructions(&F)) {
for (Use &Op : I.operands()) {
if (!canReduceUse(Op))
continue;
Count += 1;
}
}
}

return Count;
}

void llvm::reduceOperandsToArgsDeltaPass(TestRunner &Test) {
outs() << "*** Converting operands to function arguments ...\n";
int ArgCount = countOperands(Test.getProgram());
return runDeltaPass(Test, ArgCount, reduceOperandsToArgs);
return runDeltaPass(Test, reduceOperandsToArgs);
}
18 changes: 1 addition & 17 deletions llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,8 @@ static void extractSpecialGlobalsFromModule(Oracle &O, Module &Program) {
}
}

/// Counts the amount of special globals and prints their
/// respective name & index
static int countSpecialGlobals(Module &Program) {
// TODO: Silence index with --quiet flag
errs() << "----------------------------\n";
errs() << "Special Globals Index Reference:\n";
int Count = 0;
for (StringRef Name : SpecialGlobalNames) {
if (auto *Used = Program.getNamedGlobal(Name))
errs() << "\t" << ++Count << ": " << Used->getName() << "\n";
}
errs() << "----------------------------\n";
return Count;
}

void llvm::reduceSpecialGlobalsDeltaPass(TestRunner &Test) {
errs() << "*** Reducing Special Globals ...\n";
int Functions = countSpecialGlobals(Test.getProgram());
runDeltaPass(Test, Functions, extractSpecialGlobalsFromModule);
runDeltaPass(Test, extractSpecialGlobalsFromModule);
errs() << "----------------------------\n";
}