[llvm-commits] [llvm] r85465 - in /llvm/trunk/lib/Transforms: IPO/GlobalDCE.cpp Scalar/SCCP.cpp Utils/ValueMapper.cpp
Chris Lattner
sabre at nondot.org
Wed Oct 28 18:21:20 PDT 2009
Author: lattner
Date: Wed Oct 28 20:21:20 2009
New Revision: 85465
URL: http://llvm.org/viewvc/llvm-project?rev=85465&view=rev
Log:
teach various passes about blockaddress. We no longer
crash on any clang tests.
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp
llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
Modified: llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp?rev=85465&r1=85464&r2=85465&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp Wed Oct 28 20:21:20 2009
@@ -191,13 +191,13 @@
void GlobalDCE::MarkUsedGlobalsAsNeeded(Constant *C) {
if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
- GlobalIsNeeded(GV);
- else {
- // Loop over all of the operands of the constant, adding any globals they
- // use to the list of needed globals.
- for (User::op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I)
- MarkUsedGlobalsAsNeeded(cast<Constant>(*I));
- }
+ return GlobalIsNeeded(GV);
+
+ // Loop over all of the operands of the constant, adding any globals they
+ // use to the list of needed globals.
+ for (User::op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I)
+ if (Constant *OpC = dyn_cast<Constant>(*I))
+ MarkUsedGlobalsAsNeeded(OpC);
}
// RemoveUnusedGlobalValue - Loop over all of the uses of the specified
Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=85465&r1=85464&r2=85465&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Wed Oct 28 20:21:20 2009
@@ -448,10 +448,16 @@
Succs[BCValue.getConstant() == ConstantInt::getFalse(*Context)] = true;
}
}
- } else if (isa<InvokeInst>(&TI)) {
+ return;
+ }
+
+ if (isa<InvokeInst>(&TI)) {
// Invoke instructions successors are always executable.
Succs[0] = Succs[1] = true;
- } else if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
+ return;
+ }
+
+ if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
LatticeVal &SCValue = getValueState(SI->getCondition());
if (SCValue.isOverdefined() || // Overdefined condition?
(SCValue.isConstant() && !isa<ConstantInt>(SCValue.getConstant()))) {
@@ -459,9 +465,20 @@
Succs.assign(TI.getNumSuccessors(), true);
} else if (SCValue.isConstant())
Succs[SI->findCaseValue(cast<ConstantInt>(SCValue.getConstant()))] = true;
- } else {
- llvm_unreachable("SCCP: Don't know how to handle this terminator!");
+ return;
}
+
+ // TODO: This could be improved if the operand is a [cast of a] BlockAddress.
+ if (isa<IndirectBrInst>(&TI)) {
+ // Just mark all destinations executable!
+ Succs.assign(TI.getNumSuccessors(), true);
+ return;
+ }
+
+#ifndef NDEBUG
+ errs() << "Unknown terminator instruction: " << TI << '\n';
+#endif
+ llvm_unreachable("SCCP: Don't know how to handle this terminator!");
}
@@ -479,25 +496,27 @@
if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
if (BI->isUnconditional())
return true;
- else {
- LatticeVal &BCValue = getValueState(BI->getCondition());
- if (BCValue.isOverdefined()) {
- // Overdefined condition variables mean the branch could go either way.
- return true;
- } else if (BCValue.isConstant()) {
- // Not branching on an evaluatable constant?
- if (!isa<ConstantInt>(BCValue.getConstant())) return true;
-
- // Constant condition variables mean the branch can only go a single way
- return BI->getSuccessor(BCValue.getConstant() ==
- ConstantInt::getFalse(*Context)) == To;
- }
- return false;
+
+ LatticeVal &BCValue = getValueState(BI->getCondition());
+ if (BCValue.isOverdefined()) {
+ // Overdefined condition variables mean the branch could go either way.
+ return true;
+ } else if (BCValue.isConstant()) {
+ // Not branching on an evaluatable constant?
+ if (!isa<ConstantInt>(BCValue.getConstant())) return true;
+
+ // Constant condition variables mean the branch can only go a single way
+ return BI->getSuccessor(BCValue.getConstant() ==
+ ConstantInt::getFalse(*Context)) == To;
}
- } else if (isa<InvokeInst>(TI)) {
- // Invoke instructions successors are always executable.
+ return false;
+ }
+
+ // Invoke instructions successors are always executable.
+ if (isa<InvokeInst>(TI))
return true;
- } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+
+ if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
LatticeVal &SCValue = getValueState(SI->getCondition());
if (SCValue.isOverdefined()) { // Overdefined condition?
// All destinations are executable!
@@ -517,12 +536,17 @@
return SI->getDefaultDest() == To;
}
return false;
- } else {
+ }
+
+ // Just mark all destinations executable!
+ // TODO: This could be improved if the operand is a [cast of a] BlockAddress.
+ if (isa<IndirectBrInst>(&TI))
+ return true;
+
#ifndef NDEBUG
- errs() << "Unknown terminator instruction: " << *TI << '\n';
+ errs() << "Unknown terminator instruction: " << *TI << '\n';
#endif
- llvm_unreachable(0);
- }
+ llvm_unreachable(0);
}
// visit Implementations - Something changed in this instruction... Either an
Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=85465&r1=85464&r2=85465&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Wed Oct 28 20:21:20 2009
@@ -113,8 +113,8 @@
if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
Function *F = cast<Function>(MapValue(BA->getFunction(), VM));
- BasicBlock *BB = cast<BasicBlock>(MapValue(BA->getBasicBlock(), VM));
- return VM[V] = BlockAddress::get(F, BB);
+ BasicBlock *BB = cast_or_null<BasicBlock>(MapValue(BA->getBasicBlock(),VM));
+ return VM[V] = BlockAddress::get(F, BB ? BB : BA->getBasicBlock());
}
llvm_unreachable("Unknown type of constant!");
More information about the llvm-commits
mailing list