[llvm-commits] CVS: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Dec 10 12:07:04 PST 2003
Changes in directory llvm/lib/Transforms/Scalar:
IndVarSimplify.cpp updated: 1.42 -> 1.43
---
Log message:
Finegrainify namespacification
Reorder #includes
Implement: IndVarsSimplify/2003-12-10-IndVarDeadCode.ll
---
Diffs of the changes: (+27 -8)
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.42 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.43
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.42 Tue Nov 11 16:41:33 2003
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp Wed Dec 10 12:06:47 2003
@@ -15,18 +15,18 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Scalar.h"
-#include "llvm/Analysis/InductionVariable.h"
-#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Constants.h"
+#include "llvm/Type.h"
#include "llvm/iPHINode.h"
#include "llvm/iOther.h"
-#include "llvm/Type.h"
-#include "llvm/Constants.h"
+#include "llvm/Analysis/InductionVariable.h"
+#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Support/CFG.h"
+#include "llvm/Transforms/Utils/Local.h"
#include "Support/Debug.h"
#include "Support/Statistic.h"
#include "Support/STLExtras.h"
-
-namespace llvm {
+using namespace llvm;
namespace {
Statistic<> NumRemoved ("indvars", "Number of aux indvars removed");
@@ -185,8 +185,28 @@
IV->Phi->setName("");
Val->setName(OldName);
+ // Get the incoming values used by the PHI node
+ std::vector<Value*> PHIOps;
+ PHIOps.reserve(IV->Phi->getNumIncomingValues());
+ for (unsigned i = 0, e = IV->Phi->getNumIncomingValues(); i != e; ++i)
+ PHIOps.push_back(IV->Phi->getIncomingValue(i));
+
// Delete the old, now unused, phi node...
Header->getInstList().erase(IV->Phi);
+
+ // If the PHI is the last user of any instructions for computing PHI nodes
+ // that are irrelevant now, delete those instructions.
+ while (!PHIOps.empty()) {
+ Instruction *MaybeDead = dyn_cast<Instruction>(PHIOps.back());
+ PHIOps.pop_back();
+
+ if (MaybeDead && isInstructionTriviallyDead(MaybeDead)) {
+ PHIOps.insert(PHIOps.end(), MaybeDead->op_begin(),
+ MaybeDead->op_end());
+ MaybeDead->getParent()->getInstList().erase(MaybeDead);
+ }
+ }
+
Changed = true;
++NumRemoved;
}
@@ -216,8 +236,7 @@
"Canonicalize Induction Variables");
}
-Pass *createIndVarSimplifyPass() {
+Pass *llvm::createIndVarSimplifyPass() {
return new InductionVariableSimplify();
}
-} // End llvm namespace
More information about the llvm-commits
mailing list