aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-07-17 20:47:02 +0000
committerDan Gohman <gohman@apple.com>2009-07-17 20:47:02 +0000
commit9545fb05b0240e600d40b236f37e6467c1062c72 (patch)
tree80aa85f4b479a948b080f13679535c4c29b7a145 /lib
parent5c3475ecd4d91b986d1d5b2facbf6618d2fd795a (diff)
downloadexternal_llvm-9545fb05b0240e600d40b236f37e6467c1062c72.zip
external_llvm-9545fb05b0240e600d40b236f37e6467c1062c72.tar.gz
external_llvm-9545fb05b0240e600d40b236f37e6467c1062c72.tar.bz2
Add a new Operator class, for handling Instructions and ConstantExprs
in a convenient manner, factoring out some common code from InstructionCombining and ValueTracking. Move the contents of BinaryOperators.h into Operator.h and use Operator to generalize them to support ConstantExprs as well as Instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76232 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp5
-rw-r--r--lib/Analysis/ValueTracking.cpp29
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp16
3 files changed, 15 insertions, 35 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 1b0b37b..6c23f40 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -66,6 +66,7 @@
#include "llvm/GlobalVariable.h"
#include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
+#include "llvm/Operator.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/LoopInfo.h"
@@ -2430,7 +2431,7 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) {
/// createNodeForGEP - Expand GEP instructions into add and multiply
/// operations. This allows them to be analyzed by regular SCEV code.
///
-const SCEV *ScalarEvolution::createNodeForGEP(User *GEP) {
+const SCEV *ScalarEvolution::createNodeForGEP(Operator *GEP) {
const Type *IntPtrTy = TD->getIntPtrType();
Value *Base = GEP->getOperand(0);
@@ -2779,7 +2780,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
else
return getUnknown(V);
- User *U = cast<User>(V);
+ Operator *U = cast<Operator>(V);
switch (Opcode) {
case Instruction::Add:
return getAddExpr(getSCEV(U->getOperand(0)),
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index ddf1752..4cca313 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -18,24 +18,13 @@
#include "llvm/GlobalVariable.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/LLVMContext.h"
+#include "llvm/Operator.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/MathExtras.h"
#include <cstring>
using namespace llvm;
-/// getOpcode - If this is an Instruction or a ConstantExpr, return the
-/// opcode value. Otherwise return UserOp1.
-static unsigned getOpcode(const Value *V) {
- if (const Instruction *I = dyn_cast<Instruction>(V))
- return I->getOpcode();
- if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
- return CE->getOpcode();
- // Use UserOp1 to mean there's no opcode.
- return Instruction::UserOp1;
-}
-
-
/// ComputeMaskedBits - Determine which of the bits specified in Mask are
/// known to be either zero or one and return them in the KnownZero/KnownOne
/// bit sets. This code only analyzes bits in Mask, in order to short-circuit
@@ -108,11 +97,11 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
if (Depth == MaxDepth || Mask == 0)
return; // Limit search depth.
- User *I = dyn_cast<User>(V);
+ Operator *I = dyn_cast<Operator>(V);
if (!I) return;
APInt KnownZero2(KnownZero), KnownOne2(KnownOne);
- switch (getOpcode(I)) {
+ switch (I->getOpcode()) {
default: break;
case Instruction::And: {
// If either the LHS or the RHS are Zero, the result is zero.
@@ -383,7 +372,7 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
// Determine which operand has more trailing zeros, and use that
// many bits from the other operand.
if (LHSKnownZeroOut > RHSKnownZeroOut) {
- if (getOpcode(I) == Instruction::Add) {
+ if (I->getOpcode() == Instruction::Add) {
APInt Mask = APInt::getLowBitsSet(BitWidth, LHSKnownZeroOut);
KnownZero |= KnownZero2 & Mask;
KnownOne |= KnownOne2 & Mask;
@@ -523,10 +512,10 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
for (unsigned i = 0; i != 2; ++i) {
Value *L = P->getIncomingValue(i);
Value *R = P->getIncomingValue(!i);
- User *LU = dyn_cast<User>(L);
+ Operator *LU = dyn_cast<Operator>(L);
if (!LU)
continue;
- unsigned Opcode = getOpcode(LU);
+ unsigned Opcode = LU->getOpcode();
// Check for operations that have the property that if
// both their operands have low zero bits, the result
// will have low zero bits.
@@ -643,8 +632,8 @@ unsigned llvm::ComputeNumSignBits(Value *V, TargetData *TD, unsigned Depth) {
if (Depth == 6)
return 1; // Limit search depth.
- User *U = dyn_cast<User>(V);
- switch (getOpcode(V)) {
+ Operator *U = dyn_cast<Operator>(V);
+ switch (Operator::getOpcode(V)) {
default: break;
case Instruction::SExt:
Tmp = TyBits-cast<IntegerType>(U->getOperand(0)->getType())->getBitWidth();
@@ -790,7 +779,7 @@ bool llvm::CannotBeNegativeZero(const Value *V, unsigned Depth) {
if (Depth == 6)
return 1; // Limit search depth.
- const Instruction *I = dyn_cast<Instruction>(V);
+ const Operator *I = dyn_cast<Operator>(V);
if (I == 0) return false;
// (add x, 0.0) is guaranteed to return +0.0, not -0.0.
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 2b7ca6b..1c25bec 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -40,6 +40,7 @@
#include "llvm/Pass.h"
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
+#include "llvm/Operator.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Target/TargetData.h"
@@ -650,17 +651,6 @@ static User *dyn_castGetElementPtr(Value *V) {
return false;
}
-/// getOpcode - If this is an Instruction or a ConstantExpr, return the
-/// opcode value. Otherwise return UserOp1.
-static unsigned getOpcode(const Value *V) {
- if (const Instruction *I = dyn_cast<Instruction>(V))
- return I->getOpcode();
- if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
- return CE->getOpcode();
- // Use UserOp1 to mean there's no opcode.
- return Instruction::UserOp1;
-}
-
/// AddOne - Add one to a ConstantInt
static Constant *AddOne(Constant *C, LLVMContext *Context) {
return Context->getConstantExprAdd(C,
@@ -8710,7 +8700,7 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) {
// See if the value being truncated is already sign extended. If so, just
// eliminate the trunc/sext pair.
- if (getOpcode(Src) == Instruction::Trunc) {
+ if (Operator::getOpcode(Src) == Instruction::Trunc) {
Value *Op = cast<User>(Src)->getOperand(0);
unsigned OpBits = Op->getType()->getScalarSizeInBits();
unsigned MidBits = Src->getType()->getScalarSizeInBits();
@@ -9625,7 +9615,7 @@ static unsigned EnforceKnownAlignment(Value *V,
User *U = dyn_cast<User>(V);
if (!U) return Align;
- switch (getOpcode(U)) {
+ switch (Operator::getOpcode(U)) {
default: break;
case Instruction::BitCast:
return EnforceKnownAlignment(U->getOperand(0), Align, PrefAlign);