#include "llvm/Module.h"
#include "llvm/Function.h"
#include "llvm/Pass.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumMerged("constmerge\t\t- Number of global constants merged");
// mergeDuplicateConstants - Workhorse for the pass. This eliminates duplicate
// constants, starting at global ConstantNo, and adds vars to the map if they
delete GList.remove(GList.begin()+ConstantNo);
--ConstantNo; // Don't skip the next constant.
+ ++NumMerged;
MadeChanges = true;
}
}
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include <algorithm>
#include <iostream>
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumResolved("funcresolve\t- Number of varargs functions resolved");
+static Statistic<> NumTypeSymtabEntriesKilled("cleangcc\t- Number of unused typenames removed from symtab");
+static Statistic<> NumCastsMoved("cleangcc\t- Number of casts removed from head of basic block");
+static Statistic<> NumRefactoredPreds("cleangcc\t- Number of predecessor blocks refactored");
+
using std::vector;
using std::string;
using std::cerr;
Plane.erase(PI); // Alas, GCC 2.95.3 doesn't *SIGH*
PI = Plane.begin();
#endif
+ ++NumTypeSymtabEntriesKilled;
Changed = true;
} else {
++PI;
// Move the cast instruction to the current insert position...
--InsertPos; // New position for cast to go...
std::swap(*InsertPos, *I); // Cast goes down, PHI goes up
+ Changed = true;
+
+ ++NumCastsMoved;
if (isa<PHINode>(Src) && // Handle case #1
cast<PHINode>(Src)->getParent() == BB) {
// Reinsert the cast right before the terminator in Pred.
Pred->getInstList().insert(Pred->end()-1, CI);
+ Changed = true;
}
} else {
++I;
for (unsigned i = 0; i < Preds.size(); ++i) {
if (SortedPreds[i] == LastOne) { // Found a duplicate.
RefactorPredecessor(BB, SortedPreds[i]);
+ ++NumRefactoredPreds;
Changed = true;
}
LastOne = SortedPreds[i];
delete Functions[i];
Functions.erase(Functions.begin()+i);
Changed = true;
+ ++NumResolved;
continue;
}
}
assert(CI->getOperand(0) == Old);
CI->setOperand(0, Concrete);
Changed = true;
+ ++NumResolved;
} else if (CallInst *CI = dyn_cast<CallInst>(U)) {
// Can only fix up calls TO the argument, not args passed in.
if (CI->getCalledValue() == Old) {
ConvertCallTo(CI, Concrete);
Changed = true;
+ ++NumResolved;
} else {
cerr << "Couldn't cleanup this function call, must be an"
<< " argument or something!" << CI;
#include "llvm/GlobalVariable.h"
#include "llvm/Analysis/CallGraph.h"
#include "Support/DepthFirstIterator.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumRemoved("globaldce\t- Number of global values removed");
static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) {
// Calculate which functions are reachable from the external functions in the
(*I)->dropAllReferences();
N->removeAllCalledMethods();
FunctionsToDelete.push_back(N);
+ ++NumRemoved;
}
}
++I; // Cannot eliminate global variable
else {
delete M->getGlobalList().remove(I);
+ ++NumRemoved;
Changed = true;
}
return Changed;
#include "llvm/iOther.h"
#include "llvm/Type.h"
#include "llvm/Argument.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumInlined("inline\t\t- Number of functions inlined");
#include <algorithm>
#include <iostream>
using std::cerr;
// Loop through now and inline instructions a basic block at a time...
for (Function::iterator I = F->begin(); I != F->end(); )
if (DoFunctionInlining(*I)) {
+ ++NumInlined;
Changed = true;
// Iterator is now invalidated by new basic blocks inserted
I = F->begin();
#include "llvm/Pass.h"
#include "llvm/Module.h"
#include "llvm/Function.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumChanged("internalize\t- Number of functions internal'd");
class InternalizePass : public Pass {
const char *getPassName() const { return "Internalize Functions"; }
// Found a main function, mark all functions not named main as internal.
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
- if ((*I)->getName() != "main" && // Leave the main function external
- !(*I)->isExternal()) // Function must be defined here
- (*I)->setInternalLinkage(Changed = true);
+ if ((*I)->getName() != "main" && // Leave the main function external
+ !(*I)->isExternal()) { // Function must be defined here
+ (*I)->setInternalLinkage(true);
+ Changed = true;
+ ++NumChanged;
+ }
return Changed;
}
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
#include "llvm/Pass.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumRaised("raiseallocs\t- Number of allocations raised");
namespace {
CI->setName("");
ReplaceInstWithInst(BIL, BI, MallocI);
Changed = true;
+ ++NumRaised;
continue; // Skip the ++BI
} else if (CI->getCalledValue() == FreeFunc) { // Replace call to free?
ReplaceInstWithInst(BIL, BI, new FreeInst(CI->getOperand(1)));
Changed = true;
continue; // Skip the ++BI
+ ++NumRaised;
}
}
#include "llvm/Support/InstIterator.h"
#include <set>
+#include "Support/StatisticReporter.h"
+static Statistic<> NumInstKilled("constprop - Number of instructions killed");
+
namespace {
struct ConstantPropogation : public FunctionPass {
const char *getPassName() const { return "Simple Constant Propogation"; }
// Replace all of the uses of a variable with uses of the constant.
I->replaceAllUsesWith(C);
-
+
// We made a change to the function...
Changed = true;
+ ++NumInstKilled;
}
}
return Changed;
#include "llvm/Instruction.h"
#include "llvm/Pass.h"
#include "llvm/Support/InstIterator.h"
+#include "Support/StatisticReporter.h"
#include <set>
+static Statistic<> DIEEliminated("die\t\t- Number of insts removed");
+static Statistic<> DCEEliminated("dce\t\t- Number of insts removed");
+
//===----------------------------------------------------------------------===//
// DeadInstElimination pass implementation
//
BasicBlock::InstListType &Vals = BB->getInstList();
bool Changed = false;
for (BasicBlock::iterator DI = Vals.begin(); DI != Vals.end(); )
- if (dceInstruction(Vals, DI))
+ if (dceInstruction(Vals, DI)) {
Changed = true;
- else
+ ++DIEEliminated;
+ } else
++DI;
return Changed;
}
for (BasicBlock::iterator BI = BBIL.begin(); BI != BBIL.end(); )
if (DeadInsts.count(*BI)) { // Is this instruction dead?
delete BBIL.remove(BI); // Yup, remove and delete inst
+ ++DCEEliminated;
} else { // This instruction is not dead
++BI; // Continue on to the next one...
}
#include "llvm/iOther.h"
#include "llvm/BasicBlock.h"
#include "llvm/Pass.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumAdded("lowerrefs\t\t- New instructions added");
namespace {
struct DecomposePass : public BasicBlockPass {
if (!indexIsZero) {
LastPtr = new GetElementPtrInst(LastPtr, Indices, "ptr1");
NewInsts.push_back(cast<Instruction>(LastPtr));
+ ++NumAdded;
}
// Instruction 2: nextPtr2 = cast nextPtr1 to NextPtrTy
if (LastPtr->getType() != NextPtrTy) {
LastPtr = new CastInst(LastPtr, NextPtrTy, "ptr2");
NewInsts.push_back(cast<Instruction>(LastPtr));
+ ++NumAdded;
}
}
#include "llvm/Analysis/Dominators.h"
#include "llvm/Support/InstVisitor.h"
#include "llvm/Support/InstIterator.h"
+#include "Support/StatisticReporter.h"
#include <algorithm>
+static Statistic<> NumInstRemoved("gcse\t\t- Number of instructions removed");
+
namespace {
class GCSE : public FunctionPass, public InstVisitor<GCSE, bool> {
set<Instruction*> WorkList;
WorkList.erase(Other); // Other may not actually be on the worklist anymore...
+ ++NumInstRemoved; // Keep track of number of instructions eliminated
+
// Handle the easy case, where both instructions are in the same basic block
BasicBlock *BB1 = I->getParent(), *BB2 = Other->getParent();
if (BB1 == BB2) {
#include "llvm/Constants.h"
#include "llvm/Support/CFG.h"
#include "Support/STLExtras.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumRemoved ("indvars\t\t- Number of aux indvars removed");
+static Statistic<> NumInserted("indvars\t\t- Number of cannonical indvars added");
#if 0
#define DEBUG
std::bind1st(std::ptr_fun(TransformLoop), Loops));
// Get the header node for this loop. All of the phi nodes that could be
// induction variables must live in this basic block.
- BasicBlock *Header = (BasicBlock*)Loop->getBlocks().front();
+ //
+ BasicBlock *Header = Loop->getBlocks().front();
// Loop over all of the PHI nodes in the basic block, calculating the
// induction variables that they represent... stuffing the induction variable
assert(IndVars.back().InductionType == InductionVariable::Cannonical &&
"Just inserted cannonical indvar that is not cannonical!");
Cannonical = &IndVars.back();
+ ++NumInserted;
Changed = true;
}
delete IV->Phi;
InsertPos--; // Deleted an instr, decrement insert position
Changed = true;
+ ++NumRemoved;
}
}
return Changed;
}
-static bool doit(Function *M, LoopInfo &Loops) {
- // Induction Variables live in the header nodes of the loops of the function
- return reduce_apply_bool(Loops.getTopLevelLoops().begin(),
- Loops.getTopLevelLoops().end(),
- std::bind1st(std::ptr_fun(TransformLoop), &Loops));
-}
-
-
namespace {
struct InductionVariableSimplify : public FunctionPass {
const char *getPassName() const {
}
virtual bool runOnFunction(Function *F) {
- return doit(F, getAnalysis<LoopInfo>());
+ LoopInfo &LI = getAnalysis<LoopInfo>();
+
+ // Induction Variables live in the header nodes of loops
+ return reduce_apply_bool(LI.getTopLevelLoops().begin(),
+ LI.getTopLevelLoops().end(),
+ std::bind1st(std::ptr_fun(TransformLoop), &LI));
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
#include "llvm/Pass.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Support/InstVisitor.h"
+#include "Support/StatisticReporter.h"
+static Statistic<> NumCombined("instcombine\t- Number of insts combined");
namespace {
class InstCombiner : public FunctionPass,
// Now that we have an instruction, try combining it to simplify it...
Instruction *Result = visit(I);
if (Result) {
+ ++NumCombined;
// Should we replace the old instruction with a new one?
if (Result != I)
ReplaceInstWithInst(I, Result);
#include "llvm/iOperators.h"
#include "llvm/iPHINode.h"
#include "llvm/Support/CFG.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumInserted("pinodes\t\t- Number of Pi nodes inserted");
namespace {
struct PiNodeInserter : public FunctionPass {
if (Rep == 0)
cast<PHINode>(Pi)->addIncoming(V, Pred);
+
+ ++NumInserted;
return true;
}
#include "llvm/Constant.h"
#include "llvm/Support/CFG.h"
#include "Support/PostOrderIterator.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumChanged("reassociate\t- Number of insts reassociated");
+static Statistic<> NumSwapped("reassociate\t- Number of insts with operands swapped");
namespace {
class Reassociate : public FunctionPass {
std::swap(LHS, RHS);
std::swap(LHSRank, RHSRank);
Changed = true;
+ ++NumSwapped;
//cerr << "Transposed: " << I << " Result BB: " << I->getParent();
}
LHSI->setOperand(TakeOp, RHS);
I->setOperand(1, LHSI);
+ ++NumChanged;
//cerr << "Reassociated: " << I << " Result BB: " << I->getParent();
// Since we modified the RHS instruction, make sure that we recheck it.
#include "llvm/Pass.h"
#include "llvm/Support/InstVisitor.h"
#include "Support/STLExtras.h"
+#include "Support/StatisticReporter.h"
#include <algorithm>
#include <set>
#include <iostream>
using std::cerr;
+static Statistic<> NumInstRemoved("sccp\t\t- Number of instructions removed");
+
#if 0 // Enable this to get SCCP debug output
#define DEBUG_SCCP(X) X
#else
// Hey, we just changed something!
MadeChanges = true;
+ ++NumInstRemoved;
} else {
++BI;
}
#include "llvm/Constants.h"
#include "llvm/Pass.h"
#include "llvm/Target/TargetData.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumLowered("lowerallocs\t- Number of allocations lowered");
using std::vector;
namespace {
assert(MallocFunc && FreeFunc && BB && "Pass not initialized!");
// Loop over all of the instructions, looking for malloc or free instructions
- for (unsigned i = 0; i < BB->size(); ++i) {
+ for (unsigned i = 0; i != BB->size(); ++i) {
BasicBlock::InstListType &BBIL = BB->getInstList();
if (MallocInst *MI = dyn_cast<MallocInst>(*(BBIL.begin()+i))) {
BBIL.remove(BBIL.begin()+i); // remove the malloc instr...
MI->replaceAllUsesWith(MCast);
delete MI; // Delete the malloc inst
Changed = true;
+ ++NumLowered;
} else if (FreeInst *FI = dyn_cast<FreeInst>(*(BBIL.begin()+i))) {
BBIL.remove(BB->getInstList().begin()+i);
// Delete the old free instruction
delete FI;
Changed = true;
+ ++NumLowered;
}
}
#include "llvm/BasicBlock.h"
#include "llvm/Constant.h"
#include "llvm/Type.h"
+#include "Support/StatisticReporter.h"
+
+static Statistic<> NumPromoted("mem2reg\t\t- Number of alloca's promoted");
using std::vector;
using std::map;
delete I;
}
+ NumPromoted += Allocas.size();
+
// Purge data structurse so they are available the next iteration...
Allocas.clear();
AllocaLookup.clear();