From: Chris Lattner Date: Thu, 12 Nov 2009 01:29:10 +0000 (+0000) Subject: expose edge information and switch j-t to use it. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;ds=sidebyside;h=38392bbeb81233d0b342ad33166fc82ad922bc34;p=oota-llvm.git expose edge information and switch j-t to use it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86920 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/LazyValueInfo.h b/include/llvm/Analysis/LazyValueInfo.h index 0553e9e5680..d3466964336 100644 --- a/include/llvm/Analysis/LazyValueInfo.h +++ b/include/llvm/Analysis/LazyValueInfo.h @@ -47,6 +47,10 @@ public: /// getConstant - Determine whether the specified value is known to be a /// constant at the end of the specified block. Return null if not. Constant *getConstant(Value *V, BasicBlock *BB); + + /// getConstantOnEdge - Determine whether the specified value is known to be a + /// constant on the specified edge. Return null if not. + Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB); // Implementation boilerplate. diff --git a/lib/Analysis/LazyValueInfo.cpp b/lib/Analysis/LazyValueInfo.cpp index c17b7274594..6c306bd40b0 100644 --- a/lib/Analysis/LazyValueInfo.cpp +++ b/lib/Analysis/LazyValueInfo.cpp @@ -270,6 +270,27 @@ Constant *LazyValueInfo::getConstant(Value *V, BasicBlock *BB) { return 0; } +/// getConstantOnEdge - Determine whether the specified value is known to be a +/// constant on the specified edge. Return null if not. +Constant *LazyValueInfo::getConstantOnEdge(Value *V, BasicBlock *FromBB, + BasicBlock *ToBB) { + // If already a constant, return it. + if (Constant *VC = dyn_cast(V)) + return VC; + + DenseMap BlockValues; + + DEBUG(errs() << "Getting value " << *V << " on edge from '" + << FromBB->getName() << "' to '" << ToBB->getName() << "'\n"); + LVILatticeVal Result = GetValueOnEdge(V, FromBB, ToBB, BlockValues); + + DEBUG(errs() << " Result = " << Result << "\n"); + + if (Result.isConstant()) + return Result.getConstant(); + return 0; +} + /// isEqual - Determine whether the specified value is known to be equal or /// not-equal to the specified constant at the end of the specified block. LazyValueInfo::Tristate diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index e93e9cb4d37..a380857235b 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -278,7 +278,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){ for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { // If the value is known by LazyValueInfo to be a constant in a // predecessor, use that information to try to thread this block. - Constant *PredCst = LVI->getConstant(V, *PI); + Constant *PredCst = LVI->getConstantOnEdge(V, *PI, BB); if (PredCst == 0 || (!isa(PredCst) && !isa(PredCst))) continue; @@ -384,7 +384,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){ for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { // If the value is known by LazyValueInfo to be a constant in a // predecessor, use that information to try to thread this block. - Constant *PredCst = LVI->getConstant(Cmp->getOperand(0), *PI); + Constant *PredCst = LVI->getConstantOnEdge(Cmp->getOperand(0), *PI, BB); if (PredCst == 0) continue;