[llvm-commits] CVS: llvm/lib/VMCore/BasicBlock.cpp Value.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Jul 6 12:45:02 PDT 2004
Changes in directory llvm/lib/VMCore:
BasicBlock.cpp updated: 1.46 -> 1.47
Value.cpp updated: 1.44 -> 1.45
---
Log message:
Find bugs sooner rather than later. In this case, don't allow the creation
of instructions that don't have a first-class or void type.
---
Diffs of the changes: (+8 -11)
Index: llvm/lib/VMCore/BasicBlock.cpp
diff -u llvm/lib/VMCore/BasicBlock.cpp:1.46 llvm/lib/VMCore/BasicBlock.cpp:1.47
--- llvm/lib/VMCore/BasicBlock.cpp:1.46 Sat Jun 5 12:43:52 2004
+++ llvm/lib/VMCore/BasicBlock.cpp Tue Jul 6 12:44:17 2004
@@ -130,17 +130,11 @@
void BasicBlock::removePredecessor(BasicBlock *Pred) {
assert(find(pred_begin(this), pred_end(this), Pred) != pred_end(this) &&
"removePredecessor: BB is not a predecessor!");
- if (!isa<PHINode>(front())) return; // Quick exit.
-
- pred_iterator PI(pred_begin(this)), EI(pred_end(this));
- unsigned max_idx;
-
- // Loop over the rest of the predecessors until we run out, or until we find
- // out that there are more than 2 predecessors.
- for (max_idx = 0; PI != EI && max_idx < 3; ++PI, ++max_idx) /*empty*/;
+ PHINode *APN = dyn_cast<PHINode>(&front());
+ if (!APN) return; // Quick exit.
// If there are exactly two predecessors, then we want to nuke the PHI nodes
- // altogether. We cannot do this, however if this in this case however:
+ // altogether. However, we cannot do this, if this in this case:
//
// Loop:
// %x = phi [X, Loop]
@@ -151,10 +145,10 @@
// basic block. The only case this can happen is with a self loop, so we
// check for this case explicitly now.
//
+ unsigned max_idx = APN->getNumIncomingValues();
assert(max_idx != 0 && "PHI Node in block with 0 predecessors!?!?!");
if (max_idx == 2) {
- PI = pred_begin(this);
- BasicBlock *Other = *PI == Pred ? *++PI : *PI;
+ BasicBlock *Other = APN->getIncomingBlock(APN->getIncomingBlock(0) == Pred);
// Disable PHI elimination!
if (this == Other) max_idx = 3;
Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.44 llvm/lib/VMCore/Value.cpp:1.45
--- llvm/lib/VMCore/Value.cpp:1.44 Sun Jul 4 06:55:37 2004
+++ llvm/lib/VMCore/Value.cpp Tue Jul 6 12:44:17 2004
@@ -31,6 +31,9 @@
Value::Value(const Type *ty, unsigned scid, const std::string &name)
: SubclassID(scid), Ty(checkType(ty)), Name(name) {
+ if (!isa<Constant>(this) && !isa<BasicBlock>(this))
+ assert((Ty->isFirstClassType() || Ty == Type::VoidTy) &&
+ "Cannot create non-first-class values except for constants!");
}
Value::~Value() {
More information about the llvm-commits
mailing list