#include "llvm/Transforms/Scalar/DCE.h"
#include "llvm/Module.h"
#include "llvm/GlobalVariable.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
//cerr << "Killing PHIs from " << BB;
//cerr << "Pred #0 = " << *pred_begin(BB);
- //cerr << "Method == " << BB->getParent();
+ //cerr << "Function == " << BB->getParent();
do {
PHINode *PN = cast<PHINode>(I);
//
// WARNING: The entry node of a method may not be simplified.
//
-bool SimplifyCFG(Method::iterator &BBIt) {
+bool SimplifyCFG(Function::iterator &BBIt) {
BasicBlock *BB = *BBIt;
- Method *M = BB->getParent();
+ Function *M = BB->getParent();
assert(BB && BB->getParent() && "Block not embedded in method!");
assert(BB->getTerminator() && "Degenerate basic block encountered!");
Succ->setName(BB->getName());
delete BB; // Delete basic block
- //cerr << "Method after removal: \n" << M;
+ //cerr << "Function after removal: \n" << M;
return true;
}
}
return false;
}
-static bool DoDCEPass(Method *M) {
- Method::iterator BBIt, BBEnd = M->end();
- if (M->begin() == BBEnd) return false; // Nothing to do
+static bool DoDCEPass(Function *F) {
+ Function::iterator BBIt, BBEnd = F->end();
+ if (F->begin() == BBEnd) return false; // Nothing to do
bool Changed = false;
// Loop through now and remove instructions that have no uses...
- for (BBIt = M->begin(); BBIt != BBEnd; ++BBIt) {
+ for (BBIt = F->begin(); BBIt != BBEnd; ++BBIt) {
Changed |= RemoveUnusedDefs((*BBIt)->getInstList());
Changed |= RemoveSingularPHIs(*BBIt);
}
// Loop over all of the basic blocks (except the first one) and remove them
// if they are unneeded...
//
- for (BBIt = M->begin(), ++BBIt; BBIt != M->end(); ) {
+ for (BBIt = F->begin(), ++BBIt; BBIt != F->end(); ) {
if (SimplifyCFG(BBIt)) {
Changed = true;
} else {
bool Changed = false;
for (Module::iterator MI = Mod->begin(); MI != Mod->end(); ) {
- Method *Meth = *MI;
+ Function *Meth = *MI;
if (Meth->isExternal() && Meth->use_size() == 0) {
// No references to prototype?
//cerr << "Removing method proto: " << Meth->getName() << endl;
- delete Mod->getMethodList().remove(MI); // Remove prototype
+ delete Mod->getFunctionList().remove(MI); // Remove prototype
// Remove moves iterator to point to the next one automatically
Changed = true;
} else {
// It is possible that we may require multiple passes over the code to fully
// eliminate dead code. Iterate until we are done.
//
- virtual bool runOnMethod(Method *M) {
+ virtual bool runOnMethod(Function *F) {
bool Changed = false;
- while (DoDCEPass(M)) Changed = true;
+ while (DoDCEPass(F)) Changed = true;
return Changed;
}